OSDN Git Service

fcec019b177fb2dea4454f338c4ca1c19e4e8880
[android-x86/external-swiftshader.git] / src / Vulkan / VkQueue.cpp
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 #include "VkCommandBuffer.hpp"
16 #include "VkFence.hpp"
17 #include "VkQueue.hpp"
18 #include "VkSemaphore.hpp"
19 #include "Device/Renderer.hpp"
20 #include "WSI/VkSwapchainKHR.hpp"
21
22 namespace vk
23 {
24
25 Queue::Queue(uint32_t pFamilyIndex, float pPriority) : familyIndex(pFamilyIndex), priority(pPriority)
26 {
27         context = new sw::Context();
28         renderer = new sw::Renderer(context, sw::OpenGL, true);
29 }
30
31 void Queue::destroy()
32 {
33         delete context;
34         delete renderer;
35 }
36
37 void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
38 {
39         for(uint32_t i = 0; i < submitCount; i++)
40         {
41                 auto& submitInfo = pSubmits[i];
42                 for(uint32_t j = 0; j < submitInfo.waitSemaphoreCount; j++)
43                 {
44                         vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]);
45                 }
46
47                 {
48                         CommandBuffer::ExecutionState executionState;
49                         executionState.renderer = renderer;
50                         for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++)
51                         {
52                                 vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);
53                         }
54                 }
55
56                 for(uint32_t j = 0; j < submitInfo.signalSemaphoreCount; j++)
57                 {
58                         vk::Cast(submitInfo.pSignalSemaphores[j])->signal();
59                 }
60         }
61
62         // FIXME (b/117835459): signal the fence only once the work is completed
63         if(fence != VK_NULL_HANDLE)
64         {
65                 vk::Cast(fence)->signal();
66         }
67 }
68
69 void Queue::waitIdle()
70 {
71         // equivalent to submitting a fence to a queue and waiting
72         // with an infinite timeout for that fence to signal
73
74         // FIXME (b/117835459): implement once we have working fences
75 }
76
77 void Queue::present(const VkPresentInfoKHR* presentInfo)
78 {
79         for(uint32_t i = 0; i < presentInfo->waitSemaphoreCount; i++)
80         {
81                 vk::Cast(presentInfo->pWaitSemaphores[i])->wait();
82         }
83
84         for(uint32_t i = 0; i < presentInfo->swapchainCount; i++)
85         {
86                 vk::Cast(presentInfo->pSwapchains[i])->present(presentInfo->pImageIndices[i]);
87         }
88 }
89
90 } // namespace vk