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