Add 3DGS D3D12 composite debug checkpoint

This commit is contained in:
2026-04-13 20:17:13 +08:00
parent 5b89c2bb76
commit e462f7d6f7
7 changed files with 171 additions and 5 deletions

View File

@@ -1140,6 +1140,118 @@ bool App::InitializeDebugDrawResources() {
return true;
}
bool App::InitializeCompositeResources() {
D3D12_RESOURCE_DESC splatRenderTargetDesc = {};
splatRenderTargetDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
splatRenderTargetDesc.Alignment = 0;
splatRenderTargetDesc.Width = static_cast<UINT64>(m_width);
splatRenderTargetDesc.Height = static_cast<UINT>(m_height);
splatRenderTargetDesc.DepthOrArraySize = 1;
splatRenderTargetDesc.MipLevels = 1;
splatRenderTargetDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
splatRenderTargetDesc.SampleDesc.Count = 1;
splatRenderTargetDesc.SampleDesc.Quality = 0;
splatRenderTargetDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
splatRenderTargetDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
if (!m_splatRenderTargetTexture.Initialize(
m_device.GetDevice(),
splatRenderTargetDesc,
D3D12_RESOURCE_STATE_RENDER_TARGET)) {
m_lastErrorMessage = L"Failed to create the splat accumulation render target texture.";
return false;
}
m_splatRenderTargetTexture.SetState(ResourceStates::RenderTarget);
ResourceViewDesc renderTargetViewDesc = {};
renderTargetViewDesc.dimension = ResourceViewDimension::Texture2D;
renderTargetViewDesc.format = static_cast<uint32_t>(Format::R16G16B16A16_Float);
m_splatRenderTargetRtv.reset(static_cast<D3D12ResourceView*>(
m_device.CreateRenderTargetView(&m_splatRenderTargetTexture, renderTargetViewDesc)));
if (!m_splatRenderTargetRtv) {
m_lastErrorMessage = L"Failed to create the splat accumulation render target view.";
return false;
}
m_splatRenderTargetSrv.reset(static_cast<D3D12ResourceView*>(
m_device.CreateShaderResourceView(&m_splatRenderTargetTexture, renderTargetViewDesc)));
if (!m_splatRenderTargetSrv) {
m_lastErrorMessage = L"Failed to create the splat accumulation shader resource view.";
return false;
}
DescriptorSetLayoutBinding bindings[1] = {};
bindings[0].binding = 0;
bindings[0].type = static_cast<uint32_t>(DescriptorType::SRV);
bindings[0].count = 1;
bindings[0].visibility = static_cast<uint32_t>(ShaderVisibility::Pixel);
bindings[0].resourceDimension = ResourceViewDimension::Texture2D;
DescriptorSetLayoutDesc setLayout = {};
setLayout.bindings = bindings;
setLayout.bindingCount = 1;
RHIPipelineLayoutDesc pipelineLayoutDesc = {};
pipelineLayoutDesc.setLayouts = &setLayout;
pipelineLayoutDesc.setLayoutCount = 1;
m_compositePipelineLayout = m_device.CreatePipelineLayout(pipelineLayoutDesc);
if (m_compositePipelineLayout == nullptr) {
m_lastErrorMessage = L"Failed to create the composite pipeline layout.";
return false;
}
DescriptorPoolDesc poolDesc = {};
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
poolDesc.descriptorCount = 1;
poolDesc.shaderVisible = true;
m_compositeDescriptorPool = m_device.CreateDescriptorPool(poolDesc);
if (m_compositeDescriptorPool == nullptr) {
m_lastErrorMessage = L"Failed to create the composite descriptor pool.";
return false;
}
m_compositeDescriptorSet = m_compositeDescriptorPool->AllocateSet(setLayout);
if (m_compositeDescriptorSet == nullptr) {
m_lastErrorMessage = L"Failed to allocate the composite descriptor set.";
return false;
}
m_compositeDescriptorSet->Update(0, m_splatRenderTargetSrv.get());
GraphicsPipelineDesc pipelineDesc = {};
pipelineDesc.pipelineLayout = m_compositePipelineLayout;
pipelineDesc.topologyType = static_cast<uint32_t>(PrimitiveTopologyType::Triangle);
pipelineDesc.renderTargetCount = 1;
pipelineDesc.renderTargetFormats[0] = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
pipelineDesc.depthStencilFormat = static_cast<uint32_t>(Format::Unknown);
pipelineDesc.sampleCount = 1;
pipelineDesc.sampleQuality = 0;
pipelineDesc.rasterizerState.cullMode = static_cast<uint32_t>(CullMode::None);
pipelineDesc.depthStencilState.depthTestEnable = false;
pipelineDesc.depthStencilState.depthWriteEnable = false;
pipelineDesc.blendState.blendEnable = true;
pipelineDesc.blendState.srcBlend = static_cast<uint32_t>(BlendFactor::SrcAlpha);
pipelineDesc.blendState.dstBlend = static_cast<uint32_t>(BlendFactor::InvSrcAlpha);
pipelineDesc.blendState.srcBlendAlpha = static_cast<uint32_t>(BlendFactor::One);
pipelineDesc.blendState.dstBlendAlpha = static_cast<uint32_t>(BlendFactor::InvSrcAlpha);
pipelineDesc.vertexShader.fileName = ResolveShaderPath(L"CompositeVS.hlsl").wstring();
pipelineDesc.vertexShader.entryPoint = L"MainVS";
pipelineDesc.vertexShader.profile = L"vs_5_0";
pipelineDesc.fragmentShader.fileName = ResolveShaderPath(L"CompositePS.hlsl").wstring();
pipelineDesc.fragmentShader.entryPoint = L"MainPS";
pipelineDesc.fragmentShader.profile = L"ps_5_0";
m_compositePipelineState = m_device.CreatePipelineState(pipelineDesc);
if (m_compositePipelineState == nullptr) {
m_lastErrorMessage = L"Failed to create the composite pipeline state.";
return false;
}
return true;
}
void App::ShutdownGaussianGpuResources() {
m_gaussianColorView.reset();
m_gaussianShView.reset();
@@ -1256,6 +1368,20 @@ void App::ShutdownDebugDrawResources() {
ShutdownAndDelete(m_debugPipelineLayout);
}
void App::ShutdownCompositeResources() {
if (m_compositeDescriptorSet != nullptr) {
m_compositeDescriptorSet->Shutdown();
delete m_compositeDescriptorSet;
m_compositeDescriptorSet = nullptr;
}
ShutdownAndDelete(m_compositeDescriptorPool);
ShutdownAndDelete(m_compositePipelineState);
ShutdownAndDelete(m_compositePipelineLayout);
m_splatRenderTargetSrv.reset();
m_splatRenderTargetRtv.reset();
m_splatRenderTargetTexture.Shutdown();
}
void App::Shutdown() {
AppendTrace("Shutdown: begin");
if (!m_isInitialized && m_hwnd == nullptr) {
@@ -1670,8 +1796,8 @@ void App::RenderFrame(bool captureScreenshot) {
const int currentBackBufferIndex = m_swapChain.GetCurrentBackBufferIndex();
D3D12Texture& backBuffer = m_swapChain.GetBackBuffer(currentBackBufferIndex);
m_commandList.TransitionBarrier(backBuffer.GetResource(), ResourceStates::Present, ResourceStates::RenderTarget);
backBuffer.SetState(ResourceStates::RenderTarget);
const CPUDescriptorHandle rtvCpuHandle = m_rtvHeap.GetCPUDescriptorHandle(currentBackBufferIndex);
const CPUDescriptorHandle dsvCpuHandle = m_dsvHeap.GetCPUDescriptorHandle(0);
@@ -2034,12 +2160,14 @@ void App::RenderFrame(bool captureScreenshot) {
m_commandAllocator.Reset();
m_commandList.Reset();
m_commandList.TransitionBarrier(backBuffer.GetResource(), ResourceStates::RenderTarget, ResourceStates::Present);
backBuffer.SetState(ResourceStates::Present);
m_commandList.Close();
void* presentCommandLists[] = { &m_commandList };
AppendTrace("RenderFrame: execute final present-transition list");
m_commandQueue.ExecuteCommandLists(1, presentCommandLists);
} else {
m_commandList.TransitionBarrier(backBuffer.GetResource(), ResourceStates::RenderTarget, ResourceStates::Present);
backBuffer.SetState(ResourceStates::Present);
m_commandList.Close();
void* commandLists[] = { &m_commandList };
AppendTrace("RenderFrame: execute+present");