From 7acc031ccf0273b8ee9e4e7122e2962ab7e585c9 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 23 Aug 2021 17:56:57 +0200 Subject: [PATCH] gpu/internal/metal: merge buffer address and size calls Signed-off-by: Elias Naur --- gpu/internal/metal/metal_darwin.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gpu/internal/metal/metal_darwin.go b/gpu/internal/metal/metal_darwin.go index 2722b5dd..9479c2ab 100644 --- a/gpu/internal/metal/metal_darwin.go +++ b/gpu/internal/metal/metal_darwin.go @@ -21,6 +21,11 @@ import ( #include #include +typedef struct { + void *addr; + NSUInteger size; +} slice; + static CFTypeRef queueNewBuffer(CFTypeRef queueRef) { @autoreleasepool { id queue = (__bridge id)queueRef; @@ -298,17 +303,11 @@ static CFTypeRef newBuffer(CFTypeRef devRef, NSUInteger size, MTLResourceOptions } } -static void *bufferAddress(CFTypeRef bufRef) { +static slice bufferContents(CFTypeRef bufRef) { @autoreleasepool { id buf = (__bridge id)bufRef; - return [buf contents]; - } -} - -static NSUInteger bufferLength(CFTypeRef bufRef) { - @autoreleasepool { - id buf = (__bridge id)bufRef; - return [buf length]; + slice s = {.addr = [buf contents], .size = [buf length]}; + return s; } } @@ -1106,9 +1105,8 @@ func (b *Buffer) Upload(data []byte) { } func bufferStore(buf C.CFTypeRef) []byte { - addr := C.bufferAddress(buf) - n := C.bufferLength(buf) - return (*(*[1 << 30]byte)(addr))[:n:n] + contents := C.bufferContents(buf) + return (*(*[1 << 30]byte)(contents.addr))[:contents.size:contents.size] } func bufferSlice(buf C.CFTypeRef, off, len int) []byte {