arkavo-org / arkavo-org/VRMMetalKit
Extract shared Metal shader header to prevent struct layout mismatches
- Dominant language
- Swift
- Stars
- 6
- Forks
- 2
- Avg merge
- 18h 51m
- Merged PRs (30d)
- 26
Description
## Problem
`Uniforms`, `MToonMaterial`, `SpringBoneParams`, `VertexIn`, and `VertexOut` structs are copy-pasted across multiple `.metal` files with subtle divergences. This has already caused at least one concrete mismatch (see related issue for MToonMaterial Block 12).
### Affected files
- `MToonShader.metal`
- `SkinnedShader.metal`
- `SpringBonePredict.metal`
- `SpringBoneCollision.metal`
- `SpringBoneDistance.metal`
- `DebugShaders.metal`
### Examples of current divergence
- `SpringBoneParams` in `SpringBonePredict.metal` has `dragMultiplier`, `_padding1`, `externalVelocity` (96 bytes). The same struct in `SpringBoneCollision.metal` and `SpringBoneDistance.metal` stops at `settlingFrames` (72 bytes). Works today only because missing fields are at the tail.
- `MToonMaterial` Block 12 differs between MToonShader and SkinnedShader (tracked separately).
## Proposed fix
Create a shared Metal header (e.g., `VRMShaderTypes.h`) with canonical struct definitions and `#include` it from all `.metal` files. Update `Makefile` shader compilation to handle the include path.
## Risk
Adding a field anywhere but the end of a divergent struct will silently break buffer offsets with no compiler error.
Contributor guide
Research direction
Read the six affected .metal files and the Makefile first, comparing the duplicated Uniforms, MToonMaterial, SpringBoneParams, VertexIn, and VertexOut definitions. Done means the structs have canonical shared definitions, all listed shaders include them, and the Makefile shader compilation handles the include path without struct layout divergence.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, computer-graphics
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100