blob: 738f461c6576d1bceab1a7ed0386909c740749ef [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
2 * Copyright 2015 Google Inc.
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrBackendSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/gpu/vk/GrVkBackendContext.h"
10#include "include/gpu/vk/GrVkExtensions.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040011#include "src/gpu/GrRenderTarget.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrShaderCaps.h"
Brian Osman7fbb3632019-07-19 11:38:57 -040014#include "src/gpu/GrUtil.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/SkGr.h"
16#include "src/gpu/vk/GrVkCaps.h"
17#include "src/gpu/vk/GrVkInterface.h"
18#include "src/gpu/vk/GrVkTexture.h"
Ethan Nicholas0be34802019-08-15 12:36:58 -040019#include "src/gpu/vk/GrVkUniformHandler.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/vk/GrVkUtil.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050021
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040022#ifdef SK_BUILD_FOR_ANDROID
23#include <sys/system_properties.h>
24#endif
25
Greg Daniel164a9f02016-02-22 09:56:40 -050026GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
Greg Daniela0651ac2018-08-08 09:23:18 -040027 VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features,
Greg Daniel41f0e282019-01-28 13:15:05 -050028 uint32_t instanceVersion, uint32_t physicalDeviceVersion,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040029 const GrVkExtensions& extensions, GrProtected isProtected)
30 : INHERITED(contextOptions) {
Greg Daniel164a9f02016-02-22 09:56:40 -050031 /**************************************************************************
Brian Salomonf7232642018-09-19 08:58:08 -040032 * GrCaps fields
33 **************************************************************************/
jvanverth62340062016-04-26 08:01:44 -070034 fMipMapSupport = true; // always available in Vulkan
brianosmanf05ab1b2016-05-12 11:01:10 -070035 fSRGBSupport = true; // always available in Vulkan
brianosman88791862016-05-23 10:15:27 -070036 fNPOTTextureTileSupport = true; // always available in Vulkan
Greg Daniel164a9f02016-02-22 09:56:40 -050037 fReuseScratchTextures = true; //TODO: figure this out
38 fGpuTracingSupport = false; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050039 fOversizedStencilSupport = false; //TODO: figure this out
Chris Dalton1d616352017-05-31 12:51:23 -060040 fInstanceAttribSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050041
Brian Salomon9ff5acb2019-05-08 09:04:47 -040042 fSemaphoreSupport = true; // always available in Vulkan
jvanverth84741b32016-09-30 08:39:02 -070043 fFenceSyncSupport = true; // always available in Vulkan
Greg Daniel691f5e72018-02-28 14:21:34 -050044 fCrossContextTextureSupport = true;
Brian Osman499bf1a2018-09-17 11:32:42 -040045 fHalfFloatVertexAttributeSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050046
Brian Salomon1047a492019-07-02 12:25:21 -040047 // We always copy in/out of a transfer buffer so it's trivial to support row bytes.
48 fReadPixelsRowBytesSupport = true;
49 fWritePixelsRowBytesSupport = true;
50
Brian Salomone05ba5a2019-04-08 11:59:07 -040051 fTransferBufferSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050052
53 fMaxRenderTargetSize = 4096; // minimum required by spec
54 fMaxTextureSize = 4096; // minimum required by spec
Greg Daniel164a9f02016-02-22 09:56:40 -050055
Brian Salomonf7232642018-09-19 08:58:08 -040056 fDynamicStateArrayGeometryProcessorTextureSupport = true;
57
Brian Salomon94efbf52016-11-29 13:43:05 -050058 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Greg Daniel164a9f02016-02-22 09:56:40 -050059
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040060 this->init(contextOptions, vkInterface, physDev, features, physicalDeviceVersion, extensions,
61 isProtected);
Greg Daniel164a9f02016-02-22 09:56:40 -050062}
63
Brian Salomon1c53a9f2019-08-12 14:10:12 -040064namespace {
65/**
66 * This comes from section 37.1.6 of the Vulkan spec. Format is
67 * (<bits>|<tag>)_<block_size>_<texels_per_block>.
68 */
69enum class FormatCompatibilityClass {
70 k8_1_1,
71 k16_2_1,
72 k24_3_1,
73 k32_4_1,
74 k64_8_1,
75 k128_16_1,
76 kETC2_RGB_8_16,
77};
78} // anonymous namespace
Robert Phillips66a46032019-06-18 08:00:42 -040079
Brian Salomon1c53a9f2019-08-12 14:10:12 -040080static FormatCompatibilityClass format_compatibility_class(VkFormat format) {
81 switch (format) {
82 case VK_FORMAT_B8G8R8A8_UNORM:
83 case VK_FORMAT_R8G8B8A8_UNORM:
84 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
85 case VK_FORMAT_R8G8B8A8_SRGB:
86 case VK_FORMAT_R16G16_UNORM:
87 case VK_FORMAT_R16G16_SFLOAT:
88 return FormatCompatibilityClass::k32_4_1;
89
90 case VK_FORMAT_R8_UNORM:
91 return FormatCompatibilityClass::k8_1_1;
92
93 case VK_FORMAT_R5G6B5_UNORM_PACK16:
94 case VK_FORMAT_R16_SFLOAT:
95 case VK_FORMAT_R8G8_UNORM:
96 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
97 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
98 case VK_FORMAT_R16_UNORM:
99 return FormatCompatibilityClass::k16_2_1;
100
101 case VK_FORMAT_R16G16B16A16_SFLOAT:
102 case VK_FORMAT_R16G16B16A16_UNORM:
103 return FormatCompatibilityClass::k64_8_1;
104
105 case VK_FORMAT_R8G8B8_UNORM:
106 return FormatCompatibilityClass::k24_3_1;
107
108 case VK_FORMAT_R32G32B32A32_SFLOAT:
109 return FormatCompatibilityClass::k128_16_1;
110 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
111 return FormatCompatibilityClass::kETC2_RGB_8_16;
112
113 default:
114 SK_ABORT("Unsupported VkFormat");
Greg Daniel5c7b5412019-05-10 11:39:55 -0400115 }
Greg Daniel5c7b5412019-05-10 11:39:55 -0400116}
117
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400118bool GrVkCaps::canCopyImage(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr,
119 VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const {
Greg Daniel25af6712018-04-25 10:44:38 -0400120 if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) {
121 return false;
122 }
123
Greg Daniela51e93c2019-03-25 12:30:45 -0400124 if (dstHasYcbcr || srcHasYcbcr) {
125 return false;
126 }
127
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400128 // We require that all Vulkan GrSurfaces have been created with transfer_dst and transfer_src
Greg Daniel25af6712018-04-25 10:44:38 -0400129 // as image usage flags.
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400130 return format_compatibility_class(srcFormat) == format_compatibility_class(dstFormat);
Greg Daniel25af6712018-04-25 10:44:38 -0400131}
132
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400133bool GrVkCaps::canCopyAsBlit(VkFormat dstFormat, int dstSampleCnt, bool dstIsLinear,
134 bool dstHasYcbcr, VkFormat srcFormat, int srcSampleCnt,
Greg Daniela51e93c2019-03-25 12:30:45 -0400135 bool srcIsLinear, bool srcHasYcbcr) const {
Greg Daniel25af6712018-04-25 10:44:38 -0400136 // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src
137 // as image usage flags.
Greg Danielcaa795f2019-05-14 11:54:25 -0400138 if (!this->formatCanBeDstofBlit(dstFormat, dstIsLinear) ||
139 !this->formatCanBeSrcofBlit(srcFormat, srcIsLinear)) {
Greg Daniel25af6712018-04-25 10:44:38 -0400140 return false;
141 }
142
Greg Daniel25af6712018-04-25 10:44:38 -0400143 // We cannot blit images that are multisampled. Will need to figure out if we can blit the
144 // resolved msaa though.
145 if (dstSampleCnt > 1 || srcSampleCnt > 1) {
146 return false;
147 }
148
Greg Daniela51e93c2019-03-25 12:30:45 -0400149 if (dstHasYcbcr || srcHasYcbcr) {
150 return false;
151 }
152
Greg Daniel25af6712018-04-25 10:44:38 -0400153 return true;
154}
155
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400156bool GrVkCaps::canCopyAsResolve(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr,
157 VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const {
Greg Daniel25af6712018-04-25 10:44:38 -0400158 // The src surface must be multisampled.
159 if (srcSampleCnt <= 1) {
160 return false;
161 }
162
163 // The dst must not be multisampled.
164 if (dstSampleCnt > 1) {
165 return false;
166 }
167
168 // Surfaces must have the same format.
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400169 if (srcFormat != dstFormat) {
Greg Daniel25af6712018-04-25 10:44:38 -0400170 return false;
171 }
172
Greg Daniela51e93c2019-03-25 12:30:45 -0400173 if (dstHasYcbcr || srcHasYcbcr) {
174 return false;
175 }
176
Greg Daniel25af6712018-04-25 10:44:38 -0400177 return true;
178}
179
Brian Salomonc67c31c2018-12-06 10:00:03 -0500180bool GrVkCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
181 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400182 if (src->isProtected() && !dst->isProtected()) {
183 return false;
184 }
185
Greg Daniel25af6712018-04-25 10:44:38 -0400186 // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g.
187 // PromiseImage which won't get instantiated right away. Does this need a similar thing like the
188 // tracking of external or rectangle textures in GL? For now we don't create linear textures
189 // internally, and I don't believe anyone is wrapping them.
190 bool srcIsLinear = false;
191 bool dstIsLinear = false;
192
193 int dstSampleCnt = 0;
194 int srcSampleCnt = 0;
195 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
Greg Danielbe7fc462019-01-03 16:40:42 -0500196 // Copying to or from render targets that wrap a secondary command buffer is not allowed
197 // since they would require us to know the VkImage, which we don't have, as well as need us
198 // to stop and start the VkRenderPass which we don't have access to.
199 if (rtProxy->wrapsVkSecondaryCB()) {
200 return false;
201 }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600202 dstSampleCnt = rtProxy->numSamples();
Greg Daniel25af6712018-04-25 10:44:38 -0400203 }
204 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
Greg Danielbe7fc462019-01-03 16:40:42 -0500205 // Copying to or from render targets that wrap a secondary command buffer is not allowed
206 // since they would require us to know the VkImage, which we don't have, as well as need us
207 // to stop and start the VkRenderPass which we don't have access to.
208 if (rtProxy->wrapsVkSecondaryCB()) {
209 return false;
210 }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600211 srcSampleCnt = rtProxy->numSamples();
Greg Daniel25af6712018-04-25 10:44:38 -0400212 }
213 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
214 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
215
Greg Daniela51e93c2019-03-25 12:30:45 -0400216 bool dstHasYcbcr = false;
217 if (auto ycbcr = dst->backendFormat().getVkYcbcrConversionInfo()) {
218 if (ycbcr->isValid()) {
219 dstHasYcbcr = true;
220 }
221 }
222
223 bool srcHasYcbcr = false;
224 if (auto ycbcr = src->backendFormat().getVkYcbcrConversionInfo()) {
225 if (ycbcr->isValid()) {
226 srcHasYcbcr = true;
227 }
228 }
229
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400230 VkFormat dstFormat, srcFormat;
231 SkAssertResult(dst->backendFormat().asVkFormat(&dstFormat));
232 SkAssertResult(src->backendFormat().asVkFormat(&srcFormat));
233
234 return this->canCopyImage(dstFormat, dstSampleCnt, dstHasYcbcr,
235 srcFormat, srcSampleCnt, srcHasYcbcr) ||
236 this->canCopyAsBlit(dstFormat, dstSampleCnt, dstIsLinear, dstHasYcbcr,
237 srcFormat, srcSampleCnt, srcIsLinear, srcHasYcbcr) ||
238 this->canCopyAsResolve(dstFormat, dstSampleCnt, dstHasYcbcr,
239 srcFormat, srcSampleCnt, srcHasYcbcr);
Greg Daniel25af6712018-04-25 10:44:38 -0400240}
241
Greg Daniel7e000222018-12-03 10:08:21 -0500242template<typename T> T* get_extension_feature_struct(const VkPhysicalDeviceFeatures2& features,
243 VkStructureType type) {
244 // All Vulkan structs that could be part of the features chain will start with the
245 // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
246 // so we can get access to the pNext for the next struct.
247 struct CommonVulkanHeader {
248 VkStructureType sType;
249 void* pNext;
250 };
251
252 void* pNext = features.pNext;
253 while (pNext) {
254 CommonVulkanHeader* header = static_cast<CommonVulkanHeader*>(pNext);
255 if (header->sType == type) {
256 return static_cast<T*>(pNext);
257 }
258 pNext = header->pNext;
259 }
260 return nullptr;
261}
262
Greg Daniel164a9f02016-02-22 09:56:40 -0500263void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
Greg Daniela0651ac2018-08-08 09:23:18 -0400264 VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400265 uint32_t physicalDeviceVersion, const GrVkExtensions& extensions,
266 GrProtected isProtected) {
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000267 VkPhysicalDeviceProperties properties;
268 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties));
egdanield5e3b9e2016-03-08 12:19:54 -0800269
egdanield5e3b9e2016-03-08 12:19:54 -0800270 VkPhysicalDeviceMemoryProperties memoryProperties;
271 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties));
272
Greg Daniel41f0e282019-01-28 13:15:05 -0500273 SkASSERT(physicalDeviceVersion <= properties.apiVersion);
Greg Danielc0b03d82018-08-03 14:41:15 -0400274
Greg Danielcb324152019-02-25 11:36:53 -0500275 if (extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 1)) {
276 fSupportsSwapchain = true;
277 }
278
Greg Danielc0b03d82018-08-03 14:41:15 -0400279 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
280 extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) {
281 fSupportsPhysicalDeviceProperties2 = true;
282 }
283
284 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
285 extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) {
286 fSupportsMemoryRequirements2 = true;
287 }
288
289 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Daniel637c06a2018-09-12 09:44:25 -0400290 extensions.hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) {
291 fSupportsBindMemory2 = true;
292 }
293
294 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Danielc0b03d82018-08-03 14:41:15 -0400295 extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) {
296 fSupportsMaintenance1 = true;
297 }
298
299 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
300 extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) {
301 fSupportsMaintenance2 = true;
302 }
303
304 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
305 extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) {
306 fSupportsMaintenance3 = true;
307 }
308
Greg Daniela9979d12018-08-27 15:56:46 -0400309 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Daniel637c06a2018-09-12 09:44:25 -0400310 (extensions.hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) &&
Greg Daniela9979d12018-08-27 15:56:46 -0400311 this->supportsMemoryRequirements2())) {
312 fSupportsDedicatedAllocation = true;
313 }
314
315 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
316 (extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1) &&
317 this->supportsPhysicalDeviceProperties2() &&
318 extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, 1) &&
319 this->supportsDedicatedAllocation())) {
320 fSupportsExternalMemory = true;
321 }
322
323#ifdef SK_BUILD_FOR_ANDROID
Greg Daniel637c06a2018-09-12 09:44:25 -0400324 // Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they
325 // do we don't explicitly require it here even the spec says it is required.
Greg Daniela9979d12018-08-27 15:56:46 -0400326 if (extensions.hasExtension(
Greg Daniel637c06a2018-09-12 09:44:25 -0400327 VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, 2) &&
328 /* extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1) &&*/
329 this->supportsExternalMemory() &&
330 this->supportsBindMemory2()) {
Greg Daniela9979d12018-08-27 15:56:46 -0400331 fSupportsAndroidHWBExternalMemory = true;
Greg Daniel637c06a2018-09-12 09:44:25 -0400332 fSupportsAHardwareBufferImages = true;
Greg Daniela9979d12018-08-27 15:56:46 -0400333 }
334#endif
335
Greg Daniel7e000222018-12-03 10:08:21 -0500336 auto ycbcrFeatures =
337 get_extension_feature_struct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700338 features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES);
Greg Daniel7e000222018-12-03 10:08:21 -0500339 if (ycbcrFeatures && ycbcrFeatures->samplerYcbcrConversion &&
Greg Daniel7e000222018-12-03 10:08:21 -0500340 (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
341 (extensions.hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1) &&
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700342 this->supportsMaintenance1() && this->supportsBindMemory2() &&
343 this->supportsMemoryRequirements2() && this->supportsPhysicalDeviceProperties2()))) {
Greg Daniel7e000222018-12-03 10:08:21 -0500344 fSupportsYcbcrConversion = true;
345 }
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700346
Greg Daniel7e000222018-12-03 10:08:21 -0500347 // We always push back the default GrVkYcbcrConversionInfo so that the case of no conversion
348 // will return a key of 0.
349 fYcbcrInfos.push_back(GrVkYcbcrConversionInfo());
350
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400351 if ((isProtected == GrProtected::kYes) &&
352 (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0))) {
353 fSupportsProtectedMemory = true;
354 fAvoidUpdateBuffers = true;
355 fShouldAlwaysUseDedicatedImageMemory = true;
356 }
357
Greg Daniel313c6952018-08-08 09:24:08 -0400358 this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions);
Greg Daniel36443602018-08-02 12:51:52 -0400359 this->initShaderCaps(properties, features);
Greg Danielf3b11622018-03-01 15:01:27 -0500360
361 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
362#if defined(SK_CPU_X86)
363 // We need to do this before initing the config table since it uses fSRGBSupport
364 if (kImagination_VkVendor == properties.vendorID) {
365 fSRGBSupport = false;
366 }
367#endif
368 }
369
Chris Dalton8e738a22018-10-05 16:41:44 -0600370 if (kQualcomm_VkVendor == properties.vendorID) {
371 // A "clear" load for the CCPR atlas runs faster on QC than a "discard" load followed by a
372 // scissored clear.
373 // On NVIDIA and Intel, the discard load followed by clear is faster.
374 // TODO: Evaluate on ARM, Imagination, and ATI.
375 fPreferFullscreenClears = true;
376 }
377
Greg Daniel44e69f92019-03-20 11:18:25 -0400378 if (kQualcomm_VkVendor == properties.vendorID || kARM_VkVendor == properties.vendorID) {
379 // On Qualcomm and ARM mapping a gpu buffer and doing both reads and writes to it is slow.
380 // Thus for index and vertex buffers we will force to use a cpu side buffer and then copy
381 // the whole buffer up to the gpu.
Greg Daniel78e6a4c2019-03-19 14:13:36 -0400382 fBufferMapThreshold = SK_MaxS32;
383 }
384
385 if (kQualcomm_VkVendor == properties.vendorID) {
386 // On Qualcomm it looks like using vkCmdUpdateBuffer is slower than using a transfer buffer
387 // even for small sizes.
388 fAvoidUpdateBuffers = true;
389 }
390
Chris Dalton0dffbab2019-03-27 13:08:50 -0600391 if (kARM_VkVendor == properties.vendorID) {
392 // ARM seems to do better with more fine triangles as opposed to using the sample mask.
393 // (At least in our current round rect op.)
394 fPreferTrianglesOverSampleMask = true;
395 }
Greg Daniel78e6a4c2019-03-19 14:13:36 -0400396
Greg Danielcaa795f2019-05-14 11:54:25 -0400397 this->initFormatTable(vkInterface, physDev, properties);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700398 this->initStencilFormat(vkInterface, physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -0500399
Greg Daniel691f5e72018-02-28 14:21:34 -0500400 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
401 this->applyDriverCorrectnessWorkarounds(properties);
egdanielc5ec1402016-03-28 12:14:42 -0700402 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500403
Greg Daniel691f5e72018-02-28 14:21:34 -0500404 this->applyOptionsOverrides(contextOptions);
405 fShaderCaps->applyOptionsOverrides(contextOptions);
406}
407
408void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) {
egdaniel6fa0a912016-09-12 11:51:29 -0700409 if (kQualcomm_VkVendor == properties.vendorID) {
410 fMustDoCopiesFromOrigin = true;
Brian Salomona585fe92019-04-09 14:57:00 -0400411 // Transfer doesn't support this workaround.
412 fTransferBufferSupport = false;
egdaniel6fa0a912016-09-12 11:51:29 -0700413 }
414
Greg Daniel80a08dd2017-01-20 10:45:49 -0500415#if defined(SK_BUILD_FOR_WIN)
Greg Daniel900e5c82018-08-28 10:59:24 -0400416 if (kNvidia_VkVendor == properties.vendorID || kIntel_VkVendor == properties.vendorID) {
Greg Daniel80a08dd2017-01-20 10:45:49 -0500417 fMustSleepOnTearDown = true;
418 }
419#elif defined(SK_BUILD_FOR_ANDROID)
420 if (kImagination_VkVendor == properties.vendorID) {
421 fMustSleepOnTearDown = true;
422 }
423#endif
Greg Danielbce5eb92018-03-01 13:13:44 -0500424
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400425#if defined(SK_BUILD_FOR_ANDROID)
426 // Protected memory features have problems in Android P and earlier.
427 if (fSupportsProtectedMemory && (kQualcomm_VkVendor == properties.vendorID)) {
428 char androidAPIVersion[PROP_VALUE_MAX];
429 int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion);
430 if (strLength == 0 || atoi(androidAPIVersion) <= 28) {
431 fSupportsProtectedMemory = false;
432 }
433 }
434#endif
435
Greg Danielddc0c602018-06-18 11:26:30 -0400436 // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages.
437 if (kARM_VkVendor == properties.vendorID) {
438 fShouldAlwaysUseDedicatedImageMemory = true;
439 }
440
Greg Danielbce5eb92018-03-01 13:13:44 -0500441 ////////////////////////////////////////////////////////////////////////////
442 // GrCaps workarounds
443 ////////////////////////////////////////////////////////////////////////////
444
445 if (kARM_VkVendor == properties.vendorID) {
446 fInstanceAttribSupport = false;
Greg Daniel4374e962018-09-28 15:09:47 -0400447 fAvoidWritePixelsFastPath = true; // bugs.skia.org/8064
Greg Danielbce5eb92018-03-01 13:13:44 -0500448 }
449
450 // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32.
451 if (kAMD_VkVendor == properties.vendorID) {
452 fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32);
453 }
454
Greg Danielbce5eb92018-03-01 13:13:44 -0500455 ////////////////////////////////////////////////////////////////////////////
456 // GrShaderCaps workarounds
457 ////////////////////////////////////////////////////////////////////////////
458
Greg Danielbce5eb92018-03-01 13:13:44 -0500459 if (kImagination_VkVendor == properties.vendorID) {
460 fShaderCaps->fAtan2ImplementedAsAtanYOverX = true;
461 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500462}
463
464int get_max_sample_count(VkSampleCountFlags flags) {
465 SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT);
466 if (!(flags & VK_SAMPLE_COUNT_2_BIT)) {
467 return 0;
468 }
469 if (!(flags & VK_SAMPLE_COUNT_4_BIT)) {
470 return 2;
471 }
472 if (!(flags & VK_SAMPLE_COUNT_8_BIT)) {
473 return 4;
474 }
475 if (!(flags & VK_SAMPLE_COUNT_16_BIT)) {
476 return 8;
477 }
478 if (!(flags & VK_SAMPLE_COUNT_32_BIT)) {
479 return 16;
480 }
481 if (!(flags & VK_SAMPLE_COUNT_64_BIT)) {
482 return 32;
483 }
484 return 64;
485}
486
Greg Daniel313c6952018-08-08 09:24:08 -0400487void GrVkCaps::initGrCaps(const GrVkInterface* vkInterface,
488 VkPhysicalDevice physDev,
489 const VkPhysicalDeviceProperties& properties,
jvanverthfd7bd452016-03-25 06:29:52 -0700490 const VkPhysicalDeviceMemoryProperties& memoryProperties,
Greg Daniel313c6952018-08-08 09:24:08 -0400491 const VkPhysicalDeviceFeatures2& features,
492 const GrVkExtensions& extensions) {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400493 // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no
494 // need for us ever to support that amount, and it makes tests which tests all the vertex
495 // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if
496 // we ever find that need.
497 static const uint32_t kMaxVertexAttributes = 64;
498 fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes);
Greg Danielc5cc2de2017-03-20 11:40:58 -0400499
egdanield5e3b9e2016-03-08 12:19:54 -0800500 // We could actually query and get a max size for each config, however maxImageDimension2D will
501 // give the minimum max size across all configs. So for simplicity we will use that for now.
jvanverthe78d4872016-09-27 03:33:05 -0700502 fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
503 fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
Adrienne Walker724afe82018-05-15 11:36:26 -0700504 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
505 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
506 }
507 // Our render targets are always created with textures as the color
508 // attachment, hence this min:
509 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
egdanield5e3b9e2016-03-08 12:19:54 -0800510
Chris Dalton2612bae2018-02-22 13:41:37 -0700511 // TODO: check if RT's larger than 4k incur a performance cost on ARM.
512 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
513
egdanield5e3b9e2016-03-08 12:19:54 -0800514 // Assuming since we will always map in the end to upload the data we might as well just map
515 // from the get go. There is no hard data to suggest this is faster or slower.
cdalton397536c2016-03-25 12:15:03 -0700516 fBufferMapThreshold = 0;
egdanield5e3b9e2016-03-08 12:19:54 -0800517
Brian Salomon105d7c22019-04-16 13:46:14 -0400518 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag | kAsyncRead_MapFlag;
egdanield5e3b9e2016-03-08 12:19:54 -0800519
egdanield5e3b9e2016-03-08 12:19:54 -0800520 fOversizedStencilSupport = true;
Greg Daniel313c6952018-08-08 09:24:08 -0400521
522 if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2) &&
523 this->supportsPhysicalDeviceProperties2()) {
524
525 VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps;
526 blendProps.sType =
527 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT;
528 blendProps.pNext = nullptr;
529
530 VkPhysicalDeviceProperties2 props;
531 props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
532 props.pNext = &blendProps;
533
534 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props));
535
536 if (blendProps.advancedBlendAllOperations == VK_TRUE) {
537 fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
538
539 auto blendFeatures =
540 get_extension_feature_struct<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>(
541 features,
542 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT);
543 if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) {
544 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
545 } else {
546 // TODO: Currently non coherent blends are not supported in our vulkan backend. They
547 // require us to support self dependencies in our render passes.
548 // fBlendEquationSupport = kAdvanced_BlendEquationSupport;
549 }
550 }
551 }
egdanield5e3b9e2016-03-08 12:19:54 -0800552}
553
Greg Daniel36443602018-08-02 12:51:52 -0400554void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties,
Greg Daniela0651ac2018-08-08 09:23:18 -0400555 const VkPhysicalDeviceFeatures2& features) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500556 GrShaderCaps* shaderCaps = fShaderCaps.get();
557 shaderCaps->fVersionDeclString = "#version 330\n";
egdaniel3a15fd42016-04-05 11:00:29 -0700558
egdanield5e3b9e2016-03-08 12:19:54 -0800559 // Vulkan is based off ES 3.0 so the following should all be supported
Brian Salomon1edc5b92016-11-29 13:43:46 -0500560 shaderCaps->fUsesPrecisionModifiers = true;
561 shaderCaps->fFlatInterpolationSupport = true;
Brian Salomon41274562017-09-15 09:40:03 -0700562 // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed
563 // to be true with Vulkan as well.
564 shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID;
egdanield5e3b9e2016-03-08 12:19:54 -0800565
566 // GrShaderCaps
567
Brian Salomon1edc5b92016-11-29 13:43:46 -0500568 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600569
Ethan Nicholas6ac8d362019-01-22 21:43:55 +0000570 // FIXME: http://skbug.com/7733: Disable geometry shaders until Intel/Radeon GMs draw correctly.
571 // shaderCaps->fGeometryShaderSupport =
572 // shaderCaps->fGSInvocationsSupport = features.features.geometryShader;
egdanield632bb42016-03-30 12:06:48 -0700573
Greg Daniela0651ac2018-08-08 09:23:18 -0400574 shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend;
egdanield632bb42016-03-30 12:06:48 -0700575
Brian Salomon1edc5b92016-11-29 13:43:46 -0500576 shaderCaps->fIntegerSupport = true;
Chris Dalton1d616352017-05-31 12:51:23 -0600577 shaderCaps->fVertexIDSupport = true;
Chris Dalton7c7ff032018-03-28 20:09:58 -0600578 shaderCaps->fFPManipulationSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800579
cdaltona6b92ad2016-04-11 12:03:08 -0700580 // Assume the minimum precisions mandated by the SPIR-V spec.
Chris Dalton47c8ed32017-11-15 18:27:09 -0700581 shaderCaps->fFloatIs32Bits = true;
582 shaderCaps->fHalfIs32Bits = false;
cdaltona6b92ad2016-04-11 12:03:08 -0700583
Brian Salomon1edc5b92016-11-29 13:43:46 -0500584 shaderCaps->fMaxFragmentSamplers = SkTMin(
585 SkTMin(properties.limits.maxPerStageDescriptorSampledImages,
586 properties.limits.maxPerStageDescriptorSamplers),
587 (uint32_t)INT_MAX);
Greg Daniel164a9f02016-02-22 09:56:40 -0500588}
589
egdaniel8f1dcaa2016-04-01 10:10:45 -0700590bool stencil_format_supported(const GrVkInterface* interface,
591 VkPhysicalDevice physDev,
592 VkFormat format) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500593 VkFormatProperties props;
594 memset(&props, 0, sizeof(VkFormatProperties));
595 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
egdaniel8f1dcaa2016-04-01 10:10:45 -0700596 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures);
Greg Daniel164a9f02016-02-22 09:56:40 -0500597}
598
egdaniel8f1dcaa2016-04-01 10:10:45 -0700599void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) {
600 // List of legal stencil formats (though perhaps not supported on
601 // the particular gpu/driver) from most preferred to least. We are guaranteed to have either
jvanvertha4b0fed2016-04-27 11:42:21 -0700602 // VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT. VK_FORMAT_D32_SFLOAT_S8_UINT
egdaniel8f1dcaa2016-04-01 10:10:45 -0700603 // can optionally have 24 unused bits at the end so we assume the total bits is 64.
Greg Daniel164a9f02016-02-22 09:56:40 -0500604 static const StencilFormat
605 // internal Format stencil bits total bits packed?
606 gS8 = { VK_FORMAT_S8_UINT, 8, 8, false },
egdaniel8f1dcaa2016-04-01 10:10:45 -0700607 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true },
608 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true };
Greg Daniel164a9f02016-02-22 09:56:40 -0500609
egdaniel8f1dcaa2016-04-01 10:10:45 -0700610 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) {
Ethan Nicholasf610bae2018-09-20 16:55:21 -0400611 fPreferredStencilFormat = gS8;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700612 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) {
Ethan Nicholasf610bae2018-09-20 16:55:21 -0400613 fPreferredStencilFormat = gD24S8;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700614 } else {
615 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT));
Ethan Nicholasf610bae2018-09-20 16:55:21 -0400616 fPreferredStencilFormat = gD32S8;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700617 }
618}
619
Greg Danielcaa795f2019-05-14 11:54:25 -0400620static bool format_is_srgb(VkFormat format) {
Robert Phillipsf209e882019-06-25 15:59:50 -0400621 SkASSERT(GrVkFormatIsSupported(format));
622
Greg Danielcaa795f2019-05-14 11:54:25 -0400623 switch (format) {
624 case VK_FORMAT_R8G8B8A8_SRGB:
Greg Danielcaa795f2019-05-14 11:54:25 -0400625 return true;
Greg Danielcaa795f2019-05-14 11:54:25 -0400626 default:
Greg Danielcaa795f2019-05-14 11:54:25 -0400627 return false;
628 }
629}
630
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400631// These are all the valid VkFormats that we support in Skia. They are roughly ordered from most
Greg Danielcaa795f2019-05-14 11:54:25 -0400632// frequently used to least to improve look up times in arrays.
633static constexpr VkFormat kVkFormats[] = {
634 VK_FORMAT_R8G8B8A8_UNORM,
635 VK_FORMAT_R8_UNORM,
636 VK_FORMAT_B8G8R8A8_UNORM,
637 VK_FORMAT_R5G6B5_UNORM_PACK16,
638 VK_FORMAT_R16G16B16A16_SFLOAT,
639 VK_FORMAT_R16_SFLOAT,
Greg Danielcaa795f2019-05-14 11:54:25 -0400640 VK_FORMAT_R8G8B8_UNORM,
641 VK_FORMAT_R8G8_UNORM,
642 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
643 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
Greg Danieleb4a8272019-05-16 16:52:55 -0400644 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
Greg Danielcaa795f2019-05-14 11:54:25 -0400645 VK_FORMAT_R32G32B32A32_SFLOAT,
Greg Danielcaa795f2019-05-14 11:54:25 -0400646 VK_FORMAT_R8G8B8A8_SRGB,
Robert Phillipsfe18de52019-06-06 17:21:50 -0400647 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
Robert Phillipsfe18de52019-06-06 17:21:50 -0400648 VK_FORMAT_R16_UNORM,
649 VK_FORMAT_R16G16_UNORM,
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700650 VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM,
651 VK_FORMAT_G8_B8R8_2PLANE_420_UNORM,
Robert Phillips66a46032019-06-18 08:00:42 -0400652 // Experimental (for Y416 and mutant P016/P010)
653 VK_FORMAT_R16G16B16A16_UNORM,
654 VK_FORMAT_R16G16_SFLOAT,
Greg Danielcaa795f2019-05-14 11:54:25 -0400655};
656
Greg Daniel0fac8692019-08-16 13:13:17 -0400657void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) {
658#ifdef SK_DEBUG
659 for (size_t i = 0; i < kNumVkFormats; ++i) {
660 const auto& formatInfo = fFormatTable[i];
661 for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
662 const auto& ctInfo = formatInfo.fColorTypeInfos[j];
663 if (ctInfo.fColorType == colorType &&
664 !SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) {
665 bool found = false;
666 for (auto it = formats.begin(); it != formats.end(); ++it) {
667 if (kVkFormats[i] == *it) {
668 found = true;
669 }
670 }
671 SkASSERT(found);
672 }
673 }
674 }
675#endif
676 int idx = static_cast<int>(colorType);
677 for (auto it = formats.begin(); it != formats.end(); ++it) {
678 const auto& info = this->getFormatInfo(*it);
679 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
680 if (info.fColorTypeInfos[i].fColorType == colorType) {
681 fColorTypeToFormatTable[idx] = *it;
682 return;
683 }
684 }
685 }
686}
687
Greg Danielcaa795f2019-05-14 11:54:25 -0400688const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const {
Greg Daniel1ff50212019-08-02 15:54:08 -0400689 GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this);
690 return nonConstThis->getFormatInfo(format);
691}
692
693GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) {
Greg Danielcaa795f2019-05-14 11:54:25 -0400694 static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats,
695 "Size of VkFormats array must match static value in header");
696 for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) {
697 if (kVkFormats[i] == format) {
698 return fFormatTable[i];
699 }
700 }
Greg Daniel1ff50212019-08-02 15:54:08 -0400701 static FormatInfo kInvalidFormat;
Greg Daniel52ee5f62019-06-20 13:38:18 -0400702 return kInvalidFormat;
Greg Danielcaa795f2019-05-14 11:54:25 -0400703}
704
705void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000706 const VkPhysicalDeviceProperties& properties) {
Greg Danielcaa795f2019-05-14 11:54:25 -0400707 static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats,
708 "Size of VkFormats array must match static value in header");
Greg Daniel1ff50212019-08-02 15:54:08 -0400709
Greg Daniel0fac8692019-08-16 13:13:17 -0400710 std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED);
Greg Daniel1ff50212019-08-02 15:54:08 -0400711
Greg Daniel0fac8692019-08-16 13:13:17 -0400712 // Go through all the formats and init their support surface and data GrColorTypes.
Greg Daniel1ff50212019-08-02 15:54:08 -0400713 // Format: VK_FORMAT_R8G8B8A8_UNORM
714 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400715 constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
716 auto& info = this->getFormatInfo(format);
717 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400718 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400719 info.fColorTypeInfoCount = 2;
720 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
721 int ctIdx = 0;
722 // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888
723 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400724 constexpr GrColorType ct = GrColorType::kRGBA_8888;
Greg Daniel1ff50212019-08-02 15:54:08 -0400725 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400726 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400727 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
728 }
729 // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x
730 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400731 constexpr GrColorType ct = GrColorType::kRGB_888x;
Greg Daniel1ff50212019-08-02 15:54:08 -0400732 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400733 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400734 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
735 ctInfo.fTextureSwizzle = GrSwizzle::RGB1();
736 }
737 }
738 }
739
740 // Format: VK_FORMAT_R8_UNORM
741 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400742 constexpr VkFormat format = VK_FORMAT_R8_UNORM;
743 auto& info = this->getFormatInfo(format);
744 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400745 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400746 info.fColorTypeInfoCount = 2;
747 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
748 int ctIdx = 0;
749 // Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8
750 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400751 constexpr GrColorType ct = GrColorType::kAlpha_8;
Greg Daniel1ff50212019-08-02 15:54:08 -0400752 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400753 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400754 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
755 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
756 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
757 }
758 // Format: VK_FORMAT_R8_UNORM, Surface: kGray_8
759 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400760 constexpr GrColorType ct = GrColorType::kGray_8;
Greg Daniel1ff50212019-08-02 15:54:08 -0400761 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400762 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400763 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
764 ctInfo.fTextureSwizzle = GrSwizzle("rrr1");
765 }
766 }
767 }
768 // Format: VK_FORMAT_B8G8R8A8_UNORM
769 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400770 constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
771 auto& info = this->getFormatInfo(format);
772 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400773 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400774 info.fColorTypeInfoCount = 1;
775 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
776 int ctIdx = 0;
777 // Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888
778 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400779 constexpr GrColorType ct = GrColorType::kBGRA_8888;
Greg Daniel1ff50212019-08-02 15:54:08 -0400780 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400781 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400782 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
783 }
784 }
785 }
786 // Format: VK_FORMAT_R5G6B5_UNORM_PACK16
787 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400788 constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16;
789 auto& info = this->getFormatInfo(format);
790 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400791 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400792 info.fColorTypeInfoCount = 1;
793 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
794 int ctIdx = 0;
795 // Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565
796 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400797 constexpr GrColorType ct = GrColorType::kBGR_565;
Greg Daniel1ff50212019-08-02 15:54:08 -0400798 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400799 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400800 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
801 }
802 }
803 }
804 // Format: VK_FORMAT_R16G16B16A16_SFLOAT
805 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400806 constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT;
807 auto& info = this->getFormatInfo(format);
808 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400809 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400810 info.fColorTypeInfoCount = 2;
811 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
812 int ctIdx = 0;
813 // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16
814 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400815 constexpr GrColorType ct = GrColorType::kRGBA_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400816 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400817 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400818 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
819 }
820 // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped
821 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400822 constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped;
Greg Daniel1ff50212019-08-02 15:54:08 -0400823 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400824 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400825 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
826 }
827 }
828 }
829 // Format: VK_FORMAT_R16_SFLOAT
830 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400831 constexpr VkFormat format = VK_FORMAT_R16_SFLOAT;
832 auto& info = this->getFormatInfo(format);
833 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400834 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400835 info.fColorTypeInfoCount = 1;
836 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
837 int ctIdx = 0;
838 // Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16
839 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400840 constexpr GrColorType ct = GrColorType::kAlpha_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400841 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400842 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400843 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
844 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
845 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
846 }
847 }
848 }
849 // Format: VK_FORMAT_R8G8B8_UNORM
850 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400851 constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM;
852 auto& info = this->getFormatInfo(format);
853 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400854 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400855 info.fColorTypeInfoCount = 1;
856 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
857 int ctIdx = 0;
858 // Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x
859 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400860 constexpr GrColorType ct = GrColorType::kRGB_888x;
Greg Daniel1ff50212019-08-02 15:54:08 -0400861 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400862 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400863 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
864 }
865 }
866 }
867 // Format: VK_FORMAT_R8G8_UNORM
868 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400869 constexpr VkFormat format = VK_FORMAT_R8G8_UNORM;
870 auto& info = this->getFormatInfo(format);
871 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400872 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400873 info.fColorTypeInfoCount = 1;
874 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
875 int ctIdx = 0;
876 // Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88
877 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400878 constexpr GrColorType ct = GrColorType::kRG_88;
Greg Daniel1ff50212019-08-02 15:54:08 -0400879 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400880 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400881 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
882 }
883 }
884 }
885 // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32
886 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400887 constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
888 auto& info = this->getFormatInfo(format);
889 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400890 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400891 info.fColorTypeInfoCount = 1;
892 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
893 int ctIdx = 0;
894 // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102
895 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400896 constexpr GrColorType ct = GrColorType::kRGBA_1010102;
Greg Daniel1ff50212019-08-02 15:54:08 -0400897 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400898 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400899 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
900 }
901 }
902 }
903 // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16
904 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400905 constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
906 auto& info = this->getFormatInfo(format);
907 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400908 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400909 info.fColorTypeInfoCount = 1;
910 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
911 int ctIdx = 0;
912 // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444
913 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400914 constexpr GrColorType ct = GrColorType::kABGR_4444;
Greg Daniel1ff50212019-08-02 15:54:08 -0400915 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400916 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400917 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
918 ctInfo.fTextureSwizzle = GrSwizzle::BGRA();
919 ctInfo.fOutputSwizzle = GrSwizzle::BGRA();
920 }
921 }
922 }
923 // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16
924 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400925 constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
926 auto& info = this->getFormatInfo(format);
927 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400928 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400929 info.fColorTypeInfoCount = 1;
930 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
931 int ctIdx = 0;
932 // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444
933 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400934 constexpr GrColorType ct = GrColorType::kABGR_4444;
Greg Daniel1ff50212019-08-02 15:54:08 -0400935 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400936 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400937 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
938 }
939 }
940 }
941 // Format: VK_FORMAT_R32G32B32A32_SFLOAT
942 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400943 constexpr VkFormat format = VK_FORMAT_R32G32B32A32_SFLOAT;
944 auto& info = this->getFormatInfo(format);
945 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400946 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400947 info.fColorTypeInfoCount = 1;
948 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
949 int ctIdx = 0;
950 // Format: VK_FORMAT_R32G32B32A32_SFLOAT, Surface: kRGBA_F32
951 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400952 constexpr GrColorType ct = GrColorType::kRGBA_F32;
Greg Daniel1ff50212019-08-02 15:54:08 -0400953 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400954 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400955 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
956 }
957 }
958 }
959 // Format: VK_FORMAT_R8G8B8A8_SRGB
960 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400961 constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB;
962 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700963 if (fSRGBSupport) {
Greg Daniel0fac8692019-08-16 13:13:17 -0400964 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700965 }
Greg Daniel7bfc9132019-08-14 14:23:53 -0400966 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400967 info.fColorTypeInfoCount = 1;
968 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
969 int ctIdx = 0;
970 // Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB
971 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400972 constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB;
Greg Daniel1ff50212019-08-02 15:54:08 -0400973 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400974 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400975 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
976 }
977 }
978 }
979 // Format: VK_FORMAT_R16_UNORM
980 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400981 constexpr VkFormat format = VK_FORMAT_R16_UNORM;
982 auto& info = this->getFormatInfo(format);
983 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400984 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400985 info.fColorTypeInfoCount = 1;
986 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
987 int ctIdx = 0;
Robert Phillips429f0d32019-09-11 17:03:28 -0400988 // Format: VK_FORMAT_R16_UNORM, Surface: kAlpha_16
Greg Daniel1ff50212019-08-02 15:54:08 -0400989 {
Robert Phillips429f0d32019-09-11 17:03:28 -0400990 constexpr GrColorType ct = GrColorType::kAlpha_16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400991 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400992 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400993 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
Robert Phillips429f0d32019-09-11 17:03:28 -0400994 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
995 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
Greg Daniel1ff50212019-08-02 15:54:08 -0400996 }
997 }
998 }
999 // Format: VK_FORMAT_R16G16_UNORM
1000 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001001 constexpr VkFormat format = VK_FORMAT_R16G16_UNORM;
1002 auto& info = this->getFormatInfo(format);
1003 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001004 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001005 info.fColorTypeInfoCount = 1;
1006 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1007 int ctIdx = 0;
1008 // Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616
1009 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001010 constexpr GrColorType ct = GrColorType::kRG_1616;
Greg Daniel1ff50212019-08-02 15:54:08 -04001011 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001012 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001013 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1014 }
1015 }
1016 }
1017 // Format: VK_FORMAT_R16G16B16A16_UNORM
1018 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001019 constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM;
1020 auto& info = this->getFormatInfo(format);
1021 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001022 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001023 info.fColorTypeInfoCount = 1;
1024 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1025 int ctIdx = 0;
1026 // Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616
1027 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001028 constexpr GrColorType ct = GrColorType::kRGBA_16161616;
Greg Daniel1ff50212019-08-02 15:54:08 -04001029 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001030 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001031 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1032 }
1033 }
1034 }
1035 // Format: VK_FORMAT_R16G16_SFLOAT
1036 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001037 constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT;
1038 auto& info = this->getFormatInfo(format);
1039 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001040 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001041 info.fColorTypeInfoCount = 1;
1042 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1043 int ctIdx = 0;
1044 // Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16
1045 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001046 constexpr GrColorType ct = GrColorType::kRG_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -04001047 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001048 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001049 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1050 }
1051 }
1052 }
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001053 // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
1054 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001055 constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
1056 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001057 if (fSupportsYcbcrConversion) {
Greg Daniel0fac8692019-08-16 13:13:17 -04001058 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001059 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001060 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001061 info.fColorTypeInfoCount = 1;
1062 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1063 int ctIdx = 0;
1064 // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x
1065 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001066 constexpr GrColorType ct = GrColorType::kRGB_888x;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001067 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001068 ctInfo.fColorType = ct;
1069 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001070 }
1071 }
1072 }
1073 // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM
1074 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001075 constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
1076 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001077 if (fSupportsYcbcrConversion) {
Greg Daniel0fac8692019-08-16 13:13:17 -04001078 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001079 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001080 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001081 info.fColorTypeInfoCount = 1;
1082 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1083 int ctIdx = 0;
1084 // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x
1085 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001086 constexpr GrColorType ct = GrColorType::kRGB_888x;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001087 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001088 ctInfo.fColorType = ct;
1089 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001090 }
1091 }
1092 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001093 // Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
1094 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001095 constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
1096 auto& info = this->getFormatInfo(format);
1097 info.init(interface, physDev, properties, format);
Greg Daniel1ff50212019-08-02 15:54:08 -04001098 // No supported GrColorTypes.
1099 }
Greg Daniel0fac8692019-08-16 13:13:17 -04001100
1101 ////////////////////////////////////////////////////////////////////////////
1102 // Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats
1103 // are passed into the setColorType function indicates the priority in selecting which format
1104 // we use for a given GrcolorType.
1105
1106 this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM });
1107 this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16 });
1108 this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1109 VK_FORMAT_B4G4R4A4_UNORM_PACK16 });
1110 this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM });
1111 this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB });
1112 this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM,
1113 VK_FORMAT_R8G8B8A8_UNORM });
1114 this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM });
1115 this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM });
1116 this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 });
1117 this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM });
1118 this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT });
1119 this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT });
1120 this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT });
1121 this->setColorType(GrColorType::kRGBA_F32, { VK_FORMAT_R32G32B32A32_SFLOAT });
Robert Phillips429f0d32019-09-11 17:03:28 -04001122 this->setColorType(GrColorType::kAlpha_16, { VK_FORMAT_R16_UNORM });
Greg Daniel0fac8692019-08-16 13:13:17 -04001123 this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM });
1124 this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM });
1125 this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT });
egdaniel8f1dcaa2016-04-01 10:10:45 -07001126}
1127
Greg Daniel1ff50212019-08-02 15:54:08 -04001128void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
egdaniel8f1dcaa2016-04-01 10:10:45 -07001129 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
1130 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
Greg Daniel7bfc9132019-08-14 14:23:53 -04001131 *flags = *flags | kTexturable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -07001132
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001133 // Ganesh assumes that all renderable surfaces are also texturable
Greg Danielcaa795f2019-05-14 11:54:25 -04001134 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001135 *flags = *flags | kRenderable_Flag;
1136 }
egdaniel8f1dcaa2016-04-01 10:10:45 -07001137 }
1138
1139 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
1140 *flags = *flags | kBlitSrc_Flag;
1141 }
1142
1143 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
1144 *flags = *flags | kBlitDst_Flag;
1145 }
1146}
1147
Greg Danielcaa795f2019-05-14 11:54:25 -04001148void GrVkCaps::FormatInfo::initSampleCounts(const GrVkInterface* interface,
Greg Daniel81e7bf82017-07-19 14:47:42 -04001149 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001150 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -04001151 VkFormat format) {
1152 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1153 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1154 VK_IMAGE_USAGE_SAMPLED_BIT |
1155 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001156 VkImageFormatProperties properties;
1157 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
1158 format,
1159 VK_IMAGE_TYPE_2D,
1160 VK_IMAGE_TILING_OPTIMAL,
1161 usage,
Brian Osman2b23c4b2018-06-01 12:25:08 -04001162 0, // createFlags
Greg Daniel81e7bf82017-07-19 14:47:42 -04001163 &properties));
1164 VkSampleCountFlags flags = properties.sampleCounts;
1165 if (flags & VK_SAMPLE_COUNT_1_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001166 fColorSampleCounts.push_back(1);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001167 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001168 if (kImagination_VkVendor == physProps.vendorID) {
1169 // MSAA does not work on imagination
1170 return;
1171 }
Brian Osman7fbb3632019-07-19 11:38:57 -04001172 if (kIntel_VkVendor == physProps.vendorID) {
Brian Osmanb5391bf2019-08-15 14:52:52 -04001173 // MSAA doesn't work well on Intel GPUs chromium:527565, chromium:983926
1174 return;
Brian Osman7fbb3632019-07-19 11:38:57 -04001175 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001176 if (flags & VK_SAMPLE_COUNT_2_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001177 fColorSampleCounts.push_back(2);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001178 }
1179 if (flags & VK_SAMPLE_COUNT_4_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001180 fColorSampleCounts.push_back(4);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001181 }
1182 if (flags & VK_SAMPLE_COUNT_8_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001183 fColorSampleCounts.push_back(8);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001184 }
1185 if (flags & VK_SAMPLE_COUNT_16_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001186 fColorSampleCounts.push_back(16);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001187 }
1188 if (flags & VK_SAMPLE_COUNT_32_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001189 fColorSampleCounts.push_back(32);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001190 }
1191 if (flags & VK_SAMPLE_COUNT_64_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001192 fColorSampleCounts.push_back(64);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001193 }
1194}
1195
Greg Danielcaa795f2019-05-14 11:54:25 -04001196void GrVkCaps::FormatInfo::init(const GrVkInterface* interface,
egdaniel8f1dcaa2016-04-01 10:10:45 -07001197 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001198 const VkPhysicalDeviceProperties& properties,
Greg Danielcaa795f2019-05-14 11:54:25 -04001199 VkFormat format) {
egdaniel8f1dcaa2016-04-01 10:10:45 -07001200 VkFormatProperties props;
1201 memset(&props, 0, sizeof(VkFormatProperties));
1202 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
Greg Daniel1ff50212019-08-02 15:54:08 -04001203 InitFormatFlags(props.linearTilingFeatures, &fLinearFlags);
1204 InitFormatFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001205 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001206 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001207 }
Greg Daniel164a9f02016-02-22 09:56:40 -05001208}
Greg Daniel81e7bf82017-07-19 14:47:42 -04001209
Robert Phillipsf209e882019-06-25 15:59:50 -04001210bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001211 VkFormat vkFormat;
1212 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsf209e882019-06-25 15:59:50 -04001213 return false;
1214 }
1215
Brian Salomond4764a12019-08-08 12:08:24 -04001216 return format_is_srgb(vkFormat);
Robert Phillipsf209e882019-06-25 15:59:50 -04001217}
1218
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001219bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001220 VkFormat vkFormat;
1221 if (!format.asVkFormat(&vkFormat)) {
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001222 return false;
1223 }
1224
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001225 SkASSERT(GrVkFormatIsSupported(vkFormat));
1226
1227 return vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
1228}
1229
Greg Daniel7bfc9132019-08-14 14:23:53 -04001230bool GrVkCaps::isFormatTexturableAndUploadable(GrColorType ct,
1231 const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001232 VkFormat vkFormat;
1233 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001234 return false;
1235 }
1236
Greg Daniel1ff50212019-08-02 15:54:08 -04001237 uint32_t ctFlags = this->getFormatInfo(vkFormat).colorTypeFlags(ct);
1238 return this->isVkFormatTexturable(vkFormat) &&
1239 SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag);
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001240}
1241
Greg Daniel7bfc9132019-08-14 14:23:53 -04001242bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const {
1243 VkFormat vkFormat;
1244 if (!format.asVkFormat(&vkFormat)) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001245 return false;
1246 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001247 return this->isVkFormatTexturable(vkFormat);
1248}
1249
1250bool GrVkCaps::isVkFormatTexturable(VkFormat format) const {
1251 const FormatInfo& info = this->getFormatInfo(format);
1252 return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags);
Robert Phillips39ef2ef2019-05-15 08:45:53 -04001253}
1254
Greg Daniel900583a2019-08-06 12:05:31 -04001255bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
1256 int sampleCount) const {
1257 if (!this->isFormatRenderable(format, sampleCount)) {
Greg Danieleadfac92019-08-02 09:03:53 -04001258 return false;
1259 }
Brian Salomond4764a12019-08-08 12:08:24 -04001260 VkFormat vkFormat;
1261 if (!format.asVkFormat(&vkFormat)) {
1262 return false;
1263 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001264 const auto& info = this->getFormatInfo(vkFormat);
1265 if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
Greg Danieleadfac92019-08-02 09:03:53 -04001266 return false;
1267 }
Greg Daniel900583a2019-08-06 12:05:31 -04001268 return true;
Greg Danieleadfac92019-08-02 09:03:53 -04001269}
1270
Greg Daniel900583a2019-08-06 12:05:31 -04001271bool GrVkCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001272 VkFormat vkFormat;
1273 if (!format.asVkFormat(&vkFormat)) {
Greg Daniel900583a2019-08-06 12:05:31 -04001274 return false;
1275 }
Greg Daniel900583a2019-08-06 12:05:31 -04001276 return this->isFormatRenderable(vkFormat, sampleCount);
1277}
1278
1279bool GrVkCaps::isFormatRenderable(VkFormat format, int sampleCount) const {
1280 return sampleCount <= this->maxRenderTargetSampleCount(format);
Greg Danielcaa795f2019-05-14 11:54:25 -04001281}
1282
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001283int GrVkCaps::getRenderTargetSampleCount(int requestedCount,
Brian Salomon4eb38b72019-08-05 12:58:39 -04001284 const GrBackendFormat& format) const {
1285 VkFormat vkFormat;
Brian Salomond4764a12019-08-08 12:08:24 -04001286 if (!format.asVkFormat(&vkFormat)) {
Brian Salomon4eb38b72019-08-05 12:58:39 -04001287 return 0;
1288 }
1289
Brian Salomond4764a12019-08-08 12:08:24 -04001290 return this->getRenderTargetSampleCount(requestedCount, vkFormat);
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001291}
1292
Greg Danielcaa795f2019-05-14 11:54:25 -04001293int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001294 requestedCount = SkTMax(1, requestedCount);
Greg Danielcaa795f2019-05-14 11:54:25 -04001295
1296 const FormatInfo& info = this->getFormatInfo(format);
1297
1298 int count = info.fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05001299
1300 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001301 return 0;
1302 }
1303
Brian Salomonbdecacf2018-02-02 20:32:49 -05001304 if (1 == requestedCount) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001305 SkASSERT(info.fColorSampleCounts.count() && info.fColorSampleCounts[0] == 1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001306 return 1;
1307 }
1308
Greg Daniel81e7bf82017-07-19 14:47:42 -04001309 for (int i = 0; i < count; ++i) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001310 if (info.fColorSampleCounts[i] >= requestedCount) {
1311 return info.fColorSampleCounts[i];
Greg Daniel81e7bf82017-07-19 14:47:42 -04001312 }
1313 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001314 return 0;
1315}
1316
Greg Danieleadfac92019-08-02 09:03:53 -04001317int GrVkCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001318 VkFormat vkFormat;
1319 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001320 return 0;
1321 }
Brian Salomond4764a12019-08-08 12:08:24 -04001322 return this->maxRenderTargetSampleCount(vkFormat);
Greg Danielcaa795f2019-05-14 11:54:25 -04001323}
1324
1325int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const {
1326 const FormatInfo& info = this->getFormatInfo(format);
1327
1328 const auto& table = info.fColorSampleCounts;
Brian Salomonbdecacf2018-02-02 20:32:49 -05001329 if (!table.count()) {
1330 return 0;
1331 }
1332 return table[table.count() - 1];
Brian Salomond653cac2018-02-01 13:58:00 -05001333}
1334
Brian Salomon42be09d2019-07-26 12:12:26 -04001335static inline size_t align_to_4(size_t v) {
1336 switch (v & 0b11) {
1337 // v is already a multiple of 4.
1338 case 0: return v;
1339 // v is a multiple of 2 but not 4.
1340 case 2: return 2 * v;
1341 // v is not a multiple of 2.
1342 default: return 4 * v;
1343 }
1344}
1345
Brian Salomon01915c02019-08-02 09:57:21 -04001346GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
1347 const GrBackendFormat& surfaceFormat,
Brian Salomon42be09d2019-07-26 12:12:26 -04001348 GrColorType srcColorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001349 VkFormat vkFormat;
1350 if (!surfaceFormat.asVkFormat(&vkFormat)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001351 return {GrColorType::kUnknown, 0};
1352 }
1353
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001354
1355 if (GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1356 return {GrColorType::kUnknown, 0};
1357 }
1358
Greg Daniel1ff50212019-08-02 15:54:08 -04001359 // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
Brian Salomond4764a12019-08-08 12:08:24 -04001360 size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001361
Brian Salomond4764a12019-08-08 12:08:24 -04001362 const auto& info = this->getFormatInfo(vkFormat);
Greg Daniel1ff50212019-08-02 15:54:08 -04001363 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1364 const auto& ctInfo = info.fColorTypeInfos[i];
1365 if (ctInfo.fColorType == surfaceColorType) {
1366 return {surfaceColorType, offsetAlignment};
1367 }
1368 }
1369 return {GrColorType::kUnknown, 0};
Brian Salomon42be09d2019-07-26 12:12:26 -04001370}
1371
Brian Salomondc0710f2019-07-01 14:59:32 -04001372GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels(
1373 const GrSurface* surface) const {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -04001374 if (surface->isProtected()) {
Brian Salomondc0710f2019-07-01 14:59:32 -04001375 return SurfaceReadPixelsSupport::kUnsupported;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -04001376 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001377 if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
1378 // We can't directly read from a VkImage that has a ycbcr sampler.
1379 if (tex->ycbcrConversionInfo().isValid()) {
Brian Salomondc0710f2019-07-01 14:59:32 -04001380 return SurfaceReadPixelsSupport::kCopyToTexture2D;
Greg Daniela51e93c2019-03-25 12:30:45 -04001381 }
Greg Daniel00fb7242019-07-18 14:28:01 -04001382 // We can't directly read from a compressed format
1383 SkImage::CompressionType compressionType;
1384 if (GrVkFormatToCompressionType(tex->imageFormat(), &compressionType)) {
1385 return SurfaceReadPixelsSupport::kCopyToTexture2D;
1386 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001387 }
Brian Salomondc0710f2019-07-01 14:59:32 -04001388 return SurfaceReadPixelsSupport::kSupported;
Greg Daniela51e93c2019-03-25 12:30:45 -04001389}
1390
Brian Salomonc67c31c2018-12-06 10:00:03 -05001391bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
Brian Salomon3d86a192018-02-27 16:46:11 -05001392 if (auto rt = surface->asRenderTarget()) {
Chris Dalton6ce447a2019-06-23 18:07:38 -06001393 return rt->numSamples() <= 1 && SkToBool(surface->asTexture());
Brian Salomon3d86a192018-02-27 16:46:11 -05001394 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001395 // We can't write to a texture that has a ycbcr sampler.
1396 if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
1397 // We can't directly read from a VkImage that has a ycbcr sampler.
1398 if (tex->ycbcrConversionInfo().isValid()) {
1399 return false;
1400 }
1401 }
Brian Salomon3d86a192018-02-27 16:46:11 -05001402 return true;
1403}
1404
Greg Daniel0fac8692019-08-16 13:13:17 -04001405bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
1406 const GrBackendFormat& format) const {
1407 VkFormat vkFormat;
1408 if (!format.asVkFormat(&vkFormat)) {
1409 return false;
1410 }
1411 const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
1412 SkASSERT(ycbcrInfo);
1413
1414 if (ycbcrInfo->isValid() && !GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1415 // Format may be undefined for external images, which are required to have YCbCr conversion.
1416 if (VK_FORMAT_UNDEFINED == vkFormat) {
1417 return true;
1418 }
1419 return false;
1420 }
1421
1422 const auto& info = this->getFormatInfo(vkFormat);
1423 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1424 if (info.fColorTypeInfos[i].fColorType == ct) {
1425 return true;
1426 }
1427 }
1428 return false;
1429}
1430
Robert Phillips1e2cb442019-07-02 15:51:28 -04001431static GrPixelConfig validate_image_info(VkFormat format, GrColorType ct, bool hasYcbcrConversion) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001432 if (hasYcbcrConversion) {
1433 if (GrVkFormatNeedsYcbcrSampler(format)) {
1434 return kRGB_888X_GrPixelConfig;
1435 }
1436
1437 // Format may be undefined for external images, which are required to have YCbCr conversion.
1438 if (VK_FORMAT_UNDEFINED == format) {
Greg Daniel14c55c22018-12-04 11:25:03 -05001439 // We don't actually care what the color type or config are since we won't use those
Greg Daniela51e93c2019-03-25 12:30:45 -04001440 // values for external textures. However, for read pixels we will draw to a non ycbcr
1441 // texture of this config so we set RGBA here for that.
Brian Salomonf391d0f2018-12-14 09:18:50 -05001442 return kRGBA_8888_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001443 }
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001444
1445 return kUnknown_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001446 }
1447
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001448 if (VK_FORMAT_UNDEFINED == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001449 return kUnknown_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001450 }
1451
Greg Danielf5d87582017-12-18 14:48:15 -05001452 switch (ct) {
Robert Phillips1e2cb442019-07-02 15:51:28 -04001453 case GrColorType::kUnknown:
Brian Salomonf391d0f2018-12-14 09:18:50 -05001454 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001455 case GrColorType::kAlpha_8:
Greg Danielf5d87582017-12-18 14:48:15 -05001456 if (VK_FORMAT_R8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001457 return kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001458 }
1459 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001460 case GrColorType::kBGR_565:
Greg Danielf5d87582017-12-18 14:48:15 -05001461 if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001462 return kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001463 }
1464 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001465 case GrColorType::kABGR_4444:
Greg Danieleb4a8272019-05-16 16:52:55 -04001466 if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format ||
1467 VK_FORMAT_R4G4B4A4_UNORM_PACK16 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001468 return kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001469 }
1470 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001471 case GrColorType::kRGBA_8888:
Greg Danielf5d87582017-12-18 14:48:15 -05001472 if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001473 return kRGBA_8888_GrPixelConfig;
Greg Daniele877dce2019-07-11 10:52:43 -04001474 }
1475 break;
1476 case GrColorType::kRGBA_8888_SRGB:
1477 if (VK_FORMAT_R8G8B8A8_SRGB == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001478 return kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001479 }
1480 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001481 case GrColorType::kRGB_888x:
Greg Daniel475eb702018-09-28 14:16:50 -04001482 if (VK_FORMAT_R8G8B8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001483 return kRGB_888_GrPixelConfig;
Robert Phillipsffe27292019-08-01 10:08:07 -04001484 } else if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Greg Danielf259b8b2019-02-14 09:03:43 -05001485 return kRGB_888X_GrPixelConfig;
Robert Phillipsffe27292019-08-01 10:08:07 -04001486 } else if (VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK == format) {
1487 return kRGB_ETC1_GrPixelConfig;
Greg Danielf259b8b2019-02-14 09:03:43 -05001488 }
Greg Daniel475eb702018-09-28 14:16:50 -04001489 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001490 case GrColorType::kRG_88:
1491 if (VK_FORMAT_R8G8_UNORM == format) {
1492 return kRG_88_GrPixelConfig;
1493 }
1494 break;
1495 case GrColorType::kBGRA_8888:
Greg Danielf5d87582017-12-18 14:48:15 -05001496 if (VK_FORMAT_B8G8R8A8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001497 return kBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001498 }
1499 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001500 case GrColorType::kRGBA_1010102:
Brian Osman10fc6fd2018-03-02 11:01:10 -05001501 if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001502 return kRGBA_1010102_GrPixelConfig;
Brian Osman10fc6fd2018-03-02 11:01:10 -05001503 }
1504 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001505 case GrColorType::kGray_8:
Greg Danielf5d87582017-12-18 14:48:15 -05001506 if (VK_FORMAT_R8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001507 return kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001508 }
1509 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001510 case GrColorType::kAlpha_F16:
1511 if (VK_FORMAT_R16_SFLOAT == format) {
Robert Phillips0902c982019-07-16 07:47:56 -04001512 return kAlpha_half_as_Red_GrPixelConfig;
Mike Kleinb70990e2019-02-28 10:03:27 -06001513 }
1514 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001515 case GrColorType::kRGBA_F16:
Greg Danielf5d87582017-12-18 14:48:15 -05001516 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001517 return kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001518 }
1519 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001520 case GrColorType::kRGBA_F16_Clamped:
1521 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
1522 return kRGBA_half_Clamped_GrPixelConfig;
1523 }
1524 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001525 case GrColorType::kRGBA_F32:
Mike Klein37854712018-06-26 11:43:06 -04001526 if (VK_FORMAT_R32G32B32A32_SFLOAT == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001527 return kRGBA_float_GrPixelConfig;
Mike Klein37854712018-06-26 11:43:06 -04001528 }
1529 break;
Robert Phillips429f0d32019-09-11 17:03:28 -04001530 case GrColorType::kAlpha_16:
Robert Phillips1e2cb442019-07-02 15:51:28 -04001531 if (VK_FORMAT_R16_UNORM == format) {
Robert Phillips429f0d32019-09-11 17:03:28 -04001532 return kAlpha_16_GrPixelConfig;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001533 }
1534 break;
1535 case GrColorType::kRG_1616:
1536 if (VK_FORMAT_R16G16_UNORM == format) {
1537 return kRG_1616_GrPixelConfig;
1538 }
1539 break;
1540 case GrColorType::kRGBA_16161616:
1541 if (VK_FORMAT_R16G16B16A16_UNORM == format) {
1542 return kRGBA_16161616_GrPixelConfig;
1543 }
1544 break;
1545 case GrColorType::kRG_F16:
1546 if (VK_FORMAT_R16G16_SFLOAT == format) {
1547 return kRG_half_GrPixelConfig;
1548 }
1549 break;
Brian Salomon8f8354a2019-07-31 20:12:02 -04001550 // These have no equivalent:
1551 case GrColorType::kAlpha_8xxx:
1552 case GrColorType::kAlpha_F32xxx:
1553 case GrColorType::kGray_8xxx:
1554 break;
Greg Danielf5d87582017-12-18 14:48:15 -05001555 }
1556
Brian Salomonf391d0f2018-12-14 09:18:50 -05001557 return kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001558}
1559
Greg Daniel627d0532019-07-08 16:48:14 -04001560GrPixelConfig GrVkCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
1561 GrColorType ct) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001562 VkFormat vkFormat;
1563 if (!format.asVkFormat(&vkFormat)) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001564 return kUnknown_GrPixelConfig;
Robert Phillipsfc711a22018-02-13 17:03:00 -05001565 }
Brian Salomond4764a12019-08-08 12:08:24 -04001566 const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
1567 SkASSERT(ycbcrInfo);
1568 return validate_image_info(vkFormat, ct, ycbcrInfo->isValid());
Greg Danielfaa095e2017-12-19 13:15:02 -05001569}
Greg Danielf5d87582017-12-18 14:48:15 -05001570
Robert Phillips00c9f0d2019-08-02 17:17:35 -04001571GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
1572 bool isAlphaChannel) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001573 VkFormat vkFormat;
1574 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001575 return GrColorType::kUnknown;
1576 }
1577
Brian Salomond4764a12019-08-08 12:08:24 -04001578 switch (vkFormat) {
Robert Phillips00c9f0d2019-08-02 17:17:35 -04001579 case VK_FORMAT_R8_UNORM: return isAlphaChannel ? GrColorType::kAlpha_8
1580 : GrColorType::kGray_8;
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001581 case VK_FORMAT_R8G8B8A8_UNORM: return GrColorType::kRGBA_8888;
1582 case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x;
1583 case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88;
1584 case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888;
1585 case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102;
Robert Phillips429f0d32019-09-11 17:03:28 -04001586 case VK_FORMAT_R16_UNORM: return GrColorType::kAlpha_16;
Robert Phillips17a3a0b2019-09-18 13:56:54 -04001587 case VK_FORMAT_R16_SFLOAT: return GrColorType::kAlpha_F16;
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001588 case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616;
1589 // Experimental (for Y416 and mutant P016/P010)
1590 case VK_FORMAT_R16G16B16A16_UNORM: return GrColorType::kRGBA_16161616;
1591 case VK_FORMAT_R16G16_SFLOAT: return GrColorType::kRG_F16;
1592 default: return GrColorType::kUnknown;
1593 }
1594
1595 SkUNREACHABLE;
1596}
1597
Robert Phillips0a15cc62019-07-30 12:49:10 -04001598GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct,
1599 GrRenderable renderable) const {
Greg Daniel0fac8692019-08-16 13:13:17 -04001600 VkFormat format = this->getFormatFromColorType(ct);
1601 if (format == VK_FORMAT_UNDEFINED) {
Greg Daniel4065d452018-11-16 15:43:41 -05001602 return GrBackendFormat();
1603 }
1604 return GrBackendFormat::MakeVk(format);
1605}
Timothy Liang036fdfe2018-06-28 15:50:36 -04001606
Brian Salomonbb8dde82019-06-27 10:52:13 -04001607GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType(
1608 SkImage::CompressionType compressionType) const {
1609 switch (compressionType) {
1610 case SkImage::kETC1_CompressionType:
1611 return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
1612 }
1613 SK_ABORT("Invalid compression type");
Brian Salomonbb8dde82019-06-27 10:52:13 -04001614}
1615
Greg Daniel1ff50212019-08-02 15:54:08 -04001616GrSwizzle GrVkCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001617 VkFormat vkFormat;
1618 SkAssertResult(format.asVkFormat(&vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001619 const auto& info = this->getFormatInfo(vkFormat);
1620 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1621 const auto& ctInfo = info.fColorTypeInfos[i];
1622 if (ctInfo.fColorType == colorType) {
1623 return ctInfo.fTextureSwizzle;
1624 }
Greg Danieleb4a8272019-05-16 16:52:55 -04001625 }
1626 return GrSwizzle::RGBA();
1627}
1628
Greg Danieleb4a8272019-05-16 16:52:55 -04001629GrSwizzle GrVkCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001630 VkFormat vkFormat;
1631 SkAssertResult(format.asVkFormat(&vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001632 const auto& info = this->getFormatInfo(vkFormat);
1633 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1634 const auto& ctInfo = info.fColorTypeInfos[i];
1635 if (ctInfo.fColorType == colorType) {
1636 return ctInfo.fOutputSwizzle;
1637 }
1638 }
1639 return GrSwizzle::RGBA();
Greg Danieleb4a8272019-05-16 16:52:55 -04001640}
1641
Greg Danielba88ab62019-07-26 09:14:01 -04001642GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType(
Greg Daniel00fb7242019-07-18 14:28:01 -04001643 GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
1644 GrColorType dstColorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001645 VkFormat vkFormat;
1646 if (!srcBackendFormat.asVkFormat(&vkFormat)) {
Brian Salomon8f8354a2019-07-31 20:12:02 -04001647 return {GrColorType::kUnknown, 0};
Greg Danielba88ab62019-07-26 09:14:01 -04001648 }
1649
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001650 if (GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1651 return {GrColorType::kUnknown, 0};
1652 }
1653
Greg Danielba88ab62019-07-26 09:14:01 -04001654 // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
Brian Salomond4764a12019-08-08 12:08:24 -04001655 size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
Greg Daniel00fb7242019-07-18 14:28:01 -04001656
Brian Salomond4764a12019-08-08 12:08:24 -04001657 const auto& info = this->getFormatInfo(vkFormat);
Greg Daniel1ff50212019-08-02 15:54:08 -04001658 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1659 const auto& ctInfo = info.fColorTypeInfos[i];
1660 if (ctInfo.fColorType == srcColorType) {
1661 return {srcColorType, offsetAlignment};
1662 }
Greg Daniel00fb7242019-07-18 14:28:01 -04001663 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001664 return {GrColorType::kUnknown, 0};
Greg Daniel00fb7242019-07-18 14:28:01 -04001665}
Robert Phillipsffe27292019-08-01 10:08:07 -04001666
Ethan Nicholas0be34802019-08-15 12:36:58 -04001667int GrVkCaps::getFragmentUniformBinding() const {
1668 return GrVkUniformHandler::kUniformBinding;
1669}
1670
1671int GrVkCaps::getFragmentUniformSet() const {
1672 return GrVkUniformHandler::kUniformBufferDescSet;
1673}
1674
Robert Phillipsffe27292019-08-01 10:08:07 -04001675#if GR_TEST_UTILS
1676std::vector<GrCaps::TestFormatColorTypeCombination> GrVkCaps::getTestingCombinations() const {
1677 std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
1678 { GrColorType::kAlpha_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) },
1679 { GrColorType::kBGR_565, GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16) },
1680 { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_R4G4B4A4_UNORM_PACK16)},
1681 { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16)},
1682 { GrColorType::kRGBA_8888, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) },
1683 { GrColorType::kRGBA_8888_SRGB, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB) },
1684 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) },
1685 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM) },
1686 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)},
1687 { GrColorType::kRG_88, GrBackendFormat::MakeVk(VK_FORMAT_R8G8_UNORM) },
1688 { GrColorType::kBGRA_8888, GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) },
1689 { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)},
1690 { GrColorType::kGray_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) },
1691 { GrColorType::kAlpha_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16_SFLOAT) },
1692 { GrColorType::kRGBA_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) },
1693 { GrColorType::kRGBA_F16_Clamped, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) },
1694 { GrColorType::kRGBA_F32, GrBackendFormat::MakeVk(VK_FORMAT_R32G32B32A32_SFLOAT) },
Robert Phillips429f0d32019-09-11 17:03:28 -04001695 { GrColorType::kAlpha_16, GrBackendFormat::MakeVk(VK_FORMAT_R16_UNORM) },
Robert Phillipsffe27292019-08-01 10:08:07 -04001696 { GrColorType::kRG_1616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_UNORM) },
1697 { GrColorType::kRGBA_16161616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_UNORM) },
1698 { GrColorType::kRG_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_SFLOAT) },
1699 };
1700
Robert Phillipsffe27292019-08-01 10:08:07 -04001701 return combos;
1702}
1703#endif