ngscopeclient v0.2.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
79{
80 size_t Family;
81 size_t Index;
82 vk::QueueFlags Flags;
83 std::shared_ptr<QueueWrapper> Handle;
84};
85
86bool operator<(const QueueInfo& a, const QueueInfo& b);
87
96{
97public:
98 QueueManager(vk::raii::PhysicalDevice* phys, std::shared_ptr<vk::raii::Device> device);
99
123
124 std::shared_ptr<QueueHandle> GetQueueFromPool(QueuePoolID id, std::string name);
125
126public:
127 //non-copyable
128 QueueManager(QueueManager const&) = delete;
129 QueueManager& operator=(QueueManager const&) = delete;
130
131protected:
132 vk::raii::PhysicalDevice* m_phys;
133 std::shared_ptr<vk::raii::Device> m_device;
134
136 std::mutex m_mutex;
137
139 std::vector< std::shared_ptr<QueueInfo> > m_queues;
140
142 std::map<QueuePoolID, std::vector< std::shared_ptr<QueueInfo> > > m_pools;
143
144 //Names of pools
145 std::map<QueuePoolID, std::string> m_poolNames;
146};
147
148#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:96
QueuePoolID
List of different queue pools.
Definition QueueManager.h:104
@ QUEUE_POOL_TRANSFER
Dedicated transfer-only queues.
Definition QueueManager.h:118
@ QUEUE_POOL_RENDER
Queues used for graphics and display.
Definition QueueManager.h:106
@ QUEUE_POOL_MISC
Queues used for other miscellaneous stuff like the scope deskew wizard.
Definition QueueManager.h:121
@ QUEUE_POOL_RASTERIZE
Queues used for rasterizing waveforms.
Definition QueueManager.h:109
@ QUEUE_POOL_FILTER
Queues used for the filter graph (compute/transfer only)
Definition QueueManager.h:115
@ QUEUE_POOL_DRIVER
Queues used for instrument drivers (compute/transfer only)
Definition QueueManager.h:112
std::map< QueuePoolID, std::vector< std::shared_ptr< QueueInfo > > > m_pools
Queue pools used for allocation.
Definition QueueManager.h:142
std::shared_ptr< QueueHandle > GetQueueFromPool(QueuePoolID id, std::string name)
Get a queue handle for a specific pool, preferring one that has less contention.
Definition QueueManager.cpp:304
std::mutex m_mutex
Mutex to guard allocations.
Definition QueueManager.h:136
std::vector< std::shared_ptr< QueueInfo > > m_queues
All queues available on the device.
Definition QueueManager.h:139
Definition QueueManager.h:79