Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 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" |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 19 | #include "Device/Renderer.hpp" |
Ben Clayton | ed01f2c | 2019-05-20 10:42:35 +0100 | [diff] [blame] | 20 | #include "System/Synchronization.hpp" |
| 21 | |
Nicolas Capens | 2490b1a | 2020-07-13 14:33:01 -0400 | [diff] [blame] | 22 | #include <thread> |
| 23 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 24 | namespace marl { |
| 25 | class Scheduler; |
| 26 | } |
Ben Clayton | d6c6136 | 2019-08-14 18:16:01 +0100 | [diff] [blame] | 27 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 28 | namespace sw { |
Alexis Hetu | af3c102 | 2018-12-12 13:26:15 -0500 | [diff] [blame] | 29 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 30 | class Context; |
| 31 | class Renderer; |
| 32 | |
| 33 | } // namespace sw |
| 34 | |
| 35 | namespace vk { |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 36 | |
Alexis Hetu | 3575550 | 2019-07-22 13:51:49 -0400 | [diff] [blame] | 37 | class Device; |
Alexis Hetu | 7d96f51 | 2019-06-13 18:23:56 -0400 | [diff] [blame] | 38 | class Fence; |
| 39 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 40 | class Queue |
| 41 | { |
| 42 | VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC }; |
| 43 | |
| 44 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 45 | Queue(Device *device, marl::Scheduler *scheduler); |
Ben Clayton | 7e0a036 | 2019-05-20 11:32:35 +0100 | [diff] [blame] | 46 | ~Queue(); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 47 | |
| 48 | operator VkQueue() |
| 49 | { |
| 50 | return reinterpret_cast<VkQueue>(this); |
| 51 | } |
| 52 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 53 | VkResult submit(uint32_t submitCount, const VkSubmitInfo *pSubmits, Fence *fence); |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 54 | VkResult waitIdle(); |
Chris Forbes | 1d667d6 | 2019-04-05 08:25:18 -0700 | [diff] [blame] | 55 | #ifndef __ANDROID__ |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 56 | VkResult present(const VkPresentInfoKHR *presentInfo); |
Chris Forbes | 1d667d6 | 2019-04-05 08:25:18 -0700 | [diff] [blame] | 57 | #endif |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 58 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 59 | private: |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 60 | struct Task |
| 61 | { |
| 62 | uint32_t submitCount = 0; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 63 | VkSubmitInfo *pSubmits = nullptr; |
| 64 | sw::TaskEvents *events = nullptr; |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 65 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 66 | enum Type |
| 67 | { |
| 68 | KILL_THREAD, |
| 69 | SUBMIT_QUEUE |
| 70 | }; |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 71 | Type type = SUBMIT_QUEUE; |
| 72 | }; |
| 73 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 74 | void taskLoop(marl::Scheduler *scheduler); |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 75 | void garbageCollect(); |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 76 | void submitQueue(const Task &task); |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 77 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 78 | Device *device; |
Ben Clayton | 1943a29 | 2019-07-20 14:42:58 +0100 | [diff] [blame] | 79 | std::unique_ptr<sw::Renderer> renderer; |
Ben Clayton | ed01f2c | 2019-05-20 10:42:35 +0100 | [diff] [blame] | 80 | sw::Chan<Task> pending; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 81 | sw::Chan<VkSubmitInfo *> toDelete; |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 82 | std::thread queueThread; |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 83 | }; |
| 84 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 85 | static inline Queue *Cast(VkQueue object) |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 86 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 87 | return reinterpret_cast<Queue *>(object); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 90 | } // namespace vk |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 91 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 92 | #endif // VK_QUEUE_HPP_ |