Skip to content

Commit 8294f83

Browse files
author
kevyuu
committed
Convert traceRaysIndirect to use vkCmdTraceRaysIndirect2KHR.
1 parent 20ab6d6 commit 8294f83

File tree

6 files changed

+37
-74
lines changed

6 files changed

+37
-74
lines changed

include/nbl/builtin/hlsl/indirect_commands.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,22 @@ struct DispatchIndirectCommand_t
3939

4040
struct TraceRaysIndirectCommand_t
4141
{
42+
uint64_t raygenShaderRecordAddress;
43+
uint64_t raygenShaderRecordSize;
44+
uint64_t missShaderBindingTableAddress;
45+
uint64_t missShaderBindingTableSize;
46+
uint64_t missShaderBindingTableStride;
47+
uint64_t hitShaderBindingTableAddress;
48+
uint64_t hitShaderBindingTableSize;
49+
uint64_t hitShaderBindingTableStride;
50+
uint64_t callableShaderBindingTableAddress;
51+
uint64_t callableShaderBindingTableSize;
52+
uint64_t callableShaderBindingTableStride;
4253
uint32_t width;
4354
uint32_t height;
4455
uint32_t depth;
4556
};
57+
4658
}
4759
}
4860

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,7 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
531531
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
532532
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
533533
uint32_t width, uint32_t height, uint32_t depth);
534-
bool IGPUCommandBuffer::traceRaysIndirect(
535-
const asset::SBufferRange<const IGPUBuffer>& raygenGroupRange,
536-
const asset::SBufferRange<const IGPUBuffer>& missGroupsRange, uint32_t missGroupStride,
537-
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
538-
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
539-
const asset::SBufferBinding<const IGPUBuffer>& indirectBinding);
534+
bool IGPUCommandBuffer::traceRaysIndirect(const asset::SBufferBinding<const IGPUBuffer>& indirectBinding);
540535

541536
//! Secondary CommandBuffer execute
542537
bool executeCommands(const uint32_t count, IGPUCommandBuffer* const* const cmdbufs);
@@ -690,10 +685,6 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
690685
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
691686
uint32_t width, uint32_t height, uint32_t depth) = 0;
692687
virtual bool IGPUCommandBuffer::traceRaysIndirect_impl(
693-
const asset::SBufferRange<const IGPUBuffer>& raygenGroupRange,
694-
const asset::SBufferRange<const IGPUBuffer>& missGroupsRange, uint32_t missGroupStride,
695-
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
696-
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
697688
const asset::SBufferBinding<const IGPUBuffer>& indirectBinding) = 0;
698689

699690
virtual bool executeCommands_impl(const uint32_t count, IGPUCommandBuffer* const* const cmdbufs) = 0;

include/nbl/video/IGPUCommandPool.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -851,23 +851,10 @@ class IGPUCommandPool::CTraceRaysIndirectCmd final : public IFixedSizeCommand<CT
851851
{
852852
public:
853853
CTraceRaysIndirectCmd(
854-
core::smart_refctd_ptr<const IGPUBuffer>&& raygenGroupBuffer,
855-
core::smart_refctd_ptr<const IGPUBuffer>&& hitGroupsBuffer,
856-
core::smart_refctd_ptr<const IGPUBuffer>&& missGroupsBuffer,
857-
core::smart_refctd_ptr<const IGPUBuffer>&& callableGroupsBuffer,
858854
core::smart_refctd_ptr<const IGPUBuffer>&& bindingBuffer) :
859-
m_raygenGroupBuffer(raygenGroupBuffer),
860-
m_hitGroupsBuffer(hitGroupsBuffer),
861-
m_missGroupsBuffer(missGroupsBuffer),
862-
m_callableGroupsBuffer(callableGroupsBuffer),
863855
m_bindingBuffer(bindingBuffer) {}
864-
865856

866857
private:
867-
core::smart_refctd_ptr<const IGPUBuffer> m_raygenGroupBuffer;
868-
core::smart_refctd_ptr<const IGPUBuffer> m_hitGroupsBuffer;
869-
core::smart_refctd_ptr<const IGPUBuffer> m_missGroupsBuffer;
870-
core::smart_refctd_ptr<const IGPUBuffer> m_callableGroupsBuffer;
871858
core::smart_refctd_ptr<const IGPUBuffer> m_bindingBuffer;
872859
};
873860

