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

Regression - Unable to get globals.time in prepass shaders #10652

Open
AnthonyTornetta opened this issue Nov 20, 2023 · 4 comments
Open

Regression - Unable to get globals.time in prepass shaders #10652

AnthonyTornetta opened this issue Nov 20, 2023 · 4 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this!

Comments

@AnthonyTornetta
Copy link

Bevy version

0.12.0

What you did

In a wgsl shader:

#import bevy_pbr::prepass_bindings globals

// In vertex function:
var texture_index_offset = u32(globals.time / frame_duration_ms) % n_frames;

This worked in bevy 0.11.3 but since updating to 0.12 I cannot find a way to get the globals.time field.

From my understanding, the globals field is accessible through the bevy_pbr::mesh_view_bindings::globals import for non-prepass shaders, and in the bevy_pbr::prepass_bindings::globals version for prepass shaders.

What went wrong

globals.time in a prepass shader seems to be unusable in the 0.12 bevy update, and I don't see any place it was moved to.

The code above causes this error to be produced when compiling the shader:

error: no definition in scope for identifier: 'bevy_pbr::prepass_bindings::globals'
    ┌─ cosmos/shaders/animated_prepass.wgsl:194:36
    │
194 │     var texture_index_offset = u32(bevy_pbr::prepass_bindings::globals.time / frame_duration_ms) % n_frames;
    │                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown identifier
    │
    = no definition in scope for identifier: 'bevy_pbr::prepass_bindings::globals'

Trying to use bevy_pbr::mesh_view_bindings::globals instead of the prepass version will crash the game, but this also happened in 0.11.3 so isn't part of the regression.

Error for the bevy_pbr::mesh_view_bindings::globals crash if you are curious:

2023-11-20T04:18:01.201013Z  INFO bevy_asset::server: Reloading cosmos/shaders/animated_prepass.wgsl because it has changed
2023-11-20T04:18:01.248607Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread 'Compute Task Pool (0)' panicked at /home/cornchip/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.17.2/src/backend/direct.rs:3056:5:
wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
      note: label = `prepass_pipeline`
    Error matching ShaderStages(VERTEX) shader requirements against the pipeline
    Shader global ResourceBinding { group: 0, binding: 9 } is not available in the layout pipeline layout
    Binding is missing from the pipeline layout


note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system`!
thread 'main' panicked at /home/cornchip/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.12.0/src/pipelined_rendering.rs:145:45:
called `Result::unwrap()` on an `Err` value: RecvError

Additional information

All fields but the previous_view_proj seem to have been removed from globals in this commit: a15d152#diff-c5f333aa41ce294f11ba384a74bdde77ec460f9483391f95afee8bc2fbc092b7.

@AnthonyTornetta AnthonyTornetta added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 20, 2023
AnthonyTornetta added a commit to AnthonyTornetta/Cosmos that referenced this issue Nov 20, 2023
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-Time Involves time keeping and reporting P-Regression Functionality that used to work but no longer does. Add a test for this! and removed S-Needs-Triage This issue needs to be labelled A-Time Involves time keeping and reporting labels Nov 20, 2023
@IceSentry
Copy link
Contributor

This PR will fix the issue #10667

In the mean time, you should be able to add this to your shader:

#import bevy_render::globals::Globals
@group(0) @binding(1) var<uniform> globals: Globals;

nathanleiby added a commit to nathanleiby/drum-city that referenced this issue Nov 28, 2023
@blueforesticarus
Copy link

I encountered this recently in a vertex shader and got

Shader global ResourceBinding { group: 0, binding: 9 } is not available in the layout pipeline layout
Visibility flags don't include the shader stage

Looking into it it seems that globals is only visible for the fragment shader?
https://github.com/bevyengine/bevy/blob/ac6a4ff386df78ed0e66dba70860c9d16da81bbe/crates/bevy\_pbr/src/render/mesh\_view\_bindings.rs#L181-L182

    let mut entries = DynamicBindGroupLayoutEntries::new_with_indices(
        ShaderStages::FRAGMENT,

@viridia
Copy link
Contributor

viridia commented Feb 24, 2024

I'm having similar issues with my vertex shader, which uses globals.time to generation ocean waves.

@IceSentry
Copy link
Contributor

That's probably not the same issue but the resulting error message is similar. But the fix is already merged on main #12032

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-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants