From 26e622245b930f973963fa3200ab8dc0aadc3b1f Mon Sep 17 00:00:00 2001 From: skallweitNV <64953474+skallweitNV@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:28:16 +0200 Subject: Fix D3D12 dispatchRays() when using an empty miss and/or hitgroup table (#2468) --- tools/gfx/d3d12/d3d12-command-encoder.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'tools/gfx/d3d12/d3d12-command-encoder.cpp') diff --git a/tools/gfx/d3d12/d3d12-command-encoder.cpp b/tools/gfx/d3d12/d3d12-command-encoder.cpp index a9245bebc..4c99dd5a8 100644 --- a/tools/gfx/d3d12/d3d12-command-encoder.cpp +++ b/tools/gfx/d3d12/d3d12-command-encoder.cpp @@ -1383,17 +1383,23 @@ void RayTracingCommandEncoderImpl::dispatchRays( rayGenShaderIndex * kRayGenRecordSize; dispatchDesc.RayGenerationShaderRecord.SizeInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; - dispatchDesc.MissShaderTable.StartAddress = - shaderTableAddr + shaderTableImpl->m_missTableOffset; - dispatchDesc.MissShaderTable.SizeInBytes = - shaderTableImpl->m_missShaderCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; - dispatchDesc.MissShaderTable.StrideInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; - - dispatchDesc.HitGroupTable.StartAddress = - shaderTableAddr + shaderTableImpl->m_hitGroupTableOffset; - dispatchDesc.HitGroupTable.SizeInBytes = - shaderTableImpl->m_hitGroupCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; - dispatchDesc.HitGroupTable.StrideInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; + if (shaderTableImpl->m_missShaderCount > 0) + { + dispatchDesc.MissShaderTable.StartAddress = + shaderTableAddr + shaderTableImpl->m_missTableOffset; + dispatchDesc.MissShaderTable.SizeInBytes = + shaderTableImpl->m_missShaderCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; + dispatchDesc.MissShaderTable.StrideInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; + } + + if (shaderTableImpl->m_hitGroupCount > 0) + { + dispatchDesc.HitGroupTable.StartAddress = + shaderTableAddr + shaderTableImpl->m_hitGroupTableOffset; + dispatchDesc.HitGroupTable.SizeInBytes = + shaderTableImpl->m_hitGroupCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; + dispatchDesc.HitGroupTable.StrideInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; + } dispatchDesc.Width = (UINT)width; dispatchDesc.Height = (UINT)height; -- cgit v1.2.3