Skip to content

Commit 8705424

Browse files
committed
codegen: Handle a few more cases, populate some mps structs
1 parent aeeaf4b commit 8705424

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

generate/codegen/gen_function.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
177177
sb.WriteString(cw.IndentStr + fmt.Sprintf(" (*C.%s)(unsafe.Pointer(&%s))", tt.CName(), p.GoName()))
178178
case *typing.IDType:
179179
sb.WriteString(cw.IndentStr + fmt.Sprintf(" %s.Ptr()", p.GoName()))
180+
case *typing.ClassType, *typing.ProtocolType:
181+
sb.WriteString(cw.IndentStr + fmt.Sprintf(" unsafe.Pointer(&%s)", p.GoName()))
180182
default:
181183
sb.WriteString(cw.IndentStr + p.GoName())
182184
}

macos/mps/functions.gen.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func StateBatchResourceSize(batch *foundation.Array) uint {
4949
func HintTemporaryMemoryHighWaterMark(cmdBuf metal.CommandBufferWrapper, bytes uint) {
5050
C.HintTemporaryMemoryHighWaterMark(
5151
// *typing.ProtocolType
52-
cmdBuf,
52+
unsafe.Pointer(&cmdBuf),
5353
// *typing.PrimitiveType
5454
C.uint(bytes),
5555
)
@@ -73,7 +73,7 @@ func ImageBatchResourceSize(batch *foundation.Array) uint {
7373
func SetHeapCacheDuration(cmdBuf metal.CommandBufferWrapper, seconds float64) {
7474
C.SetHeapCacheDuration(
7575
// *typing.ProtocolType
76-
cmdBuf,
76+
unsafe.Pointer(&cmdBuf),
7777
// *typing.PrimitiveType
7878
C.double(seconds),
7979
)
@@ -101,7 +101,7 @@ func StateBatchSynchronize(batch *foundation.Array, cmdBuf metal.CommandBufferWr
101101
// *typing.PointerType
102102
(*C.MPSStateBatch)(unsafe.Pointer(&batch)),
103103
// *typing.ProtocolType
104-
cmdBuf,
104+
unsafe.Pointer(&cmdBuf),
105105
)
106106
}
107107

@@ -180,10 +180,10 @@ func GetCustomKernelBroadcastSourceIndex(c CustomKernelArgumentCount, sourceInde
180180
func GetImageType(image Image) ImageType {
181181
rv := C.GetImageType(
182182
// *typing.ClassType
183-
image,
183+
unsafe.Pointer(&image),
184184
)
185185
// *typing.AliasType
186-
return ImageType(rv)
186+
return *(*ImageType)(unsafe.Pointer(&rv))
187187
}
188188

189189
// Returns the integer division parameters for a specified divisor. [Full Topic]
@@ -222,7 +222,7 @@ func ImageBatchSynchronize(batch *foundation.Array, cmdBuf metal.CommandBufferWr
222222
// *typing.PointerType
223223
(*C.MPSImageBatch)(unsafe.Pointer(&batch)),
224224
// *typing.ProtocolType
225-
cmdBuf,
225+
unsafe.Pointer(&cmdBuf),
226226
)
227227
}
228228

@@ -232,7 +232,7 @@ func ImageBatchSynchronize(batch *foundation.Array, cmdBuf metal.CommandBufferWr
232232
func SupportsMTLDevice(device metal.DeviceWrapper) bool {
233233
rv := C.SupportsMTLDevice(
234234
// *typing.ProtocolType
235-
device,
235+
unsafe.Pointer(&device),
236236
)
237237
// *typing.PrimitiveType
238238
return bool(rv)

macos/mps/mps_structs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ type ImageCoordinate struct{}
3131

3232
// https://developer.apple.com/documentation/metalperformanceshaders/mpsndarrayoffsets?language=objc
3333
type NDArrayOffsets struct{}
34+
35+
// https://developer.apple.com/documentation/metalperformanceshaders/mpscustomkernelargumentcount?language=objc
36+
type CustomKernelArgumentCount struct {
37+
broadcastTextureCount uint64
38+
destinationTextureCount uint64
39+
sourceTextureCount uint64
40+
}
41+
42+
// https://developer.apple.com/documentation/metalperformanceshaders/mpsintegerdivisionparams?language=objc
43+
type IntegerDivisionParams struct {
44+
addend uint16
45+
divisor uint16
46+
recip uint16
47+
shift uint16
48+
}

0 commit comments

Comments
 (0)