finish queryDevices function

This commit is contained in:
Gregory Wells
2025-09-09 09:39:13 -04:00
parent 88649174a9
commit 0310652abc
7 changed files with 50 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 {

View File

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

View File

@@ -3,9 +3,9 @@
#include <core/src/window_surface/gryphn_surface_create_functions.h>
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);