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§
Sourcefn min_size() -> NonZero<u64>
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
Sourcefn size(&self) -> NonZero<u64>
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
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<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§
impl ShaderType for Atomic<i32>
impl ShaderType for Atomic<u32>
impl ShaderType for Option<NonZero<i32>>
impl ShaderType for Option<NonZero<u32>>
impl ShaderType for Wrapping<i32>
impl ShaderType for Wrapping<u32>
impl ShaderType for f32
impl ShaderType for i32
impl ShaderType for u32
impl<T, const N: usize> ShaderType for [T; N]where
T: ShaderType + ShaderSize,
Source§impl<T> ShaderType for &mut Twhere
T: ShaderType + ?Sized,
impl<T> ShaderType for &mut Twhere
T: ShaderType + ?Sized,
Source§impl<T> ShaderType for Cell<T>where
T: Copy + ShaderType,
impl<T> ShaderType for Cell<T>where
T: Copy + ShaderType,
Source§impl<T> ShaderType for Cow<'_, T>
impl<T> ShaderType for Cow<'_, T>
Source§impl<T> ShaderType for LinkedList<T>
impl<T> ShaderType for LinkedList<T>
Source§impl<T> ShaderType for Rc<T>where
T: ShaderType + ?Sized,
impl<T> ShaderType for Rc<T>where
T: ShaderType + ?Sized,
Source§impl<T> ShaderType for VecDeque<T>
impl<T> ShaderType for VecDeque<T>
Source§impl<T> ShaderType for [T]
impl<T> ShaderType for [T]
Implementors§
impl ShaderType for ArrayLength
impl ShaderType for AtmosphereTransform
impl ShaderType for ChromaticAberrationUniform
impl ShaderType for ColorGradingUniformwhere
Mat3: ShaderType + ShaderSize,
Vec3: ShaderType + ShaderSize,
Vec2: ShaderType + ShaderSize,
f32: ShaderType + ShaderSize,
impl ShaderType for ContactShadowsUniform
impl ShaderType for DepthOfFieldUniform
impl ShaderType for DownsamplingConstants
impl ShaderType for FilteringConstants
impl ShaderType for ForwardDecalMaterialExtUniformwhere
f32: ShaderType,
impl ShaderType for GlobalsUniform
impl ShaderType for GpuAtmosphere
impl ShaderType for GpuAtmosphereSettingswhere
UVec2: ShaderType + ShaderSize,
UVec3: ShaderType + ShaderSize,
u32: ShaderType + ShaderSize,
f32: ShaderType + ShaderSize,
impl ShaderType for GpuBinUnpackingMetadata
impl ShaderType for GpuClusteredLight
impl ShaderType for GpuDirectionalCascade
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,
[GpuRectLight; 8]: ShaderType,
impl ShaderType for GpuMorphDescriptor
impl ShaderType for GpuRectLight
impl ShaderType for GpuRenderBinnedMeshInstance
impl ShaderType for IVec2where
i32: ShaderSize,
impl ShaderType for IVec3where
i32: ShaderSize,
impl ShaderType for IVec4where
i32: ShaderSize,
impl ShaderType for IndirectBatchSet
impl ShaderType for IndirectParametersCpuMetadata
impl ShaderType for IndirectParametersGpuMetadata
impl ShaderType for IndirectParametersIndexed
impl ShaderType for IndirectParametersNonIndexed
impl ShaderType for LatePreprocessWorkItemIndirectParameters
impl ShaderType for LensDistortionUniform
impl ShaderType for LightProbesUniformwhere
[RenderLightProbe; 8]: ShaderType + ShaderSize,
i32: ShaderType + ShaderSize,
u32: ShaderType + ShaderSize,
Vec4: ShaderType + ShaderSize,
f32: ShaderType + ShaderSize,
impl ShaderType for LinearRgba
encase only.