bevy/crates
Greeble 09ff7ce9f6
Partially fix panics when setting WGPU_SETTINGS_PRIO=webgl2 (#18113)
# Overview

Fixes https://github.com/bevyengine/bevy/issues/17869.

# Summary

`WGPU_SETTINGS_PRIO` changes various limits on `RenderDevice`. This is
useful to simulate platforms with lower limits.

However, some plugins only check the limits on `RenderAdapter` (the
actual GPU) - these limits are not affected by `WGPU_SETTINGS_PRIO`. So
the plugins try to use features that are unavailable and wgpu says "oh
no". See https://github.com/bevyengine/bevy/issues/17869 for details.

The PR adds various checks on `RenderDevice` limits. This is enough to
get most examples working, but some are not fixed (see below).

# Testing

- Tested native, with and without "WGPU_SETTINGS=webgl2".
Win10/Vulkan/Nvidia".
- Also WebGL. Win10/Chrome/Nvidia.

```
$env:WGPU_SETTINGS_PRIO = "webgl2"
cargo run --example testbed_3d
cargo run --example testbed_2d
cargo run --example testbed_ui
cargo run --example deferred_rendering
cargo run --example many_lights
cargo run --example order_independent_transparency # Still broken, see below.
cargo run --example occlusion_culling # Still broken, see below.
```

# Not Fixed

While testing I found a few other cases of limits being broken. 

"Compatibility" settings (WebGPU minimums) breaks native in various
examples.

```
$env:WGPU_SETTINGS_PRIO = "compatibility"
cargo run --example testbed_3d

  In Device::create_bind_group_layout, label = 'build mesh uniforms GPU early occlusion culling bind group layout'
    Too many bindings of type StorageBuffers in Stage ShaderStages(COMPUTE), limit is 8, count was 9. Check the limit `max_storage_buffers_per_shader_stage` passed to `Adapter::request_device`
```

`occlusion_culling` breaks fake webgl.
```
$env:WGPU_SETTINGS_PRIO = "webgl2"
cargo run --example occlusion_culling

thread '<unnamed>' panicked at C:\Projects\bevy\crates\bevy_render\src\render_resource\pipeline_cache.rs:555:28:
index out of bounds: the len is 0 but the index is 2
Encountered a panic in system `bevy_render::renderer::render_system`!
```

`occlusion_culling` breaks real webgl.

```
cargo run --example occlusion_culling --target wasm32-unknown-unknown

ERROR app: panicked at C:\Users\T\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\glow-0.16.0\src\web_sys.rs:4223:9:
Tex storage 2D multisample is not supported
```

OIT breaks fake webgl.

```
$env:WGPU_SETTINGS_PRIO = "webgl2"
cargo run --example order_independent_transparency

  In Device::create_bind_group, label = 'mesh_view_bind_group'
    Number of bindings in bind group descriptor (28) does not match the number of bindings defined in the bind group layout (25)

```

OIT breaks real webgl

```
cargo run --example order_independent_transparency --target wasm32-unknown-unknown

  In Device::create_render_pipeline, label = 'pbr_oit_mesh_pipeline'
    Error matching ShaderStages(FRAGMENT) shader requirements against the pipeline
      Shader global ResourceBinding { group: 0, binding: 34 } is not available in the pipeline layout
        Binding is missing from the pipeline layout
```
2025-03-09 20:14:27 +00:00
..
bevy_a11y Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_animation Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_app Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_asset Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_audio Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_color Allow bevy_reflect and wgpu-types features in no_std for bevy_color (#18061) 2025-03-01 00:31:35 +00:00
bevy_core_pipeline Partially fix panics when setting WGPU_SETTINGS_PRIO=webgl2 (#18113) 2025-03-09 20:14:27 +00:00
bevy_derive allow Call and Closure expressions in hook macro attributes (#18017) 2025-03-06 16:39:11 +00:00
bevy_dev_tools Make Query::single (and friends) return a Result (#18082) 2025-03-02 19:51:56 +00:00
bevy_diagnostic Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_dylib Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_ecs Remove lifetime from QueryEntityError (#18157) 2025-03-09 20:05:22 +00:00
bevy_encase_derive Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_gilrs Replace some !Send resources with thread_local! (#17730) 2025-03-04 07:48:02 +00:00
bevy_gizmos Fix Component require() IDE integration (#18165) 2025-03-06 02:44:47 +00:00
bevy_gltf Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_image Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_input Fix Component require() IDE integration (#18165) 2025-03-06 02:44:47 +00:00
bevy_input_focus Make Query::single (and friends) return a Result (#18082) 2025-03-02 19:51:56 +00:00
bevy_internal Add support for experimental WESL shader source (#17953) 2025-03-09 19:26:55 +00:00
bevy_log Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_macro_utils Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_math Update itertools requirement from 0.13 to 0.14 (#18128) 2025-03-03 19:36:29 +00:00
bevy_mesh Fix mesh tangent attribute matching in mesh transform operations (#17992) 2025-03-07 17:39:42 +00:00
bevy_mikktspace Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_pbr Partially fix panics when setting WGPU_SETTINGS_PRIO=webgl2 (#18113) 2025-03-09 20:14:27 +00:00
bevy_picking Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_platform_support Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_ptr moved Debug from derive to impl_ptr in bevy_ptr (#18042) 2025-02-28 02:54:46 +00:00
bevy_reflect Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_remote BRP resource methods (#17423) 2025-02-26 20:29:47 +00:00
bevy_render Add support for experimental WESL shader source (#17953) 2025-03-09 19:26:55 +00:00
bevy_scene Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_sprite Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_state Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_tasks Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_text Add byte information to PositionedGlyph (#17900) 2025-03-08 16:35:01 +00:00
bevy_time Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_transform Transform Propagation Optimization: Static Subtree Marking (#18093) 2025-03-09 19:29:01 +00:00
bevy_ui Transform Propagation Optimization: Static Subtree Marking (#18093) 2025-03-09 19:29:01 +00:00
bevy_utils Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_window Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_winit Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00