src/nbl/video/CVulkanCommandBuffer.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -844,24 +844,9 @@ bool CVulkanCommandBuffer::traceRays_impl(
844844
return true;
845845
}
846846

847-
bool CVulkanCommandBuffer::traceRaysIndirect_impl(
848-
const asset::SBufferRange<const IGPUBuffer>& raygenGroupRange,
849-
const asset::SBufferRange<const IGPUBuffer>& missGroupsRange, uint32_t missGroupStride,
850-
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
851-
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
852-
const asset::SBufferBinding<const IGPUBuffer>& indirectBinding)
847+
bool CVulkanCommandBuffer::traceRaysIndirect_impl(const asset::SBufferBinding<const IGPUBuffer>& indirectBinding)
853848
{
854-
const auto vk_raygenGroupRegion = getVkStridedDeviceAddressRegion(raygenGroupRange, raygenGroupRange.size);
855-
const auto vk_missGroupsRegion = getVkStridedDeviceAddressRegion(missGroupsRange, missGroupStride);
856-
const auto vk_hitGroupsRegion = getVkStridedDeviceAddressRegion(hitGroupsRange, hitGroupStride);
857-
const auto vk_callableGroupsRegion = getVkStridedDeviceAddressRegion(callableGroupsRange, callableGroupStride);
858-
859-
getFunctionTable().vkCmdTraceRaysIndirectKHR(m_cmdbuf,
860-
&vk_raygenGroupRegion,
861-
&vk_missGroupsRegion,
862-
&vk_hitGroupsRegion,
863-
&vk_callableGroupsRegion,
864-
indirectBinding.buffer->getDeviceAddress() + indirectBinding.offset);
849+
getFunctionTable().vkCmdTraceRaysIndirect2KHR(m_cmdbuf, indirectBinding.buffer->getDeviceAddress() + indirectBinding.offset);
865850
return true;
866851
}
867852
bool CVulkanCommandBuffer::executeCommands_impl(const uint32_t count, IGPUCommandBuffer* const* const cmdbufs)

src/nbl/video/CVulkanCommandBuffer.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,7 @@ class CVulkanCommandBuffer final : public IGPUCommandBuffer
232232
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
233233
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
234234
uint32_t width, uint32_t height, uint32_t depth) override;
235-
bool traceRaysIndirect_impl(
236-
const asset::SBufferRange<const IGPUBuffer>& raygenGroupRange,
237-
const asset::SBufferRange<const IGPUBuffer>& missGroupsRange, uint32_t missGroupStride,
238-
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
239-
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
240-
const asset::SBufferBinding<const IGPUBuffer>& indirectBinding) override;
235+
bool traceRaysIndirect_impl(const asset::SBufferBinding<const IGPUBuffer>& indirectBinding) override;
241236

242237
bool executeCommands_impl(const uint32_t count, IGPUCommandBuffer* const* const cmdbufs) override;
243238

src/nbl/video/IGPUCommandBuffer.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define NBL_LOG_FUNCTION m_logger.log
66
#include "nbl/logging_macros.h"
77

