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
21 namespace vk
22 {
23
Queue(uint32_t pFamilyIndex,float pPriority)24 Queue::Queue(uint32_t pFamilyIndex, float pPriority) : familyIndex(pFamilyIndex), priority(pPriority)
25 {
26 context = new sw::Context();
27 renderer = new sw::Renderer(context, sw::OpenGL, true);
28 }
29
destroy()30 void Queue::destroy()
31 {
32 delete context;
33 delete renderer;
34 }
35
submit(uint32_t submitCount,const VkSubmitInfo * pSubmits,VkFence fence)36 void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
37 {
38 for(uint32_t i = 0; i < submitCount; i++)
39 {
40 auto& submitInfo = pSubmits[i];
41 for(uint32_t j = 0; j < submitInfo.waitSemaphoreCount; j++)
42 {
43 vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]);
44 }
45
46 {
47 CommandBuffer::ExecutionState executionState;
48 executionState.renderer = renderer;
49 for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++)
50 {
51 vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);
52 }
53 }
54
55 for(uint32_t j = 0; j < submitInfo.signalSemaphoreCount; j++)
56 {
57 vk::Cast(submitInfo.pSignalSemaphores[j])->signal();
58 }
59 }
60
61 // FIXME (b/117835459): signal the fence only once the work is completed
62 if(fence != VK_NULL_HANDLE)
63 {
64 vk::Cast(fence)->signal();
65 }
66 }
67
waitIdle()68 void Queue::waitIdle()
69 {
70 // equivalent to submitting a fence to a queue and waiting
71 // with an infinite timeout for that fence to signal
72
73 // FIXME (b/117835459): implement once we have working fences
74 }
75
76 } // namespace vk