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 | |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkCaps.h" |
| 9 | |
| 10 | #include <memory> |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/gpu/vk/GrVkBackendContext.h" |
| 14 | #include "include/gpu/vk/GrVkExtensions.h" |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 15 | #include "src/core/SkCompressedDataUtils.h" |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrBackendUtils.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrProgramDesc.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTarget.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrShaderCaps.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrStencilSettings.h" |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrUtil.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/SkGr.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 24 | #include "src/gpu/vk/GrVkGpu.h" |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 25 | #include "src/gpu/vk/GrVkImage.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/gpu/vk/GrVkInterface.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 27 | #include "src/gpu/vk/GrVkRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "src/gpu/vk/GrVkTexture.h" |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame] | 29 | #include "src/gpu/vk/GrVkUniformHandler.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 31 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 32 | #ifdef SK_BUILD_FOR_ANDROID |
| 33 | #include <sys/system_properties.h> |
| 34 | #endif |
| 35 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 36 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 37 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 38 | uint32_t instanceVersion, uint32_t physicalDeviceVersion, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 39 | const GrVkExtensions& extensions, GrProtected isProtected) |
| 40 | : INHERITED(contextOptions) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | /************************************************************************** |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 42 | * GrCaps fields |
| 43 | **************************************************************************/ |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 44 | fMipmapSupport = true; // always available in Vulkan |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 45 | fNPOTTextureTileSupport = true; // always available in Vulkan |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 46 | fReuseScratchTextures = true; //TODO: figure this out |
| 47 | fGpuTracingSupport = false; //TODO: figure this out |
Greg Daniel | 28bea44 | 2021-06-25 15:06:15 +0000 | [diff] [blame] | 48 | fOversizedStencilSupport = false; //TODO: figure this out |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 49 | fDrawInstancedSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 50 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 51 | fSemaphoreSupport = true; // always available in Vulkan |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 52 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 53 | fCrossContextTextureSupport = true; |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 54 | fHalfFloatVertexAttributeSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 56 | // We always copy in/out of a transfer buffer so it's trivial to support row bytes. |
| 57 | fReadPixelsRowBytesSupport = true; |
| 58 | fWritePixelsRowBytesSupport = true; |
| 59 | |
Brian Salomon | fb28c6f | 2020-01-10 13:04:45 -0500 | [diff] [blame] | 60 | fTransferFromBufferToTextureSupport = true; |
| 61 | fTransferFromSurfaceToBufferSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 62 | |
| 63 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 64 | fMaxTextureSize = 4096; // minimum required by spec |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 65 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 66 | fDynamicStateArrayGeometryProcessorTextureSupport = true; |
| 67 | |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 68 | fTextureBarrierSupport = true; |
| 69 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 70 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 71 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 72 | this->init(contextOptions, vkInterface, physDev, features, physicalDeviceVersion, extensions, |
| 73 | isProtected); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 76 | namespace { |
| 77 | /** |
| 78 | * This comes from section 37.1.6 of the Vulkan spec. Format is |
| 79 | * (<bits>|<tag>)_<block_size>_<texels_per_block>. |
| 80 | */ |
| 81 | enum class FormatCompatibilityClass { |
| 82 | k8_1_1, |
| 83 | k16_2_1, |
| 84 | k24_3_1, |
| 85 | k32_4_1, |
| 86 | k64_8_1, |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 87 | kBC1_RGB_8_16_1, |
| 88 | kBC1_RGBA_8_16, |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 89 | kETC2_RGB_8_16, |
| 90 | }; |
| 91 | } // anonymous namespace |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 92 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 93 | static FormatCompatibilityClass format_compatibility_class(VkFormat format) { |
| 94 | switch (format) { |
| 95 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 96 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 97 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 98 | case VK_FORMAT_A2R10G10B10_UNORM_PACK32: |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 99 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 100 | case VK_FORMAT_R16G16_UNORM: |
| 101 | case VK_FORMAT_R16G16_SFLOAT: |
| 102 | return FormatCompatibilityClass::k32_4_1; |
| 103 | |
| 104 | case VK_FORMAT_R8_UNORM: |
| 105 | return FormatCompatibilityClass::k8_1_1; |
| 106 | |
| 107 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 108 | case VK_FORMAT_R16_SFLOAT: |
| 109 | case VK_FORMAT_R8G8_UNORM: |
| 110 | case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
| 111 | case VK_FORMAT_R4G4B4A4_UNORM_PACK16: |
| 112 | case VK_FORMAT_R16_UNORM: |
| 113 | return FormatCompatibilityClass::k16_2_1; |
| 114 | |
| 115 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 116 | case VK_FORMAT_R16G16B16A16_UNORM: |
| 117 | return FormatCompatibilityClass::k64_8_1; |
| 118 | |
| 119 | case VK_FORMAT_R8G8B8_UNORM: |
| 120 | return FormatCompatibilityClass::k24_3_1; |
| 121 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 122 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 123 | return FormatCompatibilityClass::kETC2_RGB_8_16; |
| 124 | |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 125 | case VK_FORMAT_BC1_RGB_UNORM_BLOCK: |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 126 | return FormatCompatibilityClass::kBC1_RGB_8_16_1; |
| 127 | |
| 128 | case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: |
| 129 | return FormatCompatibilityClass::kBC1_RGBA_8_16; |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 130 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 131 | default: |
| 132 | SK_ABORT("Unsupported VkFormat"); |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 133 | } |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 136 | bool GrVkCaps::canCopyImage(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 137 | VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 138 | if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) { |
| 139 | return false; |
| 140 | } |
| 141 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 142 | if (dstHasYcbcr || srcHasYcbcr) { |
| 143 | return false; |
| 144 | } |
| 145 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 146 | // We require that all Vulkan GrSurfaces have been created with transfer_dst and transfer_src |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 147 | // as image usage flags. |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 148 | return format_compatibility_class(srcFormat) == format_compatibility_class(dstFormat); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 151 | bool GrVkCaps::canCopyAsBlit(VkFormat dstFormat, int dstSampleCnt, bool dstIsLinear, |
| 152 | bool dstHasYcbcr, VkFormat srcFormat, int srcSampleCnt, |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 153 | bool srcIsLinear, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 154 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 155 | // as image usage flags. |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 156 | if (!this->formatCanBeDstofBlit(dstFormat, dstIsLinear) || |
| 157 | !this->formatCanBeSrcofBlit(srcFormat, srcIsLinear)) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 158 | return false; |
| 159 | } |
| 160 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 161 | // We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 162 | // resolved msaa though. |
| 163 | if (dstSampleCnt > 1 || srcSampleCnt > 1) { |
| 164 | return false; |
| 165 | } |
| 166 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 167 | if (dstHasYcbcr || srcHasYcbcr) { |
| 168 | return false; |
| 169 | } |
| 170 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 171 | return true; |
| 172 | } |
| 173 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 174 | bool GrVkCaps::canCopyAsResolve(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 175 | VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 176 | // The src surface must be multisampled. |
| 177 | if (srcSampleCnt <= 1) { |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | // The dst must not be multisampled. |
| 182 | if (dstSampleCnt > 1) { |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | // Surfaces must have the same format. |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 187 | if (srcFormat != dstFormat) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 188 | return false; |
| 189 | } |
| 190 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 191 | if (dstHasYcbcr || srcHasYcbcr) { |
| 192 | return false; |
| 193 | } |
| 194 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 195 | return true; |
| 196 | } |
| 197 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 198 | bool GrVkCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 199 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
Greg Daniel | ca9dbe2 | 2020-01-02 13:44:30 -0500 | [diff] [blame] | 200 | if (src->isProtected() == GrProtected::kYes && dst->isProtected() != GrProtected::kYes) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 201 | return false; |
| 202 | } |
| 203 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 204 | // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g. |
| 205 | // PromiseImage which won't get instantiated right away. Does this need a similar thing like the |
| 206 | // tracking of external or rectangle textures in GL? For now we don't create linear textures |
| 207 | // internally, and I don't believe anyone is wrapping them. |
| 208 | bool srcIsLinear = false; |
| 209 | bool dstIsLinear = false; |
| 210 | |
| 211 | int dstSampleCnt = 0; |
| 212 | int srcSampleCnt = 0; |
| 213 | if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 214 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 215 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 216 | // to stop and start the VkRenderPass which we don't have access to. |
| 217 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 218 | return false; |
| 219 | } |
Greg Daniel | aacc9f72 | 2020-12-17 10:42:57 -0500 | [diff] [blame] | 220 | if (this->preferDiscardableMSAAAttachment() && dst->asTextureProxy() && |
| 221 | rtProxy->supportsVkInputAttachment()) { |
| 222 | dstSampleCnt = 1; |
| 223 | } else { |
| 224 | dstSampleCnt = rtProxy->numSamples(); |
| 225 | } |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 226 | } |
| 227 | if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 228 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 229 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 230 | // to stop and start the VkRenderPass which we don't have access to. |
| 231 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 232 | return false; |
| 233 | } |
Greg Daniel | aacc9f72 | 2020-12-17 10:42:57 -0500 | [diff] [blame] | 234 | if (this->preferDiscardableMSAAAttachment() && src->asTextureProxy() && |
| 235 | rtProxy->supportsVkInputAttachment()) { |
| 236 | srcSampleCnt = 1; |
| 237 | } else { |
| 238 | srcSampleCnt = rtProxy->numSamples(); |
| 239 | } |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 240 | } |
| 241 | SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy())); |
| 242 | SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy())); |
| 243 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 244 | bool dstHasYcbcr = false; |
| 245 | if (auto ycbcr = dst->backendFormat().getVkYcbcrConversionInfo()) { |
| 246 | if (ycbcr->isValid()) { |
| 247 | dstHasYcbcr = true; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | bool srcHasYcbcr = false; |
| 252 | if (auto ycbcr = src->backendFormat().getVkYcbcrConversionInfo()) { |
| 253 | if (ycbcr->isValid()) { |
| 254 | srcHasYcbcr = true; |
| 255 | } |
| 256 | } |
| 257 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 258 | VkFormat dstFormat, srcFormat; |
| 259 | SkAssertResult(dst->backendFormat().asVkFormat(&dstFormat)); |
| 260 | SkAssertResult(src->backendFormat().asVkFormat(&srcFormat)); |
| 261 | |
| 262 | return this->canCopyImage(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 263 | srcFormat, srcSampleCnt, srcHasYcbcr) || |
| 264 | this->canCopyAsBlit(dstFormat, dstSampleCnt, dstIsLinear, dstHasYcbcr, |
| 265 | srcFormat, srcSampleCnt, srcIsLinear, srcHasYcbcr) || |
| 266 | this->canCopyAsResolve(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 267 | srcFormat, srcSampleCnt, srcHasYcbcr); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 270 | template<typename T> T* get_extension_feature_struct(const VkPhysicalDeviceFeatures2& features, |
| 271 | VkStructureType type) { |
| 272 | // All Vulkan structs that could be part of the features chain will start with the |
| 273 | // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader |
| 274 | // so we can get access to the pNext for the next struct. |
| 275 | struct CommonVulkanHeader { |
| 276 | VkStructureType sType; |
| 277 | void* pNext; |
| 278 | }; |
| 279 | |
| 280 | void* pNext = features.pNext; |
| 281 | while (pNext) { |
| 282 | CommonVulkanHeader* header = static_cast<CommonVulkanHeader*>(pNext); |
| 283 | if (header->sType == type) { |
| 284 | return static_cast<T*>(pNext); |
| 285 | } |
| 286 | pNext = header->pNext; |
| 287 | } |
| 288 | return nullptr; |
| 289 | } |
| 290 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 291 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 292 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 293 | uint32_t physicalDeviceVersion, const GrVkExtensions& extensions, |
| 294 | GrProtected isProtected) { |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 295 | VkPhysicalDeviceProperties properties; |
| 296 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 297 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 298 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 299 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 300 | |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 301 | SkASSERT(physicalDeviceVersion <= properties.apiVersion); |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 302 | |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 303 | if (extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 1)) { |
| 304 | fSupportsSwapchain = true; |
| 305 | } |
| 306 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 307 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 308 | extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { |
| 309 | fSupportsPhysicalDeviceProperties2 = true; |
| 310 | } |
| 311 | |
| 312 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 313 | extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { |
| 314 | fSupportsMemoryRequirements2 = true; |
| 315 | } |
| 316 | |
| 317 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 318 | extensions.hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { |
| 319 | fSupportsBindMemory2 = true; |
| 320 | } |
| 321 | |
| 322 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 323 | extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { |
| 324 | fSupportsMaintenance1 = true; |
| 325 | } |
| 326 | |
| 327 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 328 | extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) { |
| 329 | fSupportsMaintenance2 = true; |
| 330 | } |
| 331 | |
| 332 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 333 | extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { |
| 334 | fSupportsMaintenance3 = true; |
| 335 | } |
| 336 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 337 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 338 | (extensions.hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) && |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 339 | this->supportsMemoryRequirements2())) { |
| 340 | fSupportsDedicatedAllocation = true; |
| 341 | } |
| 342 | |
| 343 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 344 | (extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1) && |
| 345 | this->supportsPhysicalDeviceProperties2() && |
| 346 | extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, 1) && |
| 347 | this->supportsDedicatedAllocation())) { |
| 348 | fSupportsExternalMemory = true; |
| 349 | } |
| 350 | |
| 351 | #ifdef SK_BUILD_FOR_ANDROID |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 352 | // Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they |
| 353 | // 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] | 354 | if (extensions.hasExtension( |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 355 | VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, 2) && |
| 356 | /* extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1) &&*/ |
| 357 | this->supportsExternalMemory() && |
| 358 | this->supportsBindMemory2()) { |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 359 | fSupportsAndroidHWBExternalMemory = true; |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 360 | fSupportsAHardwareBufferImages = true; |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 361 | } |
| 362 | #endif |
| 363 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 364 | auto ycbcrFeatures = |
| 365 | get_extension_feature_struct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>( |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 366 | features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES); |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 367 | if (ycbcrFeatures && ycbcrFeatures->samplerYcbcrConversion && |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 368 | (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 369 | (extensions.hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1) && |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 370 | this->supportsMaintenance1() && this->supportsBindMemory2() && |
| 371 | this->supportsMemoryRequirements2() && this->supportsPhysicalDeviceProperties2()))) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 372 | fSupportsYcbcrConversion = true; |
| 373 | } |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 374 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 375 | // We always push back the default GrVkYcbcrConversionInfo so that the case of no conversion |
| 376 | // will return a key of 0. |
| 377 | fYcbcrInfos.push_back(GrVkYcbcrConversionInfo()); |
| 378 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 379 | if ((isProtected == GrProtected::kYes) && |
| 380 | (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0))) { |
| 381 | fSupportsProtectedMemory = true; |
| 382 | fAvoidUpdateBuffers = true; |
| 383 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 384 | } |
| 385 | |
Greg Daniel | ed629c1 | 2020-08-14 13:11:18 -0400 | [diff] [blame] | 386 | fMaxInputAttachmentDescriptors = properties.limits.maxDescriptorSetInputAttachments; |
| 387 | |
Greg Daniel | 52a7eca | 2021-01-11 11:24:40 -0500 | [diff] [blame] | 388 | // On desktop GPUs we have found that this does not provide much benefit. The perf results show |
| 389 | // a mix of regressions, some improvements, and lots of no changes. Thus it is no worth enabling |
| 390 | // this (especially with the rendering artifacts) on desktop. |
| 391 | // |
| 392 | // On Adreno devices we were expecting to see perf gains. But instead there were actually a lot |
| 393 | // of perf regressions and only a few perf wins. This needs some follow up with qualcomm since |
| 394 | // we do expect this to be a big win on tilers. |
| 395 | // |
| 396 | // On ARM devices we are seeing an average perf win of around 50%-60% across the board. |
| 397 | if (kARM_VkVendor == properties.vendorID) { |
| 398 | fPreferDiscardableMSAAAttachment = true; |
| 399 | } |
Greg Daniel | d8d9cf1 | 2021-01-07 09:46:39 -0500 | [diff] [blame] | 400 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 401 | this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions); |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 402 | this->initShaderCaps(properties, features); |
Greg Daniel | f3b1162 | 2018-03-01 15:01:27 -0500 | [diff] [blame] | 403 | |
Chris Dalton | 8e738a2 | 2018-10-05 16:41:44 -0600 | [diff] [blame] | 404 | if (kQualcomm_VkVendor == properties.vendorID) { |
Chris Dalton | 685e09b | 2021-06-19 11:50:17 -0600 | [diff] [blame] | 405 | // A "clear" load for atlases runs faster on QC than a "discard" load followed by a |
Chris Dalton | 8e738a2 | 2018-10-05 16:41:44 -0600 | [diff] [blame] | 406 | // scissored clear. |
| 407 | // On NVIDIA and Intel, the discard load followed by clear is faster. |
| 408 | // TODO: Evaluate on ARM, Imagination, and ATI. |
| 409 | fPreferFullscreenClears = true; |
| 410 | } |
| 411 | |
Greg Daniel | 5af72c1 | 2021-02-08 13:52:08 -0500 | [diff] [blame] | 412 | if (properties.vendorID == kNvidia_VkVendor || properties.vendorID == kAMD_VkVendor) { |
| 413 | // On discrete GPUs it can be faster to read gpu only memory compared to memory that is also |
| 414 | // mappable on the host. |
| 415 | fGpuOnlyBuffersMorePerformant = true; |
Greg Daniel | d2a3912 | 2021-02-17 16:12:54 -0500 | [diff] [blame] | 416 | |
| 417 | // On discrete GPUs we try to use special DEVICE_LOCAL and HOST_VISIBLE memory for our |
| 418 | // cpu write, gpu read buffers. This memory is not ideal to be kept persistently mapped. |
| 419 | // Some discrete GPUs do not expose this special memory, however we still disable |
| 420 | // persistently mapped buffers for all of them since most GPUs with updated drivers do |
| 421 | // expose it. If this becomes an issue we can try to be more fine grained. |
| 422 | fShouldPersistentlyMapCpuToGpuBuffers = false; |
Greg Daniel | 5af72c1 | 2021-02-08 13:52:08 -0500 | [diff] [blame] | 423 | } |
| 424 | |
Greg Daniel | 78e6a4c | 2019-03-19 14:13:36 -0400 | [diff] [blame] | 425 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 426 | // On Qualcomm it looks like using vkCmdUpdateBuffer is slower than using a transfer buffer |
| 427 | // even for small sizes. |
| 428 | fAvoidUpdateBuffers = true; |
| 429 | } |
| 430 | |
Jim Van Verth | 4b3d1f3 | 2020-10-08 15:46:36 -0400 | [diff] [blame] | 431 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 432 | // Adreno devices don't support push constants well |
| 433 | fMaxPushConstantsSize = 0; |
| 434 | } |
| 435 | |
Greg Daniel | 70ea0d9 | 2021-01-14 13:08:13 -0500 | [diff] [blame] | 436 | fNativeDrawIndirectSupport = features.features.drawIndirectFirstInstance; |
| 437 | if (properties.vendorID == kQualcomm_VkVendor) { |
Chris Dalton | 8f282f5 | 2021-01-06 11:47:58 -0700 | [diff] [blame] | 438 | // Indirect draws seem slow on QC. Disable until we can investigate. http://skbug.com/11139 |
| 439 | fNativeDrawIndirectSupport = false; |
| 440 | } |
| 441 | |
Greg Daniel | 70ea0d9 | 2021-01-14 13:08:13 -0500 | [diff] [blame] | 442 | if (fNativeDrawIndirectSupport) { |
| 443 | fMaxDrawIndirectDrawCount = properties.limits.maxDrawIndirectCount; |
| 444 | SkASSERT(fMaxDrawIndirectDrawCount == 1 || features.features.multiDrawIndirect); |
| 445 | } |
| 446 | |
Greg Daniel | 569afe1 | 2020-09-14 10:25:36 -0400 | [diff] [blame] | 447 | #ifdef SK_BUILD_FOR_UNIX |
| 448 | if (kNvidia_VkVendor == properties.vendorID) { |
| 449 | // On nvidia linux we see a big perf regression when not using dedicated image allocations. |
| 450 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 451 | } |
| 452 | #endif |
| 453 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 454 | this->initFormatTable(vkInterface, physDev, properties); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 455 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 456 | |
Greg Daniel | 43833b0 | 2020-07-14 09:21:48 -0400 | [diff] [blame] | 457 | if (contextOptions.fMaxCachedVulkanSecondaryCommandBuffers >= 0) { |
| 458 | fMaxPerPoolCachedSecondaryCommandBuffers = |
| 459 | contextOptions.fMaxCachedVulkanSecondaryCommandBuffers; |
| 460 | } |
| 461 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 462 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
Robert Phillips | 9233e0c | 2019-11-20 15:20:05 +0000 | [diff] [blame] | 463 | this->applyDriverCorrectnessWorkarounds(properties); |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 464 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 465 | |
Chris Dalton | 8367e11 | 2019-11-13 12:43:21 -0700 | [diff] [blame] | 466 | this->finishInitialization(contextOptions); |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 467 | } |
| 468 | |
Robert Phillips | 9233e0c | 2019-11-20 15:20:05 +0000 | [diff] [blame] | 469 | void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) { |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 470 | #if defined(SK_BUILD_FOR_WIN) |
Greg Daniel | 900e5c8 | 2018-08-28 10:59:24 -0400 | [diff] [blame] | 471 | if (kNvidia_VkVendor == properties.vendorID || kIntel_VkVendor == properties.vendorID) { |
Greg Daniel | fda4586 | 2021-02-09 17:55:07 -0500 | [diff] [blame] | 472 | fMustSyncCommandBuffersWithQueue = true; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 473 | } |
| 474 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 475 | if (kImagination_VkVendor == properties.vendorID) { |
Greg Daniel | fda4586 | 2021-02-09 17:55:07 -0500 | [diff] [blame] | 476 | fMustSyncCommandBuffersWithQueue = true; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 477 | } |
| 478 | #endif |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 479 | |
Greg Daniel | 6ed2dcc | 2020-09-02 16:38:43 -0400 | [diff] [blame] | 480 | // Defaults to zero since all our workaround checks that use this consider things "fixed" once |
| 481 | // above a certain api level. So this will just default to it being less which will enable |
| 482 | // workarounds. |
| 483 | int androidAPIVersion = 0; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 484 | #if defined(SK_BUILD_FOR_ANDROID) |
Greg Daniel | 6ed2dcc | 2020-09-02 16:38:43 -0400 | [diff] [blame] | 485 | char androidAPIVersionStr[PROP_VALUE_MAX]; |
| 486 | int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersionStr); |
| 487 | // Defaults to zero since most checks care if it is greater than a specific value. So this will |
| 488 | // just default to it being less. |
| 489 | androidAPIVersion = (strLength == 0) ? 0 : atoi(androidAPIVersionStr); |
| 490 | #endif |
| 491 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 492 | // Protected memory features have problems in Android P and earlier. |
| 493 | if (fSupportsProtectedMemory && (kQualcomm_VkVendor == properties.vendorID)) { |
Greg Daniel | 6ed2dcc | 2020-09-02 16:38:43 -0400 | [diff] [blame] | 494 | if (androidAPIVersion <= 28) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 495 | fSupportsProtectedMemory = false; |
| 496 | } |
| 497 | } |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 498 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 499 | // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages. |
Greg Daniel | 98df291 | 2020-09-11 11:08:10 -0400 | [diff] [blame] | 500 | if (kARM_VkVendor == properties.vendorID && androidAPIVersion <= 28) { |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 501 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 502 | } |
| 503 | |
Greg Daniel | a718a61 | 2019-10-07 16:25:41 -0400 | [diff] [blame] | 504 | // On Mali galaxy s7 and s9 we see lots of rendering issues with image filters dropping out when |
Greg Daniel | 6ed2dcc | 2020-09-02 16:38:43 -0400 | [diff] [blame] | 505 | // using only primary command buffers. We also see issues on the P30 running android 28. |
| 506 | if (kARM_VkVendor == properties.vendorID && androidAPIVersion <= 28) { |
Greg Daniel | a718a61 | 2019-10-07 16:25:41 -0400 | [diff] [blame] | 507 | fPreferPrimaryOverSecondaryCommandBuffers = false; |
Greg Daniel | 70ea0d9 | 2021-01-14 13:08:13 -0500 | [diff] [blame] | 508 | // If we are using secondary command buffers our code isn't setup to insert barriers into |
| 509 | // the secondary cb so we need to disable support for them. |
| 510 | fTextureBarrierSupport = false; |
| 511 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
Greg Daniel | a718a61 | 2019-10-07 16:25:41 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Greg Daniel | d8d9cf1 | 2021-01-07 09:46:39 -0500 | [diff] [blame] | 514 | // We've seen numerous driver bugs on qualcomm devices running on android P (api 28) or earlier |
| 515 | // when trying to using discardable msaa attachments and loading from resolve. So we disable the |
| 516 | // feature for those devices. |
| 517 | if (properties.vendorID == kQualcomm_VkVendor && androidAPIVersion <= 28) { |
| 518 | fPreferDiscardableMSAAAttachment = false; |
Greg Daniel | f8a9658 | 2021-08-29 16:25:50 -0400 | [diff] [blame] | 519 | fSupportsDiscardableMSAAForDMSAA = false; |
Greg Daniel | d8d9cf1 | 2021-01-07 09:46:39 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Brian Osman | 76f635c | 2020-03-25 16:23:11 -0400 | [diff] [blame] | 522 | // On Mali G series GPUs, applying transfer functions in the fragment shader with half-floats |
| 523 | // produces answers that are much less accurate than expected/required. This forces full floats |
| 524 | // for some intermediate values to get acceptable results. |
| 525 | if (kARM_VkVendor == properties.vendorID) { |
| 526 | fShaderCaps->fColorSpaceMathNeedsFloat = true; |
| 527 | } |
| 528 | |
Greg Daniel | a718a61 | 2019-10-07 16:25:41 -0400 | [diff] [blame] | 529 | // On various devices, when calling vkCmdClearAttachments on a primary command buffer, it |
| 530 | // corrupts the bound buffers on the command buffer. As a workaround we invalidate our knowledge |
| 531 | // of bound buffers so that we will rebind them on the next draw. |
| 532 | if (kQualcomm_VkVendor == properties.vendorID || kAMD_VkVendor == properties.vendorID) { |
| 533 | fMustInvalidatePrimaryCmdBufferStateAfterClearAttachments = true; |
| 534 | } |
| 535 | |
Greg Daniel | 417743f | 2021-01-06 09:24:09 -0500 | [diff] [blame] | 536 | // On Qualcomm and Arm the gpu resolves an area larger than the render pass bounds when using |
| 537 | // discardable msaa attachments. This causes the resolve to resolve uninitialized data from the |
| 538 | // msaa image into the resolve image. |
| 539 | if (kQualcomm_VkVendor == properties.vendorID || kARM_VkVendor == properties.vendorID) { |
| 540 | fMustLoadFullImageWithDiscardableMSAA = true; |
| 541 | } |
| 542 | |
Greg Daniel | 815ec0d | 2021-01-25 14:09:27 -0500 | [diff] [blame] | 543 | #ifdef SK_BUILD_FOR_UNIX |
| 544 | if (kIntel_VkVendor == properties.vendorID) { |
| 545 | // At least on our linux Debug Intel HD405 bot we are seeing issues doing read pixels with |
| 546 | // non-conherent memory. It seems like the device is not properly honoring the |
| 547 | // vkInvalidateMappedMemoryRanges calls correctly. Other linux intel devices seem to work |
| 548 | // okay. However, since I'm not sure how to target a specific intel devices or driver |
| 549 | // version I am going to stop all intel linux from using non-coherent memory. Currently we |
| 550 | // are not shipping anything on these platforms and the only real thing that will regress is |
| 551 | // read backs. If we find later we do care about this performance we can come back to figure |
| 552 | // out how to do a more narrow workaround. |
| 553 | fMustUseCoherentHostVisibleMemory = true; |
| 554 | } |
| 555 | #endif |
| 556 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 557 | //////////////////////////////////////////////////////////////////////////// |
| 558 | // GrCaps workarounds |
| 559 | //////////////////////////////////////////////////////////////////////////// |
| 560 | |
Chris Dalton | d53853d | 2019-11-25 12:54:55 -0700 | [diff] [blame] | 561 | #ifdef SK_BUILD_FOR_ANDROID |
Chris Dalton | 9431079 | 2021-03-12 11:10:24 -0700 | [diff] [blame] | 562 | // MSAA CCPR was slow on Android. http://skbug.com/9676 |
| 563 | fDriverDisableMSAAClipAtlas = true; |
Chris Dalton | d53853d | 2019-11-25 12:54:55 -0700 | [diff] [blame] | 564 | #endif |
Chris Dalton | 78fa08b | 2019-11-16 02:53:52 +0000 | [diff] [blame] | 565 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 566 | if (kARM_VkVendor == properties.vendorID) { |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 567 | fAvoidWritePixelsFastPath = true; // bugs.skia.org/8064 |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 571 | if (kAMD_VkVendor == properties.vendorID) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 572 | fMaxVertexAttributes = std::min(fMaxVertexAttributes, 32); |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 575 | // Adreno devices fail when trying to read the dest using an input attachment and texture |
| 576 | // barriers. |
| 577 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 578 | fTextureBarrierSupport = false; |
| 579 | } |
| 580 | |
Greg Daniel | 70ea0d9 | 2021-01-14 13:08:13 -0500 | [diff] [blame] | 581 | // On ARM indirect draws are broken on Android 9 and earlier. This was tested on a P30 and |
| 582 | // Mate 20x running android 9. |
| 583 | if (properties.vendorID == kARM_VkVendor && androidAPIVersion <= 28) { |
| 584 | fNativeDrawIndirectSupport = false; |
| 585 | } |
| 586 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 587 | //////////////////////////////////////////////////////////////////////////// |
| 588 | // GrShaderCaps workarounds |
| 589 | //////////////////////////////////////////////////////////////////////////// |
| 590 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 591 | if (kImagination_VkVendor == properties.vendorID) { |
| 592 | fShaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 593 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 594 | } |
| 595 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 596 | void GrVkCaps::initGrCaps(const GrVkInterface* vkInterface, |
| 597 | VkPhysicalDevice physDev, |
| 598 | const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 599 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 600 | const VkPhysicalDeviceFeatures2& features, |
| 601 | const GrVkExtensions& extensions) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 602 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 603 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 604 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 605 | // we ever find that need. |
| 606 | static const uint32_t kMaxVertexAttributes = 64; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 607 | fMaxVertexAttributes = std::min(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 608 | |
Chris Dalton | 1c3a77e | 2020-06-09 18:51:40 -0600 | [diff] [blame] | 609 | // GrCaps::fSampleLocationsSupport refers to the ability to *query* the sample locations (not |
| 610 | // program them). For now we just set this to true if the device uses standard locations, and |
| 611 | // return the standard locations back when queried. |
| 612 | if (properties.limits.standardSampleLocations) { |
Chris Dalton | 2284aab | 2019-11-15 11:02:24 -0700 | [diff] [blame] | 613 | fSampleLocationsSupport = true; |
| 614 | } |
| 615 | |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 616 | if (extensions.hasExtension(VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME, 1)) { |
| 617 | fConservativeRasterSupport = true; |
| 618 | } |
| 619 | |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame] | 620 | fWireframeSupport = true; |
| 621 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 622 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 623 | // give the minimum max size across all configs. So for simplicity we will use that for now. |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 624 | fMaxRenderTargetSize = std::min(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 625 | fMaxTextureSize = std::min(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
Robert Phillips | 9233e0c | 2019-11-20 15:20:05 +0000 | [diff] [blame] | 626 | if (fDriverBugWorkarounds.max_texture_size_limit_4096) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 627 | fMaxTextureSize = std::min(fMaxTextureSize, 4096); |
Robert Phillips | 9233e0c | 2019-11-20 15:20:05 +0000 | [diff] [blame] | 628 | } |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 629 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 630 | // TODO: check if RT's larger than 4k incur a performance cost on ARM. |
| 631 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 632 | |
Jim Van Verth | 4b3d1f3 | 2020-10-08 15:46:36 -0400 | [diff] [blame] | 633 | fMaxPushConstantsSize = std::min(properties.limits.maxPushConstantsSize, (uint32_t)INT_MAX); |
| 634 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 635 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 636 | // 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] | 637 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 638 | |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 639 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag | kAsyncRead_MapFlag; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 640 | |
Greg Daniel | 28bea44 | 2021-06-25 15:06:15 +0000 | [diff] [blame] | 641 | fOversizedStencilSupport = true; |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 642 | |
| 643 | if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2) && |
| 644 | this->supportsPhysicalDeviceProperties2()) { |
| 645 | |
| 646 | VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps; |
| 647 | blendProps.sType = |
| 648 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT; |
| 649 | blendProps.pNext = nullptr; |
| 650 | |
| 651 | VkPhysicalDeviceProperties2 props; |
| 652 | props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; |
| 653 | props.pNext = &blendProps; |
| 654 | |
| 655 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props)); |
| 656 | |
| 657 | if (blendProps.advancedBlendAllOperations == VK_TRUE) { |
| 658 | fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
| 659 | |
| 660 | auto blendFeatures = |
| 661 | get_extension_feature_struct<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>( |
| 662 | features, |
| 663 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT); |
| 664 | if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) { |
| 665 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 666 | } else { |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 667 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | } |
Greg Daniel | f6d60d3 | 2020-01-08 13:39:16 -0500 | [diff] [blame] | 671 | |
| 672 | if (kARM_VkVendor == properties.vendorID) { |
| 673 | fShouldCollapseSrcOverToSrcWhenAble = true; |
| 674 | } |
Greg Daniel | 95ab83f | 2020-11-24 15:48:22 -0500 | [diff] [blame] | 675 | |
| 676 | // We're seeing vkCmdClearAttachments take a lot of cpu time when clearing the color attachment. |
| 677 | // We really should only be getting in there for partial clears. So instead we will do all |
| 678 | // partial clears as draws. |
| 679 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 680 | fPerformPartialClearsAsDraws = true; |
| 681 | } |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 682 | } |
| 683 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 684 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 685 | const VkPhysicalDeviceFeatures2& features) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 686 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 687 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 688 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 689 | // 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] | 690 | shaderCaps->fUsesPrecisionModifiers = true; |
| 691 | shaderCaps->fFlatInterpolationSupport = true; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 692 | // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 693 | // to be true with Vulkan as well. |
| 694 | shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 695 | |
Chris Dalton | 2284aab | 2019-11-15 11:02:24 -0700 | [diff] [blame] | 696 | shaderCaps->fSampleMaskSupport = true; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 697 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 698 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 699 | |
John Stiles | 85749c0 | 2021-03-23 17:12:03 -0400 | [diff] [blame] | 700 | // ARM GPUs calculate `matrix * vector` in SPIR-V at full precision, even when the inputs are |
| 701 | // RelaxedPrecision. Rewriting the multiply as a sum of vector*scalar fixes this. (skia:11769) |
| 702 | shaderCaps->fRewriteMatrixVectorMultiply = (kARM_VkVendor == properties.vendorID); |
| 703 | |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 704 | shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 705 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 706 | shaderCaps->fIntegerSupport = true; |
John Stiles | ec79349 | 2021-05-03 09:21:12 -0400 | [diff] [blame] | 707 | shaderCaps->fNonsquareMatrixSupport = true; |
John Stiles | bc9222b | 2021-08-17 15:58:03 -0400 | [diff] [blame] | 708 | shaderCaps->fInverseHyperbolicSupport = true; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 709 | shaderCaps->fVertexIDSupport = true; |
Chris Dalton | 6904303 | 2021-07-01 11:17:53 -0600 | [diff] [blame] | 710 | shaderCaps->fInfinitySupport = true; |
Chris Dalton | 489fa0b | 2021-05-14 17:41:17 -0600 | [diff] [blame] | 711 | shaderCaps->fBitManipulationSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 712 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 713 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 714 | shaderCaps->fFloatIs32Bits = true; |
| 715 | shaderCaps->fHalfIs32Bits = false; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 716 | |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 717 | shaderCaps->fMaxFragmentSamplers = std::min( |
| 718 | std::min(properties.limits.maxPerStageDescriptorSampledImages, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 719 | properties.limits.maxPerStageDescriptorSamplers), |
| 720 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 721 | } |
| 722 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 723 | bool stencil_format_supported(const GrVkInterface* interface, |
| 724 | VkPhysicalDevice physDev, |
| 725 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 726 | VkFormatProperties props; |
| 727 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 728 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 729 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 730 | } |
| 731 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 732 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 733 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 734 | fPreferredStencilFormat = VK_FORMAT_S8_UINT; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 735 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 736 | fPreferredStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 737 | } else { |
| 738 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 739 | fPreferredStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 743 | static bool format_is_srgb(VkFormat format) { |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 744 | SkASSERT(GrVkFormatIsSupported(format)); |
| 745 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 746 | switch (format) { |
| 747 | case VK_FORMAT_R8G8B8A8_SRGB: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 748 | return true; |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 749 | default: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 750 | return false; |
| 751 | } |
| 752 | } |
| 753 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 754 | // 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] | 755 | // frequently used to least to improve look up times in arrays. |
| 756 | static constexpr VkFormat kVkFormats[] = { |
| 757 | VK_FORMAT_R8G8B8A8_UNORM, |
| 758 | VK_FORMAT_R8_UNORM, |
| 759 | VK_FORMAT_B8G8R8A8_UNORM, |
| 760 | VK_FORMAT_R5G6B5_UNORM_PACK16, |
| 761 | VK_FORMAT_R16G16B16A16_SFLOAT, |
| 762 | VK_FORMAT_R16_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 763 | VK_FORMAT_R8G8B8_UNORM, |
| 764 | VK_FORMAT_R8G8_UNORM, |
| 765 | VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 766 | VK_FORMAT_A2R10G10B10_UNORM_PACK32, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 767 | VK_FORMAT_B4G4R4A4_UNORM_PACK16, |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 768 | VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 769 | VK_FORMAT_R8G8B8A8_SRGB, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 770 | VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 771 | VK_FORMAT_BC1_RGB_UNORM_BLOCK, |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 772 | VK_FORMAT_BC1_RGBA_UNORM_BLOCK, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 773 | VK_FORMAT_R16_UNORM, |
| 774 | VK_FORMAT_R16G16_UNORM, |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 775 | VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, |
| 776 | VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 777 | VK_FORMAT_R16G16B16A16_UNORM, |
| 778 | VK_FORMAT_R16G16_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 779 | }; |
| 780 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 781 | void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) { |
| 782 | #ifdef SK_DEBUG |
| 783 | for (size_t i = 0; i < kNumVkFormats; ++i) { |
| 784 | const auto& formatInfo = fFormatTable[i]; |
| 785 | for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) { |
| 786 | const auto& ctInfo = formatInfo.fColorTypeInfos[j]; |
| 787 | if (ctInfo.fColorType == colorType && |
| 788 | !SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) { |
| 789 | bool found = false; |
| 790 | for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 791 | if (kVkFormats[i] == *it) { |
| 792 | found = true; |
| 793 | } |
| 794 | } |
| 795 | SkASSERT(found); |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | #endif |
| 800 | int idx = static_cast<int>(colorType); |
| 801 | for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 802 | const auto& info = this->getFormatInfo(*it); |
| 803 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 804 | if (info.fColorTypeInfos[i].fColorType == colorType) { |
| 805 | fColorTypeToFormatTable[idx] = *it; |
| 806 | return; |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 812 | const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 813 | GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this); |
| 814 | return nonConstThis->getFormatInfo(format); |
| 815 | } |
| 816 | |
| 817 | GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 818 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 819 | "Size of VkFormats array must match static value in header"); |
| 820 | for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) { |
| 821 | if (kVkFormats[i] == format) { |
| 822 | return fFormatTable[i]; |
| 823 | } |
| 824 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 825 | static FormatInfo kInvalidFormat; |
Greg Daniel | 52ee5f6 | 2019-06-20 13:38:18 -0400 | [diff] [blame] | 826 | return kInvalidFormat; |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 830 | const VkPhysicalDeviceProperties& properties) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 831 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 832 | "Size of VkFormats array must match static value in header"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 833 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 834 | std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 835 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 836 | // Go through all the formats and init their support surface and data GrColorTypes. |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 837 | // Format: VK_FORMAT_R8G8B8A8_UNORM |
| 838 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 839 | constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM; |
| 840 | auto& info = this->getFormatInfo(format); |
| 841 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 842 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 843 | info.fColorTypeInfoCount = 2; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 844 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 845 | int ctIdx = 0; |
| 846 | // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888 |
| 847 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 848 | constexpr GrColorType ct = GrColorType::kRGBA_8888; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 849 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 850 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 851 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 852 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 853 | } |
| 854 | // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x |
| 855 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 856 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 857 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 858 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 859 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 860 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 861 | ctInfo.fReadSwizzle = GrSwizzle::RGB1(); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | // Format: VK_FORMAT_R8_UNORM |
| 867 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 868 | constexpr VkFormat format = VK_FORMAT_R8_UNORM; |
| 869 | auto& info = this->getFormatInfo(format); |
| 870 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 871 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 872 | info.fColorTypeInfoCount = 2; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 873 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 874 | int ctIdx = 0; |
| 875 | // Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8 |
| 876 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 877 | constexpr GrColorType ct = GrColorType::kAlpha_8; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 878 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 879 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 880 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 881 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
Brian Salomon | b43d699 | 2021-01-05 14:37:40 -0500 | [diff] [blame] | 882 | ctInfo.fReadSwizzle = GrSwizzle("000r"); |
| 883 | ctInfo.fWriteSwizzle = GrSwizzle("a000"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 884 | } |
| 885 | // Format: VK_FORMAT_R8_UNORM, Surface: kGray_8 |
| 886 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 887 | constexpr GrColorType ct = GrColorType::kGray_8; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 888 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 889 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 890 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 891 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 892 | ctInfo.fReadSwizzle = GrSwizzle("rrr1"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | } |
| 896 | // Format: VK_FORMAT_B8G8R8A8_UNORM |
| 897 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 898 | constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM; |
| 899 | auto& info = this->getFormatInfo(format); |
| 900 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 901 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 902 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 903 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 904 | int ctIdx = 0; |
| 905 | // Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888 |
| 906 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 907 | constexpr GrColorType ct = GrColorType::kBGRA_8888; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 908 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 909 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 910 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 911 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | // Format: VK_FORMAT_R5G6B5_UNORM_PACK16 |
| 916 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 917 | constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
| 918 | auto& info = this->getFormatInfo(format); |
| 919 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 920 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 921 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 922 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 923 | int ctIdx = 0; |
| 924 | // Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565 |
| 925 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 926 | constexpr GrColorType ct = GrColorType::kBGR_565; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 927 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 928 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 929 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 930 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT |
| 935 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 936 | constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT; |
| 937 | auto& info = this->getFormatInfo(format); |
| 938 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 939 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 940 | info.fColorTypeInfoCount = 2; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 941 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 942 | int ctIdx = 0; |
| 943 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16 |
| 944 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 945 | constexpr GrColorType ct = GrColorType::kRGBA_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 946 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 947 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 948 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 949 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 950 | } |
| 951 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped |
| 952 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 953 | constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 954 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 955 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 956 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 957 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | // Format: VK_FORMAT_R16_SFLOAT |
| 962 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 963 | constexpr VkFormat format = VK_FORMAT_R16_SFLOAT; |
| 964 | auto& info = this->getFormatInfo(format); |
| 965 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 966 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 967 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 968 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 969 | int ctIdx = 0; |
| 970 | // Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16 |
| 971 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 972 | constexpr GrColorType ct = GrColorType::kAlpha_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 973 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 974 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 975 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 976 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
Brian Salomon | b43d699 | 2021-01-05 14:37:40 -0500 | [diff] [blame] | 977 | ctInfo.fReadSwizzle = GrSwizzle("000r"); |
| 978 | ctInfo.fWriteSwizzle = GrSwizzle("a000"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | } |
| 982 | // Format: VK_FORMAT_R8G8B8_UNORM |
| 983 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 984 | constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM; |
| 985 | auto& info = this->getFormatInfo(format); |
| 986 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 987 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 988 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 989 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 990 | int ctIdx = 0; |
| 991 | // Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x |
| 992 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 993 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 994 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 995 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 996 | // The Vulkan format is 3 bpp so we must convert to/from that when transferring. |
| 997 | ctInfo.fTransferColorType = GrColorType::kRGB_888; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 998 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | // Format: VK_FORMAT_R8G8_UNORM |
| 1003 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1004 | constexpr VkFormat format = VK_FORMAT_R8G8_UNORM; |
| 1005 | auto& info = this->getFormatInfo(format); |
| 1006 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1007 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1008 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1009 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1010 | int ctIdx = 0; |
| 1011 | // Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88 |
| 1012 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1013 | constexpr GrColorType ct = GrColorType::kRG_88; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1014 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1015 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1016 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1017 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32 |
| 1022 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1023 | constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32; |
| 1024 | auto& info = this->getFormatInfo(format); |
| 1025 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1026 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1027 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1028 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1029 | int ctIdx = 0; |
| 1030 | // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102 |
| 1031 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1032 | constexpr GrColorType ct = GrColorType::kRGBA_1010102; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1033 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1034 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1035 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1036 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1037 | } |
| 1038 | } |
| 1039 | } |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1040 | // Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32 |
| 1041 | { |
| 1042 | constexpr VkFormat format = VK_FORMAT_A2R10G10B10_UNORM_PACK32; |
| 1043 | auto& info = this->getFormatInfo(format); |
| 1044 | info.init(interface, physDev, properties, format); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1045 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1046 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1047 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1048 | int ctIdx = 0; |
| 1049 | // Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32, Surface: kBGRA_1010102 |
| 1050 | { |
| 1051 | constexpr GrColorType ct = GrColorType::kBGRA_1010102; |
| 1052 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1053 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1054 | ctInfo.fTransferColorType = ct; |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1055 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1056 | } |
| 1057 | } |
| 1058 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1059 | // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16 |
| 1060 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1061 | constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16; |
| 1062 | auto& info = this->getFormatInfo(format); |
| 1063 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1064 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1065 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1066 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1067 | int ctIdx = 0; |
| 1068 | // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 1069 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1070 | constexpr GrColorType ct = GrColorType::kABGR_4444; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1071 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1072 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1073 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1074 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 1075 | ctInfo.fReadSwizzle = GrSwizzle::BGRA(); |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 1076 | ctInfo.fWriteSwizzle = GrSwizzle::BGRA(); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } |
Greg Daniel | 373d7dd | 2020-07-21 10:41:50 -0400 | [diff] [blame] | 1080 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1081 | // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16 |
| 1082 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1083 | constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16; |
| 1084 | auto& info = this->getFormatInfo(format); |
| 1085 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1086 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1087 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1088 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1089 | int ctIdx = 0; |
| 1090 | // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 1091 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1092 | constexpr GrColorType ct = GrColorType::kABGR_4444; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1093 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1094 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1095 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1096 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1097 | } |
| 1098 | } |
| 1099 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1100 | // Format: VK_FORMAT_R8G8B8A8_SRGB |
| 1101 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1102 | constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB; |
| 1103 | auto& info = this->getFormatInfo(format); |
Brian Salomon | 14c514d | 2019-09-26 12:30:15 -0400 | [diff] [blame] | 1104 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1105 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1106 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1107 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1108 | int ctIdx = 0; |
| 1109 | // Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB |
| 1110 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1111 | constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1112 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1113 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1114 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1115 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | // Format: VK_FORMAT_R16_UNORM |
| 1120 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1121 | constexpr VkFormat format = VK_FORMAT_R16_UNORM; |
| 1122 | auto& info = this->getFormatInfo(format); |
| 1123 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1124 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1125 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1126 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1127 | int ctIdx = 0; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1128 | // Format: VK_FORMAT_R16_UNORM, Surface: kAlpha_16 |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1129 | { |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1130 | constexpr GrColorType ct = GrColorType::kAlpha_16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1131 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1132 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1133 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1134 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
Brian Salomon | b43d699 | 2021-01-05 14:37:40 -0500 | [diff] [blame] | 1135 | ctInfo.fReadSwizzle = GrSwizzle("000r"); |
| 1136 | ctInfo.fWriteSwizzle = GrSwizzle("a000"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | // Format: VK_FORMAT_R16G16_UNORM |
| 1141 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1142 | constexpr VkFormat format = VK_FORMAT_R16G16_UNORM; |
| 1143 | auto& info = this->getFormatInfo(format); |
| 1144 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1145 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1146 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1147 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1148 | int ctIdx = 0; |
| 1149 | // Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616 |
| 1150 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1151 | constexpr GrColorType ct = GrColorType::kRG_1616; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1152 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1153 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1154 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1155 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | // Format: VK_FORMAT_R16G16B16A16_UNORM |
| 1160 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1161 | constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM; |
| 1162 | auto& info = this->getFormatInfo(format); |
| 1163 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1164 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1165 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1166 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1167 | int ctIdx = 0; |
| 1168 | // Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616 |
| 1169 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1170 | constexpr GrColorType ct = GrColorType::kRGBA_16161616; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1171 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1172 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1173 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1174 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | // Format: VK_FORMAT_R16G16_SFLOAT |
| 1179 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1180 | constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT; |
| 1181 | auto& info = this->getFormatInfo(format); |
| 1182 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1183 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1184 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1185 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1186 | int ctIdx = 0; |
| 1187 | // Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16 |
| 1188 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1189 | constexpr GrColorType ct = GrColorType::kRG_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1190 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1191 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1192 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1193 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1194 | } |
| 1195 | } |
| 1196 | } |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1197 | // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM |
| 1198 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1199 | constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM; |
| 1200 | auto& info = this->getFormatInfo(format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1201 | if (fSupportsYcbcrConversion) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1202 | info.init(interface, physDev, properties, format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1203 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1204 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1205 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1206 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1207 | int ctIdx = 0; |
| 1208 | // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x |
| 1209 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1210 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1211 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1212 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1213 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1214 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM |
| 1219 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1220 | constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; |
| 1221 | auto& info = this->getFormatInfo(format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1222 | if (fSupportsYcbcrConversion) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1223 | info.init(interface, physDev, properties, format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1224 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1225 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1226 | info.fColorTypeInfoCount = 1; |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 1227 | info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1228 | int ctIdx = 0; |
| 1229 | // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x |
| 1230 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1231 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1232 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1233 | ctInfo.fColorType = ct; |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1234 | ctInfo.fTransferColorType = ct; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1235 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1239 | // Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK |
| 1240 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1241 | constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 1242 | auto& info = this->getFormatInfo(format); |
| 1243 | info.init(interface, physDev, properties, format); |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame] | 1244 | // Setting this to texel block size |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1245 | // No supported GrColorTypes. |
| 1246 | } |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1247 | |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 1248 | // Format: VK_FORMAT_BC1_RGB_UNORM_BLOCK |
| 1249 | { |
| 1250 | constexpr VkFormat format = VK_FORMAT_BC1_RGB_UNORM_BLOCK; |
| 1251 | auto& info = this->getFormatInfo(format); |
| 1252 | info.init(interface, physDev, properties, format); |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame] | 1253 | // Setting this to texel block size |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 1254 | // No supported GrColorTypes. |
| 1255 | } |
| 1256 | |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 1257 | // Format: VK_FORMAT_BC1_RGBA_UNORM_BLOCK |
| 1258 | { |
| 1259 | constexpr VkFormat format = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; |
| 1260 | auto& info = this->getFormatInfo(format); |
| 1261 | info.init(interface, physDev, properties, format); |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame] | 1262 | // Setting this to texel block size |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 1263 | // No supported GrColorTypes. |
| 1264 | } |
| 1265 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1266 | //////////////////////////////////////////////////////////////////////////// |
| 1267 | // Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats |
| 1268 | // are passed into the setColorType function indicates the priority in selecting which format |
| 1269 | // we use for a given GrcolorType. |
| 1270 | |
| 1271 | this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM }); |
| 1272 | this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16 }); |
| 1273 | this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
| 1274 | VK_FORMAT_B4G4R4A4_UNORM_PACK16 }); |
| 1275 | this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM }); |
| 1276 | this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB }); |
| 1277 | this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM, |
| 1278 | VK_FORMAT_R8G8B8A8_UNORM }); |
| 1279 | this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM }); |
| 1280 | this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM }); |
| 1281 | this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 }); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1282 | this->setColorType(GrColorType::kBGRA_1010102, { VK_FORMAT_A2R10G10B10_UNORM_PACK32 }); |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1283 | this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM }); |
| 1284 | this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT }); |
| 1285 | this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
| 1286 | this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1287 | this->setColorType(GrColorType::kAlpha_16, { VK_FORMAT_R16_UNORM }); |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1288 | this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM }); |
| 1289 | this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM }); |
| 1290 | this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT }); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1293 | void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1294 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 1295 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1296 | *flags = *flags | kTexturable_Flag; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1297 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1298 | // Ganesh assumes that all renderable surfaces are also texturable |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1299 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1300 | *flags = *flags | kRenderable_Flag; |
| 1301 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1302 | } |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 1303 | // TODO: For Vk w/ VK_KHR_maintenance1 extension support, check |
| 1304 | // VK_FORMAT_FEATURE_TRANSFER_[SRC|DST]_BIT_KHR explicitly to set copy flags |
| 1305 | // Can do similar check for VK_KHR_sampler_ycbcr_conversion added bits |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1306 | |
| 1307 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 1308 | *flags = *flags | kBlitSrc_Flag; |
| 1309 | } |
| 1310 | |
| 1311 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 1312 | *flags = *flags | kBlitDst_Flag; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1316 | void GrVkCaps::FormatInfo::initSampleCounts(const GrVkInterface* interface, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1317 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1318 | const VkPhysicalDeviceProperties& physProps, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1319 | VkFormat format) { |
| 1320 | VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 1321 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 1322 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 1323 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1324 | VkImageFormatProperties properties; |
| 1325 | GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev, |
| 1326 | format, |
| 1327 | VK_IMAGE_TYPE_2D, |
| 1328 | VK_IMAGE_TILING_OPTIMAL, |
| 1329 | usage, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 1330 | 0, // createFlags |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1331 | &properties)); |
| 1332 | VkSampleCountFlags flags = properties.sampleCounts; |
| 1333 | if (flags & VK_SAMPLE_COUNT_1_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1334 | fColorSampleCounts.push_back(1); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1335 | } |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1336 | if (kImagination_VkVendor == physProps.vendorID) { |
| 1337 | // MSAA does not work on imagination |
| 1338 | return; |
| 1339 | } |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 1340 | if (kIntel_VkVendor == physProps.vendorID) { |
Brian Osman | b5391bf | 2019-08-15 14:52:52 -0400 | [diff] [blame] | 1341 | // MSAA doesn't work well on Intel GPUs chromium:527565, chromium:983926 |
| 1342 | return; |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 1343 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1344 | if (flags & VK_SAMPLE_COUNT_2_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1345 | fColorSampleCounts.push_back(2); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1346 | } |
| 1347 | if (flags & VK_SAMPLE_COUNT_4_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1348 | fColorSampleCounts.push_back(4); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1349 | } |
| 1350 | if (flags & VK_SAMPLE_COUNT_8_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1351 | fColorSampleCounts.push_back(8); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1352 | } |
| 1353 | if (flags & VK_SAMPLE_COUNT_16_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1354 | fColorSampleCounts.push_back(16); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1355 | } |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 1356 | // Standard sample locations are not defined for more than 16 samples, and we don't need more |
| 1357 | // than 16. Omit 32 and 64. |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1358 | } |
| 1359 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1360 | void GrVkCaps::FormatInfo::init(const GrVkInterface* interface, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1361 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1362 | const VkPhysicalDeviceProperties& properties, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1363 | VkFormat format) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1364 | VkFormatProperties props; |
| 1365 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 1366 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1367 | InitFormatFlags(props.linearTilingFeatures, &fLinearFlags); |
| 1368 | InitFormatFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1369 | if (fOptimalFlags & kRenderable_Flag) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1370 | this->initSampleCounts(interface, physDev, properties, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1371 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1372 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1373 | |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1374 | // For many checks in caps, we need to know whether the GrBackendFormat is external or not. If it is |
| 1375 | // external the VkFormat will be VK_NULL_HANDLE which is not handled by our various format |
| 1376 | // capability checks. |
| 1377 | static bool backend_format_is_external(const GrBackendFormat& format) { |
| 1378 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1379 | SkASSERT(ycbcrInfo); |
| 1380 | |
| 1381 | // All external formats have a valid ycbcrInfo used for sampling and a non zero external format. |
| 1382 | if (ycbcrInfo->isValid() && ycbcrInfo->fExternalFormat != 0) { |
| 1383 | #ifdef SK_DEBUG |
| 1384 | VkFormat vkFormat; |
| 1385 | SkAssertResult(format.asVkFormat(&vkFormat)); |
Greg Daniel | f4e176b | 2021-08-11 18:31:17 -0400 | [diff] [blame] | 1386 | SkASSERT(vkFormat == VK_FORMAT_UNDEFINED); |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1387 | #endif |
| 1388 | return true; |
| 1389 | } |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1393 | bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1394 | VkFormat vkFormat; |
| 1395 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1396 | return false; |
| 1397 | } |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1398 | if (backend_format_is_external(format)) { |
| 1399 | return false; |
| 1400 | } |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1401 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1402 | return format_is_srgb(vkFormat); |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1403 | } |
| 1404 | |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 1405 | bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1406 | VkFormat vkFormat; |
| 1407 | if (!format.asVkFormat(&vkFormat)) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1408 | return false; |
| 1409 | } |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1410 | if (backend_format_is_external(format)) { |
| 1411 | // We can always texture from an external format (assuming we have the ycbcr conversion |
| 1412 | // info which we require to be passed in). |
| 1413 | return true; |
| 1414 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1415 | return this->isVkFormatTexturable(vkFormat); |
| 1416 | } |
| 1417 | |
| 1418 | bool GrVkCaps::isVkFormatTexturable(VkFormat format) const { |
| 1419 | const FormatInfo& info = this->getFormatInfo(format); |
| 1420 | return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags); |
Robert Phillips | 39ef2ef | 2019-05-15 08:45:53 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1423 | bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 1424 | int sampleCount) const { |
| 1425 | if (!this->isFormatRenderable(format, sampleCount)) { |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1426 | return false; |
| 1427 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1428 | VkFormat vkFormat; |
| 1429 | if (!format.asVkFormat(&vkFormat)) { |
| 1430 | return false; |
| 1431 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1432 | const auto& info = this->getFormatInfo(vkFormat); |
| 1433 | if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) { |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1434 | return false; |
| 1435 | } |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1436 | return true; |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1439 | bool GrVkCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1440 | VkFormat vkFormat; |
| 1441 | if (!format.asVkFormat(&vkFormat)) { |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1442 | return false; |
| 1443 | } |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1444 | return this->isFormatRenderable(vkFormat, sampleCount); |
| 1445 | } |
| 1446 | |
| 1447 | bool GrVkCaps::isFormatRenderable(VkFormat format, int sampleCount) const { |
| 1448 | return sampleCount <= this->maxRenderTargetSampleCount(format); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1451 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1452 | const GrBackendFormat& format) const { |
| 1453 | VkFormat vkFormat; |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1454 | if (!format.asVkFormat(&vkFormat)) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1458 | return this->getRenderTargetSampleCount(requestedCount, vkFormat); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1461 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1462 | requestedCount = std::max(1, requestedCount); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1463 | |
| 1464 | const FormatInfo& info = this->getFormatInfo(format); |
| 1465 | |
| 1466 | int count = info.fColorSampleCounts.count(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1467 | |
| 1468 | if (!count) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1469 | return 0; |
| 1470 | } |
| 1471 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1472 | if (1 == requestedCount) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1473 | SkASSERT(info.fColorSampleCounts.count() && info.fColorSampleCounts[0] == 1); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1474 | return 1; |
| 1475 | } |
| 1476 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1477 | for (int i = 0; i < count; ++i) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1478 | if (info.fColorSampleCounts[i] >= requestedCount) { |
| 1479 | return info.fColorSampleCounts[i]; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1480 | } |
| 1481 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1482 | return 0; |
| 1483 | } |
| 1484 | |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1485 | int GrVkCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1486 | VkFormat vkFormat; |
| 1487 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1488 | return 0; |
| 1489 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1490 | return this->maxRenderTargetSampleCount(vkFormat); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const { |
| 1494 | const FormatInfo& info = this->getFormatInfo(format); |
| 1495 | |
| 1496 | const auto& table = info.fColorSampleCounts; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1497 | if (!table.count()) { |
| 1498 | return 0; |
| 1499 | } |
| 1500 | return table[table.count() - 1]; |
Brian Salomon | d653cac | 2018-02-01 13:58:00 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1503 | static inline size_t align_to_4(size_t v) { |
| 1504 | switch (v & 0b11) { |
| 1505 | // v is already a multiple of 4. |
| 1506 | case 0: return v; |
| 1507 | // v is a multiple of 2 but not 4. |
| 1508 | case 2: return 2 * v; |
| 1509 | // v is not a multiple of 2. |
| 1510 | default: return 4 * v; |
| 1511 | } |
| 1512 | } |
| 1513 | |
Brian Salomon | 01915c0 | 2019-08-02 09:57:21 -0400 | [diff] [blame] | 1514 | GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfaceColorType, |
| 1515 | const GrBackendFormat& surfaceFormat, |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1516 | GrColorType srcColorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1517 | VkFormat vkFormat; |
| 1518 | if (!surfaceFormat.asVkFormat(&vkFormat)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1519 | return {GrColorType::kUnknown, 0}; |
| 1520 | } |
| 1521 | |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1522 | // We don't support the ability to upload to external formats or formats that require a ycbcr |
| 1523 | // sampler. In general these types of formats are only used for sampling in a shader. |
| 1524 | if (backend_format_is_external(surfaceFormat) || GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1525 | return {GrColorType::kUnknown, 0}; |
| 1526 | } |
| 1527 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1528 | // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 1529 | size_t offsetAlignment = align_to_4(GrVkFormatBytesPerBlock(vkFormat)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1530 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1531 | const auto& info = this->getFormatInfo(vkFormat); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1532 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1533 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1534 | if (ctInfo.fColorType == surfaceColorType) { |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1535 | return {ctInfo.fTransferColorType, offsetAlignment}; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | return {GrColorType::kUnknown, 0}; |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1539 | } |
| 1540 | |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1541 | GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels( |
| 1542 | const GrSurface* surface) const { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 1543 | if (surface->isProtected()) { |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1544 | return SurfaceReadPixelsSupport::kUnsupported; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 1545 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1546 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 1547 | auto texImage = tex->textureImage(); |
| 1548 | if (!texImage) { |
Greg Daniel | c265657 | 2021-08-16 16:24:18 -0400 | [diff] [blame] | 1549 | return SurfaceReadPixelsSupport::kUnsupported; |
| 1550 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1551 | // We can't directly read from a VkImage that has a ycbcr sampler. |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 1552 | if (texImage->ycbcrConversionInfo().isValid()) { |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1553 | return SurfaceReadPixelsSupport::kCopyToTexture2D; |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1554 | } |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1555 | // We can't directly read from a compressed format |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 1556 | if (GrVkFormatIsCompressed(texImage->imageFormat())) { |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1557 | return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1558 | } |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 1559 | return SurfaceReadPixelsSupport::kSupported; |
| 1560 | } else if (auto rt = surface->asRenderTarget()) { |
| 1561 | if (rt->numSamples() > 1) { |
| 1562 | return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1563 | } |
| 1564 | return SurfaceReadPixelsSupport::kSupported; |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1565 | } |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 1566 | return SurfaceReadPixelsSupport::kUnsupported; |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1567 | } |
| 1568 | |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1569 | GrColorType GrVkCaps::transferColorType(VkFormat vkFormat, GrColorType surfaceColorType) const { |
| 1570 | const auto& info = this->getFormatInfo(vkFormat); |
| 1571 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1572 | if (info.fColorTypeInfos[i].fColorType == surfaceColorType) { |
| 1573 | return info.fColorTypeInfos[i].fTransferColorType; |
| 1574 | } |
| 1575 | } |
| 1576 | return GrColorType::kUnknown; |
| 1577 | } |
| 1578 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 1579 | bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const { |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1580 | if (auto rt = surface->asRenderTarget()) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1581 | return rt->numSamples() <= 1 && SkToBool(surface->asTexture()); |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1582 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1583 | // We can't write to a texture that has a ycbcr sampler. |
| 1584 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 1585 | auto texImage = tex->textureImage(); |
| 1586 | if (!texImage) { |
Greg Daniel | c265657 | 2021-08-16 16:24:18 -0400 | [diff] [blame] | 1587 | return false; |
| 1588 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1589 | // We can't directly read from a VkImage that has a ycbcr sampler. |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 1590 | if (texImage->ycbcrConversionInfo().isValid()) { |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1591 | return false; |
| 1592 | } |
| 1593 | } |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1594 | return true; |
| 1595 | } |
| 1596 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1597 | bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 1598 | const GrBackendFormat& format) const { |
| 1599 | VkFormat vkFormat; |
| 1600 | if (!format.asVkFormat(&vkFormat)) { |
| 1601 | return false; |
| 1602 | } |
| 1603 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1604 | SkASSERT(ycbcrInfo); |
| 1605 | |
| 1606 | if (ycbcrInfo->isValid() && !GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1607 | // Format may be undefined for external images, which are required to have YCbCr conversion. |
Greg Daniel | a7b7fe0 | 2019-09-26 15:18:32 -0400 | [diff] [blame] | 1608 | if (VK_FORMAT_UNDEFINED == vkFormat && ycbcrInfo->fExternalFormat != 0) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1609 | return true; |
| 1610 | } |
| 1611 | return false; |
| 1612 | } |
| 1613 | |
| 1614 | const auto& info = this->getFormatInfo(vkFormat); |
| 1615 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1616 | if (info.fColorTypeInfos[i].fColorType == ct) { |
| 1617 | return true; |
| 1618 | } |
| 1619 | } |
| 1620 | return false; |
| 1621 | } |
| 1622 | |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 1623 | GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct) const { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1624 | VkFormat format = this->getFormatFromColorType(ct); |
| 1625 | if (format == VK_FORMAT_UNDEFINED) { |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 1626 | return {}; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1627 | } |
| 1628 | return GrBackendFormat::MakeVk(format); |
| 1629 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 1630 | |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 1631 | bool GrVkCaps::onSupportsDynamicMSAA(const GrRenderTargetProxy* rtProxy) const { |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 1632 | // We must be able to use the rtProxy as an input attachment to load into the discardable msaa |
| 1633 | // attachment. Also the rtProxy should have a sample count of 1 so that it can be used as a |
| 1634 | // resolve attachment. |
| 1635 | return this->supportsDiscardableMSAAForDMSAA() && |
| 1636 | rtProxy->supportsVkInputAttachment() && |
| 1637 | rtProxy->numSamples() == 1; |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | bool GrVkCaps::renderTargetSupportsDiscardableMSAA(const GrVkRenderTarget* rt) const { |
| 1641 | return rt->resolveAttachment() && |
| 1642 | rt->resolveAttachment()->supportsInputAttachmentUsage() && |
| 1643 | ((rt->numSamples() > 1 && this->preferDiscardableMSAAAttachment()) || |
| 1644 | (rt->numSamples() == 1 && this->supportsDiscardableMSAAForDMSAA())); |
| 1645 | } |
| 1646 | |
| 1647 | bool GrVkCaps::programInfoWillUseDiscardableMSAA(const GrProgramInfo& programInfo) const { |
| 1648 | return programInfo.targetHasVkResolveAttachmentWithInput() && |
| 1649 | programInfo.numSamples() > 1 && |
| 1650 | ((programInfo.targetsNumSamples() > 1 && this->preferDiscardableMSAAAttachment()) || |
| 1651 | (programInfo.targetsNumSamples() == 1 && this->supportsDiscardableMSAAForDMSAA())); |
| 1652 | } |
| 1653 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1654 | GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType( |
| 1655 | SkImage::CompressionType compressionType) const { |
| 1656 | switch (compressionType) { |
Robert Phillips | ab2b722 | 2019-12-10 10:05:06 -0500 | [diff] [blame] | 1657 | case SkImage::CompressionType::kNone: |
| 1658 | return {}; |
Robert Phillips | c558f72 | 2020-01-13 13:02:26 -0500 | [diff] [blame] | 1659 | case SkImage::CompressionType::kETC2_RGB8_UNORM: |
Robert Phillips | ee94693 | 2019-12-18 11:16:17 -0500 | [diff] [blame] | 1660 | if (this->isVkFormatTexturable(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)) { |
| 1661 | return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK); |
| 1662 | } |
| 1663 | return {}; |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 1664 | case SkImage::CompressionType::kBC1_RGB8_UNORM: |
| 1665 | if (this->isVkFormatTexturable(VK_FORMAT_BC1_RGB_UNORM_BLOCK)) { |
| 1666 | return GrBackendFormat::MakeVk(VK_FORMAT_BC1_RGB_UNORM_BLOCK); |
| 1667 | } |
| 1668 | return {}; |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 1669 | case SkImage::CompressionType::kBC1_RGBA8_UNORM: |
| 1670 | if (this->isVkFormatTexturable(VK_FORMAT_BC1_RGBA_UNORM_BLOCK)) { |
| 1671 | return GrBackendFormat::MakeVk(VK_FORMAT_BC1_RGBA_UNORM_BLOCK); |
| 1672 | } |
| 1673 | return {}; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1674 | } |
Robert Phillips | ab2b722 | 2019-12-10 10:05:06 -0500 | [diff] [blame] | 1675 | |
| 1676 | SkUNREACHABLE; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 1679 | GrSwizzle GrVkCaps::onGetReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1680 | VkFormat vkFormat; |
| 1681 | SkAssertResult(format.asVkFormat(&vkFormat)); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 1682 | const auto* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1683 | SkASSERT(ycbcrInfo); |
| 1684 | if (ycbcrInfo->isValid() && ycbcrInfo->fExternalFormat != 0) { |
| 1685 | // We allow these to work with any color type and never swizzle. See |
| 1686 | // onAreColorTypeAndFormatCompatible. |
| 1687 | return GrSwizzle{"rgba"}; |
| 1688 | } |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 1689 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1690 | const auto& info = this->getFormatInfo(vkFormat); |
| 1691 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1692 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1693 | if (ctInfo.fColorType == colorType) { |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 1694 | return ctInfo.fReadSwizzle; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1695 | } |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1696 | } |
John Stiles | 7bf7999 | 2021-06-25 11:05:20 -0400 | [diff] [blame] | 1697 | SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", |
| 1698 | (int)colorType, (int)vkFormat); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 1699 | return {}; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 1702 | GrSwizzle GrVkCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1703 | VkFormat vkFormat; |
| 1704 | SkAssertResult(format.asVkFormat(&vkFormat)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1705 | const auto& info = this->getFormatInfo(vkFormat); |
| 1706 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1707 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1708 | if (ctInfo.fColorType == colorType) { |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 1709 | return ctInfo.fWriteSwizzle; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1710 | } |
| 1711 | } |
John Stiles | 7bf7999 | 2021-06-25 11:05:20 -0400 | [diff] [blame] | 1712 | SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", |
| 1713 | (int)colorType, (int)vkFormat); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 1714 | return {}; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 1717 | GrDstSampleFlags GrVkCaps::onGetDstSampleFlagsForProxy(const GrRenderTargetProxy* rt) const { |
Greg Daniel | aacc9f72 | 2020-12-17 10:42:57 -0500 | [diff] [blame] | 1718 | bool isMSAAWithResolve = rt->numSamples() > 1 && rt->asTextureProxy(); |
| 1719 | // TODO: Currently if we have an msaa rt with a resolve, the supportsVkInputAttachment call |
| 1720 | // references whether the resolve is supported as an input attachment. We need to add a check to |
| 1721 | // allow checking the color attachment (msaa or not) supports input attachment specifically. |
| 1722 | if (!isMSAAWithResolve && rt->supportsVkInputAttachment()) { |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 1723 | return GrDstSampleFlags::kRequiresTextureBarrier | GrDstSampleFlags::kAsInputAttachment; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1724 | } |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 1725 | return GrDstSampleFlags::kNone; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1726 | } |
| 1727 | |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 1728 | uint64_t GrVkCaps::computeFormatKey(const GrBackendFormat& format) const { |
| 1729 | VkFormat vkFormat; |
| 1730 | SkAssertResult(format.asVkFormat(&vkFormat)); |
| 1731 | |
| 1732 | #ifdef SK_DEBUG |
| 1733 | // We should never be trying to compute a key for an external format |
| 1734 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1735 | SkASSERT(ycbcrInfo); |
| 1736 | SkASSERT(!ycbcrInfo->isValid() || ycbcrInfo->fExternalFormat == 0); |
| 1737 | #endif |
| 1738 | |
| 1739 | // A VkFormat has a size of 64 bits. |
| 1740 | return (uint64_t)vkFormat; |
| 1741 | } |
| 1742 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1743 | GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType( |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1744 | GrColorType srcColorType, const GrBackendFormat& srcBackendFormat, |
| 1745 | GrColorType dstColorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1746 | VkFormat vkFormat; |
| 1747 | if (!srcBackendFormat.asVkFormat(&vkFormat)) { |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 1748 | return {GrColorType::kUnknown, 0}; |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1749 | } |
| 1750 | |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1751 | if (GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1752 | return {GrColorType::kUnknown, 0}; |
| 1753 | } |
| 1754 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 1755 | SkImage::CompressionType compression = GrBackendFormatToCompressionType(srcBackendFormat); |
Robert Phillips | 07f0e41 | 2020-01-17 15:20:00 -0500 | [diff] [blame] | 1756 | if (compression != SkImage::CompressionType::kNone) { |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 1757 | return { SkCompressionTypeIsOpaque(compression) ? GrColorType::kRGB_888x |
Robert Phillips | 07f0e41 | 2020-01-17 15:20:00 -0500 | [diff] [blame] | 1758 | : GrColorType::kRGBA_8888, 0 }; |
| 1759 | } |
| 1760 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1761 | // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 1762 | size_t offsetAlignment = align_to_4(GrVkFormatBytesPerBlock(vkFormat)); |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1763 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1764 | const auto& info = this->getFormatInfo(vkFormat); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1765 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1766 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1767 | if (ctInfo.fColorType == srcColorType) { |
Brian Salomon | 974c821 | 2021-04-05 16:24:00 -0400 | [diff] [blame] | 1768 | return {ctInfo.fTransferColorType, offsetAlignment}; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1769 | } |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1770 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1771 | return {GrColorType::kUnknown, 0}; |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1772 | } |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1773 | |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame] | 1774 | int GrVkCaps::getFragmentUniformBinding() const { |
| 1775 | return GrVkUniformHandler::kUniformBinding; |
| 1776 | } |
| 1777 | |
| 1778 | int GrVkCaps::getFragmentUniformSet() const { |
| 1779 | return GrVkUniformHandler::kUniformBufferDescSet; |
| 1780 | } |
| 1781 | |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 1782 | void GrVkCaps::addExtraSamplerKey(GrProcessorKeyBuilder* b, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 1783 | GrSamplerState samplerState, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 1784 | const GrBackendFormat& format) const { |
| 1785 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1786 | if (!ycbcrInfo) { |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | GrVkSampler::Key key = GrVkSampler::GenerateKey(samplerState, *ycbcrInfo); |
| 1791 | |
Brian Osman | f0de96f | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 1792 | constexpr size_t numInts = (sizeof(key) + 3) / 4; |
| 1793 | uint32_t tmp[numInts]; |
Brian Osman | acf2650 | 2021-03-03 13:35:04 +0000 | [diff] [blame] | 1794 | memcpy(tmp, &key, sizeof(key)); |
Brian Osman | f0de96f | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 1795 | |
| 1796 | for (size_t i = 0; i < numInts; ++i) { |
| 1797 | b->add32(tmp[i]); |
| 1798 | } |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 1799 | } |
| 1800 | |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1801 | /** |
| 1802 | * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all |
| 1803 | * the information needed to differentiate one pipeline from another. |
| 1804 | * |
| 1805 | * The GrProgramDesc contains all the information need to create the actual shaders for the |
| 1806 | * pipeline. |
| 1807 | * |
| 1808 | * For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the |
| 1809 | * pipline. This includes stencil settings, blending information, render pass format, draw face |
| 1810 | * information, and primitive type. Note that some state is set dynamically on the pipeline for |
| 1811 | * each draw and thus is not included in this descriptor. This includes the viewport, scissor, |
| 1812 | * and blend constant. |
| 1813 | */ |
Greg Daniel | 91b37b1 | 2021-01-05 15:40:54 -0500 | [diff] [blame] | 1814 | GrProgramDesc GrVkCaps::makeDesc(GrRenderTarget* rt, |
| 1815 | const GrProgramInfo& programInfo, |
| 1816 | ProgramDescOverrideFlags overrideFlags) const { |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1817 | GrProgramDesc desc; |
Robert Phillips | ced5e83 | 2021-03-23 09:36:53 -0400 | [diff] [blame] | 1818 | GrProgramDesc::Build(&desc, programInfo, *this); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1819 | |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1820 | GrProcessorKeyBuilder b(desc.key()); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1821 | |
| 1822 | // This will become part of the sheared off key used to persistently cache |
| 1823 | // the SPIRV code. It needs to be added right after the base key so that, |
| 1824 | // when the base-key is sheared off, the shearing code can include it in the |
| 1825 | // reduced key (c.f. the +4s in the SkData::MakeWithCopy calls in |
| 1826 | // GrVkPipelineStateBuilder.cpp). |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1827 | b.add32(GrVkGpu::kShader_PersistentCacheKeyType); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1828 | |
Greg Daniel | 2177436 | 2020-09-14 10:36:43 -0400 | [diff] [blame] | 1829 | GrVkRenderPass::SelfDependencyFlags selfDepFlags = GrVkRenderPass::SelfDependencyFlags::kNone; |
| 1830 | if (programInfo.renderPassBarriers() & GrXferBarrierFlags::kBlend) { |
| 1831 | selfDepFlags |= GrVkRenderPass::SelfDependencyFlags::kForNonCoherentAdvBlend; |
| 1832 | } |
| 1833 | if (programInfo.renderPassBarriers() & GrXferBarrierFlags::kTexture) { |
| 1834 | selfDepFlags |= GrVkRenderPass::SelfDependencyFlags::kForInputAttachment; |
| 1835 | } |
Greg Daniel | b418921 | 2020-08-10 11:46:30 -0400 | [diff] [blame] | 1836 | |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 1837 | bool needsResolve = this->programInfoWillUseDiscardableMSAA(programInfo); |
Greg Daniel | a1b5d7e | 2020-12-17 10:36:58 -0500 | [diff] [blame] | 1838 | |
Greg Daniel | 91b37b1 | 2021-01-05 15:40:54 -0500 | [diff] [blame] | 1839 | bool forceLoadFromResolve = |
| 1840 | overrideFlags & GrCaps::ProgramDescOverrideFlags::kVulkanHasResolveLoadSubpass; |
| 1841 | SkASSERT(!forceLoadFromResolve || needsResolve); |
| 1842 | |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 1843 | GrVkRenderPass::LoadFromResolve loadFromResolve = GrVkRenderPass::LoadFromResolve::kNo; |
Greg Daniel | 91b37b1 | 2021-01-05 15:40:54 -0500 | [diff] [blame] | 1844 | if (needsResolve && (programInfo.colorLoadOp() == GrLoadOp::kLoad || forceLoadFromResolve)) { |
Greg Daniel | a1b5d7e | 2020-12-17 10:36:58 -0500 | [diff] [blame] | 1845 | loadFromResolve = GrVkRenderPass::LoadFromResolve::kLoad; |
| 1846 | } |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 1847 | |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1848 | if (rt) { |
| 1849 | GrVkRenderTarget* vkRT = (GrVkRenderTarget*) rt; |
Robert Phillips | 96f2237 | 2020-05-20 12:31:18 -0400 | [diff] [blame] | 1850 | |
Greg Daniel | 00d6cf4 | 2021-03-05 22:50:08 +0000 | [diff] [blame] | 1851 | SkASSERT(!needsResolve || (vkRT->resolveAttachment() && |
| 1852 | vkRT->resolveAttachment()->supportsInputAttachmentUsage())); |
Greg Daniel | a1b5d7e | 2020-12-17 10:36:58 -0500 | [diff] [blame] | 1853 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 1854 | bool needsStencil = programInfo.needsStencil() || programInfo.isStencilEnabled(); |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1855 | // TODO: support failure in getSimpleRenderPass |
Greg Daniel | 805c622 | 2021-04-20 12:44:48 -0400 | [diff] [blame] | 1856 | auto rp = vkRT->getSimpleRenderPass(needsResolve, needsStencil, selfDepFlags, |
| 1857 | loadFromResolve); |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1858 | SkASSERT(rp); |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1859 | rp->genKey(&b); |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1860 | |
| 1861 | #ifdef SK_DEBUG |
| 1862 | if (!rp->isExternal()) { |
| 1863 | // This is to ensure ReconstructAttachmentsDescriptor keeps matching |
| 1864 | // getSimpleRenderPass' result |
| 1865 | GrVkRenderPass::AttachmentsDescriptor attachmentsDescriptor; |
| 1866 | GrVkRenderPass::AttachmentFlags attachmentFlags; |
| 1867 | GrVkRenderTarget::ReconstructAttachmentsDescriptor(*this, programInfo, |
| 1868 | &attachmentsDescriptor, |
| 1869 | &attachmentFlags); |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 1870 | SkASSERT(rp->isCompatible(attachmentsDescriptor, attachmentFlags, selfDepFlags, |
| 1871 | loadFromResolve)); |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1872 | } |
| 1873 | #endif |
| 1874 | } else { |
| 1875 | GrVkRenderPass::AttachmentsDescriptor attachmentsDescriptor; |
| 1876 | GrVkRenderPass::AttachmentFlags attachmentFlags; |
| 1877 | GrVkRenderTarget::ReconstructAttachmentsDescriptor(*this, programInfo, |
| 1878 | &attachmentsDescriptor, |
| 1879 | &attachmentFlags); |
| 1880 | |
| 1881 | // kExternal_AttachmentFlag is only set for wrapped secondary command buffers - which |
| 1882 | // will always go through the above 'rt' path (i.e., we can always pass 0 as the final |
| 1883 | // parameter to GenKey). |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1884 | GrVkRenderPass::GenKey(&b, attachmentFlags, attachmentsDescriptor, selfDepFlags, |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 1885 | loadFromResolve, 0); |
Robert Phillips | 24e2f6e | 2020-06-26 08:30:07 -0400 | [diff] [blame] | 1886 | } |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1887 | |
| 1888 | GrStencilSettings stencil = programInfo.nonGLStencilSettings(); |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1889 | stencil.genKey(&b, true); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1890 | |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1891 | programInfo.pipeline().genKey(&b, *this); |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 1892 | b.add32(programInfo.numSamples()); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1893 | |
| 1894 | // Vulkan requires the full primitive type as part of its key |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1895 | b.add32(programInfo.primitiveTypeKey()); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1896 | |
Brian Osman | e23c03d | 2021-03-05 14:58:25 -0500 | [diff] [blame] | 1897 | b.flush(); |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 1898 | return desc; |
| 1899 | } |
| 1900 | |
Greg Daniel | 638b2e8 | 2020-08-27 14:29:00 -0400 | [diff] [blame] | 1901 | GrInternalSurfaceFlags GrVkCaps::getExtraSurfaceFlagsForDeferredRT() const { |
| 1902 | // We always create vulkan RT with the input attachment flag; |
| 1903 | return GrInternalSurfaceFlags::kVkRTSupportsInputAttachment; |
| 1904 | } |
| 1905 | |
Jim Van Verth | 7d338c2 | 2021-02-03 12:54:30 -0500 | [diff] [blame] | 1906 | VkShaderStageFlags GrVkCaps::getPushConstantStageFlags() const { |
| 1907 | VkShaderStageFlags stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; |
Jim Van Verth | 7d338c2 | 2021-02-03 12:54:30 -0500 | [diff] [blame] | 1908 | return stageFlags; |
| 1909 | } |
| 1910 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1911 | #if GR_TEST_UTILS |
| 1912 | std::vector<GrCaps::TestFormatColorTypeCombination> GrVkCaps::getTestingCombinations() const { |
| 1913 | std::vector<GrCaps::TestFormatColorTypeCombination> combos = { |
| 1914 | { GrColorType::kAlpha_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 1915 | { GrColorType::kBGR_565, GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16) }, |
| 1916 | { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_R4G4B4A4_UNORM_PACK16)}, |
| 1917 | { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16)}, |
| 1918 | { GrColorType::kRGBA_8888, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 1919 | { GrColorType::kRGBA_8888_SRGB, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB) }, |
| 1920 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 1921 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM) }, |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1922 | { GrColorType::kRG_88, GrBackendFormat::MakeVk(VK_FORMAT_R8G8_UNORM) }, |
| 1923 | { GrColorType::kBGRA_8888, GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) }, |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1924 | { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)}, |
| 1925 | { GrColorType::kBGRA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2R10G10B10_UNORM_PACK32)}, |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1926 | { GrColorType::kGray_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 1927 | { GrColorType::kAlpha_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16_SFLOAT) }, |
| 1928 | { GrColorType::kRGBA_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 1929 | { GrColorType::kRGBA_F16_Clamped, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1930 | { GrColorType::kAlpha_16, GrBackendFormat::MakeVk(VK_FORMAT_R16_UNORM) }, |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1931 | { GrColorType::kRG_1616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_UNORM) }, |
| 1932 | { GrColorType::kRGBA_16161616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_UNORM) }, |
| 1933 | { GrColorType::kRG_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_SFLOAT) }, |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 1934 | // These two compressed formats both have an effective colorType of kRGB_888x |
| 1935 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)}, |
| 1936 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_BC1_RGB_UNORM_BLOCK) }, |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 1937 | { GrColorType::kRGBA_8888, GrBackendFormat::MakeVk(VK_FORMAT_BC1_RGBA_UNORM_BLOCK) }, |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1938 | }; |
| 1939 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1940 | return combos; |
| 1941 | } |
| 1942 | #endif |