vulkan remove queue API
This commit is contained in:
@@ -7,7 +7,7 @@ gnReturnCode createCommandPool(gnCommandPool commandPool, gnDevice device, gnCom
|
||||
VkCommandPoolCreateInfo poolInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
|
||||
.queueFamilyIndex = info.queueIndex,
|
||||
.queueFamilyIndex = device->outputDevice->queues[device->outputDevice->graphicsQueueIndex].queueInfo.queueIndex,
|
||||
};
|
||||
|
||||
if (vkCreateCommandPool(device->outputDevice->device, &poolInfo, NULL, &commandPool->commandPool->commandPool) != VK_SUCCESS) {
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "vulkan_instance.h"
|
||||
#include <debugger/vulkan_debugger.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct vkUserData {
|
||||
|
@@ -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);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "vulkan_present.h"
|
||||
#include "extensions/synchronization/commands/gryphn_sync_present.h"
|
||||
#include "vulkan_surface/vulkan_surface.h"
|
||||
|
||||
gnReturnCode vulkanPresentSync(gnDevice device, gnPresentSyncInfo info) {
|
||||
VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount);
|
||||
@@ -17,10 +18,7 @@ gnReturnCode vulkanPresentSync(gnDevice device, gnPresentSyncInfo info) {
|
||||
.pImageIndices = info.imageIndices
|
||||
};
|
||||
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue);
|
||||
|
||||
VkResult result = vkQueuePresentKHR(queue, &presentInfo);
|
||||
VkResult result = vkQueuePresentKHR(device->outputDevice->queues[info.presentationQueues[0]->info.surface->windowSurface->presentQueueIndex].queue, &presentInfo);
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE;
|
||||
if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE;
|
||||
return GN_SUCCESS;
|
||||
@@ -40,10 +38,7 @@ gnReturnCode vulkanPresent(gnDevice device, gnPresentInfo info) {
|
||||
.pImageIndices = info.imageIndices
|
||||
};
|
||||
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue);
|
||||
|
||||
VkResult result = vkQueuePresentKHR(queue, &presentInfo);
|
||||
VkResult result = vkQueuePresentKHR(device->outputDevice->queues[info.presentationQueues[0]->info.surface->windowSurface->presentQueueIndex].queue, &presentInfo);
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE;
|
||||
if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE;
|
||||
return GN_SUCCESS;
|
||||
|
@@ -34,8 +34,8 @@ gnReturnCode createPresentationQueue(gnPresentationQueueHandle presentationQueue
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
else
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||
createInfo.queueFamilyIndexCount = presentationInfo.queueFamilyCount;
|
||||
createInfo.pQueueFamilyIndices = presentationInfo.queueFamilies;
|
||||
createInfo.queueFamilyIndexCount = 1;
|
||||
createInfo.pQueueFamilyIndices = &device->outputDevice->queues[presentationInfo.surface->windowSurface->presentQueueIndex].queueInfo.queueIndex;
|
||||
createInfo.preTransform = details.capabilities.currentTransform;
|
||||
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
createInfo.presentMode = presentMode;
|
||||
|
@@ -26,7 +26,7 @@ gnReturnCode vulkanSubmitSync(gnDevice device, gnSubmitSyncInfo info) {
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue);
|
||||
|
||||
if (vkQueueSubmit(queue, 1, &submitInfo, info.fence->fence->fence) != VK_SUCCESS) {
|
||||
if (vkQueueSubmit(device->outputDevice->queues[device->outputDevice->graphicsQueueIndex].queue, 1, &submitInfo, info.fence->fence->fence) != VK_SUCCESS) {
|
||||
free(waitSemaphores);
|
||||
free(waitStages);
|
||||
free(commandBuffers);
|
||||
@@ -55,11 +55,8 @@ gnReturnCode vulkanSubmit(gnDevice device, gnSubmitInfo info) {
|
||||
.pSignalSemaphores = NULL
|
||||
};
|
||||
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue);
|
||||
|
||||
vkResetFences(device->outputDevice->device, 1, &device->outputDevice->barrierFence);
|
||||
if (vkQueueSubmit(queue, 1, &submitInfo, device->outputDevice->barrierFence) != VK_SUCCESS)
|
||||
if (vkQueueSubmit(device->outputDevice->queues[device->outputDevice->graphicsQueueIndex].queue, 1, &submitInfo, device->outputDevice->barrierFence) != VK_SUCCESS)
|
||||
return GN_FAILED_TO_SUBMIT_COMMAND_BUFFER;
|
||||
vkWaitForFences(device->outputDevice->device, 1, &device->outputDevice->barrierFence, VK_TRUE, UINT64_MAX);
|
||||
return GN_SUCCESS;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
typedef struct gnPlatformWindowSurface_t {
|
||||
VkSurfaceKHR surface;
|
||||
uint32_t presentQueueIndex;
|
||||
} gnPlatformWindowSurface;
|
||||
|
||||
VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format);
|
||||
|
Reference in New Issue
Block a user