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" |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 9 | #include "GrBackendSurface.h" |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 10 | #include "GrRenderTargetProxy.h" |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 11 | #include "GrRenderTarget.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 12 | #include "GrShaderCaps.h" |
Greg Daniel | d3e65aa | 2018-08-01 09:19:45 -0400 | [diff] [blame] | 13 | #include "GrVkInterface.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | #include "GrVkUtil.h" |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 15 | #include "vk/GrVkBackendContext.h" |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 16 | #include "vk/GrVkExtensions.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 17 | |
| 18 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | 92aef4b | 2018-08-02 13:55:49 -0400 | [diff] [blame] | 19 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures& features, |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 20 | uint32_t instanceVersion, const GrVkExtensions& extensions) |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 21 | : INHERITED(contextOptions) { |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 22 | fMustDoCopiesFromOrigin = false; |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 23 | fMustSubmitCommandsBeforeCopyOp = false; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 24 | fMustSleepOnTearDown = false; |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 25 | fNewCBOnPipelineChange = false; |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 26 | fShouldAlwaysUseDedicatedImageMemory = false; |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 27 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 28 | fSupportsPhysicalDeviceProperties2 = false; |
| 29 | fSupportsMemoryRequirements2 = false; |
| 30 | fSupportsMaintenance1 = false; |
| 31 | fSupportsMaintenance2 = false; |
| 32 | fSupportsMaintenance3 = false; |
| 33 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | /************************************************************************** |
| 35 | * GrDrawTargetCaps fields |
| 36 | **************************************************************************/ |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 37 | fMipMapSupport = true; // always available in Vulkan |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 38 | fSRGBSupport = true; // always available in Vulkan |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 39 | fNPOTTextureTileSupport = true; // always available in Vulkan |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 40 | fDiscardRenderTargetSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | fReuseScratchTextures = true; //TODO: figure this out |
| 42 | fGpuTracingSupport = false; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | fOversizedStencilSupport = false; //TODO: figure this out |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 44 | fInstanceAttribSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | |
Greg Daniel | 0fe4ed8 | 2018-03-15 12:27:29 +0000 | [diff] [blame] | 46 | fBlacklistCoverageCounting = true; // blacklisting ccpr until we work through a few issues. |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 47 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 48 | fCrossContextTextureSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 49 | |
| 50 | fMapBufferFlags = kNone_MapFlags; //TODO: figure this out |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 51 | fBufferMapThreshold = SK_MaxS32; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | |
| 53 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 54 | fMaxTextureSize = 4096; // minimum required by spec |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 56 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 58 | this->init(contextOptions, vkInterface, physDev, features, extensions); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 61 | bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 62 | GrSurfaceOrigin* origin, bool* rectsMustMatch, |
| 63 | bool* disallowSubrect) const { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 64 | // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false. |
| 65 | *rectsMustMatch = false; |
| 66 | *disallowSubrect = false; |
| 67 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 68 | // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa). |
| 69 | // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a |
| 70 | // render target as well. |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 71 | *origin = src->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 72 | desc->fConfig = src->config(); |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 73 | if (src->numColorSamples() > 1 || src->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 74 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
| 75 | } else { |
| 76 | // Just going to use CopyImage here |
| 77 | desc->fFlags = kNone_GrSurfaceFlags; |
| 78 | } |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 83 | bool GrVkCaps::canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin, |
| 84 | GrPixelConfig srcConfig, int srcSampleCnt, |
| 85 | GrSurfaceOrigin srcOrigin) const { |
| 86 | if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 91 | // as image usage flags. |
| 92 | if (srcOrigin != dstOrigin || GrBytesPerPixel(srcConfig) != GrBytesPerPixel(dstConfig)) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | if (this->shaderCaps()->configOutputSwizzle(srcConfig) != |
| 97 | this->shaderCaps()->configOutputSwizzle(dstConfig)) { |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | bool GrVkCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear, |
| 105 | GrPixelConfig srcConfig, int srcSampleCnt, bool srcIsLinear) const { |
| 106 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 107 | // as image usage flags. |
| 108 | if (!this->configCanBeDstofBlit(dstConfig, dstIsLinear) || |
| 109 | !this->configCanBeSrcofBlit(srcConfig, srcIsLinear)) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if (this->shaderCaps()->configOutputSwizzle(srcConfig) != |
| 114 | this->shaderCaps()->configOutputSwizzle(dstConfig)) { |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | // We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 119 | // resolved msaa though. |
| 120 | if (dstSampleCnt > 1 || srcSampleCnt > 1) { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | bool GrVkCaps::canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt, |
| 128 | GrSurfaceOrigin dstOrigin, GrPixelConfig srcConfig, |
| 129 | int srcSampleCnt, GrSurfaceOrigin srcOrigin) const { |
| 130 | // The src surface must be multisampled. |
| 131 | if (srcSampleCnt <= 1) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | // The dst must not be multisampled. |
| 136 | if (dstSampleCnt > 1) { |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | // Surfaces must have the same format. |
| 141 | if (dstConfig != srcConfig) { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | // Surfaces must have the same origin. |
| 146 | if (srcOrigin != dstOrigin) { |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | bool GrVkCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable, |
| 154 | GrPixelConfig srcConfig, bool srcIsTextureable) const { |
| 155 | // TODO: Make copySurfaceAsDraw handle the swizzle |
| 156 | if (this->shaderCaps()->configOutputSwizzle(srcConfig) != |
| 157 | this->shaderCaps()->configOutputSwizzle(dstConfig)) { |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | // Make sure the dst is a render target and the src is a texture. |
| 162 | if (!dstIsRenderable || !srcIsTextureable) { |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | return true; |
| 167 | } |
| 168 | |
| 169 | bool GrVkCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 170 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
| 171 | GrSurfaceOrigin dstOrigin = dst->origin(); |
| 172 | GrSurfaceOrigin srcOrigin = src->origin(); |
| 173 | |
| 174 | GrPixelConfig dstConfig = dst->config(); |
| 175 | GrPixelConfig srcConfig = src->config(); |
| 176 | |
| 177 | // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g. |
| 178 | // PromiseImage which won't get instantiated right away. Does this need a similar thing like the |
| 179 | // tracking of external or rectangle textures in GL? For now we don't create linear textures |
| 180 | // internally, and I don't believe anyone is wrapping them. |
| 181 | bool srcIsLinear = false; |
| 182 | bool dstIsLinear = false; |
| 183 | |
| 184 | int dstSampleCnt = 0; |
| 185 | int srcSampleCnt = 0; |
| 186 | if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) { |
| 187 | dstSampleCnt = rtProxy->numColorSamples(); |
| 188 | } |
| 189 | if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) { |
| 190 | srcSampleCnt = rtProxy->numColorSamples(); |
| 191 | } |
| 192 | SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy())); |
| 193 | SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy())); |
| 194 | |
| 195 | return this->canCopyImage(dstConfig, dstSampleCnt, dstOrigin, |
| 196 | srcConfig, srcSampleCnt, srcOrigin) || |
| 197 | this->canCopyAsBlit(dstConfig, dstSampleCnt, dstIsLinear, |
| 198 | srcConfig, srcSampleCnt, srcIsLinear) || |
| 199 | this->canCopyAsResolve(dstConfig, dstSampleCnt, dstOrigin, |
| 200 | srcConfig, srcSampleCnt, srcOrigin) || |
| 201 | this->canCopyAsDraw(dstConfig, dstSampleCnt > 0, |
| 202 | srcConfig, SkToBool(src->asTextureProxy())); |
| 203 | } |
| 204 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 205 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 206 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures& features, |
| 207 | const GrVkExtensions& extensions) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 208 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 209 | VkPhysicalDeviceProperties properties; |
| 210 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 211 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 212 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 213 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 214 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame^] | 215 | uint32_t physicalDeviceVersion = properties.apiVersion; |
| 216 | |
| 217 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 218 | extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { |
| 219 | fSupportsPhysicalDeviceProperties2 = true; |
| 220 | } |
| 221 | |
| 222 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 223 | extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { |
| 224 | fSupportsMemoryRequirements2 = true; |
| 225 | } |
| 226 | |
| 227 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 228 | extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { |
| 229 | fSupportsMaintenance1 = true; |
| 230 | } |
| 231 | |
| 232 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 233 | extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) { |
| 234 | fSupportsMaintenance2 = true; |
| 235 | } |
| 236 | |
| 237 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 238 | extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { |
| 239 | fSupportsMaintenance3 = true; |
| 240 | } |
| 241 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 242 | this->initGrCaps(properties, memoryProperties, features); |
| 243 | this->initShaderCaps(properties, features); |
Greg Daniel | f3b1162 | 2018-03-01 15:01:27 -0500 | [diff] [blame] | 244 | |
| 245 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 246 | #if defined(SK_CPU_X86) |
| 247 | // We need to do this before initing the config table since it uses fSRGBSupport |
| 248 | if (kImagination_VkVendor == properties.vendorID) { |
| 249 | fSRGBSupport = false; |
| 250 | } |
| 251 | #endif |
| 252 | } |
| 253 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 254 | this->initConfigTable(vkInterface, physDev, properties); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 255 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 256 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 257 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 258 | this->applyDriverCorrectnessWorkarounds(properties); |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 259 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 260 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 261 | // On nexus player we disable suballocating VkImage memory since we've seen large slow downs on |
| 262 | // bot run times. |
| 263 | if (kImagination_VkVendor == properties.vendorID) { |
| 264 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 265 | } |
| 266 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 267 | this->applyOptionsOverrides(contextOptions); |
| 268 | fShaderCaps->applyOptionsOverrides(contextOptions); |
| 269 | } |
| 270 | |
| 271 | void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) { |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 272 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 273 | fMustDoCopiesFromOrigin = true; |
| 274 | } |
| 275 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 276 | if (kNvidia_VkVendor == properties.vendorID) { |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 277 | fMustSubmitCommandsBeforeCopyOp = true; |
| 278 | } |
| 279 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 280 | #if defined(SK_BUILD_FOR_WIN) |
| 281 | if (kNvidia_VkVendor == properties.vendorID) { |
| 282 | fMustSleepOnTearDown = true; |
| 283 | } |
| 284 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 285 | if (kImagination_VkVendor == properties.vendorID) { |
| 286 | fMustSleepOnTearDown = true; |
| 287 | } |
| 288 | #endif |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 289 | |
| 290 | // AMD seems to have issues binding new VkPipelines inside a secondary command buffer. |
| 291 | // Current workaround is to use a different secondary command buffer for each new VkPipeline. |
| 292 | if (kAMD_VkVendor == properties.vendorID) { |
| 293 | fNewCBOnPipelineChange = true; |
| 294 | } |
| 295 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 296 | // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages. |
| 297 | if (kARM_VkVendor == properties.vendorID) { |
| 298 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 299 | } |
| 300 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 301 | //////////////////////////////////////////////////////////////////////////// |
| 302 | // GrCaps workarounds |
| 303 | //////////////////////////////////////////////////////////////////////////// |
| 304 | |
| 305 | if (kARM_VkVendor == properties.vendorID) { |
| 306 | fInstanceAttribSupport = false; |
| 307 | } |
| 308 | |
| 309 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 310 | if (kAMD_VkVendor == properties.vendorID) { |
| 311 | fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32); |
| 312 | } |
| 313 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 314 | //////////////////////////////////////////////////////////////////////////// |
| 315 | // GrShaderCaps workarounds |
| 316 | //////////////////////////////////////////////////////////////////////////// |
| 317 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 318 | if (kImagination_VkVendor == properties.vendorID) { |
| 319 | fShaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 320 | } |
| 321 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | int get_max_sample_count(VkSampleCountFlags flags) { |
| 325 | SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT); |
| 326 | if (!(flags & VK_SAMPLE_COUNT_2_BIT)) { |
| 327 | return 0; |
| 328 | } |
| 329 | if (!(flags & VK_SAMPLE_COUNT_4_BIT)) { |
| 330 | return 2; |
| 331 | } |
| 332 | if (!(flags & VK_SAMPLE_COUNT_8_BIT)) { |
| 333 | return 4; |
| 334 | } |
| 335 | if (!(flags & VK_SAMPLE_COUNT_16_BIT)) { |
| 336 | return 8; |
| 337 | } |
| 338 | if (!(flags & VK_SAMPLE_COUNT_32_BIT)) { |
| 339 | return 16; |
| 340 | } |
| 341 | if (!(flags & VK_SAMPLE_COUNT_64_BIT)) { |
| 342 | return 32; |
| 343 | } |
| 344 | return 64; |
| 345 | } |
| 346 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 347 | void GrVkCaps::initGrCaps(const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 348 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 349 | const VkPhysicalDeviceFeatures& features) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 350 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 351 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 352 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 353 | // we ever find that need. |
| 354 | static const uint32_t kMaxVertexAttributes = 64; |
| 355 | fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 356 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 357 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 358 | // 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] | 359 | fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 360 | fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
Adrienne Walker | 724afe8 | 2018-05-15 11:36:26 -0700 | [diff] [blame] | 361 | if (fDriverBugWorkarounds.max_texture_size_limit_4096) { |
| 362 | fMaxTextureSize = SkTMin(fMaxTextureSize, 4096); |
| 363 | } |
| 364 | // Our render targets are always created with textures as the color |
| 365 | // attachment, hence this min: |
| 366 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 367 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 368 | // TODO: check if RT's larger than 4k incur a performance cost on ARM. |
| 369 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 370 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 371 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 372 | // 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] | 373 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 374 | |
| 375 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 376 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 377 | fOversizedStencilSupport = true; |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 378 | fSampleShadingSupport = features.sampleRateShading; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 381 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, |
| 382 | const VkPhysicalDeviceFeatures& features) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 383 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 384 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 385 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 386 | |
| 387 | // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config. |
| 388 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 389 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 390 | // Vulkan doesn't support a single channel format stored in alpha. |
| 391 | if (GrPixelConfigIsAlphaOnly(config) && |
| 392 | kAlpha_8_as_Alpha_GrPixelConfig != config) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 393 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR(); |
| 394 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 395 | } else { |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 396 | if (kGray_8_GrPixelConfig == config || |
| 397 | kGray_8_as_Red_GrPixelConfig == config) { |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 398 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA(); |
| 399 | } else if (kRGBA_4444_GrPixelConfig == config) { |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 400 | // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we |
| 401 | // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads |
| 402 | // or writing to outputs. Since we're not actually changing the data at all, the |
| 403 | // only extra work is the swizzle in the shader for all operations. |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 404 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA(); |
| 405 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 406 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 407 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 408 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 409 | } |
| 410 | } |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 411 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 412 | // 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] | 413 | shaderCaps->fUsesPrecisionModifiers = true; |
| 414 | shaderCaps->fFlatInterpolationSupport = true; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 415 | // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 416 | // to be true with Vulkan as well. |
| 417 | shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 418 | |
| 419 | // GrShaderCaps |
| 420 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 421 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 422 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 423 | shaderCaps->fGeometryShaderSupport = features.geometryShader; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 424 | shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 425 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 426 | shaderCaps->fDualSourceBlendingSupport = features.dualSrcBlend; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 427 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 428 | shaderCaps->fIntegerSupport = true; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 429 | shaderCaps->fVertexIDSupport = true; |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 430 | shaderCaps->fFPManipulationSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 431 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 432 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 433 | shaderCaps->fFloatIs32Bits = true; |
| 434 | shaderCaps->fHalfIs32Bits = false; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 435 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 436 | // SPIR-V supports unsigned integers. |
| 437 | shaderCaps->fUnsignedSupport = true; |
| 438 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 439 | shaderCaps->fMaxVertexSamplers = |
| 440 | shaderCaps->fMaxGeometrySamplers = |
| 441 | shaderCaps->fMaxFragmentSamplers = SkTMin( |
| 442 | SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 443 | properties.limits.maxPerStageDescriptorSamplers), |
| 444 | (uint32_t)INT_MAX); |
| 445 | shaderCaps->fMaxCombinedSamplers = SkTMin( |
| 446 | SkTMin(properties.limits.maxDescriptorSetSampledImages, |
| 447 | properties.limits.maxDescriptorSetSamplers), |
| 448 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 449 | } |
| 450 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 451 | bool stencil_format_supported(const GrVkInterface* interface, |
| 452 | VkPhysicalDevice physDev, |
| 453 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 454 | VkFormatProperties props; |
| 455 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 456 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 457 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 458 | } |
| 459 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 460 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 461 | // List of legal stencil formats (though perhaps not supported on |
| 462 | // 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] | 463 | // 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] | 464 | // 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] | 465 | static const StencilFormat |
| 466 | // internal Format stencil bits total bits packed? |
| 467 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 468 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }, |
| 469 | gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 470 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 471 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
| 472 | fPreferedStencilFormat = gS8; |
| 473 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
| 474 | fPreferedStencilFormat = gD24S8; |
| 475 | } else { |
| 476 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
| 477 | fPreferedStencilFormat = gD32S8; |
| 478 | } |
| 479 | } |
| 480 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 481 | void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice physDev, |
| 482 | const VkPhysicalDeviceProperties& properties) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 483 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 484 | VkFormat format; |
| 485 | if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) { |
Greg Daniel | 0190787 | 2017-05-23 15:21:02 -0400 | [diff] [blame] | 486 | if (!GrPixelConfigIsSRGB(static_cast<GrPixelConfig>(i)) || fSRGBSupport) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 487 | fConfigTable[i].init(interface, physDev, properties, format); |
Greg Daniel | 0190787 | 2017-05-23 15:21:02 -0400 | [diff] [blame] | 488 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
| 494 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 495 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 496 | *flags = *flags | kTextureable_Flag; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 497 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 498 | // Ganesh assumes that all renderable surfaces are also texturable |
| 499 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
| 500 | *flags = *flags | kRenderable_Flag; |
| 501 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 505 | *flags = *flags | kBlitSrc_Flag; |
| 506 | } |
| 507 | |
| 508 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 509 | *flags = *flags | kBlitDst_Flag; |
| 510 | } |
| 511 | } |
| 512 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 513 | void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface, |
| 514 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 515 | const VkPhysicalDeviceProperties& physProps, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 516 | VkFormat format) { |
| 517 | VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 518 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 519 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 520 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 521 | VkImageFormatProperties properties; |
| 522 | GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev, |
| 523 | format, |
| 524 | VK_IMAGE_TYPE_2D, |
| 525 | VK_IMAGE_TILING_OPTIMAL, |
| 526 | usage, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 527 | 0, // createFlags |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 528 | &properties)); |
| 529 | VkSampleCountFlags flags = properties.sampleCounts; |
| 530 | if (flags & VK_SAMPLE_COUNT_1_BIT) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 531 | fColorSampleCounts.push(1); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 532 | } |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 533 | if (kImagination_VkVendor == physProps.vendorID) { |
| 534 | // MSAA does not work on imagination |
| 535 | return; |
| 536 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 537 | if (flags & VK_SAMPLE_COUNT_2_BIT) { |
| 538 | fColorSampleCounts.push(2); |
| 539 | } |
| 540 | if (flags & VK_SAMPLE_COUNT_4_BIT) { |
| 541 | fColorSampleCounts.push(4); |
| 542 | } |
| 543 | if (flags & VK_SAMPLE_COUNT_8_BIT) { |
| 544 | fColorSampleCounts.push(8); |
| 545 | } |
| 546 | if (flags & VK_SAMPLE_COUNT_16_BIT) { |
| 547 | fColorSampleCounts.push(16); |
| 548 | } |
| 549 | if (flags & VK_SAMPLE_COUNT_32_BIT) { |
| 550 | fColorSampleCounts.push(32); |
| 551 | } |
| 552 | if (flags & VK_SAMPLE_COUNT_64_BIT) { |
| 553 | fColorSampleCounts.push(64); |
| 554 | } |
| 555 | } |
| 556 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 557 | void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, |
| 558 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 559 | const VkPhysicalDeviceProperties& properties, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 560 | VkFormat format) { |
| 561 | VkFormatProperties props; |
| 562 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 563 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 564 | InitConfigFlags(props.linearTilingFeatures, &fLinearFlags); |
| 565 | InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 566 | if (fOptimalFlags & kRenderable_Flag) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 567 | this->initSampleCounts(interface, physDev, properties, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 568 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 569 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 570 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 571 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const { |
| 572 | requestedCount = SkTMax(1, requestedCount); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 573 | int count = fConfigTable[config].fColorSampleCounts.count(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 574 | |
| 575 | if (!count) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 579 | if (1 == requestedCount) { |
| 580 | SkASSERT(fConfigTable[config].fColorSampleCounts.count() && |
| 581 | fConfigTable[config].fColorSampleCounts[0] == 1); |
| 582 | return 1; |
| 583 | } |
| 584 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 585 | for (int i = 0; i < count; ++i) { |
| 586 | if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) { |
| 587 | return fConfigTable[config].fColorSampleCounts[i]; |
| 588 | } |
| 589 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | int GrVkCaps::maxRenderTargetSampleCount(GrPixelConfig config) const { |
| 594 | const auto& table = fConfigTable[config].fColorSampleCounts; |
| 595 | if (!table.count()) { |
| 596 | return 0; |
| 597 | } |
| 598 | return table[table.count() - 1]; |
Brian Salomon | d653cac | 2018-02-01 13:58:00 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 601 | bool GrVkCaps::surfaceSupportsWritePixels(const GrSurface* surface) const { |
| 602 | if (auto rt = surface->asRenderTarget()) { |
| 603 | return rt->numColorSamples() <= 1 && SkToBool(surface->asTexture()); |
| 604 | } |
| 605 | return true; |
| 606 | } |
| 607 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 608 | bool validate_image_info(VkFormat format, SkColorType ct, GrPixelConfig* config) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 609 | *config = kUnknown_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 610 | |
| 611 | switch (ct) { |
| 612 | case kUnknown_SkColorType: |
| 613 | return false; |
| 614 | case kAlpha_8_SkColorType: |
| 615 | if (VK_FORMAT_R8_UNORM == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 616 | *config = kAlpha_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 617 | } |
| 618 | break; |
| 619 | case kRGB_565_SkColorType: |
| 620 | if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 621 | *config = kRGB_565_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 622 | } |
| 623 | break; |
| 624 | case kARGB_4444_SkColorType: |
| 625 | if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 626 | *config = kRGBA_4444_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 627 | } |
| 628 | break; |
| 629 | case kRGBA_8888_SkColorType: |
| 630 | if (VK_FORMAT_R8G8B8A8_UNORM == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 631 | *config = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 632 | } else if (VK_FORMAT_R8G8B8A8_SRGB == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 633 | *config = kSRGBA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 634 | } |
| 635 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 636 | case kRGB_888x_SkColorType: |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 637 | // TODO: VK_FORMAT_R8G8B8_UNORM |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 638 | return false; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 639 | case kBGRA_8888_SkColorType: |
| 640 | if (VK_FORMAT_B8G8R8A8_UNORM == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 641 | *config = kBGRA_8888_GrPixelConfig; |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 642 | } else if (VK_FORMAT_B8G8R8A8_SRGB == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 643 | *config = kSBGRA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 644 | } |
| 645 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 646 | case kRGBA_1010102_SkColorType: |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 647 | if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) { |
| 648 | *config = kRGBA_1010102_GrPixelConfig; |
| 649 | } |
| 650 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 651 | case kRGB_101010x_SkColorType: |
| 652 | return false; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 653 | case kGray_8_SkColorType: |
| 654 | if (VK_FORMAT_R8_UNORM == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 655 | *config = kGray_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 656 | } |
| 657 | break; |
| 658 | case kRGBA_F16_SkColorType: |
| 659 | if (VK_FORMAT_R16G16B16A16_SFLOAT == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 660 | *config = kRGBA_half_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 661 | } |
| 662 | break; |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 663 | case kRGBA_F32_SkColorType: |
| 664 | if (VK_FORMAT_R32G32B32A32_SFLOAT == format) { |
| 665 | *config = kRGBA_float_GrPixelConfig; |
| 666 | } |
| 667 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 668 | } |
| 669 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 670 | return kUnknown_GrPixelConfig != *config; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 671 | } |
| 672 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 673 | bool GrVkCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct, |
| 674 | GrPixelConfig* config) const { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 675 | GrVkImageInfo imageInfo; |
| 676 | if (!tex.getVkImageInfo(&imageInfo)) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 677 | return false; |
| 678 | } |
| 679 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 680 | return validate_image_info(imageInfo.fFormat, ct, config); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | bool GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct, |
| 684 | GrPixelConfig* config) const { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 685 | GrVkImageInfo imageInfo; |
| 686 | if (!rt.getVkImageInfo(&imageInfo)) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 690 | return validate_image_info(imageInfo.fFormat, ct, config); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | bool GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct, |
| 694 | GrPixelConfig* config) const { |
| 695 | const VkFormat* vkFormat = format.getVkFormat(); |
| 696 | if (!vkFormat) { |
| 697 | return false; |
| 698 | } |
| 699 | return validate_image_info(*vkFormat, ct, config); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 700 | } |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 701 | |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 702 | #ifdef GR_TEST_UTILS |
| 703 | GrBackendFormat GrVkCaps::onCreateFormatFromBackendTexture( |
| 704 | const GrBackendTexture& backendTex) const { |
| 705 | GrVkImageInfo vkInfo; |
| 706 | SkAssertResult(backendTex.getVkImageInfo(&vkInfo)); |
| 707 | return GrBackendFormat::MakeVk(vkInfo.fFormat); |
| 708 | } |
| 709 | #endif |
| 710 | |