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

Portable Acceleration Structures #1955

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from

Conversation

fabian-lunarg
Copy link
Contributor

@fabian-lunarg fabian-lunarg commented Jan 14, 2025

worked mostly on decode::VulkanAddressReplacer,
finally enabling portable replay of raytracing pipelines, when using RebindAllocator (-m rebind).

  • work on Acceleration Structures (AS):
    -> tracking, meta-commands, copies, query-pool handling and rebuild
    -> rebuild AS from original input-buffers when trimming.
    -> check AS- and scratch-buffer sizes, replace resources with shadow objects where required

belongs to #1526

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344454.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5784 running.

@fabian-lunarg fabian-lunarg force-pushed the fabian_portable_acceleration_structures branch from 154df0e to c08661a Compare January 14, 2025 09:38
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344470.

@fabian-lunarg fabian-lunarg force-pushed the fabian_portable_acceleration_structures branch from c08661a to c810c23 Compare January 14, 2025 09:42
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344472.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5785 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5785 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344525.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5787 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5787 failed.

@fabian-lunarg fabian-lunarg force-pushed the fabian_portable_acceleration_structures branch from c810c23 to 62d9748 Compare January 14, 2025 13:05
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344604.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5789 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 344693.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5790 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5790 failed.

framework/decode/vulkan_address_replacer.h Show resolved Hide resolved
framework/decode/vulkan_address_replacer.h Outdated Show resolved Hide resolved
framework/decode/vulkan_address_replacer.cpp Outdated Show resolved Hide resolved
framework/decode/vulkan_address_replacer.cpp Outdated Show resolved Hide resolved
else
{
GFXRECON_LOG_INFO_ONCE(
"VulkanAddressReplacer::ProcessCmdTraceRays: missing buffer_info->replay_address, remap failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you specify the function because this macro is within a lambda, therefore __FUNCTION__ has weird value? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we might not need the log-error there at all. was mostly for debugging, also added a return value to check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

purged the log-info

framework/decode/vulkan_address_replacer.cpp Show resolved Hide resolved
bool VulkanAddressReplacer::init_pipeline()
{
if (pipeline_sbt_ != VK_NULL_HANDLE)
if (_pipeline_sbt != VK_NULL_HANDLE)
{
// assume already initialized
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I call these kinds of functions ensure_*. :)

framework/decode/vulkan_device_address_tracker.cpp Outdated Show resolved Hide resolved
framework/decode/vulkan_device_address_tracker.cpp Outdated Show resolved Hide resolved
@@ -249,7 +249,13 @@ VkResult VulkanRebindAllocator::CreateBuffer(const VkBufferCreateInfo* create

if ((create_info != nullptr) && (buffer != nullptr) && (allocator_data != nullptr))
{
result = functions_.create_buffer(device_, create_info, nullptr, buffer);
auto aligned_size = [](uint32_t size, uint32_t alignment) -> uint32_t {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a similar function in vulkan_address_replacer.cpp. How about moving this in a common header under the graphics namespace?

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 chose util/alignment_utils.h and consolidated the alignment and divup helpers there

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 345010.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5796 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5796 failed.

VkWriteDescriptorSet* in_pDescriptorWrites = p_descriptor_writes->GetPointer();
VkCopyDescriptorSet* in_pDescriptorCopies = p_pescriptor_copies->GetPointer();

{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check that one or more of the extensions are enabled before we do this? I know right now it will only be for Ray Tracing, and eventually things like device generated commands, but should we not do this work if we don't have to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, will check if we can avoid any unnecessary work

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 found we can guard the loop like this:

// bail out if we're not tracking any shadow acceleration-structures
if (shadow_as_map_.empty())
{
    return;
}

this will avoid any iteration when the class is not actively replacing stuff

GFXRECON_ASSERT(allocator != nullptr);

if (allocator->SupportsOpaqueDeviceAddresses() || !loading_trim_state_)
if (loading_trim_state_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only if loading trim state in all 3 of the following functions?

Copy link
Contributor Author

@fabian-lunarg fabian-lunarg Jan 15, 2025

Choose a reason for hiding this comment

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

those 3 meta-commands all issue calls to restore state around acceleration-structures. rebuild, (compaction-)copies and querying the compacted size. that's only required for loading the trim state (afterwards the flow is through the Override*Acceleration*() overrides)

@@ -634,7 +611,7 @@ void VulkanDecoderBase::DispatchVulkanAccelerationStructuresWritePropertiesMetaC

std::size_t bytes_read = ValueDecoder::DecodeHandleIdValue(parameter_buffer, sizeof(format::HandleId), &device_id);
bytes_read += ValueDecoder::DecodeEnumValue(parameter_buffer + bytes_read, sizeof(VkQueryType), &query_type);
bytes_read += ValueDecoder::DecodeHandleIdValue(
ValueDecoder::DecodeHandleIdValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not update the bytes read here? This seems wrong.

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 can add it back, it's just nobody will check bytes_read after that and clang-tidy remarked something there. will check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang-tidy's comment was: "The value is never used"

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... Ok. I won't push for it, but I just worry about something being added after this being incorrect. Maybe just add (void)bytes_read; line to make clang-tidy happy?

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 share your concern. if anyone appends stuff here I'd rather leave it and ignore clang-tidy (I think it's great, just not here) -> rolled back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (omitted_pipeline_cache_data_)
// NOTE: as of early 2025, rayTracingPipelineShaderGroupHandleCaptureReplay is not widely supported.
// e.g. newest nvidia desktop-drivers do not support this feature
if (device_info->property_feature_info.feature_rayTracingPipelineShaderGroupHandleCaptureReplay)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to make sure this was enabled at vkCreateDevice time? Or does the device_info already do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

device_info has it all. the feature might have been available during capture, but still missing during replay (e.g. seeing that for rayTracingPipelineShaderGroupHandleCaptureReplay between nvidia(no) <-> radv(yes))

for replay, we do checks in gfxrecon::graphics::VulkanDeviceUtil figuring out if to enable the feature or not.
the information for replay is pulled from VkPhysicalDeviceRayTracingPipelineFeaturesKHR via a vkGetPhysicalDeviceFeatures2 call. active when available both during capture & replay.
some of that logic needed to be touched in this PR (and it might not be the end of story yet).

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 345554.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5801 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5801 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 346759.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5816 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5816 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 346827.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5818 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5818 passed.

@fabian-lunarg fabian-lunarg force-pushed the fabian_portable_acceleration_structures branch from 8fd261b to ec2788e Compare January 16, 2025 11:26
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 346892.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5819 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5819 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 347107.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants