From f44b73665bc320e81e6f4257eae563e5fe21a22c Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Wed, 9 Jul 2025 20:29:07 -0400 Subject: [PATCH] submit command moved to sync extension --- include/gryphn/gryphn.h | 1 + .../apis/vulkan/loader/vulkan_device_loader.c | 2 +- .../apis/vulkan/loader/vulkan_sync_loader.c | 3 +++ .../apis/vulkan/src/submit/vulkan_submit.c | 26 +++++++++++++++++-- .../apis/vulkan/src/submit/vulkan_submit.h | 4 ++- projects/core/src/submit/gryphn_submit.h | 9 +------ .../commands/gryphn_sync_submit.c | 7 +++++ .../commands/gryphn_sync_submit.h | 18 +++++++++++++ .../synchronization/loader/sync_functions.h | 5 +++- .../extensions/sync_functions.c | 5 ++++ .../extensions/sync_functions.h | 3 +++ .../function_loader/loader/function_loader.c | 3 +++ .../function_loader/src/device_functions.h | 9 ------- 13 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 projects/extensions/synchronization/commands/gryphn_sync_submit.c create mode 100644 projects/extensions/synchronization/commands/gryphn_sync_submit.h diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index 3c9771f..adb1ca4 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -28,3 +28,4 @@ #include #include #include +#include diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c index 7b54206..dfd21e5 100644 --- a/projects/apis/vulkan/loader/vulkan_device_loader.c +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -52,7 +52,7 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { ._gnTextureData = textureData, ._gnDestroyTexture = destroyTexture, - ._gnSubmit = submit, + ._gnSubmit = vulkanSubmit, ._gnPresent = present, ._gnWaitForDevice = waitForDevice diff --git a/projects/apis/vulkan/loader/vulkan_sync_loader.c b/projects/apis/vulkan/loader/vulkan_sync_loader.c index ab44667..b6dd114 100644 --- a/projects/apis/vulkan/loader/vulkan_sync_loader.c +++ b/projects/apis/vulkan/loader/vulkan_sync_loader.c @@ -2,6 +2,7 @@ #include #include #include "presentation_queue/vulkan_presentation_queue.h" +#include "submit/vulkan_submit.h" gnSyncExtFunctions loadVulkanSyncFunctions() { return (gnSyncExtFunctions){ @@ -14,5 +15,7 @@ gnSyncExtFunctions loadVulkanSyncFunctions() { ._gnWaitForFence = waitForFence, ._gnResetFence = resetFence, ._gnDestroyFence = destroyFence, + + ._gnSubmitSync = vulkanSubmitSync }; } diff --git a/projects/apis/vulkan/src/submit/vulkan_submit.c b/projects/apis/vulkan/src/submit/vulkan_submit.c index 7afe432..90ee923 100644 --- a/projects/apis/vulkan/src/submit/vulkan_submit.c +++ b/projects/apis/vulkan/src/submit/vulkan_submit.c @@ -1,7 +1,6 @@ #include "vulkan_submit.h" - -gnReturnCode submit(gnDevice device, gnSubmitInfo info) { +gnReturnCode vulkanSubmitSync(gnDevice device, gnSubmitSyncInfo info) { VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); VkPipelineStageFlags* waitStages = malloc(sizeof(VkPipelineStageFlags) * info.waitCount); for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; @@ -40,3 +39,26 @@ gnReturnCode submit(gnDevice device, gnSubmitInfo info) { free(signalSemaphores); return GN_SUCCESS; } + +gnReturnCode vulkanSubmit(gnDevice device, gnSubmitInfo info) { + VkCommandBuffer* commandBuffers = malloc(sizeof(VkCommandBuffer) * info.commandBufferCount); + for (int i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; + + VkSubmitInfo submitInfo = { + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .waitSemaphoreCount = 0, + .pWaitSemaphores = NULL, + .pWaitDstStageMask = NULL, + .commandBufferCount = info.commandBufferCount, + .pCommandBuffers = commandBuffers, + .signalSemaphoreCount = 0, + .pSignalSemaphores = NULL + }; + + VkQueue queue; + vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue); + + if (vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE) != VK_SUCCESS) + return GN_FAILED_TO_SUBMIT_COMMAND_BUFFER; + return GN_SUCCESS; +} diff --git a/projects/apis/vulkan/src/submit/vulkan_submit.h b/projects/apis/vulkan/src/submit/vulkan_submit.h index 95129ae..e9da050 100644 --- a/projects/apis/vulkan/src/submit/vulkan_submit.h +++ b/projects/apis/vulkan/src/submit/vulkan_submit.h @@ -5,5 +5,7 @@ #include #include #include +#include "extensions/synchronization/commands/gryphn_sync_submit.h" -gnReturnCode submit(gnDevice device, gnSubmitInfo info); +gnReturnCode vulkanSubmitSync(gnDevice device, gnSubmitSyncInfo info); +gnReturnCode vulkanSubmit(gnDevice device, gnSubmitInfo info); diff --git a/projects/core/src/submit/gryphn_submit.h b/projects/core/src/submit/gryphn_submit.h index 9d12b05..4ac8680 100644 --- a/projects/core/src/submit/gryphn_submit.h +++ b/projects/core/src/submit/gryphn_submit.h @@ -1,18 +1,11 @@ #pragma once #include "stdint.h" -#include "renderpass/gryphn_render_pass_descriptor.h" +#include "utils/gryphn_error_code.h" #include "gryphn_handles.h" typedef struct gnSubmitInfo { - uint32_t waitCount; - gnRenderPassStage* waitStages; - gnSemaphoreHandle* waitSemaphores; - uint32_t signalCount; - gnSemaphoreHandle* signalSemaphores; uint32_t commandBufferCount; gnCommandBufferHandle* commandBuffers; uint32_t queueIndex; - gnFenceHandle fence; } gnSubmitInfo; - gnReturnCode gnSubmit(gnOutputDevice device, gnSubmitInfo info); diff --git a/projects/extensions/synchronization/commands/gryphn_sync_submit.c b/projects/extensions/synchronization/commands/gryphn_sync_submit.c new file mode 100644 index 0000000..ab21ec4 --- /dev/null +++ b/projects/extensions/synchronization/commands/gryphn_sync_submit.c @@ -0,0 +1,7 @@ +#include "gryphn_sync_submit.h" +#include "core/src/output_device/gryphn_output_device.h" +#include "core/src/instance/gryphn_instance.h" + +gnReturnCode gnSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info) { + return device->instance->callingLayer->syncFunctions._gnSubmitSync(device, info); +} diff --git a/projects/extensions/synchronization/commands/gryphn_sync_submit.h b/projects/extensions/synchronization/commands/gryphn_sync_submit.h new file mode 100644 index 0000000..09ebff5 --- /dev/null +++ b/projects/extensions/synchronization/commands/gryphn_sync_submit.h @@ -0,0 +1,18 @@ +#pragma once +#include "stdint.h" +#include "core/src/renderpass/gryphn_render_pass_descriptor.h" +#include "core/src/gryphn_handles.h" + +typedef struct gnSubmitSyncInfo { + uint32_t waitCount; + gnRenderPassStage* waitStages; + gnSemaphoreHandle* waitSemaphores; + uint32_t signalCount; + gnSemaphoreHandle* signalSemaphores; + uint32_t commandBufferCount; + gnCommandBufferHandle* commandBuffers; + uint32_t queueIndex; + gnFenceHandle fence; +} gnSubmitSyncInfo; + +gnReturnCode gnSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info); diff --git a/projects/extensions/synchronization/loader/sync_functions.h b/projects/extensions/synchronization/loader/sync_functions.h index 97f7105..ed43252 100644 --- a/projects/extensions/synchronization/loader/sync_functions.h +++ b/projects/extensions/synchronization/loader/sync_functions.h @@ -3,15 +3,18 @@ #include "utils/gryphn_error_code.h" #include "core/src/gryphn_handles.h" +typedef struct gnSubmitSyncInfo gnSubmitSyncInfo; + typedef struct gnSyncExtFunctions { gnReturnCode (*_gnPresentationQueueGetImageAsync)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore); - gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device); void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout); void (*_gnResetFence)(gnFenceHandle fence); void (*_gnDestroyFence)(gnFenceHandle fence); + + gnReturnCode (*_gnSubmitSync)(gnOutputDevice device, gnSubmitSyncInfo 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 23ff6fc..25e3887 100644 --- a/projects/validation_layers/function_loader/extensions/sync_functions.c +++ b/projects/validation_layers/function_loader/extensions/sync_functions.c @@ -4,6 +4,7 @@ #include #include "synchronization/semaphore/gryphn_semaphore.h" #include "synchronization/fence/gryphn_fence.h" +#include "synchronization/commands/gryphn_sync_submit.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); @@ -28,3 +29,7 @@ void checkResetFence(gnFenceHandle fence) { void checkDestroyFence(gnFenceHandle fence) { CHECK_VOID_FUNCTION(fence->device->instance, _gnDestroyFence, syncFunctions, fence); } + +gnReturnCode checkSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info) { + CHECK_FUNCTION_WITH_RETURN_CODE(device->instance, _gnSubmitSync, 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 fe7882a..46dad0b 100644 --- a/projects/validation_layers/function_loader/extensions/sync_functions.h +++ b/projects/validation_layers/function_loader/extensions/sync_functions.h @@ -7,3 +7,6 @@ gnReturnCode checkCreateFence(gnFenceHandle fence, gnOutputDeviceHandle device); void checkWaitForFence(gnFenceHandle fence, uint64_t timeout); void checkResetFence(gnFenceHandle fence); void checkDestroyFence(gnFenceHandle fence); +// gnReturnCode fdsfsdf(gnOutputDevice device, gnSubmitSyncInfo info); + +gnReturnCode checkSubmitSync(gnOutputDevice device, gnSubmitSyncInfo info); diff --git a/projects/validation_layers/function_loader/loader/function_loader.c b/projects/validation_layers/function_loader/loader/function_loader.c index 623a8bd..fe301d5 100644 --- a/projects/validation_layers/function_loader/loader/function_loader.c +++ b/projects/validation_layers/function_loader/loader/function_loader.c @@ -2,6 +2,7 @@ #include "src/instance_functions.h" #include "src/device_functions.h" #include "src/command_functions.h" +#include "extensions/sync_functions.h" gnInstanceFunctions loadFunctionLoaderInstanceFunctions() { return (gnInstanceFunctions){ @@ -115,5 +116,7 @@ gnSyncExtFunctions loadFunctionLoaderSyncExtFunctions() { ._gnWaitForFence = checkWaitForFence, ._gnResetFence = checkResetFence, ._gnDestroyFence = checkDestroyFence, + + ._gnSubmitSync = checkSubmitSync }; } diff --git a/projects/validation_layers/function_loader/src/device_functions.h b/projects/validation_layers/function_loader/src/device_functions.h index 9d90df6..b5d5d2a 100644 --- a/projects/validation_layers/function_loader/src/device_functions.h +++ b/projects/validation_layers/function_loader/src/device_functions.h @@ -1,7 +1,6 @@ #include "loader/src/gryphn_device_functions.h" gnReturnCode checkCreatePresentationQueue(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo); -gnReturnCode checkPresentationQueueGetImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); gnReturnCode checkPresentationQueueGetImage(gnPresentationQueueHandle presentationQueue, uint32_t *imageIndex); void checkDestroyPresentationQueue(gnPresentationQueueHandle presentationQueue); @@ -20,9 +19,6 @@ void checkDestroyFramebuffer(gnFramebuffer framebuffer); gnReturnCode checkCreateCommandPool(gnCommandPoolHandle commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info); void checkDestroyCommandPool(gnCommandPoolHandle commandPool); -gnReturnCode checkCreateSemaphore(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); -void checkDestroySemaphore(gnSemaphoreHandle semaphore); - gnReturnCode checkCreateBuffer(gnBufferHandle buffer, gnDeviceHandle device, gnBufferInfo info); void checkBufferData(gnBufferHandle buffer, size_t size, void* data); void checkBufferSubData(gnBufferHandle buffer, size_t offset, size_t size, void* data); @@ -41,11 +37,6 @@ gnReturnCode checkCreateTexture(gnTexture texture, gnDevice device, const gnText void checkTextureData(gnTextureHandle texture, void* pixelData); void checkDestroyTexture(gnTexture texture); -gnReturnCode checkCreateFence(gnFenceHandle fence, gnOutputDeviceHandle device); -void checkWaitForFence(gnFenceHandle fence, uint64_t timeout); -void checkResetFence(gnFenceHandle fence); -void checkDestroyFence(gnFenceHandle fence); - gnReturnCode checkSubmit(gnOutputDeviceHandle device, gnSubmitInfo submit); gnReturnCode checkPresent(gnOutputDeviceHandle device, gnPresentInfo info);