xref: /aosp_15_r20/external/swiftshader/src/Vulkan/VkQueue.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef VK_QUEUE_HPP_
16 #define VK_QUEUE_HPP_
17 
18 #include "VkObject.hpp"
19 #include "Device/Renderer.hpp"
20 #include "System/Synchronization.hpp"
21 
22 #include <thread>
23 
24 namespace marl {
25 class Scheduler;
26 }
27 
28 namespace sw {
29 
30 class Context;
31 class Renderer;
32 
33 }  // namespace sw
34 
35 namespace vk {
36 
37 class Device;
38 class Fence;
39 struct SubmitInfo;
40 
41 class Queue
42 {
43 	VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC };
44 
45 public:
46 	Queue(Device *device, marl::Scheduler *scheduler);
47 	~Queue();
48 
operator VkQueue()49 	operator VkQueue()
50 	{
51 		return reinterpret_cast<VkQueue>(this);
52 	}
53 
54 	VkResult submit(uint32_t submitCount, SubmitInfo *pSubmits, Fence *fence);
55 	VkResult waitIdle();
56 #ifndef __ANDROID__
57 	VkResult present(const VkPresentInfoKHR *presentInfo);
58 #endif
59 
60 	void beginDebugUtilsLabel(const VkDebugUtilsLabelEXT *pLabelInfo);
61 	void endDebugUtilsLabel();
62 	void insertDebugUtilsLabel(const VkDebugUtilsLabelEXT *pLabelInfo);
63 
64 private:
65 	struct Task
66 	{
67 		uint32_t submitCount = 0;
68 		SubmitInfo *pSubmits = nullptr;
69 		std::shared_ptr<sw::CountedEvent> events;
70 
71 		enum Type
72 		{
73 			KILL_THREAD,
74 			SUBMIT_QUEUE
75 		};
76 		Type type = SUBMIT_QUEUE;
77 	};
78 
79 	void taskLoop(marl::Scheduler *scheduler);
80 	void garbageCollect();
81 	void submitQueue(const Task &task);
82 
83 	Device *device;
84 	std::unique_ptr<sw::Renderer> renderer;
85 	sw::Chan<Task> pending;
86 	sw::Chan<SubmitInfo *> toDelete;
87 	std::thread queueThread;
88 };
89 
Cast(VkQueue object)90 static inline Queue *Cast(VkQueue object)
91 {
92 	return reinterpret_cast<Queue *>(object);
93 }
94 
95 }  // namespace vk
96 
97 #endif  // VK_QUEUE_HPP_
98