xref: /aosp_15_r20/external/mesa3d/src/gfxstream/guest/vulkan_enc/gfxstream_vk_private.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2023 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "gfxstream_vk_private.h"
7 
8 #include "vk_sync_dummy.h"
9 
10 /* Under the assumption that Mesa VK runtime queue submission is used, WSI flow
11  * sets this temporary state to a dummy sync type (when no explicit dma-buf
12  * synchronization is available). For gfxstream, ignore this sync object when
13  * this is the case. Synchronization will be done on the host.
14  */
15 
isNoopFence(gfxstream_vk_fence * fence)16 static bool isNoopFence(gfxstream_vk_fence* fence) {
17     return (fence && fence->vk.temporary && vk_sync_type_is_dummy(fence->vk.temporary->type));
18 }
19 
isNoopSemaphore(gfxstream_vk_semaphore * semaphore)20 static bool isNoopSemaphore(gfxstream_vk_semaphore* semaphore) {
21     return (semaphore && semaphore->vk.temporary &&
22             vk_sync_type_is_dummy(semaphore->vk.temporary->type));
23 }
24 
transformVkFenceList(const VkFence * pFences,uint32_t fenceCount)25 std::vector<VkFence> transformVkFenceList(const VkFence* pFences, uint32_t fenceCount) {
26     std::vector<VkFence> outFences;
27     for (uint32_t j = 0; j < fenceCount; ++j) {
28         VK_FROM_HANDLE(gfxstream_vk_fence, gfxstream_fence, pFences[j]);
29         if (!isNoopFence(gfxstream_fence)) {
30             outFences.push_back(gfxstream_fence->internal_object);
31         }
32     }
33     return outFences;
34 }
35 
transformVkSemaphoreList(const VkSemaphore * pSemaphores,uint32_t semaphoreCount)36 std::vector<VkSemaphore> transformVkSemaphoreList(const VkSemaphore* pSemaphores,
37                                                   uint32_t semaphoreCount) {
38     std::vector<VkSemaphore> outSemaphores;
39     for (uint32_t j = 0; j < semaphoreCount; ++j) {
40         VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, pSemaphores[j]);
41         if (!isNoopSemaphore(gfxstream_semaphore)) {
42             outSemaphores.push_back(gfxstream_semaphore->internal_object);
43         }
44     }
45     return outSemaphores;
46 }
47 
transformVkSemaphoreSubmitInfoList(const VkSemaphoreSubmitInfo * pSemaphoreSubmitInfos,uint32_t semaphoreSubmitInfoCount)48 std::vector<VkSemaphoreSubmitInfo> transformVkSemaphoreSubmitInfoList(
49     const VkSemaphoreSubmitInfo* pSemaphoreSubmitInfos, uint32_t semaphoreSubmitInfoCount) {
50     std::vector<VkSemaphoreSubmitInfo> outSemaphoreSubmitInfo;
51     for (uint32_t j = 0; j < semaphoreSubmitInfoCount; ++j) {
52         VkSemaphoreSubmitInfo outInfo = pSemaphoreSubmitInfos[j];
53         VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, outInfo.semaphore);
54         if (!isNoopSemaphore(gfxstream_semaphore)) {
55             outInfo.semaphore = gfxstream_semaphore->internal_object;
56             outSemaphoreSubmitInfo.push_back(outInfo);
57         }
58     }
59     return outSemaphoreSubmitInfo;
60 }
61