Skip to content
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 disabling the StageError::InputNotConsumed error #3748

Open
Aaron1011 opened this issue May 5, 2023 · 5 comments · May be fixed by #5531
Open

Allow disabling the StageError::InputNotConsumed error #3748

Aaron1011 opened this issue May 5, 2023 · 5 comments · May be fixed by #5531
Labels
area: validation Issues related to validation, diagnostics, and error handling

Comments

@Aaron1011
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The Ruffle project dynamically builds Naga shaders and wgpu render passes/pipelines based on user-provided code. It turns out that some user-provided input shaders have vertex shader outputs that are unused by the fragment shader. When we compile these shaders to Naga and pass the naga::Module to wgpu, a StageError::InputNotConsumed` is produced.

Describe the solution you'd like
It would be very useful to be able to disable the wgpu check that produces StageError::InputNotConsumed. Since Ruffle is compiling user-provided shaders, the original input shaders are never going to be fixed (as they would be if the error occured when compiling Ruffle's own internal shaders).

Describe alternatives you've considered
Ruffle could duplicate the wgpu InputNotConsumed logic, and modify its shader compilation to produce a naga::Module that has no unused outputs in the vertex shaders. However, this adds unnecessary complexity and runtime overhead, as AFAIK all of the target wgpu backends should be able to handle a vertex shader with unused outputs.

Additional context
Ruffle is compiling to naga by building up a naga::Module, and then using a wgpu::ShaderSource::Naga with the built module.

@teoxoy
Copy link
Member

teoxoy commented May 9, 2023

The error was introduced by #2704 but this doesn't seem to be a requirement of the WebGPU spec.

The spec only requires that fragment inputs were output by the previous vertex stage.

For each user-defined input of descriptor.fragment there must be a user-defined output of descriptor.vertex that location, type, and interpolation of the input.

NOTE: Vertex-only pipelines can have user-defined outputs in the vertex stage; their values will be discarded.

from https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-inter-stage-interfaces

So, we most likely need a workaround for gfx-rs/naga#1945.

@teoxoy teoxoy added this to the WebGPU Specification V1 milestone May 9, 2023
@teoxoy teoxoy added the area: validation Issues related to validation, diagnostics, and error handling label May 9, 2023
@cwfitzgerald
Copy link
Member

Yeah, that requirement was backed out. Afaik, we just need to pipe the full list of vertex outputs into the fragment input in Naga so Naga can generate the correct struct.

github-actions bot pushed a commit to veloren/veloren that referenced this issue Feb 15, 2024
See gfx-rs/wgpu#4915

Also:
* Remove unused vert-out frag-in variables from shaders (naga doesn't
  like this probably because they are optimized out on the fragment
  side). This restriction from naga may be relaxed in the future
  see gfx-rs/wgpu#3748.
* Enable OptimizationLevel::Performance for shaderc by default
* Add a environment variable VOXYGEN_SHADERC_OPTS for disabling this
  (e.g. to test if it actually makes a difference on any platform).
  (TODO: testing might be easier if there was a way to do toggle it
  without restarting...)
nerasw pushed a commit to nerasw/veloren that referenced this issue Feb 20, 2024
See gfx-rs/wgpu#4915

Also:
* Remove unused vert-out frag-in variables from shaders (naga doesn't
  like this probably because they are optimized out on the fragment
  side). This restriction from naga may be relaxed in the future
  see gfx-rs/wgpu#3748.
* Enable OptimizationLevel::Performance for shaderc by default
* Add a environment variable VOXYGEN_SHADERC_OPTS for disabling this
  (e.g. to test if it actually makes a difference on any platform).
  (TODO: testing might be easier if there was a way to do toggle it
  without restarting...)
@Imberflur
Copy link
Contributor

Yeah, that requirement was backed out. Afaik, we just need to pipe the full list of vertex outputs into the fragment input in Naga so Naga can generate the correct struct.

I've been looking into this a bit. The place where we have both vertex and fragment shaders, create_render_pipeline, pretty much has immutable access to the naga shader modules. So it seems like either the module needs to be cloned or this info could be passed through and utilized in the hlsl::Writer?

@teoxoy
Copy link
Member

teoxoy commented Apr 6, 2024

We'd ideally do this in the HLSL backend.

@Imberflur
Copy link
Contributor

It looks like dawn implemented this by removing the outputs on the vertex shader side https://bugs.chromium.org/p/dawn/issues/detail?id=1493#c20.

Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 14, 2024
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::writer. 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.
@Imberflur Imberflur linked a pull request Apr 14, 2024 that will close this issue
8 tasks
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 14, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 14, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 14, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 15, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 22, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue Apr 22, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue May 3, 2024
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.
Imberflur added a commit to Imberflur/wgpu that referenced this issue May 6, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: validation Issues related to validation, diagnostics, and error handling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants