blob: 0ae7c00995391e8a0a63ed5f5ed70cad66089c93 [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
10#include "GrBackendSurface.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040011#include "GrRenderTargetProxy.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050012#include "GrShaderCaps.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050013#include "GrVkUtil.h"
jvanverthfd7bd452016-03-25 06:29:52 -070014#include "vk/GrVkBackendContext.h"
Brian Salomon467921e2017-03-06 16:17:12 -050015#include "vk/GrVkInterface.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050016
17GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070018 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags)
19 : INHERITED(contextOptions) {
20 fCanUseGLSLForShaderModule = false;
egdaniel6fa0a912016-09-12 11:51:29 -070021 fMustDoCopiesFromOrigin = false;
egdanielbc9b2962016-09-27 08:00:53 -070022 fSupportsCopiesAsDraws = false;
egdanielfd016d72016-09-27 12:13:05 -070023 fMustSubmitCommandsBeforeCopyOp = false;
Greg Daniel80a08dd2017-01-20 10:45:49 -050024 fMustSleepOnTearDown = false;
Greg Daniele3cd6912017-05-17 11:15:55 -040025 fNewCBOnPipelineChange = false;
egdanielc5ec1402016-03-28 12:14:42 -070026
Greg Daniel164a9f02016-02-22 09:56:40 -050027 /**************************************************************************
28 * GrDrawTargetCaps fields
29 **************************************************************************/
jvanverth62340062016-04-26 08:01:44 -070030 fMipMapSupport = true; // always available in Vulkan
brianosmanf05ab1b2016-05-12 11:01:10 -070031 fSRGBSupport = true; // always available in Vulkan
Brian Osman57bc3ea2017-07-27 09:58:11 -040032 fSRGBDecodeDisableSupport = true; // always available in Vulkan
brianosman88791862016-05-23 10:15:27 -070033 fNPOTTextureTileSupport = true; // always available in Vulkan
egdaniel37535c92016-06-30 08:23:30 -070034 fDiscardRenderTargetSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050035 fReuseScratchTextures = true; //TODO: figure this out
36 fGpuTracingSupport = false; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050037 fOversizedStencilSupport = false; //TODO: figure this out
Chris Dalton1d616352017-05-31 12:51:23 -060038 fInstanceAttribSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050039
Chris Daltone4679fa2017-09-29 13:58:26 -060040 fBlacklistCoverageCounting = true; // blacklisting ccpr until we work through a few issues.
jvanverth84741b32016-09-30 08:39:02 -070041 fFenceSyncSupport = true; // always available in Vulkan
Greg Daniela63e7ab2017-05-16 14:38:54 -040042 fCrossContextTextureSupport = false;
Greg Daniel164a9f02016-02-22 09:56:40 -050043
44 fMapBufferFlags = kNone_MapFlags; //TODO: figure this out
cdalton397536c2016-03-25 12:15:03 -070045 fBufferMapThreshold = SK_MaxS32; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050046
47 fMaxRenderTargetSize = 4096; // minimum required by spec
48 fMaxTextureSize = 4096; // minimum required by spec
Greg Daniel164a9f02016-02-22 09:56:40 -050049
Brian Salomon94efbf52016-11-29 13:43:05 -050050 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Greg Daniel164a9f02016-02-22 09:56:40 -050051
egdanielc5ec1402016-03-28 12:14:42 -070052 this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050053}
54
Robert Phillipsbf25d432017-04-07 10:08:53 -040055bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -070056 bool* rectsMustMatch, bool* disallowSubrect) const {
57 // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false.
58 *rectsMustMatch = false;
59 *disallowSubrect = false;
60
Brian Salomon467921e2017-03-06 16:17:12 -050061 // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa).
62 // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a
63 // render target as well.
64 desc->fOrigin = src->origin();
65 desc->fConfig = src->config();
Robert Phillipsbf25d432017-04-07 10:08:53 -040066 if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) {
Brian Salomon467921e2017-03-06 16:17:12 -050067 desc->fFlags = kRenderTarget_GrSurfaceFlag;
68 } else {
69 // Just going to use CopyImage here
70 desc->fFlags = kNone_GrSurfaceFlags;
71 }
72
73 return true;
74}
75
Greg Daniel164a9f02016-02-22 09:56:40 -050076void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070077 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) {
Greg Daniel164a9f02016-02-22 09:56:40 -050078
Jim Van Verth6a40abc2017-11-02 16:56:09 +000079 VkPhysicalDeviceProperties properties;
80 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties));
egdanield5e3b9e2016-03-08 12:19:54 -080081
egdanield5e3b9e2016-03-08 12:19:54 -080082 VkPhysicalDeviceMemoryProperties memoryProperties;
83 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties));
84
jvanverthfd7bd452016-03-25 06:29:52 -070085 this->initGrCaps(properties, memoryProperties, featureFlags);
Brian Salomon1edc5b92016-11-29 13:43:46 -050086 this->initShaderCaps(properties, featureFlags);
Greg Daniel2bb6ecc2017-07-20 13:11:14 +000087 this->initConfigTable(vkInterface, physDev, properties);
egdaniel8f1dcaa2016-04-01 10:10:45 -070088 this->initStencilFormat(vkInterface, physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -050089
egdanielc5ec1402016-03-28 12:14:42 -070090 if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) {
egdanield632bb42016-03-30 12:06:48 -070091 // Currently disabling this feature since it does not play well with validation layers which
92 // expect a SPIR-V shader
93 // fCanUseGLSLForShaderModule = true;
egdanielc5ec1402016-03-28 12:14:42 -070094 }
Greg Daniel164a9f02016-02-22 09:56:40 -050095
egdaniel6fa0a912016-09-12 11:51:29 -070096 if (kQualcomm_VkVendor == properties.vendorID) {
97 fMustDoCopiesFromOrigin = true;
98 }
99
egdanielfd016d72016-09-27 12:13:05 -0700100 if (kNvidia_VkVendor == properties.vendorID) {
egdanielfd016d72016-09-27 12:13:05 -0700101 fMustSubmitCommandsBeforeCopyOp = true;
102 }
103
Greg Daniel1cdbdda2017-05-16 14:52:57 -0400104 if (kQualcomm_VkVendor != properties.vendorID) {
105 fSupportsCopiesAsDraws = true;
106 }
107
Greg Daniela63e7ab2017-05-16 14:38:54 -0400108 if (fSupportsCopiesAsDraws) {
109 fCrossContextTextureSupport = true;
110 }
111
Greg Daniel80a08dd2017-01-20 10:45:49 -0500112#if defined(SK_BUILD_FOR_WIN)
113 if (kNvidia_VkVendor == properties.vendorID) {
114 fMustSleepOnTearDown = true;
115 }
116#elif defined(SK_BUILD_FOR_ANDROID)
117 if (kImagination_VkVendor == properties.vendorID) {
118 fMustSleepOnTearDown = true;
119 }
120#endif
121
Greg Daniel164a9f02016-02-22 09:56:40 -0500122 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500123 fShaderCaps->applyOptionsOverrides(contextOptions);
Greg Daniel164a9f02016-02-22 09:56:40 -0500124}
125
126int get_max_sample_count(VkSampleCountFlags flags) {
127 SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT);
128 if (!(flags & VK_SAMPLE_COUNT_2_BIT)) {
129 return 0;
130 }
131 if (!(flags & VK_SAMPLE_COUNT_4_BIT)) {
132 return 2;
133 }
134 if (!(flags & VK_SAMPLE_COUNT_8_BIT)) {
135 return 4;
136 }
137 if (!(flags & VK_SAMPLE_COUNT_16_BIT)) {
138 return 8;
139 }
140 if (!(flags & VK_SAMPLE_COUNT_32_BIT)) {
141 return 16;
142 }
143 if (!(flags & VK_SAMPLE_COUNT_64_BIT)) {
144 return 32;
145 }
146 return 64;
147}
148
egdanield5e3b9e2016-03-08 12:19:54 -0800149void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties,
jvanverthfd7bd452016-03-25 06:29:52 -0700150 const VkPhysicalDeviceMemoryProperties& memoryProperties,
151 uint32_t featureFlags) {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400152 // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no
153 // need for us ever to support that amount, and it makes tests which tests all the vertex
154 // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if
155 // we ever find that need.
156 static const uint32_t kMaxVertexAttributes = 64;
157 fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes);
158 // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32.
159 if (kAMD_VkVendor == properties.vendorID) {
160 fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32);
161 }
162
egdanield5e3b9e2016-03-08 12:19:54 -0800163 // We could actually query and get a max size for each config, however maxImageDimension2D will
164 // give the minimum max size across all configs. So for simplicity we will use that for now.
jvanverthe78d4872016-09-27 03:33:05 -0700165 fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
166 fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
egdanield5e3b9e2016-03-08 12:19:54 -0800167
egdanield5e3b9e2016-03-08 12:19:54 -0800168 // Assuming since we will always map in the end to upload the data we might as well just map
169 // from the get go. There is no hard data to suggest this is faster or slower.
cdalton397536c2016-03-25 12:15:03 -0700170 fBufferMapThreshold = 0;
egdanield5e3b9e2016-03-08 12:19:54 -0800171
172 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
173
egdanield5e3b9e2016-03-08 12:19:54 -0800174 fOversizedStencilSupport = true;
ethannicholas28ef4452016-03-25 09:26:03 -0700175 fSampleShadingSupport = SkToBool(featureFlags & kSampleRateShading_GrVkFeatureFlag);
Greg Daniel22bc8652017-03-22 15:45:43 -0400176
177 // AMD seems to have issues binding new VkPipelines inside a secondary command buffer.
178 // Current workaround is to use a different secondary command buffer for each new VkPipeline.
179 if (kAMD_VkVendor == properties.vendorID) {
Greg Daniele3cd6912017-05-17 11:15:55 -0400180 fNewCBOnPipelineChange = true;
Greg Daniel22bc8652017-03-22 15:45:43 -0400181 }
Greg Daniel01907872017-05-23 15:21:02 -0400182
183#if defined(SK_CPU_X86)
184 if (kImagination_VkVendor == properties.vendorID) {
185 fSRGBSupport = false;
186 }
187#endif
egdanield5e3b9e2016-03-08 12:19:54 -0800188}
189
Brian Salomon1edc5b92016-11-29 13:43:46 -0500190void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint32_t featureFlags) {
191 GrShaderCaps* shaderCaps = fShaderCaps.get();
192 shaderCaps->fVersionDeclString = "#version 330\n";
egdaniel3a15fd42016-04-05 11:00:29 -0700193
Greg Daniel164a9f02016-02-22 09:56:40 -0500194
195 // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config.
196 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
197 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Greg Danielef59d872017-11-17 16:47:21 -0500198 // Vulkan doesn't support a single channel format stored in alpha.
199 if (GrPixelConfigIsAlphaOnly(config) &&
200 kAlpha_8_as_Alpha_GrPixelConfig != config) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500201 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR();
202 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
Greg Daniel164a9f02016-02-22 09:56:40 -0500203 } else {
Greg Daniel7af060a2017-12-05 16:27:11 -0500204 if (kGray_8_GrPixelConfig == config ||
205 kGray_8_as_Red_GrPixelConfig == config) {
Brian Osman986563b2017-01-10 14:20:02 -0500206 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA();
207 } else if (kRGBA_4444_GrPixelConfig == config) {
egdaniel3fe03272016-08-15 10:59:17 -0700208 // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we
209 // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads
210 // or writing to outputs. Since we're not actually changing the data at all, the
211 // only extra work is the swizzle in the shader for all operations.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500212 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA();
213 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA();
egdaniel3fe03272016-08-15 10:59:17 -0700214 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500215 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA();
egdaniel3fe03272016-08-15 10:59:17 -0700216 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500217 }
218 }
egdaniel67acb832016-02-26 08:32:20 -0800219
Greg Daniel80a08dd2017-01-20 10:45:49 -0500220 if (kImagination_VkVendor == properties.vendorID) {
221 shaderCaps->fAtan2ImplementedAsAtanYOverX = true;
222 }
223
egdanield5e3b9e2016-03-08 12:19:54 -0800224 // Vulkan is based off ES 3.0 so the following should all be supported
Brian Salomon1edc5b92016-11-29 13:43:46 -0500225 shaderCaps->fUsesPrecisionModifiers = true;
226 shaderCaps->fFlatInterpolationSupport = true;
Brian Salomon41274562017-09-15 09:40:03 -0700227 // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed
228 // to be true with Vulkan as well.
229 shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID;
egdanield5e3b9e2016-03-08 12:19:54 -0800230
231 // GrShaderCaps
232
Brian Salomon1edc5b92016-11-29 13:43:46 -0500233 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600234
Brian Salomon1edc5b92016-11-29 13:43:46 -0500235 shaderCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag);
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600236 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
egdanield632bb42016-03-30 12:06:48 -0700237
Brian Salomon1edc5b92016-11-29 13:43:46 -0500238 shaderCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag);
Greg Daniel84cff132017-03-22 16:25:53 -0400239 if (kAMD_VkVendor == properties.vendorID) {
240 // Currently DualSourceBlending is not working on AMD. vkCreateGraphicsPipeline fails when
241 // using a draw with dual source. Looking into whether it is driver bug or issue with our
242 // SPIR-V. Bug skia:6405
243 shaderCaps->fDualSourceBlendingSupport = false;
244 }
egdanield632bb42016-03-30 12:06:48 -0700245
Brian Salomon1edc5b92016-11-29 13:43:46 -0500246 shaderCaps->fIntegerSupport = true;
Chris Dalton6b65b982017-07-06 11:04:00 -0600247 shaderCaps->fTexelBufferSupport = true;
248 shaderCaps->fTexelFetchSupport = true;
Chris Dalton1d616352017-05-31 12:51:23 -0600249 shaderCaps->fVertexIDSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800250
cdaltona6b92ad2016-04-11 12:03:08 -0700251 // Assume the minimum precisions mandated by the SPIR-V spec.
Chris Dalton47c8ed32017-11-15 18:27:09 -0700252 shaderCaps->fFloatIs32Bits = true;
253 shaderCaps->fHalfIs32Bits = false;
cdaltona6b92ad2016-04-11 12:03:08 -0700254
Brian Salomon1edc5b92016-11-29 13:43:46 -0500255 shaderCaps->fMaxVertexSamplers =
256 shaderCaps->fMaxGeometrySamplers =
257 shaderCaps->fMaxFragmentSamplers = SkTMin(
258 SkTMin(properties.limits.maxPerStageDescriptorSampledImages,
259 properties.limits.maxPerStageDescriptorSamplers),
260 (uint32_t)INT_MAX);
261 shaderCaps->fMaxCombinedSamplers = SkTMin(
262 SkTMin(properties.limits.maxDescriptorSetSampledImages,
263 properties.limits.maxDescriptorSetSamplers),
264 (uint32_t)INT_MAX);
Greg Daniel164a9f02016-02-22 09:56:40 -0500265}
266
egdaniel8f1dcaa2016-04-01 10:10:45 -0700267bool stencil_format_supported(const GrVkInterface* interface,
268 VkPhysicalDevice physDev,
269 VkFormat format) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500270 VkFormatProperties props;
271 memset(&props, 0, sizeof(VkFormatProperties));
272 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
egdaniel8f1dcaa2016-04-01 10:10:45 -0700273 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures);
Greg Daniel164a9f02016-02-22 09:56:40 -0500274}
275
egdaniel8f1dcaa2016-04-01 10:10:45 -0700276void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) {
277 // List of legal stencil formats (though perhaps not supported on
278 // the particular gpu/driver) from most preferred to least. We are guaranteed to have either
jvanvertha4b0fed2016-04-27 11:42:21 -0700279 // 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 -0700280 // can optionally have 24 unused bits at the end so we assume the total bits is 64.
Greg Daniel164a9f02016-02-22 09:56:40 -0500281 static const StencilFormat
282 // internal Format stencil bits total bits packed?
283 gS8 = { VK_FORMAT_S8_UINT, 8, 8, false },
egdaniel8f1dcaa2016-04-01 10:10:45 -0700284 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true },
285 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true };
Greg Daniel164a9f02016-02-22 09:56:40 -0500286
egdaniel8f1dcaa2016-04-01 10:10:45 -0700287 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) {
288 fPreferedStencilFormat = gS8;
289 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) {
290 fPreferedStencilFormat = gD24S8;
291 } else {
292 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT));
293 fPreferedStencilFormat = gD32S8;
294 }
295}
296
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000297void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
298 const VkPhysicalDeviceProperties& properties) {
egdaniel8f1dcaa2016-04-01 10:10:45 -0700299 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
300 VkFormat format;
301 if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) {
Greg Daniel01907872017-05-23 15:21:02 -0400302 if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000303 fConfigTable[i].init(interface, physDev, properties, format);
Greg Daniel01907872017-05-23 15:21:02 -0400304 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700305 }
306 }
307}
308
309void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
310 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
311 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
312 *flags = *flags | kTextureable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700313
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400314 // Ganesh assumes that all renderable surfaces are also texturable
315 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
316 *flags = *flags | kRenderable_Flag;
317 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700318 }
319
320 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
321 *flags = *flags | kBlitSrc_Flag;
322 }
323
324 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
325 *flags = *flags | kBlitDst_Flag;
326 }
327}
328
Greg Daniel81e7bf82017-07-19 14:47:42 -0400329void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface,
330 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000331 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400332 VkFormat format) {
333 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
334 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
335 VK_IMAGE_USAGE_SAMPLED_BIT |
336 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
337 VkImageCreateFlags createFlags = GrVkFormatIsSRGB(format, nullptr)
338 ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0;
339 VkImageFormatProperties properties;
340 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
341 format,
342 VK_IMAGE_TYPE_2D,
343 VK_IMAGE_TILING_OPTIMAL,
344 usage,
345 createFlags,
346 &properties));
347 VkSampleCountFlags flags = properties.sampleCounts;
348 if (flags & VK_SAMPLE_COUNT_1_BIT) {
349 fColorSampleCounts.push(0);
350 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000351 if (kImagination_VkVendor == physProps.vendorID) {
352 // MSAA does not work on imagination
353 return;
354 }
Greg Daniel81e7bf82017-07-19 14:47:42 -0400355 if (flags & VK_SAMPLE_COUNT_2_BIT) {
356 fColorSampleCounts.push(2);
357 }
358 if (flags & VK_SAMPLE_COUNT_4_BIT) {
359 fColorSampleCounts.push(4);
360 }
361 if (flags & VK_SAMPLE_COUNT_8_BIT) {
362 fColorSampleCounts.push(8);
363 }
364 if (flags & VK_SAMPLE_COUNT_16_BIT) {
365 fColorSampleCounts.push(16);
366 }
367 if (flags & VK_SAMPLE_COUNT_32_BIT) {
368 fColorSampleCounts.push(32);
369 }
370 if (flags & VK_SAMPLE_COUNT_64_BIT) {
371 fColorSampleCounts.push(64);
372 }
373}
374
egdaniel8f1dcaa2016-04-01 10:10:45 -0700375void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface,
376 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000377 const VkPhysicalDeviceProperties& properties,
egdaniel8f1dcaa2016-04-01 10:10:45 -0700378 VkFormat format) {
379 VkFormatProperties props;
380 memset(&props, 0, sizeof(VkFormatProperties));
381 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
382 InitConfigFlags(props.linearTilingFeatures, &fLinearFlags);
383 InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400384 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000385 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400386 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500387}
Greg Daniel81e7bf82017-07-19 14:47:42 -0400388
389int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const {
390 int count = fConfigTable[config].fColorSampleCounts.count();
391 if (!count || !this->isConfigRenderable(config, true)) {
392 return 0;
393 }
394
395 for (int i = 0; i < count; ++i) {
396 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
397 return fConfigTable[config].fColorSampleCounts[i];
398 }
399 }
400 return fConfigTable[config].fColorSampleCounts[count-1];
401}
402
Greg Danielfaa095e2017-12-19 13:15:02 -0500403bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixelConfig* config) {
Greg Danielf5d87582017-12-18 14:48:15 -0500404 if (!imageInfo) {
405 return false;
406 }
407 VkFormat format = imageInfo->fFormat;
Greg Danielfaa095e2017-12-19 13:15:02 -0500408 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500409
410 switch (ct) {
411 case kUnknown_SkColorType:
412 return false;
413 case kAlpha_8_SkColorType:
414 if (VK_FORMAT_R8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500415 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500416 }
417 break;
418 case kRGB_565_SkColorType:
419 if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500420 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500421 }
422 break;
423 case kARGB_4444_SkColorType:
424 if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500425 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500426 }
427 break;
428 case kRGBA_8888_SkColorType:
429 if (VK_FORMAT_R8G8B8A8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500430 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500431 } else if (VK_FORMAT_R8G8B8A8_SRGB == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500432 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500433 }
434 break;
Brian Salomone41e1762018-01-25 14:07:47 -0500435 case kRGB_888x_SkColorType:
436 return false;
Greg Danielf5d87582017-12-18 14:48:15 -0500437 case kBGRA_8888_SkColorType:
438 if (VK_FORMAT_B8G8R8A8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500439 *config = kBGRA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500440 } else if (VK_FORMAT_B8G8R8A8_SRGB == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500441 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500442 }
443 break;
Brian Salomone41e1762018-01-25 14:07:47 -0500444 case kRGBA_1010102_SkColorType:
445 return false;
446 case kRGB_101010x_SkColorType:
447 return false;
Greg Danielf5d87582017-12-18 14:48:15 -0500448 case kGray_8_SkColorType:
449 if (VK_FORMAT_R8_UNORM == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500450 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500451 }
452 break;
453 case kRGBA_F16_SkColorType:
454 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500455 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500456 }
457 break;
458 }
459
Greg Danielfaa095e2017-12-19 13:15:02 -0500460 return kUnknown_GrPixelConfig != *config;
Greg Danielf5d87582017-12-18 14:48:15 -0500461}
462
Greg Danielfaa095e2017-12-19 13:15:02 -0500463bool GrVkCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
464 GrPixelConfig* config) const {
465 return validate_image_info(tex.getVkImageInfo(), ct, config);
466}
467
468bool GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
469 GrPixelConfig* config) const {
470 return validate_image_info(rt.getVkImageInfo(), ct, config);
471}
Greg Danielf5d87582017-12-18 14:48:15 -0500472