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
isNoopSemaphore(gfxstream_vk_semaphore * semaphore)19 static bool isNoopSemaphore(gfxstream_vk_semaphore* semaphore) {
20 /* Under the assumption that Mesa VK runtime queue submission is used, WSI flow
21 * sets this temporary state to a dummy sync type (when no explicit dma-buf
22 * synchronization is available). For gfxstream case, ignore this semaphore
23 * when this is the case. Synchronization will be done on the host.
24 */
25 return (semaphore && semaphore->vk.temporary &&
26 vk_sync_type_is_dummy(semaphore->vk.temporary->type));
27 }
28
transformVkSemaphoreList(const VkSemaphore * pSemaphores,uint32_t semaphoreCount)29 std::vector<VkSemaphore> transformVkSemaphoreList(const VkSemaphore* pSemaphores,
30 uint32_t semaphoreCount) {
31 std::vector<VkSemaphore> outSemaphores;
32 for (uint32_t j = 0; j < semaphoreCount; ++j) {
33 VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, pSemaphores[j]);
34 if (!isNoopSemaphore(gfxstream_semaphore)) {
35 outSemaphores.push_back(gfxstream_semaphore->internal_object);
36 }
37 }
38 return outSemaphores;
39 }
40
transformVkSemaphoreSubmitInfoList(const VkSemaphoreSubmitInfo * pSemaphoreSubmitInfos,uint32_t semaphoreSubmitInfoCount)41 std::vector<VkSemaphoreSubmitInfo> transformVkSemaphoreSubmitInfoList(
42 const VkSemaphoreSubmitInfo* pSemaphoreSubmitInfos, uint32_t semaphoreSubmitInfoCount) {
43 std::vector<VkSemaphoreSubmitInfo> outSemaphoreSubmitInfo;
44 for (uint32_t j = 0; j < semaphoreSubmitInfoCount; ++j) {
45 VkSemaphoreSubmitInfo outInfo = pSemaphoreSubmitInfos[j];
46 VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, outInfo.semaphore);
47 if (!isNoopSemaphore(gfxstream_semaphore)) {
48 outInfo.semaphore = gfxstream_semaphore->internal_object;
49 outSemaphoreSubmitInfo.push_back(outInfo);
50 }
51 }
52 return outSemaphoreSubmitInfo;
53 }
54