blob: 1b0db7fb231d672832dd228e20d71f40ec1217f8 [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"
Robert Phillipsbf25d432017-04-07 10:08:53 -04009#include "GrRenderTargetProxy.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050010#include "GrShaderCaps.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050011#include "GrVkUtil.h"
jvanverthfd7bd452016-03-25 06:29:52 -070012#include "vk/GrVkBackendContext.h"
Brian Salomon467921e2017-03-06 16:17:12 -050013#include "vk/GrVkInterface.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
15GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070016 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags)
17 : INHERITED(contextOptions) {
18 fCanUseGLSLForShaderModule = false;
egdaniel6fa0a912016-09-12 11:51:29 -070019 fMustDoCopiesFromOrigin = false;
egdanielbc9b2962016-09-27 08:00:53 -070020 fSupportsCopiesAsDraws = false;
egdanielfd016d72016-09-27 12:13:05 -070021 fMustSubmitCommandsBeforeCopyOp = false;
Greg Daniel80a08dd2017-01-20 10:45:49 -050022 fMustSleepOnTearDown = false;
Greg Daniele3cd6912017-05-17 11:15:55 -040023 fNewCBOnPipelineChange = false;
egdanielc5ec1402016-03-28 12:14:42 -070024
Greg Daniel164a9f02016-02-22 09:56:40 -050025 /**************************************************************************
26 * GrDrawTargetCaps fields
27 **************************************************************************/
jvanverth62340062016-04-26 08:01:44 -070028 fMipMapSupport = true; // always available in Vulkan
brianosmanf05ab1b2016-05-12 11:01:10 -070029 fSRGBSupport = true; // always available in Vulkan
Brian Osman57bc3ea2017-07-27 09:58:11 -040030 fSRGBDecodeDisableSupport = true; // always available in Vulkan
brianosman88791862016-05-23 10:15:27 -070031 fNPOTTextureTileSupport = true; // always available in Vulkan
egdaniel37535c92016-06-30 08:23:30 -070032 fDiscardRenderTargetSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050033 fReuseScratchTextures = true; //TODO: figure this out
34 fGpuTracingSupport = false; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050035 fOversizedStencilSupport = false; //TODO: figure this out
Chris Dalton1d616352017-05-31 12:51:23 -060036 fInstanceAttribSupport = true;
Greg Daniel164a9f02016-02-22 09:56:40 -050037
egdaniel9cb63402016-06-23 08:37:05 -070038 fUseDrawInsteadOfClear = false;
Chris Daltone4679fa2017-09-29 13:58:26 -060039 fBlacklistCoverageCounting = true; // blacklisting ccpr until we work through a few issues.
jvanverth84741b32016-09-30 08:39:02 -070040 fFenceSyncSupport = true; // always available in Vulkan
Greg Daniela63e7ab2017-05-16 14:38:54 -040041 fCrossContextTextureSupport = false;
Greg Daniel164a9f02016-02-22 09:56:40 -050042
43 fMapBufferFlags = kNone_MapFlags; //TODO: figure this out
cdalton397536c2016-03-25 12:15:03 -070044 fBufferMapThreshold = SK_MaxS32; //TODO: figure this out
Greg Daniel164a9f02016-02-22 09:56:40 -050045
46 fMaxRenderTargetSize = 4096; // minimum required by spec
47 fMaxTextureSize = 4096; // minimum required by spec
48 fMaxColorSampleCount = 4; // minimum required by spec
49 fMaxStencilSampleCount = 4; // minimum required by spec
50
Brian Salomon94efbf52016-11-29 13:43:05 -050051 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Greg Daniel164a9f02016-02-22 09:56:40 -050052
egdanielc5ec1402016-03-28 12:14:42 -070053 this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050054}
55
Robert Phillipsbf25d432017-04-07 10:08:53 -040056bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -070057 bool* rectsMustMatch, bool* disallowSubrect) const {
58 // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false.
59 *rectsMustMatch = false;
60 *disallowSubrect = false;
61
Brian Salomon467921e2017-03-06 16:17:12 -050062 // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa).
63 // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a
64 // render target as well.
65 desc->fOrigin = src->origin();
66 desc->fConfig = src->config();
Robert Phillipsbf25d432017-04-07 10:08:53 -040067 if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) {
Brian Salomon467921e2017-03-06 16:17:12 -050068 desc->fFlags = kRenderTarget_GrSurfaceFlag;
69 } else {
70 // Just going to use CopyImage here
71 desc->fFlags = kNone_GrSurfaceFlags;
72 }
73
74 return true;
75}
76
Greg Daniel164a9f02016-02-22 09:56:40 -050077void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070078 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) {
Greg Daniel164a9f02016-02-22 09:56:40 -050079
egdanield5e3b9e2016-03-08 12:19:54 -080080 VkPhysicalDeviceProperties properties;
81 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties));
82
egdanield5e3b9e2016-03-08 12:19:54 -080083 VkPhysicalDeviceMemoryProperties memoryProperties;
84 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties));
85
jvanverthfd7bd452016-03-25 06:29:52 -070086 this->initGrCaps(properties, memoryProperties, featureFlags);
Brian Salomon1edc5b92016-11-29 13:43:46 -050087 this->initShaderCaps(properties, featureFlags);
Greg Daniel2bb6ecc2017-07-20 13:11:14 +000088 this->initConfigTable(vkInterface, physDev, properties);
egdaniel8f1dcaa2016-04-01 10:10:45 -070089 this->initStencilFormat(vkInterface, physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -050090
egdanielc5ec1402016-03-28 12:14:42 -070091 if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) {
egdanield632bb42016-03-30 12:06:48 -070092 // Currently disabling this feature since it does not play well with validation layers which
93 // expect a SPIR-V shader
94 // fCanUseGLSLForShaderModule = true;
egdanielc5ec1402016-03-28 12:14:42 -070095 }
Greg Daniel164a9f02016-02-22 09:56:40 -050096
egdaniel6fa0a912016-09-12 11:51:29 -070097 if (kQualcomm_VkVendor == properties.vendorID) {
98 fMustDoCopiesFromOrigin = true;
99 }
100
egdanielfd016d72016-09-27 12:13:05 -0700101 if (kNvidia_VkVendor == properties.vendorID) {
egdanielfd016d72016-09-27 12:13:05 -0700102 fMustSubmitCommandsBeforeCopyOp = true;
103 }
104
Greg Daniel1cdbdda2017-05-16 14:52:57 -0400105 if (kQualcomm_VkVendor != properties.vendorID) {
106 fSupportsCopiesAsDraws = true;
107 }
108
Greg Daniela63e7ab2017-05-16 14:38:54 -0400109 if (fSupportsCopiesAsDraws) {
110 fCrossContextTextureSupport = true;
111 }
112
Greg Daniel80a08dd2017-01-20 10:45:49 -0500113#if defined(SK_BUILD_FOR_WIN)
114 if (kNvidia_VkVendor == properties.vendorID) {
115 fMustSleepOnTearDown = true;
116 }
117#elif defined(SK_BUILD_FOR_ANDROID)
118 if (kImagination_VkVendor == properties.vendorID) {
119 fMustSleepOnTearDown = true;
120 }
121#endif
122
Greg Daniel164a9f02016-02-22 09:56:40 -0500123 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500124 fShaderCaps->applyOptionsOverrides(contextOptions);
Greg Daniel164a9f02016-02-22 09:56:40 -0500125}
126
127int get_max_sample_count(VkSampleCountFlags flags) {
128 SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT);
129 if (!(flags & VK_SAMPLE_COUNT_2_BIT)) {
130 return 0;
131 }
132 if (!(flags & VK_SAMPLE_COUNT_4_BIT)) {
133 return 2;
134 }
135 if (!(flags & VK_SAMPLE_COUNT_8_BIT)) {
136 return 4;
137 }
138 if (!(flags & VK_SAMPLE_COUNT_16_BIT)) {
139 return 8;
140 }
141 if (!(flags & VK_SAMPLE_COUNT_32_BIT)) {
142 return 16;
143 }
144 if (!(flags & VK_SAMPLE_COUNT_64_BIT)) {
145 return 32;
146 }
147 return 64;
148}
149
150void GrVkCaps::initSampleCount(const VkPhysicalDeviceProperties& properties) {
151 VkSampleCountFlags colorSamples = properties.limits.framebufferColorSampleCounts;
152 VkSampleCountFlags stencilSamples = properties.limits.framebufferStencilSampleCounts;
153
154 fMaxColorSampleCount = get_max_sample_count(colorSamples);
Greg Daniel1e9ddcc2017-04-19 13:01:22 -0400155 if (kImagination_VkVendor == properties.vendorID) {
156 fMaxColorSampleCount = 0;
157 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500158 fMaxStencilSampleCount = get_max_sample_count(stencilSamples);
159}
160
egdanield5e3b9e2016-03-08 12:19:54 -0800161void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties,
jvanverthfd7bd452016-03-25 06:29:52 -0700162 const VkPhysicalDeviceMemoryProperties& memoryProperties,
163 uint32_t featureFlags) {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400164 // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no
165 // need for us ever to support that amount, and it makes tests which tests all the vertex
166 // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if
167 // we ever find that need.
168 static const uint32_t kMaxVertexAttributes = 64;
169 fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes);
170 // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32.
171 if (kAMD_VkVendor == properties.vendorID) {
172 fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32);
173 }
174
egdanield5e3b9e2016-03-08 12:19:54 -0800175 // We could actually query and get a max size for each config, however maxImageDimension2D will
176 // give the minimum max size across all configs. So for simplicity we will use that for now.
jvanverthe78d4872016-09-27 03:33:05 -0700177 fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
178 fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
egdanield5e3b9e2016-03-08 12:19:54 -0800179
180 this->initSampleCount(properties);
181
egdanield5e3b9e2016-03-08 12:19:54 -0800182 // Assuming since we will always map in the end to upload the data we might as well just map
183 // from the get go. There is no hard data to suggest this is faster or slower.
cdalton397536c2016-03-25 12:15:03 -0700184 fBufferMapThreshold = 0;
egdanield5e3b9e2016-03-08 12:19:54 -0800185
186 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
187
egdanield5e3b9e2016-03-08 12:19:54 -0800188 fOversizedStencilSupport = true;
ethannicholas28ef4452016-03-25 09:26:03 -0700189 fSampleShadingSupport = SkToBool(featureFlags & kSampleRateShading_GrVkFeatureFlag);
Greg Daniel22bc8652017-03-22 15:45:43 -0400190
191 // AMD seems to have issues binding new VkPipelines inside a secondary command buffer.
192 // Current workaround is to use a different secondary command buffer for each new VkPipeline.
193 if (kAMD_VkVendor == properties.vendorID) {
Greg Daniele3cd6912017-05-17 11:15:55 -0400194 fNewCBOnPipelineChange = true;
Greg Daniel22bc8652017-03-22 15:45:43 -0400195 }
Greg Daniel01907872017-05-23 15:21:02 -0400196
197#if defined(SK_CPU_X86)
198 if (kImagination_VkVendor == properties.vendorID) {
199 fSRGBSupport = false;
200 }
201#endif
egdanield5e3b9e2016-03-08 12:19:54 -0800202}
203
Brian Salomon1edc5b92016-11-29 13:43:46 -0500204void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint32_t featureFlags) {
205 GrShaderCaps* shaderCaps = fShaderCaps.get();
206 shaderCaps->fVersionDeclString = "#version 330\n";
egdaniel3a15fd42016-04-05 11:00:29 -0700207
Greg Daniel164a9f02016-02-22 09:56:40 -0500208
209 // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config.
210 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
211 GrPixelConfig config = static_cast<GrPixelConfig>(i);
212 if (GrPixelConfigIsAlphaOnly(config)) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500213 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR();
214 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
Greg Daniel164a9f02016-02-22 09:56:40 -0500215 } else {
Brian Osman986563b2017-01-10 14:20:02 -0500216 if (kGray_8_GrPixelConfig == config) {
217 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA();
218 } else if (kRGBA_4444_GrPixelConfig == config) {
egdaniel3fe03272016-08-15 10:59:17 -0700219 // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we
220 // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads
221 // or writing to outputs. Since we're not actually changing the data at all, the
222 // only extra work is the swizzle in the shader for all operations.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500223 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA();
224 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA();
egdaniel3fe03272016-08-15 10:59:17 -0700225 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500226 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA();
egdaniel3fe03272016-08-15 10:59:17 -0700227 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500228 }
229 }
egdaniel67acb832016-02-26 08:32:20 -0800230
Greg Daniel80a08dd2017-01-20 10:45:49 -0500231 if (kImagination_VkVendor == properties.vendorID) {
232 shaderCaps->fAtan2ImplementedAsAtanYOverX = true;
233 }
234
egdanield5e3b9e2016-03-08 12:19:54 -0800235 // Vulkan is based off ES 3.0 so the following should all be supported
Brian Salomon1edc5b92016-11-29 13:43:46 -0500236 shaderCaps->fUsesPrecisionModifiers = true;
237 shaderCaps->fFlatInterpolationSupport = true;
Brian Salomon41274562017-09-15 09:40:03 -0700238 // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed
239 // to be true with Vulkan as well.
240 shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID;
egdanield5e3b9e2016-03-08 12:19:54 -0800241
242 // GrShaderCaps
243
Brian Salomon1edc5b92016-11-29 13:43:46 -0500244 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600245
Brian Salomon1edc5b92016-11-29 13:43:46 -0500246 shaderCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag);
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600247 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
egdanield632bb42016-03-30 12:06:48 -0700248
Brian Salomon1edc5b92016-11-29 13:43:46 -0500249 shaderCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag);
Greg Daniel84cff132017-03-22 16:25:53 -0400250 if (kAMD_VkVendor == properties.vendorID) {
251 // Currently DualSourceBlending is not working on AMD. vkCreateGraphicsPipeline fails when
252 // using a draw with dual source. Looking into whether it is driver bug or issue with our
253 // SPIR-V. Bug skia:6405
254 shaderCaps->fDualSourceBlendingSupport = false;
255 }
egdanield632bb42016-03-30 12:06:48 -0700256
Brian Salomon1edc5b92016-11-29 13:43:46 -0500257 shaderCaps->fIntegerSupport = true;
Chris Dalton6b65b982017-07-06 11:04:00 -0600258 shaderCaps->fTexelBufferSupport = true;
259 shaderCaps->fTexelFetchSupport = true;
Chris Dalton1d616352017-05-31 12:51:23 -0600260 shaderCaps->fVertexIDSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800261
cdaltona6b92ad2016-04-11 12:03:08 -0700262 // Assume the minimum precisions mandated by the SPIR-V spec.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500263 shaderCaps->fShaderPrecisionVaries = true;
cdaltona6b92ad2016-04-11 12:03:08 -0700264 for (int s = 0; s < kGrShaderTypeCount; ++s) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500265 auto& highp = shaderCaps->fFloatPrecisions[s][kHigh_GrSLPrecision];
cdaltona6b92ad2016-04-11 12:03:08 -0700266 highp.fLogRangeLow = highp.fLogRangeHigh = 127;
267 highp.fBits = 23;
268
Brian Salomon1edc5b92016-11-29 13:43:46 -0500269 auto& mediump = shaderCaps->fFloatPrecisions[s][kMedium_GrSLPrecision];
cdaltona6b92ad2016-04-11 12:03:08 -0700270 mediump.fLogRangeLow = mediump.fLogRangeHigh = 14;
271 mediump.fBits = 10;
272
Brian Salomon1edc5b92016-11-29 13:43:46 -0500273 shaderCaps->fFloatPrecisions[s][kLow_GrSLPrecision] = mediump;
cdaltona6b92ad2016-04-11 12:03:08 -0700274 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500275 shaderCaps->initSamplerPrecisionTable();
cdaltona6b92ad2016-04-11 12:03:08 -0700276
Brian Salomon1edc5b92016-11-29 13:43:46 -0500277 shaderCaps->fMaxVertexSamplers =
278 shaderCaps->fMaxGeometrySamplers =
279 shaderCaps->fMaxFragmentSamplers = SkTMin(
280 SkTMin(properties.limits.maxPerStageDescriptorSampledImages,
281 properties.limits.maxPerStageDescriptorSamplers),
282 (uint32_t)INT_MAX);
283 shaderCaps->fMaxCombinedSamplers = SkTMin(
284 SkTMin(properties.limits.maxDescriptorSetSampledImages,
285 properties.limits.maxDescriptorSetSamplers),
286 (uint32_t)INT_MAX);
Greg Daniel164a9f02016-02-22 09:56:40 -0500287}
288
egdaniel8f1dcaa2016-04-01 10:10:45 -0700289bool stencil_format_supported(const GrVkInterface* interface,
290 VkPhysicalDevice physDev,
291 VkFormat format) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500292 VkFormatProperties props;
293 memset(&props, 0, sizeof(VkFormatProperties));
294 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
egdaniel8f1dcaa2016-04-01 10:10:45 -0700295 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures);
Greg Daniel164a9f02016-02-22 09:56:40 -0500296}
297
egdaniel8f1dcaa2016-04-01 10:10:45 -0700298void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) {
299 // List of legal stencil formats (though perhaps not supported on
300 // the particular gpu/driver) from most preferred to least. We are guaranteed to have either
jvanvertha4b0fed2016-04-27 11:42:21 -0700301 // 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 -0700302 // can optionally have 24 unused bits at the end so we assume the total bits is 64.
Greg Daniel164a9f02016-02-22 09:56:40 -0500303 static const StencilFormat
304 // internal Format stencil bits total bits packed?
305 gS8 = { VK_FORMAT_S8_UINT, 8, 8, false },
egdaniel8f1dcaa2016-04-01 10:10:45 -0700306 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true },
307 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true };
Greg Daniel164a9f02016-02-22 09:56:40 -0500308
egdaniel8f1dcaa2016-04-01 10:10:45 -0700309 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) {
310 fPreferedStencilFormat = gS8;
311 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) {
312 fPreferedStencilFormat = gD24S8;
313 } else {
314 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT));
315 fPreferedStencilFormat = gD32S8;
316 }
317}
318
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000319void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
320 const VkPhysicalDeviceProperties& properties) {
egdaniel8f1dcaa2016-04-01 10:10:45 -0700321 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
322 VkFormat format;
323 if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) {
Greg Daniel01907872017-05-23 15:21:02 -0400324 if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000325 fConfigTable[i].init(interface, physDev, properties, format);
Greg Daniel01907872017-05-23 15:21:02 -0400326 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700327 }
328 }
329}
330
331void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
332 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
333 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
334 *flags = *flags | kTextureable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700335
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400336 // Ganesh assumes that all renderable surfaces are also texturable
337 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
338 *flags = *flags | kRenderable_Flag;
339 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700340 }
341
342 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
343 *flags = *flags | kBlitSrc_Flag;
344 }
345
346 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
347 *flags = *flags | kBlitDst_Flag;
348 }
349}
350
Greg Daniel81e7bf82017-07-19 14:47:42 -0400351void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface,
352 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000353 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400354 VkFormat format) {
355 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
356 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
357 VK_IMAGE_USAGE_SAMPLED_BIT |
358 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
359 VkImageCreateFlags createFlags = GrVkFormatIsSRGB(format, nullptr)
360 ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0;
361 VkImageFormatProperties properties;
362 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
363 format,
364 VK_IMAGE_TYPE_2D,
365 VK_IMAGE_TILING_OPTIMAL,
366 usage,
367 createFlags,
368 &properties));
369 VkSampleCountFlags flags = properties.sampleCounts;
370 if (flags & VK_SAMPLE_COUNT_1_BIT) {
371 fColorSampleCounts.push(0);
372 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000373 if (kImagination_VkVendor == physProps.vendorID) {
374 // MSAA does not work on imagination
375 return;
376 }
Greg Daniel81e7bf82017-07-19 14:47:42 -0400377 if (flags & VK_SAMPLE_COUNT_2_BIT) {
378 fColorSampleCounts.push(2);
379 }
380 if (flags & VK_SAMPLE_COUNT_4_BIT) {
381 fColorSampleCounts.push(4);
382 }
383 if (flags & VK_SAMPLE_COUNT_8_BIT) {
384 fColorSampleCounts.push(8);
385 }
386 if (flags & VK_SAMPLE_COUNT_16_BIT) {
387 fColorSampleCounts.push(16);
388 }
389 if (flags & VK_SAMPLE_COUNT_32_BIT) {
390 fColorSampleCounts.push(32);
391 }
392 if (flags & VK_SAMPLE_COUNT_64_BIT) {
393 fColorSampleCounts.push(64);
394 }
395}
396
egdaniel8f1dcaa2016-04-01 10:10:45 -0700397void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface,
398 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000399 const VkPhysicalDeviceProperties& properties,
egdaniel8f1dcaa2016-04-01 10:10:45 -0700400 VkFormat format) {
401 VkFormatProperties props;
402 memset(&props, 0, sizeof(VkFormatProperties));
403 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
404 InitConfigFlags(props.linearTilingFeatures, &fLinearFlags);
405 InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400406 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000407 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400408 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500409}
Greg Daniel81e7bf82017-07-19 14:47:42 -0400410
411int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const {
412 int count = fConfigTable[config].fColorSampleCounts.count();
413 if (!count || !this->isConfigRenderable(config, true)) {
414 return 0;
415 }
416
417 for (int i = 0; i < count; ++i) {
418 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
419 return fConfigTable[config].fColorSampleCounts[i];
420 }
421 }
422 return fConfigTable[config].fColorSampleCounts[count-1];
423}
424