I think its a fence class
This commit is contained in:
10
rendering_api/metal/src/core/sync/fence/metal_fence.h
Normal file
10
rendering_api/metal/src/core/sync/fence/metal_fence.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "core/sync/fence/gryphn_fence.h"
|
||||||
|
#import <Metal/Metal.h>
|
||||||
|
#import <Metal/MTLEvent.h>
|
||||||
|
|
||||||
|
typedef struct gnPlatformFence_t {
|
||||||
|
id<MTLSharedEvent> fence;
|
||||||
|
MTLSharedEventListener* listener;
|
||||||
|
dispatch_semaphore_t semaphore;
|
||||||
|
} gnPlatformFence;
|
32
rendering_api/metal/src/core/sync/fence/metal_fence.m
Normal file
32
rendering_api/metal/src/core/sync/fence/metal_fence.m
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "metal_fence.h"
|
||||||
|
#include "core/devices/metal_output_devices.h"
|
||||||
|
|
||||||
|
gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* device) {
|
||||||
|
fence->fence = malloc(sizeof(gnPlatformFence));
|
||||||
|
|
||||||
|
fence->fence->fence = [device->outputDevice->device newSharedEvent];
|
||||||
|
fence->fence->listener = [[MTLSharedEventListener alloc] init];
|
||||||
|
fence->fence->semaphore = dispatch_semaphore_create(1);
|
||||||
|
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
void gnSignalFenceFn(struct gnFence_t* fence) {
|
||||||
|
dispatch_semaphore_signal(fence->fence->semaphore);
|
||||||
|
}
|
||||||
|
void gnWaitForFenceFn(struct gnFence_t* fence, uint64_t timeout) {
|
||||||
|
dispatch_semaphore_wait(fence->fence->semaphore, timeout);
|
||||||
|
}
|
||||||
|
void gnResetFenceFn(struct gnFence_t* fence) {
|
||||||
|
dispatch_semaphore_signal(fence->fence->semaphore);
|
||||||
|
[fence->fence->fence setSignaledValue:0];
|
||||||
|
[fence->fence->fence notifyListener:fence->fence->listener
|
||||||
|
atValue:1
|
||||||
|
block:^(id<MTLSharedEvent> ev, uint64_t val) {
|
||||||
|
dispatch_semaphore_signal(fence->fence->semaphore);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
void gnDestroyFenceFn(struct gnFence_t* fence) {
|
||||||
|
[fence->fence->fence release];
|
||||||
|
[fence->fence->listener release];
|
||||||
|
free(fence->fence);
|
||||||
|
}
|
Reference in New Issue
Block a user