Changing queue acquisition

This commit is contained in:
Dynamitos
2024-02-01 08:42:24 +01:00
parent d903689435
commit 725e7cb67b
11 changed files with 99 additions and 130 deletions
+2 -8
View File
@@ -56,7 +56,7 @@ Buffer::Buffer(PGraphics graphics,
.object = (uint64)buffers[i].buffer,
.pObjectName = this->name.c_str()
};
graphics->vkDebugMarkerSetObjectNameEXT(&nameInfo);
//graphics->vkDebugMarkerSetObjectNameEXT(&nameInfo);
}
}
}
@@ -85,7 +85,7 @@ void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex);
if (owner == Gfx::QueueType::TRANSFER || owner == Gfx::QueueType::DEDICATED_TRANSFER)
if (owner == Gfx::QueueType::TRANSFER)
{
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
@@ -106,12 +106,6 @@ void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstPool = graphics->getTransferCommands();
}
else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER)
{
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstPool = graphics->getDedicatedTransferCommands();
}
else if (newOwner == Gfx::QueueType::COMPUTE)
{
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
+1 -1
View File
@@ -10,7 +10,7 @@ VkBool32 Seele::Vulkan::debugCallback(
void* pUserData)
{
std::cerr << pCallbackData->pMessage << std::endl;
if(messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) || (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT))
{
return VK_FALSE;
}
+70 -79
View File
@@ -22,7 +22,6 @@ using namespace Seele::Vulkan;
thread_local PCommandPool Seele::Vulkan::Graphics::graphicsCommands = nullptr;
thread_local PCommandPool Seele::Vulkan::Graphics::computeCommands = nullptr;
thread_local PCommandPool Seele::Vulkan::Graphics::transferCommands = nullptr;
thread_local PCommandPool Seele::Vulkan::Graphics::dedicatedTransferCommands = nullptr;
Graphics::Graphics()
: instance(VK_NULL_HANDLE)
@@ -309,8 +308,6 @@ PCommandPool Graphics::getQueueCommands(Gfx::QueueType queueType)
return getComputeCommands();
case Gfx::QueueType::TRANSFER:
return getTransferCommands();
case Gfx::QueueType::DEDICATED_TRANSFER:
return getDedicatedTransferCommands();
default:
throw new std::logic_error("invalid queue type");
}
@@ -320,7 +317,7 @@ PCommandPool Graphics::getGraphicsCommands()
if(graphicsCommands == nullptr)
{
std::unique_lock l(poolLock);
graphicsCommands = pools.add(new CommandPool(this, graphicsQueue));
graphicsCommands = pools.add(new CommandPool(this, queues[graphicsQueue]));
}
return graphicsCommands;
}
@@ -328,8 +325,15 @@ PCommandPool Graphics::getComputeCommands()
{
if(computeCommands == nullptr)
{
std::unique_lock l(poolLock);
computeCommands = pools.add(new CommandPool(this, computeQueue));
if(graphicsQueue == computeQueue)
{
computeCommands = getGraphicsCommands();
}
else
{
std::unique_lock l(poolLock);
computeCommands = pools.add(new CommandPool(this, queues[computeQueue]));
}
}
return computeCommands;
}
@@ -337,20 +341,18 @@ PCommandPool Graphics::getTransferCommands()
{
if(transferCommands == nullptr)
{
std::unique_lock l(poolLock);
transferCommands = pools.add(new CommandPool(this, transferQueue));
if(graphicsQueue == transferQueue)
{
transferCommands = getGraphicsCommands();
}
else
{
std::unique_lock l(poolLock);
transferCommands = pools.add(new CommandPool(this, queues[transferQueue]));
}
}
return transferCommands;
}
PCommandPool Graphics::getDedicatedTransferCommands()
{
if(dedicatedTransferCommands == nullptr)
{
std::unique_lock l(poolLock);
dedicatedTransferCommands = pools.add(new CommandPool(this, dedicatedTransferQueue != nullptr ? dedicatedTransferQueue : transferQueue));
}
return dedicatedTransferCommands;
}
VmaAllocator Graphics::getAllocator()
{
@@ -428,7 +430,6 @@ void Graphics::setupDebugCallback()
.pUserData = nullptr,
};
VK_CHECK(CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback));
cmdDebugMarkerSetObjectName = (PFN_vkDebugMarkerSetObjectNameEXT)vkGetInstanceProcAddr(instance, "vkDebugMarkerSetObjectNameEXT");
}
void Graphics::pickPhysicalDevice()
@@ -504,18 +505,19 @@ void Graphics::createDevice(GraphicsInitializer initializer)
};
QueueCreateInfo graphicsQueueInfo;
QueueCreateInfo transferQueueInfo;
QueueCreateInfo dedicatedTransferQueueInfo;
QueueCreateInfo computeQueueInfo;
QueueCreateInfo asyncComputeInfo;
uint32 numPriorities = 0;
auto checkFamilyProperty = [](VkQueueFamilyProperties currProps, uint32 checkBit){
return (currProps.queueFlags & checkBit) == checkBit;
};
auto updateQueueInfo = [&queueProperties](uint32 familyIndex, QueueCreateInfo& info, uint32& numQueues) {
if(info.familyIndex == -1) {
if(queueProperties[familyIndex].queueCount == numQueues)
{
return;
}
info.familyIndex = familyIndex;
numQueues = std::min(numQueues + 1, queueProperties[familyIndex].queueCount);
info.queueIndex = numQueues - 1;
info.queueIndex = numQueues++;
}
};
for (uint32 familyIndex = 0; familyIndex < queueProperties.size(); ++familyIndex)
@@ -525,46 +527,20 @@ void Graphics::createDevice(GraphicsInitializer initializer)
if (checkFamilyProperty(currProps, VK_QUEUE_GRAPHICS_BIT))
{
updateQueueInfo(familyIndex, graphicsQueueInfo, numQueueFamilies);
updateQueueInfo(familyIndex, graphicsQueueInfo, numQueuesForFamily);
}
if (currProps.queueFlags & VK_QUEUE_COMPUTE_BIT)
if(Gfx::useAsyncCompute)
{
if (computeQueueInfo.familyIndex == -1)
if(checkFamilyProperty(currProps, VK_QUEUE_COMPUTE_BIT))
{
computeQueueInfo.familyIndex = familyIndex;
}
if (Gfx::useAsyncCompute && numQueueFamilies > 1)
{
if (asyncComputeInfo.familyIndex == -1)
{
if (familyIndex == (uint32)graphicsQueueInfo.familyIndex)
{
if (currProps.queueCount > 1)
{
asyncComputeInfo.familyIndex = familyIndex;
numQueuesForFamily++;
}
}
else
{
asyncComputeInfo.familyIndex = familyIndex;
}
}
updateQueueInfo(familyIndex, computeQueueInfo, numQueuesForFamily);
}
}
if (currProps.queueFlags & VK_QUEUE_TRANSFER_BIT)
if ((currProps.queueFlags ^ VK_QUEUE_TRANSFER_BIT) == 0)
{
if (transferQueueInfo.familyIndex == -1)
{
transferQueueInfo.familyIndex = familyIndex;
numQueuesForFamily++;
}
if ((currProps.queueFlags ^ VK_QUEUE_TRANSFER_BIT) == 0)
{
dedicatedTransferQueueInfo.familyIndex = familyIndex;
numQueuesForFamily++;
}
updateQueueInfo(familyIndex, transferQueueInfo, numQueuesForFamily);
}
if (numQueuesForFamily > 0)
{
VkDeviceQueueCreateInfo info = {
@@ -616,35 +592,50 @@ void Graphics::createDevice(GraphicsInitializer initializer)
};
VK_CHECK(vkCreateDevice(physicalDevice, &deviceInfo, nullptr, &handle));
std::cout << "Vulkan handle: " << handle << std::endl;
//std::cout << "Vulkan handle: " << handle << std::endl;
cmdDrawMeshTasks = (PFN_vkCmdDrawMeshTasksEXT)vkGetDeviceProcAddr(handle, "vkCmdDrawMeshTasksEXT");
graphicsQueue = new Queue(this, graphicsQueueInfo.familyIndex, 0);
if (Gfx::useAsyncCompute && asyncComputeInfo.familyIndex != -1)
graphicsQueue = 0;
computeQueue = 0;
transferQueue = 0;
queues.add(new Queue(this, graphicsQueueInfo.familyIndex, graphicsQueueInfo.queueIndex));
if(computeQueueInfo.familyIndex != -1)
{
if (asyncComputeInfo.familyIndex == graphicsQueueInfo.familyIndex)
{
// Same family as graphics, but different queue
computeQueue = new Queue(this, asyncComputeInfo.familyIndex, 1);
}
else
{
// Different family
computeQueue = new Queue(this, asyncComputeInfo.familyIndex, 0);
}
computeQueue = queues.size();
queues.add(new Queue(this, computeQueueInfo.familyIndex, computeQueueInfo.queueIndex));
}
else
if(transferQueueInfo.familyIndex != -1)
{
computeQueue = new Queue(this, computeQueueInfo.familyIndex, 0);
transferQueue = queues.size();
queues.add(new Queue(this, transferQueueInfo.familyIndex, transferQueueInfo.queueIndex));
}
transferQueue = new Queue(this, transferQueueInfo.familyIndex, 0);
if (dedicatedTransferQueueInfo.familyIndex != -1)
{
dedicatedTransferQueue = new Queue(this, dedicatedTransferQueueInfo.familyIndex, 0);
}
queueMapping.graphicsFamily = graphicsQueue->getFamilyIndex();
queueMapping.computeFamily = computeQueue->getFamilyIndex();
queueMapping.transferFamily = transferQueue->getFamilyIndex();
queueMapping.dedicatedTransferFamily = dedicatedTransferQueue != nullptr ? dedicatedTransferQueue->getFamilyIndex() : transferQueue->getFamilyIndex();
// if (Gfx::useAsyncCompute && asyncComputeInfo.familyIndex != -1)
// {
// if (asyncComputeInfo.familyIndex == graphicsQueueInfo.familyIndex)
// {
// // Same family as graphics, but different queue
// computeQueue = new Queue(this, asyncComputeInfo.familyIndex, 1);
// }
// else
// {
// // Different family
// computeQueue = new Queue(this, asyncComputeInfo.familyIndex, 0);
// }
// }
// else
// {
// computeQueue = new Queue(this, computeQueueInfo.familyIndex, 0);
// }
// transferQueue = new Queue(this, transferQueueInfo.familyIndex, 0);
// if (dedicatedTransferQueueInfo.familyIndex != -1)
// {
// dedicatedTransferQueue = new Queue(this, dedicatedTransferQueueInfo.familyIndex, 0);
// }
queueMapping.graphicsFamily = queues[graphicsQueue]->getFamilyIndex();
queueMapping.computeFamily = queues[computeQueue]->getFamilyIndex();
queueMapping.transferFamily = queues[transferQueue]->getFamilyIndex();
cmdDebugMarkerSetObjectName = (PFN_vkDebugMarkerSetObjectNameEXT)vkGetInstanceProcAddr(instance, "vkDebugMarkerSetObjectNameEXT");
}
+4 -6
View File
@@ -25,7 +25,6 @@ public:
PCommandPool getGraphicsCommands();
PCommandPool getComputeCommands();
PCommandPool getTransferCommands();
PCommandPool getDedicatedTransferCommands();
VmaAllocator getAllocator();
PDestructionManager getDestructionManager();
@@ -86,14 +85,13 @@ protected:
VkDevice handle;
VkPhysicalDevice physicalDevice;
OQueue graphicsQueue;
OQueue computeQueue;
OQueue transferQueue;
OQueue dedicatedTransferQueue;
Array<OQueue> queues;
uint32 graphicsQueue;
uint32 computeQueue;
uint32 transferQueue;
thread_local static PCommandPool graphicsCommands;
thread_local static PCommandPool computeCommands;
thread_local static PCommandPool transferCommands;
thread_local static PCommandPool dedicatedTransferCommands;
std::mutex poolLock;
Array<OCommandPool> pools;
VkPhysicalDeviceProperties props;
+5 -7
View File
@@ -321,13 +321,17 @@ void TextureBase::executeOwnershipBarrier(Gfx::QueueType newOwner)
.image = image,
.subresourceRange = {
.aspectMask = aspect,
.baseArrayLayer = 0,
.layerCount = arrayCount,
.baseMipLevel = 0,
.levelCount = mipLevels,
},
};
PCommandPool sourcePool = graphics->getQueueCommands(currentOwner);
PCommandPool dstPool = nullptr;
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
if (currentOwner == Gfx::QueueType::TRANSFER || currentOwner == Gfx::QueueType::DEDICATED_TRANSFER)
if (currentOwner == Gfx::QueueType::TRANSFER)
{
imageBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
@@ -348,12 +352,6 @@ void TextureBase::executeOwnershipBarrier(Gfx::QueueType newOwner)
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstPool = graphics->getTransferCommands();
}
else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER)
{
imageBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstPool = graphics->getDedicatedTransferCommands();
}
else if (newOwner == Gfx::QueueType::COMPUTE)
{
imageBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;