blob: 4445a3ae0bec68c0d0b5b920eb9a2f632caf8902 [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
8#include "GrVkCaps.h"
Greg Danielf5d87582017-12-18 14:48:15 -05009#include "GrBackendSurface.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040010#include "GrRenderTargetProxy.h"
Brian Salomon3d86a192018-02-27 16:46:11 -050011#include "GrRenderTarget.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050012#include "GrShaderCaps.h"
Greg Danield3e65aa2018-08-01 09:19:45 -040013#include "GrVkInterface.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014#include "GrVkUtil.h"
jvanverthfd7bd452016-03-25 06:29:52 -070015#include "vk/GrVkBackendContext.h"
Greg Danielc0b03d82018-08-03 14:41:15 -040016#include "vk/GrVkExtensions.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050017
18GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
Greg Daniela0651ac2018-08-08 09:23:18 -040019 VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features,
Greg Danielc0b03d82018-08-03 14:41:15 -040020 uint32_t instanceVersion, const GrVkExtensions& extensions)
egdanielc5ec1402016-03-28 12:14:42 -070021 : INHERITED(contextOptions) {
Greg Danielc0b03d82018-08-03 14:41:15 -040022
Greg Daniel164a9f02016-02-22 09:56:40 -050023 /**************************************************************************
Brian Salomoncd7907b2018-08-30 08:36:18 -040024 * GrDrawTargetCaps fields
25 **************************************************************************/
jvanverth62340062016-04-26 08:01:44 -070026 fMipMapSupport = true; // always available in Vulkan
brianosmanf05ab1b2016-05-12 11:01:10 -070027 fSRGBSupport = true; // always available in Vulkan
brianosman88791862016-05-23 10:15:27 -070028 fNPOTTextureTileSupport = true; // always available in Vulkan
egdaniel37535c92016-06-30 08:23:30 -070029 fDiscardRenderTargetSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050030 fReuseScratchTextures = true; //TODO: figure this out
31 fGpuTracingSupport = false; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050032 fOversizedStencilSupport = false; //TODO: figure this out
Chris Dalton1d616352017-05-31 12:51:23 -060033 fInstanceAttribSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050034
Greg Daniel0fe4ed82018-03-15 12:27:29 +000035 fBlacklistCoverageCounting = true; // blacklisting ccpr until we work through a few issues.
jvanverth84741b32016-09-30 08:39:02 -070036 fFenceSyncSupport = true; // always available in Vulkan
Greg Daniel691f5e72018-02-28 14:21:34 -050037 fCrossContextTextureSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050038
39 fMapBufferFlags = kNone_MapFlags; //TODO: figure this out
cdalton397536c2016-03-25 12:15:03 -070040 fBufferMapThreshold = SK_MaxS32; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050041
42 fMaxRenderTargetSize = 4096; // minimum required by spec
43 fMaxTextureSize = 4096; // minimum required by spec
Greg Daniel164a9f02016-02-22 09:56:40 -050044
Brian Salomon94efbf52016-11-29 13:43:05 -050045 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Greg Daniel164a9f02016-02-22 09:56:40 -050046
Greg Danielc0b03d82018-08-03 14:41:15 -040047 this->init(contextOptions, vkInterface, physDev, features, extensions);
Greg Daniel164a9f02016-02-22 09:56:40 -050048}
49
Robert Phillipsbf25d432017-04-07 10:08:53 -040050bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -050051 GrSurfaceOrigin* origin, bool* rectsMustMatch,
52 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -070053 // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false.
54 *rectsMustMatch = false;
55 *disallowSubrect = false;
56
Brian Salomon467921e2017-03-06 16:17:12 -050057 // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa).
58 // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a
59 // render target as well.
Brian Salomon2a4f9832018-03-03 22:43:43 -050060 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -050061 desc->fConfig = src->config();
Greg Daniel55fa6472018-03-16 16:13:10 -040062 if (src->numColorSamples() > 1 || src->asTextureProxy()) {
Brian Salomon467921e2017-03-06 16:17:12 -050063 desc->fFlags = kRenderTarget_GrSurfaceFlag;
64 } else {
65 // Just going to use CopyImage here
66 desc->fFlags = kNone_GrSurfaceFlags;
67 }
68
69 return true;
70}
71
Greg Daniel25af6712018-04-25 10:44:38 -040072bool GrVkCaps::canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin,
73 GrPixelConfig srcConfig, int srcSampleCnt,
74 GrSurfaceOrigin srcOrigin) const {
75 if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) {
76 return false;
77 }
78
79 // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src
80 // as image usage flags.
81 if (srcOrigin != dstOrigin || GrBytesPerPixel(srcConfig) != GrBytesPerPixel(dstConfig)) {
82 return false;
83 }
84
85 if (this->shaderCaps()->configOutputSwizzle(srcConfig) !=
86 this->shaderCaps()->configOutputSwizzle(dstConfig)) {
87 return false;
88 }
89
90 return true;
91}
92
93bool GrVkCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear,
94 GrPixelConfig srcConfig, int srcSampleCnt, bool srcIsLinear) const {
95 // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src
96 // as image usage flags.
97 if (!this->configCanBeDstofBlit(dstConfig, dstIsLinear) ||
98 !this->configCanBeSrcofBlit(srcConfig, srcIsLinear)) {
99 return false;
100 }
101
102 if (this->shaderCaps()->configOutputSwizzle(srcConfig) !=
103 this->shaderCaps()->configOutputSwizzle(dstConfig)) {
104 return false;
105 }
106
107 // We cannot blit images that are multisampled. Will need to figure out if we can blit the
108 // resolved msaa though.
109 if (dstSampleCnt > 1 || srcSampleCnt > 1) {
110 return false;
111 }
112
113 return true;
114}
115
116bool GrVkCaps::canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt,
117 GrSurfaceOrigin dstOrigin, GrPixelConfig srcConfig,
118 int srcSampleCnt, GrSurfaceOrigin srcOrigin) const {
119 // The src surface must be multisampled.
120 if (srcSampleCnt <= 1) {
121 return false;
122 }
123
124 // The dst must not be multisampled.
125 if (dstSampleCnt > 1) {
126 return false;
127 }
128
129 // Surfaces must have the same format.
130 if (dstConfig != srcConfig) {
131 return false;
132 }
133
134 // Surfaces must have the same origin.
135 if (srcOrigin != dstOrigin) {
136 return false;
137 }
138
139 return true;
140}
141
142bool GrVkCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable,
143 GrPixelConfig srcConfig, bool srcIsTextureable) const {
144 // TODO: Make copySurfaceAsDraw handle the swizzle
145 if (this->shaderCaps()->configOutputSwizzle(srcConfig) !=
146 this->shaderCaps()->configOutputSwizzle(dstConfig)) {
147 return false;
148 }
149
150 // Make sure the dst is a render target and the src is a texture.
151 if (!dstIsRenderable || !srcIsTextureable) {
152 return false;
153 }
154
155 return true;
156}
157
158bool GrVkCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
159 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
160 GrSurfaceOrigin dstOrigin = dst->origin();
161 GrSurfaceOrigin srcOrigin = src->origin();
162
163 GrPixelConfig dstConfig = dst->config();
164 GrPixelConfig srcConfig = src->config();
165
166 // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g.
167 // PromiseImage which won't get instantiated right away. Does this need a similar thing like the
168 // tracking of external or rectangle textures in GL? For now we don't create linear textures
169 // internally, and I don't believe anyone is wrapping them.
170 bool srcIsLinear = false;
171 bool dstIsLinear = false;
172
173 int dstSampleCnt = 0;
174 int srcSampleCnt = 0;
175 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
176 dstSampleCnt = rtProxy->numColorSamples();
177 }
178 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
179 srcSampleCnt = rtProxy->numColorSamples();
180 }
181 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
182 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
183
184 return this->canCopyImage(dstConfig, dstSampleCnt, dstOrigin,
185 srcConfig, srcSampleCnt, srcOrigin) ||
186 this->canCopyAsBlit(dstConfig, dstSampleCnt, dstIsLinear,
187 srcConfig, srcSampleCnt, srcIsLinear) ||
188 this->canCopyAsResolve(dstConfig, dstSampleCnt, dstOrigin,
189 srcConfig, srcSampleCnt, srcOrigin) ||
190 this->canCopyAsDraw(dstConfig, dstSampleCnt > 0,
191 srcConfig, SkToBool(src->asTextureProxy()));
192}
193
Greg Daniel164a9f02016-02-22 09:56:40 -0500194void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
Greg Daniela0651ac2018-08-08 09:23:18 -0400195 VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features,
Greg Danielc0b03d82018-08-03 14:41:15 -0400196 const GrVkExtensions& extensions) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500197
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000198 VkPhysicalDeviceProperties properties;
199 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties));
egdanield5e3b9e2016-03-08 12:19:54 -0800200
egdanield5e3b9e2016-03-08 12:19:54 -0800201 VkPhysicalDeviceMemoryProperties memoryProperties;
202 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties));
203
Greg Danielc0b03d82018-08-03 14:41:15 -0400204 uint32_t physicalDeviceVersion = properties.apiVersion;
205
206 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
207 extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) {
208 fSupportsPhysicalDeviceProperties2 = true;
209 }
210
211 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
212 extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) {
213 fSupportsMemoryRequirements2 = true;
214 }
215
216 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Daniel637c06a2018-09-12 09:44:25 -0400217 extensions.hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) {
218 fSupportsBindMemory2 = true;
219 }
220
221 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Danielc0b03d82018-08-03 14:41:15 -0400222 extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) {
223 fSupportsMaintenance1 = true;
224 }
225
226 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
227 extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) {
228 fSupportsMaintenance2 = true;
229 }
230
231 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
232 extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) {
233 fSupportsMaintenance3 = true;
234 }
235
Greg Daniela9979d12018-08-27 15:56:46 -0400236 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
Greg Daniel637c06a2018-09-12 09:44:25 -0400237 (extensions.hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) &&
Greg Daniela9979d12018-08-27 15:56:46 -0400238 this->supportsMemoryRequirements2())) {
239 fSupportsDedicatedAllocation = true;
240 }
241
242 if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) ||
243 (extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1) &&
244 this->supportsPhysicalDeviceProperties2() &&
245 extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, 1) &&
246 this->supportsDedicatedAllocation())) {
247 fSupportsExternalMemory = true;
248 }
249
250#ifdef SK_BUILD_FOR_ANDROID
Greg Daniel637c06a2018-09-12 09:44:25 -0400251 // Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they
252 // do we don't explicitly require it here even the spec says it is required.
Greg Daniela9979d12018-08-27 15:56:46 -0400253 if (extensions.hasExtension(
Greg Daniel637c06a2018-09-12 09:44:25 -0400254 VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, 2) &&
255 /* extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1) &&*/
256 this->supportsExternalMemory() &&
257 this->supportsBindMemory2()) {
Greg Daniela9979d12018-08-27 15:56:46 -0400258 fSupportsAndroidHWBExternalMemory = true;
Greg Daniel637c06a2018-09-12 09:44:25 -0400259 fSupportsAHardwareBufferImages = true;
Greg Daniela9979d12018-08-27 15:56:46 -0400260 }
261#endif
262
Greg Daniel313c6952018-08-08 09:24:08 -0400263 this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions);
Greg Daniel36443602018-08-02 12:51:52 -0400264 this->initShaderCaps(properties, features);
Greg Danielf3b11622018-03-01 15:01:27 -0500265
266 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
267#if defined(SK_CPU_X86)
268 // We need to do this before initing the config table since it uses fSRGBSupport
269 if (kImagination_VkVendor == properties.vendorID) {
270 fSRGBSupport = false;
271 }
272#endif
273 }
274
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000275 this->initConfigTable(vkInterface, physDev, properties);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700276 this->initStencilFormat(vkInterface, physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -0500277
Greg Daniel691f5e72018-02-28 14:21:34 -0500278 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
279 this->applyDriverCorrectnessWorkarounds(properties);
egdanielc5ec1402016-03-28 12:14:42 -0700280 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500281
Greg Danielddc0c602018-06-18 11:26:30 -0400282 // On nexus player we disable suballocating VkImage memory since we've seen large slow downs on
283 // bot run times.
284 if (kImagination_VkVendor == properties.vendorID) {
285 fShouldAlwaysUseDedicatedImageMemory = true;
286 }
287
Greg Daniel691f5e72018-02-28 14:21:34 -0500288 this->applyOptionsOverrides(contextOptions);
289 fShaderCaps->applyOptionsOverrides(contextOptions);
290}
291
292void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) {
egdaniel6fa0a912016-09-12 11:51:29 -0700293 if (kQualcomm_VkVendor == properties.vendorID) {
294 fMustDoCopiesFromOrigin = true;
295 }
296
egdanielfd016d72016-09-27 12:13:05 -0700297 if (kNvidia_VkVendor == properties.vendorID) {
egdanielfd016d72016-09-27 12:13:05 -0700298 fMustSubmitCommandsBeforeCopyOp = true;
299 }
300
Greg Daniel80a08dd2017-01-20 10:45:49 -0500301#if defined(SK_BUILD_FOR_WIN)
Greg Daniel900e5c82018-08-28 10:59:24 -0400302 if (kNvidia_VkVendor == properties.vendorID || kIntel_VkVendor == properties.vendorID) {
Greg Daniel80a08dd2017-01-20 10:45:49 -0500303 fMustSleepOnTearDown = true;
304 }
305#elif defined(SK_BUILD_FOR_ANDROID)
306 if (kImagination_VkVendor == properties.vendorID) {
307 fMustSleepOnTearDown = true;
308 }
309#endif
Greg Danielbce5eb92018-03-01 13:13:44 -0500310
311 // AMD seems to have issues binding new VkPipelines inside a secondary command buffer.
312 // Current workaround is to use a different secondary command buffer for each new VkPipeline.
313 if (kAMD_VkVendor == properties.vendorID) {
314 fNewCBOnPipelineChange = true;
315 }
316
Greg Danielddc0c602018-06-18 11:26:30 -0400317 // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages.
318 if (kARM_VkVendor == properties.vendorID) {
319 fShouldAlwaysUseDedicatedImageMemory = true;
320 }
321
Greg Danielbce5eb92018-03-01 13:13:44 -0500322 ////////////////////////////////////////////////////////////////////////////
323 // GrCaps workarounds
324 ////////////////////////////////////////////////////////////////////////////
325
326 if (kARM_VkVendor == properties.vendorID) {
327 fInstanceAttribSupport = false;
328 }
329
330 // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32.
331 if (kAMD_VkVendor == properties.vendorID) {
332 fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32);
333 }
334
Greg Danielbce5eb92018-03-01 13:13:44 -0500335 ////////////////////////////////////////////////////////////////////////////
336 // GrShaderCaps workarounds
337 ////////////////////////////////////////////////////////////////////////////
338
Greg Danielbce5eb92018-03-01 13:13:44 -0500339 if (kImagination_VkVendor == properties.vendorID) {
340 fShaderCaps->fAtan2ImplementedAsAtanYOverX = true;
341 }
342
Greg Daniel164a9f02016-02-22 09:56:40 -0500343}
344
345int get_max_sample_count(VkSampleCountFlags flags) {
346 SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT);
347 if (!(flags & VK_SAMPLE_COUNT_2_BIT)) {
348 return 0;
349 }
350 if (!(flags & VK_SAMPLE_COUNT_4_BIT)) {
351 return 2;
352 }
353 if (!(flags & VK_SAMPLE_COUNT_8_BIT)) {
354 return 4;
355 }
356 if (!(flags & VK_SAMPLE_COUNT_16_BIT)) {
357 return 8;
358 }
359 if (!(flags & VK_SAMPLE_COUNT_32_BIT)) {
360 return 16;
361 }
362 if (!(flags & VK_SAMPLE_COUNT_64_BIT)) {
363 return 32;
364 }
365 return 64;
366}
367
Greg Daniel313c6952018-08-08 09:24:08 -0400368template<typename T> T* get_extension_feature_struct(const VkPhysicalDeviceFeatures2& features,
369 VkStructureType type) {
370 // All Vulkan structs that could be part of the features chain will start with the
371 // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
372 // so we can get access to the pNext for the next struct.
373 struct CommonVulkanHeader {
374 VkStructureType sType;
375 void* pNext;
376 };
377
378 void* pNext = features.pNext;
379 while (pNext) {
380 CommonVulkanHeader* header = static_cast<CommonVulkanHeader*>(pNext);
381 if (header->sType == type) {
382 return static_cast<T*>(pNext);
383 }
384 pNext = header->pNext;
385 }
386 return nullptr;
387}
388
389void GrVkCaps::initGrCaps(const GrVkInterface* vkInterface,
390 VkPhysicalDevice physDev,
391 const VkPhysicalDeviceProperties& properties,
jvanverthfd7bd452016-03-25 06:29:52 -0700392 const VkPhysicalDeviceMemoryProperties& memoryProperties,
Greg Daniel313c6952018-08-08 09:24:08 -0400393 const VkPhysicalDeviceFeatures2& features,
394 const GrVkExtensions& extensions) {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400395 // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no
396 // need for us ever to support that amount, and it makes tests which tests all the vertex
397 // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if
398 // we ever find that need.
399 static const uint32_t kMaxVertexAttributes = 64;
400 fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes);
Greg Danielc5cc2de2017-03-20 11:40:58 -0400401
egdanield5e3b9e2016-03-08 12:19:54 -0800402 // We could actually query and get a max size for each config, however maxImageDimension2D will
403 // give the minimum max size across all configs. So for simplicity we will use that for now.
jvanverthe78d4872016-09-27 03:33:05 -0700404 fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
405 fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
Adrienne Walker724afe82018-05-15 11:36:26 -0700406 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
407 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
408 }
409 // Our render targets are always created with textures as the color
410 // attachment, hence this min:
411 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
egdanield5e3b9e2016-03-08 12:19:54 -0800412
Chris Dalton2612bae2018-02-22 13:41:37 -0700413 // TODO: check if RT's larger than 4k incur a performance cost on ARM.
414 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
415
egdanield5e3b9e2016-03-08 12:19:54 -0800416 // Assuming since we will always map in the end to upload the data we might as well just map
417 // from the get go. There is no hard data to suggest this is faster or slower.
cdalton397536c2016-03-25 12:15:03 -0700418 fBufferMapThreshold = 0;
egdanield5e3b9e2016-03-08 12:19:54 -0800419
420 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
421
egdanield5e3b9e2016-03-08 12:19:54 -0800422 fOversizedStencilSupport = true;
Greg Daniela0651ac2018-08-08 09:23:18 -0400423 fSampleShadingSupport = features.features.sampleRateShading;
Greg Daniel313c6952018-08-08 09:24:08 -0400424
425 if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2) &&
426 this->supportsPhysicalDeviceProperties2()) {
427
428 VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps;
429 blendProps.sType =
430 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT;
431 blendProps.pNext = nullptr;
432
433 VkPhysicalDeviceProperties2 props;
434 props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
435 props.pNext = &blendProps;
436
437 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props));
438
439 if (blendProps.advancedBlendAllOperations == VK_TRUE) {
440 fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
441
442 auto blendFeatures =
443 get_extension_feature_struct<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>(
444 features,
445 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT);
446 if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) {
447 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
448 } else {
449 // TODO: Currently non coherent blends are not supported in our vulkan backend. They
450 // require us to support self dependencies in our render passes.
451 // fBlendEquationSupport = kAdvanced_BlendEquationSupport;
452 }
453 }
454 }
egdanield5e3b9e2016-03-08 12:19:54 -0800455}
456
Greg Daniel36443602018-08-02 12:51:52 -0400457void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties,
Greg Daniela0651ac2018-08-08 09:23:18 -0400458 const VkPhysicalDeviceFeatures2& features) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500459 GrShaderCaps* shaderCaps = fShaderCaps.get();
460 shaderCaps->fVersionDeclString = "#version 330\n";
egdaniel3a15fd42016-04-05 11:00:29 -0700461
Greg Daniel164a9f02016-02-22 09:56:40 -0500462
463 // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config.
464 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
465 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Greg Danielef59d872017-11-17 16:47:21 -0500466 // Vulkan doesn't support a single channel format stored in alpha.
467 if (GrPixelConfigIsAlphaOnly(config) &&
468 kAlpha_8_as_Alpha_GrPixelConfig != config) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500469 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR();
470 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
Greg Daniel164a9f02016-02-22 09:56:40 -0500471 } else {
Greg Daniel7af060a2017-12-05 16:27:11 -0500472 if (kGray_8_GrPixelConfig == config ||
473 kGray_8_as_Red_GrPixelConfig == config) {
Brian Osman986563b2017-01-10 14:20:02 -0500474 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA();
475 } else if (kRGBA_4444_GrPixelConfig == config) {
egdaniel3fe03272016-08-15 10:59:17 -0700476 // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we
477 // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads
478 // or writing to outputs. Since we're not actually changing the data at all, the
479 // only extra work is the swizzle in the shader for all operations.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500480 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA();
481 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA();
egdaniel3fe03272016-08-15 10:59:17 -0700482 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500483 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA();
egdaniel3fe03272016-08-15 10:59:17 -0700484 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500485 }
486 }
egdaniel67acb832016-02-26 08:32:20 -0800487
egdanield5e3b9e2016-03-08 12:19:54 -0800488 // Vulkan is based off ES 3.0 so the following should all be supported
Brian Salomon1edc5b92016-11-29 13:43:46 -0500489 shaderCaps->fUsesPrecisionModifiers = true;
490 shaderCaps->fFlatInterpolationSupport = true;
Brian Salomon41274562017-09-15 09:40:03 -0700491 // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed
492 // to be true with Vulkan as well.
493 shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID;
egdanield5e3b9e2016-03-08 12:19:54 -0800494
495 // GrShaderCaps
496
Brian Salomon1edc5b92016-11-29 13:43:46 -0500497 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600498
Greg Daniela0651ac2018-08-08 09:23:18 -0400499 shaderCaps->fGeometryShaderSupport = features.features.geometryShader;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600500 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
egdanield632bb42016-03-30 12:06:48 -0700501
Greg Daniela0651ac2018-08-08 09:23:18 -0400502 shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend;
egdanield632bb42016-03-30 12:06:48 -0700503
Brian Salomon1edc5b92016-11-29 13:43:46 -0500504 shaderCaps->fIntegerSupport = true;
Chris Dalton1d616352017-05-31 12:51:23 -0600505 shaderCaps->fVertexIDSupport = true;
Chris Dalton7c7ff032018-03-28 20:09:58 -0600506 shaderCaps->fFPManipulationSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800507
cdaltona6b92ad2016-04-11 12:03:08 -0700508 // Assume the minimum precisions mandated by the SPIR-V spec.
Chris Dalton47c8ed32017-11-15 18:27:09 -0700509 shaderCaps->fFloatIs32Bits = true;
510 shaderCaps->fHalfIs32Bits = false;
cdaltona6b92ad2016-04-11 12:03:08 -0700511
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400512 // SPIR-V supports unsigned integers.
513 shaderCaps->fUnsignedSupport = true;
514
Brian Salomon1edc5b92016-11-29 13:43:46 -0500515 shaderCaps->fMaxVertexSamplers =
516 shaderCaps->fMaxGeometrySamplers =
517 shaderCaps->fMaxFragmentSamplers = SkTMin(
518 SkTMin(properties.limits.maxPerStageDescriptorSampledImages,
519 properties.limits.maxPerStageDescriptorSamplers),
520 (uint32_t)INT_MAX);
521 shaderCaps->fMaxCombinedSamplers = SkTMin(
522 SkTMin(properties.limits.maxDescriptorSetSampledImages,
523 properties.limits.maxDescriptorSetSamplers),
524 (uint32_t)INT_MAX);
Greg Daniel164a9f02016-02-22 09:56:40 -0500525}
526
egdaniel8f1dcaa2016-04-01 10:10:45 -0700527bool stencil_format_supported(const GrVkInterface* interface,
528 VkPhysicalDevice physDev,
529 VkFormat format) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500530 VkFormatProperties props;
531 memset(&props, 0, sizeof(VkFormatProperties));
532 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
egdaniel8f1dcaa2016-04-01 10:10:45 -0700533 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures);
Greg Daniel164a9f02016-02-22 09:56:40 -0500534}
535
egdaniel8f1dcaa2016-04-01 10:10:45 -0700536void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) {
537 // List of legal stencil formats (though perhaps not supported on
538 // the particular gpu/driver) from most preferred to least. We are guaranteed to have either
jvanvertha4b0fed2016-04-27 11:42:21 -0700539 // 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 -0700540 // can optionally have 24 unused bits at the end so we assume the total bits is 64.
Greg Daniel164a9f02016-02-22 09:56:40 -0500541 static const StencilFormat
542 // internal Format stencil bits total bits packed?
543 gS8 = { VK_FORMAT_S8_UINT, 8, 8, false },
egdaniel8f1dcaa2016-04-01 10:10:45 -0700544 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true },
545 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true };
Greg Daniel164a9f02016-02-22 09:56:40 -0500546
egdaniel8f1dcaa2016-04-01 10:10:45 -0700547 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) {
548 fPreferedStencilFormat = gS8;
549 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) {
550 fPreferedStencilFormat = gD24S8;
551 } else {
552 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT));
553 fPreferedStencilFormat = gD32S8;
554 }
555}
556
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000557void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
558 const VkPhysicalDeviceProperties& properties) {
egdaniel8f1dcaa2016-04-01 10:10:45 -0700559 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
560 VkFormat format;
561 if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) {
Greg Daniel01907872017-05-23 15:21:02 -0400562 if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000563 fConfigTable[i].init(interface, physDev, properties, format);
Greg Daniel01907872017-05-23 15:21:02 -0400564 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700565 }
566 }
567}
568
569void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
570 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
571 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
572 *flags = *flags | kTextureable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700573
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400574 // Ganesh assumes that all renderable surfaces are also texturable
575 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
576 *flags = *flags | kRenderable_Flag;
577 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700578 }
579
580 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
581 *flags = *flags | kBlitSrc_Flag;
582 }
583
584 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
585 *flags = *flags | kBlitDst_Flag;
586 }
587}
588
Greg Daniel81e7bf82017-07-19 14:47:42 -0400589void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface,
590 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000591 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400592 VkFormat format) {
593 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
594 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
595 VK_IMAGE_USAGE_SAMPLED_BIT |
596 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Greg Daniel81e7bf82017-07-19 14:47:42 -0400597 VkImageFormatProperties properties;
598 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
599 format,
600 VK_IMAGE_TYPE_2D,
601 VK_IMAGE_TILING_OPTIMAL,
602 usage,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400603 0, // createFlags
Greg Daniel81e7bf82017-07-19 14:47:42 -0400604 &properties));
605 VkSampleCountFlags flags = properties.sampleCounts;
606 if (flags & VK_SAMPLE_COUNT_1_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400607 fColorSampleCounts.push_back(1);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400608 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000609 if (kImagination_VkVendor == physProps.vendorID) {
610 // MSAA does not work on imagination
611 return;
612 }
Greg Daniel81e7bf82017-07-19 14:47:42 -0400613 if (flags & VK_SAMPLE_COUNT_2_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400614 fColorSampleCounts.push_back(2);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400615 }
616 if (flags & VK_SAMPLE_COUNT_4_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400617 fColorSampleCounts.push_back(4);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400618 }
619 if (flags & VK_SAMPLE_COUNT_8_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400620 fColorSampleCounts.push_back(8);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400621 }
622 if (flags & VK_SAMPLE_COUNT_16_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400623 fColorSampleCounts.push_back(16);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400624 }
625 if (flags & VK_SAMPLE_COUNT_32_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400626 fColorSampleCounts.push_back(32);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400627 }
628 if (flags & VK_SAMPLE_COUNT_64_BIT) {
Mike Reedb5475792018-08-08 16:17:42 -0400629 fColorSampleCounts.push_back(64);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400630 }
631}
632
egdaniel8f1dcaa2016-04-01 10:10:45 -0700633void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface,
634 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000635 const VkPhysicalDeviceProperties& properties,
egdaniel8f1dcaa2016-04-01 10:10:45 -0700636 VkFormat format) {
637 VkFormatProperties props;
638 memset(&props, 0, sizeof(VkFormatProperties));
639 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
640 InitConfigFlags(props.linearTilingFeatures, &fLinearFlags);
641 InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400642 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000643 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400644 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500645}
Greg Daniel81e7bf82017-07-19 14:47:42 -0400646
Brian Salomonbdecacf2018-02-02 20:32:49 -0500647int GrVkCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
648 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400649 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -0500650
651 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -0400652 return 0;
653 }
654
Brian Salomonbdecacf2018-02-02 20:32:49 -0500655 if (1 == requestedCount) {
656 SkASSERT(fConfigTable[config].fColorSampleCounts.count() &&
657 fConfigTable[config].fColorSampleCounts[0] == 1);
658 return 1;
659 }
660
Greg Daniel81e7bf82017-07-19 14:47:42 -0400661 for (int i = 0; i < count; ++i) {
662 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
663 return fConfigTable[config].fColorSampleCounts[i];
664 }
665 }
Brian Salomonbdecacf2018-02-02 20:32:49 -0500666 return 0;
667}
668
669int GrVkCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
670 const auto& table = fConfigTable[config].fColorSampleCounts;
671 if (!table.count()) {
672 return 0;
673 }
674 return table[table.count() - 1];
Brian Salomond653cac2018-02-01 13:58:00 -0500675}
676
Brian Salomon3d86a192018-02-27 16:46:11 -0500677bool GrVkCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
678 if (auto rt = surface->asRenderTarget()) {
679 return rt->numColorSamples() <= 1 && SkToBool(surface->asTexture());
680 }
681 return true;
682}
683
Robert Phillipsfc711a22018-02-13 17:03:00 -0500684bool validate_image_info(VkFormat format, SkColorType ct, GrPixelConfig* config) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500685 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500686
687 switch (ct) {
688 case kUnknown_SkColorType:
689 return false;
690 case kAlpha_8_SkColorType:
691 if (VK_FORMAT_R8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500692 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500693 }
694 break;
695 case kRGB_565_SkColorType:
696 if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500697 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500698 }
699 break;
700 case kARGB_4444_SkColorType:
701 if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500702 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500703 }
704 break;
705 case kRGBA_8888_SkColorType:
706 if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500707 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500708 } else if (VK_FORMAT_R8G8B8A8_SRGB == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500709 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500710 }
711 break;
Brian Salomone41e1762018-01-25 14:07:47 -0500712 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -0400713 // TODO: VK_FORMAT_R8G8B8_UNORM
Brian Salomone41e1762018-01-25 14:07:47 -0500714 return false;
Greg Danielf5d87582017-12-18 14:48:15 -0500715 case kBGRA_8888_SkColorType:
716 if (VK_FORMAT_B8G8R8A8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500717 *config = kBGRA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500718 } else if (VK_FORMAT_B8G8R8A8_SRGB == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500719 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500720 }
721 break;
Brian Salomone41e1762018-01-25 14:07:47 -0500722 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -0500723 if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) {
724 *config = kRGBA_1010102_GrPixelConfig;
725 }
726 break;
Brian Salomone41e1762018-01-25 14:07:47 -0500727 case kRGB_101010x_SkColorType:
728 return false;
Greg Danielf5d87582017-12-18 14:48:15 -0500729 case kGray_8_SkColorType:
730 if (VK_FORMAT_R8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500731 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500732 }
733 break;
734 case kRGBA_F16_SkColorType:
735 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500736 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500737 }
738 break;
Mike Klein37854712018-06-26 11:43:06 -0400739 case kRGBA_F32_SkColorType:
740 if (VK_FORMAT_R32G32B32A32_SFLOAT == format) {
741 *config = kRGBA_float_GrPixelConfig;
742 }
743 break;
Greg Danielf5d87582017-12-18 14:48:15 -0500744 }
745
Greg Danielfaa095e2017-12-19 13:15:02 -0500746 return kUnknown_GrPixelConfig != *config;
Greg Danielf5d87582017-12-18 14:48:15 -0500747}
748
Greg Danielfaa095e2017-12-19 13:15:02 -0500749bool GrVkCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
750 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -0400751 GrVkImageInfo imageInfo;
752 if (!tex.getVkImageInfo(&imageInfo)) {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500753 return false;
754 }
755
Greg Daniel52e16d92018-04-10 09:34:07 -0400756 return validate_image_info(imageInfo.fFormat, ct, config);
Greg Danielfaa095e2017-12-19 13:15:02 -0500757}
758
759bool GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
760 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -0400761 GrVkImageInfo imageInfo;
762 if (!rt.getVkImageInfo(&imageInfo)) {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500763 return false;
764 }
765
Greg Daniel323fbcf2018-04-10 13:46:30 -0400766 return validate_image_info(imageInfo.fFormat, ct, config);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500767}
768
769bool GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
770 GrPixelConfig* config) const {
771 const VkFormat* vkFormat = format.getVkFormat();
772 if (!vkFormat) {
773 return false;
774 }
775 return validate_image_info(*vkFormat, ct, config);
Greg Danielfaa095e2017-12-19 13:15:02 -0500776}
Greg Danielf5d87582017-12-18 14:48:15 -0500777
Timothy Liang036fdfe2018-06-28 15:50:36 -0400778#ifdef GR_TEST_UTILS
779GrBackendFormat GrVkCaps::onCreateFormatFromBackendTexture(
780 const GrBackendTexture& backendTex) const {
781 GrVkImageInfo vkInfo;
782 SkAssertResult(backendTex.getVkImageInfo(&vkInfo));
783 return GrBackendFormat::MakeVk(vkInfo.fFormat);
784}
785#endif
786