Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/vsg/vk/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace vsg
AllocationCallbacks* getAllocationCallbacks() { return _allocator.get(); }
const AllocationCallbacks* getAllocationCallbacks() const { return _allocator.get(); }

const Queues& getQueues() const { return _queues; }

ref_ptr<Queue> getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex = 0);

const Extensions* getExtensions() const { return _extensions.get(); }
Expand Down Expand Up @@ -83,7 +85,7 @@ namespace vsg
ref_ptr<AllocationCallbacks> _allocator;
ref_ptr<Extensions> _extensions;

std::list<ref_ptr<Queue>> _queues;
Queues _queues;
};
VSG_type_name(vsg::Device);

Expand Down
6 changes: 5 additions & 1 deletion include/vsg/vk/Queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace vsg
operator VkQueue() const { return _vkQueue; }
VkQueue vk() const { return _vkQueue; }

VkQueueFlags queueFlags() const { return _queueFlags; }
uint32_t queueFamilyIndex() const { return _queueFamilyIndex; }
uint32_t queueIndex() const { return _queueIndex; }

Expand All @@ -42,7 +43,7 @@ namespace vsg
VkResult waitIdle();

protected:
Queue(VkQueue queue, uint32_t queueFamilyIndex, uint32_t queueIndex);
Queue(VkQueue queue, VkQueueFlags queueFlags, uint32_t queueFamilyIndex, uint32_t queueIndex);
virtual ~Queue();

Queue() = delete;
Expand All @@ -53,10 +54,13 @@ namespace vsg
friend class Device;

VkQueue _vkQueue;
VkQueueFlags _queueFlags;
uint32_t _queueFamilyIndex;
uint32_t _queueIndex;
std::mutex _mutex;
};
VSG_type_name(vsg::Queue);

using Queues = std::vector<ref_ptr<Queue>>;

} // namespace vsg
36 changes: 29 additions & 7 deletions src/vsg/app/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,29 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr
uint32_t numBuffers = 3;

auto device = deviceQueueFamily.device;
uint32_t transferQueueFamily = device->getPhysicalDevice()->getQueueFamily(VK_QUEUE_TRANSFER_BIT);

// get main queue used for RecordAndSubmitTask
ref_ptr<Queue> mainQueue = device->getQueue(deviceQueueFamily.queueFamily);

// get presentat queue if required/supported
ref_ptr<Queue> presentQueue;
if (deviceQueueFamily.presentFamily >= 0) presentQueue = device->getQueue(deviceQueueFamily.presentFamily);

// get an appropriate transfer queue
ref_ptr<Queue> transferQueue = mainQueue;

VkQueueFlags transferQueueFlags = VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT; // use VK_QUEUE_GRAPHICS_BIT to ensure we can blit images
for (auto& queue : device->getQueues())
{
if ((queue->queueFlags() & transferQueueFlags) == transferQueueFlags)
{
if (queue != mainQueue)
{
transferQueue = queue;
break;
}
}
}

if (deviceQueueFamily.presentFamily >= 0)
{
Expand All @@ -474,11 +496,11 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr
recordAndSubmitTask->commandGraphs = commandGraphs;
recordAndSubmitTask->signalSemaphores.emplace_back(renderFinishedSemaphore);
recordAndSubmitTask->windows = windows;
recordAndSubmitTask->queue = device->getQueue(deviceQueueFamily.queueFamily);
recordAndSubmitTask->queue = mainQueue;
recordAndSubmitTasks.emplace_back(recordAndSubmitTask);

recordAndSubmitTask->earlyTransferTask->transferQueue = device->getQueue(transferQueueFamily);
recordAndSubmitTask->lateTransferTask->transferQueue = device->getQueue(transferQueueFamily);
recordAndSubmitTask->earlyTransferTask->transferQueue = transferQueue;
recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue;

auto presentation = vsg::Presentation::create();
presentation->waitSemaphores.emplace_back(renderFinishedSemaphore);
Expand All @@ -492,11 +514,11 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr
// set up Submission with CommandBuffer and signals
auto recordAndSubmitTask = vsg::RecordAndSubmitTask::create(device, numBuffers);
recordAndSubmitTask->commandGraphs = commandGraphs;
recordAndSubmitTask->queue = device->getQueue(deviceQueueFamily.queueFamily);
recordAndSubmitTask->queue = mainQueue;
recordAndSubmitTasks.emplace_back(recordAndSubmitTask);

recordAndSubmitTask->earlyTransferTask->transferQueue = device->getQueue(transferQueueFamily);
recordAndSubmitTask->lateTransferTask->transferQueue = device->getQueue(transferQueueFamily);
recordAndSubmitTask->earlyTransferTask->transferQueue = transferQueue;
recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue;
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/vsg/vk/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ Device::Device(PhysicalDevice* physicalDevice, const QueueSettings& queueSetting
VkQueue vk_queue;
vkGetDeviceQueue(_device, queueInfo.queueFamilyIndex, queueIndex, &vk_queue);

ref_ptr<Queue> queue(new Queue(vk_queue, queueInfo.queueFamilyIndex, queueIndex));
VkQueueFlags queueFlags = 0;

if (queueInfo.queueFamilyIndex < queueFamilyProperties.size())
{
queueFlags = queueFamilyProperties[queueInfo.queueFamilyIndex].queueFlags;
}
else
{
warn("vsg::Device::Device(..) constructor unable to match queue family flags to PhysicalDevice queueFamilyProperties.");
}

ref_ptr<Queue> queue(new Queue(vk_queue, queueFlags, queueInfo.queueFamilyIndex, queueIndex));
_queues.emplace_back(queue);
}
}
Expand Down Expand Up @@ -175,15 +186,11 @@ ref_ptr<Queue> Device::getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex)
if (queue->queueFamilyIndex() == queueFamilyIndex && queue->queueIndex() == queueIndex) return queue;
}

debug("Device::getQueue(", queueFamilyIndex, ", ", queueIndex, ") failed back to next closest.");

for (auto& queue : _queues)
{
if (queue->queueFamilyIndex() == queueFamilyIndex) return queue;
}

warn("Device::getQueue(", queueFamilyIndex, ", ", queueIndex, ") failed to find any suitable Queue.");

return {};
}

Expand Down
3 changes: 2 additions & 1 deletion src/vsg/vk/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

using namespace vsg;

Queue::Queue(VkQueue queue, uint32_t queueFamilyIndex, uint32_t queueIndex) :
Queue::Queue(VkQueue queue, VkQueueFlags queueFlags, uint32_t queueFamilyIndex, uint32_t queueIndex) :
_vkQueue(queue),
_queueFlags(queueFlags),
_queueFamilyIndex(queueFamilyIndex),
_queueIndex(queueIndex)
{
Expand Down