Skip to content

fix(hal/metal/device.go): [*Device.CreateComputePipeline] and [*Device.CreateRenderPipeline] resolves translated entrypoint name by [naga.TranslationInfo]#167

Merged
kolkov merged 2 commits intogogpu:mainfrom
k-chimi:fix-metal-entrypoint-name-resolve
May 1, 2026

Conversation

@k-chimi
Copy link
Copy Markdown
Contributor

@k-chimi k-chimi commented May 1, 2026

resolve #168

$ CGO_ENABLED=0 go run ./examples/compute-copy/
=== Compute Shader: Scaled Copy ===

1. Creating instance... OK
2. Requesting adapter... OK (Apple M4 Max)
3. Creating device... OK
4. Input: 1024 float32 elements, scale = 2.5
5. Creating buffers... OK
6. Creating compute pipeline... OK
7. Dispatching compute... OK
8. Reading results... OK

Sample results (first 8):
  [0] 1.0 * 2.5 = 2.5
  [1] 2.0 * 2.5 = 5.0
  [2] 3.0 * 2.5 = 7.5
  [3] 4.0 * 2.5 = 10.0
  [4] 5.0 * 2.5 = 12.5
  [5] 6.0 * 2.5 = 15.0
  [6] 7.0 * 2.5 = 17.5
  [7] 8.0 * 2.5 = 20.0

PASS: all 1024 elements match (tolerance=0.0010)

…vice.CreateRenderPipeline]` resolves translated entrypoint name by `[naga.TranslationInfo]`
@k-chimi k-chimi requested a review from kolkov as a code owner May 1, 2026 05:07
@k-chimi k-chimi changed the title fix(hal/metal/device.go): [*Device.CreateComputePipeline] and `[*De… fix(hal/metal/device.go): [*Device.CreateComputePipeline] and [*Device.CreateRenderPipeline] resolves translated entrypoint name by [naga.TranslationInfo] May 1, 2026
Copy link
Copy Markdown
Contributor

@kolkov kolkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix! Correctly identified the root cause — naga MSL renames reserved words like mainmain_, and the Metal HAL was using the original name. Matches Rust wgpu-hal pattern (device.rs:231).

Two bugs to fix before merge:

1. Vertex entry point looks up in fragmentModule (line ~607)

entrypointName := desc.Vertex.EntryPoint
if translated, ok := fragmentModule.translatedEntrypointNames[entrypointName]; ok {

Should be vertexModule, not fragmentModule. Works now only because vertex+fragment typically share the same ShaderModule, but breaks with separate modules.

2. getWorkgroupSize receives translated name but map uses original names (line ~842)

workgroupSize := getWorkgroupSize(computeModule, entrypointName)

extractWorkgroupSizes stores ep.Name (original) as key. After translation "main""main_", lookup misses → falls back to {64,1,1} instead of the actual workgroup size. Should use desc.Compute.EntryPoint (original name) here, not entrypointName.

Minor

  • Field name translatedEntrypointNamesentryPointNames (Go convention, matches naga TranslationInfo.EntryPointNames)
  • Non-WGSL path: map[string]string{}nil (nil map lookup returns false, same behavior, simpler)

@k-chimi
Copy link
Copy Markdown
Contributor Author

k-chimi commented May 1, 2026

Thanks! I've fix my code! Please check it when you have a moment 🙏

@k-chimi k-chimi requested a review from kolkov May 1, 2026 07:45
Copy link
Copy Markdown
Contributor

@kolkov kolkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues fixed. LGTM! 🎉

  • vertexModule correctly used for vertex entry point lookup
  • entrypointNames field name is cleaner
  • getWorkgroupSize correctly uses original name

Great contribution — solid root cause analysis and clean fix.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit e100226 into gogpu:main May 1, 2026
11 checks passed
@k-chimi k-chimi deleted the fix-metal-entrypoint-name-resolve branch May 1, 2026 07:56
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.

Bug(metal)?: [*Device.CreateComputePipeline] fails to resolve entrypoint in some cases

2 participants