1 // Copyright 2022 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 expresso or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <cstdint> 18 #include <vector> 19 20 #include "BorrowedImage.h" 21 #include "goldfish_vk_dispatch.h" 22 23 namespace gfxstream { 24 namespace vk { 25 26 struct BorrowedImageInfoVk : public BorrowedImageInfo { 27 VkImage image = VK_NULL_HANDLE; 28 VkImageView imageView = VK_NULL_HANDLE; 29 VkImageCreateInfo imageCreateInfo = {}; 30 31 // The image layout that `image` is in before composition. 32 // 33 // This is currently ignored for composition target images as 34 // composition targets are expected to be cleared during 35 // composition. 36 VkImageLayout preBorrowLayout = VK_IMAGE_LAYOUT_UNDEFINED; 37 38 // The queue family index that owns `image` before composition. 39 uint32_t preBorrowQueueFamilyIndex = 0; 40 41 // The image layout that `image` should be transitioned to 42 // after composition. 43 // 44 // This is currently ignored for composition target images as 45 // composition targets are expected to be transitioned to 46 // VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL after composition for 47 // blitting to display images. 48 VkImageLayout postBorrowLayout = VK_IMAGE_LAYOUT_UNDEFINED; 49 50 // The queue family index that `image` should be transitioned to 51 // after composition. 52 uint32_t postBorrowQueueFamilyIndex = 0; 53 }; 54 55 // The caller should always record the queue transfer barriers with stages that supoort 56 // VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT. 57 void addNeededBarriersToUseBorrowedImage( 58 const BorrowedImageInfoVk& borrowedImageInfo, uint32_t usedQueueFamilyIndex, 59 VkImageLayout usedInitialImageLayout, VkImageLayout usedFinalImageLayout, 60 VkAccessFlags usedAccessMask, std::vector<VkImageMemoryBarrier>* preUseQueueTransferBarriers, 61 std::vector<VkImageMemoryBarrier>* preUseLayoutTransitionBarriers, 62 std::vector<VkImageMemoryBarrier>* postUseLayoutTransitionBarriers, 63 std::vector<VkImageMemoryBarrier>* postUseQueueTransferBarriers); 64 65 } // namespace vk 66 } // namespace gfxstream 67