Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Texture and Sampler Types

Wyn has two opaque GPU-resource types for image sampling. They are handles, not values: they can’t be constructed, copied, or used in arithmetic — only bound (via #[texture] / #[sampler] on an entry-point parameter) and passed to the texture operations below.

TypeMeaning
texture2dA 2D, f32-sampled image.
samplerA filtering sampler.

(texture2d is monomorphic in this version — the sampled type is fixed to f32, matching the no-angle-bracket style of vec4f32 / mat4f32.)

Texture operations

texture_load(tex: texture2d, coord: vec2i32, lod: i32) -> vec4f32 — raw texel fetch at integer coordinate coord and mip level lod. No filtering.

texture_sample(tex: texture2d, samp: sampler, uv: vec2f32, lod: f32) -> vec4f32 — filtered sample at UV uv, using sampler samp, at an explicit mip level lod.

Both operations are referentially transparent: their result is a pure function of their arguments. In particular texture_sample takes an explicit lod rather than computing one from screen-space derivatives, so it has no hidden cross-invocation dependence and is valid in any shader stage. (Derivative-based automatic mip selection — and a referentially-transparent texture_sample_grad variant taking explicit gradients — is planned future work.)

#[fragment]
entry fs(
    #[location(0)] uv: vec2f32,
    #[texture(set=0, binding=0)] tex: texture2d,
    #[sampler(set=0, binding=1)] samp: sampler
) #[location(0)] vec4f32 =
    let filtered = texture_sample(tex, samp, uv, 0.0) in
    let texel    = texture_load(tex, @[0, 0], 0) in
    filtered + texel