Fix D3D12 descriptor set staging for shader tables

This commit is contained in:
2026-04-12 11:49:12 +08:00
parent 7ee28a7969
commit 347d08463b
4 changed files with 81 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
#include "fixtures/D3D12TestFixture.h"
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
#include "XCEngine/RHI/D3D12/D3D12DescriptorSet.h"
#include "XCEngine/RHI/D3D12/D3D12PipelineLayout.h"
#include "XCEngine/RHI/RHIDescriptorPool.h"
@@ -54,6 +55,64 @@ TEST_F(D3D12TestFixture, DescriptorSet_MixedBindings_AssignDescriptorIndicesByTy
delete pool;
}
TEST_F(D3D12TestFixture, DescriptorSet_TableBindingsUseCpuVisibleStagingHeaps) {
DescriptorPoolDesc texturePoolDesc = {};
texturePoolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
texturePoolDesc.descriptorCount = 2;
texturePoolDesc.shaderVisible = true;
RHIDescriptorPool* texturePool = GetDevice()->CreateDescriptorPool(texturePoolDesc);
ASSERT_NE(texturePool, nullptr);
DescriptorSetLayoutBinding textureBinding = {};
textureBinding.binding = 0;
textureBinding.type = static_cast<uint32_t>(DescriptorType::SRV);
textureBinding.count = 1;
DescriptorSetLayoutDesc textureLayoutDesc = {};
textureLayoutDesc.bindings = &textureBinding;
textureLayoutDesc.bindingCount = 1;
RHIDescriptorSet* textureSet = texturePool->AllocateSet(textureLayoutDesc);
ASSERT_NE(textureSet, nullptr);
auto* textureD3D12Set = static_cast<D3D12DescriptorSet*>(textureSet);
ASSERT_NE(textureD3D12Set->GetHeap(), nullptr);
EXPECT_FALSE(textureD3D12Set->GetHeap()->IsShaderVisible());
DescriptorPoolDesc samplerPoolDesc = {};
samplerPoolDesc.type = DescriptorHeapType::Sampler;
samplerPoolDesc.descriptorCount = 1;
samplerPoolDesc.shaderVisible = true;
RHIDescriptorPool* samplerPool = GetDevice()->CreateDescriptorPool(samplerPoolDesc);
ASSERT_NE(samplerPool, nullptr);
DescriptorSetLayoutBinding samplerBinding = {};
samplerBinding.binding = 0;
samplerBinding.type = static_cast<uint32_t>(DescriptorType::Sampler);
samplerBinding.count = 1;
DescriptorSetLayoutDesc samplerLayoutDesc = {};
samplerLayoutDesc.bindings = &samplerBinding;
samplerLayoutDesc.bindingCount = 1;
RHIDescriptorSet* samplerSet = samplerPool->AllocateSet(samplerLayoutDesc);
ASSERT_NE(samplerSet, nullptr);
auto* samplerD3D12Set = static_cast<D3D12DescriptorSet*>(samplerSet);
ASSERT_NE(samplerD3D12Set->GetHeap(), nullptr);
EXPECT_FALSE(samplerD3D12Set->GetHeap()->IsShaderVisible());
textureSet->Shutdown();
delete textureSet;
texturePool->Shutdown();
delete texturePool;
samplerSet->Shutdown();
delete samplerSet;
samplerPool->Shutdown();
delete samplerPool;
}
TEST_F(D3D12TestFixture, DescriptorSet_MultipleConstantBuffersUploadIndependently) {
DescriptorPoolDesc poolDesc = {};
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;