From 0310652abc7bc7e78dc1bf2b1ac0fd606afcafe7 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Tue, 9 Sep 2025 09:39:13 -0400 Subject: [PATCH] finish queryDevices function --- .../apis/metal/src/instance/metal_instance.h | 2 +- .../apis/metal/src/instance/metal_instance.m | 2 +- .../vulkan/src/instance/vulkan_instance.c | 35 +++++++++++++++++++ .../vulkan/src/instance/vulkan_instance.h | 3 ++ .../loader/src/gryphn_instance_functions.h | 2 +- .../function_loader/src/instance_functions.c | 10 ++++-- .../function_loader/src/instance_functions.h | 2 +- 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/projects/apis/metal/src/instance/metal_instance.h b/projects/apis/metal/src/instance/metal_instance.h index 01e7f26..e30068e 100644 --- a/projects/apis/metal/src/instance/metal_instance.h +++ b/projects/apis/metal/src/instance/metal_instance.h @@ -8,5 +8,5 @@ typedef struct gnPlatformInstance_t { } gnPlatformInstance; gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators); -gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices); +gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next); void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators); diff --git a/projects/apis/metal/src/instance/metal_instance.m b/projects/apis/metal/src/instance/metal_instance.m index 126fa82..51a42be 100644 --- a/projects/apis/metal/src/instance/metal_instance.m +++ b/projects/apis/metal/src/instance/metal_instance.m @@ -8,7 +8,7 @@ gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData); return GN_SUCCESS; } -gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices) { +gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next) { if (instance == GN_NULL_HANDLE) return NULL; NSArray *metalDevices = MTLCopyAllDevices(); *count = (uint32_t)[metalDevices count]; diff --git a/projects/apis/vulkan/src/instance/vulkan_instance.c b/projects/apis/vulkan/src/instance/vulkan_instance.c index 64da4f0..ca1eb2b 100644 --- a/projects/apis/vulkan/src/instance/vulkan_instance.c +++ b/projects/apis/vulkan/src/instance/vulkan_instance.c @@ -1,4 +1,5 @@ #include "vulkan_instance.h" +// #include "output_device/vulkan_physical_device.h" #include "vulkan_result_converter.h" GN_ARRAY_LIST_DEFINITION(vkString) @@ -109,6 +110,40 @@ gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInf return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance)); } +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; + void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) { if (next != NULL) { return; } vkDestroyInstance(instance->instance->vk_instance, NULL); diff --git a/projects/apis/vulkan/src/instance/vulkan_instance.h b/projects/apis/vulkan/src/instance/vulkan_instance.h index 32c667d..b95ae2c 100644 --- a/projects/apis/vulkan/src/instance/vulkan_instance.h +++ b/projects/apis/vulkan/src/instance/vulkan_instance.h @@ -4,6 +4,8 @@ #include "utils/lists/gryphn_array_list.h" #include "loader/src/gryphn_instance_functions.h" +void vulkanLoadNeededQueues(gnPhysicalDevice physicalDevice); + typedef struct vkUserData { gnDebuggerCallback debuggerCallback; void* userData; @@ -15,6 +17,7 @@ typedef struct gnPlatformInstance_t { } gnPlatformInstance; gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); +gnReturnCode vulkanQueryDevices(gnInstanceHandle handle, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next); void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); typedef const char* vkString; diff --git a/projects/loader/src/gryphn_instance_functions.h b/projects/loader/src/gryphn_instance_functions.h index 63d22cc..1a412fa 100644 --- a/projects/loader/src/gryphn_instance_functions.h +++ b/projects/loader/src/gryphn_instance_functions.h @@ -21,7 +21,7 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo; typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle, gnInstanceCreateInfo*, gryphnInstanceFunctionLayers*, gnAllocators*); -typedef gnReturnCode (*PFN_gnInstanceQueryDevices)(gnInstanceHandle, uint32_t*, gnPhysicalDeviceHandle*); +typedef gnReturnCode (*PFN_gnInstanceQueryDevices)(gnInstanceHandle, uint32_t*, gnPhysicalDeviceHandle*, gryphnInstanceFunctionLayers*); typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle, gryphnInstanceFunctionLayers*, gnAllocators*); typedef struct gnInstanceFunctions { diff --git a/projects/validation_layers/function_loader/src/instance_functions.c b/projects/validation_layers/function_loader/src/instance_functions.c index 4a80407..e686c02 100644 --- a/projects/validation_layers/function_loader/src/instance_functions.c +++ b/projects/validation_layers/function_loader/src/instance_functions.c @@ -24,8 +24,14 @@ void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayer next->destroyInstance(instance, next->next, alloctors); } -gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) { - CHECK_RETURNED_FUNCTION(instance, _gnGetPhysicalDevices, instanceFunctions, NULL, instance, count); +gnReturnCode checkQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next) { + if (next == NULL || next->queryDevices == 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->queryDevices(instance, count, devices, next->next); } gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface) { CHECK_RETURNED_FUNCTION(device->instance, _gnPhysicalDeviceCanPresentToSurface, instanceFunctions, GN_FALSE, device, windowSurface); diff --git a/projects/validation_layers/function_loader/src/instance_functions.h b/projects/validation_layers/function_loader/src/instance_functions.h index ef60bf8..9169734 100644 --- a/projects/validation_layers/function_loader/src/instance_functions.h +++ b/projects/validation_layers/function_loader/src/instance_functions.h @@ -3,9 +3,9 @@ #include gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); +gnReturnCode checkQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next); void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); -gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count); gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface); gnReturnCode checkCreateOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);