From 9ae7689ab89f9f0972600608cc803a1fc5d246ab Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Wed, 9 Jul 2025 20:35:16 -0400 Subject: [PATCH] move present over to sync extension --- .../apis/vulkan/loader/vulkan_device_loader.c | 2 +- .../apis/vulkan/loader/vulkan_sync_loader.c | 4 ++- .../apis/vulkan/src/present/vulkan_present.c | 26 ++++++++++++++++++- .../apis/vulkan/src/present/vulkan_present.h | 3 ++- projects/core/src/present/gryphn_present.h | 4 +-- .../commands/gryphn_sync_present.c | 7 +++++ .../commands/gryphn_sync_present.h | 15 +++++++++++ .../synchronization/loader/sync_functions.h | 2 ++ .../extensions/sync_functions.c | 5 ++++ .../extensions/sync_functions.h | 1 + .../function_loader/loader/function_loader.c | 3 ++- 11 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 projects/extensions/synchronization/commands/gryphn_sync_present.c create mode 100644 projects/extensions/synchronization/commands/gryphn_sync_present.h diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c index dfd21e5..58e855a 100644 --- a/projects/apis/vulkan/loader/vulkan_device_loader.c +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -53,7 +53,7 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { ._gnDestroyTexture = destroyTexture, ._gnSubmit = vulkanSubmit, - ._gnPresent = present, + ._gnPresent = vulkanPresent, ._gnWaitForDevice = waitForDevice }; diff --git a/projects/apis/vulkan/loader/vulkan_sync_loader.c b/projects/apis/vulkan/loader/vulkan_sync_loader.c index b6dd114..5816b03 100644 --- a/projects/apis/vulkan/loader/vulkan_sync_loader.c +++ b/projects/apis/vulkan/loader/vulkan_sync_loader.c @@ -3,6 +3,7 @@ #include #include "presentation_queue/vulkan_presentation_queue.h" #include "submit/vulkan_submit.h" +#include "present/vulkan_present.h" gnSyncExtFunctions loadVulkanSyncFunctions() { return (gnSyncExtFunctions){ @@ -16,6 +17,7 @@ gnSyncExtFunctions loadVulkanSyncFunctions() { ._gnResetFence = resetFence, ._gnDestroyFence = destroyFence, - ._gnSubmitSync = vulkanSubmitSync + ._gnSubmitSync = vulkanSubmitSync, + ._gnPresentSync = vulkanPresentSync }; } diff --git a/projects/apis/vulkan/src/present/vulkan_present.c b/projects/apis/vulkan/src/present/vulkan_present.c index aafbfbc..035a54f 100644 --- a/projects/apis/vulkan/src/present/vulkan_present.c +++ b/projects/apis/vulkan/src/present/vulkan_present.c @@ -1,6 +1,7 @@ #include "vulkan_present.h" +#include "extensions/synchronization/commands/gryphn_sync_present.h" -gnReturnCode present(gnDevice device, gnPresentInfo info) { +gnReturnCode vulkanPresentSync(gnDevice device, gnPresentSyncInfo info) { VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; @@ -24,3 +25,26 @@ gnReturnCode present(gnDevice device, gnPresentInfo info) { if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; return GN_SUCCESS; } + + +gnReturnCode vulkanPresent(gnDevice device, gnPresentInfo info) { + VkSwapchainKHR* swapchains = malloc(sizeof(VkSwapchainKHR) * info.presentationQueueCount); + for (int i = 0; i < info.presentationQueueCount; i++) swapchains[i] = info.presentationQueues[i]->presentationQueue->swapChain; + + VkPresentInfoKHR presentInfo = { + .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + .waitSemaphoreCount = 0, + .pWaitSemaphores = NULL, + .swapchainCount = info.presentationQueueCount, + .pSwapchains = swapchains, + .pImageIndices = info.imageIndices + }; + + VkQueue queue; + vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue); + + VkResult result = vkQueuePresentKHR(queue, &presentInfo); + 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; +} diff --git a/projects/apis/vulkan/src/present/vulkan_present.h b/projects/apis/vulkan/src/present/vulkan_present.h index f108d19..ce72090 100644 --- a/projects/apis/vulkan/src/present/vulkan_present.h +++ b/projects/apis/vulkan/src/present/vulkan_present.h @@ -3,4 +3,5 @@ #include #include -gnReturnCode present(gnDevice device, gnPresentInfo info); +gnReturnCode vulkanPresentSync(gnDevice device, gnPresentSyncInfo info); +gnReturnCode vulkanPresent(gnDevice device, gnPresentInfo info); diff --git a/projects/core/src/present/gryphn_present.h b/projects/core/src/present/gryphn_present.h index a3e4a35..1d875a0 100644 --- a/projects/core/src/present/gryphn_present.h +++ b/projects/core/src/present/gryphn_present.h @@ -1,11 +1,9 @@ #pragma once -#include "utils/gryphn_error_code.h" #include "stdint.h" +#include "utils/gryphn_error_code.h" #include "gryphn_handles.h" typedef struct gnPresentInfo { - uint32_t waitCount; - gnSemaphoreHandle* waitSemaphores; uint32_t presentationQueueCount; gnPresentationQueueHandle* presentationQueues; uint32_t* imageIndices; diff --git a/projects/extensions/synchronization/commands/gryphn_sync_present.c b/projects/extensions/synchronization/commands/gryphn_sync_present.c new file mode 100644 index 0000000..0b9ea72 --- /dev/null +++ b/projects/extensions/synchronization/commands/gryphn_sync_present.c @@ -0,0 +1,7 @@ +#include "gryphn_sync_present.h" +#include "core/src/output_device/gryphn_output_device.h" +#include "core/src/instance/gryphn_instance.h" + +gnReturnCode gnPresentSync(gnOutputDeviceHandle device, gnPresentSyncInfo info) { + return device->instance->callingLayer->syncFunctions._gnPresentSync(device, info); +} diff --git a/projects/extensions/synchronization/commands/gryphn_sync_present.h b/projects/extensions/synchronization/commands/gryphn_sync_present.h new file mode 100644 index 0000000..874eee4 --- /dev/null +++ b/projects/extensions/synchronization/commands/gryphn_sync_present.h @@ -0,0 +1,15 @@ +#pragma once +#include "stdint.h" +#include "utils/gryphn_error_code.h" +#include "gryphn_handles.h" + +typedef struct gnPresentSyncInfo { + uint32_t waitCount; + gnSemaphoreHandle* waitSemaphores; + uint32_t presentationQueueCount; + gnPresentationQueueHandle* presentationQueues; + uint32_t* imageIndices; + uint32_t queueIndex; +} gnPresentSyncInfo; + +gnReturnCode gnPresentSync(gnOutputDeviceHandle device, gnPresentSyncInfo info); diff --git a/projects/extensions/synchronization/loader/sync_functions.h b/projects/extensions/synchronization/loader/sync_functions.h index ed43252..c4a17da 100644 --- a/projects/extensions/synchronization/loader/sync_functions.h +++ b/projects/extensions/synchronization/loader/sync_functions.h @@ -4,6 +4,7 @@ #include "core/src/gryphn_handles.h" typedef struct gnSubmitSyncInfo gnSubmitSyncInfo; +typedef struct gnPresentSyncInfo gnPresentSyncInfo; typedef struct gnSyncExtFunctions { gnReturnCode (*_gnPresentationQueueGetImageAsync)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); @@ -17,4 +18,5 @@ typedef struct gnSyncExtFunctions { void (*_gnDestroyFence)(gnFenceHandle fence); gnReturnCode (*_gnSubmitSync)(gnOutputDevice device, gnSubmitSyncInfo info); + gnReturnCode (*_gnPresentSync)(gnOutputDeviceHandle device, gnPresentSyncInfo info); } gnSyncExtFunctions; diff --git a/projects/validation_layers/function_loader/extensions/sync_functions.c b/projects/validation_layers/function_loader/extensions/sync_functions.c index 25e3887..f8b4c60 100644 --- a/projects/validation_layers/function_loader/extensions/sync_functions.c +++ b/projects/validation_layers/function_loader/extensions/sync_functions.c @@ -5,6 +5,7 @@ #include "synchronization/semaphore/gryphn_semaphore.h" #include "synchronization/fence/gryphn_fence.h" #include "synchronization/commands/gryphn_sync_submit.h" +#include "synchronization/commands/gryphn_sync_present.h" gnReturnCode checkPresentationQueueGetImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex) { CHECK_FUNCTION_WITH_RETURN_CODE(presentationQueue->outputDevice->instance, _gnPresentationQueueGetImageAsync, syncFunctions, presentationQueue, timeout, semaphore, imageIndex); @@ -33,3 +34,7 @@ void checkDestroyFence(gnFenceHandle fence) { gnReturnCode checkSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info) { CHECK_FUNCTION_WITH_RETURN_CODE(device->instance, _gnSubmitSync, syncFunctions, device, info); } + +gnReturnCode checkPresentSync(gnOutputDevice device, gnPresentSyncInfo info) { + CHECK_FUNCTION_WITH_RETURN_CODE(device->instance, _gnPresentSync, syncFunctions, device, info); +} diff --git a/projects/validation_layers/function_loader/extensions/sync_functions.h b/projects/validation_layers/function_loader/extensions/sync_functions.h index 46dad0b..888562b 100644 --- a/projects/validation_layers/function_loader/extensions/sync_functions.h +++ b/projects/validation_layers/function_loader/extensions/sync_functions.h @@ -10,3 +10,4 @@ void checkDestroyFence(gnFenceHandle fence); // gnReturnCode fdsfsdf(gnOutputDevice device, gnSubmitSyncInfo info); gnReturnCode checkSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info); +gnReturnCode checkPresentSync(gnOutputDevice device, gnPresentSyncInfo info); diff --git a/projects/validation_layers/function_loader/loader/function_loader.c b/projects/validation_layers/function_loader/loader/function_loader.c index fe301d5..edb7d7c 100644 --- a/projects/validation_layers/function_loader/loader/function_loader.c +++ b/projects/validation_layers/function_loader/loader/function_loader.c @@ -117,6 +117,7 @@ gnSyncExtFunctions loadFunctionLoaderSyncExtFunctions() { ._gnResetFence = checkResetFence, ._gnDestroyFence = checkDestroyFence, - ._gnSubmitSync = checkSubmitSync + ._gnSubmitSync = checkSubmitSync, + ._gnPresentSync = checkPresentSync }; }