-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Make PersistentGpuBufferable a safe trait #12744
Make PersistentGpuBufferable a safe trait #12744
Conversation
Note: the current implementations for |
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.
Encase can be slow, and I highly doubt anyone is using this feature on big-endian systems. Unless there's a way to do it without overhead, or we put it behind a conditional config, I'd rather just do an assertion that the system is little-endian or something.
fn size_in_bytes(&self) -> usize; | ||
|
||
/// Convert `self` + `metadata` into bytes (little-endian), and write to the provided buffer slice. | ||
/// Any bytes not written to in the slice will be zeroed out when uploaded to the GPU. |
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.
Theoretically, it would be nice for wgpu to provide a way to skip the zeroing, so this may change in the future if they add that. We can leave it for now though :)
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 asked about this in the wgpu matrix chat and it seems feasible, though it may need to be exposed via &mut [MaybeUninit<u8>]
, which would only require unsafe inside the implementation instead of as a part of the trait itself.
(Didn't mean to approve, meant to request changes) |
Objective
Fixes #12727. All parts that
PersistentGpuBuffer
interact with should be 100% safe both on the CPU and the GPU:Queue::write_buffer_with
zeroes out the slice being written to and when uploading to the GPU, and all slice writes are bounds checked on the CPU side.Solution
Make
PersistentGpuBufferable
a safe trait. Enforce it's correct implementation via assertions. Re-enableforbid(unsafe_code)
onbevy_pbr
.