From ef067bef2f2188a4b3c420cbcd8d223874888ed2 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Thu, 25 Aug 2022 09:11:04 -0700 Subject: Fix for Vulkan ray tracing test using a non-zero raygen shader index (#2380) * Fixed math errors in SBT creation causing a ray tracing test to fail with a fully zero output when given a non-zero raygen shader index * Removed unnecessary code * raygen memcpy now copies the 32 bytes from srcHandle and zeroes out the remaining 32 bytes due to 64 byte alignment --- tools/gfx-unit-test/ray-tracing-tests.cpp | 3 --- tools/gfx/vulkan/vk-shader-table.cpp | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/gfx-unit-test/ray-tracing-tests.cpp b/tools/gfx-unit-test/ray-tracing-tests.cpp index 558c700d3..97a6ad7d1 100644 --- a/tools/gfx-unit-test/ray-tracing-tests.cpp +++ b/tools/gfx-unit-test/ray-tracing-tests.cpp @@ -488,11 +488,8 @@ namespace gfx_test runTestImpl(rayTracingTestImpl, unitTestContext, Slang::RenderApiFlag::D3D12); } -#if 0 - //TODO: fix test failure. SLANG_UNIT_TEST(RayTracingTestBVulkan) { runTestImpl(rayTracingTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); } -#endif } diff --git a/tools/gfx/vulkan/vk-shader-table.cpp b/tools/gfx/vulkan/vk-shader-table.cpp index 89225f7c2..a47750ddb 100644 --- a/tools/gfx/vulkan/vk-shader-table.cpp +++ b/tools/gfx/vulkan/vk-shader-table.cpp @@ -22,8 +22,7 @@ RefPtr ShaderTableImpl::createDeviceBuffer( auto vkApi = m_device->m_api; auto rtProps = vkApi.m_rtProperties; uint32_t handleSize = rtProps.shaderGroupHandleSize; - m_raygenTableSize = (uint32_t)VulkanUtil::calcAligned( - m_rayGenShaderCount * handleSize, rtProps.shaderGroupBaseAlignment); + m_raygenTableSize = m_rayGenShaderCount * rtProps.shaderGroupBaseAlignment; m_missTableSize = (uint32_t)VulkanUtil::calcAligned( m_missShaderCount * handleSize, rtProps.shaderGroupBaseAlignment); m_hitTableSize = (uint32_t)VulkanUtil::calcAligned( @@ -75,7 +74,7 @@ RefPtr ShaderTableImpl::createDeviceBuffer( // index in the buffer of handles. for (uint32_t i = 0; i < m_rayGenShaderCount; i++) { - auto dstHandlePtr = subTablePtr + i * handleSize; + auto dstHandlePtr = subTablePtr + i * rtProps.shaderGroupBaseAlignment; auto shaderGroupName = m_shaderGroupNames[shaderTableEntryCounter++]; auto shaderGroupIndexPtr = pipelineImpl->shaderGroupNameToIndex.TryGetValue(shaderGroupName); @@ -85,6 +84,7 @@ RefPtr ShaderTableImpl::createDeviceBuffer( auto shaderGroupIndex = *shaderGroupIndexPtr; auto srcHandlePtr = handles.getBuffer() + shaderGroupIndex * handleSize; memcpy(dstHandlePtr, srcHandlePtr, handleSize); + memset(dstHandlePtr + handleSize, 0, rtProps.shaderGroupBaseAlignment - handleSize); } subTablePtr += m_raygenTableSize; -- cgit v1.2.3