Skip to content

Spirv shader bypass#3996

Closed
molikto wants to merge 7 commits intobevyengine:mainfrom
molikto:spirv-shader-passthrough
Closed

Spirv shader bypass#3996
molikto wants to merge 7 commits intobevyengine:mainfrom
molikto:spirv-shader-passthrough

Conversation

@molikto
Copy link
Contributor

@molikto molikto commented Feb 20, 2022

Objective

Expose wgpu spirv-shader-passthrough as a bevy feature.

Solution

add a feature to bevy_render and bevy itself.

alternative: #3997
More alternative:

  • having a different file extension passthrough.spv
  • some API to runtime specify if shader is loaded passthrough or not

(But I didn't implement these, because the passthrough is hopefully only temporary, and I don't see why people want some passthrough but some doesn't.)

# Conflicts:
#	crates/bevy_render/src/options.rs

# Conflicts:
#	crates/bevy_render/src/options.rs
@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Feb 20, 2022
"bevy_internal/bevy_ui",
]

spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this to the feature docs and note that it is incompatible with wasm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And any other system which doesn't support spirv, i.e dx12 and metal, afaik.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is only compatible with Vulkan. Maybe easier to say that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molikto please add documentation of the feature to docs/cargo_features.md and make note that it is only supported for Vulkan, if that is indeed correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shfty documentation is still missing here.

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible and removed S-Needs-Triage This issue needs to be labelled labels Feb 21, 2022
@molikto
Copy link
Contributor Author

molikto commented Mar 2, 2022

I am more in favor of #3997 so until we decided which PR to take I am not addressing comments to this PR :-)

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a couple of suggestions that allow enabling the feature but not failing if the backend does not support it, rather falling back to non-passthrough behaviour. Code that wants/needs passthrough can then used RenderDevice::features() to check for support at runtime and load the appropriate shader.

molikto and others added 3 commits March 2, 2022 14:20
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Co-authored-by: Robert Swain <robert.swain@gmail.com>
@molikto molikto requested a review from superdump March 2, 2022 06:21
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me but it needs updating and the build is failing. I prefer this PR to the other one as this one allows people to enable the feature if they need it, and if they need it, it is only available based on whether it is actually supported or not as indicated by the render device wgpu::Features.

@molikto molikto requested a review from superdump March 8, 2022 04:57
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just missing some documentation.

"bevy_internal/bevy_ui",
]

spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molikto please add documentation of the feature to docs/cargo_features.md and make note that it is only supported for Vulkan, if that is indeed correct.

@molikto molikto closed this Mar 9, 2022
@cart
Copy link
Member

cart commented Mar 9, 2022

Is there context on why both #3996 and #3997 were closed? This seems like a desirable feature.

@superdump
Copy link
Contributor

I’m also confused by this being closed. I was wondering if I would see another PR open in its place…

@molikto
Copy link
Contributor Author

molikto commented Mar 10, 2022

personally I don't like this approach anymore, it adds a feature flag to bevy and I think it's just confusing for people that don't care about this feature at all. I think maybe a proper solution is when we have asset .meta files.

@molikto molikto deleted the spirv-shader-passthrough branch May 17, 2022 04:46
@ProfLander
Copy link
Contributor

I've come across a need for this while developing Bevy Rust-GPU; naga has some bugs and unimplemented SPIR-V features that prevent the use of certain valid rust-gpu code (most notably, code emitted by the new SPIR-T optimizations rust-gpu enabled by default in 0.6).

I've verified that the affected shaders function as intended after manually patching this PR into my own bevy branch.

To wit, I'm interested in adopting this PR @cart @superdump; it still compiles with up-to-date bevy, so should be mergeable in its current state if there are no additional changes that might be desirable in hindsight.

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing documentation of the feature. @Shfty if you want to make a new PR to address that, please credit molikto for their work. Ideally just make a branch from theirs and make your changes on top. :)

"bevy_internal/bevy_ui",
]

spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shfty documentation is still missing here.

@ProfLander
Copy link
Contributor

ProfLander commented Mar 19, 2023

Great 🙂 will do.

Unfortunately it looks like molikto deleted their branch, so I'll have to reimplement and add credit in the commit messages / upcoming PR. Will do some research on the current state of SPIR-V support for various APIs, sort the docs, and open a new pull.

github-merge-queue bot pushed a commit that referenced this pull request Sep 22, 2024
**Note:** This is an adoption of @Shfty 's adoption (#8131) of #3996!
All I've done is updated the branch and run the docs CI.

> **Note:** This is an adoption of #3996, originally authored by
@molikto
> 
> # Objective
> Allow use of `wgpu::Features::SPIRV_SHADER_PASSTHROUGH` and the
corresponding `wgpu::Device::create_shader_module_spirv` for SPIR-V
shader assets.
> 
> This enables use-cases where naga is not sufficient to load a given
(valid) SPIR-V module, i.e. cases where naga lacks support for a given
SPIR-V feature employed by a third-party codegen backend like
`rust-gpu`.
> 
> ## Solution
> * Reimplemented the changes from [Spirv shader
bypass #3996](#3996), on account
of the original branch having been deleted.
> * Documented the new `spirv_shader_passthrough` feature flag with the
appropriate platform support context from [wgpu's
documentation](https://docs.rs/wgpu/latest/wgpu/struct.Features.html#associatedconstant.SPIRV_SHADER_PASSTHROUGH).
> 
> ## Changelog
> * Adds a `spirv_shader_passthrough` feature flag to the following
crates:
>   
>   * `bevy`
>   * `bevy_internal`
>   * `bevy_render`
> * Extends `RenderDevice::create_shader_module` with a conditional call
to `wgpu::Device::create_shader_module_spirv` if
`spirv_shader_passthrough` is enabled and
`wgpu::Features::SPIRV_SHADER_PASSTHROUGH` is present for the current
platform.
> * Documents the relevant `wgpu` platform support in
`docs/cargo_features.md`

---------

Co-authored-by: Josh Palmer <1253239+Shfty@users.noreply.github.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants