Skip to content

Commit

Permalink
Fix texture-array descriptors and adjust pipeline desc
Browse files Browse the repository at this point in the history
  • Loading branch information
StarsX committed Apr 15, 2024
1 parent cb160f3 commit be0477b
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 331 deletions.
2 changes: 2 additions & 0 deletions Optional/XUSGGltfLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool GltfLoader::Import(const char* pszFilename, bool needNorm, bool needColor,
const auto size = sizeof(uint8_t) * reqChannels * width * height;
m_textures[i].Data.resize(size);
memcpy(m_textures[i].Data.data(), pTexData, size);
STBI_FREE(pTexData);
m_textures[i].Width = width;
m_textures[i].Height = height;
m_textures[i].Channels = reqChannels;
Expand Down Expand Up @@ -517,6 +518,7 @@ void GltfLoader::regenerateUV1(uint32_t vertexOffset, uint32_t vertexCount, bool
if (error != xatlas::AddMeshError::Success)
{
subset.LightMapScl = float2(1.0f);
xatlas::Destroy(pAtlas);
return;
}

Expand Down
56 changes: 51 additions & 5 deletions XUSG/Core/XUSG.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ namespace XUSG

XUSG_DEF_ENUM_FLAG_OPERATORS(ColorWrite);

enum class LineRasterization : uint8_t
{
ALIASED,
ALPHA_ANTIALIASED,
QUADRILATERAL_WIDE,
QUADRILATERAL_NARROW
};

enum class ComparisonFunc : uint8_t
{
NEVER,
Expand Down Expand Up @@ -1110,8 +1118,10 @@ namespace XUSG
virtual uint32_t Create(void* pAdapter, uint32_t minFeatureLevel, const wchar_t* name = nullptr) = 0;
virtual uint32_t GetDeviceRemovedReason() const = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

using uptr = std::unique_ptr<Device>;
Expand All @@ -1137,8 +1147,10 @@ namespace XUSG

virtual uint64_t GetCompletedValue() const = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

using uptr = std::unique_ptr<Fence>;
Expand Down Expand Up @@ -1167,8 +1179,10 @@ namespace XUSG
const IndirectArgument* pArguments, const PipelineLayout& pipelineLayout = nullptr,
uint32_t nodeMask = 0, const wchar_t* name = nullptr) = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

using uptr = std::unique_ptr<CommandLayout>;
Expand All @@ -1190,9 +1204,13 @@ namespace XUSG
virtual bool Create(const Device* pDevice, CommandListType type, const wchar_t* name = nullptr) = 0;
virtual bool Reset() = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

// Get API native handle of the device for this command allocator
virtual void* GetDeviceHandle() const = 0;

virtual const Device* GetDevice() const = 0;
Expand Down Expand Up @@ -1315,9 +1333,13 @@ namespace XUSG
const Resource* pArgumentBuffer, uint64_t argumentBufferOffset = 0,
const Resource* pCountBuffer = nullptr, uint64_t countBufferOffset = 0) = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

// Get API native handle of the device for this command list
virtual void* GetDeviceHandle() const = 0;

virtual const Device* GetDevice() const = 0;
Expand Down Expand Up @@ -1353,9 +1375,13 @@ namespace XUSG
virtual void ExecuteCommandLists(uint32_t numCommandLists, const CommandList* const* ppCommandLists) = 0;
virtual void ExecuteCommandList(const CommandList* pCommandList) = 0;

// Create from API native handle
virtual void Create(void* pHandle, const wchar_t* name = nullptr) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

// Get API native handle of the device for this command list
virtual void* GetDeviceHandle() const = 0;

virtual const Device* GetDevice() const = 0;
Expand Down Expand Up @@ -1392,8 +1418,10 @@ namespace XUSG

virtual uint8_t GetCurrentBackBufferIndex() const = 0;

// Create from API native handle
virtual void Create(void* pHandle) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

using uptr = std::unique_ptr<SwapChain>;
Expand Down Expand Up @@ -1429,10 +1457,12 @@ namespace XUSG

virtual uint64_t GetVirtualAddress(int offset = 0) const = 0;

// Create from API native handle
virtual void Create(void* pDeviceHandle, void* pResourceHandle,
const wchar_t* name = nullptr, uint32_t maxThreads = 1) = 0;
virtual void SetName(const wchar_t* name) = 0;

// Get API native handle
virtual void* GetHandle() const = 0;

using uptr = std::unique_ptr<Resource>;
Expand Down Expand Up @@ -2244,12 +2274,11 @@ namespace XUSG
FillMode Fill;
CullMode Cull;
bool FrontCounterClockwise;
int DepthBias;
float DepthBias;
float DepthBiasClamp;
float SlopeScaledDepthBias;
bool DepthClipEnable;
bool MultisampleEnable;
bool AntialiasedLineEnable;
LineRasterization LineRasterizationMode;
uint8_t ForcedSampleCount;
bool ConservativeRaster;
};
Expand All @@ -2260,6 +2289,8 @@ namespace XUSG
StencilOp StencilDepthFailOp;
StencilOp StencilPassOp;
ComparisonFunc StencilFunc;
uint8_t StencilReadMask;
uint8_t StencilWriteMask;
};

