From 6e22c85e43c20be7f8ae7f76ca7338ce4634a8ea Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Wed, 9 Jul 2025 20:00:44 -0400 Subject: [PATCH] finish moving some stuff over to the extension --- include/gryphn/gryphn.h | 1 + .../apis/vulkan/loader/vulkan_device_loader.c | 12 +-------- projects/apis/vulkan/loader/vulkan_loader.h | 2 ++ .../apis/vulkan/loader/vulkan_sync_loader.c | 18 +++++++++++++ .../vulkan_presentation_queue.c | 12 +++++++++ .../vulkan_presentation_queue.h | 1 + .../gryphn_presentation_queue.h | 1 - projects/extensions/CMakeLists.txt | 1 + .../gryphn_synced_presentation_queue.c | 6 +++++ .../gryphn_synced_presentation_queue.h | 6 +++++ projects/loader/src/gryphn_loader.c | 27 +++++++++++++++++-- .../function_loader/CMakeLists.txt | 3 ++- .../function_loader/loader/function_loader.c | 23 +++++++++------- .../function_loader/loader/function_loader.h | 3 +++ 14 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 projects/apis/vulkan/loader/vulkan_sync_loader.c create mode 100644 projects/extensions/synchronization/gryphn_synced_presentation_queue.c create mode 100644 projects/extensions/synchronization/gryphn_synced_presentation_queue.h diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index 168857f..3c9771f 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -27,3 +27,4 @@ // extenions #include #include +#include diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c index 06465b8..7b54206 100644 --- a/projects/apis/vulkan/loader/vulkan_device_loader.c +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -9,8 +9,6 @@ #include #include #include -#include -#include #include #include #include @@ -18,7 +16,7 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { return (gnDeviceFunctions){ ._gnCreatePresentationQueue = createPresentationQueue, - // ._gnPresentationQueueGetImageAsync = getPresentQueueImageAsync, + ._gnPresentationQueueGetImage = getVulkanPresentQueueImage, ._gnDestroyPresentationQueue = destroyPresentationQueue, ._gnCreateShaderModule = createShaderModule, @@ -36,9 +34,6 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { ._gnCreateCommandPool = createCommandPool, ._gnDestroyCommandPool = destroyCommandPool, - // ._gnCreateSemaphore = createSemaphore, - // ._gnDestroySemaphore = destroySemaphore, - ._gnCreateBuffer = createBuffer, ._gnBufferData = bufferData, ._gnBufferSubData = vulkanBufferSubData, @@ -57,11 +52,6 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { ._gnTextureData = textureData, ._gnDestroyTexture = destroyTexture, - // ._gnCreateFence = createFence, - // ._gnWaitForFence = waitForFence, - // ._gnResetFence = resetFence, - // ._gnDestroyFence = destroyFence, - ._gnSubmit = submit, ._gnPresent = present, diff --git a/projects/apis/vulkan/loader/vulkan_loader.h b/projects/apis/vulkan/loader/vulkan_loader.h index b6f706d..8da5b3d 100644 --- a/projects/apis/vulkan/loader/vulkan_loader.h +++ b/projects/apis/vulkan/loader/vulkan_loader.h @@ -2,7 +2,9 @@ #include "loader/src/gryphn_instance_functions.h" #include "loader/src/gryphn_device_functions.h" #include "loader/src/gryphn_command_functions.h" +#include "extensions/synchronization/loader/sync_functions.h" gnInstanceFunctions loadVulkanInstanceFunctions(); gnDeviceFunctions loadVulkanDeviceFunctions(); gnCommandFunctions loadVulkanCommandFunctions(); +gnSyncExtFunctions loadVulkanSyncFunctions(); diff --git a/projects/apis/vulkan/loader/vulkan_sync_loader.c b/projects/apis/vulkan/loader/vulkan_sync_loader.c new file mode 100644 index 0000000..ab44667 --- /dev/null +++ b/projects/apis/vulkan/loader/vulkan_sync_loader.c @@ -0,0 +1,18 @@ +#include "vulkan_loader.h" +#include +#include +#include "presentation_queue/vulkan_presentation_queue.h" + +gnSyncExtFunctions loadVulkanSyncFunctions() { + return (gnSyncExtFunctions){ + ._gnPresentationQueueGetImageAsync = getPresentQueueImageAsync, + + ._gnCreateSemaphore = createSemaphore, + ._gnDestroySemaphore = destroySemaphore, + + ._gnCreateFence = createFence, + ._gnWaitForFence = waitForFence, + ._gnResetFence = resetFence, + ._gnDestroyFence = destroyFence, + }; +} diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c index 6ada9d4..26c6587 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -81,6 +81,18 @@ gnReturnCode createPresentationQueue(gnPresentationQueueHandle presentationQueue return GN_SUCCESS; } +gnReturnCode getVulkanPresentQueueImage(gnPresentationQueueHandle presentationQueue, uint32_t* imageIndex) { + VkResult result = vkAcquireNextImageKHR( + presentationQueue->outputDevice->outputDevice->device, + presentationQueue->presentationQueue->swapChain, + UINT64_MAX, VK_NULL_HANDLE, VK_NULL_HANDLE, imageIndex); + + if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; + if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; + + return GN_SUCCESS; +} + gnReturnCode getPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex) { VkResult result = vkAcquireNextImageKHR( presentationQueue->outputDevice->outputDevice->device, diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.h b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.h index 1bbc230..82226dc 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.h +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.h @@ -10,5 +10,6 @@ typedef struct gnPlatformPresentationQueue_t { } gnPlatformPresentationQueue; gnReturnCode createPresentationQueue(gnPresentationQueueHandle presentationQueue, const gnDevice device, gnPresentationQueueInfo presentationInfo); +gnReturnCode getVulkanPresentQueueImage(gnPresentationQueueHandle presentationQueue, uint32_t* imageIndex); gnReturnCode getPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex); void destroyPresentationQueue(gnPresentationQueueHandle queue); diff --git a/projects/core/src/presentation_queue/gryphn_presentation_queue.h b/projects/core/src/presentation_queue/gryphn_presentation_queue.h index 7798f28..71921c5 100644 --- a/projects/core/src/presentation_queue/gryphn_presentation_queue.h +++ b/projects/core/src/presentation_queue/gryphn_presentation_queue.h @@ -28,7 +28,6 @@ struct gnPresentationQueue_t { #endif gnReturnCode gnCreatePresentationQueue(gnPresentationQueueHandle* presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo); -// gnReturnCode gnPresentationQueueGetImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); gnReturnCode gnPresentationQueueGetImage(gnPresentationQueue presentationQueue, uint32_t* imageIndex); uint32_t gnGetPresentationQueueImageCount(gnPresentationQueueHandle presentationQueue); gnTextureHandle gnGetPresentationQueueImage(gnPresentationQueueHandle presentationQueue, uint32_t index); diff --git a/projects/extensions/CMakeLists.txt b/projects/extensions/CMakeLists.txt index d5a1a72..0540e09 100644 --- a/projects/extensions/CMakeLists.txt +++ b/projects/extensions/CMakeLists.txt @@ -8,3 +8,4 @@ target_include_directories(GryphnExtensions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/. target_include_directories(GryphnExtensions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/) target_include_directories(GryphnExtensions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/src/) target_include_directories(GryphnExtensions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) +target_include_directories(GryphnExtensions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../platform/) diff --git a/projects/extensions/synchronization/gryphn_synced_presentation_queue.c b/projects/extensions/synchronization/gryphn_synced_presentation_queue.c new file mode 100644 index 0000000..ebb8906 --- /dev/null +++ b/projects/extensions/synchronization/gryphn_synced_presentation_queue.c @@ -0,0 +1,6 @@ +#include "gryphn_synced_presentation_queue.h" +#include "core/src/presentation_queue/gryphn_presentation_queue.h" + +gnReturnCode gnPresentationQueueGetImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex) { + return presentationQueue->outputDevice->instance->callingLayer->syncFunctions._gnPresentationQueueGetImageAsync(presentationQueue, timeout, semaphore, imageIndex); +} diff --git a/projects/extensions/synchronization/gryphn_synced_presentation_queue.h b/projects/extensions/synchronization/gryphn_synced_presentation_queue.h new file mode 100644 index 0000000..eed5f27 --- /dev/null +++ b/projects/extensions/synchronization/gryphn_synced_presentation_queue.h @@ -0,0 +1,6 @@ +#pragma once +#include "stdint.h" +#include "utils/gryphn_error_code.h" +#include "core/src/gryphn_handles.h" + +gnReturnCode gnPresentationQueueGetImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); diff --git a/projects/loader/src/gryphn_loader.c b/projects/loader/src/gryphn_loader.c index c7a7f08..2936236 100644 --- a/projects/loader/src/gryphn_loader.c +++ b/projects/loader/src/gryphn_loader.c @@ -67,6 +67,25 @@ gnCommandFunctions loadAPICommandFunctions(gnRenderingAPI api) { } } +gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api) { + switch (api) { + case GN_RENDERINGAPI_NONE: return (gnSyncExtFunctions){ NULL }; +#ifdef GN_API_VULKAN + case GN_RENDERINGAPI_VULKAN: return loadVulkanSyncFunctions(); +#endif + + case GN_RENDERINGAPI_SOFTWARE: return (gnSyncExtFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX11: return (gnSyncExtFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX12: return (gnSyncExtFunctions){ NULL }; + case GN_RENDERINGAPI_OPENGL: return (gnSyncExtFunctions){ NULL }; +#ifdef GN_API_METAL + case GN_RENDERINGAPI_METAL: return loadMetalSyncFunctions(); +#endif + + default: return (gnSyncExtFunctions){NULL}; + } +} + loaderLayer null_layer() { return (loaderLayer){ .instanceFunctions = (gnInstanceFunctions){ NULL }, @@ -79,7 +98,9 @@ loaderLayer api_loaded_layer(gnRenderingAPI api) { return (loaderLayer){ .instanceFunctions = loadAPIInstanceFunctions(api), .deviceFunctions = loadAPIDeviceFunctions(api), - .commandFunctions = loadAPICommandFunctions(api) + .commandFunctions = loadAPICommandFunctions(api), + + .syncFunctions = loadAPISyncFunctions(api) }; } @@ -87,7 +108,9 @@ loaderLayer function_check_layer() { return (loaderLayer){ .instanceFunctions = loadFunctionLoaderInstanceFunctions(), .deviceFunctions = loadFunctionLoaderDeviceFunctions(), - .commandFunctions = loadFunctionLoaderCommandFunctions() + .commandFunctions = loadFunctionLoaderCommandFunctions(), + + .syncFunctions = loadFunctionLoaderSyncExtFunctions() }; } diff --git a/projects/validation_layers/function_loader/CMakeLists.txt b/projects/validation_layers/function_loader/CMakeLists.txt index eea374d..f8aa044 100644 --- a/projects/validation_layers/function_loader/CMakeLists.txt +++ b/projects/validation_layers/function_loader/CMakeLists.txt @@ -2,8 +2,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS on) project(GryphnFunctionValidator) file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS "src/*.c") +file(GLOB_RECURSE EXT_FILES CONFIGURE_DEPENDS "extensions/*.c") file(GLOB_RECURSE LOADER_FILES CONFIGURE_DEPENDS "loader/*.c") -add_library(GryphnFunctionValidator STATIC ${SOURCE_FILES} ${LOADER_FILES}) +add_library(GryphnFunctionValidator STATIC ${SOURCE_FILES} ${EXT_FILES} ${LOADER_FILES}) target_include_directories(GryphnFunctionValidator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/) target_include_directories(GryphnFunctionValidator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../) target_include_directories(GryphnFunctionValidator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/src/) diff --git a/projects/validation_layers/function_loader/loader/function_loader.c b/projects/validation_layers/function_loader/loader/function_loader.c index 10571f0..623a8bd 100644 --- a/projects/validation_layers/function_loader/loader/function_loader.c +++ b/projects/validation_layers/function_loader/loader/function_loader.c @@ -40,7 +40,6 @@ gnInstanceFunctions loadFunctionLoaderInstanceFunctions() { gnDeviceFunctions loadFunctionLoaderDeviceFunctions() { return (gnDeviceFunctions){ ._gnCreatePresentationQueue = checkCreatePresentationQueue, - // ._gnPresentationQueueGetImageAsync = checkPresentationQueueGetImageAsync, ._gnPresentationQueueGetImage = checkPresentationQueueGetImage, ._gnDestroyPresentationQueue = checkDestroyPresentationQueue, @@ -59,9 +58,6 @@ gnDeviceFunctions loadFunctionLoaderDeviceFunctions() { ._gnCreateCommandPool = checkCreateCommandPool, ._gnDestroyCommandPool = checkDestroyCommandPool, - // ._gnCreateSemaphore = checkCreateSemaphore, - // ._gnDestroySemaphore = checkDestroySemaphore, - ._gnCreateBuffer = checkCreateBuffer, ._gnBufferData = checkBufferData, ._gnBufferSubData = checkBufferSubData, @@ -80,11 +76,6 @@ gnDeviceFunctions loadFunctionLoaderDeviceFunctions() { ._gnTextureData = checkTextureData, ._gnDestroyTexture = checkDestroyTexture, - // ._gnCreateFence = checkCreateFence, - // ._gnWaitForFence = checkWaitForFence, - // ._gnResetFence = checkResetFence, - // ._gnDestroyFence = checkDestroyFence, - ._gnSubmit = checkSubmit, ._gnPresent = checkPresent, @@ -112,3 +103,17 @@ gnCommandFunctions loadFunctionLoaderCommandFunctions() { ._gnCommandDrawIndexed = checkCommandDrawIndexed, }; } + +gnSyncExtFunctions loadFunctionLoaderSyncExtFunctions() { + return (gnSyncExtFunctions) { + ._gnPresentationQueueGetImageAsync = checkPresentationQueueGetImageAsync, + + ._gnCreateSemaphore = checkCreateSemaphore, + ._gnDestroySemaphore = checkDestroySemaphore, + + ._gnCreateFence = checkCreateFence, + ._gnWaitForFence = checkWaitForFence, + ._gnResetFence = checkResetFence, + ._gnDestroyFence = checkDestroyFence, + }; +} diff --git a/projects/validation_layers/function_loader/loader/function_loader.h b/projects/validation_layers/function_loader/loader/function_loader.h index 9a064b5..882f8f9 100644 --- a/projects/validation_layers/function_loader/loader/function_loader.h +++ b/projects/validation_layers/function_loader/loader/function_loader.h @@ -6,3 +6,6 @@ gnInstanceFunctions loadFunctionLoaderInstanceFunctions(); gnDeviceFunctions loadFunctionLoaderDeviceFunctions(); gnCommandFunctions loadFunctionLoaderCommandFunctions(); + +#include "extensions/synchronization/loader/sync_functions.h" +gnSyncExtFunctions loadFunctionLoaderSyncExtFunctions();