redo some syncronization stuff
This commit is contained in:
@@ -32,6 +32,7 @@ gnReturnCode createMetalPresentationQueue(gnPresentationQueueHandle presentation
|
||||
}
|
||||
[textureDescriptor release];
|
||||
|
||||
presentationQueue->presentationQueue->neededImages = mtlImageNeededArrayListCreate();
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -45,18 +46,20 @@ void mtlTakeImageFromQueue(uint32_t* whereToPut, gnPresentationQueue queue, gnSe
|
||||
}
|
||||
|
||||
void mtlAddImageBackToQueue(gnPresentationQueue queue, uint32_t index) {
|
||||
uint32_tArrayListAdd(queue->presentationQueue->avaliableTextures, index);
|
||||
if (mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) > 0) {
|
||||
mtlImageNeeded* needed = mtlImageNeededArrayListRefAt(queue->presentationQueue->neededImages, mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) - 1);
|
||||
mtlTakeImageFromQueue(needed->whereToPut, queue, needed->semaphoreToSignal);
|
||||
mtlImageNeededArrayListRemove(queue->presentationQueue->neededImages);
|
||||
}
|
||||
else
|
||||
else {
|
||||
uint32_tArrayListAdd(queue->presentationQueue->avaliableTextures, index);
|
||||
}
|
||||
}
|
||||
|
||||
gnReturnCode getMetalPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex) {
|
||||
time_t last_time = time(NULL);
|
||||
while(uint32_tArrayListCount(presentationQueue->presentationQueue->avaliableTextures) == 0 || timeout >= 0) {
|
||||
while(uint32_tArrayListCount(presentationQueue->presentationQueue->avaliableTextures) == 0 && timeout >= 0) {
|
||||
time_t curr_time = time(NULL);
|
||||
timeout -= (curr_time - last_time);
|
||||
last_time = curr_time;
|
||||
|
@@ -28,7 +28,7 @@ gnReturnCode metalSyncSubmit(gnOutputDevice device, gnSubmitSyncInfo info) {
|
||||
.message = gnCombineStrings(gnCreateString("Command buffer failed to run "), buffer.error.localizedDescription.UTF8String)
|
||||
});
|
||||
if (atomic_fetch_sub_explicit(&buffersLeft, 1, memory_order_acq_rel) == 1)
|
||||
[fenceToSignal->fence->event setSignaledValue:fenceToSignal->fence->currentValue];
|
||||
signalMetalFence(fenceToSignal);
|
||||
}];
|
||||
|
||||
[commandBuffer commit];
|
||||
|
@@ -10,5 +10,6 @@ typedef struct gnPlatformFence_t {
|
||||
|
||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device);
|
||||
void waitForMetalFence(gnFence fence, uint64_t timeout);
|
||||
void signalMetalFence(gnFence fence);
|
||||
void resetMetalFence(gnFence fence);
|
||||
void destroyMetalFence(gnFence fence);
|
||||
|
@@ -2,16 +2,20 @@
|
||||
#include "devices/metal_output_devices.h"
|
||||
|
||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device) {
|
||||
if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE;
|
||||
|
||||
fence->fence = malloc(sizeof(gnPlatformFence));
|
||||
fence->fence->event = [device->outputDevice->device newSharedEvent];
|
||||
fence->fence->currentValue = 0;
|
||||
fence->fence->event = [[device->outputDevice->device newSharedEvent] retain];
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void waitForMetalFence(gnFence fence, uint64_t timeout) {
|
||||
[fence->fence->event waitUntilSignaledValue:fence->fence->currentValue timeoutMS:timeout];
|
||||
[fence->fence->event waitUntilSignaledValue:1 timeoutMS:timeout];
|
||||
}
|
||||
void signalMetalFence(gnFence fence) {
|
||||
[fence->fence->event setSignaledValue:1];
|
||||
}
|
||||
void resetMetalFence(gnFence fence) {
|
||||
fence->fence->currentValue++;
|
||||
[fence->fence->event setSignaledValue:0];
|
||||
}
|
||||
void destroyMetalFence(gnFence fence) {
|
||||
[fence->fence->event release];
|
||||
|
Reference in New Issue
Block a user