• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2016 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef GrVkTypes_DEFINED
10 #define GrVkTypes_DEFINED
11 
12 #include "include/gpu/GrTypes.h"
13 #include "include/gpu/vk/VulkanTypes.h"
14 
15 using GrVkBackendMemory = skgpu::VulkanBackendMemory;
16 using GrVkAlloc = skgpu::VulkanAlloc;
17 
18 // This struct is used to pass in the necessary information to create a VkSamplerYcbcrConversion
19 // object for an VkExternalFormatANDROID.
20 struct GrVkYcbcrConversionInfo {
21     bool operator==(const GrVkYcbcrConversionInfo& that) const {
22         // Invalid objects are not required to have all other fields initialized or matching.
23         if (!this->isValid() && !that.isValid()) {
24             return true;
25         }
26         return this->fFormat == that.fFormat &&
27                this->fExternalFormat == that.fExternalFormat &&
28                this->fYcbcrModel == that.fYcbcrModel &&
29                this->fYcbcrRange == that.fYcbcrRange &&
30                this->fXChromaOffset == that.fXChromaOffset &&
31                this->fYChromaOffset == that.fYChromaOffset &&
32                this->fChromaFilter == that.fChromaFilter &&
33                this->fForceExplicitReconstruction == that.fForceExplicitReconstruction;
34     }
35     bool operator!=(const GrVkYcbcrConversionInfo& that) const { return !(*this == that); }
36 
isValidGrVkYcbcrConversionInfo37     bool isValid() const {
38         return fYcbcrModel != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY ||
39                fExternalFormat != 0;
40     }
41 
42     // Format of the source image. Must be set to VK_FORMAT_UNDEFINED for external images or
43     // a valid image format otherwise.
44     VkFormat fFormat = VK_FORMAT_UNDEFINED;
45 
46     // The external format. Must be non-zero for external images, zero otherwise.
47     // Should be compatible to be used in a VkExternalFormatANDROID struct.
48     uint64_t fExternalFormat = 0;
49 
50     VkSamplerYcbcrModelConversion fYcbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
51     VkSamplerYcbcrRange fYcbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
52     VkChromaLocation fXChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
53     VkChromaLocation fYChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
54     VkFilter fChromaFilter = VK_FILTER_NEAREST;
55     VkBool32 fForceExplicitReconstruction = false;
56 
57     // For external images format features here should be those returned by a call to
58     // vkAndroidHardwareBufferFormatPropertiesANDROID
59     VkFormatFeatureFlags fFormatFeatures = 0;
60 };
61 
62 /*
63  * When wrapping a GrBackendTexture or GrBackendRendenderTarget, the fCurrentQueueFamily should
64  * either be VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_EXTERNAL, or VK_QUEUE_FAMILY_FOREIGN_EXT. If
65  * fSharingMode is VK_SHARING_MODE_EXCLUSIVE then fCurrentQueueFamily can also be the graphics
66  * queue index passed into Skia.
67  */
68 struct GrVkImageInfo {
69     VkImage                  fImage = VK_NULL_HANDLE;
70     skgpu::VulkanAlloc       fAlloc;
71     VkImageTiling            fImageTiling = VK_IMAGE_TILING_OPTIMAL;
72     VkImageLayout            fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
73     VkFormat                 fFormat = VK_FORMAT_UNDEFINED;
74     VkImageUsageFlags        fImageUsageFlags = 0;
75     uint32_t                 fSampleCount = 1;
76     uint32_t                 fLevelCount = 0;
77     uint32_t                 fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED;
78     GrProtected              fProtected = GrProtected::kNo;
79     GrVkYcbcrConversionInfo  fYcbcrConversionInfo;
80     VkSharingMode            fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
81 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
82     bool                     fPartOfSwapchainOrAndroidWindow = false;
83 #endif
84 
85 #if GR_TEST_UTILS
86     bool operator==(const GrVkImageInfo& that) const {
87         bool equal = fImage == that.fImage && fAlloc == that.fAlloc &&
88                      fImageTiling == that.fImageTiling &&
89                      fImageLayout == that.fImageLayout &&
90                      fFormat == that.fFormat &&
91                      fImageUsageFlags == that.fImageUsageFlags &&
92                      fSampleCount == that.fSampleCount &&
93                      fLevelCount == that.fLevelCount &&
94                      fCurrentQueueFamily == that.fCurrentQueueFamily &&
95                      fProtected == that.fProtected &&
96                      fYcbcrConversionInfo == that.fYcbcrConversionInfo &&
97                      fSharingMode == that.fSharingMode;
98 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
99         equal = equal && (fPartOfSwapchainOrAndroidWindow == that.fPartOfSwapchainOrAndroidWindow);
100 #endif
101         return equal;
102     }
103 #endif
104 };
105 
106 using GrVkGetProc = skgpu::VulkanGetProc;
107 
108 /**
109  * This object is wrapped in a GrBackendDrawableInfo and passed in as an argument to
110  * drawBackendGpu() calls on an SkDrawable. The drawable will use this info to inject direct
111  * Vulkan calls into our stream of GPU draws.
112  *
113  * The SkDrawable is given a secondary VkCommandBuffer in which to record draws. The GPU backend
114  * will then execute that command buffer within a render pass it is using for its own draws. The
115  * drawable is also given the attachment of the color index, a compatible VkRenderPass, and the
116  * VkFormat of the color attachment so that it can make VkPipeline objects for the draws. The
117  * SkDrawable must not alter the state of the VkRenderpass or sub pass.
118  *
119  * Additionally, the SkDrawable may fill in the passed in fDrawBounds with the bounds of the draws
120  * that it submits to the command buffer. This will be used by the GPU backend for setting the
121  * bounds in vkCmdBeginRenderPass. If fDrawBounds is not updated, we will assume that the entire
122  * attachment may have been written to.
123  *
124  * The SkDrawable is always allowed to create its own command buffers and submit them to the queue
125  * to render offscreen textures which will be sampled in draws added to the passed in
126  * VkCommandBuffer. If this is done the SkDrawable is in charge of adding the required memory
127  * barriers to the queue for the sampled images since the Skia backend will not do this.
128  */
129 struct GrVkDrawableInfo {
130     VkCommandBuffer fSecondaryCommandBuffer;
131     uint32_t        fColorAttachmentIndex;
132     VkRenderPass    fCompatibleRenderPass;
133     VkFormat        fFormat;
134     VkRect2D*       fDrawBounds;
135 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
136     bool            fFromSwapchainOrAndroidWindow;
137 #endif
138 };
139 
140 struct GrVkSurfaceInfo {
141     uint32_t fSampleCount = 1;
142     uint32_t fLevelCount = 0;
143     GrProtected fProtected = GrProtected::kNo;
144 
145     VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL;
146     VkFormat fFormat = VK_FORMAT_UNDEFINED;
147     VkImageUsageFlags fImageUsageFlags = 0;
148     GrVkYcbcrConversionInfo fYcbcrConversionInfo;
149     VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
150 };
151 
152 #endif
153