1 /* 2 * Copyright (c) 2024 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 GpuImageDesc; 26 27 namespace PlatformHardwareBufferUtil { 28 struct HardwareBufferProperties { 29 VkDeviceSize allocationSize { 0 }; 30 uint32_t memoryTypeBits { 0 }; 31 32 VkFormat format { VK_FORMAT_UNDEFINED }; 33 uint64_t externalFormat { 0 }; 34 VkFormatFeatureFlags formatFeatures { 0 }; 35 VkComponentMapping samplerYcbcrConversionComponents { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, 36 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; 37 VkSamplerYcbcrModelConversion suggestedYcbcrModel { VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY }; 38 VkSamplerYcbcrRange suggestedYcbcrRange { VK_SAMPLER_YCBCR_RANGE_ITU_FULL }; 39 VkChromaLocation suggestedXChromaOffset { VK_CHROMA_LOCATION_COSITED_EVEN }; 40 VkChromaLocation suggestedYChromaOffset { VK_CHROMA_LOCATION_COSITED_EVEN }; 41 }; 42 43 HardwareBufferProperties QueryHwBufferFormatProperties(const DeviceVk& deviceVk, uintptr_t hwBuffer); 44 uint32_t GetMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties, 45 const uint32_t memoryTypeBits, const VkMemoryPropertyFlags memoryPropertyFlags); 46 VkImageCreateInfo GetHwBufferImageCreateInfo(const GpuImageDesc& desc); 47 VkMemoryRequirements GetImageMemoryRequirements(const DeviceVk& deviceVk, const VkImage image, 48 const VkImageAspectFlags imageAspectFlags, const bool useMemoryRequirements2); 49 50 struct HardwareBufferImage { 51 VkImage image; 52 VkDeviceMemory deviceMemory; 53 }; 54 HardwareBufferImage CreateHwPlatformImage(const DeviceVk& deviceVk, const HardwareBufferProperties& hwBufferProperties, 55 const GpuImageDesc& desc, uintptr_t hwBuffer); 56 void DestroyHwPlatformImage(const DeviceVk& deviceVk, VkImage image, VkDeviceMemory deviceMemory); 57 58 void FillYcbcrConversionInfo(const DeviceVk& deviceVk, const HardwareBufferProperties& hwBufferProperties, 59 VkSamplerYcbcrConversionCreateInfo& ycbcrConversionCreateInfo); 60 } // namespace PlatformHardwareBufferUtil 61 RENDER_END_NAMESPACE() 62 63 #endif // VULKAN_PLATFORM_HARDWARE_BUFFER_UTIL_VK_H 64