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 <vulkan/vk_icd.h> 21 #include <thread> 22 23 #include "System/Synchronization.hpp" 24 25 namespace marl { 26 class Scheduler; 27 } 28 29 namespace sw { 30 31 class Context; 32 class Renderer; 33 34 } // namespace sw 35 36 namespace vk { 37 38 class Device; 39 class Fence; 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, const VkSubmitInfo *pSubmits, Fence *fence); 55 VkResult waitIdle(); 56 #ifndef __ANDROID__ 57 VkResult present(const VkPresentInfoKHR *presentInfo); 58 #endif 59 60 private: 61 struct Task 62 { 63 uint32_t submitCount = 0; 64 VkSubmitInfo *pSubmits = nullptr; 65 sw::TaskEvents *events = nullptr; 66 67 enum Type 68 { 69 KILL_THREAD, 70 SUBMIT_QUEUE 71 }; 72 Type type = SUBMIT_QUEUE; 73 }; 74 75 void taskLoop(marl::Scheduler *scheduler); 76 void garbageCollect(); 77 void submitQueue(const Task &task); 78 79 Device *device; 80 std::unique_ptr<sw::Renderer> renderer; 81 sw::Chan<Task> pending; 82 sw::Chan<VkSubmitInfo *> toDelete; 83 std::thread queueThread; 84 }; 85 Cast(VkQueue object)86static inline Queue *Cast(VkQueue object) 87 { 88 return reinterpret_cast<Queue *>(object); 89 } 90 91 } // namespace vk 92 93 #endif // VK_QUEUE_HPP_ 94