Skip to main content

ShaderType

Trait ShaderType 

Source
pub trait ShaderType {
    // Provided methods
    fn min_size() -> NonZero<u64> { ... }
    fn size(&self) -> NonZero<u64> { ... }
    fn assert_uniform_compat() { ... }
}
Expand description

Base trait for all WGSL host-shareable types

Provided Methods§

Source

fn min_size() -> NonZero<u64>

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) -> NonZero<u64>

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<test_impl::Vec4f>>::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

<[test_impl::Vec4f; 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 {
    #[shader(size(runtime))]
    vec: Vec<test_impl::Vec4f>
}
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 #[shader(align)] attribute)

#[derive(ShaderType)]
struct Valid {
    a: f32,
    #[shader(align(16))]
    b: S,
}
Valid::assert_uniform_compat();

Will not panic (fixed via size attribute)

#[derive(ShaderType)]
struct Valid {
    #[shader(size(16))]
    a: f32,
    b: S,
}
Valid::assert_uniform_compat();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ShaderType for Atomic<i32>

Source§

impl ShaderType for Atomic<u32>

Source§

impl ShaderType for Option<NonZero<i32>>

Source§

impl ShaderType for Option<NonZero<u32>>

Source§

impl ShaderType for Wrapping<i32>

Source§

impl ShaderType for Wrapping<u32>

Source§

impl ShaderType for f32

Source§

impl ShaderType for i32

Source§

impl ShaderType for u32

Source§

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

Source§

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

Source§

fn size(&self) -> NonZero<u64>

Source§

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

Source§

fn size(&self) -> NonZero<u64>

Source§

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

Source§

fn size(&self) -> NonZero<u64>

Source§

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

Source§

fn size(&self) -> NonZero<u64>

Source§

impl<T> ShaderType for LinkedList<T>

Source§

fn size(&self) -> NonZero<u64>

Source§

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

Source§

fn size(&self) -> NonZero<u64>

Source§

impl<T> ShaderType for VecDeque<T>

Source§

fn size(&self) -> NonZero<u64>

Source§

impl<T> ShaderType for [T]

Source§

fn size(&self) -> NonZero<u64>

Implementors§

Source§

impl ShaderType for ArrayLength

Source§

impl ShaderType for AtmosphereTransform

Source§

impl ShaderType for ChromaticAberrationUniform

Source§

impl ShaderType for ColorGradingUniform

Source§

impl ShaderType for ContactShadowsUniform

Source§

impl ShaderType for DepthOfFieldUniform

Source§

impl ShaderType for DownsamplingConstants

Source§

impl ShaderType for FilteringConstants

Source§

impl ShaderType for ForwardDecalMaterialExtUniform
where f32: ShaderType,

Source§

impl ShaderType for GlobalsUniform

Source§

impl ShaderType for GpuAtmosphere

Source§

impl ShaderType for GpuAtmosphereSettings

Source§

impl ShaderType for GpuBinUnpackingMetadata

Source§

impl ShaderType for GpuClusteredLight

Source§

impl ShaderType for GpuDirectionalCascade

Source§

impl ShaderType for GpuDirectionalLight

Source§

impl ShaderType for GpuFog

Source§

impl ShaderType for GpuLights

Source§

impl ShaderType for GpuMorphDescriptor

Source§

impl ShaderType for GpuRectLight

Source§

impl ShaderType for GpuRenderBinnedMeshInstance

Source§

impl ShaderType for IVec2
where i32: ShaderSize,

Source§

impl ShaderType for IVec3
where i32: ShaderSize,

Source§

impl ShaderType for IVec4
where i32: ShaderSize,

Source§

impl ShaderType for IndirectBatchSet

Source§

impl ShaderType for IndirectParametersCpuMetadata

Source§

impl ShaderType for IndirectParametersGpuMetadata

Source§

impl ShaderType for IndirectParametersIndexed

Source§

impl ShaderType for IndirectParametersNonIndexed

Source§

impl ShaderType for LatePreprocessWorkItemIndirectParameters

Source§

impl ShaderType for LensDistortionUniform

Source§

impl ShaderType for LightProbesUniform

Source§

impl ShaderType for LinearRgba

Available on crate feature encase only.
Source§

impl ShaderType for Mat2
where f32: ShaderSize,

Source§

impl ShaderType for Mat3
where f32: ShaderSize,

Source§

impl ShaderType for Mat4
where f32: ShaderSize,

Source§

impl ShaderType for MeshCullingData

Source§

impl ShaderType for MeshInputUniform

Source§

impl ShaderType for MeshUniform

Source§

impl ShaderType for MorphAttributes

Source§

impl ShaderType for OitFragmentNode

Source§

impl ShaderType for OrderIndependentTransparencySettings

Source§

impl ShaderType for PbrDeferredLightingDepthId
where u32: ShaderType,

Source§

impl ShaderType for PreprocessWorkItem

Source§

impl ShaderType for PreviousViewData

Source§

impl ShaderType for RenderClusteredDecal

Source§

impl ShaderType for ScreenSpaceReflectionsUniform

Source§

impl ShaderType for SkyboxUniforms

Source§

impl ShaderType for StandardMaterialUniform

Source§

impl ShaderType for UVec2
where u32: ShaderSize,

Source§

impl ShaderType for UVec3
where u32: ShaderSize,

Source§

impl ShaderType for UVec4
where u32: ShaderSize,

Source§

impl ShaderType for Vec2
where f32: ShaderSize,

Source§

impl ShaderType for Vec3
where f32: ShaderSize,

Source§

impl ShaderType for Vec4
where f32: ShaderSize,

Source§

impl ShaderType for ViewUniform

Source§

impl ShaderType for VignetteUniform

Source§

impl ShaderType for WireframeVertexPullParams

Source§

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

Source§

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

Source§

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