struct DepthStencil
Expand All @@ -2268,10 +2299,9 @@ namespace XUSG
bool DepthWriteMask;
ComparisonFunc Comparison;
bool StencilEnable;
uint8_t StencilReadMask;
uint8_t StencilWriteMask;
DepthStencilOp FrontFace;
DepthStencilOp BackFace;
bool DepthBoundsTestEnable;
};

class PipelineLib;
Expand Down Expand Up @@ -2310,8 +2340,13 @@ namespace XUSG
virtual Pipeline CreatePipeline(PipelineLib* pPipelineLib, const wchar_t* name = nullptr) const = 0;
virtual Pipeline GetPipeline(PipelineLib* pPipelineLib, const wchar_t* name = nullptr) const = 0;

// Get the key of the pipeline cache for XUSG pipeline lib
virtual const std::string& GetKey() const = 0;

// Get API native desc of this PSO handle
// pInputElements should be a pointer to std::vector<[API]_INPUT_ELEMENT_DESC>
virtual void GetHandleDesc(void* pHandleDesc, void* pInputElements, PipelineLib* pPipelineLib) const = 0;

using uptr = std::unique_ptr<State>;
using sptr = std::shared_ptr<State>;

Expand Down Expand Up @@ -2340,6 +2375,10 @@ namespace XUSG
virtual const Rasterizer* GetRasterizer(RasterizerPreset preset) = 0;
virtual const DepthStencil* GetDepthStencil(DepthStencilPreset preset) = 0;

// Get API native desc of this PSO handle
// pInputElements should be a pointer to std::vector<[API]_INPUT_ELEMENT_DESC>
virtual void GetHandleDesc(void* pHandleDesc, void* pInputElements, const std::string& key) = 0;

static DepthStencil DepthStencilDefault();
static DepthStencil DepthStencilNone();
static DepthStencil DepthRead();
Expand Down Expand Up @@ -2400,8 +2439,12 @@ namespace XUSG
virtual Pipeline CreatePipeline(PipelineLib* pPipelineLib, const wchar_t* name = nullptr) const = 0;
virtual Pipeline GetPipeline(PipelineLib* pPipelineLib, const wchar_t* name = nullptr) const = 0;

// Get the key of the pipeline cache for XUSG pipeline lib
virtual const std::string& GetKey() const = 0;

// Get API native desc of this PSO handle
virtual void GetHandleDesc(void* pHandleDesc, PipelineLib* pPipelineLib) const = 0;

using uptr = std::unique_ptr<State>;
using sptr = std::shared_ptr<State>;

Expand All @@ -2422,6 +2465,9 @@ namespace XUSG
virtual Pipeline CreatePipeline(const State* pState, const wchar_t* name = nullptr) = 0;
virtual Pipeline GetPipeline(const State* pState, const wchar_t* name = nullptr) = 0;

// Get API native desc of this PSO handle
virtual void GetHandleDesc(void* pHandleDesc, const std::string& key) = 0;

using uptr = std::unique_ptr<PipelineLib>;
using sptr = std::shared_ptr<PipelineLib>;

Expand Down
40 changes: 27 additions & 13 deletions XUSG/Core/XUSGComputeState_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ const string& State_DX12::GetKey() const
return m_key;
}

void State_DX12::GetHandleDesc(void* pHandleDesc, PipelineLib* pPipelineLib) const
{
pPipelineLib->GetHandleDesc(pHandleDesc, GetKey());
}

//--------------------------------------------------------------------------------------

PipelineLib_DX12::PipelineLib_DX12() :
Expand Down Expand Up @@ -104,19 +109,8 @@ Pipeline PipelineLib_DX12::GetPipeline(const State* pState, const wchar_t* name)
Pipeline PipelineLib_DX12::createPipeline(const string& key, const wchar_t* name)
{
// Fill desc
const auto pDesc = reinterpret_cast<const PipelineDesc*>(key.data());
D3D12_COMPUTE_PIPELINE_STATE_DESC desc = {};
if (pDesc->Layout)
desc.pRootSignature = static_cast<ID3D12RootSignature*>(pDesc->Layout);

if (pDesc->Shader)
desc.CS = CD3DX12_SHADER_BYTECODE(static_cast<ID3DBlob*>(pDesc->Shader));

const auto pCachedPipeline = static_cast<ID3DBlob*>(pDesc->CachedPipeline);
desc.CachedPSO.pCachedBlob = pCachedPipeline ? pCachedPipeline->GetBufferPointer() : nullptr;
desc.CachedPSO.CachedBlobSizeInBytes = pCachedPipeline ? pCachedPipeline->GetBufferSize() : 0;
desc.NodeMask = pDesc->NodeMask;
desc.Flags = GetDX12PipelineFlags(pDesc->Flags);
D3D12_COMPUTE_PIPELINE_STATE_DESC desc;
GetHandleDesc(&desc, key);

// Create pipeline
com_ptr<ID3D12PipelineState> pipeline;
Expand All @@ -136,3 +130,23 @@ Pipeline PipelineLib_DX12::getPipeline(const string& key, const wchar_t* name)

return pPipeline->second.get();
}

