1 // Copyright (C) 2023 The Android Open Source Project
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 "gfxstream_vk_private.h"
16 
17 #include "vk_sync_dummy.h"
18 
19 /* Under the assumption that Mesa VK runtime queue submission is used, WSI flow
20  * sets this temporary state to a dummy sync type (when no explicit dma-buf
21  * synchronization is available). For gfxstream, ignore this sync object when
22  * this is the case. Synchronization will be done on the host.
23  */
24 
isNoopFence(gfxstream_vk_fence * fence)25 static bool isNoopFence(gfxstream_vk_fence* fence) {
26     return (fence && fence->vk.temporary && vk_sync_type_is_dummy(fence->vk.temporary->type));
27 }
28 
isNoopSemaphore(gfxstream_vk_semaphore * semaphore)29 static bool isNoopSemaphore(gfxstream_vk_semaphore* semaphore) {
30     return (semaphore && semaphore->vk.temporary &&
31             vk_sync_type_is_dummy(semaphore->vk.temporary->type));
32 }
33 
transformVkFenceList(const VkFence * pFences,uint32_t fenceCount)34 std::vector<VkFence> transformVkFenceList(const VkFence* pFences, uint32_t fenceCount) {
35     std::vector<VkFence> outFences;
36     for (uint32_t j = 0; j < fenceCount; ++j) {
37         VK_FROM_HANDLE(gfxstream_vk_fence, gfxstream_fence, pFences[j]);
38         if (!isNoopFence(gfxstream_fence)) {
39             outFences.push_back(gfxstream_fence->internal_object);
40         }
41     }
42     return outFences;
43 }
44 
transformVkSemaphoreList(const VkSemaphore * pSemaphores,uint32_t semaphoreCount)45 std::vector<VkSemaphore> transformVkSemaphoreList(const VkSemaphore* pSemaphores,
46                                                   uint32_t semaphoreCount) {
47     std::vector<VkSemaphore> outSemaphores;
48     for (uint32_t j = 0; j < semaphoreCount; ++j) {
49         VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, pSemaphores[j]);
50         if (!isNoopSemaphore(gfxstream_semaphore)) {
51             outSemaphores.push_back(gfxstream_semaphore->internal_object);
52         }
53     }
54     return outSemaphores;
55 }
56 
transformVkSemaphoreSubmitInfoList(const VkSemaphoreSubmitInfo * pSemaphoreSubmitInfos,uint32_t semaphoreSubmitInfoCount)57 std::vector<VkSemaphoreSubmitInfo> transformVkSemaphoreSubmitInfoList(
58     const VkSemaphoreSubmitInfo* pSemaphoreSubmitInfos, uint32_t semaphoreSubmitInfoCount) {
59     std::vector<VkSemaphoreSubmitInfo> outSemaphoreSubmitInfo;
60     for (uint32_t j = 0; j < semaphoreSubmitInfoCount; ++j) {
61         VkSemaphoreSubmitInfo outInfo = pSemaphoreSubmitInfos[j];
62         VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, outInfo.semaphore);
63         if (!isNoopSemaphore(gfxstream_semaphore)) {
64             outInfo.semaphore = gfxstream_semaphore->internal_object;
65             outSemaphoreSubmitInfo.push_back(outInfo);
66         }
67     }
68     return outSemaphoreSubmitInfo;
69 }
70