blob: 7af5312509a31916bc1f378bb5a682e9979b086d [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 VK_FORMAT_R16G16B16A16_UNORM,
653 VK_FORMAT_R16G16_SFLOAT,
Greg Danielcaa795f2019-05-14 11:54:25 -0400654};
655
Greg Daniel0fac8692019-08-16 13:13:17 -0400656void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) {
657#ifdef SK_DEBUG
658 for (size_t i = 0; i < kNumVkFormats; ++i) {
659 const auto& formatInfo = fFormatTable[i];
660 for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
661 const auto& ctInfo = formatInfo.fColorTypeInfos[j];
662 if (ctInfo.fColorType == colorType &&
663 !SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) {
664 bool found = false;
665 for (auto it = formats.begin(); it != formats.end(); ++it) {
666 if (kVkFormats[i] == *it) {
667 found = true;
668 }
669 }
670 SkASSERT(found);
671 }
672 }
673 }
674#endif
675 int idx = static_cast<int>(colorType);
676 for (auto it = formats.begin(); it != formats.end(); ++it) {
677 const auto& info = this->getFormatInfo(*it);
678 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
679 if (info.fColorTypeInfos[i].fColorType == colorType) {
680 fColorTypeToFormatTable[idx] = *it;
681 return;
682 }
683 }
684 }
685}
686
Greg Danielcaa795f2019-05-14 11:54:25 -0400687const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const {
Greg Daniel1ff50212019-08-02 15:54:08 -0400688 GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this);
689 return nonConstThis->getFormatInfo(format);
690}
691
692GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) {
Greg Danielcaa795f2019-05-14 11:54:25 -0400693 static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats,
694 "Size of VkFormats array must match static value in header");
695 for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) {
696 if (kVkFormats[i] == format) {
697 return fFormatTable[i];
698 }
699 }
Greg Daniel1ff50212019-08-02 15:54:08 -0400700 static FormatInfo kInvalidFormat;
Greg Daniel52ee5f62019-06-20 13:38:18 -0400701 return kInvalidFormat;
Greg Danielcaa795f2019-05-14 11:54:25 -0400702}
703
704void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000705 const VkPhysicalDeviceProperties& properties) {
Greg Danielcaa795f2019-05-14 11:54:25 -0400706 static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats,
707 "Size of VkFormats array must match static value in header");
Greg Daniel1ff50212019-08-02 15:54:08 -0400708
Greg Daniel0fac8692019-08-16 13:13:17 -0400709 std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED);
Greg Daniel1ff50212019-08-02 15:54:08 -0400710
Greg Daniel0fac8692019-08-16 13:13:17 -0400711 // Go through all the formats and init their support surface and data GrColorTypes.
Greg Daniel1ff50212019-08-02 15:54:08 -0400712 // Format: VK_FORMAT_R8G8B8A8_UNORM
713 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400714 constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
715 auto& info = this->getFormatInfo(format);
716 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400717 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400718 info.fColorTypeInfoCount = 2;
719 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
720 int ctIdx = 0;
721 // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888
722 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400723 constexpr GrColorType ct = GrColorType::kRGBA_8888;
Greg Daniel1ff50212019-08-02 15:54:08 -0400724 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400725 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400726 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
727 }
728 // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x
729 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400730 constexpr GrColorType ct = GrColorType::kRGB_888x;
Greg Daniel1ff50212019-08-02 15:54:08 -0400731 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400732 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400733 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
734 ctInfo.fTextureSwizzle = GrSwizzle::RGB1();
735 }
736 }
737 }
738
739 // Format: VK_FORMAT_R8_UNORM
740 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400741 constexpr VkFormat format = VK_FORMAT_R8_UNORM;
742 auto& info = this->getFormatInfo(format);
743 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400744 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400745 info.fColorTypeInfoCount = 2;
746 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
747 int ctIdx = 0;
748 // Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8
749 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400750 constexpr GrColorType ct = GrColorType::kAlpha_8;
Greg Daniel1ff50212019-08-02 15:54:08 -0400751 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400752 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400753 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
754 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
755 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
756 }
757 // Format: VK_FORMAT_R8_UNORM, Surface: kGray_8
758 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400759 constexpr GrColorType ct = GrColorType::kGray_8;
Greg Daniel1ff50212019-08-02 15:54:08 -0400760 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400761 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400762 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
763 ctInfo.fTextureSwizzle = GrSwizzle("rrr1");
764 }
765 }
766 }
767 // Format: VK_FORMAT_B8G8R8A8_UNORM
768 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400769 constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
770 auto& info = this->getFormatInfo(format);
771 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400772 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400773 info.fColorTypeInfoCount = 1;
774 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
775 int ctIdx = 0;
776 // Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888
777 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400778 constexpr GrColorType ct = GrColorType::kBGRA_8888;
Greg Daniel1ff50212019-08-02 15:54:08 -0400779 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400780 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400781 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
782 }
783 }
784 }
785 // Format: VK_FORMAT_R5G6B5_UNORM_PACK16
786 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400787 constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16;
788 auto& info = this->getFormatInfo(format);
789 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400790 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400791 info.fColorTypeInfoCount = 1;
792 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
793 int ctIdx = 0;
794 // Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565
795 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400796 constexpr GrColorType ct = GrColorType::kBGR_565;
Greg Daniel1ff50212019-08-02 15:54:08 -0400797 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400798 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400799 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
800 }
801 }
802 }
803 // Format: VK_FORMAT_R16G16B16A16_SFLOAT
804 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400805 constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT;
806 auto& info = this->getFormatInfo(format);
807 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400808 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400809 info.fColorTypeInfoCount = 2;
810 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
811 int ctIdx = 0;
812 // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16
813 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400814 constexpr GrColorType ct = GrColorType::kRGBA_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400815 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400816 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400817 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
818 }
819 // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped
820 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400821 constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped;
Greg Daniel1ff50212019-08-02 15:54:08 -0400822 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400823 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400824 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
825 }
826 }
827 }
828 // Format: VK_FORMAT_R16_SFLOAT
829 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400830 constexpr VkFormat format = VK_FORMAT_R16_SFLOAT;
831 auto& info = this->getFormatInfo(format);
832 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400833 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400834 info.fColorTypeInfoCount = 1;
835 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
836 int ctIdx = 0;
837 // Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16
838 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400839 constexpr GrColorType ct = GrColorType::kAlpha_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400840 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400841 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400842 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
843 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
844 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
845 }
846 }
847 }
848 // Format: VK_FORMAT_R8G8B8_UNORM
849 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400850 constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM;
851 auto& info = this->getFormatInfo(format);
852 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400853 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400854 info.fColorTypeInfoCount = 1;
855 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
856 int ctIdx = 0;
857 // Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x
858 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400859 constexpr GrColorType ct = GrColorType::kRGB_888x;
Greg Daniel1ff50212019-08-02 15:54:08 -0400860 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400861 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400862 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
863 }
864 }
865 }
866 // Format: VK_FORMAT_R8G8_UNORM
867 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400868 constexpr VkFormat format = VK_FORMAT_R8G8_UNORM;
869 auto& info = this->getFormatInfo(format);
870 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400871 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400872 info.fColorTypeInfoCount = 1;
873 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
874 int ctIdx = 0;
875 // Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88
876 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400877 constexpr GrColorType ct = GrColorType::kRG_88;
Greg Daniel1ff50212019-08-02 15:54:08 -0400878 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400879 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400880 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
881 }
882 }
883 }
884 // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32
885 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400886 constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
887 auto& info = this->getFormatInfo(format);
888 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400889 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400890 info.fColorTypeInfoCount = 1;
891 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
892 int ctIdx = 0;
893 // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102
894 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400895 constexpr GrColorType ct = GrColorType::kRGBA_1010102;
Greg Daniel1ff50212019-08-02 15:54:08 -0400896 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400897 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400898 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
899 }
900 }
901 }
902 // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16
903 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400904 constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
905 auto& info = this->getFormatInfo(format);
906 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400907 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400908 info.fColorTypeInfoCount = 1;
909 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
910 int ctIdx = 0;
911 // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444
912 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400913 constexpr GrColorType ct = GrColorType::kABGR_4444;
Greg Daniel1ff50212019-08-02 15:54:08 -0400914 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400915 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400916 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
917 ctInfo.fTextureSwizzle = GrSwizzle::BGRA();
918 ctInfo.fOutputSwizzle = GrSwizzle::BGRA();
919 }
920 }
921 }
922 // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16
923 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400924 constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
925 auto& info = this->getFormatInfo(format);
926 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400927 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400928 info.fColorTypeInfoCount = 1;
929 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
930 int ctIdx = 0;
931 // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444
932 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400933 constexpr GrColorType ct = GrColorType::kABGR_4444;
Greg Daniel1ff50212019-08-02 15:54:08 -0400934 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400935 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400936 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
937 }
938 }
939 }
940 // Format: VK_FORMAT_R32G32B32A32_SFLOAT
941 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400942 constexpr VkFormat format = VK_FORMAT_R32G32B32A32_SFLOAT;
943 auto& info = this->getFormatInfo(format);
944 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400945 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400946 info.fColorTypeInfoCount = 1;
947 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
948 int ctIdx = 0;
949 // Format: VK_FORMAT_R32G32B32A32_SFLOAT, Surface: kRGBA_F32
950 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400951 constexpr GrColorType ct = GrColorType::kRGBA_F32;
Greg Daniel1ff50212019-08-02 15:54:08 -0400952 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400953 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400954 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
955 }
956 }
957 }
958 // Format: VK_FORMAT_R8G8B8A8_SRGB
959 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400960 constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB;
961 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700962 if (fSRGBSupport) {
Greg Daniel0fac8692019-08-16 13:13:17 -0400963 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700964 }
Greg Daniel7bfc9132019-08-14 14:23:53 -0400965 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400966 info.fColorTypeInfoCount = 1;
967 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
968 int ctIdx = 0;
969 // Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB
970 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400971 constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB;
Greg Daniel1ff50212019-08-02 15:54:08 -0400972 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400973 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400974 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
975 }
976 }
977 }
978 // Format: VK_FORMAT_R16_UNORM
979 {
Greg Daniel0fac8692019-08-16 13:13:17 -0400980 constexpr VkFormat format = VK_FORMAT_R16_UNORM;
981 auto& info = this->getFormatInfo(format);
982 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -0400983 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -0400984 info.fColorTypeInfoCount = 1;
985 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
986 int ctIdx = 0;
Robert Phillips429f0d32019-09-11 17:03:28 -0400987 // Format: VK_FORMAT_R16_UNORM, Surface: kAlpha_16
Greg Daniel1ff50212019-08-02 15:54:08 -0400988 {
Robert Phillips429f0d32019-09-11 17:03:28 -0400989 constexpr GrColorType ct = GrColorType::kAlpha_16;
Greg Daniel1ff50212019-08-02 15:54:08 -0400990 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -0400991 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -0400992 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
Robert Phillips429f0d32019-09-11 17:03:28 -0400993 ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
994 ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
Greg Daniel1ff50212019-08-02 15:54:08 -0400995 }
996 }
997 }
998 // Format: VK_FORMAT_R16G16_UNORM
999 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001000 constexpr VkFormat format = VK_FORMAT_R16G16_UNORM;
1001 auto& info = this->getFormatInfo(format);
1002 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001003 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001004 info.fColorTypeInfoCount = 1;
1005 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1006 int ctIdx = 0;
1007 // Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616
1008 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001009 constexpr GrColorType ct = GrColorType::kRG_1616;
Greg Daniel1ff50212019-08-02 15:54:08 -04001010 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001011 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001012 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1013 }
1014 }
1015 }
1016 // Format: VK_FORMAT_R16G16B16A16_UNORM
1017 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001018 constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM;
1019 auto& info = this->getFormatInfo(format);
1020 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001021 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001022 info.fColorTypeInfoCount = 1;
1023 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1024 int ctIdx = 0;
1025 // Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616
1026 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001027 constexpr GrColorType ct = GrColorType::kRGBA_16161616;
Greg Daniel1ff50212019-08-02 15:54:08 -04001028 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001029 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001030 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1031 }
1032 }
1033 }
1034 // Format: VK_FORMAT_R16G16_SFLOAT
1035 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001036 constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT;
1037 auto& info = this->getFormatInfo(format);
1038 info.init(interface, physDev, properties, format);
Greg Daniel7bfc9132019-08-14 14:23:53 -04001039 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001040 info.fColorTypeInfoCount = 1;
1041 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1042 int ctIdx = 0;
1043 // Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16
1044 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001045 constexpr GrColorType ct = GrColorType::kRG_F16;
Greg Daniel1ff50212019-08-02 15:54:08 -04001046 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001047 ctInfo.fColorType = ct;
Greg Daniel1ff50212019-08-02 15:54:08 -04001048 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1049 }
1050 }
1051 }
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001052 // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
1053 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001054 constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
1055 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001056 if (fSupportsYcbcrConversion) {
Greg Daniel0fac8692019-08-16 13:13:17 -04001057 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001058 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001059 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001060 info.fColorTypeInfoCount = 1;
1061 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1062 int ctIdx = 0;
1063 // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x
1064 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001065 constexpr GrColorType ct = GrColorType::kRGB_888x;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001066 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001067 ctInfo.fColorType = ct;
1068 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001069 }
1070 }
1071 }
1072 // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM
1073 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001074 constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
1075 auto& info = this->getFormatInfo(format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001076 if (fSupportsYcbcrConversion) {
Greg Daniel0fac8692019-08-16 13:13:17 -04001077 info.init(interface, physDev, properties, format);
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001078 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001079 if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001080 info.fColorTypeInfoCount = 1;
1081 info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
1082 int ctIdx = 0;
1083 // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x
1084 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001085 constexpr GrColorType ct = GrColorType::kRGB_888x;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001086 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
Greg Daniel0fac8692019-08-16 13:13:17 -04001087 ctInfo.fColorType = ct;
1088 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001089 }
1090 }
1091 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001092 // Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
1093 {
Greg Daniel0fac8692019-08-16 13:13:17 -04001094 constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
1095 auto& info = this->getFormatInfo(format);
1096 info.init(interface, physDev, properties, format);
Greg Daniel1ff50212019-08-02 15:54:08 -04001097 // No supported GrColorTypes.
1098 }
Greg Daniel0fac8692019-08-16 13:13:17 -04001099
1100 ////////////////////////////////////////////////////////////////////////////
1101 // Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats
1102 // are passed into the setColorType function indicates the priority in selecting which format
1103 // we use for a given GrcolorType.
1104
1105 this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM });
1106 this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16 });
1107 this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1108 VK_FORMAT_B4G4R4A4_UNORM_PACK16 });
1109 this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM });
1110 this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB });
1111 this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM,
1112 VK_FORMAT_R8G8B8A8_UNORM });
1113 this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM });
1114 this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM });
1115 this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 });
1116 this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM });
1117 this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT });
1118 this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT });
1119 this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT });
1120 this->setColorType(GrColorType::kRGBA_F32, { VK_FORMAT_R32G32B32A32_SFLOAT });
Robert Phillips429f0d32019-09-11 17:03:28 -04001121 this->setColorType(GrColorType::kAlpha_16, { VK_FORMAT_R16_UNORM });
Greg Daniel0fac8692019-08-16 13:13:17 -04001122 this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM });
1123 this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM });
1124 this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT });
egdaniel8f1dcaa2016-04-01 10:10:45 -07001125}
1126
Greg Daniel1ff50212019-08-02 15:54:08 -04001127void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
egdaniel8f1dcaa2016-04-01 10:10:45 -07001128 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
1129 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
Greg Daniel7bfc9132019-08-14 14:23:53 -04001130 *flags = *flags | kTexturable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -07001131
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001132 // Ganesh assumes that all renderable surfaces are also texturable
Greg Danielcaa795f2019-05-14 11:54:25 -04001133 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001134 *flags = *flags | kRenderable_Flag;
1135 }
egdaniel8f1dcaa2016-04-01 10:10:45 -07001136 }
1137
1138 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
1139 *flags = *flags | kBlitSrc_Flag;
1140 }
1141
1142 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
1143 *flags = *flags | kBlitDst_Flag;
1144 }
1145}
1146
Greg Danielcaa795f2019-05-14 11:54:25 -04001147void GrVkCaps::FormatInfo::initSampleCounts(const GrVkInterface* interface,
Greg Daniel81e7bf82017-07-19 14:47:42 -04001148 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001149 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -04001150 VkFormat format) {
1151 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1152 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1153 VK_IMAGE_USAGE_SAMPLED_BIT |
1154 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001155 VkImageFormatProperties properties;
1156 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
1157 format,
1158 VK_IMAGE_TYPE_2D,
1159 VK_IMAGE_TILING_OPTIMAL,
1160 usage,
Brian Osman2b23c4b2018-06-01 12:25:08 -04001161 0, // createFlags
Greg Daniel81e7bf82017-07-19 14:47:42 -04001162 &properties));
1163 VkSampleCountFlags flags = properties.sampleCounts;
1164 if (flags & VK_SAMPLE_COUNT_1_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001165 fColorSampleCounts.push_back(1);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001166 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001167 if (kImagination_VkVendor == physProps.vendorID) {
1168 // MSAA does not work on imagination
1169 return;
1170 }
Brian Osman7fbb3632019-07-19 11:38:57 -04001171 if (kIntel_VkVendor == physProps.vendorID) {
Brian Osmanb5391bf2019-08-15 14:52:52 -04001172 // MSAA doesn't work well on Intel GPUs chromium:527565, chromium:983926
1173 return;
Brian Osman7fbb3632019-07-19 11:38:57 -04001174 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001175 if (flags & VK_SAMPLE_COUNT_2_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001176 fColorSampleCounts.push_back(2);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001177 }
1178 if (flags & VK_SAMPLE_COUNT_4_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001179 fColorSampleCounts.push_back(4);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001180 }
1181 if (flags & VK_SAMPLE_COUNT_8_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001182 fColorSampleCounts.push_back(8);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001183 }
1184 if (flags & VK_SAMPLE_COUNT_16_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001185 fColorSampleCounts.push_back(16);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001186 }
1187 if (flags & VK_SAMPLE_COUNT_32_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001188 fColorSampleCounts.push_back(32);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001189 }
1190 if (flags & VK_SAMPLE_COUNT_64_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -04001191 fColorSampleCounts.push_back(64);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001192 }
1193}
1194
Greg Danielcaa795f2019-05-14 11:54:25 -04001195void GrVkCaps::FormatInfo::init(const GrVkInterface* interface,
egdaniel8f1dcaa2016-04-01 10:10:45 -07001196 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001197 const VkPhysicalDeviceProperties& properties,
Greg Danielcaa795f2019-05-14 11:54:25 -04001198 VkFormat format) {
egdaniel8f1dcaa2016-04-01 10:10:45 -07001199 VkFormatProperties props;
1200 memset(&props, 0, sizeof(VkFormatProperties));
1201 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
Greg Daniel1ff50212019-08-02 15:54:08 -04001202 InitFormatFlags(props.linearTilingFeatures, &fLinearFlags);
1203 InitFormatFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001204 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00001205 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -04001206 }
Greg Daniel164a9f02016-02-22 09:56:40 -05001207}
Greg Daniel81e7bf82017-07-19 14:47:42 -04001208
Robert Phillipsf209e882019-06-25 15:59:50 -04001209bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001210 VkFormat vkFormat;
1211 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsf209e882019-06-25 15:59:50 -04001212 return false;
1213 }
1214
Brian Salomond4764a12019-08-08 12:08:24 -04001215 return format_is_srgb(vkFormat);
Robert Phillipsf209e882019-06-25 15:59:50 -04001216}
1217
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001218bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001219 VkFormat vkFormat;
1220 if (!format.asVkFormat(&vkFormat)) {
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001221 return false;
1222 }
1223
Robert Phillips8ff8bcc2019-07-29 17:03:35 -04001224 SkASSERT(GrVkFormatIsSupported(vkFormat));
1225
1226 return vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
1227}
1228
Greg Daniel7bfc9132019-08-14 14:23:53 -04001229bool GrVkCaps::isFormatTexturableAndUploadable(GrColorType ct,
1230 const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001231 VkFormat vkFormat;
1232 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001233 return false;
1234 }
1235
Greg Daniel1ff50212019-08-02 15:54:08 -04001236 uint32_t ctFlags = this->getFormatInfo(vkFormat).colorTypeFlags(ct);
1237 return this->isVkFormatTexturable(vkFormat) &&
1238 SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag);
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001239}
1240
Greg Daniel7bfc9132019-08-14 14:23:53 -04001241bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const {
1242 VkFormat vkFormat;
1243 if (!format.asVkFormat(&vkFormat)) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001244 return false;
1245 }
Greg Daniel7bfc9132019-08-14 14:23:53 -04001246 return this->isVkFormatTexturable(vkFormat);
1247}
1248
1249bool GrVkCaps::isVkFormatTexturable(VkFormat format) const {
1250 const FormatInfo& info = this->getFormatInfo(format);
1251 return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags);
Robert Phillips39ef2ef2019-05-15 08:45:53 -04001252}
1253
Greg Daniel900583a2019-08-06 12:05:31 -04001254bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
1255 int sampleCount) const {
1256 if (!this->isFormatRenderable(format, sampleCount)) {
Greg Danieleadfac92019-08-02 09:03:53 -04001257 return false;
1258 }
Brian Salomond4764a12019-08-08 12:08:24 -04001259 VkFormat vkFormat;
1260 if (!format.asVkFormat(&vkFormat)) {
1261 return false;
1262 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001263 const auto& info = this->getFormatInfo(vkFormat);
1264 if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
Greg Danieleadfac92019-08-02 09:03:53 -04001265 return false;
1266 }
Greg Daniel900583a2019-08-06 12:05:31 -04001267 return true;
Greg Danieleadfac92019-08-02 09:03:53 -04001268}
1269
Greg Daniel900583a2019-08-06 12:05:31 -04001270bool GrVkCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001271 VkFormat vkFormat;
1272 if (!format.asVkFormat(&vkFormat)) {
Greg Daniel900583a2019-08-06 12:05:31 -04001273 return false;
1274 }
Greg Daniel900583a2019-08-06 12:05:31 -04001275 return this->isFormatRenderable(vkFormat, sampleCount);
1276}
1277
1278bool GrVkCaps::isFormatRenderable(VkFormat format, int sampleCount) const {
1279 return sampleCount <= this->maxRenderTargetSampleCount(format);
Greg Danielcaa795f2019-05-14 11:54:25 -04001280}
1281
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001282int GrVkCaps::getRenderTargetSampleCount(int requestedCount,
Brian Salomon4eb38b72019-08-05 12:58:39 -04001283 const GrBackendFormat& format) const {
1284 VkFormat vkFormat;
Brian Salomond4764a12019-08-08 12:08:24 -04001285 if (!format.asVkFormat(&vkFormat)) {
Brian Salomon4eb38b72019-08-05 12:58:39 -04001286 return 0;
1287 }
1288
Brian Salomond4764a12019-08-08 12:08:24 -04001289 return this->getRenderTargetSampleCount(requestedCount, vkFormat);
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001290}
1291
Greg Danielcaa795f2019-05-14 11:54:25 -04001292int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001293 requestedCount = SkTMax(1, requestedCount);
Greg Danielcaa795f2019-05-14 11:54:25 -04001294
1295 const FormatInfo& info = this->getFormatInfo(format);
1296
1297 int count = info.fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05001298
1299 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001300 return 0;
1301 }
1302
Brian Salomonbdecacf2018-02-02 20:32:49 -05001303 if (1 == requestedCount) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001304 SkASSERT(info.fColorSampleCounts.count() && info.fColorSampleCounts[0] == 1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001305 return 1;
1306 }
1307
Greg Daniel81e7bf82017-07-19 14:47:42 -04001308 for (int i = 0; i < count; ++i) {
Greg Danielcaa795f2019-05-14 11:54:25 -04001309 if (info.fColorSampleCounts[i] >= requestedCount) {
1310 return info.fColorSampleCounts[i];
Greg Daniel81e7bf82017-07-19 14:47:42 -04001311 }
1312 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001313 return 0;
1314}
1315
Greg Danieleadfac92019-08-02 09:03:53 -04001316int GrVkCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001317 VkFormat vkFormat;
1318 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001319 return 0;
1320 }
Brian Salomond4764a12019-08-08 12:08:24 -04001321 return this->maxRenderTargetSampleCount(vkFormat);
Greg Danielcaa795f2019-05-14 11:54:25 -04001322}
1323
1324int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const {
1325 const FormatInfo& info = this->getFormatInfo(format);
1326
1327 const auto& table = info.fColorSampleCounts;
Brian Salomonbdecacf2018-02-02 20:32:49 -05001328 if (!table.count()) {
1329 return 0;
1330 }
1331 return table[table.count() - 1];
Brian Salomond653cac2018-02-01 13:58:00 -05001332}
1333
Brian Salomon42be09d2019-07-26 12:12:26 -04001334static inline size_t align_to_4(size_t v) {
1335 switch (v & 0b11) {
1336 // v is already a multiple of 4.
1337 case 0: return v;
1338 // v is a multiple of 2 but not 4.
1339 case 2: return 2 * v;
1340 // v is not a multiple of 2.
1341 default: return 4 * v;
1342 }
1343}
1344
Brian Salomon01915c02019-08-02 09:57:21 -04001345GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
1346 const GrBackendFormat& surfaceFormat,
Brian Salomon42be09d2019-07-26 12:12:26 -04001347 GrColorType srcColorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001348 VkFormat vkFormat;
1349 if (!surfaceFormat.asVkFormat(&vkFormat)) {
Greg Daniel1ff50212019-08-02 15:54:08 -04001350 return {GrColorType::kUnknown, 0};
1351 }
1352
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001353
1354 if (GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1355 return {GrColorType::kUnknown, 0};
1356 }
1357
Greg Daniel1ff50212019-08-02 15:54:08 -04001358 // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
Brian Salomond4764a12019-08-08 12:08:24 -04001359 size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001360
Brian Salomond4764a12019-08-08 12:08:24 -04001361 const auto& info = this->getFormatInfo(vkFormat);
Greg Daniel1ff50212019-08-02 15:54:08 -04001362 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1363 const auto& ctInfo = info.fColorTypeInfos[i];
1364 if (ctInfo.fColorType == surfaceColorType) {
1365 return {surfaceColorType, offsetAlignment};
1366 }
1367 }
1368 return {GrColorType::kUnknown, 0};
Brian Salomon42be09d2019-07-26 12:12:26 -04001369}
1370
Brian Salomondc0710f2019-07-01 14:59:32 -04001371GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels(
1372 const GrSurface* surface) const {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -04001373 if (surface->isProtected()) {
Brian Salomondc0710f2019-07-01 14:59:32 -04001374 return SurfaceReadPixelsSupport::kUnsupported;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -04001375 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001376 if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
1377 // We can't directly read from a VkImage that has a ycbcr sampler.
1378 if (tex->ycbcrConversionInfo().isValid()) {
Brian Salomondc0710f2019-07-01 14:59:32 -04001379 return SurfaceReadPixelsSupport::kCopyToTexture2D;
Greg Daniela51e93c2019-03-25 12:30:45 -04001380 }
Greg Daniel00fb7242019-07-18 14:28:01 -04001381 // We can't directly read from a compressed format
1382 SkImage::CompressionType compressionType;
1383 if (GrVkFormatToCompressionType(tex->imageFormat(), &compressionType)) {
1384 return SurfaceReadPixelsSupport::kCopyToTexture2D;
1385 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001386 }
Brian Salomondc0710f2019-07-01 14:59:32 -04001387 return SurfaceReadPixelsSupport::kSupported;
Greg Daniela51e93c2019-03-25 12:30:45 -04001388}
1389
Brian Salomonc67c31c2018-12-06 10:00:03 -05001390bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
Brian Salomon3d86a192018-02-27 16:46:11 -05001391 if (auto rt = surface->asRenderTarget()) {
Chris Dalton6ce447a2019-06-23 18:07:38 -06001392 return rt->numSamples() <= 1 && SkToBool(surface->asTexture());
Brian Salomon3d86a192018-02-27 16:46:11 -05001393 }
Greg Daniela51e93c2019-03-25 12:30:45 -04001394 // We can't write to a texture that has a ycbcr sampler.
1395 if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
1396 // We can't directly read from a VkImage that has a ycbcr sampler.
1397 if (tex->ycbcrConversionInfo().isValid()) {
1398 return false;
1399 }
1400 }
Brian Salomon3d86a192018-02-27 16:46:11 -05001401 return true;
1402}
1403
Greg Daniel0fac8692019-08-16 13:13:17 -04001404bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
1405 const GrBackendFormat& format) const {
1406 VkFormat vkFormat;
1407 if (!format.asVkFormat(&vkFormat)) {
1408 return false;
1409 }
1410 const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
1411 SkASSERT(ycbcrInfo);
1412
1413 if (ycbcrInfo->isValid() && !GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1414 // Format may be undefined for external images, which are required to have YCbCr conversion.
1415 if (VK_FORMAT_UNDEFINED == vkFormat) {
1416 return true;
1417 }
1418 return false;
1419 }
1420
1421 const auto& info = this->getFormatInfo(vkFormat);
1422 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1423 if (info.fColorTypeInfos[i].fColorType == ct) {
1424 return true;
1425 }
1426 }
1427 return false;
1428}
1429
Robert Phillips1e2cb442019-07-02 15:51:28 -04001430static GrPixelConfig validate_image_info(VkFormat format, GrColorType ct, bool hasYcbcrConversion) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001431 if (hasYcbcrConversion) {
1432 if (GrVkFormatNeedsYcbcrSampler(format)) {
1433 return kRGB_888X_GrPixelConfig;
1434 }
1435
1436 // Format may be undefined for external images, which are required to have YCbCr conversion.
1437 if (VK_FORMAT_UNDEFINED == format) {
Greg Daniel14c55c22018-12-04 11:25:03 -05001438 // 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 -04001439 // values for external textures. However, for read pixels we will draw to a non ycbcr
1440 // texture of this config so we set RGBA here for that.
Brian Salomonf391d0f2018-12-14 09:18:50 -05001441 return kRGBA_8888_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001442 }
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001443
1444 return kUnknown_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001445 }
1446
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001447 if (VK_FORMAT_UNDEFINED == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001448 return kUnknown_GrPixelConfig;
Greg Daniel14c55c22018-12-04 11:25:03 -05001449 }
1450
Greg Danielf5d87582017-12-18 14:48:15 -05001451 switch (ct) {
Robert Phillips1e2cb442019-07-02 15:51:28 -04001452 case GrColorType::kUnknown:
Brian Salomonf391d0f2018-12-14 09:18:50 -05001453 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001454 case GrColorType::kAlpha_8:
Greg Danielf5d87582017-12-18 14:48:15 -05001455 if (VK_FORMAT_R8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001456 return kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001457 }
1458 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001459 case GrColorType::kBGR_565:
Greg Danielf5d87582017-12-18 14:48:15 -05001460 if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001461 return kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001462 }
1463 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001464 case GrColorType::kABGR_4444:
Greg Danieleb4a8272019-05-16 16:52:55 -04001465 if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format ||
1466 VK_FORMAT_R4G4B4A4_UNORM_PACK16 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001467 return kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001468 }
1469 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001470 case GrColorType::kRGBA_8888:
Greg Danielf5d87582017-12-18 14:48:15 -05001471 if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001472 return kRGBA_8888_GrPixelConfig;
Greg Daniele877dce2019-07-11 10:52:43 -04001473 }
1474 break;
1475 case GrColorType::kRGBA_8888_SRGB:
1476 if (VK_FORMAT_R8G8B8A8_SRGB == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001477 return kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001478 }
1479 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001480 case GrColorType::kRGB_888x:
Greg Daniel475eb702018-09-28 14:16:50 -04001481 if (VK_FORMAT_R8G8B8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001482 return kRGB_888_GrPixelConfig;
Robert Phillipsffe27292019-08-01 10:08:07 -04001483 } else if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Greg Danielf259b8b2019-02-14 09:03:43 -05001484 return kRGB_888X_GrPixelConfig;
Robert Phillipsffe27292019-08-01 10:08:07 -04001485 } else if (VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK == format) {
1486 return kRGB_ETC1_GrPixelConfig;
Greg Danielf259b8b2019-02-14 09:03:43 -05001487 }
Greg Daniel475eb702018-09-28 14:16:50 -04001488 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001489 case GrColorType::kRG_88:
1490 if (VK_FORMAT_R8G8_UNORM == format) {
1491 return kRG_88_GrPixelConfig;
1492 }
1493 break;
1494 case GrColorType::kBGRA_8888:
Greg Danielf5d87582017-12-18 14:48:15 -05001495 if (VK_FORMAT_B8G8R8A8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001496 return kBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001497 }
1498 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001499 case GrColorType::kRGBA_1010102:
Brian Osman10fc6fd2018-03-02 11:01:10 -05001500 if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001501 return kRGBA_1010102_GrPixelConfig;
Brian Osman10fc6fd2018-03-02 11:01:10 -05001502 }
1503 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001504 case GrColorType::kGray_8:
Greg Danielf5d87582017-12-18 14:48:15 -05001505 if (VK_FORMAT_R8_UNORM == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001506 return kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001507 }
1508 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001509 case GrColorType::kAlpha_F16:
1510 if (VK_FORMAT_R16_SFLOAT == format) {
Robert Phillips0902c982019-07-16 07:47:56 -04001511 return kAlpha_half_as_Red_GrPixelConfig;
Mike Kleinb70990e2019-02-28 10:03:27 -06001512 }
1513 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001514 case GrColorType::kRGBA_F16:
Greg Danielf5d87582017-12-18 14:48:15 -05001515 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001516 return kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001517 }
1518 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001519 case GrColorType::kRGBA_F16_Clamped:
1520 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
1521 return kRGBA_half_Clamped_GrPixelConfig;
1522 }
1523 break;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001524 case GrColorType::kRGBA_F32:
Mike Klein37854712018-06-26 11:43:06 -04001525 if (VK_FORMAT_R32G32B32A32_SFLOAT == format) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001526 return kRGBA_float_GrPixelConfig;
Mike Klein37854712018-06-26 11:43:06 -04001527 }
1528 break;
Robert Phillips429f0d32019-09-11 17:03:28 -04001529 case GrColorType::kAlpha_16:
Robert Phillips1e2cb442019-07-02 15:51:28 -04001530 if (VK_FORMAT_R16_UNORM == format) {
Robert Phillips429f0d32019-09-11 17:03:28 -04001531 return kAlpha_16_GrPixelConfig;
Robert Phillips1e2cb442019-07-02 15:51:28 -04001532 }
1533 break;
1534 case GrColorType::kRG_1616:
1535 if (VK_FORMAT_R16G16_UNORM == format) {
1536 return kRG_1616_GrPixelConfig;
1537 }
1538 break;
1539 case GrColorType::kRGBA_16161616:
1540 if (VK_FORMAT_R16G16B16A16_UNORM == format) {
1541 return kRGBA_16161616_GrPixelConfig;
1542 }
1543 break;
1544 case GrColorType::kRG_F16:
1545 if (VK_FORMAT_R16G16_SFLOAT == format) {
1546 return kRG_half_GrPixelConfig;
1547 }
1548 break;
Brian Salomon8f8354a2019-07-31 20:12:02 -04001549 // These have no equivalent:
1550 case GrColorType::kAlpha_8xxx:
1551 case GrColorType::kAlpha_F32xxx:
1552 case GrColorType::kGray_8xxx:
1553 break;
Greg Danielf5d87582017-12-18 14:48:15 -05001554 }
1555
Brian Salomonf391d0f2018-12-14 09:18:50 -05001556 return kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05001557}
1558
Greg Daniel627d0532019-07-08 16:48:14 -04001559GrPixelConfig GrVkCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
1560 GrColorType ct) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001561 VkFormat vkFormat;
1562 if (!format.asVkFormat(&vkFormat)) {
Brian Salomonf391d0f2018-12-14 09:18:50 -05001563 return kUnknown_GrPixelConfig;
Robert Phillipsfc711a22018-02-13 17:03:00 -05001564 }
Brian Salomond4764a12019-08-08 12:08:24 -04001565 const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
1566 SkASSERT(ycbcrInfo);
1567 return validate_image_info(vkFormat, ct, ycbcrInfo->isValid());
Greg Danielfaa095e2017-12-19 13:15:02 -05001568}
Greg Danielf5d87582017-12-18 14:48:15 -05001569
Robert Phillips00c9f0d2019-08-02 17:17:35 -04001570GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
1571 bool isAlphaChannel) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001572 VkFormat vkFormat;
1573 if (!format.asVkFormat(&vkFormat)) {
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001574 return GrColorType::kUnknown;
1575 }
1576
Brian Salomond4764a12019-08-08 12:08:24 -04001577 switch (vkFormat) {
Robert Phillips00c9f0d2019-08-02 17:17:35 -04001578 case VK_FORMAT_R8_UNORM: return isAlphaChannel ? GrColorType::kAlpha_8
1579 : GrColorType::kGray_8;
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001580 case VK_FORMAT_R8G8B8A8_UNORM: return GrColorType::kRGBA_8888;
1581 case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x;
1582 case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88;
1583 case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888;
1584 case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102;
Robert Phillips429f0d32019-09-11 17:03:28 -04001585 case VK_FORMAT_R16_UNORM: return GrColorType::kAlpha_16;
Robert Phillips17a3a0b2019-09-18 13:56:54 -04001586 case VK_FORMAT_R16_SFLOAT: return GrColorType::kAlpha_F16;
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001587 case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616;
Robert Phillipsc80b0e92019-07-23 10:27:09 -04001588 case VK_FORMAT_R16G16B16A16_UNORM: return GrColorType::kRGBA_16161616;
1589 case VK_FORMAT_R16G16_SFLOAT: return GrColorType::kRG_F16;
1590 default: return GrColorType::kUnknown;
1591 }
1592
1593 SkUNREACHABLE;
1594}
1595
Robert Phillips0a15cc62019-07-30 12:49:10 -04001596GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct,
1597 GrRenderable renderable) const {
Greg Daniel0fac8692019-08-16 13:13:17 -04001598 VkFormat format = this->getFormatFromColorType(ct);
1599 if (format == VK_FORMAT_UNDEFINED) {
Greg Daniel4065d452018-11-16 15:43:41 -05001600 return GrBackendFormat();
1601 }
1602 return GrBackendFormat::MakeVk(format);
1603}
Timothy Liang036fdfe2018-06-28 15:50:36 -04001604
Brian Salomonbb8dde82019-06-27 10:52:13 -04001605GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType(
1606 SkImage::CompressionType compressionType) const {
1607 switch (compressionType) {
1608 case SkImage::kETC1_CompressionType:
1609 return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
1610 }
1611 SK_ABORT("Invalid compression type");
Brian Salomonbb8dde82019-06-27 10:52:13 -04001612}
1613
Greg Daniel1ff50212019-08-02 15:54:08 -04001614GrSwizzle GrVkCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001615 VkFormat vkFormat;
1616 SkAssertResult(format.asVkFormat(&vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001617 const auto& info = this->getFormatInfo(vkFormat);
1618 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1619 const auto& ctInfo = info.fColorTypeInfos[i];
1620 if (ctInfo.fColorType == colorType) {
1621 return ctInfo.fTextureSwizzle;
1622 }
Greg Danieleb4a8272019-05-16 16:52:55 -04001623 }
1624 return GrSwizzle::RGBA();
1625}
1626
Greg Danieleb4a8272019-05-16 16:52:55 -04001627GrSwizzle GrVkCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001628 VkFormat vkFormat;
1629 SkAssertResult(format.asVkFormat(&vkFormat));
Greg Daniel1ff50212019-08-02 15:54:08 -04001630 const auto& info = this->getFormatInfo(vkFormat);
1631 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1632 const auto& ctInfo = info.fColorTypeInfos[i];
1633 if (ctInfo.fColorType == colorType) {
1634 return ctInfo.fOutputSwizzle;
1635 }
1636 }
1637 return GrSwizzle::RGBA();
Greg Danieleb4a8272019-05-16 16:52:55 -04001638}
1639
Greg Danielba88ab62019-07-26 09:14:01 -04001640GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType(
Greg Daniel00fb7242019-07-18 14:28:01 -04001641 GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
1642 GrColorType dstColorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -04001643 VkFormat vkFormat;
1644 if (!srcBackendFormat.asVkFormat(&vkFormat)) {
Brian Salomon8f8354a2019-07-31 20:12:02 -04001645 return {GrColorType::kUnknown, 0};
Greg Danielba88ab62019-07-26 09:14:01 -04001646 }
1647
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001648 if (GrVkFormatNeedsYcbcrSampler(vkFormat)) {
1649 return {GrColorType::kUnknown, 0};
1650 }
1651
Greg Danielba88ab62019-07-26 09:14:01 -04001652 // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
Brian Salomond4764a12019-08-08 12:08:24 -04001653 size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
Greg Daniel00fb7242019-07-18 14:28:01 -04001654
Brian Salomond4764a12019-08-08 12:08:24 -04001655 const auto& info = this->getFormatInfo(vkFormat);
Greg Daniel1ff50212019-08-02 15:54:08 -04001656 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1657 const auto& ctInfo = info.fColorTypeInfos[i];
1658 if (ctInfo.fColorType == srcColorType) {
1659 return {srcColorType, offsetAlignment};
1660 }
Greg Daniel00fb7242019-07-18 14:28:01 -04001661 }
Greg Daniel1ff50212019-08-02 15:54:08 -04001662 return {GrColorType::kUnknown, 0};
Greg Daniel00fb7242019-07-18 14:28:01 -04001663}
Robert Phillipsffe27292019-08-01 10:08:07 -04001664
Ethan Nicholas0be34802019-08-15 12:36:58 -04001665int GrVkCaps::getFragmentUniformBinding() const {
1666 return GrVkUniformHandler::kUniformBinding;
1667}
1668
1669int GrVkCaps::getFragmentUniformSet() const {
1670 return GrVkUniformHandler::kUniformBufferDescSet;
1671}
1672
Robert Phillipsffe27292019-08-01 10:08:07 -04001673#if GR_TEST_UTILS
1674std::vector<GrCaps::TestFormatColorTypeCombination> GrVkCaps::getTestingCombinations() const {
1675 std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
1676 { GrColorType::kAlpha_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) },
1677 { GrColorType::kBGR_565, GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16) },
1678 { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_R4G4B4A4_UNORM_PACK16)},
1679 { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16)},
1680 { GrColorType::kRGBA_8888, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) },
1681 { GrColorType::kRGBA_8888_SRGB, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB) },
1682 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) },
1683 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM) },
1684 { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)},
1685 { GrColorType::kRG_88, GrBackendFormat::MakeVk(VK_FORMAT_R8G8_UNORM) },
1686 { GrColorType::kBGRA_8888, GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) },
1687 { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)},
1688 { GrColorType::kGray_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) },
1689 { GrColorType::kAlpha_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16_SFLOAT) },
1690 { GrColorType::kRGBA_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) },
1691 { GrColorType::kRGBA_F16_Clamped, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) },
1692 { GrColorType::kRGBA_F32, GrBackendFormat::MakeVk(VK_FORMAT_R32G32B32A32_SFLOAT) },
Robert Phillips429f0d32019-09-11 17:03:28 -04001693 { GrColorType::kAlpha_16, GrBackendFormat::MakeVk(VK_FORMAT_R16_UNORM) },
Robert Phillipsffe27292019-08-01 10:08:07 -04001694 { GrColorType::kRG_1616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_UNORM) },
1695 { GrColorType::kRGBA_16161616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_UNORM) },
1696 { GrColorType::kRG_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_SFLOAT) },
1697 };
1698
Robert Phillipsffe27292019-08-01 10:08:07 -04001699 return combos;
1700}
1701#endif