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

Batch resources initialization #2081

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

Conversation

panos-lunarg
Copy link
Contributor

@panos-lunarg panos-lunarg commented Mar 19, 2025

Instead of uploading each resource with a separate queue submission,
batch several resources into a larger staging buffer and upload them
with a single queue submit

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398542.

@panos-lunarg panos-lunarg marked this pull request as draft March 19, 2025 09:46
@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 8085ffa to fba1e95 Compare March 19, 2025 09:48
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398544.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from fba1e95 to b87d9ea Compare March 19, 2025 10:02
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398549.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6367 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6367 failed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from b87d9ea to ff46ca2 Compare March 19, 2025 12:18
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398648.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6368 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6368 failed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from ff46ca2 to 552a3f4 Compare March 19, 2025 13:33
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398739.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6369 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6369 passed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 552a3f4 to dc8a0b3 Compare March 19, 2025 15:26
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 398888.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6370 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6370 passed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from dc8a0b3 to fa940da Compare March 20, 2025 06:09
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 399452.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6375 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6375 passed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from fa940da to 829393e Compare March 20, 2025 13:14
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 399670.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6378 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6378 passed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 829393e to b2a3d6d Compare March 21, 2025 07:29
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 400745.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 404029.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6403 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6403 failed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 404378.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 404378 cancelled.

VkImageLayout final_layout,
uint32_t layer_count,
uint32_t level_count,
VkBufferImageCopy* level_copies)
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this change alters the contract with the caller, I'd prefer to leave this const and then make a local copy with the offset, if that doesn't have a big performance impact. Maybe std::vector<VkBufferImageCopy> offsetted_level_copies(level_copies, level_copies, level_count); around line 322 and then add offset in the loop. Same for the change below to InitializeBuffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a member variable that is cleared and filled again from the passed array to reduce heap allocation costs.

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

Copy link
Contributor

@bradgrantham-lunarg bradgrantham-lunarg Apr 4, 2025

Choose a reason for hiding this comment

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

I recommend clear and then insert the elements into the vector rather than keep resizeing and std::copying it. The storage for vectors is never reduced so a clear and resize should pretty quickly reach steady state on the storage of the vector. The danger with resize and copy is that 1) if someone else modifies this code and doesn't change the resize, the vector could be undersized and the copy could overwrite memory.

Copy link
Contributor Author

@panos-lunarg panos-lunarg Apr 6, 2025

Choose a reason for hiding this comment

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

Right. I was under the impression that resize will shrink the vector's capacity if its current size is larger than the requested, but that's not the case. Your suggestion should work better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be addressed now. I think clear can be skipped and just resize and overwrite over existing entries.

begin_info.flags = 0;
begin_info.pInheritanceInfo = nullptr;

result = device_table_->BeginCommandBuffer(iter->second.command_buffer, &begin_info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a failure fatal here and other places that operate on command buffers in this 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.

What do you mean? In general I tried to do error checking. Have you spotted something I missed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just mean, you're checking the return from BeginCommandBuffer here - if it can return something other than Vk_SUCCESS here, it seems like we should print an error and maybe a fatal error. Unless there's no realistic way it can ever fail. But I can imagine maybe we could get VK_ERROR_OUT_OF_HOST_MEMORY; do you think we should check for errors?

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 general I followed the error checking logic that is applied in the rest of the file. The callers of this function will check the return value and act accordingly which is basically to propagate the error higher.
VulkanResourceInitializer exposes 4 public functions. The user of the class (the vulkan replay consumer) checks the return value and prints an error if there is one.

{
FlushStagingBuffer();
VkResult result = VK_SUCCESS;
for (auto& exec_object : command_exec_objects_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be const and what other additions in this PR can be const?

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

@bradgrantham-lunarg bradgrantham-lunarg removed the request for review from mikes-lunarg March 25, 2025 16:38
@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 3650483 to d4d17df Compare March 26, 2025 08:32
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 404983.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6421 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6421 failed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from d4d17df to 78c60d7 Compare March 26, 2025 15:24
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 405323.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6427 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6427 passed.

@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 78c60d7 to 8bda62d Compare March 27, 2025 06:52
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 406010.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6435 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6435 passed.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 414365.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6559 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6559 passed.

AcquireInitializedStagingBuffer will call LoadData so InitializeImage
does not need to explicitly call it again.
Instead of uploading each resource with a separate queue submission,
batch several resources into a larger staging buffer and upload them
with a single queue submit
@panos-lunarg panos-lunarg force-pushed the batch_resources_initialization branch from 1be2cba to 3a33f75 Compare April 9, 2025 05:05
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 416925.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6580 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 6580 passed.

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