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" |
| 9 | |
| 10 | #include "GrVkUtil.h" |
| 11 | #include "glsl/GrGLSLCaps.h" |
| 12 | #include "vk/GrVkInterface.h" |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 13 | #include "vk/GrVkBackendContext.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
| 15 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 16 | VkPhysicalDevice physDev, uint32_t featureFlags) : INHERITED(contextOptions) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 17 | /************************************************************************** |
| 18 | * GrDrawTargetCaps fields |
| 19 | **************************************************************************/ |
| 20 | fMipMapSupport = false; //TODO: figure this out |
| 21 | fNPOTTextureTileSupport = false; //TODO: figure this out |
| 22 | fTwoSidedStencilSupport = false; //TODO: figure this out |
| 23 | fStencilWrapOpsSupport = false; //TODO: figure this out |
| 24 | fDiscardRenderTargetSupport = false; //TODO: figure this out |
| 25 | fReuseScratchTextures = true; //TODO: figure this out |
| 26 | fGpuTracingSupport = false; //TODO: figure this out |
| 27 | fCompressedTexSubImageSupport = false; //TODO: figure this out |
| 28 | fOversizedStencilSupport = false; //TODO: figure this out |
| 29 | |
| 30 | fUseDrawInsteadOfClear = false; //TODO: figure this out |
| 31 | |
| 32 | fMapBufferFlags = kNone_MapFlags; //TODO: figure this out |
robertphillips | f8c3ba4 | 2016-03-25 04:55:58 -0700 | [diff] [blame] | 33 | fGeometryBufferMapThreshold = SK_MaxS32; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | |
| 35 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 36 | fMaxTextureSize = 4096; // minimum required by spec |
| 37 | fMaxColorSampleCount = 4; // minimum required by spec |
| 38 | fMaxStencilSampleCount = 4; // minimum required by spec |
| 39 | |
| 40 | |
| 41 | fShaderCaps.reset(new GrGLSLCaps(contextOptions)); |
| 42 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 43 | this->init(contextOptions, vkInterface, physDev, featureFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 47 | VkPhysicalDevice physDev, uint32_t featureFlags) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 48 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 49 | VkPhysicalDeviceProperties properties; |
| 50 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
| 51 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 52 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 53 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 54 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 55 | this->initGrCaps(properties, memoryProperties, featureFlags); |
| 56 | this->initGLSLCaps(properties, featureFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | this->initConfigTexturableTable(vkInterface, physDev); |
| 58 | this->initConfigRenderableTable(vkInterface, physDev); |
| 59 | this->initStencilFormats(vkInterface, physDev); |
| 60 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 61 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 62 | |
| 63 | this->applyOptionsOverrides(contextOptions); |
| 64 | // need to friend GrVkCaps in GrGLSLCaps.h |
| 65 | // GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 66 | // glslCaps->applyOptionsOverrides(contextOptions); |
| 67 | } |
| 68 | |
| 69 | int get_max_sample_count(VkSampleCountFlags flags) { |
| 70 | SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT); |
| 71 | if (!(flags & VK_SAMPLE_COUNT_2_BIT)) { |
| 72 | return 0; |
| 73 | } |
| 74 | if (!(flags & VK_SAMPLE_COUNT_4_BIT)) { |
| 75 | return 2; |
| 76 | } |
| 77 | if (!(flags & VK_SAMPLE_COUNT_8_BIT)) { |
| 78 | return 4; |
| 79 | } |
| 80 | if (!(flags & VK_SAMPLE_COUNT_16_BIT)) { |
| 81 | return 8; |
| 82 | } |
| 83 | if (!(flags & VK_SAMPLE_COUNT_32_BIT)) { |
| 84 | return 16; |
| 85 | } |
| 86 | if (!(flags & VK_SAMPLE_COUNT_64_BIT)) { |
| 87 | return 32; |
| 88 | } |
| 89 | return 64; |
| 90 | } |
| 91 | |
| 92 | void GrVkCaps::initSampleCount(const VkPhysicalDeviceProperties& properties) { |
| 93 | VkSampleCountFlags colorSamples = properties.limits.framebufferColorSampleCounts; |
| 94 | VkSampleCountFlags stencilSamples = properties.limits.framebufferStencilSampleCounts; |
| 95 | |
| 96 | fMaxColorSampleCount = get_max_sample_count(colorSamples); |
| 97 | fMaxStencilSampleCount = get_max_sample_count(stencilSamples); |
| 98 | } |
| 99 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 100 | void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 101 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
| 102 | uint32_t featureFlags) { |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 103 | fMaxVertexAttributes = properties.limits.maxVertexInputAttributes; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 104 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 105 | // give the minimum max size across all configs. So for simplicity we will use that for now. |
| 106 | fMaxRenderTargetSize = properties.limits.maxImageDimension2D; |
| 107 | fMaxTextureSize = properties.limits.maxImageDimension2D; |
| 108 | |
| 109 | this->initSampleCount(properties); |
| 110 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 111 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 112 | // from the get go. There is no hard data to suggest this is faster or slower. |
robertphillips | f8c3ba4 | 2016-03-25 04:55:58 -0700 | [diff] [blame] | 113 | fGeometryBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 114 | |
| 115 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 116 | |
| 117 | fStencilWrapOpsSupport = true; |
| 118 | fOversizedStencilSupport = true; |
| 119 | } |
| 120 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 121 | void GrVkCaps::initGLSLCaps(const VkPhysicalDeviceProperties& properties, |
| 122 | uint32_t featureFlags) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 123 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 124 | glslCaps->fVersionDeclString = "#version 310 es\n"; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 125 | |
| 126 | // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config. |
| 127 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 128 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
| 129 | if (GrPixelConfigIsAlphaOnly(config)) { |
| 130 | glslCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR(); |
| 131 | glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
| 132 | } else { |
| 133 | glslCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA(); |
| 134 | } |
| 135 | } |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 136 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 137 | // Vulkan is based off ES 3.0 so the following should all be supported |
| 138 | glslCaps->fUsesPrecisionModifiers = true; |
| 139 | glslCaps->fFlatInterpolationSupport = true; |
| 140 | |
| 141 | // GrShaderCaps |
| 142 | |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 143 | glslCaps->fShaderDerivativeSupport = true; |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 144 | glslCaps->fGeometryShaderSupport = SkToBool(featureFlags & kGeometryShader_GrVkFeatureFlag); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 145 | #if 0 |
| 146 | // For now disabling dual source blending till we get it hooked up in the rest of system |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame^] | 147 | glslCaps->fDualSourceBlendingSupport = SkToBool(featureFlags & kDualSrcBlend_GrVkFeatureFlag); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 148 | #endif |
| 149 | glslCaps->fIntegerSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 150 | |
| 151 | glslCaps->fMaxVertexSamplers = |
| 152 | glslCaps->fMaxGeometrySamplers = |
| 153 | glslCaps->fMaxFragmentSamplers = SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 154 | properties.limits.maxPerStageDescriptorSamplers); |
| 155 | glslCaps->fMaxCombinedSamplers = SkTMin(properties.limits.maxDescriptorSetSampledImages, |
| 156 | properties.limits.maxDescriptorSetSamplers); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void format_supported_for_feature(const GrVkInterface* interface, |
| 160 | VkPhysicalDevice physDev, |
| 161 | VkFormat format, |
| 162 | VkFormatFeatureFlagBits featureBit, |
| 163 | bool* linearSupport, |
| 164 | bool* optimalSupport) { |
| 165 | VkFormatProperties props; |
| 166 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 167 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 168 | *linearSupport = SkToBool(props.linearTilingFeatures & featureBit); |
| 169 | *optimalSupport = SkToBool(props.optimalTilingFeatures & featureBit); |
| 170 | } |
| 171 | |
| 172 | static void config_supported_for_feature(const GrVkInterface* interface, |
| 173 | VkPhysicalDevice physDev, |
| 174 | GrPixelConfig config, |
| 175 | VkFormatFeatureFlagBits featureBit, |
| 176 | bool* linearSupport, |
| 177 | bool* optimalSupport) { |
| 178 | VkFormat format; |
| 179 | if (!GrPixelConfigToVkFormat(config, &format)) { |
| 180 | *linearSupport = false; |
| 181 | *optimalSupport = false; |
| 182 | return; |
| 183 | } |
| 184 | format_supported_for_feature(interface, physDev, format, featureBit, |
| 185 | linearSupport, optimalSupport); |
| 186 | } |
| 187 | |
| 188 | // Currently just assumeing if something can be rendered to without MSAA it also works for MSAAA |
| 189 | #define SET_CONFIG_IS_RENDERABLE(config) \ |
| 190 | config_supported_for_feature(interface, \ |
| 191 | physDev, \ |
| 192 | config, \ |
| 193 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT, \ |
| 194 | &fConfigLinearRenderSupport[config][kNo_MSAA], \ |
| 195 | &fConfigRenderSupport[config][kNo_MSAA] ); \ |
| 196 | fConfigRenderSupport[config][kYes_MSAA] = fConfigRenderSupport[config][kNo_MSAA]; \ |
| 197 | fConfigLinearRenderSupport[config][kYes_MSAA] = fConfigLinearRenderSupport[config][kNo_MSAA]; |
| 198 | |
| 199 | |
| 200 | void GrVkCaps::initConfigRenderableTable(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 201 | enum { |
| 202 | kNo_MSAA = 0, |
| 203 | kYes_MSAA = 1, |
| 204 | }; |
| 205 | |
| 206 | // Base render support |
| 207 | SET_CONFIG_IS_RENDERABLE(kAlpha_8_GrPixelConfig); |
| 208 | SET_CONFIG_IS_RENDERABLE(kRGB_565_GrPixelConfig); |
| 209 | SET_CONFIG_IS_RENDERABLE(kRGBA_4444_GrPixelConfig); |
| 210 | SET_CONFIG_IS_RENDERABLE(kRGBA_8888_GrPixelConfig); |
| 211 | SET_CONFIG_IS_RENDERABLE(kBGRA_8888_GrPixelConfig); |
| 212 | |
| 213 | SET_CONFIG_IS_RENDERABLE(kSRGBA_8888_GrPixelConfig); |
| 214 | |
| 215 | // Float render support |
| 216 | SET_CONFIG_IS_RENDERABLE(kRGBA_float_GrPixelConfig); |
| 217 | SET_CONFIG_IS_RENDERABLE(kRGBA_half_GrPixelConfig); |
| 218 | SET_CONFIG_IS_RENDERABLE(kAlpha_half_GrPixelConfig); |
| 219 | } |
| 220 | |
| 221 | #define SET_CONFIG_IS_TEXTURABLE(config) \ |
| 222 | config_supported_for_feature(interface, \ |
| 223 | physDev, \ |
| 224 | config, \ |
| 225 | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT, \ |
| 226 | &fConfigLinearTextureSupport[config], \ |
| 227 | &fConfigTextureSupport[config]); |
| 228 | |
| 229 | void GrVkCaps::initConfigTexturableTable(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 230 | // Base texture support |
| 231 | SET_CONFIG_IS_TEXTURABLE(kAlpha_8_GrPixelConfig); |
| 232 | SET_CONFIG_IS_TEXTURABLE(kRGB_565_GrPixelConfig); |
| 233 | SET_CONFIG_IS_TEXTURABLE(kRGBA_4444_GrPixelConfig); |
| 234 | SET_CONFIG_IS_TEXTURABLE(kRGBA_8888_GrPixelConfig); |
| 235 | SET_CONFIG_IS_TEXTURABLE(kBGRA_8888_GrPixelConfig); |
| 236 | |
| 237 | SET_CONFIG_IS_TEXTURABLE(kIndex_8_GrPixelConfig); |
| 238 | SET_CONFIG_IS_TEXTURABLE(kSRGBA_8888_GrPixelConfig); |
| 239 | |
| 240 | // Compressed texture support |
| 241 | SET_CONFIG_IS_TEXTURABLE(kETC1_GrPixelConfig); |
| 242 | SET_CONFIG_IS_TEXTURABLE(kLATC_GrPixelConfig); |
| 243 | SET_CONFIG_IS_TEXTURABLE(kR11_EAC_GrPixelConfig); |
| 244 | SET_CONFIG_IS_TEXTURABLE(kASTC_12x12_GrPixelConfig); |
| 245 | |
| 246 | // Float texture support |
| 247 | SET_CONFIG_IS_TEXTURABLE(kRGBA_float_GrPixelConfig); |
| 248 | SET_CONFIG_IS_TEXTURABLE(kRGBA_half_GrPixelConfig); |
| 249 | SET_CONFIG_IS_TEXTURABLE(kAlpha_half_GrPixelConfig); |
| 250 | } |
| 251 | |
| 252 | #define SET_CONFIG_CAN_STENCIL(config) \ |
| 253 | bool SK_MACRO_APPEND_LINE(linearSupported); \ |
| 254 | bool SK_MACRO_APPEND_LINE(optimalSupported); \ |
| 255 | format_supported_for_feature(interface, \ |
| 256 | physDev, \ |
| 257 | config.fInternalFormat, \ |
| 258 | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, \ |
| 259 | &SK_MACRO_APPEND_LINE(linearSupported), \ |
| 260 | &SK_MACRO_APPEND_LINE(optimalSupported)); \ |
| 261 | if (SK_MACRO_APPEND_LINE(linearSupported)) fLinearStencilFormats.push_back(config); \ |
| 262 | if (SK_MACRO_APPEND_LINE(optimalSupported)) fStencilFormats.push_back(config); |
| 263 | |
| 264 | void GrVkCaps::initStencilFormats(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 265 | // Build up list of legal stencil formats (though perhaps not supported on |
| 266 | // the particular gpu/driver) from most preferred to least. |
| 267 | |
| 268 | static const StencilFormat |
| 269 | // internal Format stencil bits total bits packed? |
| 270 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
| 271 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }; |
| 272 | |
| 273 | // I'm simply assuming that these two will be supported since they are used in example code. |
| 274 | // TODO: Actaully figure this out |
| 275 | SET_CONFIG_CAN_STENCIL(gS8); |
| 276 | SET_CONFIG_CAN_STENCIL(gD24S8); |
| 277 | } |
| 278 | |