add helper functions to get queue indices

This commit is contained in:
Greg Wells
2025-05-23 21:03:15 -04:00
parent 02432e04d3
commit 84a29764c0
4 changed files with 45 additions and 5 deletions

View File

@@ -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
);
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);