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 raytracing: Add VulkanAddressReplacer #1879

Merged

Conversation

fabian-lunarg
Copy link
Contributor

@fabian-lunarg fabian-lunarg commented Nov 21, 2024

  • Add decode::VulkanAddressReplacer class
  • Adds (compute-)shader-code used internally by VulkanAddressReplacer
  • used to sanitize inputs to vkCmdTraceRays | vkCmdBuildAccelerationStructuresKHR
  • injected calls are marked as such, using decode::Begin/EndInjectedCommands
  • rebind-allocator: use VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT

this PR solves issues around portable replay wrt. shader-binding-table (SBT) handling.
it only partially solves remaining issues around VkAccelerationStructure, which will be addressed in a follow-up

belongs to #1526

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307164.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307178.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5356 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307197.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5357 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307213.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307215.

@@ -24,7 +24,7 @@ android {
}
externalNativeBuild {
cmake {
cppFlags "-fexceptions", "-std=c++14", "-Wno-nullability-completeness"
cppFlags "-fexceptions", "-std=c++17", "-Wno-nullability-completeness"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fyi @bradgrantham - in this PR, I'm adjusting our android c++ dialect to c++17, matching the other configs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for doing this. I think it's important for us to try to maintain consistency between the two. Especially as we add C++17 features into GFXR.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5359 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5359 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307286.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5361 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307306.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5362 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307342.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5363 running.

framework/decode/vulkan_device_address_tracker.h Outdated Show resolved Hide resolved
framework/decode/vulkan_address_replacer.cpp Show resolved Hide resolved
framework/decode/vulkan_address_replacer.cpp Outdated Show resolved Hide resolved
android/framework/decode/CMakeLists.txt Show resolved Hide resolved
framework/decode/vulkan_replay_consumer_base.cpp Outdated 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
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307367.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5364 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5364 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 307821.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5367 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5367 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 308221.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5370 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5370 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 315511.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5486 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5486 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 315569.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5487 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5487 passed.

Copy link
Contributor

@MarkY-LunarG MarkY-LunarG left a comment

Choose a reason for hiding this comment

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

Just mostly a few cleanups and questions.

@@ -24,7 +24,7 @@ android {
}
externalNativeBuild {
cmake {
cppFlags "-fexceptions", "-std=c++14", "-Wno-nullability-completeness"
cppFlags "-fexceptions", "-std=c++17", "-Wno-nullability-completeness"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for doing this. I think it's important for us to try to maintain consistency between the two. Especially as we add C++17 features into GFXR.

return memory_type_index;
}

//! 16 bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was me, counting bytes during development. I'll remove 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.

done

framework/decode/vulkan_address_replacer.cpp Show resolved Hide resolved
// NOTE: we expect this map to be populated here, but not for older captures (before #1844) using trimming.
if (group_handle_map.empty())
{
// the capture appears to be older and is missing information we require here -> bail out
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe log an INFO_ONCE level message here? (Side note, I don't even know if we have an INFO_ONCE, if not, just use INFO).

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'll check. and yes, was also thinking back/forth to use warning or just INFO

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 do have a GFXRECON_LOG_INFO_ONCE, using that

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

}
}

// TODO: testing only -> remove when closing issue #1526
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Thanks for remembering to associate a TODO with a PR.

device_table_->CmdBindPipeline(command_buffer_info->handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_bda_);

// NOTE: using push-constants here requires us to re-establish the previous data, if any
device_table_->CmdPushConstants(command_buffer_info->handle,
Copy link
Contributor

Choose a reason for hiding this comment

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

Be careful of push constants size. Some HW (Arm?) may have no support or very limited support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

glad you're asking :)

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 was also worried about this and basically chose this all-in approach with using buffer-device-addresses for everything (input/output addresses, hashmap-storage).

}
}

void VulkanAddressReplacer::init_pipeline()
Copy link
Contributor

Choose a reason for hiding this comment

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

For each of these functions, you might want to put a note that they should only be used in a "mark injected" section. This just makes sure others going forward continue to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively, instead of putting notes to the private methods,
maybe document this ("all vulkan-commands will be wrapped with markers")
as general contract or "expected behavior" inside a class doc-string?

Copy link
Contributor Author

@fabian-lunarg fabian-lunarg Dec 3, 2024

Choose a reason for hiding this comment

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

I wrote a class-doc saying:

Important note: all internal Vulkan-API calls performed by this class are expected to be wrapped by calls to:
 * - decode::BeginInjectedCommands() / decode::EndInjectedCommands()


if (pipeline_bda_ == VK_NULL_HANDLE)
{
init_pipeline();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we hit a fatal error inside this, we should abandon and jump out.

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. we check, print an error and bail out in case this goes wrong

* @param callable_sbt ray-callable sbt
* @param address_tracker const reference to a VulkanDeviceAddressTracker, used for mapping device-addresses
* @param group_handle_map a map from capture- to replay-time group-handles
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Great comment

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)

// g_replacer_sbt_comp: original GLSL source
Copy link
Contributor

Choose a reason for hiding this comment

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

I have to admit, at first I'm was "what is this?", but then I saw the binary blobs below. I like this way of doing 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.

I copied this approach from Dustin :)

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 315750.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5490 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5490 passed.

@fabian-lunarg fabian-lunarg merged commit 342de43 into LunarG:dev Dec 3, 2024
9 checks passed
@fabian-lunarg fabian-lunarg deleted the fabian_vulkan_address_replacer branch December 3, 2024 17:10
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