Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 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 Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 9 | #include "GrRenderTargetProxy.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 10 | #include "GrShaderCaps.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 11 | #include "GrVkUtil.h" |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 12 | #include "vk/GrVkBackendContext.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 13 | #include "vk/GrVkInterface.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
| 15 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 16 | VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) |
| 17 | : INHERITED(contextOptions) { |
| 18 | fCanUseGLSLForShaderModule = false; |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 19 | fMustDoCopiesFromOrigin = false; |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 20 | fSupportsCopiesAsDraws = false; |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 21 | fMustSubmitCommandsBeforeCopyOp = false; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 22 | fMustSleepOnTearDown = false; |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 23 | fNewCBOnPipelineChange = false; |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 24 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | /************************************************************************** |
| 26 | * GrDrawTargetCaps fields |
| 27 | **************************************************************************/ |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 28 | fMipMapSupport = true; // always available in Vulkan |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 29 | fSRGBSupport = true; // always available in Vulkan |
Brian Osman | 57bc3ea | 2017-07-27 09:58:11 -0400 | [diff] [blame] | 30 | fSRGBDecodeDisableSupport = true; // always available in Vulkan |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 31 | fNPOTTextureTileSupport = true; // always available in Vulkan |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 32 | fDiscardRenderTargetSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | fReuseScratchTextures = true; //TODO: figure this out |
| 34 | fGpuTracingSupport = false; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | fOversizedStencilSupport = false; //TODO: figure this out |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 36 | fInstanceAttribSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | |
Chris Dalton | e4679fa | 2017-09-29 13:58:26 -0600 | [diff] [blame] | 38 | fBlacklistCoverageCounting = true; // blacklisting ccpr until we work through a few issues. |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 39 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | a63e7ab | 2017-05-16 14:38:54 -0400 | [diff] [blame] | 40 | fCrossContextTextureSupport = false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | |
| 42 | fMapBufferFlags = kNone_MapFlags; //TODO: figure this out |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 43 | fBufferMapThreshold = SK_MaxS32; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 44 | |
| 45 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 46 | fMaxTextureSize = 4096; // minimum required by spec |
| 47 | fMaxColorSampleCount = 4; // minimum required by spec |
| 48 | fMaxStencilSampleCount = 4; // minimum required by spec |
| 49 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 50 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 51 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 52 | this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 55 | bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 56 | bool* rectsMustMatch, bool* disallowSubrect) const { |
| 57 | // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false. |
| 58 | *rectsMustMatch = false; |
| 59 | *disallowSubrect = false; |
| 60 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 61 | // 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 Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 66 | if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 67 | 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 76 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 77 | VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 78 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 79 | VkPhysicalDeviceProperties properties; |
| 80 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 81 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 82 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 83 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 84 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 85 | this->initGrCaps(properties, memoryProperties, featureFlags); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 86 | this->initShaderCaps(properties, featureFlags); |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 87 | this->initConfigTable(vkInterface, physDev, properties); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 88 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 89 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 90 | if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) { |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 91 | // Currently disabling this feature since it does not play well with validation layers which |
| 92 | // expect a SPIR-V shader |
| 93 | // fCanUseGLSLForShaderModule = true; |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 94 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 95 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 96 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 97 | fMustDoCopiesFromOrigin = true; |
| 98 | } |
| 99 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 100 | if (kNvidia_VkVendor == properties.vendorID) { |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 101 | fMustSubmitCommandsBeforeCopyOp = true; |
| 102 | } |
| 103 | |
Greg Daniel | 1cdbdda | 2017-05-16 14:52:57 -0400 | [diff] [blame] | 104 | if (kQualcomm_VkVendor != properties.vendorID) { |
| 105 | fSupportsCopiesAsDraws = true; |
| 106 | } |
| 107 | |
Greg Daniel | a63e7ab | 2017-05-16 14:38:54 -0400 | [diff] [blame] | 108 | if (fSupportsCopiesAsDraws) { |
| 109 | fCrossContextTextureSupport = true; |
| 110 | } |
| 111 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 112 | #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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 122 | this->applyOptionsOverrides(contextOptions); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 123 | fShaderCaps->applyOptionsOverrides(contextOptions); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | int 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 | |
| 149 | void GrVkCaps::initSampleCount(const VkPhysicalDeviceProperties& properties) { |
| 150 | VkSampleCountFlags colorSamples = properties.limits.framebufferColorSampleCounts; |
| 151 | VkSampleCountFlags stencilSamples = properties.limits.framebufferStencilSampleCounts; |
| 152 | |
| 153 | fMaxColorSampleCount = get_max_sample_count(colorSamples); |
Greg Daniel | 1e9ddcc | 2017-04-19 13:01:22 -0400 | [diff] [blame] | 154 | if (kImagination_VkVendor == properties.vendorID) { |
| 155 | fMaxColorSampleCount = 0; |
| 156 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 157 | fMaxStencilSampleCount = get_max_sample_count(stencilSamples); |
| 158 | } |
| 159 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 160 | void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 161 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
| 162 | uint32_t featureFlags) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 163 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 164 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 165 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 166 | // we ever find that need. |
| 167 | static const uint32_t kMaxVertexAttributes = 64; |
| 168 | fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
| 169 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 170 | if (kAMD_VkVendor == properties.vendorID) { |
| 171 | fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32); |
| 172 | } |
| 173 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 174 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 175 | // give the minimum max size across all configs. So for simplicity we will use that for now. |
jvanverth | e78d487 | 2016-09-27 03:33:05 -0700 | [diff] [blame] | 176 | fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 177 | fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 178 | |
| 179 | this->initSampleCount(properties); |
| 180 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 181 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 182 | // from the get go. There is no hard data to suggest this is faster or slower. |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 183 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 184 | |
| 185 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 186 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 187 | fOversizedStencilSupport = true; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 188 | fSampleShadingSupport = SkToBool(featureFlags & kSampleRateShading_GrVkFeatureFlag); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 189 | |
| 190 | // AMD seems to have issues binding new VkPipelines inside a secondary command buffer. |
| 191 | // Current workaround is to use a different secondary command buffer for each new VkPipeline. |
| 192 | if (kAMD_VkVendor == properties.vendorID) { |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 193 | fNewCBOnPipelineChange = true; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 194 | } |
Greg Daniel | 0190787 | 2017-05-23 15:21:02 -0400 | [diff] [blame] | 195 | |
| 196 | #if defined(SK_CPU_X86) |
| 197 | if (kImagination_VkVendor == properties.vendorID) { |
| 198 | fSRGBSupport = false; |
| 199 | } |
| 200 | #endif |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 203 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint32_t featureFlags) { |
| 204 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 205 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 206 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 207 | |
| 208 | // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config. |
| 209 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 210 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
| 211 | if (GrPixelConfigIsAlphaOnly(config)) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 212 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR(); |
| 213 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 214 | } else { |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 215 | if (kGray_8_GrPixelConfig == config) { |
| 216 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA(); |
| 217 | } else if (kRGBA_4444_GrPixelConfig == config) { |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 218 | // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we |
| 219 | // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads |
| 220 | // or writing to outputs. Since we're not actually changing the data at all, the |
| 221 | // only extra work is the swizzle in the shader for all operations. |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 222 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA(); |
| 223 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 224 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 225 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 226 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 229 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 230 | if (kImagination_VkVendor == properties.vendorID) { |
| 231 | shaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 232 | } |
| 233 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 234 | // Vulkan is based off ES 3.0 so the following should all be supported |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 235 | shaderCaps->fUsesPrecisionModifiers = true; |
| 236 | shaderCaps->fFlatInterpolationSupport = true; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 237 | // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 238 | // to be true with Vulkan as well. |
| 239 | shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 240 | |
| 241 | // GrShaderCaps |
| 242 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 243 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 244 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 245 | shaderCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag); |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 246 | shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 247 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 248 | shaderCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag); |
Greg Daniel | 84cff13 | 2017-03-22 16:25:53 -0400 | [diff] [blame] | 249 | if (kAMD_VkVendor == properties.vendorID) { |
| 250 | // Currently DualSourceBlending is not working on AMD. vkCreateGraphicsPipeline fails when |
| 251 | // using a draw with dual source. Looking into whether it is driver bug or issue with our |
| 252 | // SPIR-V. Bug skia:6405 |
| 253 | shaderCaps->fDualSourceBlendingSupport = false; |
| 254 | } |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 255 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 256 | shaderCaps->fIntegerSupport = true; |
Chris Dalton | 6b65b98 | 2017-07-06 11:04:00 -0600 | [diff] [blame] | 257 | shaderCaps->fTexelBufferSupport = true; |
| 258 | shaderCaps->fTexelFetchSupport = true; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 259 | shaderCaps->fVertexIDSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 260 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 261 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 262 | shaderCaps->fShaderPrecisionVaries = true; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 263 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 264 | auto& highp = shaderCaps->fFloatPrecisions[s][kHigh_GrSLPrecision]; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 265 | highp.fLogRangeLow = highp.fLogRangeHigh = 127; |
| 266 | highp.fBits = 23; |
| 267 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 268 | auto& mediump = shaderCaps->fFloatPrecisions[s][kMedium_GrSLPrecision]; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 269 | mediump.fLogRangeLow = mediump.fLogRangeHigh = 14; |
| 270 | mediump.fBits = 10; |
| 271 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 272 | shaderCaps->fFloatPrecisions[s][kLow_GrSLPrecision] = mediump; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 273 | } |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 274 | shaderCaps->initSamplerPrecisionTable(); |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 275 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 276 | shaderCaps->fMaxVertexSamplers = |
| 277 | shaderCaps->fMaxGeometrySamplers = |
| 278 | shaderCaps->fMaxFragmentSamplers = SkTMin( |
| 279 | SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 280 | properties.limits.maxPerStageDescriptorSamplers), |
| 281 | (uint32_t)INT_MAX); |
| 282 | shaderCaps->fMaxCombinedSamplers = SkTMin( |
| 283 | SkTMin(properties.limits.maxDescriptorSetSampledImages, |
| 284 | properties.limits.maxDescriptorSetSamplers), |
| 285 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 286 | } |
| 287 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 288 | bool stencil_format_supported(const GrVkInterface* interface, |
| 289 | VkPhysicalDevice physDev, |
| 290 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 291 | VkFormatProperties props; |
| 292 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 293 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 294 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 295 | } |
| 296 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 297 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 298 | // List of legal stencil formats (though perhaps not supported on |
| 299 | // the particular gpu/driver) from most preferred to least. We are guaranteed to have either |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 300 | // VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT. VK_FORMAT_D32_SFLOAT_S8_UINT |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 301 | // can optionally have 24 unused bits at the end so we assume the total bits is 64. |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 302 | static const StencilFormat |
| 303 | // internal Format stencil bits total bits packed? |
| 304 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 305 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }, |
| 306 | gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 307 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 308 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
| 309 | fPreferedStencilFormat = gS8; |
| 310 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
| 311 | fPreferedStencilFormat = gD24S8; |
| 312 | } else { |
| 313 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
| 314 | fPreferedStencilFormat = gD32S8; |
| 315 | } |
| 316 | } |
| 317 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 318 | void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev, |
| 319 | const VkPhysicalDeviceProperties& properties) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 320 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 321 | VkFormat format; |
| 322 | if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) { |
Greg Daniel | 0190787 | 2017-05-23 15:21:02 -0400 | [diff] [blame] | 323 | if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 324 | fConfigTable[i].init(interface, physDev, properties, format); |
Greg Daniel | 0190787 | 2017-05-23 15:21:02 -0400 | [diff] [blame] | 325 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
| 331 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 332 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 333 | *flags = *flags | kTextureable_Flag; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 334 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 335 | // Ganesh assumes that all renderable surfaces are also texturable |
| 336 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
| 337 | *flags = *flags | kRenderable_Flag; |
| 338 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 342 | *flags = *flags | kBlitSrc_Flag; |
| 343 | } |
| 344 | |
| 345 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 346 | *flags = *flags | kBlitDst_Flag; |
| 347 | } |
| 348 | } |
| 349 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 350 | void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface, |
| 351 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 352 | const VkPhysicalDeviceProperties& physProps, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 353 | VkFormat format) { |
| 354 | VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 355 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 356 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 357 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 358 | VkImageCreateFlags createFlags = GrVkFormatIsSRGB(format, nullptr) |
| 359 | ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0; |
| 360 | VkImageFormatProperties properties; |
| 361 | GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev, |
| 362 | format, |
| 363 | VK_IMAGE_TYPE_2D, |
| 364 | VK_IMAGE_TILING_OPTIMAL, |
| 365 | usage, |
| 366 | createFlags, |
| 367 | &properties)); |
| 368 | VkSampleCountFlags flags = properties.sampleCounts; |
| 369 | if (flags & VK_SAMPLE_COUNT_1_BIT) { |
| 370 | fColorSampleCounts.push(0); |
| 371 | } |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 372 | if (kImagination_VkVendor == physProps.vendorID) { |
| 373 | // MSAA does not work on imagination |
| 374 | return; |
| 375 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 376 | if (flags & VK_SAMPLE_COUNT_2_BIT) { |
| 377 | fColorSampleCounts.push(2); |
| 378 | } |
| 379 | if (flags & VK_SAMPLE_COUNT_4_BIT) { |
| 380 | fColorSampleCounts.push(4); |
| 381 | } |
| 382 | if (flags & VK_SAMPLE_COUNT_8_BIT) { |
| 383 | fColorSampleCounts.push(8); |
| 384 | } |
| 385 | if (flags & VK_SAMPLE_COUNT_16_BIT) { |
| 386 | fColorSampleCounts.push(16); |
| 387 | } |
| 388 | if (flags & VK_SAMPLE_COUNT_32_BIT) { |
| 389 | fColorSampleCounts.push(32); |
| 390 | } |
| 391 | if (flags & VK_SAMPLE_COUNT_64_BIT) { |
| 392 | fColorSampleCounts.push(64); |
| 393 | } |
| 394 | } |
| 395 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 396 | void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, |
| 397 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 398 | const VkPhysicalDeviceProperties& properties, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 399 | VkFormat format) { |
| 400 | VkFormatProperties props; |
| 401 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 402 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 403 | InitConfigFlags(props.linearTilingFeatures, &fLinearFlags); |
| 404 | InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 405 | if (fOptimalFlags & kRenderable_Flag) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 406 | this->initSampleCounts(interface, physDev, properties, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 407 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 408 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 409 | |
| 410 | int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const { |
| 411 | int count = fConfigTable[config].fColorSampleCounts.count(); |
| 412 | if (!count || !this->isConfigRenderable(config, true)) { |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | for (int i = 0; i < count; ++i) { |
| 417 | if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) { |
| 418 | return fConfigTable[config].fColorSampleCounts[i]; |
| 419 | } |
| 420 | } |
| 421 | return fConfigTable[config].fColorSampleCounts[count-1]; |
| 422 | } |
| 423 | |