Debian Codegraph @

include/gpu/graphite/vk/VulkanGraphiteTypes.h

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