• 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 SubmitInfo
65 	{
66 		uint32_t waitSemaphoreCount;
67 		const VkSemaphore *pWaitSemaphores;
68 		const VkPipelineStageFlags *pWaitDstStageMask;
69 		uint32_t commandBufferCount;
70 		const VkCommandBuffer *pCommandBuffers;
71 		uint32_t signalSemaphoreCount;
72 		const VkSemaphore *pSignalSemaphores;
73 		uint32_t waitSemaphoreValueCount;
74 		const uint64_t *pWaitSemaphoreValues;
75 		uint32_t signalSemaphoreValueCount;
76 		const uint64_t *pSignalSemaphoreValues;
77 	};
78 
79 	struct Task
80 	{
81 		uint32_t submitCount = 0;
82 		SubmitInfo *pSubmits = nullptr;
83 		std::shared_ptr<sw::CountedEvent> events;
84 
85 		enum Type
86 		{
87 			KILL_THREAD,
88 			SUBMIT_QUEUE
89 		};
90 		Type type = SUBMIT_QUEUE;
91 	};
92 
93 	void taskLoop(marl::Scheduler *scheduler);
94 	void garbageCollect();
95 	void submitQueue(const Task &task);
96 	static SubmitInfo *DeepCopySubmitInfo(uint32_t submitCount, const VkSubmitInfo *pSubmits);
97 
98 	Device *device;
99 	std::unique_ptr<sw::Renderer> renderer;
100 	sw::Chan<Task> pending;
101 	sw::Chan<SubmitInfo *> toDelete;
102 	std::thread queueThread;
103 };
104 
Cast(VkQueue object)105 static inline Queue *Cast(VkQueue object)
106 {
107 	return reinterpret_cast<Queue *>(object);
108 }
109 
110 }  // namespace vk
111 
112 #endif  // VK_QUEUE_HPP_
113