Skip to content

Use shared transfer buffers#951

Merged
paulthomson merged 6 commits intogoogle:mainfrom
ilkkasaa:shared_buffers
Jun 18, 2021
Merged

Use shared transfer buffers#951
paulthomson merged 6 commits intogoogle:mainfrom
ilkkasaa:shared_buffers

Conversation

@ilkkasaa
Copy link
Contributor

Descriptors were using separate transfer buffers when they were
using same buffer. This prevented e.g. using the same buffer in
multiple storage buffer bindings.

This commit moves the transfer buffer/image ownership from descriptors to
pipeline to allow descriptors to share the transfer buffers. Now the
descriptors can have the same buffer binding even if the descriptors
are of different types e.g. storage/uniform/storage_texel_buffer etc.

Fixes #950

ilkkasaa added 3 commits May 19, 2021 10:38
Descriptors were using separate transfer buffers when they were
using same buffer. This prevented e.g. using the same buffer in
multiple storage buffer bindings.

This commit moves the transfer buffer/image ownership from descriptors to
pipeline to allow descriptors to share the transfer buffers. Now the
descriptors can have the same buffer binding even if the descriptors
are of different types e.g. storage/uniform/storage_texel_buffer etc.

Fixes google#950
return Result("Unexpected buffer type when deciding usage flags");
auto& transfer_buffer = transfer_resources[amber_buffer];
// Unset transfer buffer's read only property if needed.
if (!IsReadOnly() && transfer_resources[amber_buffer]->IsReadOnly()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the SetReadOnly do something else than just set a member variable to true or false? If not, could simply do SetReadOnly(IsReadOnly()) outside these blocks.

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 simplified this a little bit. The transfer buffer's readOnly property should never be changed from false to true, because some descriptors may need only read access, but some other may need write access too.

}
}

// Initialize transfer buffers. Transfer images are already initialized in
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to initialize them in different places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transfer buffers needed to be initialized in later phase, because the buffer usage flags could change while looping through the descriptors in the loop above. Both transfer buffers and images are now initialized here to make the code more readable.

Simplify transfer buffer's readOnly property logic.
Copy link
Contributor

@asuonpaa asuonpaa left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Collaborator

@paulthomson paulthomson left a comment

Choose a reason for hiding this comment

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

Nice! One comment. And please rebase and/or merge from main.


Result Initialize(const VkBufferUsageFlags usage);
TransferBuffer* AsTransferBuffer() override { return this; }
void AddUsageFlags(VkBufferUsageFlags flags) { usage_flags_ |= flags; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we assert that buffer_ is VK_NULL_HANDLE? I.e. you cannot add usage flags after Initialize?

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. I'll add that

ilkkasaa and others added 2 commits June 17, 2021 16:05
Verify that the transfer buffer is not initialized when adding buffer usage flags.
@paulthomson paulthomson merged commit 8c3bfef into google:main Jun 18, 2021
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.

Add ability to use same buffer in multiple bindings

3 participants