-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix the extended_material example on WebGL2 #18812
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
base: main
Are you sure you want to change the base?
Conversation
#[uniform(100)] | ||
quantize_steps: u32, | ||
quantize_steps: UVec4, |
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.
As evidenced by other parts of the Bevy codebase, we prefer to use this type of pattern to address alignment issues:
bevy/crates/bevy_gizmos/src/lib.rs
Line 506 in 6f3ea06
_padding: bevy_math::Vec3, |
@@ -16,7 +16,8 @@ | |||
#endif | |||
|
|||
struct MyExtendedMaterial { | |||
quantize_steps: u32, | |||
// WebGL2 structs must be 16 byte aligned. We only use the `x` field | |||
quantize_steps: vec4<u32>, |
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.
quantize_steps: vec4<u32>, | |
quantize_steps: u32, | |
#ifdef SIXTEEN_BYTE_ALIGNMENT | |
_padding: vec3<u32>, | |
#endif |
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.
Some maintainers mentioned we should try to stay away from conditional compilation, if this is not the pattern we should be following anymore we should update the other examples to the simpler version too, or create a backlog task in the issues.
I'm fine with both approaches (the proposed one and the first alternative). And even the mix of both (adding a separate padding field with no conditional compilation). As far as the examples go, my personal vote would go to a padding field without conditional compilation (in rust and WGSL) + a comment to mention the WebGL2 special requirement. |
Thats a very good suggestion I like it! Add a separate padding field but no conditional compilation clutter. |
Objective
Solution
Replaced the
u32
field inMyExtension
by aUVec4
and only use thex
coordinate.Alternatives
1- Separate conditional padding field
We can also add conditional padding to both structs:
EDIT: this alternative works fine too
2- Don't fix it, unlist it
While the fix is quite simple, it does muddy the waters a tiny bit due to
quantize_steps
now being a UVec4 instead of a simple u32. We could simply remove this example from the examples that support WebGL2.Testing