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

FieldValue on Metal / WebGPUEffect
Blend stages / simultaneous textures8 / 8 (NATIVE_BITMAP_INPUTS); lighting and lightmap augmentations share this budgetBounds stage compilation (material_compile.rs) and engine-stage-materials stage programs
Texture operationsSelect, modulate (1×/2×/4×), add, signed add, subtract, diffuse/texture/factor/current alpha blends, modulate-alpha-add-colour, bump and bump-luminance, dot3, multiply-addEvaluated by shaders/material_combiner.slang and the CPU reference evaluator (evaluate_material_graph)
RasterMip LOD bias, anisotropy, literal and slope-scaled depth biasMaterial compiler bias requests
Texture kinds & filtering2D and cube with mip chains; linear min/mag, anisotropic min (up to 16×), point/linear mipStage texture upload and sampler creation
Texture addressingWrap and clampSampling uniforms and sampler states
Blend factorsZero, one, src/inv-src colour, src/inv-src alpha, dst colour (add equation)Blend lowering
Alpha compareGreater, or disabledFragment alpha cutout against reference
Vertex stream / lights1 stream (136-byte max stride), 8 fixed-function light slots, sphere-map texgenCPU fixed-function lighting and vertex preparation
Max index / primitive countu16::MAX / u32::MAX / 616-bit index streams
Texture formatsBC1/2/3 when supported (Metal; WebGPU texture-compression-bc), plus RGBA8; palette and 16-bit gray expand before uploadHost decodes to RGBA8 where Device::supports(...) is false
Max texture extentQueried 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_operation selects 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–3 channels become (XY, 0, 1); unwritten TEXCOORD4–7 become (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.