ShaderCompiler

Struct ShaderCompiler 

Source
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: Validator

Implementations§

Source§

impl ShaderCompiler

Source

pub fn new() -> Self

Source

pub fn compile(&mut self, source: &str) -> Result<CompiledShader>

Compile and validate a WGSL shader

Source

pub fn cache_stats(&self) -> CacheStats

Get cache statistics

Source

pub fn clear_cache(&mut self)

Clear the cache

Source

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.

Source

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.

Source

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:

  1. The vertex shader consumes the warp-mesh WarpVertex (pos_clip + uv_warp) instead of generating a fullscreen triangle. uv_warp is the per-vertex MD2-formula-warped UV the CPU writes each frame; the rasteriser interpolates it across each triangle.
  2. ret is seeded from sampler_main_texture at the warped UV. The renderer is expected to bind prev_texture to the sampler_main_texture slot so MD2’s “previous frame at the warped UV” semantics fall out for free.
Source

pub fn compile_user_warp_shader(&mut self, hlsl: &str) -> Result<CompiledShader>

Empty-plan convenience for Self::compile_user_warp_shader_with_plan.

Trait Implementations§

Source§

impl Default for ShaderCompiler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.