-
Notifications
You must be signed in to change notification settings - Fork 127
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
Rework vulkan optimizer #1658
base: dev
Are you sure you want to change the base?
Rework vulkan optimizer #1658
Conversation
CI gfxreconstruct build queued with queue ID 231913. |
CI gfxreconstruct build # 4572 running. |
CI gfxreconstruct build # 4572 passed. |
CI gfxreconstruct build queued with queue ID 243984. |
CI gfxreconstruct build # 4695 running. |
CI gfxreconstruct build # 4695 passed. |
CI gfxreconstruct build queued with queue ID 244265. |
CI gfxreconstruct build # 4699 running. |
CI gfxreconstruct build # 4699 passed. |
CI gfxreconstruct build queued with queue ID 341189. |
CI gfxreconstruct build # 5747 running. |
CI gfxreconstruct build # 5747 failed. |
// To test this example you need any trace that performs an acceleration structure copy with | ||
// VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR mode, for example: | ||
// https://github.com/ARM-software/tracetooltests/blob/main/src/vulkan_as_3.cpp | ||
class VulkanExampleModifier : public util::VulkanModifierBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the class called VulkanExampleModifier
?
- meaning it's not used as test-case, but in production code
- it actually claims it 'Adds vkSetDebugUtilsObjectNameEXT calls after relevant vkCreateAccelerationStructureKHR'
I think it should have another name to better express what it is/does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's meant for demonstration only, to showcase how the optimization interface was intended to be used, thus the name. Has no real use other than that, can be removed completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking into moving this class into a test-case. it would serve the purpose to demonstrate usage, but not live in the production-codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then, I see another issue. usage of VulkanExampleModifier
has been hard-coded into 'tools/optimize/main.cpp'
|
CI gfxreconstruct build queued with queue ID 350987. |
CI gfxreconstruct build # 5879 running. |
CI gfxreconstruct build # 5879 failed. |
dfc7788
to
84bf02f
Compare
CI gfxreconstruct build queued with queue ID 352651. |
CI gfxreconstruct build # 5894 running. |
CI gfxreconstruct build # 5894 passed. |
84bf02f
to
814527f
Compare
CI gfxreconstruct build queued with queue ID 359365. |
CI gfxreconstruct build # 5964 running. |
CI gfxreconstruct build # 5964 passed. |
CI gfxreconstruct build queued with queue ID 359680. |
CI gfxreconstruct build # 5966 running. |
CI gfxreconstruct build # 5966 passed. |
Current implementation does not allow to implement different kind of optimizations in a modular and scalable way. This commit established base infrastructure allowing imlementation of modules that can process vulkan calls and apply modifications to them. Gfxrecon-optimize uses 2 pass approach - first pass to generate optimization data and a second pass to generate modified trace. Modifications are performed in predefined order for each call separately. Each modifier is given a pointer to same modifiable parameter buffer, a method to insert new calls before current call and a flag to request removal of current call from trace. Change-Id: Ic1f396d70cd58eb0d416273bf0fec4e7c9c02f58
Change-Id: Ibf8290f90a73aaa7aac0442a16f0bad70bc3e3dc
- add required 'override' statements - tested on macOS14.5, clang-1500.3.9.4
- DRY: break out a shared utility, avoiding code-duplication
be1bd25
to
ef32975
Compare
CI gfxreconstruct build queued with queue ID 365144. |
CI gfxreconstruct build # 6014 running. |
CI gfxreconstruct build # 6014 passed. |
else if ((file_processor.GetCurrentFrameNumber() > 0) && | ||
(file_processor.GetErrorState() == gfxrecon::decode::FileProcessor::kErrorNone)) | ||
|
||
// TODO: resref_consumer should derive from VulkanModifierBase and be handled like other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add a clear condition to the TODO (or remove it). when will it be removed? like a specific date or best a referenced issue/PR-#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove it, this no longer applies
|
||
gfxrecon::decode::FileProcessor file_processor; | ||
if (file_processor.Initialize(input_filename)) | ||
{ | ||
gfxrecon::decode::VulkanDecoder decoder; | ||
gfxrecon::decode::VulkanReferencedResourceConsumer resref_consumer; | ||
auto example_modifier = std::make_unique<gfxrecon::decode::VulkanExampleModifier>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usage of VulkanExampleModifier
is hard-coded here and should not be, since it's a production codebase/tool.
when we remove that addition I do not see a clear way how modifiers can be added.
maybe I'm missing something, but what is the concept here, like e.g. will there be cmd-line parameters to gfxrecon-optimize
to add/select modifiers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this iteration modifiers would be added similarly to this example, hardcoded without optimizer parameters.
There are kinds of modifications we typically need for any vulkan trace - removing unused blocks, unused extensions/features, corrupted blocks at the end of the file - to name a few.
Then we have modifications that user may need - like handling portable raytracing via postprocessing, general device address processing, possibly bindless, etc. - that would need to be parametrized.
Lastly there are very specific modifications that require user input, like remove calls by thread or device id, those will have to be parametrized and handled separately.
I'd like to keep things modular and scalable, have a separate class for every kind of optimization we might need to do in the future. While the user could choose the modifications he needs and their order, I think as this solution scales we'll need to group them instead, creating predefined optimization profile and have the user target that via parameter.
That would be the general idea, but the goal of this PR is to establish a base scalable architecture that we can build on top of in next PRs.
size_t parameter_buffer_size = static_cast<size_t>(block_header.size) - sizeof(call_id); | ||
uint64_t uncompressed_size = 0; | ||
decode::ApiCallInfo call_info{ GetCurrentBlockIndex() }; | ||
bool success = ReadBytes(&call_info.thread_id, sizeof(call_info.thread_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
success
is not checked after reading here
|
||
bool VulkanFileOptimizer::ProcessFunctionCall(const format::BlockHeader& block_header, format::ApiCallId call_id) | ||
{ | ||
// Regular funciton call processing/compression handling - duplicated in multiple places, TODO: extract, reuse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in comment and unclear TODO. either remove or add more information?
std::vector<std::unique_ptr<util::VulkanModifierBase>> modifiers; | ||
}; | ||
|
||
explicit VulkanFileOptimizer(VulkanOptimizationData* optimization_data) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VulkanOptimizationData*
is passed as raw-pointer, which is then stored as member.
better pass by value and move into place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean transfer the ownership of optimization_data inside VulkanFileOptimizer? I don't mind, but also don't see the benefit. The purpose here was to avoid copies that may become costly as the optimization data grows. Caller maintains ownership, consumer gets the input as raw ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::unique_ptr<gfxrecon::VulkanFileOptimizer::VulkanOptimizationData> GetVulkanOptimizationData(...)
returns a unique-pointer.
so yes, I think it would be better to transfer ownership of that instead of using a raw-pointer.
there would be no copy and the benefit would be to avoid a potentially dangling pointer in optimization_data_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning unique ptr here does not generate a copy
Current implementation does not allow to implement different kind of optimizations in a modular and scalable way.
This commit established base infrastructure allowing implementation of modules that can process vulkan calls and apply modifications to them.
Gfxrecon-optimize for vulkan uses 2 pass approach:
Modifications are performed in predefined order for each call separately.
Each modifier is given a pointer to same modifiable parameter buffer, a method to insert new calls before current call and a flag to request removal of current call from trace.