Material Device Capabilities
scene/materials/src/device_caps.rs defines the capability record (NativeDeviceCaps, MaterialDeviceProfile) that material compilers budget against. The Metal and WebGPU backends report explicit format support and lower materials portably without emulating a specific hardware vendor.
Capability Record
| Field | Value on Metal / WebGPU | Effect |
|---|---|---|
| Blend stages / simultaneous textures | 8 / 8 (NATIVE_BITMAP_INPUTS); lighting and lightmap augmentations share this budget | Bounds stage compilation (material_compile.rs) and engine-stage-materials stage programs |
| Texture operations | Select, modulate (1×/2×/4×), add, signed add, subtract, diffuse/texture/factor/current alpha blends, modulate-alpha-add-colour, bump and bump-luminance, dot3, multiply-add | Evaluated by shaders/material_combiner.slang and the CPU reference evaluator (evaluate_material_graph) |
| Raster | Mip LOD bias, anisotropy, literal and slope-scaled depth bias | Material compiler bias requests |
| Texture kinds & filtering | 2D and cube with mip chains; linear min/mag, anisotropic min (up to 16×), point/linear mip | Stage texture upload and sampler creation |
| Texture addressing | Wrap and clamp | Sampling uniforms and sampler states |
| Blend factors | Zero, one, src/inv-src colour, src/inv-src alpha, dst colour (add equation) | Blend lowering |
| Alpha compare | Greater, or disabled | Fragment alpha cutout against reference |
| Vertex stream / lights | 1 stream (136-byte max stride), 8 fixed-function light slots, sphere-map texgen | CPU fixed-function lighting and vertex preparation |
| Max index / primitive count | u16::MAX / u32::MAX / 6 | 16-bit index streams |
| Texture formats | BC1/2/3 when supported (Metal; WebGPU texture-compression-bc), plus RGBA8; palette and 16-bit gray expand before upload | Host decodes to RGBA8 where Device::supports(...) is false |
| Max texture extent | Queried from renderer (native_device_caps) | Mip selection; diagnostic convert_textures flag caps at 256 via texture_conversion_caps |
Fallback & Selection Rules
- Callers or tests budgeting for fewer stages/textures modify the record directly; the engine holds no vendor presets.
specular_stage_operationselects add (unmasked), multiply-add (constant mask), modulate-alpha-add-colour (if supported), or modulate 2×.- Failed supported material compilation retries the last eligible modifier, then the resolved root, then the default material without inventing replacement art.
Explicit Device Definitions
These rules are engine definitions shared across CPU and GPU evaluation rather than adapter quirks:
- Unwritten texture outputs — Unwritten
TEXCOORD0–3channels become(XY, 0, 1); unwrittenTEXCOORD4–7become(0, 0, 0, 1). Cubemaps consume interpolated(x, y, 0). - Render-target sampling — Sampling a render target reads an immutable snapshot copied immediately before the draw; a texture is never bound simultaneously as attachment and sampler.
- Alpha retention — An enabled colour stage with alpha disabled preserves incoming alpha (so generated bump stages preserve incoming RGBA while displacing the next sample).
- Short & non-finite coordinates — Missing components default to zero; non-finite coordinates (including division by zero in projection) become zero before bump displacement and addressing; a resulting zero cubemap vector becomes
(1, 0, 0). - Bump generation — Reads the authored mip regardless of animated selection; unsupported source formats emit zero displacement.