vulkan+gryphn sync impl

This commit is contained in:
Greg Wells
2025-05-30 11:00:20 -04:00
parent 7ffae404bb
commit 014b315faa
11 changed files with 114 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
#include "vulkan_fence.h"
#include "output_device/vulkan_output_devices.h"
gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* device) {
fence->fence = malloc(sizeof(gnPlatformFence));
VkFenceCreateInfo fenceInfo = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
};
if (vkCreateFence(device->outputDevice->device, &fenceInfo, NULL, &fence->fence->fence) != VK_SUCCESS)
return GN_FAILED_TO_CREATE_FENCE;
return GN_SUCCESS;
}
void gnSignalFenceFn(struct gnFence_t* fence) {}
void gnWaitForFenceFn(struct gnFence_t* fence, uint64_t timeout) {
vkWaitForFences(fence->device->outputDevice->device, 1, &fence->fence->fence, VK_TRUE, timeout);
}
void gnResetFenceFn(struct gnFence_t* fence) {
vkResetFences(fence->device->outputDevice->device, 1, &fence->fence->fence);
}
void gnDestroyFenceFn(struct gnFence_t* fence) {
vkDestroyFence(fence->device->outputDevice->device, fence->fence->fence, NULL);
free(fence->fence);
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include <vulkan/vulkan.h>
#include "core/sync/fence/gryphn_fence.h"
typedef struct gnPlatformFence_t {
VkFence fence;
} gnPlatformFence;

View File

@@ -0,0 +1,17 @@
#include "vulkan_semaphore.h"
#include "output_device/vulkan_output_devices.h"
gnReturnCode gnCreateSemaphoreFn(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device) {
semaphore->semaphore = malloc(sizeof(gnPlatformSemaphore));
VkSemaphoreCreateInfo semaphoreInfo = {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
};
if (vkCreateSemaphore(device->outputDevice->device, &semaphoreInfo, NULL, &semaphore->semaphore->semaphore))
return GN_FAILED_TO_CREATE_SEMAPHORE;
return GN_SUCCESS;
}
void gnDestroySemaphoreFn(struct gnSemaphore_t* semaphore) {
vkDestroySemaphore(semaphore->device->outputDevice->device, semaphore->semaphore->semaphore, NULL);
free(semaphore->semaphore);
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include <vulkan/vulkan.h>
#include "core/sync/semaphore/gryphn_semaphore.h"
typedef struct gnPlatformSemaphore_t {
VkSemaphore semaphore;
} gnPlatformSemaphore;

View File

@@ -14,6 +14,8 @@
#include "command/command_pool/gryphn_command_pool.h" #include "command/command_pool/gryphn_command_pool.h"
#include "command/command_buffer/gryphn_command_buffer.h" #include "command/command_buffer/gryphn_command_buffer.h"
#include "renderpass/gryphn_render_pass.h" #include "renderpass/gryphn_render_pass.h"
#include "sync/fence/gryphn_fence.h"
#include "sync/semaphore/gryphn_semaphore.h"
typedef struct gnFunctions_t { typedef struct gnFunctions_t {
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info); gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
@@ -72,6 +74,15 @@ typedef struct gnDeviceFunctions_t {
gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info); gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info);
void (*_gnDestroyCommandPool)(struct gnCommandPool_t* commandPool); void (*_gnDestroyCommandPool)(struct gnCommandPool_t* commandPool);
gnReturnCode (*_gnCreateSemaphore)(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device);
void (*_gnDestroySemaphore)(struct gnSemaphore_t* semaphore);
gnReturnCode (*_gnCreateFence)(struct gnFence_t* fence, struct gnOutputDevice_t* device);
void (*_gnSignalFence)(struct gnFence_t* fence);
void (*_gnWaitForFence)(struct gnFence_t* fence, uint64_t timeout);
void (*_gnResetFence)(struct gnFence_t* fence);
void (*_gnDestroyFence)(struct gnFence_t* fence);
} gnDeviceFunctions; } gnDeviceFunctions;
typedef struct gnCommandFunctions_t { typedef struct gnCommandFunctions_t {

View File

@@ -81,6 +81,13 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti
gnLoadDLLFunction(lib, functions->_gnDestroyFramebuffer, "gnDestroyFramebufferFn"); gnLoadDLLFunction(lib, functions->_gnDestroyFramebuffer, "gnDestroyFramebufferFn");
gnLoadDLLFunction(lib, functions->_gnCreateCommandPool, "gnCreateCommandPoolFn"); gnLoadDLLFunction(lib, functions->_gnCreateCommandPool, "gnCreateCommandPoolFn");
gnLoadDLLFunction(lib, functions->_gnDestroyCommandPool, "gnDestroyCommandPoolFn"); gnLoadDLLFunction(lib, functions->_gnDestroyCommandPool, "gnDestroyCommandPoolFn");
gnLoadDLLFunction(lib, functions->_gnCreateSemaphore, "gnCreateSemaphoreFn");
gnLoadDLLFunction(lib, functions->_gnDestroySemaphore, "gnDestroySemaphoreFn");
gnLoadDLLFunction(lib, functions->_gnCreateFence, "gnCreateFenceFn");
gnLoadDLLFunction(lib, functions->_gnSignalFence, "gnSignalFenceFn");
gnLoadDLLFunction(lib, functions->_gnWaitForFence, "gnWaitForFenceFn");
gnLoadDLLFunction(lib, functions->_gnResetFence, "gnResetFenceFn");
gnLoadDLLFunction(lib, functions->_gnDestroyFence, "gnDestroyFenceFn");
} }
void gnLoadCommandFunctions(struct gnDynamicLibrary_t* lib, struct gnCommandFunctions_t* functions) { void gnLoadCommandFunctions(struct gnDynamicLibrary_t* lib, struct gnCommandFunctions_t* functions) {

View File

@@ -0,0 +1,24 @@
#include "gryphn_fence.h"
#include "core/gryphn_platform_functions.h"
#include "stdio.h"
gnReturnCode gnCreateFence(struct gnFence_t* fence, struct gnOutputDevice_t* device) {
fence->device = device;
fence->signaled = gnFalse;
return device->deviceFunctions->_gnCreateFence(fence, device);
}
void gnSignalFence(struct gnFence_t* fence) {
fence->signaled = gnTrue;
// fence->device->deviceFunctions->_gnSignalFence(fence);
}
void gnWaitForFence(struct gnFence_t* fence, uint64_t timeout) {
if (fence->signaled == gnTrue) return;
fence->device->deviceFunctions->_gnWaitForFence(fence, timeout);
}
void gnResetFence(struct gnFence_t* fence) {
fence->signaled = gnFalse;
fence->device->deviceFunctions->_gnResetFence(fence);
}
void gnDestroyFence(struct gnFence_t* fence) {
fence->device->deviceFunctions->_gnDestroyFence(fence);
}

View File

@@ -4,6 +4,8 @@
typedef struct gnFence_t { typedef struct gnFence_t {
struct gnPlatformFence_t* fence; struct gnPlatformFence_t* fence;
struct gnOutputDevice_t* device;
gnBool signaled;
} gnFence; } gnFence;
gnReturnCode gnCreateFence(struct gnFence_t* fence, struct gnOutputDevice_t* device); gnReturnCode gnCreateFence(struct gnFence_t* fence, struct gnOutputDevice_t* device);

View File

@@ -0,0 +1,10 @@
#include "gryphn_semaphore.h"
#include "core/gryphn_platform_functions.h"
gnReturnCode gnCreateSemaphore(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device) {
semaphore->device = device;
return device->deviceFunctions->_gnCreateSemaphore(semaphore, device);
}
void gnDestroySemaphore(struct gnSemaphore_t* semaphore) {
semaphore->device->deviceFunctions->_gnDestroySemaphore(semaphore);
}

View File

@@ -3,6 +3,7 @@
typedef struct gnSemaphore_t { typedef struct gnSemaphore_t {
struct gnPlatformSemaphore_t* semaphore; struct gnPlatformSemaphore_t* semaphore;
struct gnOutputDevice_t* device;
} gnSemaphore; } gnSemaphore;
gnReturnCode gnCreateSemaphore(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device); gnReturnCode gnCreateSemaphore(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device);

View File

@@ -30,7 +30,9 @@ typedef enum gnReturnCode_t {
GN_FAILED_TO_CREATE_COMMAND_POOL, GN_FAILED_TO_CREATE_COMMAND_POOL,
GN_FAILED_TO_BEGIN_RECORDING, GN_FAILED_TO_BEGIN_RECORDING,
GN_FAIELD_TO_END_RECORDING, GN_FAIELD_TO_END_RECORDING,
GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS,
GN_FAILED_TO_CREATE_FENCE,
GN_FAILED_TO_CREATE_SEMAPHORE
} gnReturnCode; } gnReturnCode;
typedef gnReturnCode gnErrorCode; typedef gnReturnCode gnErrorCode;
@@ -66,5 +68,7 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
case GN_FAILED_TO_BEGIN_RECORDING: return "GN_FAILED_TO_BEGIN_RECORDING"; case GN_FAILED_TO_BEGIN_RECORDING: return "GN_FAILED_TO_BEGIN_RECORDING";
case GN_FAIELD_TO_END_RECORDING: return "GN_FAIELD_TO_END_RECORDING"; case GN_FAIELD_TO_END_RECORDING: return "GN_FAIELD_TO_END_RECORDING";
case GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS: return "GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS"; case GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS: return "GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS";
case GN_FAILED_TO_CREATE_FENCE: return "GN_FAILED_TO_CREATE_FENCE";
case GN_FAILED_TO_CREATE_SEMAPHORE: return "GN_FAILED_TO_CREATE_SEMAPHORE";
} }
} }