Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RT pipeline capture/replay flags and features #3499

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,19 @@ bool WrappedVulkan::Serialise_vkCreateDevice(SerialiserType &ser, VkPhysicalDevi
VkPhysicalDeviceProperties2 availPropsBase = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
availPropsBase.pNext = &rayProps;
ObjDisp(physicalDevice)->GetPhysicalDeviceProperties2(Unwrap(physicalDevice), &availPropsBase);

if(ext->rayTracingPipeline && !avail.rayTracingPipelineShaderGroupHandleCaptureReplay)
{
SET_ERROR_RESULT(m_FailedReplayResult, ResultCode::APIHardwareUnsupported,
"Capture requires rayTracingPipeline support, which is available, but "
"rayTracingPipelineShaderGroupHandleCaptureReplay support is not "
"available which is required to replay\n"
"\n%s",
GetPhysDeviceCompatString(false, false).c_str());
return false;
}
if(ext->rayTracingPipeline)
ext->rayTracingPipelineShaderGroupHandleCaptureReplay = VK_TRUE;
}
END_PHYS_EXT_CHECK();
}
Expand Down
32 changes: 23 additions & 9 deletions renderdoc/driver/vulkan/wrappers/vk_shader_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,14 +1464,29 @@ VkResult WrappedVulkan::vkCreateRayTracingPipelinesKHR(
{
VkResult ret;

// to be extra sure just in case the driver doesn't, set pipelines to VK_NULL_HANDLE first.
VkRayTracingPipelineCreateInfoKHR *unwrappedCreateInfos =
UnwrapInfos(m_State, pCreateInfos, createInfoCount);

for(uint32_t i = 0; i < createInfoCount; i++)
{
// to be extra sure just in case the driver doesn't, set pipelines to VK_NULL_HANDLE first.
pPipelines[i] = VK_NULL_HANDLE;

// Patch in capture/replay creation flags
VkPipelineCreateFlags2CreateInfoKHR *flagsInfo =
(VkPipelineCreateFlags2CreateInfoKHR *)FindNextStruct(
&unwrappedCreateInfos[i], VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR);
if(flagsInfo)
flagsInfo->flags |= VK_PIPELINE_CREATE_2_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR;
else
unwrappedCreateInfos[i].flags |=
VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR;
}

// deferred operations are currently not wrapped
SERIALISE_TIME_CALL(ret = ObjDisp(device)->CreateRayTracingPipelinesKHR(
Unwrap(device), VK_NULL_HANDLE, Unwrap(pipelineCache), createInfoCount,
UnwrapInfos(m_State, pCreateInfos, createInfoCount), NULL, pPipelines));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically below here where we already have modifiedCreateInfo you'd want to apply a similar kind of patching to add the necessary flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started on this, but it's actually a bit more complicated than the existing modifiedCreateInfo patching. We need to patch any VkPipelineCreateFlags2CreateInfoKHR if it exists, which by extension means we need to patch the entire pNext chain (or at least, all elements of it up until VkPipelineCreateFlags2CreateInfoKHR). I'm not sure how to go about that properly?

For what it's worth, it seems like the current code is buggy in that regard since the derivative pipeline check also only considers the flags from the pipeline create info itself, not of any potential VkPipelineCreateFlags2CreateInfoKHR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually make a very good point about the derivative check. It made me go to check - that flags2 struct is added in KHR_maintenance5 which RenderDoc does not currently support, the existing code was copied from pre-existing handling on normal pipelines.

So none of this handling is needed yet, and the code is not currently buggy (just lacking support). The new code you've added is fine to sttay as it's illegal for any application to do pass the struct in anyway, and it will be correct for the future.

Unfortunately the next-chain pattern in general is extremely annoying when it comes to patching... I have helpers for copying a whole chain to patch it but it gets messy quickly.

unwrappedCreateInfos, NULL, pPipelines));

if(ret == VK_SUCCESS || ret == VK_PIPELINE_COMPILE_REQUIRED)
{
Expand All @@ -1491,25 +1506,24 @@ VkResult WrappedVulkan::vkCreateRayTracingPipelinesKHR(
{
CACHE_THREAD_SERIALISER();

VkRayTracingPipelineCreateInfoKHR modifiedCreateInfo;
const VkRayTracingPipelineCreateInfoKHR *createInfo = &pCreateInfos[i];
VkRayTracingPipelineCreateInfoKHR modifiedCreateInfo = pCreateInfos[i];
modifiedCreateInfo.flags |=
VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR;

if(createInfo->flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT)
if(pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT)
{
// since we serialise one by one, we need to fixup basePipelineIndex
if(createInfo->basePipelineIndex != -1 && createInfo->basePipelineIndex < (int)i)
if(pCreateInfos[i].basePipelineIndex != -1 && pCreateInfos[i].basePipelineIndex < (int)i)
{
modifiedCreateInfo = *createInfo;
modifiedCreateInfo.basePipelineHandle =
pPipelines[modifiedCreateInfo.basePipelineIndex];
modifiedCreateInfo.basePipelineIndex = -1;
createInfo = &modifiedCreateInfo;
}
}

SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCreateRayTracingPipelinesKHR);
Serialise_vkCreateRayTracingPipelinesKHR(ser, device, deferredOperation, pipelineCache, 1,
createInfo, NULL, &pPipelines[i]);
&modifiedCreateInfo, NULL, &pPipelines[i]);

chunk = scope.Get();
}
Expand Down