blob: e6a018b2ba81f605ad79e974b9c592767525d3a2 [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
49 fMaxColorSampleCount = 4; // minimum required by spec
50 fMaxStencilSampleCount = 4; // minimum required by spec
51
Brian Salomon94efbf52016-11-29 13:43:05 -050052 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Greg Daniel164a9f02016-02-22 09:56:40 -050053
egdanielc5ec1402016-03-28 12:14:42 -070054 this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050055}
56
Robert Phillipsbf25d432017-04-07 10:08:53 -040057bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -070058 bool* rectsMustMatch, bool* disallowSubrect) const {
59 // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false.
60 *rectsMustMatch = false;
61 *disallowSubrect = false;
62
Brian Salomon467921e2017-03-06 16:17:12 -050063 // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa).
64 // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a
65 // render target as well.
66 desc->fOrigin = src->origin();
67 desc->fConfig = src->config();
Robert Phillipsbf25d432017-04-07 10:08:53 -040068 if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) {
Brian Salomon467921e2017-03-06 16:17:12 -050069 desc->fFlags = kRenderTarget_GrSurfaceFlag;
70 } else {
71 // Just going to use CopyImage here
72 desc->fFlags = kNone_GrSurfaceFlags;
73 }
74
75 return true;
76}
77
Greg Daniel164a9f02016-02-22 09:56:40 -050078void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070079 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) {
Greg Daniel164a9f02016-02-22 09:56:40 -050080
Jim Van Verth6a40abc2017-11-02 16:56:09 +000081 VkPhysicalDeviceProperties properties;
82 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties));
egdanield5e3b9e2016-03-08 12:19:54 -080083
egdanield5e3b9e2016-03-08 12:19:54 -080084 VkPhysicalDeviceMemoryProperties memoryProperties;
85 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties));
86
jvanverthfd7bd452016-03-25 06:29:52 -070087 this->initGrCaps(properties, memoryProperties, featureFlags);
Brian Salomon1edc5b92016-11-29 13:43:46 -050088 this->initShaderCaps(properties, featureFlags);
Greg Daniel2bb6ecc2017-07-20 13:11:14 +000089 this->initConfigTable(vkInterface, physDev, properties);
egdaniel8f1dcaa2016-04-01 10:10:45 -070090 this->initStencilFormat(vkInterface, physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -050091
egdanielc5ec1402016-03-28 12:14:42 -070092 if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) {
egdanield632bb42016-03-30 12:06:48 -070093 // Currently disabling this feature since it does not play well with validation layers which
94 // expect a SPIR-V shader
95 // fCanUseGLSLForShaderModule = true;
egdanielc5ec1402016-03-28 12:14:42 -070096 }
Greg Daniel164a9f02016-02-22 09:56:40 -050097
egdaniel6fa0a912016-09-12 11:51:29 -070098 if (kQualcomm_VkVendor == properties.vendorID) {
99 fMustDoCopiesFromOrigin = true;
100 }
101
egdanielfd016d72016-09-27 12:13:05 -0700102 if (kNvidia_VkVendor == properties.vendorID) {
egdanielfd016d72016-09-27 12:13:05 -0700103 fMustSubmitCommandsBeforeCopyOp = true;
104 }
105
Greg Daniel1cdbdda2017-05-16 14:52:57 -0400106 if (kQualcomm_VkVendor != properties.vendorID) {
107 fSupportsCopiesAsDraws = true;
108 }
109
Greg Daniela63e7ab2017-05-16 14:38:54 -0400110 if (fSupportsCopiesAsDraws) {
111 fCrossContextTextureSupport = true;
112 }
113
Greg Daniel80a08dd2017-01-20 10:45:49 -0500114#if defined(SK_BUILD_FOR_WIN)
115 if (kNvidia_VkVendor == properties.vendorID) {
116 fMustSleepOnTearDown = true;
117 }
118#elif defined(SK_BUILD_FOR_ANDROID)
119 if (kImagination_VkVendor == properties.vendorID) {
120 fMustSleepOnTearDown = true;
121 }
122#endif
123
Greg Daniel164a9f02016-02-22 09:56:40 -0500124 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500125 fShaderCaps->applyOptionsOverrides(contextOptions);
Greg Daniel164a9f02016-02-22 09:56:40 -0500126}
127
128int get_max_sample_count(VkSampleCountFlags flags) {
129 SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT);
130 if (!(flags & VK_SAMPLE_COUNT_2_BIT)) {
131 return 0;
132 }
133 if (!(flags & VK_SAMPLE_COUNT_4_BIT)) {
134 return 2;
135 }
136 if (!(flags & VK_SAMPLE_COUNT_8_BIT)) {
137 return 4;
138 }
139 if (!(flags & VK_SAMPLE_COUNT_16_BIT)) {
140 return 8;
141 }
142 if (!(flags & VK_SAMPLE_COUNT_32_BIT)) {
143 return 16;
144 }
145 if (!(flags & VK_SAMPLE_COUNT_64_BIT)) {
146 return 32;
147 }
148 return 64;
149}
150
151void GrVkCaps::initSampleCount(const VkPhysicalDeviceProperties& properties) {
152 VkSampleCountFlags colorSamples = properties.limits.framebufferColorSampleCounts;
153 VkSampleCountFlags stencilSamples = properties.limits.framebufferStencilSampleCounts;
154
155 fMaxColorSampleCount = get_max_sample_count(colorSamples);
Greg Daniel1e9ddcc2017-04-19 13:01:22 -0400156 if (kImagination_VkVendor == properties.vendorID) {
157 fMaxColorSampleCount = 0;
158 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500159 fMaxStencilSampleCount = get_max_sample_count(stencilSamples);
160}
161
egdanield5e3b9e2016-03-08 12:19:54 -0800162void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties,
jvanverthfd7bd452016-03-25 06:29:52 -0700163 const VkPhysicalDeviceMemoryProperties& memoryProperties,
164 uint32_t featureFlags) {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400165 // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no
166 // need for us ever to support that amount, and it makes tests which tests all the vertex
167 // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if
168 // we ever find that need.
169 static const uint32_t kMaxVertexAttributes = 64;
170 fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes);
171 // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32.
172 if (kAMD_VkVendor == properties.vendorID) {
173 fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32);
174 }
175
egdanield5e3b9e2016-03-08 12:19:54 -0800176 // We could actually query and get a max size for each config, however maxImageDimension2D will
177 // give the minimum max size across all configs. So for simplicity we will use that for now.
jvanverthe78d4872016-09-27 03:33:05 -0700178 fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
179 fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX);
egdanield5e3b9e2016-03-08 12:19:54 -0800180
181 this->initSampleCount(properties);
182
egdanield5e3b9e2016-03-08 12:19:54 -0800183 // Assuming since we will always map in the end to upload the data we might as well just map
184 // from the get go. There is no hard data to suggest this is faster or slower.
cdalton397536c2016-03-25 12:15:03 -0700185 fBufferMapThreshold = 0;
egdanield5e3b9e2016-03-08 12:19:54 -0800186
187 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
188
egdanield5e3b9e2016-03-08 12:19:54 -0800189 fOversizedStencilSupport = true;
ethannicholas28ef4452016-03-25 09:26:03 -0700190 fSampleShadingSupport = SkToBool(featureFlags & kSampleRateShading_GrVkFeatureFlag);
Greg Daniel22bc8652017-03-22 15:45:43 -0400191
192 // AMD seems to have issues binding new VkPipelines inside a secondary command buffer.
193 // Current workaround is to use a different secondary command buffer for each new VkPipeline.
194 if (kAMD_VkVendor == properties.vendorID) {
Greg Daniele3cd6912017-05-17 11:15:55 -0400195 fNewCBOnPipelineChange = true;
Greg Daniel22bc8652017-03-22 15:45:43 -0400196 }
Greg Daniel01907872017-05-23 15:21:02 -0400197
198#if defined(SK_CPU_X86)
199 if (kImagination_VkVendor == properties.vendorID) {
200 fSRGBSupport = false;
201 }
202#endif
egdanield5e3b9e2016-03-08 12:19:54 -0800203}
204
Brian Salomon1edc5b92016-11-29 13:43:46 -0500205void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint32_t featureFlags) {
206 GrShaderCaps* shaderCaps = fShaderCaps.get();
207 shaderCaps->fVersionDeclString = "#version 330\n";
egdaniel3a15fd42016-04-05 11:00:29 -0700208
Greg Daniel164a9f02016-02-22 09:56:40 -0500209
210 // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config.
211 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
212 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Greg Danielef59d872017-11-17 16:47:21 -0500213 // Vulkan doesn't support a single channel format stored in alpha.
214 if (GrPixelConfigIsAlphaOnly(config) &&
215 kAlpha_8_as_Alpha_GrPixelConfig != config) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500216 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR();
217 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
Greg Daniel164a9f02016-02-22 09:56:40 -0500218 } else {
Greg Daniel7af060a2017-12-05 16:27:11 -0500219 if (kGray_8_GrPixelConfig == config ||
220 kGray_8_as_Red_GrPixelConfig == config) {
Brian Osman986563b2017-01-10 14:20:02 -0500221 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA();
222 } else if (kRGBA_4444_GrPixelConfig == config) {
egdaniel3fe03272016-08-15 10:59:17 -0700223 // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we
224 // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads
225 // or writing to outputs. Since we're not actually changing the data at all, the
226 // only extra work is the swizzle in the shader for all operations.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500227 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA();
228 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA();
egdaniel3fe03272016-08-15 10:59:17 -0700229 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500230 shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA();
egdaniel3fe03272016-08-15 10:59:17 -0700231 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500232 }
233 }
egdaniel67acb832016-02-26 08:32:20 -0800234
Greg Daniel80a08dd2017-01-20 10:45:49 -0500235 if (kImagination_VkVendor == properties.vendorID) {
236 shaderCaps->fAtan2ImplementedAsAtanYOverX = true;
237 }
238
egdanield5e3b9e2016-03-08 12:19:54 -0800239 // Vulkan is based off ES 3.0 so the following should all be supported
Brian Salomon1edc5b92016-11-29 13:43:46 -0500240 shaderCaps->fUsesPrecisionModifiers = true;
241 shaderCaps->fFlatInterpolationSupport = true;
Brian Salomon41274562017-09-15 09:40:03 -0700242 // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed
243 // to be true with Vulkan as well.
244 shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID;
egdanield5e3b9e2016-03-08 12:19:54 -0800245
246 // GrShaderCaps
247
Brian Salomon1edc5b92016-11-29 13:43:46 -0500248 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600249
Brian Salomon1edc5b92016-11-29 13:43:46 -0500250 shaderCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag);
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600251 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
egdanield632bb42016-03-30 12:06:48 -0700252
Brian Salomon1edc5b92016-11-29 13:43:46 -0500253 shaderCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag);
Greg Daniel84cff132017-03-22 16:25:53 -0400254 if (kAMD_VkVendor == properties.vendorID) {
255 // Currently DualSourceBlending is not working on AMD. vkCreateGraphicsPipeline fails when
256 // using a draw with dual source. Looking into whether it is driver bug or issue with our
257 // SPIR-V. Bug skia:6405
258 shaderCaps->fDualSourceBlendingSupport = false;
259 }
egdanield632bb42016-03-30 12:06:48 -0700260
Brian Salomon1edc5b92016-11-29 13:43:46 -0500261 shaderCaps->fIntegerSupport = true;
Chris Dalton6b65b982017-07-06 11:04:00 -0600262 shaderCaps->fTexelBufferSupport = true;
263 shaderCaps->fTexelFetchSupport = true;
Chris Dalton1d616352017-05-31 12:51:23 -0600264 shaderCaps->fVertexIDSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800265
cdaltona6b92ad2016-04-11 12:03:08 -0700266 // Assume the minimum precisions mandated by the SPIR-V spec.
Chris Dalton47c8ed32017-11-15 18:27:09 -0700267 shaderCaps->fFloatIs32Bits = true;
268 shaderCaps->fHalfIs32Bits = false;
cdaltona6b92ad2016-04-11 12:03:08 -0700269
Brian Salomon1edc5b92016-11-29 13:43:46 -0500270 shaderCaps->fMaxVertexSamplers =
271 shaderCaps->fMaxGeometrySamplers =
272 shaderCaps->fMaxFragmentSamplers = SkTMin(
273 SkTMin(properties.limits.maxPerStageDescriptorSampledImages,
274 properties.limits.maxPerStageDescriptorSamplers),
275 (uint32_t)INT_MAX);
276 shaderCaps->fMaxCombinedSamplers = SkTMin(
277 SkTMin(properties.limits.maxDescriptorSetSampledImages,
278 properties.limits.maxDescriptorSetSamplers),
279 (uint32_t)INT_MAX);
Greg Daniel164a9f02016-02-22 09:56:40 -0500280}
281
egdaniel8f1dcaa2016-04-01 10:10:45 -0700282bool stencil_format_supported(const GrVkInterface* interface,
283 VkPhysicalDevice physDev,
284 VkFormat format) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500285 VkFormatProperties props;
286 memset(&props, 0, sizeof(VkFormatProperties));
287 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
egdaniel8f1dcaa2016-04-01 10:10:45 -0700288 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures);
Greg Daniel164a9f02016-02-22 09:56:40 -0500289}
290
egdaniel8f1dcaa2016-04-01 10:10:45 -0700291void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) {
292 // List of legal stencil formats (though perhaps not supported on
293 // the particular gpu/driver) from most preferred to least. We are guaranteed to have either
jvanvertha4b0fed2016-04-27 11:42:21 -0700294 // 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 -0700295 // can optionally have 24 unused bits at the end so we assume the total bits is 64.
Greg Daniel164a9f02016-02-22 09:56:40 -0500296 static const StencilFormat
297 // internal Format stencil bits total bits packed?
298 gS8 = { VK_FORMAT_S8_UINT, 8, 8, false },
egdaniel8f1dcaa2016-04-01 10:10:45 -0700299 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true },
300 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true };
Greg Daniel164a9f02016-02-22 09:56:40 -0500301
egdaniel8f1dcaa2016-04-01 10:10:45 -0700302 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) {
303 fPreferedStencilFormat = gS8;
304 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) {
305 fPreferedStencilFormat = gD24S8;
306 } else {
307 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT));
308 fPreferedStencilFormat = gD32S8;
309 }
310}
311
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000312void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev,
313 const VkPhysicalDeviceProperties& properties) {
egdaniel8f1dcaa2016-04-01 10:10:45 -0700314 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
315 VkFormat format;
316 if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) {
Greg Daniel01907872017-05-23 15:21:02 -0400317 if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000318 fConfigTable[i].init(interface, physDev, properties, format);
Greg Daniel01907872017-05-23 15:21:02 -0400319 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700320 }
321 }
322}
323
324void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
325 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) &&
326 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) {
327 *flags = *flags | kTextureable_Flag;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700328
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400329 // Ganesh assumes that all renderable surfaces are also texturable
330 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) {
331 *flags = *flags | kRenderable_Flag;
332 }
egdaniel8f1dcaa2016-04-01 10:10:45 -0700333 }
334
335 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) {
336 *flags = *flags | kBlitSrc_Flag;
337 }
338
339 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) {
340 *flags = *flags | kBlitDst_Flag;
341 }
342}
343
Greg Daniel81e7bf82017-07-19 14:47:42 -0400344void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface,
345 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000346 const VkPhysicalDeviceProperties& physProps,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400347 VkFormat format) {
348 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
349 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
350 VK_IMAGE_USAGE_SAMPLED_BIT |
351 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
352 VkImageCreateFlags createFlags = GrVkFormatIsSRGB(format, nullptr)
353 ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0;
354 VkImageFormatProperties properties;
355 GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev,
356 format,
357 VK_IMAGE_TYPE_2D,
358 VK_IMAGE_TILING_OPTIMAL,
359 usage,
360 createFlags,
361 &properties));
362 VkSampleCountFlags flags = properties.sampleCounts;
363 if (flags & VK_SAMPLE_COUNT_1_BIT) {
364 fColorSampleCounts.push(0);
365 }
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000366 if (kImagination_VkVendor == physProps.vendorID) {
367 // MSAA does not work on imagination
368 return;
369 }
Greg Daniel81e7bf82017-07-19 14:47:42 -0400370 if (flags & VK_SAMPLE_COUNT_2_BIT) {
371 fColorSampleCounts.push(2);
372 }
373 if (flags & VK_SAMPLE_COUNT_4_BIT) {
374 fColorSampleCounts.push(4);
375 }
376 if (flags & VK_SAMPLE_COUNT_8_BIT) {
377 fColorSampleCounts.push(8);
378 }
379 if (flags & VK_SAMPLE_COUNT_16_BIT) {
380 fColorSampleCounts.push(16);
381 }
382 if (flags & VK_SAMPLE_COUNT_32_BIT) {
383 fColorSampleCounts.push(32);
384 }
385 if (flags & VK_SAMPLE_COUNT_64_BIT) {
386 fColorSampleCounts.push(64);
387 }
388}
389
egdaniel8f1dcaa2016-04-01 10:10:45 -0700390void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface,
391 VkPhysicalDevice physDev,
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000392 const VkPhysicalDeviceProperties& properties,
egdaniel8f1dcaa2016-04-01 10:10:45 -0700393 VkFormat format) {
394 VkFormatProperties props;
395 memset(&props, 0, sizeof(VkFormatProperties));
396 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props));
397 InitConfigFlags(props.linearTilingFeatures, &fLinearFlags);
398 InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400399 if (fOptimalFlags & kRenderable_Flag) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000400 this->initSampleCounts(interface, physDev, properties, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400401 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500402}
Greg Daniel81e7bf82017-07-19 14:47:42 -0400403
404int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const {
405 int count = fConfigTable[config].fColorSampleCounts.count();
406 if (!count || !this->isConfigRenderable(config, true)) {
407 return 0;
408 }
409
410 for (int i = 0; i < count; ++i) {
411 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
412 return fConfigTable[config].fColorSampleCounts[i];
413 }
414 }
415 return fConfigTable[config].fColorSampleCounts[count-1];
416}
417
Greg Danielf5d87582017-12-18 14:48:15 -0500418bool GrVkCaps::onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
419 const GrVkImageInfo* imageInfo = tex->getVkImageInfo();
420 if (!imageInfo) {
421 return false;
422 }
423 VkFormat format = imageInfo->fFormat;
424 tex->fConfig = kUnknown_GrPixelConfig;
425
426 switch (ct) {
427 case kUnknown_SkColorType:
428 return false;
429 case kAlpha_8_SkColorType:
430 if (VK_FORMAT_R8_UNORM == format) {
431 tex->fConfig = kAlpha_8_as_Red_GrPixelConfig;
432 }
433 break;
434 case kRGB_565_SkColorType:
435 if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
436 tex->fConfig = kRGB_565_GrPixelConfig;
437 }
438 break;
439 case kARGB_4444_SkColorType:
440 if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) {
441 tex->fConfig = kRGBA_4444_GrPixelConfig;
442 }
443 break;
444 case kRGBA_8888_SkColorType:
445 if (VK_FORMAT_R8G8B8A8_UNORM == format) {
446 tex->fConfig = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500447 } else if (VK_FORMAT_R8G8B8A8_SRGB == format) {
448 tex->fConfig = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500449 }
450 break;
451 case kBGRA_8888_SkColorType:
452 if (VK_FORMAT_B8G8R8A8_UNORM == format) {
453 tex->fConfig = kBGRA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -0500454 } else if (VK_FORMAT_B8G8R8A8_SRGB == format) {
455 tex->fConfig = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -0500456 }
457 break;
458 case kGray_8_SkColorType:
459 if (VK_FORMAT_R8_UNORM == format) {
460 tex->fConfig = kGray_8_as_Red_GrPixelConfig;
461 }
462 break;
463 case kRGBA_F16_SkColorType:
464 if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
465 tex->fConfig = kRGBA_half_GrPixelConfig;
466 }
467 break;
468 }
469
470 return kUnknown_GrPixelConfig != tex->fConfig;
471}
472
473