pub struct ShaderCompiler {
cache: Arc<Mutex<HashMap<String, CompiledShader>>>,
validator: Validator,
}Expand description
Shader compiler with caching
Fields§
§cache: Arc<Mutex<HashMap<String, CompiledShader>>>§validator: ValidatorImplementations§
Source§impl ShaderCompiler
impl ShaderCompiler
pub fn new() -> Self
Sourcepub fn compile(&mut self, source: &str) -> Result<CompiledShader>
pub fn compile(&mut self, source: &str) -> Result<CompiledShader>
Compile and validate a WGSL shader
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the cache
Sourcepub fn compile_user_comp_shader(&mut self, hlsl: &str) -> Result<CompiledShader>
pub fn compile_user_comp_shader(&mut self, hlsl: &str) -> Result<CompiledShader>
Translate a MilkDrop 2 comp shader from HLSL, wrap it into a complete WGSL fragment module (prelude + texture bindings + standard MD2 fragment inputs + entry points), and validate via naga.
Returns the wrapped WGSL on success — the renderer’s CompPipeline
can feed it to wgpu::Device::create_shader_module directly. On
failure, the error string captures whichever stage tripped (regex
translation, WGSL parse, validation).
Compile rates depend on the AST-based translator in onedrop_hlsl;
presets the translator can’t fully translate fall back to a gamma-only
default shader at the caller level so the render path stays alive.
Sourcepub fn compile_user_comp_shader_with_plan(
&mut self,
hlsl: &str,
plan: &TextureBindingPlan,
) -> Result<CompiledShader>
pub fn compile_user_comp_shader_with_plan( &mut self, hlsl: &str, plan: &TextureBindingPlan, ) -> Result<CompiledShader>
Variant of Self::compile_user_comp_shader that threads a
TextureBindingPlan through the translator and wrapper. The
renderer scans the HLSL, resolves each sampler sampler_X; against
its texture pool, and hands the result over here so the emitted
WGSL routes tex2D(sampler_clouds, …) onto the right user-texture
binding and exposes the matching texsize_clouds constant inside
fs_main.
Sourcepub fn compile_user_warp_shader_with_plan(
&mut self,
hlsl: &str,
plan: &TextureBindingPlan,
) -> Result<CompiledShader>
pub fn compile_user_warp_shader_with_plan( &mut self, hlsl: &str, plan: &TextureBindingPlan, ) -> Result<CompiledShader>
Compile a user-authored MD2 warp shader (the per-pixel feedback stage that runs before the composite pass) through the same HLSL→WGSL translator the comp pipeline uses, then validate via naga.
The wrapper at wrap_user_warp_shader_with_plan mirrors the
comp wrapper’s bind-group layout — same ShaderUniforms, same
texture binding numbers, same GetPixel/GetBlur* helpers — so
the renderer can reuse the comp pipeline’s texture-plan
machinery. The only structural differences:
- The vertex shader consumes the warp-mesh
WarpVertex(pos_clip+uv_warp) instead of generating a fullscreen triangle.uv_warpis the per-vertex MD2-formula-warped UV the CPU writes each frame; the rasteriser interpolates it across each triangle. retis seeded fromsampler_main_textureat the warped UV. The renderer is expected to bindprev_textureto thesampler_main_textureslot so MD2’s “previous frame at the warped UV” semantics fall out for free.
Sourcepub fn compile_user_warp_shader(&mut self, hlsl: &str) -> Result<CompiledShader>
pub fn compile_user_warp_shader(&mut self, hlsl: &str) -> Result<CompiledShader>
Empty-plan convenience for Self::compile_user_warp_shader_with_plan.