Skip to content

Commit

Permalink
Fix the descriptor table lib
Browse files Browse the repository at this point in the history
  • Loading branch information
StarsX committed Feb 12, 2023
1 parent a8d69e1 commit d823fee
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
1 change: 0 additions & 1 deletion XUSG-EZ/XUSG-EZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ namespace XUSG
virtual void GenerateMips(Texture* pResource, SamplerPreset sampler, const Blob& customShader = nullptr) = 0;
virtual void GenerateMips(Texture3D* pResource, SamplerPreset sampler, const Blob& customShader = nullptr) = 0;

virtual const InputLayout* GetInputLayout(uint32_t index) const = 0;
virtual const Graphics::Blend* GetBlend(Graphics::BlendPreset preset, uint8_t numColorRTs = 1) = 0;
virtual const Graphics::Rasterizer* GetRasterizer(Graphics::RasterizerPreset preset) = 0;
virtual const Graphics::DepthStencil* GetDepthStencil(Graphics::DepthStencilPreset preset) = 0;
Expand Down
5 changes: 0 additions & 5 deletions XUSG-EZ/XUSG-EZ_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,6 @@ void EZ::CommandList_DX12::GenerateMips(Texture3D* pResource, SamplerPreset samp
}
}

const InputLayout* EZ::CommandList_DX12::GetInputLayout(uint32_t index) const
{
return m_graphicsPipelineLib->GetInputLayout(index);
}

const Graphics::Blend* EZ::CommandList_DX12::GetBlend(Graphics::BlendPreset preset, uint8_t numColorRTs)
{
return m_graphicsPipelineLib->GetBlend(preset, numColorRTs);
Expand Down
1 change: 0 additions & 1 deletion XUSG-EZ/XUSG-EZ_DX12.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ namespace XUSG
void GenerateMips(Texture* pResource, SamplerPreset sampler, const Blob& customShader = nullptr);
void GenerateMips(Texture3D* pResource, SamplerPreset sampler, const Blob& customShader = nullptr);

const InputLayout* GetInputLayout(uint32_t index) const;
const Graphics::Blend* GetBlend(Graphics::BlendPreset preset, uint8_t numColorRTs = 1);
const Graphics::Rasterizer* GetRasterizer(Graphics::RasterizerPreset preset);
const Graphics::DepthStencil* GetDepthStencil(Graphics::DepthStencilPreset preset);
Expand Down
7 changes: 6 additions & 1 deletion XUSG/Core/XUSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Compute::PipelineLib::sptr Compute::PipelineLib::MakeShared(const Device* pDevic
return make_shared<PipelineLib_DX12>(pDevice);
}

XUSG_INTERFACE Blob XUSG::GetPipelineCache(Pipeline pipeline, API api)
Blob XUSG::GetPipelineCache(Pipeline pipeline, API api)
{
return GetDX12PipelineCache(pipeline);
}
Expand Down Expand Up @@ -395,3 +395,8 @@ uint8_t XUSG::Log2(uint32_t value)
return static_cast<uint8_t>(log2(value));
#endif
}

uint32_t XUSG::DivideRoundUp(uint32_t x, uint32_t n)
{
return XUSG_DIV_UP(x, n);
}
1 change: 1 addition & 0 deletions XUSG/Core/XUSG.h
Original file line number Diff line number Diff line change
Expand Up @@ -2289,4 +2289,5 @@ namespace XUSG
XUSG_INTERFACE uint8_t CalculateMipLevels(uint32_t width, uint32_t height, uint32_t depth = 1);
XUSG_INTERFACE uint8_t CalculateMipLevels(uint64_t width, uint32_t height, uint32_t depth = 1);
XUSG_INTERFACE uint8_t Log2(uint32_t value);
XUSG_INTERFACE uint32_t DivideRoundUp(uint32_t x, uint32_t n);
}
57 changes: 34 additions & 23 deletions XUSG/Core/XUSGDescriptor_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,27 @@ bool DescriptorTableLib_DX12::reallocateCbvSrvUavHeap(const string& key)
{
assert(key.size() > 0);
const auto& index = key[0];
const auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Descriptor));
auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Descriptor));

// Allocate a new heap if neccessary
const auto& descriptorHeap = m_descriptorHeaps[CBV_SRV_UAV_HEAP][index];
auto descriptorCount = getNewHeapSize(numDescriptors, CBV_SRV_UAV_HEAP, index);
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < descriptorCount)
const auto descriptorCount = m_descriptorCounts[CBV_SRV_UAV_HEAP][index];
numDescriptors += descriptorCount;
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < numDescriptors)
{
descriptorCount = calculateGrowth(descriptorCount, CBV_SRV_UAV_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(CBV_SRV_UAV_HEAP, descriptorCount, index), false);
const auto oldHeapStart = descriptorHeap ? descriptorHeap->GetGPUDescriptorHandleForHeapStart().ptr : 0;
numDescriptors = calculateGrowth(numDescriptors, CBV_SRV_UAV_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(CBV_SRV_UAV_HEAP, numDescriptors, index), false);

// Recreate descriptor tables
assert(descriptorHeap);
const auto newHeapStart = descriptorHeap->GetGPUDescriptorHandleForHeapStart().ptr;
m_descriptorCounts[CBV_SRV_UAV_HEAP][index] = descriptorCount;
for (const auto& tableEntry : m_cbvSrvUavTables[index])
*tableEntry.second = *createCbvSrvUavTable(tableEntry.first, nullptr);
{
*tableEntry.second = *tableEntry.second - oldHeapStart + newHeapStart;
*tableEntry.second = *createCbvSrvUavTable(tableEntry.first, tableEntry.second);
}
}