8+
#include "nbl/builtin/hlsl/indirect_commands.hlsl"
9+
810
namespace nbl::video
911
{
1012

@@ -992,6 +994,11 @@ bool IGPUCommandBuffer::bindRayTracingPipeline(const IGPURayTracingPipeline* con
992994
return false;
993995
}
994996

997+
if (!pipeline->getCachedCreationParams().dynamicStackSize)
998+
{
999+
m_haveRtPipelineStackSize = false;
1000+
}
1001+
9951002
m_boundRayTracingPipeline = pipeline;
9961003

9971004
m_noCommands = false;
@@ -1892,6 +1899,10 @@ bool IGPUCommandBuffer::setRayTracingPipelineStackSize(uint32_t pipelineStackSiz
18921899
{
18931900
if (!checkStateBeforeRecording(queue_flags_t::COMPUTE_BIT,RENDERPASS_SCOPE::OUTSIDE))
18941901
return false;
1902+
if (m_boundRayTracingPipeline != nullptr && m_boundRayTracingPipeline->getCachedCreationParams().dynamicStackSize)
1903+
{
1904+
NBL_LOG_ERROR("Cannot set dynamic state when state is not mark as dynamic on bound pipeline!");
1905+
}
18951906
m_haveRtPipelineStackSize = true;
18961907
return setRayTracingPipelineStackSize_impl(pipelineStackSize);
18971908
}
@@ -1967,12 +1978,7 @@ bool IGPUCommandBuffer::traceRays(
19671978
width, height, depth);
19681979
}
19691980

1970-
bool IGPUCommandBuffer::traceRaysIndirect(
1971-
const asset::SBufferRange<const IGPUBuffer>& raygenGroupRange,
1972-
const asset::SBufferRange<const IGPUBuffer>& missGroupsRange, uint32_t missGroupStride,
1973-
const asset::SBufferRange<const IGPUBuffer>& hitGroupsRange, uint32_t hitGroupStride,
1974-
const asset::SBufferRange<const IGPUBuffer>& callableGroupsRange, uint32_t callableGroupStride,
1975-
const asset::SBufferBinding<const IGPUBuffer>& indirectBinding)
1981+
bool IGPUCommandBuffer::traceRaysIndirect(const asset::SBufferBinding<const IGPUBuffer>& indirectBinding)
19761982
{
19771983
if (!checkStateBeforeRecording(queue_flags_t::COMPUTE_BIT,RENDERPASS_SCOPE::OUTSIDE))
19781984
return false;
@@ -1982,15 +1988,16 @@ bool IGPUCommandBuffer::traceRaysIndirect(
19821988
NBL_LOG_ERROR("invalid bound pipeline for traceRays command!");
19831989
return false;
19841990
}
1985-
const auto flags = m_boundRayTracingPipeline->getCreationFlags();
19861991

1987-
if (invalidShaderGroups(raygenGroupRange,
1988-
missGroupsRange, missGroupStride,
1989-
hitGroupsRange, hitGroupStride,
1990-
callableGroupsRange, callableGroupStride,
1991-
flags))
1992+
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysIndirectKHR.html#VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03634
1993+
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysIndirectKHR.html#VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03633
1994+
if (invalidBufferBinding(indirectBinding, 4u,IGPUBuffer::EUF_INDIRECT_BUFFER_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT))
1995+
return false;
1996+
1997+
https://docs.vulkan.org/spec/latest/chapters/raytracing.html#VUID-vkCmdTraceRaysIndirect2KHR-indirectDeviceAddress-03633
1998+
if (indirectBinding.buffer->getSize() - indirectBinding.offset <= sizeof(hlsl::TraceRaysIndirectCommand_t))
19921999
{
1993-
NBL_LOG_ERROR("invalid shader groups for traceRays command!");
2000+
NBL_LOG_ERROR("buffer size - offset must be at least the size of TraceRaysIndirectCommand_t!");
19942001
return false;
19952002
}
19962003

@@ -2002,29 +2009,15 @@ bool IGPUCommandBuffer::traceRaysIndirect(
20022009
}
20032010

20042011
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CTraceRaysIndirectCmd>(m_commandList,
2005-
core::smart_refctd_ptr<const IGPUBuffer>(raygenGroupRange.buffer),
2006-
core::smart_refctd_ptr<const IGPUBuffer>(missGroupsRange.buffer),
2007-
core::smart_refctd_ptr<const IGPUBuffer>(hitGroupsRange.buffer),
2008-
core::smart_refctd_ptr<const IGPUBuffer>(callableGroupsRange.buffer),
20092012
core::smart_refctd_ptr<const IGPUBuffer>(indirectBinding.buffer)))
20102013
{
20112014
NBL_LOG_ERROR("out of host memory!");
20122015
return false;
20132016
}
20142017

2015-
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysIndirectKHR.html#VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03634
2016-
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysIndirectKHR.html#VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03633
2017-
if (invalidBufferBinding(indirectBinding, 4u,IGPUBuffer::EUF_INDIRECT_BUFFER_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT))
2018-
return false;
2019-
20202018
m_noCommands = false;
20212019

2022-
return traceRaysIndirect_impl(
2023-
raygenGroupRange,
2024-
missGroupsRange, missGroupStride,
2025-
hitGroupsRange, hitGroupStride,
2026-
callableGroupsRange, callableGroupStride,
2027-
indirectBinding);
2020+
return traceRaysIndirect_impl(indirectBinding);
20282021
}
20292022

20302023
bool IGPUCommandBuffer::executeCommands(const uint32_t count, IGPUCommandBuffer* const* const cmdbufs)

0 commit comments

Comments
 (0)