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

Rework vulkan optimizer #1658

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

Conversation

bartosz-muszarski-arm
Copy link
Contributor

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:

  • first pass to generate optimization data
  • 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.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 231913.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4572 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4572 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 243984.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4695 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4695 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 244265.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4699 running.

@bartosz-muszarski-arm bartosz-muszarski-arm marked this pull request as ready for review August 27, 2024 15:22
@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 4699 passed.

@fabian-lunarg fabian-lunarg self-assigned this Sep 9, 2024
@bradgrantham-lunarg bradgrantham-lunarg added P2 A high-priority code maintenance issue or a functional problem that is recoverable or not a crash. optimize Issue with optimize vulkan labels Oct 10, 2024
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 341189.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5747 running.

@ci-tester-lunarg
Copy link

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
Copy link
Contributor

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

Copy link
Contributor Author

@bartosz-muszarski-arm bartosz-muszarski-arm Jan 23, 2025

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.

Copy link
Contributor

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

Copy link
Contributor

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'

@fabian-lunarg
Copy link
Contributor

fabian-lunarg commented Jan 16, 2025

I'm currently investigating the failed CI-run from last week. it looks many tests related to dump_resources feature fail, due to different json out. this might require adjusting our ground-truth, let me come back for this
was a red herring

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 350987.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5879 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5879 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 352651.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5894 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5894 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 359365.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5964 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5964 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 359680.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5966 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5966 passed.

bartosz-muszarski-arm and others added 4 commits February 5, 2025 11:25
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
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 365144.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6014 running.

@ci-tester-lunarg
Copy link

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
Copy link
Contributor

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-#

Copy link
Contributor Author

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>();
Copy link
Contributor

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?

Copy link
Contributor Author

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));
Copy link
Contributor

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
Copy link
Contributor

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) :
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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_

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimize Issue with optimize P2 A high-priority code maintenance issue or a functional problem that is recoverable or not a crash. vulkan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants