1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 16 #ifndef VULKAN_PLATFORM_HARDWARE_BUFFER_UTIL_VK_H 17 #define VULKAN_PLATFORM_HARDWARE_BUFFER_UTIL_VK_H 18 19 #include <vulkan/vulkan_core.h> 20 21 #include <render/namespace.h> 22 23 RENDER_BEGIN_NAMESPACE() 24 class DeviceVk; 25 struct GpuBufferDesc; 26 struct GpuImageDesc; 27 28 namespace PlatformHardwareBufferUtil { 29 struct HardwareBufferProperties { 30 VkDeviceSize allocationSize { 0 }; 31 uint32_t memoryTypeBits { 0 }; 32 33 VkFormat format { VK_FORMAT_UNDEFINED }; 34 uint64_t externalFormat { 0 }; 35 VkFormatFeatureFlags formatFeatures { 0 }; 36 VkComponentMapping samplerYcbcrConversionComponents { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, 37 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; 38 VkSamplerYcbcrModelConversion suggestedYcbcrModel { VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY }; 39 VkSamplerYcbcrRange suggestedYcbcrRange { VK_SAMPLER_YCBCR_RANGE_ITU_FULL }; 40 VkChromaLocation suggestedXChromaOffset { VK_CHROMA_LOCATION_COSITED_EVEN }; 41 VkChromaLocation suggestedYChromaOffset { VK_CHROMA_LOCATION_COSITED_EVEN }; 42 }; 43 44 HardwareBufferProperties QueryHwBufferFormatProperties(const DeviceVk& deviceVk, uintptr_t hwBuffer); 45 uint32_t GetMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties, 46 uint32_t memoryTypeBits, VkMemoryPropertyFlags memoryPropertyFlags); 47 VkImageCreateInfo GetHwBufferImageCreateInfo(const GpuImageDesc& desc); 48 VkMemoryRequirements GetImageMemoryRequirements( 49 const DeviceVk& deviceVk, VkImage image, VkImageAspectFlags imageAspectFlags, bool useMemoryRequirements2); 50 51 struct HardwareBufferImage { 52 VkImage image; 53 VkDeviceMemory deviceMemory; 54 }; 55 HardwareBufferImage CreateHwPlatformImage(const DeviceVk& deviceVk, const HardwareBufferProperties& hwBufferProperties, 56 const GpuImageDesc& desc, uintptr_t hwBuffer); 57 void DestroyHwPlatformImage(const DeviceVk& deviceVk, VkImage image, VkDeviceMemory deviceMemory); 58 59 void FillYcbcrConversionInfo( 60 const HardwareBufferProperties& hwBufferProperties, VkSamplerYcbcrConversionCreateInfo& ycbcrConversionCreateInfo); 61 62 struct HardwareBufferBuffer { 63 VkBuffer buffer; 64 VkDeviceMemory deviceMemory; 65 }; 66 HardwareBufferBuffer CreateHwPlatformBuffer(const DeviceVk& deviceVk, 67 const HardwareBufferProperties& hwBufferProperties, const GpuBufferDesc& desc, uintptr_t hwBuffer); 68 void DestroyHwPlatformBuffer(const DeviceVk& deviceVk, VkBuffer buffer, VkDeviceMemory deviceMemory); 69 } // namespace PlatformHardwareBufferUtil 70 RENDER_END_NAMESPACE() 71 72 #endif // VULKAN_PLATFORM_HARDWARE_BUFFER_UTIL_VK_H 73