Trait bevy::render::render_resource::encase::ShaderType
source · pub trait ShaderType {
// Provided methods
fn min_size() -> NonZeroU64 { ... }
fn size(&self) -> NonZeroU64 { ... }
fn assert_uniform_compat() { ... }
}
Expand description
Base trait for all WGSL host-shareable types
Provided Methods§
sourcefn min_size() -> NonZeroU64
fn min_size() -> NonZeroU64
Represents the minimum size of Self
(equivalent to GPUBufferBindingLayout.minBindingSize)
For WGSL fixed-footprint types
it represents WGSL Size
(equivalent to ShaderSize::SHADER_SIZE
)
For WGSL runtime-sized arrays and WGSL structs containing runtime-sized arrays (non fixed-footprint types) this will be calculated by assuming the array has one element
sourcefn size(&self) -> NonZeroU64
fn size(&self) -> NonZeroU64
Returns the size of Self
at runtime
For WGSL fixed-footprint types
it’s equivalent to Self::min_size
and ShaderSize::SHADER_SIZE
sourcefn assert_uniform_compat()
fn assert_uniform_compat()
Asserts that Self
meets the requirements of the
uniform address space restrictions on stored values and the
uniform address space layout constraints
Examples
Array
Will panic since runtime-sized arrays are not compatible with the uniform address space restrictions on stored values
<Vec<mint::Vector4<f32>>>::assert_uniform_compat();
Will panic since the stride is 4 bytes
<[f32; 2]>::assert_uniform_compat();
Will not panic since the stride is 16 bytes
<[mint::Vector4<f32>; 2]>::assert_uniform_compat();
Struct
Will panic since runtime-sized arrays are not compatible with the uniform address space restrictions on stored values
#[derive(ShaderType)]
struct Invalid {
#[size(runtime)]
vec: Vec<mint::Vector4<f32>>
}
Invalid::assert_uniform_compat();
Will panic since the inner struct’s size must be a multiple of 16
#[derive(ShaderType)]
struct S {
x: f32,
}
#[derive(ShaderType)]
struct Invalid {
a: f32,
b: S, // offset between fields 'a' and 'b' must be at least 16 (currently: 4)
}
Invalid::assert_uniform_compat();
Will not panic (fixed via align attribute)
#[derive(ShaderType)]
struct Valid {
a: f32,
#[align(16)]
b: S,
}
Valid::assert_uniform_compat();
Will not panic (fixed via size attribute)
#[derive(ShaderType)]
struct Valid {
#[size(16)]
a: f32,
b: S,
}
Valid::assert_uniform_compat();