bevyengine / bevyengine/bevy

`AsBindGroup` error: the trait bound `bool: ShaderSize` is not satisfied

Open
#18,391 3 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

v0.15.3

## What you did

```rust
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
struct CustomMaterial {
#[uniform(0)]
color: LinearRgba,
#[uniform(0)]
is_red: bool,
}
```

## What went wrong

```
error[E0277]: the trait bound `bool: ShaderSize` is not satisfied
--> src/main.rs:36:27
|
36 | #[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
| ^^^^^^^^^^^ the trait `ShaderSize` is not implemented for `bool`
|
= help: the following other types implement trait `ShaderSize`:
&T
&mut T
ArrayLength
AtomicI32
AtomicU32
Box
CasUniform
ChromaticAberrationUniform
and 56 others
= note: required for `&'a bool` to implement `ShaderSize`
note: required by a bound in `_::{closure#0}::check::assert_impl`
--> src/main.rs:36:27
|
36 | #[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
| ^^^^^^^^^^^ required by this bound in `assert_impl`
= note: this error originates in the derive macro `AsBindGroup` which comes from the expansion of the derive macro `bevy::render::render_resource::ShaderType` (in Nightly builds, run with -Z macro-backtrace for more info)
```

However, according to the [Bevy Docs](https://docs.rs/bevy/latest/bevy/render/render_resource/trait.ShaderSize.html):

> ## ShaderSize
>
> Trait implemented for all [WGSL fixed-footprint types](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types)

Then according to [WGSL fixed-footprint types](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types):

> The types with [creation-fixed footprint](https://gpuweb.github.io/gpuweb/wgsl/#creation-fixed-footprint) are:
>
> - a [scalar](https://gpuweb.github.io/gpuweb/wgsl/#scalar) type
> - ...

Then according to [scalar](https://gpuweb.github.io/gpuweb/wgsl/#scalar):

> The scalar types are [bool](https://gpuweb.github.io/gpuweb/wgsl/#bool), [AbstractInt](https://gpuweb.github.io/gpuweb/wgsl/#abstractint), [AbstractFloat](https://gpuweb.github.io/gpuweb/wgsl/#abstractfloat), [i32](https://gpuweb.github.io/gpuweb/wgsl/#i32), [u32](https://gpuweb.github.io/gpuweb/wgsl/#u32), [f32](https://gpuweb.github.io/gpuweb/wgsl/#f32), and [f16](https://gpuweb.github.io/gpuweb/wgsl/#f16).

It includes the `bool`.

Either the code or the documentation should be wrong if I understand it correctly.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the AsBindGroup derive error in src/main.rs with the shown CustomMaterial and compare the ShaderSize implementation with the Bevy ShaderSize documentation and WGSL fixed-footprint rules. Determine whether the code or documentation is inconsistent, then add the appropriate regression coverage or documentation correction and verify the example compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.