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
+3
View File
@@ -38,6 +38,9 @@
"value": "/opt/homebrew/opt/vulkan-validationlayers/share/vulkan/explicit_layer.d"
}
],
"logging": {
"moduleLoad": false
},
"externalConsole": false,
"MIMode": "lldb",
"targetArchitecture": "arm64"
+1 -1
View File
@@ -89,7 +89,7 @@ void TextureAsset::load(ArchiveBuffer& buffer)
.sourceData = {
.size = ktxTexture_GetDataSize(ktxTexture(kTexture)),
.data = ktxTexture_GetData(ktxTexture(kTexture)),
.owner = Gfx::QueueType::DEDICATED_TRANSFER,
.owner = Gfx::QueueType::TRANSFER,
},
.format = Vulkan::cast((VkFormat)kTexture->vkFormat),
.width = kTexture->baseWidth,
+1 -2
View File
@@ -164,7 +164,7 @@ typedef uint32 KeyModifierFlags;
namespace Gfx
{
static constexpr bool useAsyncCompute = true;
static constexpr bool useAsyncCompute = false;
static constexpr bool useMeshShading = true;
static constexpr uint32 numFramesBuffered = 3;
@@ -179,7 +179,6 @@ enum class QueueType
GRAPHICS = 1,
COMPUTE = 2,
TRANSFER = 3,
DEDICATED_TRANSFER = 4
};
typedef uint32_t SeFlags;
@@ -201,6 +201,7 @@ void BasePass::createRenderPass()
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment->setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { colorAttachment },
.depthAttachment = depthAttachment,
@@ -37,6 +37,12 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
};
oLightIndexCounter->updateContents(counterReset);
tLightIndexCounter->updateContents(counterReset);
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
cullingDescriptorLayout->reset();
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
@@ -47,24 +53,6 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
void LightCullingPass::render()
{
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
oLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
depthAttachment->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
@@ -82,7 +70,7 @@ void LightCullingPass::render()
computeCommand->bindDescriptor({ viewParamsSet, dispatchParamsSet, cullingDescriptorSet, lightEnv->getDescriptorSet() });
computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
Array<Gfx::PComputeCommand> commands = {computeCommand};
std::cout << "Execute" << std::endl;
//std::cout << "Execute" << std::endl;
graphics->executeCommands(commands);
//std::cout << "LightCulling render()" << std::endl;
//co_return;
@@ -157,10 +145,10 @@ void LightCullingPass::publishOutputs()
},
.numElements = 1,
.dynamic = true,
//.name = "oLightIndexCounter",
.name = "oLightIndexCounter",
};
oLightIndexCounter = graphics->createShaderBuffer(structInfo);
//structInfo.name = "tLightIndexCounter";
structInfo.name = "tLightIndexCounter";
tLightIndexCounter = graphics->createShaderBuffer(structInfo);
structInfo = {
.sourceData = {
@@ -172,10 +160,10 @@ void LightCullingPass::publishOutputs()
.owner = Gfx::QueueType::COMPUTE
},
.dynamic = false,
//.name = "oLightIndexList",
.name = "oLightIndexList",
};
oLightIndexList = graphics->createShaderBuffer(structInfo);
//structInfo.name = "tLightIndexList";
structInfo.name = "tLightIndexList";
tLightIndexList = graphics->createShaderBuffer(structInfo);
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
-3
View File
@@ -38,7 +38,6 @@ struct QueueFamilyMapping
uint32 graphicsFamily;
uint32 computeFamily;
uint32 transferFamily;
uint32 dedicatedTransferFamily;
uint32 getQueueTypeFamilyIndex(Gfx::QueueType type) const
{
switch (type)
@@ -49,8 +48,6 @@ struct QueueFamilyMapping
return computeFamily;
case Gfx::QueueType::TRANSFER:
return transferFamily;
case Gfx::QueueType::DEDICATED_TRANSFER:
return dedicatedTransferFamily;
default:
return 0x7fff;
}
+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;