void PipelineLib_DX12::GetHandleDesc(void* pHandleDesc, const string& key)
{
const auto pDesc = reinterpret_cast<const PipelineDesc*>(key.data());
auto& desc = *static_cast<D3D12_COMPUTE_PIPELINE_STATE_DESC*>(pHandleDesc);
desc = {};

// Fill desc
if (pDesc->Layout)
desc.pRootSignature = static_cast<ID3D12RootSignature*>(pDesc->Layout);

if (pDesc->Shader)
desc.CS = CD3DX12_SHADER_BYTECODE(static_cast<ID3DBlob*>(pDesc->Shader));

const auto pCachedPipeline = static_cast<ID3DBlob*>(pDesc->CachedPipeline);
desc.CachedPSO.pCachedBlob = pCachedPipeline ? pCachedPipeline->GetBufferPointer() : nullptr;
desc.CachedPSO.CachedBlobSizeInBytes = pCachedPipeline ? pCachedPipeline->GetBufferSize() : 0;
desc.NodeMask = pDesc->NodeMask;
desc.Flags = GetDX12PipelineFlags(pDesc->Flags);
}
4 changes: 4 additions & 0 deletions XUSG/Core/XUSGComputeState_DX12.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace XUSG

const std::string& GetKey() const;

void GetHandleDesc(void* pHandleDesc, PipelineLib* pPipelineLib) const;

protected:
PipelineDesc* m_pKey;
std::string m_key;
Expand All @@ -56,6 +58,8 @@ namespace XUSG
Pipeline CreatePipeline(const State* pState, const wchar_t* name = nullptr);
Pipeline GetPipeline(const State* pState, const wchar_t* name = nullptr);

void GetHandleDesc(void* pHandleDesc, const std::string& key);

protected:
virtual Pipeline createPipeline(const std::string& key, const wchar_t* name);
Pipeline getPipeline(const std::string& key, const wchar_t* nam);
Expand Down
5 changes: 2 additions & 3 deletions XUSG/Core/XUSGDepthStencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ Graphics::DepthStencil PipelineLib::DepthStencilDefault()
depthStencil.DepthWriteMask = true;
depthStencil.Comparison = ComparisonFunc::LESS;
depthStencil.StencilEnable = false;
depthStencil.StencilReadMask = 0xff;
depthStencil.StencilWriteMask = 0xff;
depthStencil.DepthBoundsTestEnable = false;

const DepthStencilOp defaultStencilOp =
{ StencilOp::KEEP, StencilOp::KEEP, StencilOp::KEEP, ComparisonFunc::ALWAYS };
{ StencilOp::KEEP, StencilOp::KEEP, StencilOp::KEEP, ComparisonFunc::ALWAYS, 0xff, 0xff };
depthStencil.FrontFace = defaultStencilOp;
depthStencil.BackFace = defaultStencilOp;

Expand Down
13 changes: 13 additions & 0 deletions XUSG/Core/XUSGEnum_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,19 @@ uint8_t XUSG::GetDX12ColorWrite(ColorWrite writeMask)
return mask;
}

D3D12_LINE_RASTERIZATION_MODE XUSG::GetDX12LineRasterizationMode(LineRasterization mode)
{
static const D3D12_LINE_RASTERIZATION_MODE modes[] =
{
D3D12_LINE_RASTERIZATION_MODE_ALIASED,
D3D12_LINE_RASTERIZATION_MODE_ALPHA_ANTIALIASED,
D3D12_LINE_RASTERIZATION_MODE_QUADRILATERAL_WIDE,
D3D12_LINE_RASTERIZATION_MODE_QUADRILATERAL_NARROW
};

return modes[static_cast<uint32_t>(mode)];
}

D3D12_COMPARISON_FUNC XUSG::GetDX12ComparisonFunc(ComparisonFunc comparisonFunc)
{
static const D3D12_COMPARISON_FUNC comparisonFuncs[] =
Expand Down
2 changes: 2 additions & 0 deletions XUSG/Core/XUSGEnum_DX12.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace XUSG

uint8_t GetDX12ColorWrite(ColorWrite writeMask);

D3D12_LINE_RASTERIZATION_MODE GetDX12LineRasterizationMode(LineRasterization mode);

D3D12_COMPARISON_FUNC GetDX12ComparisonFunc(ComparisonFunc comparisonFunc);
D3D12_STENCIL_OP GetDX12StencilOp(StencilOp stencilOp);

Expand Down
Loading

0 comments on commit be0477b

Please sign in to comment.