blob: af80df89dbc62e89c5f9ae10adf63416f374e488 [file] [log] [blame]
Alexis Hetu767b41b2018-09-26 11:25:46 -04001// 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 Hetue1f51b92019-04-23 15:34:34 -040019#include "Device/Renderer.hpp"
Ben Claytoned01f2c2019-05-20 10:42:35 +010020#include "System/Synchronization.hpp"
21
Nicolas Capens2490b1a2020-07-13 14:33:01 -040022#include <thread>
23
Ben Clayton2ed93ab2019-12-17 20:38:03 +000024namespace marl {
25class Scheduler;
26}
Ben Claytond6c61362019-08-14 18:16:01 +010027
Nicolas Capens157ba262019-12-10 17:49:14 -050028namespace sw {
Alexis Hetuaf3c1022018-12-12 13:26:15 -050029
Nicolas Capens157ba262019-12-10 17:49:14 -050030class Context;
31class Renderer;
32
33} // namespace sw
34
35namespace vk {
Alexis Hetu767b41b2018-09-26 11:25:46 -040036
Alexis Hetu35755502019-07-22 13:51:49 -040037class Device;
Alexis Hetu7d96f512019-06-13 18:23:56 -040038class Fence;
39
Alexis Hetu767b41b2018-09-26 11:25:46 -040040class Queue
41{
42 VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC };
43
44public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000045 Queue(Device *device, marl::Scheduler *scheduler);
Ben Clayton7e0a0362019-05-20 11:32:35 +010046 ~Queue();
Alexis Hetu767b41b2018-09-26 11:25:46 -040047
48 operator VkQueue()
49 {
50 return reinterpret_cast<VkQueue>(this);
51 }
52
Ben Clayton2ed93ab2019-12-17 20:38:03 +000053 VkResult submit(uint32_t submitCount, const VkSubmitInfo *pSubmits, Fence *fence);
Alexis Hetue1f51b92019-04-23 15:34:34 -040054 VkResult waitIdle();
Chris Forbes1d667d62019-04-05 08:25:18 -070055#ifndef __ANDROID__
Ben Clayton2ed93ab2019-12-17 20:38:03 +000056 VkResult present(const VkPresentInfoKHR *presentInfo);
Chris Forbes1d667d62019-04-05 08:25:18 -070057#endif
Alexis Hetu072dc0d2018-10-31 11:41:25 -040058
Alexis Hetu767b41b2018-09-26 11:25:46 -040059private:
Alexis Hetue1f51b92019-04-23 15:34:34 -040060 struct Task
61 {
62 uint32_t submitCount = 0;
Ben Clayton2ed93ab2019-12-17 20:38:03 +000063 VkSubmitInfo *pSubmits = nullptr;
64 sw::TaskEvents *events = nullptr;
Alexis Hetue1f51b92019-04-23 15:34:34 -040065
Ben Clayton2ed93ab2019-12-17 20:38:03 +000066 enum Type
67 {
68 KILL_THREAD,
69 SUBMIT_QUEUE
70 };
Alexis Hetue1f51b92019-04-23 15:34:34 -040071 Type type = SUBMIT_QUEUE;
72 };
73
Ben Clayton2ed93ab2019-12-17 20:38:03 +000074 void taskLoop(marl::Scheduler *scheduler);
Alexis Hetue1f51b92019-04-23 15:34:34 -040075 void garbageCollect();
Ben Clayton2ed93ab2019-12-17 20:38:03 +000076 void submitQueue(const Task &task);
Alexis Hetue1f51b92019-04-23 15:34:34 -040077
Ben Clayton2ed93ab2019-12-17 20:38:03 +000078 Device *device;
Ben Clayton1943a292019-07-20 14:42:58 +010079 std::unique_ptr<sw::Renderer> renderer;
Ben Claytoned01f2c2019-05-20 10:42:35 +010080 sw::Chan<Task> pending;
Ben Clayton2ed93ab2019-12-17 20:38:03 +000081 sw::Chan<VkSubmitInfo *> toDelete;
Alexis Hetue1f51b92019-04-23 15:34:34 -040082 std::thread queueThread;
Alexis Hetu767b41b2018-09-26 11:25:46 -040083};
84
Ben Clayton2ed93ab2019-12-17 20:38:03 +000085static inline Queue *Cast(VkQueue object)
Alexis Hetu767b41b2018-09-26 11:25:46 -040086{
Ben Clayton2ed93ab2019-12-17 20:38:03 +000087 return reinterpret_cast<Queue *>(object);
Alexis Hetu767b41b2018-09-26 11:25:46 -040088}
89
Nicolas Capens157ba262019-12-10 17:49:14 -050090} // namespace vk
Alexis Hetu767b41b2018-09-26 11:25:46 -040091
Ben Clayton2ed93ab2019-12-17 20:38:03 +000092#endif // VK_QUEUE_HPP_