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§

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

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

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();

Implementations on Foreign Types§

§

impl ShaderType for i32

§

impl ShaderType for AtomicU32

§

impl ShaderType for Option<NonZeroU32>

§

impl<T> ShaderType for &mut Twhere T: ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for Arc<T>where T: ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for Cell<T>where T: Copy + ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl<T, const N: usize> ShaderType for [T; N]where T: ShaderType + ShaderSize,

§

impl<T> ShaderType for [T]where T: ShaderType + ShaderSize, [T]: Length,

§

fn size(&self) -> NonZeroU64

§

impl ShaderType for AtomicI32

§

impl ShaderType for f32

§

impl<T> ShaderType for Rc<T>where T: ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl ShaderType for u32

§

impl ShaderType for Option<NonZeroI32>

§

impl<T> ShaderType for Box<T, Global>where T: ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for LinkedList<T>where T: ShaderType + ShaderSize, LinkedList<T>: Length,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for VecDeque<T, Global>where T: ShaderType + ShaderSize, VecDeque<T, Global>: Length,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for &Twhere T: ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for Vec<T, Global>where T: ShaderType + ShaderSize, Vec<T, Global>: Length,

§

fn size(&self) -> NonZeroU64

§

impl<T> ShaderType for Cow<'_, T>where T: ToOwned<Owned = T> + ShaderType + ?Sized,

§

fn size(&self) -> NonZeroU64

§

impl ShaderType for Wrapping<i32>

§

impl ShaderType for Wrapping<u32>

Implementors§

§

impl ShaderType for Color

§

impl ShaderType for Mat2where f32: ShaderSize,

§

impl ShaderType for Mat3where f32: ShaderSize,

§

impl ShaderType for Mat4where f32: ShaderSize,

§

impl ShaderType for Vec2where f32: ShaderSize,

§

impl ShaderType for Vec3where f32: ShaderSize,

§

impl ShaderType for Vec4where f32: ShaderSize,

§

impl ShaderType for IVec2where i32: ShaderSize,

§

impl ShaderType for IVec3where i32: ShaderSize,

§

impl ShaderType for IVec4where i32: ShaderSize,

§

impl ShaderType for UVec2where u32: ShaderSize,

§

impl ShaderType for UVec3where u32: ShaderSize,

§

impl ShaderType for UVec4where u32: ShaderSize,

§

impl ShaderType for GpuDirectionalCascadewhere Mat4: ShaderType + ShaderSize, f32: ShaderType + ShaderSize,

§

impl ShaderType for GpuDirectionalLightwhere [GpuDirectionalCascade; 4]: ShaderType + ShaderSize, Vec4: ShaderType + ShaderSize, Vec3: ShaderType + ShaderSize, u32: ShaderType + ShaderSize, f32: ShaderType + ShaderSize,

§

impl ShaderType for GpuFogwhere Vec4: ShaderType + ShaderSize, Vec3: ShaderType + ShaderSize, f32: ShaderType + ShaderSize, u32: ShaderType,

§

impl ShaderType for GpuLightswhere [GpuDirectionalLight; 10]: ShaderType + ShaderSize, Vec4: ShaderType + ShaderSize, UVec4: ShaderType + ShaderSize, u32: ShaderType + ShaderSize, i32: ShaderType + ShaderSize,

§

impl ShaderType for GpuPointLightwhere Vec4: ShaderType + ShaderSize, u32: ShaderType + ShaderSize, f32: ShaderType + ShaderSize,

§

impl ShaderType for GpuPointLightsStoragewhere Vec<GpuPointLight, Global>: ShaderType,

§

impl ShaderType for GpuPointLightsUniformwhere Box<[GpuPointLight; 256], Global>: ShaderType,

§

impl ShaderType for MeshUniformwhere Mat4: ShaderType + ShaderSize, u32: ShaderType,

§

impl ShaderType for StandardMaterialUniformwhere Vec4: ShaderType + ShaderSize, f32: ShaderType + ShaderSize, u32: ShaderType + ShaderSize,

§

impl ShaderType for ColorMaterialUniformwhere Vec4: ShaderType + ShaderSize, u32: ShaderType,

§

impl ShaderType for Mesh2dUniformwhere Mat4: ShaderType + ShaderSize, u32: ShaderType,

§

impl ShaderType for GlobalsUniformwhere f32: ShaderType + ShaderSize, u32: ShaderType,

§

impl ShaderType for ColorGradingwhere f32: ShaderType + ShaderSize,

§

impl ShaderType for ViewUniformwhere Mat4: ShaderType + ShaderSize, Vec3: ShaderType + ShaderSize, Vec4: ShaderType + ShaderSize, ColorGrading: ShaderType,

§

impl ShaderType for ArrayLength