mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
gpu/internal/metal: merge buffer address and size calls
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -21,6 +21,11 @@ import (
|
|||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include <Metal/Metal.h>
|
#include <Metal/Metal.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *addr;
|
||||||
|
NSUInteger size;
|
||||||
|
} slice;
|
||||||
|
|
||||||
static CFTypeRef queueNewBuffer(CFTypeRef queueRef) {
|
static CFTypeRef queueNewBuffer(CFTypeRef queueRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
id<MTLCommandQueue> queue = (__bridge id<MTLCommandQueue>)queueRef;
|
id<MTLCommandQueue> queue = (__bridge id<MTLCommandQueue>)queueRef;
|
||||||
@@ -298,17 +303,11 @@ static CFTypeRef newBuffer(CFTypeRef devRef, NSUInteger size, MTLResourceOptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *bufferAddress(CFTypeRef bufRef) {
|
static slice bufferContents(CFTypeRef bufRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
id<MTLBuffer> buf = (__bridge id<MTLBuffer>)bufRef;
|
id<MTLBuffer> buf = (__bridge id<MTLBuffer>)bufRef;
|
||||||
return [buf contents];
|
slice s = {.addr = [buf contents], .size = [buf length]};
|
||||||
}
|
return s;
|
||||||
}
|
|
||||||
|
|
||||||
static NSUInteger bufferLength(CFTypeRef bufRef) {
|
|
||||||
@autoreleasepool {
|
|
||||||
id<MTLBuffer> buf = (__bridge id<MTLBuffer>)bufRef;
|
|
||||||
return [buf length];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,9 +1105,8 @@ func (b *Buffer) Upload(data []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func bufferStore(buf C.CFTypeRef) []byte {
|
func bufferStore(buf C.CFTypeRef) []byte {
|
||||||
addr := C.bufferAddress(buf)
|
contents := C.bufferContents(buf)
|
||||||
n := C.bufferLength(buf)
|
return (*(*[1 << 30]byte)(contents.addr))[:contents.size:contents.size]
|
||||||
return (*(*[1 << 30]byte)(addr))[:n:n]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bufferSlice(buf C.CFTypeRef, off, len int) []byte {
|
func bufferSlice(buf C.CFTypeRef, off, len int) []byte {
|
||||||
|
|||||||
Reference in New Issue
Block a user