[naga glsl-out] Differentiate between support for std140
and std430
#7579
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.
Description
When outputting code for older OpenGL versions, I noticed that Naga does not differentiate between not having support for explicit bindings/locations and outputting Uniform memory layouts. Furthermore, if no global binding was given, no attempt at writing an explicit memory layout is made at all. This PR attempts to improve that by making a distinction between:
std140
layoutstd430
layout...And then outputting the memory layout if at all possible, even if no explicit location is supported/exists.
The result is that globals that have no explicitly given bindings now get a memory layout anyway.
Testing
I ran the whole test suite with
cargo xtask test
, of course, which showed a small amount of weird failures on my own system that were present on previous commits too. I also examined and validated (withglslang
) the resulting changed shaders.Furthermore, I reasoned (with my admittedly limited knowledge) that this change should be fine, because:
But I admit I don't think I grasp the complete scope of how these changes could break things. Specifically, I saw some shader snapshots that were testing padding related things (
naga/tests/out/glsl/wgsl-struct-layout.needs_padding_comp.Compute.glsl
andnaga/tests/out/glsl/wgsl-struct-layout.no_padding_comp.Compute.glsl
) that worry me slightly, as changing memory layouts could break things if padding was manually inserted using different rules. In theory, however, it should be fine as the previous default wasstd140
anyway (for Vulkan, I believe) andshared
for OpenGL, which leaves layout fully up to the driver and thus makes little sense to have padding inserted manually.If these changes turn out to break other code, I'd be happy to take another look if someone points me in the right direction!
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.NOTE: I added the changelog entry to "new features" because I didn't know how you all differentiate between new features and changes (or if this is seen as a bug), but feel free to shuffle that around if you wish.