• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class SkStream;
17 class SkWStream;
18 
19 namespace skgpu::graphite {
20 
21 class SK_API VulkanTextureInfo final : public TextureInfo::Data {
22 public:
23     // VkImageCreateInfo properties
24     // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not
25     // be accepted
26     VkImageCreateFlags fFlags = 0;
27     VkFormat           fFormat = VK_FORMAT_UNDEFINED;
28     VkImageTiling      fImageTiling = VK_IMAGE_TILING_OPTIMAL;
29     VkImageUsageFlags  fImageUsageFlags = 0;
30     VkSharingMode      fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
31 
32     // Properties related to the image view and sampling. These are less inherent properties of the
33     // VkImage but describe how the VkImage should be used within Skia.
34 
35     // What aspect to use for the VkImageView. The normal, default is VK_IMAGE_ASPECT_COLOR_BIT.
36     // However, if the VkImage is a Ycbcr format, the client can pass a specific plan here to have
37     // Skia directly sample a plane. In that case the client should also pass in a VkFormat that is
38     // compatible with the plane as described by the Vulkan spec.
39     VkImageAspectFlags        fAspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
40     VulkanYcbcrConversionInfo fYcbcrConversionInfo;
41 
42     VulkanTextureInfo() = default;
VulkanTextureInfo(uint32_t sampleCount,Mipmapped mipmapped,VkImageCreateFlags flags,VkFormat format,VkImageTiling imageTiling,VkImageUsageFlags imageUsageFlags,VkSharingMode sharingMode,VkImageAspectFlags aspectMask,VulkanYcbcrConversionInfo ycbcrConversionInfo)43     VulkanTextureInfo(uint32_t sampleCount,
44                       Mipmapped mipmapped,
45                       VkImageCreateFlags flags,
46                       VkFormat format,
47                       VkImageTiling imageTiling,
48                       VkImageUsageFlags imageUsageFlags,
49                       VkSharingMode sharingMode,
50                       VkImageAspectFlags aspectMask,
51                       VulkanYcbcrConversionInfo ycbcrConversionInfo)
52             : Data(sampleCount, mipmapped)
53             , fFlags(flags)
54             , fFormat(format)
55             , fImageTiling(imageTiling)
56             , fImageUsageFlags(imageUsageFlags)
57             , fSharingMode(sharingMode)
58             , fAspectMask(aspectMask)
59             , fYcbcrConversionInfo(ycbcrConversionInfo) {}
60 
61 private:
62     friend class TextureInfo;
63     friend class TextureInfoPriv;
64 
65     // Non-virtual template API for TextureInfo::Data accessed directly when backend type is known.
66     static constexpr skgpu::BackendApi kBackend = skgpu::BackendApi::kVulkan;
67 
isProtected()68     Protected isProtected() const {
69         return fFlags & VK_IMAGE_CREATE_PROTECTED_BIT ? Protected::kYes : Protected::kNo;
70     }
71     TextureFormat viewFormat() const;
72 
73     bool serialize(SkWStream*) const;
74     bool deserialize(SkStream*);
75 
76     // Virtual API when the specific backend type is not available.
77     SkString toBackendString() const override;
78 
copyTo(TextureInfo::AnyTextureInfoData & dstData)79     void copyTo(TextureInfo::AnyTextureInfoData& dstData) const override {
80         dstData.emplace<VulkanTextureInfo>(*this);
81     }
82     bool isCompatible(const TextureInfo& that, bool requireExact) const override;
83 };
84 
85 namespace TextureInfos {
86 SK_API TextureInfo MakeVulkan(const VulkanTextureInfo&);
87 
88 SK_API bool GetVulkanTextureInfo(const TextureInfo&, VulkanTextureInfo*);
89 }  // namespace TextureInfos
90 
91 namespace BackendTextures {
92 SK_API BackendTexture MakeVulkan(SkISize dimensions,
93                                  const VulkanTextureInfo&,
94                                  VkImageLayout,
95                                  uint32_t queueFamilyIndex,
96                                  VkImage,
97                                  VulkanAlloc);
98 }  // namespace BackendTextures
99 
100 namespace BackendSemaphores {
101 SK_API BackendSemaphore MakeVulkan(VkSemaphore);
102 
103 SK_API VkSemaphore GetVkSemaphore(const BackendSemaphore&);
104 }  // namespace BackendSemaphores
105 
106 }  // namespace skgpu::graphite
107 
108 #endif  // skgpu_graphite_VulkanGraphiteTypes_DEFINED
109