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