Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/gpu/vk/GrVkBackendContext.h" |
| 10 | #include "include/gpu/vk/GrVkExtensions.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrRenderTarget.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrShaderCaps.h" |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrUtil.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/SkGr.h" |
| 16 | #include "src/gpu/vk/GrVkCaps.h" |
| 17 | #include "src/gpu/vk/GrVkInterface.h" |
| 18 | #include "src/gpu/vk/GrVkTexture.h" |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame] | 19 | #include "src/gpu/vk/GrVkUniformHandler.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 21 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 22 | #ifdef SK_BUILD_FOR_ANDROID |
| 23 | #include <sys/system_properties.h> |
| 24 | #endif |
| 25 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 26 | GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 27 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 28 | uint32_t instanceVersion, uint32_t physicalDeviceVersion, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 29 | const GrVkExtensions& extensions, GrProtected isProtected) |
| 30 | : INHERITED(contextOptions) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 31 | /************************************************************************** |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 32 | * GrCaps fields |
| 33 | **************************************************************************/ |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 34 | fMipMapSupport = true; // always available in Vulkan |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 35 | fSRGBSupport = true; // always available in Vulkan |
brianosman | 8879186 | 2016-05-23 10:15:27 -0700 | [diff] [blame] | 36 | fNPOTTextureTileSupport = true; // always available in Vulkan |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | fReuseScratchTextures = true; //TODO: figure this out |
| 38 | fGpuTracingSupport = false; //TODO: figure this out |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 39 | fOversizedStencilSupport = false; //TODO: figure this out |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 40 | fInstanceAttribSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 42 | fSemaphoreSupport = true; // always available in Vulkan |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 43 | fFenceSyncSupport = true; // always available in Vulkan |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 44 | fCrossContextTextureSupport = true; |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 45 | fHalfFloatVertexAttributeSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 46 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 47 | // We always copy in/out of a transfer buffer so it's trivial to support row bytes. |
| 48 | fReadPixelsRowBytesSupport = true; |
| 49 | fWritePixelsRowBytesSupport = true; |
| 50 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 51 | fTransferBufferSupport = true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | |
| 53 | fMaxRenderTargetSize = 4096; // minimum required by spec |
| 54 | fMaxTextureSize = 4096; // minimum required by spec |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 56 | fDynamicStateArrayGeometryProcessorTextureSupport = true; |
| 57 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 58 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 60 | this->init(contextOptions, vkInterface, physDev, features, physicalDeviceVersion, extensions, |
| 61 | isProtected); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 64 | namespace { |
| 65 | /** |
| 66 | * This comes from section 37.1.6 of the Vulkan spec. Format is |
| 67 | * (<bits>|<tag>)_<block_size>_<texels_per_block>. |
| 68 | */ |
| 69 | enum class FormatCompatibilityClass { |
| 70 | k8_1_1, |
| 71 | k16_2_1, |
| 72 | k24_3_1, |
| 73 | k32_4_1, |
| 74 | k64_8_1, |
| 75 | k128_16_1, |
| 76 | kETC2_RGB_8_16, |
| 77 | }; |
| 78 | } // anonymous namespace |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 79 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 80 | static FormatCompatibilityClass format_compatibility_class(VkFormat format) { |
| 81 | switch (format) { |
| 82 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 83 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 84 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: |
| 85 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 86 | case VK_FORMAT_R16G16_UNORM: |
| 87 | case VK_FORMAT_R16G16_SFLOAT: |
| 88 | return FormatCompatibilityClass::k32_4_1; |
| 89 | |
| 90 | case VK_FORMAT_R8_UNORM: |
| 91 | return FormatCompatibilityClass::k8_1_1; |
| 92 | |
| 93 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 94 | case VK_FORMAT_R16_SFLOAT: |
| 95 | case VK_FORMAT_R8G8_UNORM: |
| 96 | case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
| 97 | case VK_FORMAT_R4G4B4A4_UNORM_PACK16: |
| 98 | case VK_FORMAT_R16_UNORM: |
| 99 | return FormatCompatibilityClass::k16_2_1; |
| 100 | |
| 101 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 102 | case VK_FORMAT_R16G16B16A16_UNORM: |
| 103 | return FormatCompatibilityClass::k64_8_1; |
| 104 | |
| 105 | case VK_FORMAT_R8G8B8_UNORM: |
| 106 | return FormatCompatibilityClass::k24_3_1; |
| 107 | |
| 108 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 109 | return FormatCompatibilityClass::k128_16_1; |
| 110 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 111 | return FormatCompatibilityClass::kETC2_RGB_8_16; |
| 112 | |
| 113 | default: |
| 114 | SK_ABORT("Unsupported VkFormat"); |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 115 | } |
Greg Daniel | 5c7b541 | 2019-05-10 11:39:55 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 118 | bool GrVkCaps::canCopyImage(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 119 | VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 120 | if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) { |
| 121 | return false; |
| 122 | } |
| 123 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 124 | if (dstHasYcbcr || srcHasYcbcr) { |
| 125 | return false; |
| 126 | } |
| 127 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 128 | // 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] | 129 | // as image usage flags. |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 130 | return format_compatibility_class(srcFormat) == format_compatibility_class(dstFormat); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 133 | bool GrVkCaps::canCopyAsBlit(VkFormat dstFormat, int dstSampleCnt, bool dstIsLinear, |
| 134 | bool dstHasYcbcr, VkFormat srcFormat, int srcSampleCnt, |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 135 | bool srcIsLinear, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 136 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 137 | // as image usage flags. |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 138 | if (!this->formatCanBeDstofBlit(dstFormat, dstIsLinear) || |
| 139 | !this->formatCanBeSrcofBlit(srcFormat, srcIsLinear)) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 140 | return false; |
| 141 | } |
| 142 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 143 | // We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 144 | // resolved msaa though. |
| 145 | if (dstSampleCnt > 1 || srcSampleCnt > 1) { |
| 146 | return false; |
| 147 | } |
| 148 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 149 | if (dstHasYcbcr || srcHasYcbcr) { |
| 150 | return false; |
| 151 | } |
| 152 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 153 | return true; |
| 154 | } |
| 155 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 156 | bool GrVkCaps::canCopyAsResolve(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 157 | VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 158 | // The src surface must be multisampled. |
| 159 | if (srcSampleCnt <= 1) { |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | // The dst must not be multisampled. |
| 164 | if (dstSampleCnt > 1) { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | // Surfaces must have the same format. |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 169 | if (srcFormat != dstFormat) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 170 | return false; |
| 171 | } |
| 172 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 173 | if (dstHasYcbcr || srcHasYcbcr) { |
| 174 | return false; |
| 175 | } |
| 176 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 180 | bool GrVkCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 181 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 182 | if (src->isProtected() && !dst->isProtected()) { |
| 183 | return false; |
| 184 | } |
| 185 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 186 | // TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g. |
| 187 | // PromiseImage which won't get instantiated right away. Does this need a similar thing like the |
| 188 | // tracking of external or rectangle textures in GL? For now we don't create linear textures |
| 189 | // internally, and I don't believe anyone is wrapping them. |
| 190 | bool srcIsLinear = false; |
| 191 | bool dstIsLinear = false; |
| 192 | |
| 193 | int dstSampleCnt = 0; |
| 194 | int srcSampleCnt = 0; |
| 195 | if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 196 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 197 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 198 | // to stop and start the VkRenderPass which we don't have access to. |
| 199 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 200 | return false; |
| 201 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 202 | dstSampleCnt = rtProxy->numSamples(); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 203 | } |
| 204 | if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 205 | // Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 206 | // since they would require us to know the VkImage, which we don't have, as well as need us |
| 207 | // to stop and start the VkRenderPass which we don't have access to. |
| 208 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 209 | return false; |
| 210 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 211 | srcSampleCnt = rtProxy->numSamples(); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 212 | } |
| 213 | SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy())); |
| 214 | SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy())); |
| 215 | |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 216 | bool dstHasYcbcr = false; |
| 217 | if (auto ycbcr = dst->backendFormat().getVkYcbcrConversionInfo()) { |
| 218 | if (ycbcr->isValid()) { |
| 219 | dstHasYcbcr = true; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | bool srcHasYcbcr = false; |
| 224 | if (auto ycbcr = src->backendFormat().getVkYcbcrConversionInfo()) { |
| 225 | if (ycbcr->isValid()) { |
| 226 | srcHasYcbcr = true; |
| 227 | } |
| 228 | } |
| 229 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 230 | VkFormat dstFormat, srcFormat; |
| 231 | SkAssertResult(dst->backendFormat().asVkFormat(&dstFormat)); |
| 232 | SkAssertResult(src->backendFormat().asVkFormat(&srcFormat)); |
| 233 | |
| 234 | return this->canCopyImage(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 235 | srcFormat, srcSampleCnt, srcHasYcbcr) || |
| 236 | this->canCopyAsBlit(dstFormat, dstSampleCnt, dstIsLinear, dstHasYcbcr, |
| 237 | srcFormat, srcSampleCnt, srcIsLinear, srcHasYcbcr) || |
| 238 | this->canCopyAsResolve(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 239 | srcFormat, srcSampleCnt, srcHasYcbcr); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 242 | template<typename T> T* get_extension_feature_struct(const VkPhysicalDeviceFeatures2& features, |
| 243 | VkStructureType type) { |
| 244 | // All Vulkan structs that could be part of the features chain will start with the |
| 245 | // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader |
| 246 | // so we can get access to the pNext for the next struct. |
| 247 | struct CommonVulkanHeader { |
| 248 | VkStructureType sType; |
| 249 | void* pNext; |
| 250 | }; |
| 251 | |
| 252 | void* pNext = features.pNext; |
| 253 | while (pNext) { |
| 254 | CommonVulkanHeader* header = static_cast<CommonVulkanHeader*>(pNext); |
| 255 | if (header->sType == type) { |
| 256 | return static_cast<T*>(pNext); |
| 257 | } |
| 258 | pNext = header->pNext; |
| 259 | } |
| 260 | return nullptr; |
| 261 | } |
| 262 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 263 | void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 264 | VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures2& features, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 265 | uint32_t physicalDeviceVersion, const GrVkExtensions& extensions, |
| 266 | GrProtected isProtected) { |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 267 | VkPhysicalDeviceProperties properties; |
| 268 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 269 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 270 | VkPhysicalDeviceMemoryProperties memoryProperties; |
| 271 | GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 272 | |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 273 | SkASSERT(physicalDeviceVersion <= properties.apiVersion); |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 274 | |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 275 | if (extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 1)) { |
| 276 | fSupportsSwapchain = true; |
| 277 | } |
| 278 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 279 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 280 | extensions.hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { |
| 281 | fSupportsPhysicalDeviceProperties2 = true; |
| 282 | } |
| 283 | |
| 284 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 285 | extensions.hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { |
| 286 | fSupportsMemoryRequirements2 = true; |
| 287 | } |
| 288 | |
| 289 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 290 | extensions.hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { |
| 291 | fSupportsBindMemory2 = true; |
| 292 | } |
| 293 | |
| 294 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 295 | extensions.hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { |
| 296 | fSupportsMaintenance1 = true; |
| 297 | } |
| 298 | |
| 299 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 300 | extensions.hasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME, 1)) { |
| 301 | fSupportsMaintenance2 = true; |
| 302 | } |
| 303 | |
| 304 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 305 | extensions.hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { |
| 306 | fSupportsMaintenance3 = true; |
| 307 | } |
| 308 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 309 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 310 | (extensions.hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) && |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 311 | this->supportsMemoryRequirements2())) { |
| 312 | fSupportsDedicatedAllocation = true; |
| 313 | } |
| 314 | |
| 315 | if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 316 | (extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1) && |
| 317 | this->supportsPhysicalDeviceProperties2() && |
| 318 | extensions.hasExtension(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, 1) && |
| 319 | this->supportsDedicatedAllocation())) { |
| 320 | fSupportsExternalMemory = true; |
| 321 | } |
| 322 | |
| 323 | #ifdef SK_BUILD_FOR_ANDROID |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 324 | // Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they |
| 325 | // 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] | 326 | if (extensions.hasExtension( |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 327 | VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, 2) && |
| 328 | /* extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1) &&*/ |
| 329 | this->supportsExternalMemory() && |
| 330 | this->supportsBindMemory2()) { |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 331 | fSupportsAndroidHWBExternalMemory = true; |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 332 | fSupportsAHardwareBufferImages = true; |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 333 | } |
| 334 | #endif |
| 335 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 336 | auto ycbcrFeatures = |
| 337 | get_extension_feature_struct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>( |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 338 | features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES); |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 339 | if (ycbcrFeatures && ycbcrFeatures->samplerYcbcrConversion && |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 340 | (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || |
| 341 | (extensions.hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1) && |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 342 | this->supportsMaintenance1() && this->supportsBindMemory2() && |
| 343 | this->supportsMemoryRequirements2() && this->supportsPhysicalDeviceProperties2()))) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 344 | fSupportsYcbcrConversion = true; |
| 345 | } |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 346 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 347 | // We always push back the default GrVkYcbcrConversionInfo so that the case of no conversion |
| 348 | // will return a key of 0. |
| 349 | fYcbcrInfos.push_back(GrVkYcbcrConversionInfo()); |
| 350 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 351 | if ((isProtected == GrProtected::kYes) && |
| 352 | (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0))) { |
| 353 | fSupportsProtectedMemory = true; |
| 354 | fAvoidUpdateBuffers = true; |
| 355 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 356 | } |
| 357 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 358 | this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions); |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 359 | this->initShaderCaps(properties, features); |
Greg Daniel | f3b1162 | 2018-03-01 15:01:27 -0500 | [diff] [blame] | 360 | |
| 361 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 362 | #if defined(SK_CPU_X86) |
| 363 | // We need to do this before initing the config table since it uses fSRGBSupport |
| 364 | if (kImagination_VkVendor == properties.vendorID) { |
| 365 | fSRGBSupport = false; |
| 366 | } |
| 367 | #endif |
| 368 | } |
| 369 | |
Chris Dalton | 8e738a2 | 2018-10-05 16:41:44 -0600 | [diff] [blame] | 370 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 371 | // A "clear" load for the CCPR atlas runs faster on QC than a "discard" load followed by a |
| 372 | // scissored clear. |
| 373 | // On NVIDIA and Intel, the discard load followed by clear is faster. |
| 374 | // TODO: Evaluate on ARM, Imagination, and ATI. |
| 375 | fPreferFullscreenClears = true; |
| 376 | } |
| 377 | |
Greg Daniel | 44e69f9 | 2019-03-20 11:18:25 -0400 | [diff] [blame] | 378 | if (kQualcomm_VkVendor == properties.vendorID || kARM_VkVendor == properties.vendorID) { |
| 379 | // On Qualcomm and ARM mapping a gpu buffer and doing both reads and writes to it is slow. |
| 380 | // Thus for index and vertex buffers we will force to use a cpu side buffer and then copy |
| 381 | // the whole buffer up to the gpu. |
Greg Daniel | 78e6a4c | 2019-03-19 14:13:36 -0400 | [diff] [blame] | 382 | fBufferMapThreshold = SK_MaxS32; |
| 383 | } |
| 384 | |
| 385 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 386 | // On Qualcomm it looks like using vkCmdUpdateBuffer is slower than using a transfer buffer |
| 387 | // even for small sizes. |
| 388 | fAvoidUpdateBuffers = true; |
| 389 | } |
| 390 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 391 | if (kARM_VkVendor == properties.vendorID) { |
| 392 | // ARM seems to do better with more fine triangles as opposed to using the sample mask. |
| 393 | // (At least in our current round rect op.) |
| 394 | fPreferTrianglesOverSampleMask = true; |
| 395 | } |
Greg Daniel | 78e6a4c | 2019-03-19 14:13:36 -0400 | [diff] [blame] | 396 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 397 | this->initFormatTable(vkInterface, physDev, properties); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 398 | this->initStencilFormat(vkInterface, physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 399 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 400 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 401 | this->applyDriverCorrectnessWorkarounds(properties); |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 402 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 403 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 404 | this->applyOptionsOverrides(contextOptions); |
| 405 | fShaderCaps->applyOptionsOverrides(contextOptions); |
| 406 | } |
| 407 | |
| 408 | void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) { |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 409 | if (kQualcomm_VkVendor == properties.vendorID) { |
| 410 | fMustDoCopiesFromOrigin = true; |
Brian Salomon | a585fe9 | 2019-04-09 14:57:00 -0400 | [diff] [blame] | 411 | // Transfer doesn't support this workaround. |
| 412 | fTransferBufferSupport = false; |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 415 | #if defined(SK_BUILD_FOR_WIN) |
Greg Daniel | 900e5c8 | 2018-08-28 10:59:24 -0400 | [diff] [blame] | 416 | if (kNvidia_VkVendor == properties.vendorID || kIntel_VkVendor == properties.vendorID) { |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 417 | fMustSleepOnTearDown = true; |
| 418 | } |
| 419 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 420 | if (kImagination_VkVendor == properties.vendorID) { |
| 421 | fMustSleepOnTearDown = true; |
| 422 | } |
| 423 | #endif |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 424 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 425 | #if defined(SK_BUILD_FOR_ANDROID) |
| 426 | // Protected memory features have problems in Android P and earlier. |
| 427 | if (fSupportsProtectedMemory && (kQualcomm_VkVendor == properties.vendorID)) { |
| 428 | char androidAPIVersion[PROP_VALUE_MAX]; |
| 429 | int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion); |
| 430 | if (strLength == 0 || atoi(androidAPIVersion) <= 28) { |
| 431 | fSupportsProtectedMemory = false; |
| 432 | } |
| 433 | } |
| 434 | #endif |
| 435 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 436 | // On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages. |
| 437 | if (kARM_VkVendor == properties.vendorID) { |
| 438 | fShouldAlwaysUseDedicatedImageMemory = true; |
| 439 | } |
| 440 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 441 | //////////////////////////////////////////////////////////////////////////// |
| 442 | // GrCaps workarounds |
| 443 | //////////////////////////////////////////////////////////////////////////// |
| 444 | |
| 445 | if (kARM_VkVendor == properties.vendorID) { |
| 446 | fInstanceAttribSupport = false; |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 447 | fAvoidWritePixelsFastPath = true; // bugs.skia.org/8064 |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | // AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 451 | if (kAMD_VkVendor == properties.vendorID) { |
| 452 | fMaxVertexAttributes = SkTMin(fMaxVertexAttributes, 32); |
| 453 | } |
| 454 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 455 | //////////////////////////////////////////////////////////////////////////// |
| 456 | // GrShaderCaps workarounds |
| 457 | //////////////////////////////////////////////////////////////////////////// |
| 458 | |
Greg Daniel | bce5eb9 | 2018-03-01 13:13:44 -0500 | [diff] [blame] | 459 | if (kImagination_VkVendor == properties.vendorID) { |
| 460 | fShaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 461 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | int get_max_sample_count(VkSampleCountFlags flags) { |
| 465 | SkASSERT(flags & VK_SAMPLE_COUNT_1_BIT); |
| 466 | if (!(flags & VK_SAMPLE_COUNT_2_BIT)) { |
| 467 | return 0; |
| 468 | } |
| 469 | if (!(flags & VK_SAMPLE_COUNT_4_BIT)) { |
| 470 | return 2; |
| 471 | } |
| 472 | if (!(flags & VK_SAMPLE_COUNT_8_BIT)) { |
| 473 | return 4; |
| 474 | } |
| 475 | if (!(flags & VK_SAMPLE_COUNT_16_BIT)) { |
| 476 | return 8; |
| 477 | } |
| 478 | if (!(flags & VK_SAMPLE_COUNT_32_BIT)) { |
| 479 | return 16; |
| 480 | } |
| 481 | if (!(flags & VK_SAMPLE_COUNT_64_BIT)) { |
| 482 | return 32; |
| 483 | } |
| 484 | return 64; |
| 485 | } |
| 486 | |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 487 | void GrVkCaps::initGrCaps(const GrVkInterface* vkInterface, |
| 488 | VkPhysicalDevice physDev, |
| 489 | const VkPhysicalDeviceProperties& properties, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 490 | const VkPhysicalDeviceMemoryProperties& memoryProperties, |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 491 | const VkPhysicalDeviceFeatures2& features, |
| 492 | const GrVkExtensions& extensions) { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 493 | // So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 494 | // need for us ever to support that amount, and it makes tests which tests all the vertex |
| 495 | // attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 496 | // we ever find that need. |
| 497 | static const uint32_t kMaxVertexAttributes = 64; |
| 498 | fMaxVertexAttributes = SkTMin(properties.limits.maxVertexInputAttributes, kMaxVertexAttributes); |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 499 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 500 | // We could actually query and get a max size for each config, however maxImageDimension2D will |
| 501 | // give the minimum max size across all configs. So for simplicity we will use that for now. |
jvanverth | e78d487 | 2016-09-27 03:33:05 -0700 | [diff] [blame] | 502 | fMaxRenderTargetSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 503 | fMaxTextureSize = SkTMin(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
Adrienne Walker | 724afe8 | 2018-05-15 11:36:26 -0700 | [diff] [blame] | 504 | if (fDriverBugWorkarounds.max_texture_size_limit_4096) { |
| 505 | fMaxTextureSize = SkTMin(fMaxTextureSize, 4096); |
| 506 | } |
| 507 | // Our render targets are always created with textures as the color |
| 508 | // attachment, hence this min: |
| 509 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 510 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 511 | // TODO: check if RT's larger than 4k incur a performance cost on ARM. |
| 512 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 513 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 514 | // Assuming since we will always map in the end to upload the data we might as well just map |
| 515 | // 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] | 516 | fBufferMapThreshold = 0; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 517 | |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 518 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag | kAsyncRead_MapFlag; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 519 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 520 | fOversizedStencilSupport = true; |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 521 | |
| 522 | if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2) && |
| 523 | this->supportsPhysicalDeviceProperties2()) { |
| 524 | |
| 525 | VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps; |
| 526 | blendProps.sType = |
| 527 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT; |
| 528 | blendProps.pNext = nullptr; |
| 529 | |
| 530 | VkPhysicalDeviceProperties2 props; |
| 531 | props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; |
| 532 | props.pNext = &blendProps; |
| 533 | |
| 534 | GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props)); |
| 535 | |
| 536 | if (blendProps.advancedBlendAllOperations == VK_TRUE) { |
| 537 | fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
| 538 | |
| 539 | auto blendFeatures = |
| 540 | get_extension_feature_struct<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>( |
| 541 | features, |
| 542 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT); |
| 543 | if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) { |
| 544 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 545 | } else { |
| 546 | // TODO: Currently non coherent blends are not supported in our vulkan backend. They |
| 547 | // require us to support self dependencies in our render passes. |
| 548 | // fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 549 | } |
| 550 | } |
| 551 | } |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Greg Daniel | 3644360 | 2018-08-02 12:51:52 -0400 | [diff] [blame] | 554 | void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 555 | const VkPhysicalDeviceFeatures2& features) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 556 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 557 | shaderCaps->fVersionDeclString = "#version 330\n"; |
egdaniel | 3a15fd4 | 2016-04-05 11:00:29 -0700 | [diff] [blame] | 558 | |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 559 | // 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] | 560 | shaderCaps->fUsesPrecisionModifiers = true; |
| 561 | shaderCaps->fFlatInterpolationSupport = true; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 562 | // Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 563 | // to be true with Vulkan as well. |
| 564 | shaderCaps->fPreferFlatInterpolation = kQualcomm_VkVendor != properties.vendorID; |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 565 | |
| 566 | // GrShaderCaps |
| 567 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 568 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 569 | |
Ethan Nicholas | 6ac8d36 | 2019-01-22 21:43:55 +0000 | [diff] [blame] | 570 | // FIXME: http://skbug.com/7733: Disable geometry shaders until Intel/Radeon GMs draw correctly. |
| 571 | // shaderCaps->fGeometryShaderSupport = |
| 572 | // shaderCaps->fGSInvocationsSupport = features.features.geometryShader; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 573 | |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 574 | shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend; |
egdaniel | d632bb4 | 2016-03-30 12:06:48 -0700 | [diff] [blame] | 575 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 576 | shaderCaps->fIntegerSupport = true; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 577 | shaderCaps->fVertexIDSupport = true; |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 578 | shaderCaps->fFPManipulationSupport = true; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 579 | |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 580 | // Assume the minimum precisions mandated by the SPIR-V spec. |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 581 | shaderCaps->fFloatIs32Bits = true; |
| 582 | shaderCaps->fHalfIs32Bits = false; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 583 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 584 | shaderCaps->fMaxFragmentSamplers = SkTMin( |
| 585 | SkTMin(properties.limits.maxPerStageDescriptorSampledImages, |
| 586 | properties.limits.maxPerStageDescriptorSamplers), |
| 587 | (uint32_t)INT_MAX); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 588 | } |
| 589 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 590 | bool stencil_format_supported(const GrVkInterface* interface, |
| 591 | VkPhysicalDevice physDev, |
| 592 | VkFormat format) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 593 | VkFormatProperties props; |
| 594 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 595 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 596 | return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 597 | } |
| 598 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 599 | void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevice physDev) { |
| 600 | // List of legal stencil formats (though perhaps not supported on |
| 601 | // the particular gpu/driver) from most preferred to least. We are guaranteed to have either |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 602 | // VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT. VK_FORMAT_D32_SFLOAT_S8_UINT |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 603 | // can optionally have 24 unused bits at the end so we assume the total bits is 64. |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 604 | static const StencilFormat |
| 605 | // internal Format stencil bits total bits packed? |
| 606 | gS8 = { VK_FORMAT_S8_UINT, 8, 8, false }, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 607 | gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32, true }, |
| 608 | gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64, true }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 609 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 610 | if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 611 | fPreferredStencilFormat = gS8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 612 | } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 613 | fPreferredStencilFormat = gD24S8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 614 | } else { |
| 615 | SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 616 | fPreferredStencilFormat = gD32S8; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 620 | static bool format_is_srgb(VkFormat format) { |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 621 | SkASSERT(GrVkFormatIsSupported(format)); |
| 622 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 623 | switch (format) { |
| 624 | case VK_FORMAT_R8G8B8A8_SRGB: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 625 | return true; |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 626 | default: |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 627 | return false; |
| 628 | } |
| 629 | } |
| 630 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 631 | // 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] | 632 | // frequently used to least to improve look up times in arrays. |
| 633 | static constexpr VkFormat kVkFormats[] = { |
| 634 | VK_FORMAT_R8G8B8A8_UNORM, |
| 635 | VK_FORMAT_R8_UNORM, |
| 636 | VK_FORMAT_B8G8R8A8_UNORM, |
| 637 | VK_FORMAT_R5G6B5_UNORM_PACK16, |
| 638 | VK_FORMAT_R16G16B16A16_SFLOAT, |
| 639 | VK_FORMAT_R16_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 640 | VK_FORMAT_R8G8B8_UNORM, |
| 641 | VK_FORMAT_R8G8_UNORM, |
| 642 | VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
| 643 | VK_FORMAT_B4G4R4A4_UNORM_PACK16, |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 644 | VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 645 | VK_FORMAT_R32G32B32A32_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 646 | VK_FORMAT_R8G8B8A8_SRGB, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 647 | VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 648 | VK_FORMAT_R16_UNORM, |
| 649 | VK_FORMAT_R16G16_UNORM, |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 650 | VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, |
| 651 | VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 652 | VK_FORMAT_R16G16B16A16_UNORM, |
| 653 | VK_FORMAT_R16G16_SFLOAT, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 654 | }; |
| 655 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 656 | void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) { |
| 657 | #ifdef SK_DEBUG |
| 658 | for (size_t i = 0; i < kNumVkFormats; ++i) { |
| 659 | const auto& formatInfo = fFormatTable[i]; |
| 660 | for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) { |
| 661 | const auto& ctInfo = formatInfo.fColorTypeInfos[j]; |
| 662 | if (ctInfo.fColorType == colorType && |
| 663 | !SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) { |
| 664 | bool found = false; |
| 665 | for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 666 | if (kVkFormats[i] == *it) { |
| 667 | found = true; |
| 668 | } |
| 669 | } |
| 670 | SkASSERT(found); |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | #endif |
| 675 | int idx = static_cast<int>(colorType); |
| 676 | for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 677 | const auto& info = this->getFormatInfo(*it); |
| 678 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 679 | if (info.fColorTypeInfos[i].fColorType == colorType) { |
| 680 | fColorTypeToFormatTable[idx] = *it; |
| 681 | return; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 687 | const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 688 | GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this); |
| 689 | return nonConstThis->getFormatInfo(format); |
| 690 | } |
| 691 | |
| 692 | GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 693 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 694 | "Size of VkFormats array must match static value in header"); |
| 695 | for (size_t i = 0; i < SK_ARRAY_COUNT(kVkFormats); ++i) { |
| 696 | if (kVkFormats[i] == format) { |
| 697 | return fFormatTable[i]; |
| 698 | } |
| 699 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 700 | static FormatInfo kInvalidFormat; |
Greg Daniel | 52ee5f6 | 2019-06-20 13:38:18 -0400 | [diff] [blame] | 701 | return kInvalidFormat; |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 705 | const VkPhysicalDeviceProperties& properties) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 706 | static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 707 | "Size of VkFormats array must match static value in header"); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 708 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 709 | std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 710 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 711 | // 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] | 712 | // Format: VK_FORMAT_R8G8B8A8_UNORM |
| 713 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 714 | constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM; |
| 715 | auto& info = this->getFormatInfo(format); |
| 716 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 717 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 718 | info.fColorTypeInfoCount = 2; |
| 719 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 720 | int ctIdx = 0; |
| 721 | // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888 |
| 722 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 723 | constexpr GrColorType ct = GrColorType::kRGBA_8888; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 724 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 725 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 726 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 727 | } |
| 728 | // Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x |
| 729 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 730 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 731 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 732 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 733 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 734 | ctInfo.fTextureSwizzle = GrSwizzle::RGB1(); |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | // Format: VK_FORMAT_R8_UNORM |
| 740 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 741 | constexpr VkFormat format = VK_FORMAT_R8_UNORM; |
| 742 | auto& info = this->getFormatInfo(format); |
| 743 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 744 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 745 | info.fColorTypeInfoCount = 2; |
| 746 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 747 | int ctIdx = 0; |
| 748 | // Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8 |
| 749 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 750 | constexpr GrColorType ct = GrColorType::kAlpha_8; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 751 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 752 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 753 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 754 | ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| 755 | ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
| 756 | } |
| 757 | // Format: VK_FORMAT_R8_UNORM, Surface: kGray_8 |
| 758 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 759 | constexpr GrColorType ct = GrColorType::kGray_8; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 760 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 761 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 762 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 763 | ctInfo.fTextureSwizzle = GrSwizzle("rrr1"); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | // Format: VK_FORMAT_B8G8R8A8_UNORM |
| 768 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 769 | constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM; |
| 770 | auto& info = this->getFormatInfo(format); |
| 771 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 772 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 773 | info.fColorTypeInfoCount = 1; |
| 774 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 775 | int ctIdx = 0; |
| 776 | // Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888 |
| 777 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 778 | constexpr GrColorType ct = GrColorType::kBGRA_8888; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 779 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 780 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 781 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | // Format: VK_FORMAT_R5G6B5_UNORM_PACK16 |
| 786 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 787 | constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
| 788 | auto& info = this->getFormatInfo(format); |
| 789 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 790 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 791 | info.fColorTypeInfoCount = 1; |
| 792 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 793 | int ctIdx = 0; |
| 794 | // Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565 |
| 795 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 796 | constexpr GrColorType ct = GrColorType::kBGR_565; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 797 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 798 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 799 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT |
| 804 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 805 | constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT; |
| 806 | auto& info = this->getFormatInfo(format); |
| 807 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 808 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 809 | info.fColorTypeInfoCount = 2; |
| 810 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 811 | int ctIdx = 0; |
| 812 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16 |
| 813 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 814 | constexpr GrColorType ct = GrColorType::kRGBA_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 815 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 816 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 817 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 818 | } |
| 819 | // Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped |
| 820 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 821 | constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 822 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 823 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 824 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | // Format: VK_FORMAT_R16_SFLOAT |
| 829 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 830 | constexpr VkFormat format = VK_FORMAT_R16_SFLOAT; |
| 831 | auto& info = this->getFormatInfo(format); |
| 832 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 833 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 834 | info.fColorTypeInfoCount = 1; |
| 835 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 836 | int ctIdx = 0; |
| 837 | // Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16 |
| 838 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 839 | constexpr GrColorType ct = GrColorType::kAlpha_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 840 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 841 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 842 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 843 | ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| 844 | ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | // Format: VK_FORMAT_R8G8B8_UNORM |
| 849 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 850 | constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM; |
| 851 | auto& info = this->getFormatInfo(format); |
| 852 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 853 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 854 | info.fColorTypeInfoCount = 1; |
| 855 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 856 | int ctIdx = 0; |
| 857 | // Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x |
| 858 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 859 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 860 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 861 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 862 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | // Format: VK_FORMAT_R8G8_UNORM |
| 867 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 868 | constexpr VkFormat format = VK_FORMAT_R8G8_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 = 1; |
| 873 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 874 | int ctIdx = 0; |
| 875 | // Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88 |
| 876 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 877 | constexpr GrColorType ct = GrColorType::kRG_88; |
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; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 880 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32 |
| 885 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 886 | constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32; |
| 887 | auto& info = this->getFormatInfo(format); |
| 888 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 889 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 890 | info.fColorTypeInfoCount = 1; |
| 891 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 892 | int ctIdx = 0; |
| 893 | // Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102 |
| 894 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 895 | constexpr GrColorType ct = GrColorType::kRGBA_1010102; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 896 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 897 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 898 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16 |
| 903 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 904 | constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16; |
| 905 | auto& info = this->getFormatInfo(format); |
| 906 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 907 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 908 | info.fColorTypeInfoCount = 1; |
| 909 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 910 | int ctIdx = 0; |
| 911 | // Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 912 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 913 | constexpr GrColorType ct = GrColorType::kABGR_4444; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 914 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 915 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 916 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 917 | ctInfo.fTextureSwizzle = GrSwizzle::BGRA(); |
| 918 | ctInfo.fOutputSwizzle = GrSwizzle::BGRA(); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16 |
| 923 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 924 | constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16; |
| 925 | auto& info = this->getFormatInfo(format); |
| 926 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 927 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 928 | info.fColorTypeInfoCount = 1; |
| 929 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 930 | int ctIdx = 0; |
| 931 | // Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 932 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 933 | constexpr GrColorType ct = GrColorType::kABGR_4444; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 934 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 935 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 936 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | // Format: VK_FORMAT_R32G32B32A32_SFLOAT |
| 941 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 942 | constexpr VkFormat format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 943 | auto& info = this->getFormatInfo(format); |
| 944 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 945 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 946 | info.fColorTypeInfoCount = 1; |
| 947 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 948 | int ctIdx = 0; |
| 949 | // Format: VK_FORMAT_R32G32B32A32_SFLOAT, Surface: kRGBA_F32 |
| 950 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 951 | constexpr GrColorType ct = GrColorType::kRGBA_F32; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 952 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 953 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 954 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | // Format: VK_FORMAT_R8G8B8A8_SRGB |
| 959 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 960 | constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB; |
| 961 | auto& info = this->getFormatInfo(format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 962 | if (fSRGBSupport) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 963 | info.init(interface, physDev, properties, format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 964 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 965 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 966 | info.fColorTypeInfoCount = 1; |
| 967 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 968 | int ctIdx = 0; |
| 969 | // Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB |
| 970 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 971 | constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 972 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 973 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 974 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | // Format: VK_FORMAT_R16_UNORM |
| 979 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 980 | constexpr VkFormat format = VK_FORMAT_R16_UNORM; |
| 981 | auto& info = this->getFormatInfo(format); |
| 982 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 983 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 984 | info.fColorTypeInfoCount = 1; |
| 985 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 986 | int ctIdx = 0; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 987 | // Format: VK_FORMAT_R16_UNORM, Surface: kAlpha_16 |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 988 | { |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 989 | constexpr GrColorType ct = GrColorType::kAlpha_16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 990 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 991 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 992 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 993 | ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| 994 | ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | } |
| 998 | // Format: VK_FORMAT_R16G16_UNORM |
| 999 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1000 | constexpr VkFormat format = VK_FORMAT_R16G16_UNORM; |
| 1001 | auto& info = this->getFormatInfo(format); |
| 1002 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1003 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1004 | info.fColorTypeInfoCount = 1; |
| 1005 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 1006 | int ctIdx = 0; |
| 1007 | // Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616 |
| 1008 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1009 | constexpr GrColorType ct = GrColorType::kRG_1616; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1010 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1011 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1012 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | // Format: VK_FORMAT_R16G16B16A16_UNORM |
| 1017 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1018 | constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM; |
| 1019 | auto& info = this->getFormatInfo(format); |
| 1020 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1021 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1022 | info.fColorTypeInfoCount = 1; |
| 1023 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 1024 | int ctIdx = 0; |
| 1025 | // Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616 |
| 1026 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1027 | constexpr GrColorType ct = GrColorType::kRGBA_16161616; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1028 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1029 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1030 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | // Format: VK_FORMAT_R16G16_SFLOAT |
| 1035 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1036 | constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT; |
| 1037 | auto& info = this->getFormatInfo(format); |
| 1038 | info.init(interface, physDev, properties, format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1039 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1040 | info.fColorTypeInfoCount = 1; |
| 1041 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 1042 | int ctIdx = 0; |
| 1043 | // Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16 |
| 1044 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1045 | constexpr GrColorType ct = GrColorType::kRG_F16; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1046 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1047 | ctInfo.fColorType = ct; |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1048 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1049 | } |
| 1050 | } |
| 1051 | } |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1052 | // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM |
| 1053 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1054 | constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM; |
| 1055 | auto& info = this->getFormatInfo(format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1056 | if (fSupportsYcbcrConversion) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1057 | info.init(interface, physDev, properties, format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1058 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1059 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1060 | info.fColorTypeInfoCount = 1; |
| 1061 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 1062 | int ctIdx = 0; |
| 1063 | // Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x |
| 1064 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1065 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1066 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1067 | ctInfo.fColorType = ct; |
| 1068 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM |
| 1073 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1074 | constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; |
| 1075 | auto& info = this->getFormatInfo(format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1076 | if (fSupportsYcbcrConversion) { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1077 | info.init(interface, physDev, properties, format); |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1078 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1079 | if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1080 | info.fColorTypeInfoCount = 1; |
| 1081 | info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| 1082 | int ctIdx = 0; |
| 1083 | // Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x |
| 1084 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1085 | constexpr GrColorType ct = GrColorType::kRGB_888x; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1086 | auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1087 | ctInfo.fColorType = ct; |
| 1088 | ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1092 | // Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK |
| 1093 | { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1094 | constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 1095 | auto& info = this->getFormatInfo(format); |
| 1096 | info.init(interface, physDev, properties, format); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1097 | // No supported GrColorTypes. |
| 1098 | } |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1099 | |
| 1100 | //////////////////////////////////////////////////////////////////////////// |
| 1101 | // Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats |
| 1102 | // are passed into the setColorType function indicates the priority in selecting which format |
| 1103 | // we use for a given GrcolorType. |
| 1104 | |
| 1105 | this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM }); |
| 1106 | this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16 }); |
| 1107 | this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
| 1108 | VK_FORMAT_B4G4R4A4_UNORM_PACK16 }); |
| 1109 | this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM }); |
| 1110 | this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB }); |
| 1111 | this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM, |
| 1112 | VK_FORMAT_R8G8B8A8_UNORM }); |
| 1113 | this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM }); |
| 1114 | this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM }); |
| 1115 | this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 }); |
| 1116 | this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM }); |
| 1117 | this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT }); |
| 1118 | this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
| 1119 | this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
| 1120 | this->setColorType(GrColorType::kRGBA_F32, { VK_FORMAT_R32G32B32A32_SFLOAT }); |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1121 | this->setColorType(GrColorType::kAlpha_16, { VK_FORMAT_R16_UNORM }); |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1122 | this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM }); |
| 1123 | this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM }); |
| 1124 | this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT }); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1127 | void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1128 | if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 1129 | SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1130 | *flags = *flags | kTexturable_Flag; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1131 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1132 | // Ganesh assumes that all renderable surfaces are also texturable |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1133 | if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1134 | *flags = *flags | kRenderable_Flag; |
| 1135 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 1139 | *flags = *flags | kBlitSrc_Flag; |
| 1140 | } |
| 1141 | |
| 1142 | if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 1143 | *flags = *flags | kBlitDst_Flag; |
| 1144 | } |
| 1145 | } |
| 1146 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1147 | void GrVkCaps::FormatInfo::initSampleCounts(const GrVkInterface* interface, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1148 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1149 | const VkPhysicalDeviceProperties& physProps, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1150 | VkFormat format) { |
| 1151 | VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 1152 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 1153 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 1154 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1155 | VkImageFormatProperties properties; |
| 1156 | GR_VK_CALL(interface, GetPhysicalDeviceImageFormatProperties(physDev, |
| 1157 | format, |
| 1158 | VK_IMAGE_TYPE_2D, |
| 1159 | VK_IMAGE_TILING_OPTIMAL, |
| 1160 | usage, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 1161 | 0, // createFlags |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1162 | &properties)); |
| 1163 | VkSampleCountFlags flags = properties.sampleCounts; |
| 1164 | if (flags & VK_SAMPLE_COUNT_1_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1165 | fColorSampleCounts.push_back(1); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1166 | } |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1167 | if (kImagination_VkVendor == physProps.vendorID) { |
| 1168 | // MSAA does not work on imagination |
| 1169 | return; |
| 1170 | } |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 1171 | if (kIntel_VkVendor == physProps.vendorID) { |
Brian Osman | b5391bf | 2019-08-15 14:52:52 -0400 | [diff] [blame] | 1172 | // MSAA doesn't work well on Intel GPUs chromium:527565, chromium:983926 |
| 1173 | return; |
Brian Osman | 7fbb363 | 2019-07-19 11:38:57 -0400 | [diff] [blame] | 1174 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1175 | if (flags & VK_SAMPLE_COUNT_2_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1176 | fColorSampleCounts.push_back(2); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1177 | } |
| 1178 | if (flags & VK_SAMPLE_COUNT_4_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1179 | fColorSampleCounts.push_back(4); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1180 | } |
| 1181 | if (flags & VK_SAMPLE_COUNT_8_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1182 | fColorSampleCounts.push_back(8); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1183 | } |
| 1184 | if (flags & VK_SAMPLE_COUNT_16_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1185 | fColorSampleCounts.push_back(16); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1186 | } |
| 1187 | if (flags & VK_SAMPLE_COUNT_32_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1188 | fColorSampleCounts.push_back(32); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1189 | } |
| 1190 | if (flags & VK_SAMPLE_COUNT_64_BIT) { |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1191 | fColorSampleCounts.push_back(64); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1195 | void GrVkCaps::FormatInfo::init(const GrVkInterface* interface, |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1196 | VkPhysicalDevice physDev, |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1197 | const VkPhysicalDeviceProperties& properties, |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1198 | VkFormat format) { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1199 | VkFormatProperties props; |
| 1200 | memset(&props, 0, sizeof(VkFormatProperties)); |
| 1201 | GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1202 | InitFormatFlags(props.linearTilingFeatures, &fLinearFlags); |
| 1203 | InitFormatFlags(props.optimalTilingFeatures, &fOptimalFlags); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1204 | if (fOptimalFlags & kRenderable_Flag) { |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 1205 | this->initSampleCounts(interface, physDev, properties, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1206 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1207 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1208 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1209 | bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1210 | VkFormat vkFormat; |
| 1211 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1212 | return false; |
| 1213 | } |
| 1214 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1215 | return format_is_srgb(vkFormat); |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 1218 | bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1219 | VkFormat vkFormat; |
| 1220 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 1221 | return false; |
| 1222 | } |
| 1223 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 1224 | SkASSERT(GrVkFormatIsSupported(vkFormat)); |
| 1225 | |
| 1226 | return vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 1227 | } |
| 1228 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1229 | bool GrVkCaps::isFormatTexturableAndUploadable(GrColorType ct, |
| 1230 | const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1231 | VkFormat vkFormat; |
| 1232 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1233 | return false; |
| 1234 | } |
| 1235 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1236 | uint32_t ctFlags = this->getFormatInfo(vkFormat).colorTypeFlags(ct); |
| 1237 | return this->isVkFormatTexturable(vkFormat) && |
| 1238 | SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1239 | } |
| 1240 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1241 | bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const { |
| 1242 | VkFormat vkFormat; |
| 1243 | if (!format.asVkFormat(&vkFormat)) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1244 | return false; |
| 1245 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1246 | return this->isVkFormatTexturable(vkFormat); |
| 1247 | } |
| 1248 | |
| 1249 | bool GrVkCaps::isVkFormatTexturable(VkFormat format) const { |
| 1250 | const FormatInfo& info = this->getFormatInfo(format); |
| 1251 | return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags); |
Robert Phillips | 39ef2ef | 2019-05-15 08:45:53 -0400 | [diff] [blame] | 1252 | } |
| 1253 | |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1254 | bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 1255 | int sampleCount) const { |
| 1256 | if (!this->isFormatRenderable(format, sampleCount)) { |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1257 | return false; |
| 1258 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1259 | VkFormat vkFormat; |
| 1260 | if (!format.asVkFormat(&vkFormat)) { |
| 1261 | return false; |
| 1262 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1263 | const auto& info = this->getFormatInfo(vkFormat); |
| 1264 | if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) { |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1267 | return true; |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1270 | bool GrVkCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1271 | VkFormat vkFormat; |
| 1272 | if (!format.asVkFormat(&vkFormat)) { |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1273 | return false; |
| 1274 | } |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1275 | return this->isFormatRenderable(vkFormat, sampleCount); |
| 1276 | } |
| 1277 | |
| 1278 | bool GrVkCaps::isFormatRenderable(VkFormat format, int sampleCount) const { |
| 1279 | return sampleCount <= this->maxRenderTargetSampleCount(format); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1280 | } |
| 1281 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1282 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1283 | const GrBackendFormat& format) const { |
| 1284 | VkFormat vkFormat; |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1285 | if (!format.asVkFormat(&vkFormat)) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1286 | return 0; |
| 1287 | } |
| 1288 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1289 | return this->getRenderTargetSampleCount(requestedCount, vkFormat); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1292 | int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1293 | requestedCount = SkTMax(1, requestedCount); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1294 | |
| 1295 | const FormatInfo& info = this->getFormatInfo(format); |
| 1296 | |
| 1297 | int count = info.fColorSampleCounts.count(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1298 | |
| 1299 | if (!count) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1300 | return 0; |
| 1301 | } |
| 1302 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1303 | if (1 == requestedCount) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1304 | SkASSERT(info.fColorSampleCounts.count() && info.fColorSampleCounts[0] == 1); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1305 | return 1; |
| 1306 | } |
| 1307 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1308 | for (int i = 0; i < count; ++i) { |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1309 | if (info.fColorSampleCounts[i] >= requestedCount) { |
| 1310 | return info.fColorSampleCounts[i]; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1311 | } |
| 1312 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1313 | return 0; |
| 1314 | } |
| 1315 | |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 1316 | int GrVkCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1317 | VkFormat vkFormat; |
| 1318 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 1319 | return 0; |
| 1320 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1321 | return this->maxRenderTargetSampleCount(vkFormat); |
Greg Daniel | caa795f | 2019-05-14 11:54:25 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const { |
| 1325 | const FormatInfo& info = this->getFormatInfo(format); |
| 1326 | |
| 1327 | const auto& table = info.fColorSampleCounts; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1328 | if (!table.count()) { |
| 1329 | return 0; |
| 1330 | } |
| 1331 | return table[table.count() - 1]; |
Brian Salomon | d653cac | 2018-02-01 13:58:00 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1334 | static inline size_t align_to_4(size_t v) { |
| 1335 | switch (v & 0b11) { |
| 1336 | // v is already a multiple of 4. |
| 1337 | case 0: return v; |
| 1338 | // v is a multiple of 2 but not 4. |
| 1339 | case 2: return 2 * v; |
| 1340 | // v is not a multiple of 2. |
| 1341 | default: return 4 * v; |
| 1342 | } |
| 1343 | } |
| 1344 | |
Brian Salomon | 01915c0 | 2019-08-02 09:57:21 -0400 | [diff] [blame] | 1345 | GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfaceColorType, |
| 1346 | const GrBackendFormat& surfaceFormat, |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1347 | GrColorType srcColorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1348 | VkFormat vkFormat; |
| 1349 | if (!surfaceFormat.asVkFormat(&vkFormat)) { |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1350 | return {GrColorType::kUnknown, 0}; |
| 1351 | } |
| 1352 | |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1353 | |
| 1354 | if (GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1355 | return {GrColorType::kUnknown, 0}; |
| 1356 | } |
| 1357 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1358 | // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1359 | size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1360 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1361 | const auto& info = this->getFormatInfo(vkFormat); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1362 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1363 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1364 | if (ctInfo.fColorType == surfaceColorType) { |
| 1365 | return {surfaceColorType, offsetAlignment}; |
| 1366 | } |
| 1367 | } |
| 1368 | return {GrColorType::kUnknown, 0}; |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1371 | GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels( |
| 1372 | const GrSurface* surface) const { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 1373 | if (surface->isProtected()) { |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1374 | return SurfaceReadPixelsSupport::kUnsupported; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 1375 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1376 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 1377 | // We can't directly read from a VkImage that has a ycbcr sampler. |
| 1378 | if (tex->ycbcrConversionInfo().isValid()) { |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1379 | return SurfaceReadPixelsSupport::kCopyToTexture2D; |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1380 | } |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1381 | // We can't directly read from a compressed format |
| 1382 | SkImage::CompressionType compressionType; |
| 1383 | if (GrVkFormatToCompressionType(tex->imageFormat(), &compressionType)) { |
| 1384 | return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1385 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1386 | } |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 1387 | return SurfaceReadPixelsSupport::kSupported; |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 1390 | bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const { |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1391 | if (auto rt = surface->asRenderTarget()) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1392 | return rt->numSamples() <= 1 && SkToBool(surface->asTexture()); |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1393 | } |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1394 | // We can't write to a texture that has a ycbcr sampler. |
| 1395 | if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 1396 | // We can't directly read from a VkImage that has a ycbcr sampler. |
| 1397 | if (tex->ycbcrConversionInfo().isValid()) { |
| 1398 | return false; |
| 1399 | } |
| 1400 | } |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 1401 | return true; |
| 1402 | } |
| 1403 | |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1404 | bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 1405 | const GrBackendFormat& format) const { |
| 1406 | VkFormat vkFormat; |
| 1407 | if (!format.asVkFormat(&vkFormat)) { |
| 1408 | return false; |
| 1409 | } |
| 1410 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1411 | SkASSERT(ycbcrInfo); |
| 1412 | |
| 1413 | if (ycbcrInfo->isValid() && !GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1414 | // Format may be undefined for external images, which are required to have YCbCr conversion. |
| 1415 | if (VK_FORMAT_UNDEFINED == vkFormat) { |
| 1416 | return true; |
| 1417 | } |
| 1418 | return false; |
| 1419 | } |
| 1420 | |
| 1421 | const auto& info = this->getFormatInfo(vkFormat); |
| 1422 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1423 | if (info.fColorTypeInfos[i].fColorType == ct) { |
| 1424 | return true; |
| 1425 | } |
| 1426 | } |
| 1427 | return false; |
| 1428 | } |
| 1429 | |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1430 | static GrPixelConfig validate_image_info(VkFormat format, GrColorType ct, bool hasYcbcrConversion) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1431 | if (hasYcbcrConversion) { |
| 1432 | if (GrVkFormatNeedsYcbcrSampler(format)) { |
| 1433 | return kRGB_888X_GrPixelConfig; |
| 1434 | } |
| 1435 | |
| 1436 | // Format may be undefined for external images, which are required to have YCbCr conversion. |
| 1437 | if (VK_FORMAT_UNDEFINED == format) { |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 1438 | // We don't actually care what the color type or config are since we won't use those |
Greg Daniel | a51e93c | 2019-03-25 12:30:45 -0400 | [diff] [blame] | 1439 | // values for external textures. However, for read pixels we will draw to a non ycbcr |
| 1440 | // texture of this config so we set RGBA here for that. |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1441 | return kRGBA_8888_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 1442 | } |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1443 | |
| 1444 | return kUnknown_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 1445 | } |
| 1446 | |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1447 | if (VK_FORMAT_UNDEFINED == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1448 | return kUnknown_GrPixelConfig; |
Greg Daniel | 14c55c2 | 2018-12-04 11:25:03 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1451 | switch (ct) { |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1452 | case GrColorType::kUnknown: |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1453 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1454 | case GrColorType::kAlpha_8: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1455 | if (VK_FORMAT_R8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1456 | return kAlpha_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1457 | } |
| 1458 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1459 | case GrColorType::kBGR_565: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1460 | if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1461 | return kRGB_565_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1462 | } |
| 1463 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1464 | case GrColorType::kABGR_4444: |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1465 | if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format || |
| 1466 | VK_FORMAT_R4G4B4A4_UNORM_PACK16 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1467 | return kRGBA_4444_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1468 | } |
| 1469 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1470 | case GrColorType::kRGBA_8888: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1471 | if (VK_FORMAT_R8G8B8A8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1472 | return kRGBA_8888_GrPixelConfig; |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 1473 | } |
| 1474 | break; |
| 1475 | case GrColorType::kRGBA_8888_SRGB: |
| 1476 | if (VK_FORMAT_R8G8B8A8_SRGB == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1477 | return kSRGBA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1478 | } |
| 1479 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1480 | case GrColorType::kRGB_888x: |
Greg Daniel | 475eb70 | 2018-09-28 14:16:50 -0400 | [diff] [blame] | 1481 | if (VK_FORMAT_R8G8B8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1482 | return kRGB_888_GrPixelConfig; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1483 | } else if (VK_FORMAT_R8G8B8A8_UNORM == format) { |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 1484 | return kRGB_888X_GrPixelConfig; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1485 | } else if (VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK == format) { |
| 1486 | return kRGB_ETC1_GrPixelConfig; |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 1487 | } |
Greg Daniel | 475eb70 | 2018-09-28 14:16:50 -0400 | [diff] [blame] | 1488 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1489 | case GrColorType::kRG_88: |
| 1490 | if (VK_FORMAT_R8G8_UNORM == format) { |
| 1491 | return kRG_88_GrPixelConfig; |
| 1492 | } |
| 1493 | break; |
| 1494 | case GrColorType::kBGRA_8888: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1495 | if (VK_FORMAT_B8G8R8A8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1496 | return kBGRA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1497 | } |
| 1498 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1499 | case GrColorType::kRGBA_1010102: |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1500 | if (VK_FORMAT_A2B10G10R10_UNORM_PACK32 == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1501 | return kRGBA_1010102_GrPixelConfig; |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1502 | } |
| 1503 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1504 | case GrColorType::kGray_8: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1505 | if (VK_FORMAT_R8_UNORM == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1506 | return kGray_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1507 | } |
| 1508 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1509 | case GrColorType::kAlpha_F16: |
| 1510 | if (VK_FORMAT_R16_SFLOAT == format) { |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 1511 | return kAlpha_half_as_Red_GrPixelConfig; |
Mike Klein | b70990e | 2019-02-28 10:03:27 -0600 | [diff] [blame] | 1512 | } |
| 1513 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1514 | case GrColorType::kRGBA_F16: |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1515 | if (VK_FORMAT_R16G16B16A16_SFLOAT == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1516 | return kRGBA_half_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1517 | } |
| 1518 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1519 | case GrColorType::kRGBA_F16_Clamped: |
| 1520 | if (VK_FORMAT_R16G16B16A16_SFLOAT == format) { |
| 1521 | return kRGBA_half_Clamped_GrPixelConfig; |
| 1522 | } |
| 1523 | break; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1524 | case GrColorType::kRGBA_F32: |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 1525 | if (VK_FORMAT_R32G32B32A32_SFLOAT == format) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1526 | return kRGBA_float_GrPixelConfig; |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 1527 | } |
| 1528 | break; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1529 | case GrColorType::kAlpha_16: |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1530 | if (VK_FORMAT_R16_UNORM == format) { |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1531 | return kAlpha_16_GrPixelConfig; |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 1532 | } |
| 1533 | break; |
| 1534 | case GrColorType::kRG_1616: |
| 1535 | if (VK_FORMAT_R16G16_UNORM == format) { |
| 1536 | return kRG_1616_GrPixelConfig; |
| 1537 | } |
| 1538 | break; |
| 1539 | case GrColorType::kRGBA_16161616: |
| 1540 | if (VK_FORMAT_R16G16B16A16_UNORM == format) { |
| 1541 | return kRGBA_16161616_GrPixelConfig; |
| 1542 | } |
| 1543 | break; |
| 1544 | case GrColorType::kRG_F16: |
| 1545 | if (VK_FORMAT_R16G16_SFLOAT == format) { |
| 1546 | return kRG_half_GrPixelConfig; |
| 1547 | } |
| 1548 | break; |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 1549 | // These have no equivalent: |
| 1550 | case GrColorType::kAlpha_8xxx: |
| 1551 | case GrColorType::kAlpha_F32xxx: |
| 1552 | case GrColorType::kGray_8xxx: |
| 1553 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1554 | } |
| 1555 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1556 | return kUnknown_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
Greg Daniel | 627d053 | 2019-07-08 16:48:14 -0400 | [diff] [blame] | 1559 | GrPixelConfig GrVkCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format, |
| 1560 | GrColorType ct) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1561 | VkFormat vkFormat; |
| 1562 | if (!format.asVkFormat(&vkFormat)) { |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 1563 | return kUnknown_GrPixelConfig; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 1564 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1565 | const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo(); |
| 1566 | SkASSERT(ycbcrInfo); |
| 1567 | return validate_image_info(vkFormat, ct, ycbcrInfo->isValid()); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1568 | } |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 1569 | |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame] | 1570 | GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format, |
| 1571 | bool isAlphaChannel) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1572 | VkFormat vkFormat; |
| 1573 | if (!format.asVkFormat(&vkFormat)) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 1574 | return GrColorType::kUnknown; |
| 1575 | } |
| 1576 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1577 | switch (vkFormat) { |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame] | 1578 | case VK_FORMAT_R8_UNORM: return isAlphaChannel ? GrColorType::kAlpha_8 |
| 1579 | : GrColorType::kGray_8; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 1580 | case VK_FORMAT_R8G8B8A8_UNORM: return GrColorType::kRGBA_8888; |
| 1581 | case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x; |
| 1582 | case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88; |
| 1583 | case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888; |
| 1584 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1585 | case VK_FORMAT_R16_UNORM: return GrColorType::kAlpha_16; |
Robert Phillips | 17a3a0b | 2019-09-18 13:56:54 -0400 | [diff] [blame] | 1586 | case VK_FORMAT_R16_SFLOAT: return GrColorType::kAlpha_F16; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 1587 | case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 1588 | case VK_FORMAT_R16G16B16A16_UNORM: return GrColorType::kRGBA_16161616; |
| 1589 | case VK_FORMAT_R16G16_SFLOAT: return GrColorType::kRG_F16; |
| 1590 | default: return GrColorType::kUnknown; |
| 1591 | } |
| 1592 | |
| 1593 | SkUNREACHABLE; |
| 1594 | } |
| 1595 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1596 | GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct, |
| 1597 | GrRenderable renderable) const { |
Greg Daniel | 0fac869 | 2019-08-16 13:13:17 -0400 | [diff] [blame] | 1598 | VkFormat format = this->getFormatFromColorType(ct); |
| 1599 | if (format == VK_FORMAT_UNDEFINED) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1600 | return GrBackendFormat(); |
| 1601 | } |
| 1602 | return GrBackendFormat::MakeVk(format); |
| 1603 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 1604 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1605 | GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType( |
| 1606 | SkImage::CompressionType compressionType) const { |
| 1607 | switch (compressionType) { |
| 1608 | case SkImage::kETC1_CompressionType: |
| 1609 | return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK); |
| 1610 | } |
| 1611 | SK_ABORT("Invalid compression type"); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1612 | } |
| 1613 | |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1614 | GrSwizzle GrVkCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1615 | VkFormat vkFormat; |
| 1616 | SkAssertResult(format.asVkFormat(&vkFormat)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1617 | const auto& info = this->getFormatInfo(vkFormat); |
| 1618 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1619 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1620 | if (ctInfo.fColorType == colorType) { |
| 1621 | return ctInfo.fTextureSwizzle; |
| 1622 | } |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1623 | } |
| 1624 | return GrSwizzle::RGBA(); |
| 1625 | } |
| 1626 | |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1627 | GrSwizzle GrVkCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1628 | VkFormat vkFormat; |
| 1629 | SkAssertResult(format.asVkFormat(&vkFormat)); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1630 | const auto& info = this->getFormatInfo(vkFormat); |
| 1631 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1632 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1633 | if (ctInfo.fColorType == colorType) { |
| 1634 | return ctInfo.fOutputSwizzle; |
| 1635 | } |
| 1636 | } |
| 1637 | return GrSwizzle::RGBA(); |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1640 | GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType( |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1641 | GrColorType srcColorType, const GrBackendFormat& srcBackendFormat, |
| 1642 | GrColorType dstColorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1643 | VkFormat vkFormat; |
| 1644 | if (!srcBackendFormat.asVkFormat(&vkFormat)) { |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 1645 | return {GrColorType::kUnknown, 0}; |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1648 | if (GrVkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1649 | return {GrColorType::kUnknown, 0}; |
| 1650 | } |
| 1651 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1652 | // The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1653 | size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat)); |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1654 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1655 | const auto& info = this->getFormatInfo(vkFormat); |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1656 | for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1657 | const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1658 | if (ctInfo.fColorType == srcColorType) { |
| 1659 | return {srcColorType, offsetAlignment}; |
| 1660 | } |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1661 | } |
Greg Daniel | 1ff5021 | 2019-08-02 15:54:08 -0400 | [diff] [blame] | 1662 | return {GrColorType::kUnknown, 0}; |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 1663 | } |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1664 | |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame] | 1665 | int GrVkCaps::getFragmentUniformBinding() const { |
| 1666 | return GrVkUniformHandler::kUniformBinding; |
| 1667 | } |
| 1668 | |
| 1669 | int GrVkCaps::getFragmentUniformSet() const { |
| 1670 | return GrVkUniformHandler::kUniformBufferDescSet; |
| 1671 | } |
| 1672 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1673 | #if GR_TEST_UTILS |
| 1674 | std::vector<GrCaps::TestFormatColorTypeCombination> GrVkCaps::getTestingCombinations() const { |
| 1675 | std::vector<GrCaps::TestFormatColorTypeCombination> combos = { |
| 1676 | { GrColorType::kAlpha_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 1677 | { GrColorType::kBGR_565, GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16) }, |
| 1678 | { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_R4G4B4A4_UNORM_PACK16)}, |
| 1679 | { GrColorType::kABGR_4444, GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16)}, |
| 1680 | { GrColorType::kRGBA_8888, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 1681 | { GrColorType::kRGBA_8888_SRGB, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB) }, |
| 1682 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 1683 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM) }, |
| 1684 | { GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)}, |
| 1685 | { GrColorType::kRG_88, GrBackendFormat::MakeVk(VK_FORMAT_R8G8_UNORM) }, |
| 1686 | { GrColorType::kBGRA_8888, GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) }, |
| 1687 | { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)}, |
| 1688 | { GrColorType::kGray_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 1689 | { GrColorType::kAlpha_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16_SFLOAT) }, |
| 1690 | { GrColorType::kRGBA_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 1691 | { GrColorType::kRGBA_F16_Clamped, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 1692 | { GrColorType::kRGBA_F32, GrBackendFormat::MakeVk(VK_FORMAT_R32G32B32A32_SFLOAT) }, |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1693 | { GrColorType::kAlpha_16, GrBackendFormat::MakeVk(VK_FORMAT_R16_UNORM) }, |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1694 | { GrColorType::kRG_1616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_UNORM) }, |
| 1695 | { GrColorType::kRGBA_16161616, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_UNORM) }, |
| 1696 | { GrColorType::kRG_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_SFLOAT) }, |
| 1697 | }; |
| 1698 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 1699 | return combos; |
| 1700 | } |
| 1701 | #endif |