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 | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 23 | fNewSecondaryCBOnPipelineChange = 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 |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 30 | fNPOTTextureTileSupport = true; // always available in Vulkan |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 31 | fDiscardRenderTargetSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | fReuseScratchTextures = true; //TODO: figure this out |
| 33 | fGpuTracingSupport = false; //TODO: figure this out |
| 34 | fCompressedTexSubImageSupport = false; //TODO: figure this out |
| 35 | fOversizedStencilSupport = false; //TODO: figure this out |
| 36 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 37 | fUseDrawInsteadOfClear = false; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 38 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | a63e7ab | 2017-05-16 14:38:54 -0400 | [diff] [blame^] | 39 | fCrossContextTextureSupport = false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 40 | |
| 41 | fMapBufferFlags = kNone_MapFlags; //TODO: figure this out |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 42 | fBufferMapThreshold = SK_MaxS32; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | |
| 44 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 45 | fMaxTextureSize = 4096; // minimum required by spec |
| 46 | fMaxColorSampleCount = 4; // minimum required by spec |
| 47 | fMaxStencilSampleCount = 4; // minimum required by spec |
| 48 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 49 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 50 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 51 | this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 54 | bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 55 | bool* rectsMustMatch, bool* disallowSubrect) const { |
| 56 | // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false. |
| 57 | *rectsMustMatch = false; |
| 58 | *disallowSubrect = false; |
| 59 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 60 | // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa). |
| 61 | // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a |
| 62 | // render target as well. |
| 63 | desc->fOrigin = src->origin(); |
| 64 | desc->fConfig = src->config(); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 65 | if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 66 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
| 67 | } else { |
| 68 | // Just going to use CopyImage here |
| 69 | desc->fFlags = kNone_GrSurfaceFlags; |
| 70 | } |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 75 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 76 | VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t extensionFlags) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 77 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 78 | VkPhysicalDeviceProperties properties; |
| 79 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
| 80 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 81 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 82 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 83 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 84 | this->initGrCaps(properties, memoryProperties, featureFlags); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 85 | this->initShaderCaps(properties, featureFlags); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 86 | this->initConfigTable(vkInterface, physDev); |
| 87 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 88 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 89 | if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) { |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 90 | // Currently disabling this feature since it does not play well with validation layers which |
| 91 | // expect a SPIR-V shader |
| 92 | // fCanUseGLSLForShaderModule = true; |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 93 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 94 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 95 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 96 | fMustDoCopiesFromOrigin = true; |
| 97 | } |
| 98 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 99 | if (kNvidia_VkVendor == properties.vendorID) { |
| 100 | fSupportsCopiesAsDraws = true; |
| 101 | fMustSubmitCommandsBeforeCopyOp = true; |
| 102 | } |
| 103 | |
Greg Daniel | a63e7ab | 2017-05-16 14:38:54 -0400 | [diff] [blame^] | 104 | if (fSupportsCopiesAsDraws) { |
| 105 | fCrossContextTextureSupport = true; |
| 106 | } |
| 107 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 108 | #if defined(SK_BUILD_FOR_WIN) |
| 109 | if (kNvidia_VkVendor == properties.vendorID) { |
| 110 | fMustSleepOnTearDown = true; |
| 111 | } |
| 112 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 113 | if (kImagination_VkVendor == properties.vendorID) { |
| 114 | fMustSleepOnTearDown = true; |
| 115 | } |
| 116 | #endif |
| 117 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 118 | this->applyOptionsOverrides(contextOptions); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 119 | fShaderCaps->applyOptionsOverrides(contextOptions); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int get_max_sample_count(VkSampleCountFlags flags) { |
| 123 | SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT); |
| 124 | if (!(flags & VK_SAMPLE_COUNT_2_BIT)) { |
| 125 | return 0; |
| 126 | } |
| 127 | if (!(flags & VK_SAMPLE_COUNT_4_BIT)) { |
| 128 | return 2; |
| 129 | } |
| 130 | if (!(flags & VK_SAMPLE_COUNT_8_BIT)) { |
| 131 | return 4; |
| 132 | } |
| 133 | if (!(flags & VK_SAMPLE_COUNT_16_BIT)) { |
| 134 | return 8; |
| 135 | } |
| 136 | if (!(flags & VK_SAMPLE_COUNT_32_BIT)) { |
| 137 | return 16; |
| 138 | } |
| 139 | if (!(flags & VK_SAMPLE_COUNT_64_BIT)) { |
| 140 | return 32; |
| 141 | } |
| 142 | return 64; |
| 143 | } |
| 144 | |
| 145 | void GrVkCaps::initSampleCount(const VkPhysicalDeviceProperties& properties) { |
| 146 | VkSampleCountFlags colorSamples = properties.limits.framebufferColorSampleCounts; |
| 147 | VkSampleCountFlags stencilSamples = properties.limits.framebufferStencilSampleCounts; |
| 148 | |
| 149 | fMaxColorSampleCount = get_max_sample_count(colorSamples); |
Greg Daniel | 1e9ddcc | 2017-04-19 13:01:22 -0400 | [diff] [blame] | 150 | if (kImagination_VkVendor == properties.vendorID) { |
| 151 | fMaxColorSampleCount = 0; |
| 152 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 153 | fMaxStencilSampleCount = get_max_sample_count(stencilSamples); |
| 154 | } |
| 155 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 156 | void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 157 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
| 158 | uint32_t featureFlags) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 159 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 160 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 161 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 162 | // we ever find that need. |
| 163 | static const uint32_t kMaxVertexAttributes = 64; |
| 164 | fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
| 165 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 166 | if (kAMD_VkVendor == properties.vendorID) { |
| 167 | fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32); |
| 168 | } |
| 169 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 170 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 171 | // 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] | 172 | fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 173 | fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 174 | |
| 175 | this->initSampleCount(properties); |
| 176 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 177 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 178 | // 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] | 179 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 180 | |
| 181 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 182 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 183 | fOversizedStencilSupport = true; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 184 | fSampleShadingSupport = SkToBool(featureFlags & kSampleRateShading_GrVkFeatureFlag); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 185 | |
| 186 | // AMD seems to have issues binding new VkPipelines inside a secondary command buffer. |
| 187 | // Current workaround is to use a different secondary command buffer for each new VkPipeline. |
| 188 | if (kAMD_VkVendor == properties.vendorID) { |
| 189 | fNewSecondaryCBOnPipelineChange = true; |
| 190 | } |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 193 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint32_t featureFlags) { |
| 194 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 195 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 196 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 197 | |
| 198 | // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config. |
| 199 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 200 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
| 201 | if (GrPixelConfigIsAlphaOnly(config)) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 202 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR(); |
| 203 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 204 | } else { |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 205 | if (kGray_8_GrPixelConfig == config) { |
| 206 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA(); |
| 207 | } else if (kRGBA_4444_GrPixelConfig == config) { |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 208 | // 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 Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 212 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA(); |
| 213 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 214 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 215 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 216 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 217 | } |
| 218 | } |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 219 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 220 | if (kImagination_VkVendor == properties.vendorID) { |
| 221 | shaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 222 | } |
| 223 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 224 | // 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] | 225 | shaderCaps->fUsesPrecisionModifiers = true; |
| 226 | shaderCaps->fFlatInterpolationSupport = true; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 227 | |
| 228 | // GrShaderCaps |
| 229 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 230 | shaderCaps->fShaderDerivativeSupport = true; |
| 231 | shaderCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag); |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 232 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 233 | shaderCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag); |
Greg Daniel | 84cff13 | 2017-03-22 16:25:53 -0400 | [diff] [blame] | 234 | if (kAMD_VkVendor == properties.vendorID) { |
| 235 | // Currently DualSourceBlending is not working on AMD. vkCreateGraphicsPipeline fails when |
| 236 | // using a draw with dual source. Looking into whether it is driver bug or issue with our |
| 237 | // SPIR-V. Bug skia:6405 |
| 238 | shaderCaps->fDualSourceBlendingSupport = false; |
| 239 | } |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 240 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 241 | shaderCaps->fIntegerSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 242 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 243 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 244 | shaderCaps->fShaderPrecisionVaries = true; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 245 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 246 | auto& highp = shaderCaps->fFloatPrecisions[s][kHigh_GrSLPrecision]; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 247 | highp.fLogRangeLow = highp.fLogRangeHigh = 127; |
| 248 | highp.fBits = 23; |
| 249 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 250 | auto& mediump = shaderCaps->fFloatPrecisions[s][kMedium_GrSLPrecision]; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 251 | mediump.fLogRangeLow = mediump.fLogRangeHigh = 14; |
| 252 | mediump.fBits = 10; |
| 253 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 254 | shaderCaps->fFloatPrecisions[s][kLow_GrSLPrecision] = mediump; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 255 | } |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 256 | shaderCaps->initSamplerPrecisionTable(); |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 257 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 258 | shaderCaps->fMaxVertexSamplers = |
| 259 | shaderCaps->fMaxGeometrySamplers = |
| 260 | shaderCaps->fMaxFragmentSamplers = SkTMin( |
| 261 | SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 262 | properties.limits.maxPerStageDescriptorSamplers), |
| 263 | (uint32_t)INT_MAX); |
| 264 | shaderCaps->fMaxCombinedSamplers = SkTMin( |
| 265 | SkTMin(properties.limits.maxDescriptorSetSampledImages, |
| 266 | properties.limits.maxDescriptorSetSamplers), |
| 267 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 268 | } |
| 269 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 270 | bool stencil_format_supported(const GrVkInterface* interface, |
| 271 | VkPhysicalDevice physDev, |
| 272 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 273 | VkFormatProperties props; |
| 274 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 275 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 276 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 277 | } |
| 278 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 279 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 280 | // List of legal stencil formats (though perhaps not supported on |
| 281 | // 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] | 282 | // 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] | 283 | // 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] | 284 | static const StencilFormat |
| 285 | // internal Format stencil bits total bits packed? |
| 286 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 287 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }, |
| 288 | gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 289 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 290 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
| 291 | fPreferedStencilFormat = gS8; |
| 292 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
| 293 | fPreferedStencilFormat = gD24S8; |
| 294 | } else { |
| 295 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
| 296 | fPreferedStencilFormat = gD32S8; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 301 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 302 | VkFormat format; |
| 303 | if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) { |
| 304 | fConfigTable[i].init(interface, physDev, format); |
| 305 | } |
| 306 | } |
Robert Phillips | 351b045 | 2017-02-01 14:45:04 -0500 | [diff] [blame] | 307 | |
| 308 | // We currently do not support compressed textures in Vulkan |
| 309 | const uint16_t kFlagsToRemove = ConfigInfo::kTextureable_Flag|ConfigInfo::kRenderable_Flag; |
| 310 | fConfigTable[kETC1_GrPixelConfig].fOptimalFlags &= ~kFlagsToRemove; |
| 311 | fConfigTable[kETC1_GrPixelConfig].fLinearFlags &= ~kFlagsToRemove; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
| 315 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 316 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 317 | *flags = *flags | kTextureable_Flag; |
| 318 | } |
| 319 | |
| 320 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
| 321 | *flags = *flags | kRenderable_Flag; |
| 322 | } |
| 323 | |
| 324 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 325 | *flags = *flags | kBlitSrc_Flag; |
| 326 | } |
| 327 | |
| 328 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 329 | *flags = *flags | kBlitDst_Flag; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, |
| 334 | VkPhysicalDevice physDev, |
| 335 | VkFormat format) { |
| 336 | VkFormatProperties props; |
| 337 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 338 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 339 | InitConfigFlags(props.linearTilingFeatures, &fLinearFlags); |
| 340 | InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 341 | } |