• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
40 class Queue
41 {
42 	VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC };
43 
44 public:
45 	Queue(Device *device, marl::Scheduler *scheduler);
46 	~Queue();
47 
operator VkQueue()48 	operator VkQueue()
49 	{
50 		return reinterpret_cast<VkQueue>(this);
51 	}
52 
53 	VkResult submit(uint32_t submitCount, const VkSubmitInfo *pSubmits, Fence *fence);
54 	VkResult waitIdle();
55 #ifndef __ANDROID__
56 	VkResult present(const VkPresentInfoKHR *presentInfo);
57 #endif
58 
59 	void beginDebugUtilsLabel(const VkDebugUtilsLabelEXT *pLabelInfo);
60 	void endDebugUtilsLabel();
61 	void insertDebugUtilsLabel(const VkDebugUtilsLabelEXT *pLabelInfo);
62 
63 private:
64 	struct Task
65 	{
66 		uint32_t submitCount = 0;
67 		VkSubmitInfo *pSubmits = nullptr;
68 		std::shared_ptr<sw::CountedEvent> events;
69 
70 		enum Type
71 		{
72 			KILL_THREAD,
73 			SUBMIT_QUEUE
74 		};
75 		Type type = SUBMIT_QUEUE;
76 	};
77 
78 	void taskLoop(marl::Scheduler *scheduler);
79 	void garbageCollect();
80 	void submitQueue(const Task &task);
81 
82 	Device *device;
83 	std::unique_ptr<sw::Renderer> renderer;
84 	sw::Chan<Task> pending;
85 	sw::Chan<VkSubmitInfo *> toDelete;
86 	std::thread queueThread;
87 };
88 
Cast(VkQueue object)89 static inline Queue *Cast(VkQueue object)
90 {
91 	return reinterpret_cast<Queue *>(object);
92 }
93 
94 }  // namespace vk
95 
96 #endif  // VK_QUEUE_HPP_
97