Skip to content

fix(msl): vertex stage_in for struct args, metal::discard_fragment namespace#38

Merged
kolkov merged 4 commits intomainfrom
fix/msl-stage-in-discard
Mar 1, 2026
Merged

fix(msl): vertex stage_in for struct args, metal::discard_fragment namespace#38
kolkov merged 4 commits intomainfrom
fix/msl-stage-in-discard

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Mar 1, 2026

Summary

Fix two MSL backend bugs that caused Metal shader compilation failures on Apple Silicon (reported in gogpu/ui#23):

  • Vertex [[stage_in]] for struct-typed arguments — vertex shaders with struct inputs (e.g., fn vs_main(in: VertexInput)) now correctly generate a synthesized _Input struct with [[attribute(N)]] members and [[stage_in]] parameter; previously gated to fragment-only
  • metal::discard_fragment() namespace — add required metal:: prefix; bare discard_fragment() was rejected by Metal compiler

Also includes test coverage improvements from previous sessions.

Changes

File Change
msl/functions.go Remove fragment-only gate, use binding-based attribute generation
msl/statements.go Add Namespace prefix to discard_fragment()
msl/statements_test.go Update TestMSL_Kill expected output
snapshot/testdata/golden/msl/vertex_colors.msl Update golden with vs_main_Input struct
CHANGELOG.md Add v0.14.4 entry

Test plan

  • All naga tests pass (go test ./...)
  • All 29 snapshot tests pass across 4 backends
  • go fmt clean
  • Lint clean (only pre-existing revive issue in glsl test)
  • Real Metal validation by @rcarlier on Apple M3 after release

kolkov added 3 commits March 1, 2026 17:59
- msl/expressions_test.go: MSL expression generation tests
- msl/statements_test.go: MSL statement generation tests
- msl/types_test.go: MSL type mapping, entry point tests
- glsl/expressions_test.go: GLSL type/expression/statement tests
- ir/validate_expression_test.go: comprehensive expression/type validation
- Removed old validate_test.go (superseded by new comprehensive tests)
…mespace

- Remove fragment-only gate in writeEntryPointInputStruct, allowing
  vertex shaders with struct-typed inputs (e.g. fn vs_main(in: VertexInput))
  to generate synthesized _Input struct with [[attribute(N)]] members
- Use member binding-based attribute generation (locationInputAttribute,
  builtinInputAttribute) instead of hardcoded position/user attributes
- Add metal:: namespace prefix to discard_fragment() call

Fixes gogpu/ui#23
@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
msl/functions.go 46.66% 7 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

- Add fallback attribute generation for struct members without explicit
  bindings (fragment: [[position]]/[[user(locnN)]], vertex: [[attribute(N)]])
- Fix revive lint: globalIdBinding → globalIDBinding
- Add cyclop nolint for writeEntryPointInputStruct
@kolkov kolkov merged commit bb5e4a5 into main Mar 1, 2026
10 of 11 checks passed
@kolkov kolkov deleted the fix/msl-stage-in-discard branch March 1, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant