Trait 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§

source

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

source

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

source

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ShaderType for Option<NonZeroI32>

source§

impl ShaderType for Option<NonZeroU32>

source§

impl ShaderType for f32

source§

impl ShaderType for i32

source§

impl ShaderType for u32

source§

impl ShaderType for Wrapping<i32>

source§

impl ShaderType for Wrapping<u32>

source§

impl ShaderType for AtomicI32

source§

impl ShaderType for AtomicU32

source§

impl ShaderType for Mat3
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for Mat2
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for Mat4
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for Vec4
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for Vec2
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for Vec3
where f32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for IVec2
where i32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for IVec3
where i32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for IVec4
where i32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for UVec2
where u32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for UVec3
where u32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for UVec4
where u32: ShaderSize,

Available on crate feature glam only.
source§

impl ShaderType for IVec2
where i32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for IVec3
where i32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for IVec4
where i32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for UVec2
where u32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for UVec3
where u32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for UVec4
where u32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Mat2
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Mat3
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Mat4
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Vec2
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Vec3
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

impl ShaderType for Vec4
where f32: ShaderSize,

Available on crate feature ultraviolet only.
source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<T> ShaderType for Matrix2<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Matrix3<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Matrix4<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Point2<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Point3<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Vector2<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Vector3<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Vector4<T>
where T: ShaderSize,

Available on crate feature cgmath only.
source§

impl<T> ShaderType for Vector<T>
where T: ShaderType + ShaderSize + Clone, Self: Length,

Available on crate feature im-rc only.
source§

impl<T> ShaderType for Vector<T>
where T: ShaderType + ShaderSize + Clone, Self: Length,

Available on crate feature im only.
source§

impl<T> ShaderType for Vector<T>
where T: ShaderType + ShaderSize + Clone, Self: Length,

Available on crate feature imbl only.
source§

impl<T> ShaderType for ColumnMatrix2<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix2x3<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix2x4<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix3<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix3x2<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix3x4<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix4<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix4x2<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for ColumnMatrix4x3<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Point2<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Point3<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Vector2<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Vector3<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Vector4<T>
where T: ShaderSize,

Available on crate feature mint only.
source§

impl<T> ShaderType for Mat2<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Mat3<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Mat4<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Vec2<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Vec3<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Vec4<T>
where T: ShaderSize,

Available on crate feature vek only.
source§

impl<T> ShaderType for Matrix2<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix2x3<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix2x4<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix3<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix3x2<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix3x4<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix4<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix4x2<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Matrix4x3<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Vector2<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Vector3<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for Vector4<T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView2x3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView2x4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView3x2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView3x4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView4x2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixView4x3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut2x3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut2x4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut3x2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut3x4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut4x2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for MatrixViewMut4x3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorView2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorView3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorView4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorViewMut2<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorViewMut3<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T> ShaderType for VectorViewMut4<'_, T>
where T: ShaderSize,

Available on crate feature nalgebra only.
source§

impl<T, A: Array<Item = T>> ShaderType for SmallVec<A>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate feature smallvec only.
source§

impl<T, A: Array<Item = T>> ShaderType for TinyVec<A>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate feature tinyvec only.
source§

impl<T, A: Array<Item = T>> ShaderType for ArrayVec<A>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate feature tinyvec only.
source§

impl<T, P: SharedPointerKind> ShaderType for SharedPointer<T, P>
where T: ShaderType,

Available on crate feature archery only.
source§

impl<T, P: SharedPointerKind> ShaderType for List<T, P>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate features rpds and archery only.
source§

impl<T, P: SharedPointerKind> ShaderType for Queue<T, P>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate features rpds and archery only.
source§

impl<T, P: SharedPointerKind> ShaderType for Stack<T, P>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate features rpds and archery only.
source§

impl<T, P: SharedPointerKind> ShaderType for Vector<T, P>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate features rpds and archery only.
source§

impl<T, S: RawData<Elem = T>, D: Dimension> ShaderType for ArrayBase<S, D>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate feature ndarray only.
source§

impl<T, const N: usize> ShaderType for ArrayVec<T, N>
where T: ShaderType + ShaderSize, Self: Length,

Available on crate feature arrayvec only.
source§

impl<T, const NUM: usize, const DEN: usize> ShaderType for StaticRc<T, NUM, DEN>
where T: ShaderType + ?Sized,

Available on crate feature static-rc only.
source§

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

Implementors§