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