← Extensions to GPUI

Paint and shader extension. Opt in through xgpui-shader; ordinary output is sRGB, with explicit native wide-SDR programs.

Shader paints and instanced shaders

Both rendering models are experimental and require portable-shaders. Choose by integration and workload; neither name implies stabilization or broader backend support.

ChoiceShader paintsInstanced shaders
Rust entryshader_paint::ShaderProgram::new(source)instanced::ShaderProgram::<T>::new(source)
Use whenA reusable paint should fill a styled background, border or pathTyped effects should draw directly in scene order, including many repeated instances
RenderingCached offscreen output, integrated through PaintMain-pass draws; compatible consecutive instances can batch
ParametersNamed ShaderParameters; reflected packing into immutable ShaderPaint snapshotsPOD ShaderInstance records with explicit field metadata, checked against WGSL layout
Parameter limits1–32 f32 scalar/vector members; at most 1,024 packed bytesAt most 128 bytes; f32 scalars/vectors with verified offsets and stride
WGSL entryfn paint(input: PaintInput) -> vec4<f32>; supplied global parametersfn shade(input: ShaderInput, parameters: Parameters) -> vec4<f32>
CoordinatesFull source UV, local logical position and sizeFull effect UV, local logical position and size, plus scale factor
Clipping and opacityHost applies coverage and opacity without remapping the paint fieldHost applies content-mask clipping and inherited opacity; shader supplies analytical shape coverage
Loops and derivativesRejected, as is discardSubject to Naga validation
ResourcesNo user textures, resource bindings or computeNo user resource bindings or compute
OutputStraight-alpha encoded-sRGB SDREncoded-sRGB SDR by default; explicit new_linear_p3 requires an active native WideGamutSdr window
BackendsMetal, D3D11 and optional wgpu adaptersMetal, D3D11, wgpu, browser WebGPU and WebGL2

Backend implementation does not establish driver acceptance on every platform. The shader-paint guide and instanced shader guide record runtime validation and remaining platform checks. Main-pass batching preserves draw order; it does not sort all matching programs together. Reuse compiled programs in either model.

Migration from v1/v2 terminology

“v1” referred to shader paints; “v2” referred to instanced shaders. These are parallel rendering models, not successive releases of one API. Existing guide filenames remain available to preserve incoming links.

// Before: removed beta API.
use xgpui_shader::experimental::{ShaderParameters, ShaderProgram};
let program = ShaderProgram::new_v1(source)?;
// After: identical source and output contracts.
use xgpui_shader::shader_paint::{ShaderParameters, ShaderProgram};
let program = ShaderProgram::new(source)?;
let paint = program.paint(ShaderParameters::new().float("gain", 0.5))?;

ShaderPaint is also exported from shader_paint. The old experimental module and new_v1 constructor have been removed as a breaking beta API change; update all callers to the new names. No aliases or deprecated forwarding APIs remain. instanced::ShaderProgram<T>::new and typed instance terminology are unchanged.

Version numbers are reserved for actual source-contract or ABI revisions within each rendering model. Naming changes do not relax validation, change color semantics, or add backend support.