-
Notifications
You must be signed in to change notification settings - Fork 933
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
Allow unconsumed inputs in fragment shaders #5531
Conversation
1ed945e
to
f226525
Compare
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.
Here are some questions and notes for reviewers.
c3caa2d
to
0a04bf3
Compare
Great to see work here! Marking un-draft so it gets added to the review queue |
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.
wgpu side looks fine, added some comments some of the naga things
9ae8bb7
to
3f11d08
Compare
03f0bba
to
de5faaf
Compare
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.
Just clearing from my review queue, need someone from naga to look at this
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.
This is great! Sorry for taking so long to take a look at it.
@Imberflur could you rebase the PR? |
outputs when generating HLSL. Fixes gfx-rs#3748 * Add naga::back::hlsl::FragmentEntryPoint for providing information about the fragment entry point when generating vertex entry points via naga::back::hlsl::Writer::write. Vertex outputs not consumed by the fragment entry point are omitted in the final output struct. * Add naga snapshot 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.
* Add note that nesting structs for the inter-stage interface can't happen. * Remove new TODO notes (some addressed and some transferred to an issue gfx-rs#5577) * Changed issue that regression test refers to 3748 -> 5553 * Add debug_assert that binding.is_some() in hlsl writer * Fix typos caught in CI Also, fix compiling snapshot test when hlsl-out feature is not enabled.
de5faaf
to
2acc943
Compare
@teoxoy rebased! |
By removing them from vertex outputs when generating HLSL.
naga::back::hlsl::FragmentEntryPoint
for 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.naga
snapshot test for this new feature,Features::SHADER_UNUSED_VERTEX_OUTPUT
,StageError::InputNotConsumed
, and associated validation logic.Connections
Fixes #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:
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:cargo xtask test
on machine with dx12.Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.