Apply a consistent padding in shader uniforms for the WebGL2 target #18863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Following the discussions in #18812 (and a few messages on Discord), paddings for the WebGL2 target in the different bevy shader uniforms are found to not always be optimal (or even correct) in size, nor consistent in style.
As an example, in
post_processing.wgsl
, the following uniform does not have the expected size.Solution
vec2
&vec3
as padding fieldsu32
fields as padding_webgl2_padding_*b
)line_joints.wgsl
seemed not up to date with the rust-side following the gizmos dashed line update. Thegap_scale
andline_scale
fields were missing from the shader-side uniform declaration. They were only declared inLineGizmoUniform
inlines.wgsl
.LineGizmoUniform
declaration inlines.wgsl
exported via a#define_import_path bevy_gizmos::lines
?SkyboxUniforms
, thetransform
andbrightness
fields were swapped. I may be wrong but I supposed that themat4x4<f32>
being after thef32
could cause padding to be inserted between the brightness and transform fields (to align the mat4x4 on 16 byte).skybox
example to crash on WebGL2, even by removing all the padding fields in this uniform, or by adding just 1 or 2 instead of 3. I don't know why this is the case.For reference, WGSL alignment and size.
Testing