Module compiler

Module compiler 

Source
Expand description

Shader compiler with naga validation

StructsΒ§

CacheStats
Cache statistics
CompiledShader
Compiled shader with validated module
ShaderCompiler
Shader compiler with caching

ConstantsΒ§

MD2_MATH_CONSTANTS πŸ”’
MD2 math constants (mirrors projectM’s milkdrop-shaders.h).
MD2_NOISE_TEXSIZE_CONSTANTS πŸ”’
Procedural noise pack texsize_* vec4 constants. Module-scope (was previously emitted inside fs_main) so lifted user functions that reference texsize_noise_lq.zw for a per-texel offset compile cleanly. The values are fixed at engine init (see onedrop-renderer::noise), so promoting them from let to const is a free win.
MD2_PRIVATE_STATE_DECLS πŸ”’
MD2 per-invocation private state hoisted to module scope.
USER_COMP_BINDINGS πŸ”’
USER_COMP_FRAGMENT_PREFIX πŸ”’
USER_COMP_FRAGMENT_SUFFIX πŸ”’
USER_COMP_HELPERS πŸ”’
MD2 helper functions every comp shader expects to find at module scope.
USER_COMP_VERTEX πŸ”’
USER_TEXTURE_FIRST_BINDING
First @binding index used by the user-texture array. The 14 bindings below this are claimed by built-ins (uniforms, main texture, blur, noise, four sampler variants) β€” see USER_COMP_BINDINGS.
USER_TEXTURE_SLOTS
Re-export so the renderer can spell the same constant in its bind group builder. Single source of truth: the wrapper declares MAX_USER_TEXTURE_SLOTS bindings; the comp pipeline allocates that many entries.
USER_WARP_FRAGMENT_PREFIX πŸ”’
Fragment-shader header for user-authored warp shaders. Same shape as USER_COMP_FRAGMENT_PREFIX (seed every MD2 var<private> binding from uniforms and per-invocation inputs), but uv/uv_orig come from the rasterised warp UV β€” not from a fullscreen-triangle screen UV β€” and ret is seeded from the previous-frame texture at that warped UV. The renderer binds prev_texture to sampler_main_texture so GetPixel(uv) (defined in the shared helpers) does the right thing.
USER_WARP_FRAGMENT_SUFFIX πŸ”’
Fragment-shader trailer for the warp pass. Same convention as the comp suffix (return vec4(ret, 1.0)), minus the gamma_adj factor β€” gamma is a display-side concern applied later in the comp pass.
USER_WARP_VERTEX πŸ”’
Warp-pass vertex shader. Consumes the same WarpVertex layout the renderer uses for the default warp pipeline (pos_clip: vec2<f32> at @location(0) plus uv_warp: vec2<f32> at @location(1)) so switching between the default and user pipelines doesn’t change vertex buffer plumbing on the renderer side.

FunctionsΒ§

append_user_texsize_constants πŸ”’
Emit a let texsize_<NAME>: vec4<f32> = vec4<f32>(w, h, 1/w, 1/h); line for each filled slot in the plan. Preset code reads these directly: tex2D(sampler_clouds, uv + texsize_clouds.zw * dt) is a common pattern for β€œstep one texel along the texture dimension”.
wrap_user_comp_shader
Wrap a translated WGSL fragment body into a complete shader module (prelude + texture bindings + entry points).
wrap_user_comp_shader_with_plan
Same as wrap_user_comp_shader, but emits per-preset texsize_<NAME> constants from the supplied TextureBindingPlan. The user-texture bindings themselves are always declared (so the bind-group layout the comp pipeline owns stays stable); only the WGSL identifiers the user body can reference (texsize_clouds, …) change per preset.
wrap_user_warp_shader_with_plan
Wrap a translated WGSL fragment body for the warp pass into a complete shader module. Mirror of wrap_user_comp_shader_with_plan β€” same uniforms, same texture bindings, same MD2 private-state declarations β€” but with a vertex shader that consumes the warp-mesh WarpVertex (pos_clip + uv_warp) and a fragment that seeds uv from uv_warp and ret from the previous-frame texture at that UV.