bevyengine / bevyengine/bevy

Enforce `ShaderSize` on `UniformBuffer` and `DynamicUniformBuffer` at compile time.

Open
#8,351 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Docs
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## How can Bevy's documentation be improved?

Both:

https://docs.rs/bevy/latest/bevy/render/render_resource/struct.UniformBuffer.html
https://docs.rs/bevy/latest/bevy/render/render_resource/struct.DynamicUniformBuffer.html

Constrain `T : ShaderType`. However, this is overly broad, as uniform buffers only support fixed-size arrays.

`encase` has a trait `ShaderSize` that is automatically implemented by the `ShaderType` derive, if the type has no dynamically sized arrays.

We should constrain `UniformBuffer` and `DynamicUniformBuffer` to `ShaderSize` instead of `ShaderType` to catch these errors at compile time. Currently, using a variable length array will result in a panic from an assertion within `encase` at runtime.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.