1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
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"
25 Queue::Queue(uint32_t pFamilyIndex, float pPriority) : familyIndex(pFamilyIndex), priority(pPriority)
27 context = new sw::Context();
28 renderer = new sw::Renderer(context, sw::OpenGL, true);
37 void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
39 for(uint32_t i = 0; i < submitCount; i++)
41 auto& submitInfo = pSubmits[i];
42 for(uint32_t j = 0; j < submitInfo.waitSemaphoreCount; j++)
44 vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]);
48 CommandBuffer::ExecutionState executionState;
49 executionState.renderer = renderer;
50 for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++)
52 vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);
56 for(uint32_t j = 0; j < submitInfo.signalSemaphoreCount; j++)
58 vk::Cast(submitInfo.pSignalSemaphores[j])->signal();
62 // FIXME (b/117835459): signal the fence only once the work is completed
63 if(fence != VK_NULL_HANDLE)
65 vk::Cast(fence)->signal();
69 void Queue::waitIdle()
71 // equivalent to submitting a fence to a queue and waiting
72 // with an infinite timeout for that fence to signal
74 // FIXME (b/117835459): implement once we have working fences
77 void Queue::present(const VkPresentInfoKHR* presentInfo)
79 for(uint32_t i = 0; i < presentInfo->waitSemaphoreCount; i++)
81 vk::Cast(presentInfo->pWaitSemaphores[i])->wait();
84 for(uint32_t i = 0; i < presentInfo->swapchainCount; i++)
86 vk::Cast(presentInfo->pSwapchains[i])->present(presentInfo->pImageIndices[i]);