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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrBackendSurface.h" |
| 9 | #include "include/gpu/GrRenderTarget.h" |
| 10 | #include "include/gpu/vk/GrVkBackendContext.h" |
| 11 | #include "include/gpu/vk/GrVkExtensions.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrShaderCaps.h" |
| 14 | #include "src/gpu/SkGr.h" |
| 15 | #include "src/gpu/vk/GrVkCaps.h" |
| 16 | #include "src/gpu/vk/GrVkInterface.h" |
| 17 | #include "src/gpu/vk/GrVkTexture.h" |
| 18 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 19 | |
| 20 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 21 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 22 | uint32_t instanceVersion, uint32_t physicalDeviceVersion, |
| 23 | const GrVkExtensions& extensions) |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 24 | : INHERITED(contextOptions) { |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 25 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 26 | /************************************************************************** |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 27 | * GrCaps fields |
| 28 | **************************************************************************/ |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 29 | fMipMapSupport = true; // always available in Vulkan |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 30 | fSRGBSupport = true; // always available in Vulkan |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 31 | fNPOTTextureTileSupport = true; // always available in Vulkan |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 32 | fDiscardRenderTargetSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | fReuseScratchTextures = true; //TODO: figure this out |
| 34 | fGpuTracingSupport = false; //TODO: figure this out |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 35 | fCompressedTexSubImageSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 36 | fOversizedStencilSupport = false; //TODO: figure this out |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 37 | fInstanceAttribSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 38 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 39 | fSemaphoreSupport = true; // always available in Vulkan |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 40 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 41 | fCrossContextTextureSupport = true; |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 42 | fHalfFloatVertexAttributeSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 44 | fTransferBufferSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | |
| 46 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 47 | fMaxTextureSize = 4096; // minimum required by spec |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 48 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 49 | fDynamicStateArrayGeometryProcessorTextureSupport = true; |
| 50 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 51 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 53 | this->init(contextOptions, vkInterface, physDev, features, physicalDeviceVersion, extensions); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 56 | bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 57 | bool* rectsMustMatch, bool* disallowSubrect) const { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 58 | // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false. |
| 59 | *rectsMustMatch = false; |
| 60 | *disallowSubrect = false; |
| 61 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 62 | // We can always succeed here with either a CopyImage (none msaa src) or ResolveImage (msaa). |
| 63 | // For CopyImage we can make a simple texture, for ResolveImage we require the dst to be a |
| 64 | // render target as well. |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 65 | desc->fConfig = src->config(); |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 66 | if (src->numColorSamples() > 1 || src->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 67 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
| 68 | } else { |
| 69 | // Just going to use CopyImage here |
| 70 | desc->fFlags = kNone_GrSurfaceFlags; |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 76 | static int get_compatible_format_class(GrPixelConfig config) { |
| 77 | switch (config) { |
| 78 | case kAlpha_8_GrPixelConfig: |
| 79 | case kAlpha_8_as_Red_GrPixelConfig: |
| 80 | case kGray_8_GrPixelConfig: |
| 81 | case kGray_8_as_Red_GrPixelConfig: |
| 82 | return 1; |
| 83 | case kRGB_565_GrPixelConfig: |
| 84 | case kRGBA_4444_GrPixelConfig: |
| 85 | case kRG_88_GrPixelConfig: |
| 86 | case kAlpha_half_GrPixelConfig: |
| 87 | case kAlpha_half_as_Red_GrPixelConfig: |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 88 | case kR_16_GrPixelConfig: |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 89 | return 2; |
| 90 | case kRGB_888_GrPixelConfig: |
| 91 | return 3; |
| 92 | case kRGBA_8888_GrPixelConfig: |
| 93 | case kRGB_888X_GrPixelConfig: |
| 94 | case kBGRA_8888_GrPixelConfig: |
| 95 | case kSRGBA_8888_GrPixelConfig: |
| 96 | case kSBGRA_8888_GrPixelConfig: |
| 97 | case kRGBA_1010102_GrPixelConfig: |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 98 | case kRG_1616_GrPixelConfig: |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 99 | return 4; |
| 100 | case kRGBA_half_GrPixelConfig: |
| 101 | case kRGBA_half_Clamped_GrPixelConfig: |
| 102 | case kRG_float_GrPixelConfig: |
| 103 | return 5; |
| 104 | case kRGBA_float_GrPixelConfig: |
| 105 | return 6; |
| 106 | case kRGB_ETC1_GrPixelConfig: |
| 107 | return 7; |
| 108 | case kUnknown_GrPixelConfig: |
| 109 | case kAlpha_8_as_Alpha_GrPixelConfig: |
| 110 | case kGray_8_as_Lum_GrPixelConfig: |
| 111 | SK_ABORT("Unsupported Vulkan pixel config"); |
| 112 | return 0; |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 113 | |
| 114 | // Experimental (for Y416 and mutant P016/P010) |
| 115 | case kRGBA_16161616_GrPixelConfig: |
| 116 | return 8; |
| 117 | case kRG_half_GrPixelConfig: |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 118 | return 4; |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 119 | } |
| 120 | SK_ABORT("Invalid pixel config"); |
| 121 | return 0; |
| 122 | } |
| 123 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 124 | bool GrVkCaps::canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, bool dstHasYcbcr, |
| 125 | GrPixelConfig srcConfig, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 126 | if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) { |
| 127 | return false; |
| 128 | } |
| 129 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 130 | if (dstHasYcbcr || srcHasYcbcr) { |
| 131 | return false; |
| 132 | } |
| 133 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 134 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 135 | // as image usage flags. |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 136 | if (get_compatible_format_class(srcConfig) != get_compatible_format_class(dstConfig)) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
| 140 | if (this->shaderCaps()->configOutputSwizzle(srcConfig) != |
| 141 | this->shaderCaps()->configOutputSwizzle(dstConfig)) { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | bool GrVkCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear, |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 149 | bool dstHasYcbcr, GrPixelConfig srcConfig, int srcSampleCnt, |
| 150 | bool srcIsLinear, bool srcHasYcbcr) const { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 151 | |
| 152 | VkFormat dstFormat; |
| 153 | SkAssertResult(GrPixelConfigToVkFormat(dstConfig, &dstFormat)); |
| 154 | VkFormat srcFormat; |
| 155 | SkAssertResult(GrPixelConfigToVkFormat(srcConfig, &srcFormat)); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 156 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 157 | // as image usage flags. |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 158 | if (!this->formatCanBeDstofBlit(dstFormat, dstIsLinear) || |
| 159 | !this->formatCanBeSrcofBlit(srcFormat, srcIsLinear)) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 160 | return false; |
| 161 | } |
| 162 | |
| 163 | if (this->shaderCaps()->configOutputSwizzle(srcConfig) != |
| 164 | this->shaderCaps()->configOutputSwizzle(dstConfig)) { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | // We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 169 | // resolved msaa though. |
| 170 | if (dstSampleCnt > 1 || srcSampleCnt > 1) { |
| 171 | return false; |
| 172 | } |
| 173 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 174 | if (dstHasYcbcr || srcHasYcbcr) { |
| 175 | return false; |
| 176 | } |
| 177 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 178 | return true; |
| 179 | } |
| 180 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 181 | bool GrVkCaps::canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt, bool dstHasYcbcr, |
| 182 | GrPixelConfig srcConfig, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 183 | // The src surface must be multisampled. |
| 184 | if (srcSampleCnt <= 1) { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | // The dst must not be multisampled. |
| 189 | if (dstSampleCnt > 1) { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | // Surfaces must have the same format. |
| 194 | if (dstConfig != srcConfig) { |
| 195 | return false; |
| 196 | } |
| 197 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 198 | if (dstHasYcbcr || srcHasYcbcr) { |
| 199 | return false; |
| 200 | } |
| 201 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 202 | return true; |
| 203 | } |
| 204 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 205 | bool GrVkCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 206 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 207 | GrPixelConfig dstConfig = dst->config(); |
| 208 | GrPixelConfig srcConfig = src->config(); |
| 209 | |
| 210 | // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g. |
| 211 | // PromiseImage which won't get instantiated right away. Does this need a similar thing like the |
| 212 | // tracking of external or rectangle textures in GL? For now we don't create linear textures |
| 213 | // internally, and I don't believe anyone is wrapping them. |
| 214 | bool srcIsLinear = false; |
| 215 | bool dstIsLinear = false; |
| 216 | |
| 217 | int dstSampleCnt = 0; |
| 218 | int srcSampleCnt = 0; |
| 219 | if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 220 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 221 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 222 | // to stop and start the VkRenderPass which we don't have access to. |
| 223 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 224 | return false; |
| 225 | } |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 226 | dstSampleCnt = rtProxy->numColorSamples(); |
| 227 | } |
| 228 | if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 229 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 230 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 231 | // to stop and start the VkRenderPass which we don't have access to. |
| 232 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 233 | return false; |
| 234 | } |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 235 | srcSampleCnt = rtProxy->numColorSamples(); |
| 236 | } |
| 237 | SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy())); |
| 238 | SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy())); |
| 239 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 240 | bool dstHasYcbcr = false; |
| 241 | if (auto ycbcr = dst->backendFormat().getVkYcbcrConversionInfo()) { |
| 242 | if (ycbcr->isValid()) { |
| 243 | dstHasYcbcr = true; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | bool srcHasYcbcr = false; |
| 248 | if (auto ycbcr = src->backendFormat().getVkYcbcrConversionInfo()) { |
| 249 | if (ycbcr->isValid()) { |
| 250 | srcHasYcbcr = true; |
| 251 | } |
| 252 | } |
| 253 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 254 | return this->canCopyImage(dstConfig, dstSampleCnt, dstHasYcbcr, |
| 255 | srcConfig, srcSampleCnt, srcHasYcbcr) || |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 256 | this->canCopyAsBlit(dstConfig, dstSampleCnt, dstIsLinear, dstHasYcbcr, |
| 257 | srcConfig, srcSampleCnt, srcIsLinear, srcHasYcbcr) || |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 258 | this->canCopyAsResolve(dstConfig, dstSampleCnt, dstHasYcbcr, |
| 259 | srcConfig, srcSampleCnt, srcHasYcbcr); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 262 | template<typename T> T* get_extension_feature_struct(const VkPhysicalDeviceFeatures2& features, |
| 263 | VkStructureType type) { |
| 264 | // All Vulkan structs that could be part of the features chain will start with the |
| 265 | // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader |
| 266 | // so we can get access to the pNext for the next struct. |
| 267 | struct CommonVulkanHeader { |
| 268 | VkStructureType sType; |
| 269 | void* pNext; |
| 270 | }; |
| 271 | |
| 272 | void* pNext = features.pNext; |
| 273 | while (pNext) { |
| 274 | CommonVulkanHeader* header = static_cast<CommonVulkanHeader*>(pNext); |
| 275 | if (header->sType == type) { |
| 276 | return static_cast<T*>(pNext); |
| 277 | } |
| 278 | pNext = header->pNext; |
| 279 | } |
| 280 | return nullptr; |
| 281 | } |
| 282 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 283 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 284 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 285 | uint32_t physicalDeviceVersion, const GrVkExtensions& extensions) { |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 286 | VkPhysicalDeviceProperties properties; |
| 287 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 288 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 289 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 290 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 291 | |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 292 | SkASSERT(physicalDeviceVersion <= properties.apiVersion); |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 293 | |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 294 | if (extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 1)) { |
| 295 | fSupportsSwapchain = true; |
| 296 | } |
| 297 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 298 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 299 | extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { |
| 300 | fSupportsPhysicalDeviceProperties2 = true; |
| 301 | } |
| 302 | |
| 303 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 304 | extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { |
| 305 | fSupportsMemoryRequirements2 = true; |
| 306 | } |
| 307 | |
| 308 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 309 | extensions.hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { |
| 310 | fSupportsBindMemory2 = true; |
| 311 | } |
| 312 | |
| 313 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 314 | extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { |
| 315 | fSupportsMaintenance1 = true; |
| 316 | } |
| 317 | |
| 318 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 319 | extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) { |
| 320 | fSupportsMaintenance2 = true; |
| 321 | } |
| 322 | |
| 323 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 324 | extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { |
| 325 | fSupportsMaintenance3 = true; |
| 326 | } |
| 327 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 328 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 329 | (extensions.hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) && |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 330 | this->supportsMemoryRequirements2())) { |
| 331 | fSupportsDedicatedAllocation = true; |
| 332 | } |
| 333 | |
| 334 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 335 | (extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1) && |
| 336 | this->supportsPhysicalDeviceProperties2() && |
| 337 | extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, 1) && |
| 338 | this->supportsDedicatedAllocation())) { |
| 339 | fSupportsExternalMemory = true; |
| 340 | } |
| 341 | |
| 342 | #ifdef SK_BUILD_FOR_ANDROID |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 343 | // Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they |
| 344 | // 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] | 345 | if (extensions.hasExtension( |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 346 | VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, 2) && |
| 347 | /* extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1) &&*/ |
| 348 | this->supportsExternalMemory() && |
| 349 | this->supportsBindMemory2()) { |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 350 | fSupportsAndroidHWBExternalMemory = true; |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 351 | fSupportsAHardwareBufferImages = true; |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 352 | } |
| 353 | #endif |
| 354 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 355 | auto ycbcrFeatures = |
| 356 | get_extension_feature_struct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>( |
| 357 | features, |
| 358 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES); |
| 359 | if (ycbcrFeatures && ycbcrFeatures->samplerYcbcrConversion && |
| 360 | fSupportsAndroidHWBExternalMemory && |
| 361 | (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 362 | (extensions.hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1) && |
| 363 | this->supportsMaintenance1() && |
| 364 | this->supportsBindMemory2() && |
| 365 | this->supportsMemoryRequirements2() && |
| 366 | this->supportsPhysicalDeviceProperties2()))) { |
| 367 | fSupportsYcbcrConversion = true; |
| 368 | } |
| 369 | // We always push back the default GrVkYcbcrConversionInfo so that the case of no conversion |
| 370 | // will return a key of 0. |
| 371 | fYcbcrInfos.push_back(GrVkYcbcrConversionInfo()); |
| 372 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 373 | this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions); |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 374 | this->initShaderCaps(properties, features); |
Greg Daniel | f3b1162 | 2018-03-01 15:01:27 -0500 | [diff] [blame] | 375 | |
| 376 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 377 | #if defined(SK_CPU_X86) |
| 378 | // We need to do this before initing the config table since it uses fSRGBSupport |
| 379 | if (kImagination_VkVendor == properties.vendorID) { |
| 380 | fSRGBSupport = false; |
| 381 | } |
| 382 | #endif |
| 383 | } |
| 384 | |
Chris Dalton | 8e738a2 | 2018-10-05 16:41:44 -0600 | [diff] [blame] | 385 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 386 | // A "clear" load for the CCPR atlas runs faster on QC than a "discard" load followed by a |
| 387 | // scissored clear. |
| 388 | // On NVIDIA and Intel, the discard load followed by clear is faster. |
| 389 | // TODO: Evaluate on ARM, Imagination, and ATI. |
| 390 | fPreferFullscreenClears = true; |
| 391 | } |
| 392 | |
Greg Daniel | 44e69f9 | 2019-03-20 11:18:25 -0400 | [diff] [blame] | 393 | if (kQualcomm_VkVendor == properties.vendorID || kARM_VkVendor == properties.vendorID) { |
| 394 | // On Qualcomm and ARM mapping a gpu buffer and doing both reads and writes to it is slow. |
| 395 | // Thus for index and vertex buffers we will force to use a cpu side buffer and then copy |
| 396 | // the whole buffer up to the gpu. |
Greg Daniel | 78e6a4c | 2019-03-19 14:13:36 -0400 | [diff] [blame] | 397 | fBufferMapThreshold = SK_MaxS32; |
| 398 | } |
| 399 | |
| 400 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 401 | // On Qualcomm it looks like using vkCmdUpdateBuffer is slower than using a transfer buffer |
| 402 | // even for small sizes. |
| 403 | fAvoidUpdateBuffers = true; |
| 404 | } |
| 405 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 406 | if (kARM_VkVendor == properties.vendorID) { |
| 407 | // ARM seems to do better with more fine triangles as opposed to using the sample mask. |
| 408 | // (At least in our current round rect op.) |
| 409 | fPreferTrianglesOverSampleMask = true; |
| 410 | } |
Greg Daniel | 78e6a4c | 2019-03-19 14:13:36 -0400 | [diff] [blame] | 411 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 412 | this->initFormatTable(vkInterface, physDev, properties); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 413 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 414 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 415 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 416 | this->applyDriverCorrectnessWorkarounds(properties); |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 417 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 418 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 419 | this->applyOptionsOverrides(contextOptions); |
| 420 | fShaderCaps->applyOptionsOverrides(contextOptions); |
| 421 | } |
| 422 | |
| 423 | void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) { |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 424 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 425 | fMustDoCopiesFromOrigin = true; |
Brian Salomon | a585fe9 | 2019-04-09 14:57:00 -0400 | [diff] [blame] | 426 | // Transfer doesn't support this workaround. |
| 427 | fTransferBufferSupport = false; |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 430 | #if defined(SK_BUILD_FOR_WIN) |
Greg Daniel | 900e5c8 | 2018-08-28 10:59:24 -0400 | [diff] [blame] | 431 | if (kNvidia_VkVendor == properties.vendorID || kIntel_VkVendor == properties.vendorID) { |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 432 | fMustSleepOnTearDown = true; |
| 433 | } |
| 434 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 435 | if (kImagination_VkVendor == properties.vendorID) { |
| 436 | fMustSleepOnTearDown = true; |
| 437 | } |
| 438 | #endif |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 439 | |
| 440 | // AMD seems to have issues binding new VkPipelines inside a secondary command buffer. |
| 441 | // Current workaround is to use a different secondary command buffer for each new VkPipeline. |
| 442 | if (kAMD_VkVendor == properties.vendorID) { |
| 443 | fNewCBOnPipelineChange = true; |
| 444 | } |
| 445 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 446 | // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages. |
| 447 | if (kARM_VkVendor == properties.vendorID) { |
| 448 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 449 | } |
| 450 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 451 | //////////////////////////////////////////////////////////////////////////// |
| 452 | // GrCaps workarounds |
| 453 | //////////////////////////////////////////////////////////////////////////// |
| 454 | |
| 455 | if (kARM_VkVendor == properties.vendorID) { |
| 456 | fInstanceAttribSupport = false; |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 457 | fAvoidWritePixelsFastPath = true; // bugs.skia.org/8064 |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 461 | if (kAMD_VkVendor == properties.vendorID) { |
| 462 | fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32); |
| 463 | } |
| 464 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 465 | //////////////////////////////////////////////////////////////////////////// |
| 466 | // GrShaderCaps workarounds |
| 467 | //////////////////////////////////////////////////////////////////////////// |
| 468 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 469 | if (kImagination_VkVendor == properties.vendorID) { |
| 470 | fShaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 471 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | int get_max_sample_count(VkSampleCountFlags flags) { |
| 475 | SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT); |
| 476 | if (!(flags & VK_SAMPLE_COUNT_2_BIT)) { |
| 477 | return 0; |
| 478 | } |
| 479 | if (!(flags & VK_SAMPLE_COUNT_4_BIT)) { |
| 480 | return 2; |
| 481 | } |
| 482 | if (!(flags & VK_SAMPLE_COUNT_8_BIT)) { |
| 483 | return 4; |
| 484 | } |
| 485 | if (!(flags & VK_SAMPLE_COUNT_16_BIT)) { |
| 486 | return 8; |
| 487 | } |
| 488 | if (!(flags & VK_SAMPLE_COUNT_32_BIT)) { |
| 489 | return 16; |
| 490 | } |
| 491 | if (!(flags & VK_SAMPLE_COUNT_64_BIT)) { |
| 492 | return 32; |
| 493 | } |
| 494 | return 64; |
| 495 | } |
| 496 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 497 | void GrVkCaps::initGrCaps(const GrVkInterface* vkInterface, |
| 498 | VkPhysicalDevice physDev, |
| 499 | const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 500 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 501 | const VkPhysicalDeviceFeatures2& features, |
| 502 | const GrVkExtensions& extensions) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 503 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 504 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 505 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 506 | // we ever find that need. |
| 507 | static const uint32_t kMaxVertexAttributes = 64; |
| 508 | fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 509 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 510 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 511 | // 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] | 512 | fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 513 | fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
Adrienne Walker | 724afe8 | 2018-05-15 11:36:26 -0700 | [diff] [blame] | 514 | if (fDriverBugWorkarounds.max_texture_size_limit_4096) { |
| 515 | fMaxTextureSize = SkTMin(fMaxTextureSize, 4096); |
| 516 | } |
| 517 | // Our render targets are always created with textures as the color |
| 518 | // attachment, hence this min: |
| 519 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 520 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 521 | // TODO: check if RT's larger than 4k incur a performance cost on ARM. |
| 522 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 523 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 524 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 525 | // 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] | 526 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 527 | |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 528 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag | kAsyncRead_MapFlag; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 529 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 530 | fOversizedStencilSupport = true; |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 531 | |
| 532 | if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2) && |
| 533 | this->supportsPhysicalDeviceProperties2()) { |
| 534 | |
| 535 | VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps; |
| 536 | blendProps.sType = |
| 537 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT; |
| 538 | blendProps.pNext = nullptr; |
| 539 | |
| 540 | VkPhysicalDeviceProperties2 props; |
| 541 | props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; |
| 542 | props.pNext = &blendProps; |
| 543 | |
| 544 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props)); |
| 545 | |
| 546 | if (blendProps.advancedBlendAllOperations == VK_TRUE) { |
| 547 | fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
| 548 | |
| 549 | auto blendFeatures = |
| 550 | get_extension_feature_struct<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>( |
| 551 | features, |
| 552 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT); |
| 553 | if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) { |
| 554 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 555 | } else { |
| 556 | // TODO: Currently non coherent blends are not supported in our vulkan backend. They |
| 557 | // require us to support self dependencies in our render passes. |
| 558 | // fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 559 | } |
| 560 | } |
| 561 | } |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 564 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 565 | const VkPhysicalDeviceFeatures2& features) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 566 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 567 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 568 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 569 | |
| 570 | // fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config. |
| 571 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 572 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 573 | // Vulkan doesn't support a single channel format stored in alpha. |
| 574 | if (GrPixelConfigIsAlphaOnly(config) && |
| 575 | kAlpha_8_as_Alpha_GrPixelConfig != config) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 576 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR(); |
| 577 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 578 | } else { |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 579 | if (kGray_8_GrPixelConfig == config || |
| 580 | kGray_8_as_Red_GrPixelConfig == config) { |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 581 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA(); |
| 582 | } else if (kRGBA_4444_GrPixelConfig == config) { |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 583 | // The vulkan spec does not require R4G4B4A4 to be supported for texturing so we |
| 584 | // store the data in a B4G4R4A4 texture and then swizzle it when doing texture reads |
| 585 | // or writing to outputs. Since we're not actually changing the data at all, the |
| 586 | // only extra work is the swizzle in the shader for all operations. |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 587 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::BGRA(); |
| 588 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::BGRA(); |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 589 | } else if (kRGB_888X_GrPixelConfig == config) { |
| 590 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGB1(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 591 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 592 | shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA(); |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 593 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 594 | } |
| 595 | } |
egdaniel | 67acb83 | 2016-02-26 08:32:20 -0800 | [diff] [blame] | 596 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 597 | // 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] | 598 | shaderCaps->fUsesPrecisionModifiers = true; |
| 599 | shaderCaps->fFlatInterpolationSupport = true; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 600 | // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 601 | // to be true with Vulkan as well. |
| 602 | shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 603 | |
| 604 | // GrShaderCaps |
| 605 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 606 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 607 | |
Ethan Nicholas | 6ac8d36 | 2019-01-22 21:43:55 +0000 | [diff] [blame] | 608 | // FIXME: http://skbug.com/7733: Disable geometry shaders until Intel/Radeon GMs draw correctly. |
| 609 | // shaderCaps->fGeometryShaderSupport = |
| 610 | // shaderCaps->fGSInvocationsSupport = features.features.geometryShader; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 611 | |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 612 | shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 613 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 614 | shaderCaps->fIntegerSupport = true; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 615 | shaderCaps->fVertexIDSupport = true; |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 616 | shaderCaps->fFPManipulationSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 617 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 618 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 619 | shaderCaps->fFloatIs32Bits = true; |
| 620 | shaderCaps->fHalfIs32Bits = false; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 621 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 622 | shaderCaps->fMaxFragmentSamplers = SkTMin( |
| 623 | SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 624 | properties.limits.maxPerStageDescriptorSamplers), |
| 625 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 626 | } |
| 627 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 628 | bool stencil_format_supported(const GrVkInterface* interface, |
| 629 | VkPhysicalDevice physDev, |
| 630 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 631 | VkFormatProperties props; |
| 632 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 633 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 634 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 635 | } |
| 636 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 637 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 638 | // List of legal stencil formats (though perhaps not supported on |
| 639 | // 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] | 640 | // 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] | 641 | // 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] | 642 | static const StencilFormat |
| 643 | // internal Format stencil bits total bits packed? |
| 644 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 645 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }, |
| 646 | gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 647 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 648 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 649 | fPreferredStencilFormat = gS8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 650 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 651 | fPreferredStencilFormat = gD24S8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 652 | } else { |
| 653 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 654 | fPreferredStencilFormat = gD32S8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 658 | static bool format_is_srgb(VkFormat format) { |
| 659 | switch (format) { |
| 660 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 661 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 662 | return true; |
| 663 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 664 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 665 | case VK_FORMAT_R8G8B8A8_SINT: |
| 666 | case VK_FORMAT_R8G8B8_UNORM: |
| 667 | case VK_FORMAT_R8G8_UNORM: |
| 668 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: |
| 669 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 670 | case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 671 | case VK_FORMAT_R4G4B4A4_UNORM_PACK16: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 672 | case VK_FORMAT_R8_UNORM: |
| 673 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 674 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 675 | case VK_FORMAT_R32G32_SFLOAT: |
| 676 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 677 | case VK_FORMAT_R16_SFLOAT: |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 678 | case VK_FORMAT_R16_UNORM: |
| 679 | case VK_FORMAT_R16G16_UNORM: |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 680 | // Experimental (for Y416 and mutant P016/P010) |
| 681 | case VK_FORMAT_R16G16B16A16_UNORM: |
| 682 | case VK_FORMAT_R16G16_SFLOAT: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 683 | return false; |
| 684 | default: |
| 685 | SK_ABORT("Unsupported VkFormat"); |
| 686 | return false; |
| 687 | } |
| 688 | } |
| 689 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 690 | // These are all the valid VkFormats that we support in Skia. They are roughly ordered from most |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 691 | // frequently used to least to improve look up times in arrays. |
| 692 | static constexpr VkFormat kVkFormats[] = { |
| 693 | VK_FORMAT_R8G8B8A8_UNORM, |
| 694 | VK_FORMAT_R8_UNORM, |
| 695 | VK_FORMAT_B8G8R8A8_UNORM, |
| 696 | VK_FORMAT_R5G6B5_UNORM_PACK16, |
| 697 | VK_FORMAT_R16G16B16A16_SFLOAT, |
| 698 | VK_FORMAT_R16_SFLOAT, |
| 699 | VK_FORMAT_R8G8B8A8_SINT, |
| 700 | VK_FORMAT_R8G8B8_UNORM, |
| 701 | VK_FORMAT_R8G8_UNORM, |
| 702 | VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
| 703 | VK_FORMAT_B4G4R4A4_UNORM_PACK16, |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 704 | VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 705 | VK_FORMAT_R32G32B32A32_SFLOAT, |
| 706 | VK_FORMAT_R32G32_SFLOAT, |
| 707 | VK_FORMAT_R8G8B8A8_SRGB, |
| 708 | VK_FORMAT_B8G8R8A8_SRGB, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 709 | VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 710 | VK_FORMAT_R16_UNORM, |
| 711 | VK_FORMAT_R16G16_UNORM, |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 712 | // Experimental (for Y416 and mutant P016/P010) |
| 713 | VK_FORMAT_R16G16B16A16_UNORM, |
| 714 | VK_FORMAT_R16G16_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 715 | }; |
| 716 | |
| 717 | const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const { |
| 718 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 719 | "Size of VkFormats array must match static value in header"); |
| 720 | for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) { |
| 721 | if (kVkFormats[i] == format) { |
| 722 | return fFormatTable[i]; |
| 723 | } |
| 724 | } |
| 725 | SK_ABORT("Invalid VkFormat"); |
| 726 | static const FormatInfo kInvalidConfig; |
| 727 | return kInvalidConfig; |
| 728 | } |
| 729 | |
| 730 | void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 731 | const VkPhysicalDeviceProperties& properties) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 732 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 733 | "Size of VkFormats array must match static value in header"); |
| 734 | for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) { |
| 735 | VkFormat format = kVkFormats[i]; |
| 736 | if (!format_is_srgb(format) || fSRGBSupport) { |
| 737 | fFormatTable[i].init(interface, physDev, properties, format); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 742 | void GrVkCaps::FormatInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 743 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 744 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 745 | *flags = *flags | kTextureable_Flag; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 746 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 747 | // Ganesh assumes that all renderable surfaces are also texturable |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 748 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 749 | *flags = *flags | kRenderable_Flag; |
| 750 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 754 | *flags = *flags | kBlitSrc_Flag; |
| 755 | } |
| 756 | |
| 757 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 758 | *flags = *flags | kBlitDst_Flag; |
| 759 | } |
| 760 | } |
| 761 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 762 | void GrVkCaps::FormatInfo::initSampleCounts(const GrVkInterface* interface, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 763 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 764 | const VkPhysicalDeviceProperties& physProps, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 765 | VkFormat format) { |
| 766 | VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 767 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 768 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 769 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 770 | VkImageFormatProperties properties; |
| 771 | GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev, |
| 772 | format, |
| 773 | VK_IMAGE_TYPE_2D, |
| 774 | VK_IMAGE_TILING_OPTIMAL, |
| 775 | usage, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 776 | 0, // createFlags |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 777 | &properties)); |
| 778 | VkSampleCountFlags flags = properties.sampleCounts; |
| 779 | if (flags & VK_SAMPLE_COUNT_1_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 780 | fColorSampleCounts.push_back(1); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 781 | } |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 782 | if (kImagination_VkVendor == physProps.vendorID) { |
| 783 | // MSAA does not work on imagination |
| 784 | return; |
| 785 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 786 | if (flags & VK_SAMPLE_COUNT_2_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 787 | fColorSampleCounts.push_back(2); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 788 | } |
| 789 | if (flags & VK_SAMPLE_COUNT_4_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 790 | fColorSampleCounts.push_back(4); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 791 | } |
| 792 | if (flags & VK_SAMPLE_COUNT_8_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 793 | fColorSampleCounts.push_back(8); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 794 | } |
| 795 | if (flags & VK_SAMPLE_COUNT_16_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 796 | fColorSampleCounts.push_back(16); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 797 | } |
| 798 | if (flags & VK_SAMPLE_COUNT_32_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 799 | fColorSampleCounts.push_back(32); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 800 | } |
| 801 | if (flags & VK_SAMPLE_COUNT_64_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 802 | fColorSampleCounts.push_back(64); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 806 | void GrVkCaps::FormatInfo::init(const GrVkInterface* interface, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 807 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 808 | const VkPhysicalDeviceProperties& properties, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 809 | VkFormat format) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 810 | VkFormatProperties props; |
| 811 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 812 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 813 | InitConfigFlags(props.linearTilingFeatures, &fLinearFlags); |
| 814 | InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 815 | if (fOptimalFlags & kRenderable_Flag) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 816 | this->initSampleCounts(interface, physDev, properties, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 817 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 818 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 819 | |
Robert Phillips | 39ef2ef | 2019-05-15 08:45:53 -0400 | [diff] [blame] | 820 | bool GrVkCaps::isFormatTexturable(VkFormat format) const { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 821 | if (!GrVkFormatIsSupported(format)) { |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | const FormatInfo& info = this->getFormatInfo(format); |
| 826 | return SkToBool(FormatInfo::kTextureable_Flag & info.fOptimalFlags); |
| 827 | } |
| 828 | |
| 829 | bool GrVkCaps::isConfigTexturable(GrPixelConfig config) const { |
| 830 | VkFormat format; |
| 831 | if (!GrPixelConfigToVkFormat(config, &format)) { |
| 832 | return false; |
| 833 | } |
Robert Phillips | 39ef2ef | 2019-05-15 08:45:53 -0400 | [diff] [blame] | 834 | return this->isFormatTexturable(format); |
| 835 | } |
| 836 | |
| 837 | bool GrVkCaps::isFormatRenderable(VkFormat format) const { |
| 838 | return this->maxRenderTargetSampleCount(format) > 0; |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 839 | } |
| 840 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 841 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 842 | // Currently we don't allow RGB_888X to be renderable because we don't have a way to handle |
| 843 | // blends that reference dst alpha when the values in the dst alpha channel are uninitialized. |
| 844 | if (config == kRGB_888X_GrPixelConfig) { |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | VkFormat format; |
| 849 | if (!GrPixelConfigToVkFormat(config, &format)) { |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | return this->getRenderTargetSampleCount(requestedCount, format); |
| 854 | } |
| 855 | |
| 856 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 857 | requestedCount = SkTMax(1, requestedCount); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 858 | |
| 859 | const FormatInfo& info = this->getFormatInfo(format); |
| 860 | |
| 861 | int count = info.fColorSampleCounts.count(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 862 | |
| 863 | if (!count) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 867 | if (1 == requestedCount) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 868 | SkASSERT(info.fColorSampleCounts.count() && info.fColorSampleCounts[0] == 1); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 869 | return 1; |
| 870 | } |
| 871 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 872 | for (int i = 0; i < count; ++i) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 873 | if (info.fColorSampleCounts[i] >= requestedCount) { |
| 874 | return info.fColorSampleCounts[i]; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 875 | } |
| 876 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | int GrVkCaps::maxRenderTargetSampleCount(GrPixelConfig config) const { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 881 | // Currently we don't allow RGB_888X to be renderable because we don't have a way to handle |
| 882 | // blends that reference dst alpha when the values in the dst alpha channel are uninitialized. |
| 883 | if (config == kRGB_888X_GrPixelConfig) { |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | VkFormat format; |
| 888 | if (!GrPixelConfigToVkFormat(config, &format)) { |
| 889 | return 0; |
| 890 | } |
| 891 | return this->maxRenderTargetSampleCount(format); |
| 892 | } |
| 893 | |
| 894 | int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const { |
| 895 | const FormatInfo& info = this->getFormatInfo(format); |
| 896 | |
| 897 | const auto& table = info.fColorSampleCounts; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 898 | if (!table.count()) { |
| 899 | return 0; |
| 900 | } |
| 901 | return table[table.count() - 1]; |
Brian Salomon | d653cac | 2018-02-01 13:58:00 -0500 | [diff] [blame] | 902 | } |
| 903 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 904 | bool GrVkCaps::surfaceSupportsReadPixels(const GrSurface* surface) const { |
| 905 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 906 | // We can't directly read from a VkImage that has a ycbcr sampler. |
| 907 | if (tex->ycbcrConversionInfo().isValid()) { |
| 908 | return false; |
| 909 | } |
| 910 | } |
| 911 | return true; |
| 912 | } |
| 913 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 914 | bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const { |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 915 | if (auto rt = surface->asRenderTarget()) { |
| 916 | return rt->numColorSamples() <= 1 && SkToBool(surface->asTexture()); |
| 917 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 918 | // We can't write to a texture that has a ycbcr sampler. |
| 919 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 920 | // We can't directly read from a VkImage that has a ycbcr sampler. |
| 921 | if (tex->ycbcrConversionInfo().isValid()) { |
| 922 | return false; |
| 923 | } |
| 924 | } |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 925 | return true; |
| 926 | } |
| 927 | |
Robert Phillips | c1bee13 | 2019-02-06 16:04:34 -0500 | [diff] [blame] | 928 | static GrPixelConfig validate_image_info(VkFormat format, SkColorType ct, bool hasYcbcrConversion) { |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 929 | if (format == VK_FORMAT_UNDEFINED) { |
| 930 | // If the format is undefined then it is only valid as an external image which requires that |
| 931 | // we have a valid VkYcbcrConversion. |
| 932 | if (hasYcbcrConversion) { |
| 933 | // We don't actually care what the color type or config are since we won't use those |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 934 | // values for external textures. However, for read pixels we will draw to a non ycbcr |
| 935 | // texture of this config so we set RGBA here for that. |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 936 | return kRGBA_8888_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 937 | } else { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 938 | return kUnknown_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | if (hasYcbcrConversion) { |
| 943 | // We only support having a ycbcr conversion for external images. |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 944 | return kUnknown_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 945 | } |
| 946 | |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 947 | switch (ct) { |
| 948 | case kUnknown_SkColorType: |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 949 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 950 | case kAlpha_8_SkColorType: |
| 951 | if (VK_FORMAT_R8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 952 | return kAlpha_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 953 | } |
| 954 | break; |
| 955 | case kRGB_565_SkColorType: |
| 956 | if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 957 | return kRGB_565_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 958 | } |
| 959 | break; |
| 960 | case kARGB_4444_SkColorType: |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 961 | if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format || |
| 962 | VK_FORMAT_R4G4B4A4_UNORM_PACK16 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 963 | return kRGBA_4444_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 964 | } |
| 965 | break; |
| 966 | case kRGBA_8888_SkColorType: |
| 967 | if (VK_FORMAT_R8G8B8A8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 968 | return kRGBA_8888_GrPixelConfig; |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 969 | } else if (VK_FORMAT_R8G8B8A8_SRGB == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 970 | return kSRGBA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 971 | } |
| 972 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 973 | case kRGB_888x_SkColorType: |
Greg Daniel | 475eb70 | 2018-09-28 14:16:50 -0400 | [diff] [blame] | 974 | if (VK_FORMAT_R8G8B8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 975 | return kRGB_888_GrPixelConfig; |
Greg Daniel | 475eb70 | 2018-09-28 14:16:50 -0400 | [diff] [blame] | 976 | } |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 977 | if (VK_FORMAT_R8G8B8A8_UNORM == format) { |
| 978 | return kRGB_888X_GrPixelConfig; |
| 979 | } |
Greg Daniel | 475eb70 | 2018-09-28 14:16:50 -0400 | [diff] [blame] | 980 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 981 | case kBGRA_8888_SkColorType: |
| 982 | if (VK_FORMAT_B8G8R8A8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 983 | return kBGRA_8888_GrPixelConfig; |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 984 | } else if (VK_FORMAT_B8G8R8A8_SRGB == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 985 | return kSBGRA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 986 | } |
| 987 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 988 | case kRGBA_1010102_SkColorType: |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 989 | if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 990 | return kRGBA_1010102_GrPixelConfig; |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 991 | } |
| 992 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 993 | case kRGB_101010x_SkColorType: |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 994 | return kUnknown_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 995 | case kGray_8_SkColorType: |
| 996 | if (VK_FORMAT_R8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 997 | return kGray_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 998 | } |
| 999 | break; |
Brian Osman | d0626aa | 2019-03-11 15:28:06 -0400 | [diff] [blame] | 1000 | case kRGBA_F16Norm_SkColorType: |
Mike Klein | b70990e | 2019-02-28 10:03:27 -0600 | [diff] [blame] | 1001 | if (VK_FORMAT_R16G16B16A16_SFLOAT == format) { |
Brian Osman | d0626aa | 2019-03-11 15:28:06 -0400 | [diff] [blame] | 1002 | return kRGBA_half_Clamped_GrPixelConfig; |
Mike Klein | b70990e | 2019-02-28 10:03:27 -0600 | [diff] [blame] | 1003 | } |
| 1004 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1005 | case kRGBA_F16_SkColorType: |
| 1006 | if (VK_FORMAT_R16G16B16A16_SFLOAT == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1007 | return kRGBA_half_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1008 | } |
| 1009 | break; |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 1010 | case kRGBA_F32_SkColorType: |
| 1011 | if (VK_FORMAT_R32G32B32A32_SFLOAT == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1012 | return kRGBA_float_GrPixelConfig; |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 1013 | } |
| 1014 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1015 | } |
| 1016 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1017 | return kUnknown_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1020 | GrPixelConfig GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, |
| 1021 | SkColorType ct) const { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1022 | GrVkImageInfo imageInfo; |
| 1023 | if (!rt.getVkImageInfo(&imageInfo)) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1024 | return kUnknown_GrPixelConfig; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 1025 | } |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1026 | return validate_image_info(imageInfo.fFormat, ct, imageInfo.fYcbcrConversionInfo.isValid()); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 1027 | } |
| 1028 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1029 | GrPixelConfig GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, |
| 1030 | SkColorType ct) const { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 1031 | const VkFormat* vkFormat = format.getVkFormat(); |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 1032 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1033 | if (!vkFormat || !ycbcrInfo) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1034 | return kUnknown_GrPixelConfig; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 1035 | } |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1036 | return validate_image_info(*vkFormat, ct, ycbcrInfo->isValid()); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1037 | } |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1038 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1039 | static GrPixelConfig get_yuva_config(VkFormat vkFormat) { |
Jim Van Verth | 9bf8120 | 2018-10-30 15:53:36 -0400 | [diff] [blame] | 1040 | switch (vkFormat) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1041 | case VK_FORMAT_R8_UNORM: |
| 1042 | return kAlpha_8_as_Red_GrPixelConfig; |
| 1043 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 1044 | return kRGBA_8888_GrPixelConfig; |
| 1045 | case VK_FORMAT_R8G8B8_UNORM: |
| 1046 | return kRGB_888_GrPixelConfig; |
| 1047 | case VK_FORMAT_R8G8_UNORM: |
| 1048 | return kRG_88_GrPixelConfig; |
| 1049 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 1050 | return kBGRA_8888_GrPixelConfig; |
Robert Phillips | 2dd1b47 | 2019-03-21 09:00:20 -0400 | [diff] [blame] | 1051 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: |
| 1052 | return kRGBA_1010102_GrPixelConfig; |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 1053 | case VK_FORMAT_R16_UNORM: |
| 1054 | return kR_16_GrPixelConfig; |
| 1055 | case VK_FORMAT_R16G16_UNORM: |
| 1056 | return kRG_1616_GrPixelConfig; |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 1057 | // Experimental (for Y416 and mutant P016/P010) |
| 1058 | case VK_FORMAT_R16G16B16A16_UNORM: |
| 1059 | return kRGBA_16161616_GrPixelConfig; |
| 1060 | case VK_FORMAT_R16G16_SFLOAT: |
| 1061 | return kRG_half_GrPixelConfig; |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1062 | default: |
| 1063 | return kUnknown_GrPixelConfig; |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 1064 | } |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1067 | GrPixelConfig GrVkCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const { |
Jim Van Verth | 9bf8120 | 2018-10-30 15:53:36 -0400 | [diff] [blame] | 1068 | const VkFormat* vkFormat = format.getVkFormat(); |
| 1069 | if (!vkFormat) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1070 | return kUnknown_GrPixelConfig; |
Jim Van Verth | 9bf8120 | 2018-10-30 15:53:36 -0400 | [diff] [blame] | 1071 | } |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1072 | return get_yuva_config(*vkFormat); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 1073 | } |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1074 | |
| 1075 | GrBackendFormat GrVkCaps::getBackendFormatFromGrColorType(GrColorType ct, |
| 1076 | GrSRGBEncoded srgbEncoded) const { |
| 1077 | GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded); |
| 1078 | if (config == kUnknown_GrPixelConfig) { |
| 1079 | return GrBackendFormat(); |
| 1080 | } |
| 1081 | VkFormat format; |
| 1082 | if (!GrPixelConfigToVkFormat(config, &format)) { |
| 1083 | return GrBackendFormat(); |
| 1084 | } |
| 1085 | return GrBackendFormat::MakeVk(format); |
| 1086 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 1087 | |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1088 | #ifdef SK_DEBUG |
| 1089 | static bool format_color_type_valid_pair(VkFormat vkFormat, GrColorType colorType) { |
| 1090 | switch (colorType) { |
| 1091 | case GrColorType::kUnknown: |
| 1092 | return false; |
| 1093 | case GrColorType::kAlpha_8: |
| 1094 | return VK_FORMAT_R8_UNORM == vkFormat; |
Greg Daniel | 48fec76 | 2019-06-18 17:06:43 -0400 | [diff] [blame^] | 1095 | case GrColorType::kBGR_565: |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1096 | return VK_FORMAT_R5G6B5_UNORM_PACK16 == vkFormat; |
| 1097 | case GrColorType::kABGR_4444: |
| 1098 | return VK_FORMAT_B4G4R4A4_UNORM_PACK16 == vkFormat || |
| 1099 | VK_FORMAT_R4G4B4A4_UNORM_PACK16 == vkFormat; |
| 1100 | case GrColorType::kRGBA_8888: |
| 1101 | return VK_FORMAT_R8G8B8A8_UNORM == vkFormat || VK_FORMAT_R8G8B8A8_SRGB == vkFormat; |
| 1102 | case GrColorType::kRGB_888x: |
| 1103 | return VK_FORMAT_R8G8B8_UNORM == vkFormat || VK_FORMAT_R8G8B8A8_UNORM == vkFormat; |
| 1104 | case GrColorType::kRG_88: |
| 1105 | return VK_FORMAT_R8G8_UNORM == vkFormat; |
| 1106 | case GrColorType::kBGRA_8888: |
| 1107 | return VK_FORMAT_B8G8R8A8_UNORM == vkFormat || VK_FORMAT_B8G8R8A8_SRGB == vkFormat; |
| 1108 | case GrColorType::kRGBA_1010102: |
| 1109 | return VK_FORMAT_A2B10G10R10_UNORM_PACK32 == vkFormat; |
| 1110 | case GrColorType::kGray_8: |
| 1111 | return VK_FORMAT_R8_UNORM == vkFormat; |
| 1112 | case GrColorType::kAlpha_F16: |
| 1113 | return VK_FORMAT_R16_SFLOAT == vkFormat; |
| 1114 | case GrColorType::kRGBA_F16: |
| 1115 | return VK_FORMAT_R16G16B16A16_SFLOAT == vkFormat; |
| 1116 | case GrColorType::kRGBA_F16_Clamped: |
| 1117 | return VK_FORMAT_R16G16B16A16_SFLOAT == vkFormat; |
| 1118 | case GrColorType::kRG_F32: |
| 1119 | return VK_FORMAT_R32G32_SFLOAT == vkFormat; |
| 1120 | case GrColorType::kRGBA_F32: |
| 1121 | return VK_FORMAT_R32G32B32A32_SFLOAT == vkFormat; |
| 1122 | case GrColorType::kRGB_ETC1: |
| 1123 | return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK == vkFormat; |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 1124 | case GrColorType::kR_16: |
| 1125 | return VK_FORMAT_R16_UNORM == vkFormat; |
| 1126 | case GrColorType::kRG_1616: |
| 1127 | return VK_FORMAT_R16G16_UNORM == vkFormat; |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 1128 | // Experimental (for Y416 and mutant P016/P010) |
| 1129 | case GrColorType::kRGBA_16161616: |
| 1130 | return VK_FORMAT_R16G16B16A16_UNORM == vkFormat; |
| 1131 | case GrColorType::kRG_half: |
| 1132 | return VK_FORMAT_R16G16_SFLOAT == vkFormat; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1133 | } |
Greg Daniel | 4f71ccc | 2019-05-17 10:56:46 -0400 | [diff] [blame] | 1134 | SK_ABORT("Unknown color type"); |
| 1135 | return false; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1136 | } |
| 1137 | #endif |
| 1138 | |
| 1139 | static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType, |
| 1140 | bool forOutput) { |
| 1141 | SkASSERT(format.getVkFormat()); |
| 1142 | VkFormat vkFormat = *format.getVkFormat(); |
| 1143 | |
| 1144 | SkASSERT(format_color_type_valid_pair(vkFormat, colorType)); |
| 1145 | |
| 1146 | switch (colorType) { |
| 1147 | case GrColorType::kAlpha_8: // fall through |
| 1148 | case GrColorType::kAlpha_F16: |
| 1149 | if (forOutput) { |
| 1150 | return GrSwizzle::AAAA(); |
| 1151 | } else { |
| 1152 | return GrSwizzle::RRRR(); |
| 1153 | } |
| 1154 | case GrColorType::kGray_8: |
| 1155 | if (!forOutput) { |
| 1156 | return GrSwizzle::RRRA(); |
| 1157 | } |
| 1158 | break; |
| 1159 | case GrColorType::kABGR_4444: |
| 1160 | if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == vkFormat) { |
| 1161 | return GrSwizzle::BGRA(); |
| 1162 | } |
| 1163 | break; |
| 1164 | case GrColorType::kRGB_888x: |
| 1165 | if (!forOutput) { |
| 1166 | return GrSwizzle::RGB1(); |
| 1167 | } |
| 1168 | default: |
| 1169 | return GrSwizzle::RGBA(); |
| 1170 | } |
| 1171 | return GrSwizzle::RGBA(); |
| 1172 | } |
| 1173 | |
| 1174 | GrSwizzle GrVkCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
| 1175 | return get_swizzle(format, colorType, false); |
| 1176 | } |
| 1177 | GrSwizzle GrVkCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
| 1178 | return get_swizzle(format, colorType, true); |
| 1179 | } |
| 1180 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 1181 | size_t GrVkCaps::onTransferFromOffsetAlignment(GrColorType bufferColorType) const { |
Brian Salomon | a585fe9 | 2019-04-09 14:57:00 -0400 | [diff] [blame] | 1182 | // This GrColorType has 32 bpp but the Vulkan pixel format we use for with may have 24bpp |
| 1183 | // (VK_FORMAT_R8G8B8_...) or may be 32 bpp. We don't support post transforming the pixel data |
| 1184 | // for transfer-from currently and don't want to have to pass info about the src surface here. |
| 1185 | if (bufferColorType == GrColorType::kRGB_888x) { |
| 1186 | return false; |
| 1187 | } |
| 1188 | size_t bpp = GrColorTypeBytesPerPixel(bufferColorType); |
| 1189 | // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
| 1190 | switch (bpp & 0b11) { |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 1191 | // bpp is already a multiple of 4. |
| 1192 | case 0: return bpp; |
| 1193 | // bpp is a multiple of 2 but not 4. |
| 1194 | case 2: return 2 * bpp; |
| 1195 | // bpp is not a multiple of 2. |
| 1196 | default: return 4 * bpp; |
Brian Salomon | a585fe9 | 2019-04-09 14:57:00 -0400 | [diff] [blame] | 1197 | } |
Brian Salomon | a585fe9 | 2019-04-09 14:57:00 -0400 | [diff] [blame] | 1198 | } |