return true;
Expand All @@ -363,19 +371,27 @@ bool DescriptorTableLib_DX12::reallocateSamplerHeap(const string& key)
{
assert(key.size() > 0);
const auto& index = key[0];
const auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Sampler*));
auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Sampler*));

// Allocate a new heap if neccessary
const auto& descriptorHeap = m_descriptorHeaps[SAMPLER_HEAP][index];
auto descriptorCount = getNewHeapSize(numDescriptors, SAMPLER_HEAP, index);
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < descriptorCount)
const auto descriptorCount = m_descriptorCounts[SAMPLER_HEAP][index];
numDescriptors += descriptorCount;
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < numDescriptors)
{
descriptorCount = calculateGrowth(descriptorCount, SAMPLER_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(SAMPLER_HEAP, descriptorCount, index), false);
const auto oldHeapStart = descriptorHeap ? descriptorHeap->GetGPUDescriptorHandleForHeapStart().ptr : 0;
numDescriptors = calculateGrowth(numDescriptors, SAMPLER_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(SAMPLER_HEAP, numDescriptors, index), false);

// Recreate descriptor tables
assert(descriptorHeap);
const auto newHeapStart = descriptorHeap->GetGPUDescriptorHandleForHeapStart().ptr;
m_descriptorCounts[SAMPLER_HEAP][index] = descriptorCount;
for (const auto& tableEntry : m_samplerTables[index])
*tableEntry.second = *createSamplerTable(tableEntry.first, nullptr);
{
*tableEntry.second = *tableEntry.second - oldHeapStart + newHeapStart;
*tableEntry.second = *createSamplerTable(tableEntry.first, tableEntry.second);
}
}

return true;
Expand All @@ -385,15 +401,15 @@ bool DescriptorTableLib_DX12::reallocateRtvHeap(const string& key)
{
assert(key.size() > 0);
const auto& index = key[0];
const auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Descriptor));
auto numDescriptors = static_cast<uint32_t>(key.size() / sizeof(Descriptor));

// Allocate a new heap if neccessary
const auto& descriptorHeap = m_descriptorHeaps[RTV_HEAP][index];
auto descriptorCount = getNewHeapSize(numDescriptors, RTV_HEAP, index);
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < descriptorCount)
numDescriptors += m_descriptorCounts[RTV_HEAP][index];
if (!descriptorHeap || descriptorHeap->GetDesc().NumDescriptors < numDescriptors)
{
descriptorCount = calculateGrowth(descriptorCount, RTV_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(RTV_HEAP, descriptorCount, index), false);
numDescriptors = calculateGrowth(numDescriptors, RTV_HEAP, index);
XUSG_N_RETURN(allocateDescriptorHeap(RTV_HEAP, numDescriptors, index), false);

// Recreate descriptor tables
for (const auto& tableEntry : m_rtvTables[index])
Expand Down Expand Up @@ -522,7 +538,7 @@ DescriptorTable DescriptorTableLib_DX12::createSamplerTable(const string& key, D
desc.MinLOD = pSamplers[i]->MinLOD;
desc.MaxLOD = pSamplers[i]->MaxLOD;

// Copy a descriptor
// Create a sampler descriptor
m_device->CreateSampler(&desc, dst);
dst.Offset(descriptorStride);
}
Expand Down Expand Up @@ -654,11 +670,6 @@ Framebuffer DescriptorTableLib_DX12::getFramebuffer(const string& key,
return framebuffer;
}

uint32_t DescriptorTableLib_DX12::getNewHeapSize(uint32_t numDescriptors, DescriptorHeapType type, uint8_t index) const
{
return m_descriptorCounts[type][index] + numDescriptors;
}

uint32_t DescriptorTableLib_DX12::calculateGrowth(uint32_t newSize, DescriptorHeapType type, uint8_t index) const
{
const auto& oldCapacity = m_descriptorCounts[type][index];
Expand Down
1 change: 0 additions & 1 deletion XUSG/Core/XUSGDescriptor_DX12.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ namespace XUSG
Framebuffer createFramebuffer(const std::string& key, const Descriptor *pDsv, const Framebuffer* pFramebuffer);
Framebuffer getFramebuffer(const std::string& key, const Descriptor* pDsv, const Framebuffer* pFramebuffer);

uint32_t getNewHeapSize(uint32_t numDescriptors, DescriptorHeapType type, uint8_t index) const;
uint32_t calculateGrowth(uint32_t newSize, DescriptorHeapType type, uint8_t index) const;

com_ptr<ID3D12Device> m_device;
Expand Down

0 comments on commit d823fee

Please sign in to comment.