Allow unconsumed inputs in fragment shaders
By removing them from vertex outputs when generating HLSL.
- Add
naga::back::hlsl::FragmentEntryPointfor providing information about the fragment entry point when generating vertex entry points vianaga::back::hlsl::Writer::write. Vertex outputs not consumed by the fragment entry point are omitted in the final output struct. - Add
nagasnapshot test for this new feature, - Remove
Features::SHADER_UNUSED_VERTEX_OUTPUT,StageError::InputNotConsumed, and associated validation logic. - Make wgpu dx12 backend pass fragment shader info when generating vertex HLSL.
- Add wgpu regression test for allowing unconsumed inputs.
Connections Fixes https://github.com/gfx-rs/wgpu/issues/3748
Description
My case affected by this is passing in SPIRV from shaderc which can optimize out unused inputs from the fragment shader. The shaders are dynamically configured with a pre-processor based on various settings from the user so it can be hard to predict when certain inter-stage variables are unused, and my attempt at configuring out particular outputs from vertex shaders quickly became overly verbose.
As noted in the linked issue, this validation was originally in the WebGPU spec but was removed. The validation was necessary for generating HLSL with matching inter-stage interfaces but we can work around that by adjusting the HLSL generation to account for any unconsumed inputs.
After investigating this I found two potential ways to account for this in the generated HLSL:
- Pass info about vertex outputs when generating fragment inputs and add in the missing fields to the fragment input struct.
- Pass info about fragment inputs when generating vertex outputs and omit unconsumed fields from the vertex output struct.
I went with the second option since it seemed simpler to implement than generating new fields and nicely removed unnecessary work passing unused values (although I assume drivers can probably optimize this out).
Note: This is a breaking change.
Testing I added a test to for whether the wgpu validation logic now allows unconsumed inputs and a naga snapshot test for removing the unconsumed vertex outputs when generating HLSL.
~~I have not tested on a windows machine with the dx12 backend!~~ So here are some testing TODOs:
- [x] Run
cargo xtask teston machine with dx12. - [ ] Cherry-pick this to branch I'm currently using for veloren and test if it works there.
Checklist
- [x] Run
cargo fmt. - [x] Run
cargo clippy. If applicable, add:- [ ]
--target wasm32-unknown-unknown - [ ]
--target wasm32-unknown-emscripten
- [ ]
- [x] Run
cargo xtask testto run tests. - [x] Add change to
CHANGELOG.md. See simple instructions inside file.
Great to see work here! Marking un-draft so it gets added to the review queue
@Imberflur could you rebase the PR?
@teoxoy rebased!