Skip to content

[Migrated] Incorrect index validation #75

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

Open
rust-gpu-bot opened this issue Nov 13, 2024 · 3 comments
Open

[Migrated] Incorrect index validation #75

rust-gpu-bot opened this issue Nov 13, 2024 · 3 comments

Comments

@rust-gpu-bot
Copy link

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1093

Originally creatd by atynagano on 2023-09-21T11:51:47Z


https://github.com/EmbarkStudios/rust-gpu/blob/e87c324bfda6bea144fe2635586281c4ef144f0d/crates/spirv-std/src/byte_addressable_buffer.rs#L73-L78

if byte_index + mem::size_of::<T>() as u32 > (mem::size_of::<u32> * self.data.len()) as u32

Isn't the right-hand side multiplied by 4 because data is &[u32]?

@rust-gpu-bot
Copy link
Author

Comment from Patryk27 on 2023-09-21T17:09:22Z


ByteAddressableBuffer requires for the data to be aligned to 4 bytes, so the current condition is fine IMO; the naming could be better (word_index: u32), but the comment above explains it's inherited from HLSL.

Note that buffer_load_intrinsic() ends up doing 4 * byte_index:

https://github.com/EmbarkStudios/rust-gpu/blob/e87c324bfda6bea144fe2635586281c4ef144f0d/crates/rustc_codegen_spirv/src/builder/byte_addressable_buffer.rs#L202

@rust-gpu-bot
Copy link
Author

Comment from atynagano on 2023-09-22T00:15:22Z


So does the left side size_of<T> needs to be divided by 4? Or does size_of returns dword size?

@rust-gpu-bot
Copy link
Author

Comment from Patryk27 on 2023-09-22T05:23:20Z


Oh, yeah - I think it should say mem::size_of::<T>() / 4 then 🤔

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

No branches or pull requests

1 participant