ngscopeclient v0.2
Loading...
Searching...
No Matches
QueueHandle.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 QueueHandle_h
37#define QueueHandle_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
48//needs to be here not in ScratchBufferManager so QueueHandle can use it
50{
51public:
53 virtual ~ScratchBufferBase();
54};
55
65{
66public:
67
68 QueueHandle(std::shared_ptr<QueueWrapper>& queue, const std::string& name);
70
72 void Submit(vk::raii::CommandBuffer const& cmdBuf);
73
75 void SubmitAndBlock(vk::raii::CommandBuffer const& cmdBuf);
76
77 const std::string GetName() const
78 { return m_queue->GetName(); }
79
87 template<class T>
89
93 void WaitIdle()
94 {
95 const std::lock_guard<std::recursive_mutex> lock(m_queue->GetMutex());
96 _waitFence();
97 }
98
100
101 std::shared_ptr<QueueWrapper> GetQueue()
102 { return m_queue; }
103
104public:
105 //non-copyable
106 QueueHandle(QueueHandle const&) = delete;
107 QueueHandle& operator=(QueueHandle const&) = delete;
108
109protected:
112 void _waitFence();
113
114protected:
115 friend QueueLock;
116 std::shared_ptr<QueueWrapper> m_queue;
117 std::unique_ptr<vk::raii::Fence> m_fence;
118 bool m_fenceBusy;
119
120 std::string m_fenceName;
121
123 std::recursive_mutex m_fenceMutex;
124
126 std::set<std::unique_ptr<ScratchBufferBase> > m_usedScratchBuffers;
127};
128
129
130#endif
Declaration of QueueWrapper.
Definition AcceleratorBuffer.h:204
Wrapper around a Vulkan Queue object.
Definition QueueHandle.h:65
void Submit(vk::raii::CommandBuffer const &cmdBuf)
Submit the given command buffer on the queue.
Definition QueueHandle.cpp:86
void WaitIdle()
Wait for all previous submits to complete.
Definition QueueHandle.h:93
void SubmitAndBlock(vk::raii::CommandBuffer const &cmdBuf)
Submit the given command buffer on the queue and wait until completion.
Definition QueueHandle.cpp:98
bool WaitIdleWithTimeout(uint64_t nanoseconds)
Wait for previous submits to complete, but only up to a timeout.
Definition QueueHandle.cpp:122
std::recursive_mutex m_fenceMutex
The mutex controlling access to the fence.
Definition QueueHandle.h:123
std::set< std::unique_ptr< ScratchBufferBase > > m_usedScratchBuffers
Scratch buffers used by jobs in the queue.
Definition QueueHandle.h:126
void _waitFence()
Definition QueueHandle.cpp:141
void MarkScratchBufferUsed(T &buf)
Mark a scratch buffer as in use by command buffers pending for this queue.
Definition ScratchBufferManager.h:187
Obtains exclusive access to a Vulkan Queue for the duration of its existence, similar to a std::lock_...
Definition QueueManager.h:58
Definition QueueHandle.h:50