xref: /aosp_15_r20/external/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 Google LLC.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef skgpu_graphite_VulkanGraphiteTypes_DEFINED
9 #define skgpu_graphite_VulkanGraphiteTypes_DEFINED
10 
11 #include "include/gpu/graphite/BackendTexture.h"
12 #include "include/gpu/graphite/GraphiteTypes.h"
13 #include "include/gpu/graphite/TextureInfo.h"
14 #include "include/gpu/vk/VulkanTypes.h"
15 
16 namespace skgpu::graphite {
17 
18 struct VulkanTextureInfo {
19     uint32_t fSampleCount = 1;
20     Mipmapped fMipmapped = Mipmapped::kNo;
21 
22     // VkImageCreateInfo properties
23     // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not
24     // be accepted
25     VkImageCreateFlags       fFlags = 0;
26     VkFormat                 fFormat = VK_FORMAT_UNDEFINED;
27     VkImageTiling            fImageTiling = VK_IMAGE_TILING_OPTIMAL;
28     VkImageUsageFlags        fImageUsageFlags = 0;
29     VkSharingMode            fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
30 
31     // Properties related to the image view and sampling. These are less inherent properties of the
32     // VkImage but describe how the VkImage should be used within Skia.
33 
34     // What aspect to use for the VkImageView. The normal, default is VK_IMAGE_ASPECT_COLOR_BIT.
35     // However, if the VkImage is a Ycbcr format, the client can pass a specific plan here to have
36     // Skia directly sample a plane. In that case the client should also pass in a VkFormat that is
37     // compatible with the plane as described by the Vulkan spec.
38     VkImageAspectFlags         fAspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
39     VulkanYcbcrConversionInfo  fYcbcrConversionInfo;
40 
41     VulkanTextureInfo() = default;
VulkanTextureInfoVulkanTextureInfo42     VulkanTextureInfo(uint32_t sampleCount,
43                       Mipmapped mipmapped,
44                       VkImageCreateFlags flags,
45                       VkFormat format,
46                       VkImageTiling imageTiling,
47                       VkImageUsageFlags imageUsageFlags,
48                       VkSharingMode sharingMode,
49                       VkImageAspectFlags aspectMask,
50                       VulkanYcbcrConversionInfo ycbcrConversionInfo)
51             : fSampleCount(sampleCount)
52             , fMipmapped(mipmapped)
53             , fFlags(flags)
54             , fFormat(format)
55             , fImageTiling(imageTiling)
56             , fImageUsageFlags(imageUsageFlags)
57             , fSharingMode(sharingMode)
58             , fAspectMask(aspectMask)
59             , fYcbcrConversionInfo(ycbcrConversionInfo) {}
60 };
61 
62 namespace TextureInfos {
63 SK_API TextureInfo MakeVulkan(const VulkanTextureInfo&);
64 
65 SK_API bool GetVulkanTextureInfo(const TextureInfo&, VulkanTextureInfo*);
66 }  // namespace TextureInfos
67 
68 namespace BackendTextures {
69 SK_API BackendTexture MakeVulkan(SkISize dimensions,
70                                  const VulkanTextureInfo&,
71                                  VkImageLayout,
72                                  uint32_t queueFamilyIndex,
73                                  VkImage,
74                                  VulkanAlloc);
75 }  // namespace BackendTextures
76 
77 namespace BackendSemaphores {
78 SK_API BackendSemaphore MakeVulkan(VkSemaphore);
79 
80 SK_API VkSemaphore GetVkSemaphore(const BackendSemaphore&);
81 
82 }  // namespace BackendSemaphores
83 
84 }  // namespace skgpu::graphite
85 
86 #endif  // skgpu_graphite_VulkanGraphiteTypes_DEFINED
87