redo metal fence model
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
#import <Metal/Metal.h>
|
||||
#import <Metal/MTLEvent.h>
|
||||
|
||||
typedef struct gnPlatformFence_t {} gnPlatformFence;
|
||||
typedef struct gnPlatformFence_t {
|
||||
uint32_t currentValue;
|
||||
id<MTLSharedEvent> event;
|
||||
} gnPlatformFence;
|
||||
|
||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device);
|
||||
void singalMetalFence(gnFence fence);
|
||||
void waitForMetalFence(gnFence fence, uint64_t timeout);
|
||||
void resetMetalFence(gnFence fence);
|
||||
void destroyMetalFence(gnFence fence);
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
#include "metal_fence.h"
|
||||
#include "devices/metal_output_devices.h"
|
||||
|
||||
gnReturnCode createMetalFence(gnFence 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);
|
||||
|
||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device) {
|
||||
fence->fence = malloc(sizeof(gnPlatformFence));
|
||||
fence->fence->event = [device->outputDevice->device newSharedEvent];
|
||||
fence->fence->currentValue = 0;
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void singalMetalFence(gnFence fence) {
|
||||
// dispatch_semaphore_signal(fence->fence->semaphore);
|
||||
}
|
||||
void waitForMetalFence(gnFence fence, uint64_t timeout) {
|
||||
// dispatch_semaphore_wait(fence->fence->semaphore, timeout);
|
||||
while (fence->signaled == GN_FALSE) {}
|
||||
[fence->fence->event waitUntilSignaledValue:fence->fence->currentValue timeoutMS:timeout];
|
||||
}
|
||||
void resetMetalFence(gnFence 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);
|
||||
// }];
|
||||
fence->fence->currentValue++;
|
||||
}
|
||||
void destroyMetalFence(gnFence fence) {
|
||||
// [fence->fence->fence release];
|
||||
// [fence->fence->listener release];
|
||||
// free(fence->fence);
|
||||
[fence->fence->event release];
|
||||
free(fence->fence);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user