arkavo-org / arkavo-org/VRMMetalKit
MToon: specialize shader pipelines via [[function_constant]] feature flags
- Dominant language
- Swift
- Stars
- 6
- Forks
- 2
- Avg merge
- 18h 51m
- Merged PRs (30d)
- 26
Description
## Source
Romero perf review, item 4.
## Problem
The MToon shader is an ubershader — branches at runtime on uniform flags (matcap, rim, alpha-cutout, shade-shift texture, …). Apple Silicon handles uniform branches well, but the compiler still spills registers defensively for the worst-case path.
## Proposed change
Use Metal `[[function_constant(n)]]` to compile a dedicated pipeline variant per material's actual feature set. Extend `VRMPipelineCache` key from `(blendMode, …)` to `(vertexDescriptor, featureMask, blendMode)`. Variants compile lazily as new materials are seen; the cache amortises the cost.
## Affected
- `Sources/VRMMetalKit/Renderer/VRMPipelineCache.swift`
- `Sources/VRMMetalKit/Shaders/MToon.metal`
- `Sources/VRMMetalKit/Renderer/VRMRenderer.swift` (variant selection at bind time)
## Related
- #155 (MToon shader maintenance)
- #125 (per-light dedup — should land first or be coordinated)
- #121 (shared shader header — same area)
- #156 (measure)
Contributor guide
Research direction
Start with Sources/VRMMetalKit/Renderer/VRMPipelineCache.swift and Sources/VRMMetalKit/Shaders/MToon.metal, then trace variant selection in Sources/VRMMetalKit/Renderer/VRMRenderer.swift. Determine how feature flags map to function constants and how the cache key and lazy compilation interact with material binding. Done means feature-specific MToon pipeline variants are selected and cached correctly; coordinate with #125 and review related work in #155 and #121.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100