Skip to content

Commit de99217

Browse files
authored
fix(msl): use references (&) instead of pointers (*) for buffer parameters
Buffer parameters now generate 'constant T& name' instead of 'constant T* name'. Pointer syntax required '->' for member access while expression writer generates dot access, causing Metal compilation errors on Apple Silicon (ui#23).
1 parent bb5e4a5 commit de99217

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.5] - 2026-03-04
9+
10+
### Fixed
11+
12+
#### MSL Backend
13+
- **Buffer parameters use references (`&`) instead of pointers (`*`)** — buffer parameters now generate `constant Uniforms& u [[buffer(0)]]` (reference) instead of `constant Uniforms* u [[buffer(0)]]` (pointer); pointer syntax required `->` or `(*u).` for member access while the expression writer generates `.` access, causing Metal compilation errors on Apple Silicon ([gogpu/ui#23](https://github.com/gogpu/ui/issues/23))
14+
815
## [0.14.4] - 2026-03-01
916

1017
### Fixed

msl/expressions.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,12 +1146,9 @@ func (w *Writer) isIntegerExpression(handle ir.ExpressionHandle) bool {
11461146
}
11471147

11481148
func (w *Writer) pointerNeedsDeref(pt ir.PointerType) bool {
1149-
switch pt.Space {
1150-
case ir.SpaceUniform, ir.SpaceStorage, ir.SpacePushConstant:
1151-
return true
1152-
default:
1153-
return false
1154-
}
1149+
// Buffer parameters use references (&) in MSL, not pointers (*).
1150+
// References don't need explicit dereference.
1151+
return false
11551152
}
11561153

11571154
func (w *Writer) shouldDerefPointer(handle ir.ExpressionHandle) bool {

msl/functions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ func (w *Writer) writeGlobalResourceParam(handle uint32, global *ir.GlobalVariab
528528
typeName := w.writeTypeName(global.Type, StorageAccess(0))
529529

530530
if space == spaceConstant || space == spaceDevice {
531-
w.write("%s %s* %s [[buffer(%d)]]", space, typeName, name, binding)
531+
w.write("%s %s& %s [[buffer(%d)]]", space, typeName, name, binding)
532532
} else {
533533
w.write("%s %s [[buffer(%d)]]", typeName, name, binding)
534534
}

snapshot/testdata/golden/msl/collatz.msl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ uint collatz_iterations(uint n_base) {
4242
}
4343

4444
kernel void main_(metal::uint3 gid [[thread_position_in_grid]],
45-
device Data* data [[buffer(0)]]) {
45+
device Data& data [[buffer(0)]]) {
4646
uint _fc9 = collatz_iterations(data.values[gid[0]]);
4747
data.values[gid[0]] = _fc9;
4848
}

snapshot/testdata/golden/msl/globals.msl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ T _naga_mod(T lhs, D rhs) {
2727
}
2828

2929
kernel void main_(uint local_idx [[thread_index_in_threadgroup]],
30-
constant Uniforms* uniforms [[buffer(0)]]) {
30+
constant Uniforms& uniforms [[buffer(0)]]) {
3131
shared_data.inner[local_idx] = (uniforms.scale * float(local_idx));
3232
threadgroup_barrier(mem_flags::mem_threadgroup);
3333
}

snapshot/testdata/golden/msl/uniforms_mvp.msl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct vs_main_Output {
3838
};
3939

4040
vertex vs_main_Output vs_main(vs_main_Input _input [[stage_in]],
41-
constant Uniforms* uniforms [[buffer(0)]]) {
41+
constant Uniforms& uniforms [[buffer(0)]]) {
4242
auto position_ = _input.position_;
4343
VertexOutput out_ = VertexOutput();
4444

@@ -57,7 +57,7 @@ struct fs_main_Input {
5757
};
5858

5959
fragment metal::float4 fs_main(fs_main_Input _input [[stage_in]],
60-
constant Uniforms* uniforms [[buffer(0)]]) {
60+
constant Uniforms& uniforms [[buffer(0)]]) {
6161
auto world_pos = _input.world_pos;
6262

6363
return metal::float4(((metal::normalize(world_pos) * 0.5) + 0.5), 1.0);

snapshot/testdata/golden/msl/workgroup_memory.msl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ T _naga_mod(T lhs, D rhs) {
2626
}
2727

2828
kernel void main_(uint lid [[thread_index_in_threadgroup]], metal::uint3 gid [[thread_position_in_grid]],
29-
constant Params* params [[buffer(0)]],
30-
device type_6* output [[buffer(1)]]) {
29+
constant Params& params [[buffer(0)]],
30+
device type_6& output [[buffer(1)]]) {
3131
shared_data.inner[lid] = (float(gid[0]) * 0.5);
3232
threadgroup_barrier(mem_flags::mem_threadgroup);
3333
if ((lid < 128u)) {

0 commit comments

Comments
 (0)