ngscopeclient v0.2
Loading...
Searching...
No Matches
QueueManager.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
36#ifndef QueueManager_h
37#define QueueManager_h
38
39#include <map>
40#include <memory>
41#include <mutex>
42#include <tuple>
43#include <vector>
44#include <vulkan/vulkan_raii.hpp>
45
46#include "QueueWrapper.h"
47#include "QueueHandle.h"
48
49class QueueLock;
50
58{
59public:
60 QueueLock(std::shared_ptr<QueueHandle> handle)
61 : m_lock(handle->GetQueue()->m_mutex)
62 , m_handle(handle)
63 { handle->_waitFence(); }
64
65 vk::raii::Queue& operator*()
66 { return *(m_handle->GetQueue()->GetQueue()); }
67
68public:
69 //non-copyable
70 QueueLock(QueueLock const&) = delete;
71 QueueLock& operator=(QueueLock const&) = delete;
72
73protected:
74 const std::lock_guard<std::recursive_mutex> m_lock;
75 std::shared_ptr<QueueHandle> m_handle;
76};
77
78
87{
88public:
89 QueueManager(vk::raii::PhysicalDevice* phys, std::shared_ptr<vk::raii::Device> device);
90
114
116 std::shared_ptr<QueueHandle> GetComputeQueue(const std::string& name)
117 { return GetQueueWithFlags(vk::QueueFlagBits::eCompute | vk::QueueFlagBits::eTransfer, name); }
118
121 std::shared_ptr<QueueHandle> GetRenderQueue(const std::string& name)
122 { return GetQueueWithFlags(vk::QueueFlagBits::eGraphics | vk::QueueFlagBits::eTransfer, name); }
123
126 std::shared_ptr<QueueHandle> GetTransferQueue(const std::string& name)
127 { return GetQueueWithFlags(vk::QueueFlagBits::eCompute | vk::QueueFlagBits::eTransfer, name); }
128
131 std::shared_ptr<QueueHandle> GetQueueWithFlags(vk::QueueFlags flags, std::string name);
132
133public:
134 //non-copyable
135 QueueManager(QueueManager const&) = delete;
136 QueueManager& operator=(QueueManager const&) = delete;
137
138protected:
139 vk::raii::PhysicalDevice* m_phys;
140 std::shared_ptr<vk::raii::Device> m_device;
141
143 std::mutex m_mutex;
144
146 {
147 size_t Family;
148 size_t Index;
149 vk::QueueFlags Flags;
150 std::shared_ptr<QueueWrapper> Handle;
151 };
152
154 std::vector<QueueInfo> m_queues;
155
157 std::map<QueuePoolID, std::vector<QueueInfo> > m_pools;
158
159 //Names of pools
160 std::map<QueuePoolID, std::string> m_poolNames;
161};
162
163#endif
Vulkan queue management.
Declaration of QueueWrapper.
Definition AcceleratorBuffer.h:204
Obtains exclusive access to a Vulkan Queue for the duration of its existence, similar to a std::lock_...
Definition QueueManager.h:58
Allocates and hands out std::shared_ptr<QueueHandle> instances for thread-safe access to Vulkan Queue...
Definition QueueManager.h:87
QueuePoolID
List of different queue pools.
Definition QueueManager.h:95
@ QUEUE_POOL_TRANSFER
Dedicated transfer-only queues.
Definition QueueManager.h:109
@ QUEUE_POOL_RENDER
Queues used for graphics and display.
Definition QueueManager.h:97
@ QUEUE_POOL_MISC
Queues used for other miscellaneous stuff like the scope deskew wizard.
Definition QueueManager.h:112
@ QUEUE_POOL_RASTERIZE
Queues used for rasterizing waveforms.
Definition QueueManager.h:100
@ QUEUE_POOL_FILTER
Queues used for the filter graph (compute/transfer only)
Definition QueueManager.h:106
@ QUEUE_POOL_DRIVER
Queues used for instrument drivers (compute/transfer only)
Definition QueueManager.h:103
std::shared_ptr< QueueHandle > GetComputeQueue(const std::string &name)
Get a handle to a compute queue.
Definition QueueManager.h:116
std::shared_ptr< QueueHandle > GetTransferQueue(const std::string &name)
Definition QueueManager.h:126
std::map< QueuePoolID, std::vector< QueueInfo > > m_pools
Queue pools used for allocation.
Definition QueueManager.h:157
std::shared_ptr< QueueHandle > GetRenderQueue(const std::string &name)
Definition QueueManager.h:121
std::vector< QueueInfo > m_queues
All queues available on the device.
Definition QueueManager.h:154
std::mutex m_mutex
Mutex to guard allocations.
Definition QueueManager.h:143
std::shared_ptr< QueueHandle > GetQueueWithFlags(vk::QueueFlags flags, std::string name)
Definition QueueManager.cpp:144
Definition QueueManager.h:146