redo some syncronization stuff
This commit is contained in:
@@ -32,6 +32,7 @@ gnReturnCode createMetalPresentationQueue(gnPresentationQueueHandle presentation
|
|||||||
}
|
}
|
||||||
[textureDescriptor release];
|
[textureDescriptor release];
|
||||||
|
|
||||||
|
presentationQueue->presentationQueue->neededImages = mtlImageNeededArrayListCreate();
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,18 +46,20 @@ void mtlTakeImageFromQueue(uint32_t* whereToPut, gnPresentationQueue queue, gnSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mtlAddImageBackToQueue(gnPresentationQueue queue, uint32_t index) {
|
void mtlAddImageBackToQueue(gnPresentationQueue queue, uint32_t index) {
|
||||||
|
uint32_tArrayListAdd(queue->presentationQueue->avaliableTextures, index);
|
||||||
if (mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) > 0) {
|
if (mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) > 0) {
|
||||||
mtlImageNeeded* needed = mtlImageNeededArrayListRefAt(queue->presentationQueue->neededImages, mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) - 1);
|
mtlImageNeeded* needed = mtlImageNeededArrayListRefAt(queue->presentationQueue->neededImages, mtlImageNeededArrayListCount(queue->presentationQueue->neededImages) - 1);
|
||||||
mtlTakeImageFromQueue(needed->whereToPut, queue, needed->semaphoreToSignal);
|
mtlTakeImageFromQueue(needed->whereToPut, queue, needed->semaphoreToSignal);
|
||||||
mtlImageNeededArrayListRemove(queue->presentationQueue->neededImages);
|
mtlImageNeededArrayListRemove(queue->presentationQueue->neededImages);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
uint32_tArrayListAdd(queue->presentationQueue->avaliableTextures, index);
|
uint32_tArrayListAdd(queue->presentationQueue->avaliableTextures, index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gnReturnCode getMetalPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex) {
|
gnReturnCode getMetalPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex) {
|
||||||
time_t last_time = time(NULL);
|
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);
|
time_t curr_time = time(NULL);
|
||||||
timeout -= (curr_time - last_time);
|
timeout -= (curr_time - last_time);
|
||||||
last_time = curr_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)
|
.message = gnCombineStrings(gnCreateString("Command buffer failed to run "), buffer.error.localizedDescription.UTF8String)
|
||||||
});
|
});
|
||||||
if (atomic_fetch_sub_explicit(&buffersLeft, 1, memory_order_acq_rel) == 1)
|
if (atomic_fetch_sub_explicit(&buffersLeft, 1, memory_order_acq_rel) == 1)
|
||||||
[fenceToSignal->fence->event setSignaledValue:fenceToSignal->fence->currentValue];
|
signalMetalFence(fenceToSignal);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[commandBuffer commit];
|
[commandBuffer commit];
|
||||||
|
@@ -10,5 +10,6 @@ typedef struct gnPlatformFence_t {
|
|||||||
|
|
||||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device);
|
gnReturnCode createMetalFence(gnFence fence, gnDevice device);
|
||||||
void waitForMetalFence(gnFence fence, uint64_t timeout);
|
void waitForMetalFence(gnFence fence, uint64_t timeout);
|
||||||
|
void signalMetalFence(gnFence fence);
|
||||||
void resetMetalFence(gnFence fence);
|
void resetMetalFence(gnFence fence);
|
||||||
void destroyMetalFence(gnFence fence);
|
void destroyMetalFence(gnFence fence);
|
||||||
|
@@ -2,16 +2,20 @@
|
|||||||
#include "devices/metal_output_devices.h"
|
#include "devices/metal_output_devices.h"
|
||||||
|
|
||||||
gnReturnCode createMetalFence(gnFence fence, gnDevice device) {
|
gnReturnCode createMetalFence(gnFence fence, gnDevice device) {
|
||||||
|
if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE;
|
||||||
|
|
||||||
fence->fence = malloc(sizeof(gnPlatformFence));
|
fence->fence = malloc(sizeof(gnPlatformFence));
|
||||||
fence->fence->event = [device->outputDevice->device newSharedEvent];
|
fence->fence->event = [[device->outputDevice->device newSharedEvent] retain];
|
||||||
fence->fence->currentValue = 0;
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void waitForMetalFence(gnFence fence, uint64_t timeout) {
|
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) {
|
void resetMetalFence(gnFence fence) {
|
||||||
fence->fence->currentValue++;
|
[fence->fence->event setSignaledValue:0];
|
||||||
}
|
}
|
||||||
void destroyMetalFence(gnFence fence) {
|
void destroyMetalFence(gnFence fence) {
|
||||||
[fence->fence->event release];
|
[fence->fence->event release];
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
#include "command/command_pool/gryphn_command_pool.h"
|
#include "command/command_pool/gryphn_command_pool.h"
|
||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||||
@@ -12,11 +14,11 @@ gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
gnCommandBufferHandle* buffersArray = malloc(sizeof(gnCommandBufferHandle) * count);
|
||||||
gnCommandBufferArrayListAt(buffers, i)->commandBuffer = malloc(sizeof(struct gnCommandBuffer_t));
|
gnReturnCode code = gnCommandPoolAllocateCommandBuffersFromPointer(buffersArray, count, commandPool);
|
||||||
gnCommandBufferArrayListAt(buffers, i)->commandPool = commandPool;
|
for (uint32_t i = 0; i < count; i++)
|
||||||
}
|
gnCommandBufferArrayListAdd(buffers, buffersArray[i]);
|
||||||
return gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferArrayListData(buffers), count, commandPool);
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
|
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
|
||||||
|
@@ -5,10 +5,8 @@
|
|||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
#include "validation_layers/function_loader/loader/function_loader.h"
|
#include "validation_layers/function_loader/loader/function_loader.h"
|
||||||
|
|
||||||
|
|
||||||
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
||||||
*instance = malloc(sizeof(struct gnInstance_t));
|
*instance = malloc(sizeof(struct gnInstance_t));
|
||||||
@@ -28,8 +26,8 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
|||||||
if (!gnIsExtensionSuppoted(info->coreAPI, info->extensions[i])) unsupportedExtension = GN_TRUE;
|
if (!gnIsExtensionSuppoted(info->coreAPI, info->extensions[i])) unsupportedExtension = GN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ((*instance)->enabledExtensions[GN_EXT_SYNCHRONIZATION]) (*instance)->layers.data[0].syncFunctions = loadAPISyncFunctions(info->coreAPI);
|
if ((*instance)->enabledExtensions[GN_EXT_SYNCHRONIZATION]) loaderLayerArrayListRefAt((*instance)->layers, 0)->syncFunctions = loadAPISyncFunctions(info->coreAPI);
|
||||||
// if ((*instance)->enabledExtensions[GN_EXT_QUEUES]) (*instance)->layers.data[0].queueFunctions = loadAPIQueueFunctions(info->coreAPI);
|
if ((*instance)->enabledExtensions[GN_EXT_QUEUES]) loaderLayerArrayListRefAt((*instance)->layers, 0)->queueFunctions = loadAPIQueueFunctions(info->coreAPI);
|
||||||
|
|
||||||
if (info->debuggerInfo.layerCount > 0) {
|
if (info->debuggerInfo.layerCount > 0) {
|
||||||
for (uint32_t i = 0; i < info->debuggerInfo.layerCount; i++) {
|
for (uint32_t i = 0; i < info->debuggerInfo.layerCount; i++) {
|
||||||
|
Reference in New Issue
Block a user