From a446d6e75f1df3ca1085d29ca9c128338a00bfcb Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Wed, 10 Sep 2025 13:26:18 -0400 Subject: [PATCH] instance suitability functions --- .../vulkan/loader/vulkan_instance_loader.c | 1 + .../vulkan/src/instance/vulkan_instance.c | 35 ++++--------------- .../vulkan/src/instance/vulkan_instance.h | 1 + projects/core/src/instance/gryphn_instance.c | 6 +++- projects/core/src/instance/gryphn_instance.h | 6 +++- .../loader/src/gryphn_instance_functions.h | 3 +- projects/loader/src/gryphn_loader.h | 1 + .../function_loader/loader/function_loader.c | 6 ++-- .../function_loader/src/instance_functions.c | 10 ++++++ .../function_loader/src/instance_functions.h | 1 + 10 files changed, 36 insertions(+), 34 deletions(-) diff --git a/projects/apis/vulkan/loader/vulkan_instance_loader.c b/projects/apis/vulkan/loader/vulkan_instance_loader.c index 7242eb9..fe5f69c 100644 --- a/projects/apis/vulkan/loader/vulkan_instance_loader.c +++ b/projects/apis/vulkan/loader/vulkan_instance_loader.c @@ -7,6 +7,7 @@ gryphnInstanceFunctionLayers loadVulkanAPILayer(void) { return (gryphnInstanceFunctionLayers) { .createInstance = vulkanCreateInstance, + .isSuitable = vulkanIsInstanceSuitable, .destroyInstance = vulkanDestroyInstance, .queryDevices = vulkanQueryDevices, .next = NULL diff --git a/projects/apis/vulkan/src/instance/vulkan_instance.c b/projects/apis/vulkan/src/instance/vulkan_instance.c index ca1eb2b..2418ec1 100644 --- a/projects/apis/vulkan/src/instance/vulkan_instance.c +++ b/projects/apis/vulkan/src/instance/vulkan_instance.c @@ -113,36 +113,13 @@ gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInf gnReturnCode vulkanQueryDevices(gnInstanceHandle handle, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next) { return VkResultToGnReturnCode(vkEnumeratePhysicalDevices(handle->instance->vk_instance, count, NULL)); } - // for (uint32_t i = 0; i < *count; i++) { - // outputDevices[i] = (uint64_t)malloc(sizeof(vulkanPhysicalDevice)); - // vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)outputDevices[i]; - // device->device = physicalDevices[i]; - // VkPhysicalDeviceProperties deviceProperties; - // vkGetPhysicalDeviceProperties(physicalDevices[i], &deviceProperties); - // device->properties.name = gnCreateString(deviceProperties.deviceName); - // switch(deviceProperties.deviceType) { - // case VK_PHYSICAL_DEVICE_TYPE_OTHER: device->properties.deviceType = GN_EXTERNAL_DEVICE; - // case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: device->properties.deviceType = GN_INTEGRATED_DEVICE; - // case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: device->properties.deviceType = GN_DEDICATED_DEVICE; - // case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: device->properties.deviceType = GN_INTEGRATED_DEVICE; - // case VK_PHYSICAL_DEVICE_TYPE_CPU: device->properties.deviceType = GN_INTEGRATED_DEVICE; - // case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: device->properties.deviceType = GN_INTEGRATED_DEVICE; - // } - - // if (handle->enabledExtensions[GN_EXT_QUEUES] == GN_FALSE) - // vulkanLoadNeededQueues(outputDevices[i]); - - - // VkPhysicalDeviceProperties physicalDeviceProperties; - // vkGetPhysicalDeviceProperties(physicalDevices[i], &physicalDeviceProperties); - // device->features.maxColorSamples = vkSampleCountToGryphn(physicalDeviceProperties.limits.framebufferColorSampleCounts); - // device->features.maxDepthSamples = vkSampleCountToGryphn(physicalDeviceProperties.limits.framebufferDepthSampleCounts); - // device->features.maxMemoryAllocations = physicalDeviceProperties.limits.maxMemoryAllocationCount; - // device->features.maxPushConstantSize = physicalDeviceProperties.limits.maxPushConstantsSize; - // } - // free(physicalDevices); - // return outputDevices; +gnBool vulkanIsInstanceSuitable(gnInstanceHandle instance, gnSuitableField field, gryphnInstanceFunctionLayers* next) { + switch (field) { + case GN_NON_EXISTANT_PHYSICAL_DEVICE: return GN_FALSE; + } + return GN_FALSE; +} void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) { if (next != NULL) { return; } diff --git a/projects/apis/vulkan/src/instance/vulkan_instance.h b/projects/apis/vulkan/src/instance/vulkan_instance.h index b95ae2c..419f379 100644 --- a/projects/apis/vulkan/src/instance/vulkan_instance.h +++ b/projects/apis/vulkan/src/instance/vulkan_instance.h @@ -17,6 +17,7 @@ typedef struct gnPlatformInstance_t { } gnPlatformInstance; gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); +gnBool vulkanIsInstanceSuitable(gnInstanceHandle instance, gnSuitableField field, gryphnInstanceFunctionLayers* next); gnReturnCode vulkanQueryDevices(gnInstanceHandle handle, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next); void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index c04eb0c..41790e4 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -84,8 +84,12 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next, &(*instance)->allocators); } +gnBool gnIsInstanceSuitable(gnInstance instance, gnSuitableField field) { + return instance->functions->isSuitable(instance, field, instance->functions->next); +} + gnReturnCode gnInstanceQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices) { - return instance->functions->queryDevices(instance, count, devices); + return instance->functions->queryDevices(instance, count, devices, instance->functions->next); } void gnDestroyInstance(gnInstanceHandle* instance) { diff --git a/projects/core/src/instance/gryphn_instance.h b/projects/core/src/instance/gryphn_instance.h index 70f6c73..77ce344 100644 --- a/projects/core/src/instance/gryphn_instance.h +++ b/projects/core/src/instance/gryphn_instance.h @@ -7,7 +7,6 @@ #include "gryphn_allocators.h" #include - typedef struct gnApplicationInfo { gnString applicationName; gnVersion applicationVersion; @@ -16,6 +15,10 @@ typedef struct gnApplicationInfo { gnVersion engineVersion; } gnApplicationInfo; +typedef enum gnSuitableField { + GN_NON_EXISTANT_PHYSICAL_DEVICE +} gnSuitableField; + typedef struct gnInstanceCreateInfo { gnApplicationInfo applicationInfo; gnDebuggerCreateInfo debuggerInfo; @@ -45,5 +48,6 @@ struct gnInstance_t { #endif gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info); +gnBool gnIsInstanceSuitable(gnInstance instance, gnSuitableField field); gnReturnCode gnInstanceQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices); void gnDestroyInstance(gnInstanceHandle* instance); diff --git a/projects/loader/src/gryphn_instance_functions.h b/projects/loader/src/gryphn_instance_functions.h index 1a412fa..7d0d9b0 100644 --- a/projects/loader/src/gryphn_instance_functions.h +++ b/projects/loader/src/gryphn_instance_functions.h @@ -8,7 +8,7 @@ typedef struct gnInstanceCreateInfo gnInstanceCreateInfo; typedef struct gnSurfaceDetails gnSurfaceDetails; typedef struct gnOutputDeviceInfo gnOutputDeviceInfo; - +typedef enum gnSuitableField gnSuitableField; #ifdef GN_PLATFORM_LINUX #ifdef GN_WINDOW_X11 @@ -21,6 +21,7 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo; typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle, gnInstanceCreateInfo*, gryphnInstanceFunctionLayers*, gnAllocators*); +typedef gnBool (*PFN_gnIsInstanceSuitable)(gnInstanceHandle, gnSuitableField, gryphnInstanceFunctionLayers*); typedef gnReturnCode (*PFN_gnInstanceQueryDevices)(gnInstanceHandle, uint32_t*, gnPhysicalDeviceHandle*, gryphnInstanceFunctionLayers*); typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle, gryphnInstanceFunctionLayers*, gnAllocators*); diff --git a/projects/loader/src/gryphn_loader.h b/projects/loader/src/gryphn_loader.h index 7aaefe1..fb0ffb4 100644 --- a/projects/loader/src/gryphn_loader.h +++ b/projects/loader/src/gryphn_loader.h @@ -15,6 +15,7 @@ typedef struct gryphnFunctionLayer { typedef struct gryphnInstanceFunctionLayers { PFN_gnCreateInstance createInstance; + PFN_gnIsInstanceSuitable isSuitable; PFN_gnInstanceQueryDevices queryDevices; PFN_gnDestroyInstance destroyInstance; struct gryphnInstanceFunctionLayers* next; diff --git a/projects/validation_layers/function_loader/loader/function_loader.c b/projects/validation_layers/function_loader/loader/function_loader.c index 229f50f..517aec1 100644 --- a/projects/validation_layers/function_loader/loader/function_loader.c +++ b/projects/validation_layers/function_loader/loader/function_loader.c @@ -8,13 +8,15 @@ gryphnInstanceFunctionLayers checkerLoadInstanceFunctions(void) { return (gryphnInstanceFunctionLayers) { .createInstance = checkCreateInstance, - .destroyInstance = checkDestroyInstance + .isSuitable = checkIsInstanceSuitable, + .queryDevices = checkQueryDevices, + .destroyInstance = checkDestroyInstance, + .next = GN_NULL_HANDLE }; } gnInstanceFunctions loadFunctionLoaderInstanceFunctions(void) { return (gnInstanceFunctions){ - ._gnGetPhysicalDevices = checkGetPhysicalDevices, ._gnPhysicalDeviceCanPresentToSurface = checkCanDevicePresent, ._gnCreateOutputDevice = checkCreateOutputDevice, diff --git a/projects/validation_layers/function_loader/src/instance_functions.c b/projects/validation_layers/function_loader/src/instance_functions.c index e686c02..4f8d346 100644 --- a/projects/validation_layers/function_loader/src/instance_functions.c +++ b/projects/validation_layers/function_loader/src/instance_functions.c @@ -24,6 +24,16 @@ void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayer next->destroyInstance(instance, next->next, alloctors); } +gnBool checkIsInstanceSuitable(gnInstanceHandle instance, gnSuitableField field, gryphnInstanceFunctionLayers* next) { + if (next == NULL || next->isSuitable == NULL) { + gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){ + .message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn") + }); + return GN_FAILED_TO_LOAD_FUNCTION; + } + return next->isSuitable(instance, field, next); +} + gnReturnCode checkQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next) { if (next == NULL || next->queryDevices == NULL) { gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){ diff --git a/projects/validation_layers/function_loader/src/instance_functions.h b/projects/validation_layers/function_loader/src/instance_functions.h index 9169734..3e2b58d 100644 --- a/projects/validation_layers/function_loader/src/instance_functions.h +++ b/projects/validation_layers/function_loader/src/instance_functions.h @@ -3,6 +3,7 @@ #include gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); +gnBool checkIsInstanceSuitable(gnInstanceHandle instance, gnSuitableField field, gryphnInstanceFunctionLayers* next); gnReturnCode checkQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next); void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);