From 84a29764c064362ddd183e46ac00980b95c9cb6f Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Fri, 23 May 2025 21:03:15 -0400 Subject: [PATCH] add helper functions to get queue indices --- src/core/debugger/gryphn_debugger.c | 9 +++++ src/core/debugger/gryphn_debugger.h | 2 ++ .../gryphn_physical_output_device.c | 36 ++++++++++++++++--- .../gryphn_physical_output_device.h | 3 ++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/core/debugger/gryphn_debugger.c b/src/core/debugger/gryphn_debugger.c index c7217bb..318076a 100644 --- a/src/core/debugger/gryphn_debugger.c +++ b/src/core/debugger/gryphn_debugger.c @@ -13,3 +13,12 @@ gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const void gnDestroyDebugger(gnDebugger* debugger) { debugger->instance->functions->_gnDestroyDebugger(debugger); } + +void gnDebuggerSetErrorMessage(gnDebugger* debugger, gnMessageData data) { + debugger->info.callback( + GN_MESSAGE_ERROR, + GN_DEBUG_MESSAGE_VALIDATION, + data, + debugger->info.userData + ); +} diff --git a/src/core/debugger/gryphn_debugger.h b/src/core/debugger/gryphn_debugger.h index c83d548..317c083 100644 --- a/src/core/debugger/gryphn_debugger.h +++ b/src/core/debugger/gryphn_debugger.h @@ -52,3 +52,5 @@ typedef struct gnDebugger_t { gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info); void gnDestroyDebugger(gnDebugger* debugger); + +void gnDebuggerSetErrorMessage(gnDebugger* debugger, gnMessageData data); diff --git a/src/core/output_device/gryphn_physical_output_device.c b/src/core/output_device/gryphn_physical_output_device.c index 10a64c4..db0386a 100644 --- a/src/core/output_device/gryphn_physical_output_device.c +++ b/src/core/output_device/gryphn_physical_output_device.c @@ -13,15 +13,41 @@ gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count) { gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface) { if (queueIndex >= device.queueProperties.queueCount) { - device.instance->debugger->info.callback( - GN_MESSAGE_ERROR, - GN_DEBUG_MESSAGE_VALIDATION, + gnDebuggerSetErrorMessage(device.instance->debugger, (gnMessageData){ .message = gnCreateString("gnQueueCanPresentToSurface queue index passed in is large then queueProperties.queueCount") - }, - NULL + } ); return gnFalse; } return device.instance->functions->_gnQueueCanPresentToSurface(device, queueIndex, windowSurface); } + +int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device) { + for (int i = 0; i < device.queueProperties.queueCount; i++) { + if (device.queueProperties.queueProperties[i].queueType & GN_QUEUE_GRAPHICS) { + return i; + break; + } + } + gnDebuggerSetErrorMessage(device.instance->debugger, + (gnMessageData){ + .message = gnCreateString("gnGetGraphicsQueueIndex failed no queue that support graphics on this device") + } + ); + return -1; +} +int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface) { + for (int i = 0; i < device.queueProperties.queueCount; i++) { + if (gnQueueCanPresentToSurface(device, i, windowSurface)) { + return i; + break; + } + } + gnDebuggerSetErrorMessage(device.instance->debugger, + (gnMessageData){ + .message = gnCreateString("gnGetPresentQueueIndex failed no queue that support presenting to this window surface") + } + ); + return -1; +} diff --git a/src/core/output_device/gryphn_physical_output_device.h b/src/core/output_device/gryphn_physical_output_device.h index b8d4257..372cb9d 100644 --- a/src/core/output_device/gryphn_physical_output_device.h +++ b/src/core/output_device/gryphn_physical_output_device.h @@ -40,3 +40,6 @@ typedef struct gnPhysicalDevice_t { gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count); gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface); + +int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device); +int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface);