Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Parent: #126
Related: #27, #28
Problem
GPU-driven draws and visibility-buffer shading require geometry/material resources to be addressable from GPU-visible IDs. Bloom still relies heavily on per-material/per-draw binding, while wgpu feature support differs across Metal, DX12, Vulkan, mobile, and WebGPU. Making “bindless” mandatory would break the engine's broad platform promise; avoiding indirection blocks modern rendering architecture.
Outcome
One generation-safe resource-ID model with capability-tiered implementations:
- Tier A: descriptor-indexed/global texture and sampler tables where the adapter/backend supports the required features robustly;
- Tier B: paged texture arrays/atlases plus material indirection with bounded page switches;
- Tier C: existing bind-group material path as a correctness fallback.
Shaders and scene data consume stable IDs; only the backend table implementation varies.
Architecture contract
IDs and lifetime
- Separate typed IDs for material, texture, sampler, mesh, and buffer views.
- IDs contain or reference a generation so stale handles resolve to a diagnostic fallback, never an unrelated reused resource.
- A residency manager owns allocation, retirement after GPU completion, fallback resources, and per-frame update batches.
- Define hard limits and expose them through renderer capabilities.
Material data
- Move scalar/vector PBR parameters into a GPU storage buffer indexed by
material_id. - Store texture/sampler IDs in the material record; do not embed backend bind-group objects in scene/material ownership.
- Keep the existing custom-material ABI functional. Version the ABI only if unavoidable and provide migration diagnostics.
Capability selection
- Probe actual adapter features/limits at device creation; do not infer solely from OS/backend.
- Tier selection is logged and queryable from TypeScript.
- Allow a test/debug override to force each lower tier on capable hardware.
- Web/mobile limits must be derived from
adapter.limits(), not desktop defaults.
Shader interface
- Centralize resource lookup helpers in shared WGSL.
- Out-of-range/nonresident IDs sample visible diagnostic defaults in debug and safe neutral defaults in release.
- Preserve correct color-space and normal-map sampling across table implementations.
Staged implementation
- Introduce IDs, GPU material records, and Tier C adapter without changing draw behavior.
- Implement Tier B using texture-array pages; group indirect draws by page when necessary.
- Implement Tier A only behind explicit feature checks and backend tests.
- Switch perf ticket 009: GPU-driven rendering — indirect multi-draw + GPU cull #28 and perf ticket 008: visibility buffer (Nanite-style) replaces 4-MRT G-buffer #27 to consume the common IDs.
- Add streaming residency hooks without implementing the full cooker/streamer here.
Acceptance criteria
- A stress scene with at least 4,096 material textures and 10,000 visible material instances renders without handle corruption; tier-specific documented limits may reduce resident textures but must stream/fallback deterministically.
- Tier A performs no per-material bind-group creation or switching inside the opaque GPU-driven pass.
- Tier B reports page count/switches and stays within documented adapter limits.
- Forced Tier C matches current rendering and keeps web/mobile adapters functional.
- Destroy/recreate/churn tests prove stale IDs cannot alias newly allocated resources.
- sRGB, linear data, HDR, normal, mip, and sampler modes have golden coverage.
- The quality corpus matches the existing material path within tolerance before perf ticket 008: visibility buffer (Nanite-style) replaces 4-MRT G-buffer #27 migration.
- TypeScript exposes a read-only capability/limit report and receives an actionable error when a requested resource class is unsupported.
Likely files
native/shared/src/renderer/material_system.rsnative/shared/src/renderer/material_pipeline.rsnative/shared/src/renderer/material_system_wasm.rsnative/shared/src/renderer/shaders/native/shared/shaders/material_abi.wgslnative/shared/src/handles.rs- device creation in
native/*/src/lib.rs - public capability API under
src/core/orsrc/models/
Non-goals
- Requiring descriptor indexing on all platforms.
- Virtual texture page streaming itself.
- Removing the compatibility renderer before every target passes.
Dependencies
- Independent first stage.
- Required before completing perf ticket 009: GPU-driven rendering — indirect multi-draw + GPU cull #28/perf ticket 008: visibility buffer (Nanite-style) replaces 4-MRT G-buffer #27 and virtualized geometry.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
proggeramlug commentedon Jul 23, 2026
Implemented and qualified.
What landed
MaterialId,TextureId,SamplerId,MeshId, andBufferViewIdvalues. Slot reuse increments the generation; stale IDs resolve to the fallback record/resource instead of aliasing a replacement.wgpu::Devicefeatures/limits:BLOOM_MATERIAL_TIERand TypeScript API).getMaterialBindingCapabilities()andsetMaterialBindingTierOverride()through TypeScript, native FFI, web parity, and watchOS stubs.docs/material-texture-indirection.md. perf ticket 008: visibility buffer (Nanite-style) replaces 4-MRT G-buffer #27 and perf ticket 009: GPU-driven rendering — indirect multi-draw + GPU cull #28 can consume these stable IDs without owning backend bind groups.Tier/stress evidence
Visual and performance qualification
Exact post-refactor source:
tools/quality/out/issue-130-final2-auto-full/result.jsontools/quality/out/issue-130-final2-vs-issue-129/result.jsonResults:
SSIM 0.999903679, luminance RMSE 0.001074704, mean OKLab delta 0.000035214, mean edge delta 0.000026091 — all within the checked-in gates.
approved baseline missingbecause governed portable baselines have not been human-approved. No baseline was installed or overwritten.Forced Tier C was also captured and compared:
tools/quality/out/issue-130-final-auto-full/result.jsontools/quality/out/issue-130-final-tier-c-full/result.jsontools/quality/out/issue-130-final-auto-vs-tier-c/result.jsontools/quality/out/issue-130-final-auto-vs-tier-c-sponza-rerun1/result.jsonAll Tier A-vs-C artifacts pass. The isolated repeat passes every timing bound (CPU mean delta 0.026 ms, GPU mean delta 0.802 ms); only the intentionally different selected-tier metadata remains.
Validation
material_system.rssplit to 1,960 lines)Android cross-check reached its native dependencies but the local machine has no
aarch64-linux-android-clang/clang++; the failure is the missing NDK compiler,not a Rust/source diagnostic. Android FFI coverage and the shared/wasm fallback
paths pass.