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

Add additional defensive code within vkUpdateDescriptorSets(). #2293

Merged
merged 1 commit into from
Jul 28, 2024

Conversation

billhollings
Copy link
Contributor

@billhollings billhollings commented Jul 26, 2024

  • MVKDescriptorSet::write(): Revert to verifying each descriptor has the same type as its descriptor binding, to guard against an app mistakenly running off the end of an array of descriptors.

  • MVKDescriptorSet::hasMetalArgumentBuffer() ensure _layout is available.

  • MVKDescriptorSet::write() & read(): Refactor descriptor iteration to clarify loop indexing, and to check array limits to guard against an app mistakenly running off the end of an array of descriptors.

Copy link
Collaborator

@cdavis5e cdavis5e left a comment

Choose a reason for hiding this comment

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

This doesn't seem to have actually helped much with #2283... I'm worried that this could negatively affect the performance of MoltenVK, especially with large descriptor sets. If the bug is in the client, this may not even be necessary.

- MVKDescriptorSet::write() & read(): Refactor descriptor iteration
  to clarify loop indexing, and to check array limits to guard against
  an app mistakenly running off the end of an array of descriptors.
@billhollings
Copy link
Contributor Author

This doesn't seem to have actually helped much with #2283... I'm worried that this could negatively affect the performance of MoltenVK, especially with large descriptor sets. If the bug is in the client, this may not even be necessary.

Thanks for pointing that out. Yeah, I agree. I've removed the existing code from here.

I do think there is still some validity in guarding against an app mistakenly running off the end of a descriptor binding array, and into descriptors of the wrong type, during a descriptor set update. So I've modified both write and read to check array limits before looping, which will accomplish the same thing the descriptor type checking, without the cost of doing it on each array element.

In doing so, I also refactored write() and read() to clarify the logic, and the various indexes being iterated.

@billhollings billhollings merged commit 6c60f4e into KhronosGroup:main Jul 28, 2024
6 checks passed
@billhollings billhollings deleted the updt-desc-robustness branch July 28, 2024 12:41
@billhollings
Copy link
Contributor Author

I do think there is still some validity in guarding against an app mistakenly running off the end of a descriptor binding array, and into descriptors of the wrong type, during a descriptor set update. So I've modified both write and read to check array limits before looping, which will accomplish the same thing the descriptor type checking, without the cost of doing it on each array element.

Oops. This PR went too far. Vulkan requires the ability to write and copy beyond the size of a descriptor binding and into subsequent bindings of the same type, including for inline buffer bindings. PR #2303 reverts this and adds the same capability for inline buffer bindings.

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.

2 participants