Skip to main content

Module gpu_shapes

Module gpu_shapes 

Source
Expand description

Built-in GPU shape pipelines (D109 / Phase 27 Step 3) — geometry, uniform layout, and WGSL sources.

Lives in rosace-render (Layer 4) so SkiaCanvas::play_picture can convert shape DrawCommands to GPU quads without an upward dependency; rosace-shader::builtin (Layer 5) wraps these WGSL sources into ShaderSpecs and registers them, and re-exports everything here for app-facing use.

The SDF fragment shaders that replace tiny-skia’s CPU rasterization for ROSACE’s built-in DrawCommand shapes. Five pipelines cover all eight shape variants:

PipelineServes
FILL_RRECTFillRect (r=0), FillRRect, FillCircle
STROKE_RRECTStrokeRect (r=0), StrokeRRect
GRADIENTFillGradient (two-stop, axis-aligned, rounded)
ARCFillArc (ring segment, round caps)
SHADOWDrawShadow (Gaussian-approx rounded shadow)

Every conversion function here maps a shape in PHYSICAL pixels to (quad_rect, uniform_bytes): the quad is the shape’s bounds inflated by the AA/blur margin (an SDF’s anti-aliasing ramp extends past the exact bounds; an un-inflated quad would slice the ramp off), and the uniforms carry the true geometry in quad-local px. Colors are sRGB u8 (what DrawCommand records) converted to LINEAR premultiplied-ready f32 here — the fragment outputs linear, the sRGB surface encodes on write (the same one-correct-round-trip rule as the compositor’s texture formats).

All uniform structs share ONE layout (BuiltinShapeUniforms, 64 bytes) so every pipeline binds identically; each interprets params its own way, documented per conversion function.

Structs§

BuiltinShapeUniforms
The one uniform layout every built-in pipeline binds.

Constants§

ARC_ID
FILL_RRECT_ID
Raw pipeline ids of the built-in pipelines — inside PipelineId’s reserved built-in range (< 0x100). rosace-shader::builtin exposes the typed constants.
GRADIENT_ID
SHADOW_ID
STROKE_RRECT_ID

Functions§

arc_quad
FillArcARC quad: ring segment of thickness along the circle of radius centered at center, from start_deg sweeping sweep_deg clockwise (0° = 3 o’clock, y-down), ROUND caps (the CPU path strokes with LineCap::Round). shape: (center in quad-local px); params: (radius, thickness, start_rad, sweep_rad) — sweep normalized non-negative here so the shader needs no sign handling.
builtin_wgsl_sources
The five built-in pipelines as (raw_id, full_wgsl_fragment_source) — consumed by rosace-shader::builtin::register_builtins(), which wraps them in ShaderSpecs (a Layer-5 type this crate cannot name).
fill_rrect_quad
FillRect/FillRRect/FillCircleFILL_RRECT quad. params: (corner_radius, 0, 0, 0).
gradient_quad
FillGradientGRADIENT quad. Two stops, from at the rect’s top/left edge to to at the bottom/right (pad spread), masked by the rounded rect. params: (corner_radius, vertical ? 1 : 0, 0, 0).
linear_rgba
sRGB u8 RGBA → linear f32 RGBA (alpha is linear already).
shadow_quad
DrawShadowSHADOW quad: Gaussian-approximate drop shadow of the rounded rect. params: (corner_radius, sigma, 0, 0). Sigma maps from the CPU path’s box-blur blur parameter: three box passes of width b approximate a Gaussian with σ ≈ b/2 — tuned against the real build_shadow_mask output in the A/B demo, not derived on paper.
stroke_rrect_quad
StrokeRect/StrokeRRectSTROKE_RRECT quad. The stroke is centered on the shape edge (tiny-skia Stroke convention). params: (corner_radius, stroke_width, 0, 0).