Expand description
Standard WGSL prelude injected ahead of every translated user shader.
The prelude exposes the MilkDrop 2 uniform set (audio, time, aspect,
q1..q32, etc.) under a single uniforms binding so warp and comp
HLSL shaders can be translated to WGSL with a known reference target.
Two artefacts must stay in lockstep:
ShaderUniforms— the Rust mirror, repr-C, Pod/Zeroable. The renderer fills it each frame fromRenderState/MilkContextand uploads it viawgpu::Queue::write_buffer.SHADER_UNIFORMS_WGSL— the WGSLstructdeclaration plus the@group(0) @binding(0) var<uniform> uniforms: ShaderUniforms;line. Concatenated to the front of every translated user shader before naga validates and the renderer compiles it.
Layout discipline (matches WGSL/std140-ish uniform alignment):
- All scalar
f32fields packed at the top in groups of four (each group is one 16-byte slot). - All
vec4<f32>fields after, contiguous (each is exactly 16 bytes, so no further padding is needed). - Trailing
array<vec4<f32>, N>forq1..q32— eight vec4 slots = 32 floats.
The size in bytes is asserted by the
tests::layout_is_byte_for_byte_compatible test in this module
against a naga-parsed WGSL module: any drift between the Rust struct
and the WGSL declaration trips the test.
Structs§
- Shader
Uniforms - Rust mirror of the WGSL
ShaderUniformsstruct.
Constants§
- SHADER_
Q_ CHANNELS - Number of
q*channels exposed to user shaders. MilkDrop 2 shipsq1..q32; the engine tracks 64 internally but only the first 32 cross into shader-land. - SHADER_
UNIFORMS_ WGSL - WGSL
structdeclaration mirroringShaderUniformsplus the standard@group(0) @binding(0)uniform binding.
Functions§
- with_
prelude - Build a full prelude string by appending the user’s shader body to the
standard
ShaderUniformsdeclaration.bodyis expected to already be translated to WGSL.