Debian Codegraph @

src/gfxstream/guest/vulkan_enc/gfxstream_vk_private.cpp

raw
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 #include "vulkan/vulkan_core.h"
10
11 /* Under the assumption that Mesa VK runtime queue submission is used, WSI flow
12 * sets this temporary state to a dummy sync type (when no explicit dma-buf
13 * synchronization is available). For gfxstream, ignore this sync object when
14 * this is the case. Synchronization will be done on the host.
15 */
16
17 static bool isNoopFence(gfxstream_vk_fence* fence) {
18 return (fence && fence->vk.temporary && vk_sync_type_is_dummy(fence->vk.temporary->type));
19 }
20
21 static bool isNoopSemaphore(gfxstream_vk_semaphore* semaphore) {
22 return (semaphore && semaphore->vk.temporary &&
23 vk_sync_type_is_dummy(semaphore->vk.temporary->type));
24 }
25
26 std::vector<VkFence> transformVkFenceList(const VkFence* pFences, uint32_t fenceCount) {
27 std::vector<VkFence> outFences;
28 for (uint32_t j = 0; j < fenceCount; ++j) {
29 VK_FROM_HANDLE(gfxstream_vk_fence, gfxstream_fence, pFences[j]);
30 if (!isNoopFence(gfxstream_fence)) {
31 outFences.push_back(gfxstream_fence->internal_object);
32 }
33 }
34 return outFences;
35 }
36
37 std::vector<VkSemaphore> transformVkSemaphoreList(const VkSemaphore* pSemaphores,
38 uint32_t semaphoreCount) {
39 std::vector<VkSemaphore> outSemaphores;
40 for (uint32_t j = 0; j < semaphoreCount; ++j) {
41 VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, pSemaphores[j]);
42 if (!isNoopSemaphore(gfxstream_semaphore)) {
43 outSemaphores.push_back(gfxstream_semaphore->internal_object);
44 }
45 }
46 return outSemaphores;
47 }
48
49 std::vector<VkSemaphoreSubmitInfo> transformVkSemaphoreSubmitInfoList(
50 const VkSemaphoreSubmitInfo* pSemaphoreSubmitInfos, uint32_t semaphoreSubmitInfoCount) {
51 std::vector<VkSemaphoreSubmitInfo> outSemaphoreSubmitInfo;
52 for (uint32_t j = 0; j < semaphoreSubmitInfoCount; ++j) {
53 VkSemaphoreSubmitInfo outInfo = pSemaphoreSubmitInfos[j];
54 VK_FROM_HANDLE(gfxstream_vk_semaphore, gfxstream_semaphore, outInfo.semaphore);
55 if (!isNoopSemaphore(gfxstream_semaphore)) {
56 outInfo.semaphore = gfxstream_semaphore->internal_object;
57 outSemaphoreSubmitInfo.push_back(outInfo);
58 }
59 }
60 return outSemaphoreSubmitInfo;
61 }
62
63 float linearChannelToSRGB(float cl)
64 {
65 if (cl <= 0.0f)
66 return 0.0f;
67 else if (cl < 0.0031308f)
68 return 12.92f * cl;
69 else if (cl < 1.0f)
70 return 1.055f * pow(cl, 0.41666f) - 0.055f;
71 else
72 return 1.0f;
73 }
74
75 float srgbFormatNeedsConversionForClearColor(const VkFormat& format) {
76 return format == VK_FORMAT_R8G8B8A8_SRGB;
77 }