vulkan remove queue API
This commit is contained in:
@@ -8,13 +8,13 @@
|
||||
gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
|
||||
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
||||
|
||||
VkDeviceQueueCreateInfo* queueCreateInfos = malloc(sizeof(VkDeviceQueueCreateInfo) * deviceInfo.queueInfoCount);
|
||||
VkDeviceQueueCreateInfo* queueCreateInfos = malloc(sizeof(VkDeviceQueueCreateInfo) * deviceInfo.physicalDevice->physicalDevice->neededQueueCount);
|
||||
float queuePriority = 1.0f;
|
||||
for (int i = 0; i < deviceInfo.queueInfoCount; i++) {
|
||||
for (int i = 0; i < deviceInfo.physicalDevice->physicalDevice->neededQueueCount; i++) {
|
||||
queueCreateInfos[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||
queueCreateInfos[i].flags = 0;
|
||||
queueCreateInfos[i].queueFamilyIndex = deviceInfo.queueInfos[i].queueIndex;
|
||||
queueCreateInfos[i].queueCount = deviceInfo.queueInfos[i].queueCount;
|
||||
queueCreateInfos[i].queueFamilyIndex = deviceInfo.physicalDevice->physicalDevice->neededQueues[i].queueIndex;
|
||||
queueCreateInfos[i].queueCount = 1;
|
||||
queueCreateInfos[i].pQueuePriorities = &queuePriority;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHan
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||
.queueCreateInfoCount = deviceInfo.queueInfoCount,
|
||||
.queueCreateInfoCount = deviceInfo.physicalDevice->physicalDevice->neededQueueCount,
|
||||
.pQueueCreateInfos = queueCreateInfos,
|
||||
.pEnabledFeatures = &deviceFeatures
|
||||
};
|
||||
@@ -45,9 +45,20 @@ gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHan
|
||||
if (vkCreateDevice(deviceInfo.physicalDevice->physicalDevice->device, &deviceCreateInfo, NULL, &outputDevice->outputDevice->device) != VK_SUCCESS)
|
||||
return GN_FAILED_TO_CREATE_DEVICE;
|
||||
|
||||
outputDevice->outputDevice->queues = malloc(sizeof(VkQueue) * deviceInfo.queueInfoCount);
|
||||
for (int i = 0; i < deviceInfo.queueInfoCount; i++) {
|
||||
vkGetDeviceQueue(outputDevice->outputDevice->device, deviceInfo.queueInfos[i].queueIndex, 0, &outputDevice->outputDevice->queues[i]);
|
||||
outputDevice->outputDevice->queues = malloc(sizeof(VkQueue) * deviceInfo.physicalDevice->physicalDevice->neededQueueCount);
|
||||
uint32_t transferQueue = 0;
|
||||
for (int i = 0; i < deviceInfo.physicalDevice->physicalDevice->neededQueueCount; i++) {
|
||||
outputDevice->outputDevice->queues[i].queueInfo = deviceInfo.physicalDevice->physicalDevice->neededQueues[i];
|
||||
|
||||
vkGetDeviceQueue(outputDevice->outputDevice->device, deviceInfo.physicalDevice->physicalDevice->neededQueues[i].queueIndex, 0, &outputDevice->outputDevice->queues[i].queue);
|
||||
if ((outputDevice->outputDevice->queues[i].queueInfo.createFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) {
|
||||
outputDevice->outputDevice->transferQueueIndex = i;
|
||||
transferQueue = outputDevice->outputDevice->queues[i].queueInfo.queueIndex;
|
||||
}
|
||||
|
||||
if ((outputDevice->outputDevice->queues[i].queueInfo.createFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) {
|
||||
outputDevice->outputDevice->graphicsQueueIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t queueCount = 0;
|
||||
@@ -64,19 +75,10 @@ gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHan
|
||||
queueFamilies
|
||||
);
|
||||
|
||||
uint32_t transferQueueIndex = 0;
|
||||
for (int i = 0; i < queueCount; i++) {
|
||||
if ((queueFamilies[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) {
|
||||
transferQueueIndex = i;
|
||||
vkGetDeviceQueue(outputDevice->outputDevice->device, deviceInfo.queueInfos[i].queueIndex, 0, &outputDevice->outputDevice->transferQueue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VkCommandPoolCreateInfo poolInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
|
||||
.queueFamilyIndex = transferQueueIndex
|
||||
.queueFamilyIndex = transferQueue
|
||||
};
|
||||
|
||||
if (vkCreateCommandPool(outputDevice->outputDevice->device, &poolInfo, NULL, &outputDevice->outputDevice->transferCommandPool) != VK_SUCCESS)
|
||||
@@ -116,5 +118,5 @@ VkCommandBuffer gnBeginVulkanTransferOperation(gnDevice device) {
|
||||
return VkBeginTransferOperation(device->outputDevice->device, device->outputDevice->transferCommandPool);
|
||||
}
|
||||
void gnEndVulkanTransferOperation(gnDevice device, VkCommandBuffer buffer) {
|
||||
VkEndTransferOperation(buffer, device->outputDevice->transferCommandPool, device->outputDevice->transferQueue, device->outputDevice->device);
|
||||
VkEndTransferOperation(buffer, device->outputDevice->transferCommandPool, device->outputDevice->queues[device->outputDevice->transferQueueIndex].queue, device->outputDevice->device);
|
||||
}
|
||||
|
||||
@@ -2,20 +2,26 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <output_device/gryphn_output_device.h>
|
||||
#include "buffers/vulkan_buffer.h"
|
||||
#include "vulkan_physical_device.h"
|
||||
|
||||
typedef struct vulkanQueue {
|
||||
VkQueue queue;
|
||||
vulkanNeededQueue queueInfo;
|
||||
} vulkanQueue;
|
||||
|
||||
typedef struct gnPlatformOutputDevice_t {
|
||||
VkDevice device;
|
||||
uint32_t queueCount;
|
||||
VkQueue* queues;
|
||||
|
||||
VkQueue transferQueue;
|
||||
uint32_t transferQueueIndex, graphicsQueueIndex;
|
||||
uint32_t queueCount;
|
||||
vulkanQueue* queues;
|
||||
|
||||
VkCommandPool transferCommandPool;
|
||||
|
||||
VkGryphnBuffer stagingBuffer;
|
||||
VkDeviceSize stagingBufferSize;
|
||||
|
||||
VkFence barrierFence;
|
||||
|
||||
gnBool enabledOversizedDescriptorPools;
|
||||
} gnPlatformOutputDevice;
|
||||
|
||||
|
||||
@@ -56,20 +56,37 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device
|
||||
case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE;
|
||||
}
|
||||
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevices[i], &outputDevices[i]->queueProperties.queueCount, NULL);
|
||||
uint32_t queueFamilyCount = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevices[i], &queueFamilyCount, NULL);
|
||||
VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * queueFamilyCount);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevices[i], &queueFamilyCount, queueFamilies);
|
||||
|
||||
VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * outputDevices[i]->queueProperties.queueCount);
|
||||
outputDevices[i]->queueProperties.queueProperties = malloc(sizeof(gnQueueProperties) * outputDevices[i]->queueProperties.queueCount);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevices[i], &outputDevices[i]->queueProperties.queueCount, queueFamilies);
|
||||
for (int c = 0; c < outputDevices[i]->queueProperties.queueCount; c++) {
|
||||
outputDevices[i]->queueProperties.queueProperties[i].queueCount = queueFamilies[i].queueCount;
|
||||
outputDevices[i]->physicalDevice->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount);
|
||||
gnBool foundGraphicsQueueFamily = gnFalse, foundTransferQueueFamily = gnFalse;
|
||||
for (int c = 0; c < queueFamilyCount; c++) {
|
||||
gnBool hasNeededQueue = gnFalse;
|
||||
|
||||
gnQueueTypeFlags finalQueueType = 0;
|
||||
if (queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) finalQueueType |= GN_QUEUE_GRAPHICS;
|
||||
if (queueFamilies[i].queueFlags & VK_QUEUE_COMPUTE_BIT) finalQueueType |= GN_QUEUE_COMPUTE;
|
||||
if (queueFamilies[i].queueFlags & VK_QUEUE_TRANSFER_BIT) finalQueueType |= GN_QUEUE_TRANSFER;
|
||||
if (queueFamilies[i].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) finalQueueType |= GN_QUEUE_SPARSE_BINDING;
|
||||
outputDevices[i]->queueProperties.queueProperties[i].queueType = finalQueueType;
|
||||
if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) {
|
||||
foundGraphicsQueueFamily = true;
|
||||
hasNeededQueue = gnTrue;
|
||||
}
|
||||
if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) {
|
||||
foundTransferQueueFamily = true;
|
||||
hasNeededQueue = gnTrue;
|
||||
}
|
||||
|
||||
if (hasNeededQueue) {
|
||||
vulkanNeededQueue neededQueue = {
|
||||
.queueIndex = c,
|
||||
.createFlags = 0,
|
||||
.usedForPresent = gnFalse
|
||||
};
|
||||
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;
|
||||
|
||||
outputDevices[i]->physicalDevice->neededQueues[outputDevices[i]->physicalDevice->neededQueueCount] = neededQueue;
|
||||
outputDevices[i]->physicalDevice->neededQueueCount++;
|
||||
}
|
||||
}
|
||||
|
||||
VkPhysicalDeviceProperties physicalDeviceProperties;
|
||||
@@ -78,16 +95,55 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device
|
||||
outputDevices[i]->features.maxDepthSamples = vkSampleCountToGryphn(physicalDeviceProperties.limits.framebufferDepthSampleCounts);
|
||||
outputDevices[i]->features.maxMemoryAllocations = physicalDeviceProperties.limits.maxMemoryAllocationCount;
|
||||
outputDevices[i]->features.maxPushConstantSize = physicalDeviceProperties.limits.maxPushConstantsSize;
|
||||
|
||||
free(queueFamilies);
|
||||
}
|
||||
free(physicalDevices);
|
||||
|
||||
return outputDevices;
|
||||
}
|
||||
|
||||
gnBool queueCanPresentToSurface(gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
|
||||
VkBool32 supportsPresent = VK_FALSE;
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, queueIndex, windowSurface->windowSurface->surface, &supportsPresent);
|
||||
if (supportsPresent)
|
||||
return gnTrue;
|
||||
return gnFalse;
|
||||
gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface) {
|
||||
gnBool foundQueue = gnFalse;
|
||||
for (int 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 = gnTrue;
|
||||
foundQueue = gnTrue;
|
||||
break;
|
||||
}
|
||||
surface->windowSurface->presentQueueIndex = i;
|
||||
}
|
||||
|
||||
if (!foundQueue) {
|
||||
uint32_t queueFamilyCount = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(device->physicalDevice->device, &queueFamilyCount, NULL);
|
||||
|
||||
for (int 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 = gnTrue
|
||||
};
|
||||
foundQueue = gnTrue;
|
||||
surface->windowSurface->presentQueueIndex = device->physicalDevice->neededQueueCount;
|
||||
device->physicalDevice->neededQueueCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundQueue;
|
||||
}
|
||||
|
||||
// gnBool queueCanPresentToSurface(gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
|
||||
// VkBool32 supportsPresent = VK_FALSE;
|
||||
// vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, queueIndex, windowSurface->windowSurface->surface, &supportsPresent);
|
||||
// if (supportsPresent)
|
||||
// return gnTrue;
|
||||
// return gnFalse;
|
||||
// }
|
||||
|
||||
@@ -2,8 +2,17 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <output_device/gryphn_physical_output_device.h>
|
||||
|
||||
typedef struct vulkanNeededQueue {
|
||||
VkQueueFlags createFlags;
|
||||
gnBool usedForPresent;
|
||||
uint32_t queueIndex;
|
||||
} vulkanNeededQueue;
|
||||
|
||||
typedef struct gnPlatformPhysicalDevice_t {
|
||||
VkPhysicalDevice device;
|
||||
uint32_t neededQueueCount;
|
||||
vulkanNeededQueue* neededQueues;
|
||||
|
||||
} gnPlatformPhysicalDevice;
|
||||
|
||||
gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount);
|
||||
|
||||
Reference in New Issue
Block a user