diff --git a/projects/apis/vulkan/src/output_device/vulkan_physical_device.c b/projects/apis/vulkan/src/output_device/vulkan_physical_device.c index 6336039..65fa2a0 100644 --- a/projects/apis/vulkan/src/output_device/vulkan_physical_device.c +++ b/projects/apis/vulkan/src/output_device/vulkan_physical_device.c @@ -31,13 +31,15 @@ VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts) { return sampleCount; } -void vulkanLoadNeededQueues(VkPhysicalDevice vulkanDevice, gnPhysicalDevice gryphnDevice) { - uint32_t queueFamilyCount = 0; - vkGetPhysicalDeviceQueueFamilyProperties(vulkanDevice, &queueFamilyCount, NULL); - VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * queueFamilyCount); - vkGetPhysicalDeviceQueueFamilyProperties(vulkanDevice, &queueFamilyCount, queueFamilies); +void vulkanLoadNeededQueues(gnPhysicalDevice physicalDevice) { + vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)physicalDevice; - gryphnDevice->physicalDevice->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount); + uint32_t queueFamilyCount = 0; + vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, NULL); + VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * queueFamilyCount); + vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, queueFamilies); + + device->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount); for (uint32_t c = 0; c < queueFamilyCount; c++) { gnBool hasNeededQueue = GN_FALSE; @@ -55,98 +57,24 @@ void vulkanLoadNeededQueues(VkPhysicalDevice vulkanDevice, gnPhysicalDevice gryp if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT)) neededQueue.createFlags |= VK_QUEUE_GRAPHICS_BIT; if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT)) neededQueue.createFlags |= VK_QUEUE_TRANSFER_BIT; - gryphnDevice->physicalDevice->neededQueues[gryphnDevice->physicalDevice->neededQueueCount] = neededQueue; - gryphnDevice->physicalDevice->neededQueueCount++; + device->neededQueues[device->neededQueueCount] = neededQueue; + device->neededQueueCount++; } } free(queueFamilies); } -gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount) { - vkEnumeratePhysicalDevices(instance->instance->vk_instance, deviceCount, NULL); - if (deviceCount == 0) - return NULL; - VkPhysicalDevice* physicalDevices = malloc(sizeof(VkPhysicalDevice) * *deviceCount); - vkEnumeratePhysicalDevices(instance->instance->vk_instance, deviceCount, physicalDevices); - gnPhysicalDevice* outputDevices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount); +gnBool deviceCanPresentToSurface(gnPhysicalDevice physicalDevice, gnWindowSurface surface) { + vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)physicalDevice; - for (uint32_t i = 0; i < *deviceCount; i++) { - outputDevices[i] = malloc(sizeof(gnPhysicalOutputDevice_t)); - outputDevices[i]->physicalDevice = malloc(sizeof(struct gnPlatformPhysicalDevice_t)); - outputDevices[i]->physicalDevice->device = physicalDevices[i]; - - VkPhysicalDeviceProperties deviceProperties; - vkGetPhysicalDeviceProperties(physicalDevices[i], &deviceProperties); - outputDevices[i]->properties.name = gnCreateString(deviceProperties.deviceName); - switch(deviceProperties.deviceType) { - case VK_PHYSICAL_DEVICE_TYPE_OTHER: outputDevices[i]->properties.deviceType = GN_EXTERNAL_DEVICE; - case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE; - case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: outputDevices[i]->properties.deviceType = GN_DEDICATED_DEVICE; - case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE; - case VK_PHYSICAL_DEVICE_TYPE_CPU: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE; - case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE; - } - - if (instance->enabledExtensions[GN_EXT_QUEUES] == GN_FALSE) - vulkanLoadNeededQueues(physicalDevices[i], outputDevices[i]); - - - VkPhysicalDeviceProperties physicalDeviceProperties; - vkGetPhysicalDeviceProperties(physicalDevices[i], &physicalDeviceProperties); - outputDevices[i]->features.maxColorSamples = vkSampleCountToGryphn(physicalDeviceProperties.limits.framebufferColorSampleCounts); - outputDevices[i]->features.maxDepthSamples = vkSampleCountToGryphn(physicalDeviceProperties.limits.framebufferDepthSampleCounts); - outputDevices[i]->features.maxMemoryAllocations = physicalDeviceProperties.limits.maxMemoryAllocationCount; - outputDevices[i]->features.maxPushConstantSize = physicalDeviceProperties.limits.maxPushConstantsSize; - } - free(physicalDevices); - - return outputDevices; -} - -gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface) { uint32_t queueFamilyCount = 0; - vkGetPhysicalDeviceQueueFamilyProperties(device->physicalDevice->device, &queueFamilyCount, NULL); + vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, NULL); for (uint32_t i = 0; i < queueFamilyCount; i++) { VkBool32 supportsPresent; - vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, i, surface->windowSurface->surface, &supportsPresent); + vkGetPhysicalDeviceSurfaceSupportKHR(device->device, i, surface->windowSurface->surface, &supportsPresent); if (supportsPresent) return GN_TRUE; } return GN_FALSE; } - - // gnBool foundQueue = GN_FALSE; - // for (uint32_t i = 0; i < device->physicalDevice->neededQueueCount; i++) { - // VkBool32 supportsPresent = VK_FALSE; - // vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, device->physicalDevice->neededQueues[i].queueIndex, surface->windowSurface->surface, &supportsPresent); - // if (supportsPresent) { - // device->physicalDevice->neededQueues[i].usedForPresent = GN_TRUE; - // foundQueue = GN_TRUE; - // break; - // } - // surface->windowSurface->presentQueueIndex = i; - // } - - // if (!foundQueue) { - // uint32_t queueFamilyCount = 0; - // vkGetPhysicalDeviceQueueFamilyProperties(device->physicalDevice->device, &queueFamilyCount, NULL); - - // for (uint32_t i = 0; i < queueFamilyCount; i++) { - // VkBool32 supportsPresent = VK_FALSE; - // vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, i, surface->windowSurface->surface, &supportsPresent); - // if (supportsPresent) { - // device->physicalDevice->neededQueues[device->physicalDevice->neededQueueCount] = (vulkanNeededQueue){ - // .queueIndex = i, - // .createFlags = 0, - // .usedForPresent = GN_TRUE - // }; - // foundQueue = GN_TRUE; - // surface->windowSurface->presentQueueIndex = device->physicalDevice->neededQueueCount; - // device->physicalDevice->neededQueueCount++; - // break; - // } - // } - // } - - // return foundQueue; diff --git a/projects/apis/vulkan/src/output_device/vulkan_physical_device.h b/projects/apis/vulkan/src/output_device/vulkan_physical_device.h index 973a409..dfdf6ec 100644 --- a/projects/apis/vulkan/src/output_device/vulkan_physical_device.h +++ b/projects/apis/vulkan/src/output_device/vulkan_physical_device.h @@ -8,13 +8,6 @@ typedef struct vulkanNeededQueue { uint32_t queueIndex; } vulkanNeededQueue; -typedef struct gnPlatformPhysicalDevice_t { - VkPhysicalDevice device; - uint32_t neededQueueCount; - vulkanNeededQueue* neededQueues; - -} gnPlatformPhysicalDevice; - gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount); gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface); diff --git a/projects/core/src/gryphn_handles.h b/projects/core/src/gryphn_handles.h index f5adc93..4501ce8 100644 --- a/projects/core/src/gryphn_handles.h +++ b/projects/core/src/gryphn_handles.h @@ -10,9 +10,15 @@ typedef struct type##_t* type##Handle; \ typedef struct type##_t* type // The value of this handle is defined by the implementation +#ifndef GN_IMPLEMENTATION #define GN_IMPLEMENTATION_HANDLE(type) \ typedef uint64_t type##Handle; \ typedef uint64_t type +#else +#define GN_IMPLEMENTATION_HANDLE(type) \ +typedef uint64_t type##Handle; \ +typedef uint64_t type +#endif // can be used to alias a normal handle or an implementation handle #define GN_HANDLE_ALIAS(handle, alias) \ @@ -20,7 +26,7 @@ typedef struct handle##_t* alias##Handle; \ typedef struct handle##_t* alias GN_HANDLE(gnInstance); -GN_HANDLE(gnPhysicalDevice); // NOTE: needs to become a impl handle +GN_IMPLEMENTATION_HANDLE(gnPhysicalDevice); // NOTE: needs to become a impl handle GN_HANDLE(gnWindowSurface); GN_HANDLE(gnPresentationQueue); diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index 464ff8a..c04eb0c 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -84,6 +84,10 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next, &(*instance)->allocators); } +gnReturnCode gnInstanceQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices) { + return instance->functions->queryDevices(instance, count, devices); +} + void gnDestroyInstance(gnInstanceHandle* instance) { if (instance == GN_NULL_HANDLE) return; (*instance)->functions->destroyInstance(*instance, (*instance)->functions->next, &(*instance)->allocators); diff --git a/projects/core/src/instance/gryphn_instance.h b/projects/core/src/instance/gryphn_instance.h index 5f04990..70f6c73 100644 --- a/projects/core/src/instance/gryphn_instance.h +++ b/projects/core/src/instance/gryphn_instance.h @@ -45,4 +45,5 @@ struct gnInstance_t { #endif gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info); +gnReturnCode gnInstanceQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices); void gnDestroyInstance(gnInstanceHandle* instance); diff --git a/projects/core/src/output_device/gryphn_physical_device.c b/projects/core/src/output_device/gryphn_physical_device.c index 60071f9..c1c7549 100644 --- a/projects/core/src/output_device/gryphn_physical_device.c +++ b/projects/core/src/output_device/gryphn_physical_device.c @@ -4,14 +4,12 @@ gnPhysicalDeviceHandle* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count) {; gnPhysicalDeviceHandle* devices = instance->callingLayer->instanceFunctions._gnGetPhysicalDevices(instance, count); - for (uint32_t i = 0; i < *count; i++) - devices[i]->instance = instance; return devices; } -gnBool gnPhysicalDeviceCanPresentToSurface(gnPhysicalDeviceHandle device, gnWindowSurfaceHandle windowSurface) { - return device->instance->callingLayer->instanceFunctions._gnPhysicalDeviceCanPresentToSurface(device, windowSurface); +gnBool gnPhysicalDeviceCanPresentToSurface(gnInstanceHandle instance, gnPhysicalDeviceHandle device, gnWindowSurfaceHandle windowSurface) { + return instance->callingLayer->instanceFunctions._gnPhysicalDeviceCanPresentToSurface(device, windowSurface); } -gnPhysicalDeviceProperties gnGetPhysicalDeviceProperties(gnPhysicalDeviceHandle device) { return device->properties; } -gnPhysicalDeviceFeatures gnGetPhysicalDeviceFeatures(gnPhysicalDeviceHandle device) { return device->features; } +// gnPhysicalDeviceProperties gnGetPhysicalDeviceProperties(gnPhysicalDeviceHandle device) { return device->properties; } +// gnPhysicalDeviceFeatures gnGetPhysicalDeviceFeatures(gnPhysicalDeviceHandle device) { return device->features; } diff --git a/projects/core/src/output_device/gryphn_physical_device.h b/projects/core/src/output_device/gryphn_physical_device.h index fc6faa3..59a76f0 100644 --- a/projects/core/src/output_device/gryphn_physical_device.h +++ b/projects/core/src/output_device/gryphn_physical_device.h @@ -28,18 +28,18 @@ typedef struct gnPhysicalDeviceFeatures { uint32_t maxPushConstantSize; } gnPhysicalDeviceFeatures; -#ifdef GN_REVEAL_IMPL -typedef struct gnPhysicalDevice_t { - struct gnPlatformPhysicalDevice_t* physicalDevice; - gnPhysicalDeviceProperties properties; - gnPhysicalDeviceFeatures features; +// #ifdef GN_REVEAL_IMPL +// typedef struct gnPhysicalDevice_t { +// struct gnPlatformPhysicalDevice_t* physicalDevice; +// gnPhysicalDeviceProperties properties; +// gnPhysicalDeviceFeatures features; - gnInstanceHandle instance; -} gnPhysicalOutputDevice_t; -#endif +// gnInstanceHandle instance; +// } gnPhysicalOutputDevice_t; +// #endif gnPhysicalDeviceHandle* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count); -gnBool gnPhysicalDeviceCanPresentToSurface(gnPhysicalDeviceHandle device, gnWindowSurfaceHandle windowSurface); +gnBool gnPhysicalDeviceCanPresentToSurface(gnInstance instance, gnPhysicalDeviceHandle device, gnWindowSurfaceHandle windowSurface); gnPhysicalDeviceProperties gnGetPhysicalDeviceProperties(gnPhysicalDeviceHandle device); gnPhysicalDeviceFeatures gnGetPhysicalDeviceFeatures(gnPhysicalDeviceHandle device); diff --git a/projects/loader/src/gryphn_instance_functions.h b/projects/loader/src/gryphn_instance_functions.h index 096be97..cd50339 100644 --- a/projects/loader/src/gryphn_instance_functions.h +++ b/projects/loader/src/gryphn_instance_functions.h @@ -20,8 +20,9 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo; #endif typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; -typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); -typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors); +typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle, gnInstanceCreateInfo*, gryphnInstanceFunctionLayers*, gnAllocators*); +typedef gnReturnCode (*PFN_gnInstanceQueryDevices)(gnInstanceHandle, uint32_t*, gnPhysicalDeviceHandle*); +typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle, gryphnInstanceFunctionLayers*, gnAllocators*); typedef struct gnInstanceFunctions { gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count); diff --git a/projects/loader/src/gryphn_loader.h b/projects/loader/src/gryphn_loader.h index 606ec3e..7aaefe1 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_gnInstanceQueryDevices queryDevices; PFN_gnDestroyInstance destroyInstance; struct gryphnInstanceFunctionLayers* next; } gryphnInstanceFunctionLayers;