| 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 |
|
| 8 |
#include "src/gpu/ganesh/vk/GrVkCaps.h" |
| 9 |
|
| 10 |
#include "include/core/SkRect.h" |
| 11 |
#include "include/core/SkSize.h" |
| 12 |
#include "include/core/SkTextureCompressionType.h" |
| 13 |
#include "include/core/SkTypes.h" |
| 14 |
#include "include/gpu/GpuTypes.h" |
| 15 |
#include "include/gpu/ganesh/GrBackendSurface.h" |
| 16 |
#include "include/gpu/ganesh/GrContextOptions.h" |
| 17 |
#include "include/gpu/ganesh/vk/GrVkBackendSurface.h" |
| 18 |
#include "include/gpu/vk/VulkanExtensions.h" |
| 19 |
#include "include/gpu/vk/VulkanTypes.h" |
| 20 |
#include "src/core/SkCompressedDataUtils.h" |
| 21 |
#include "src/gpu/KeyBuilder.h" |
| 22 |
#include "src/gpu/ganesh/GrBackendUtils.h" |
| 23 |
#include "src/gpu/ganesh/GrPipeline.h" |
| 24 |
#include "src/gpu/ganesh/GrProgramDesc.h" |
| 25 |
#include "src/gpu/ganesh/GrProgramInfo.h" |
| 26 |
#include "src/gpu/ganesh/GrRenderTarget.h" |
| 27 |
#include "src/gpu/ganesh/GrRenderTargetProxy.h" |
| 28 |
#include "src/gpu/ganesh/GrShaderCaps.h" |
| 29 |
#include "src/gpu/ganesh/GrStencilSettings.h" |
| 30 |
#include "src/gpu/ganesh/GrSurface.h" |
| 31 |
#include "src/gpu/ganesh/GrSurfaceProxy.h" |
| 32 |
#include "src/gpu/ganesh/GrXferProcessor.h" |
| 33 |
#include "src/gpu/ganesh/TestFormatColorTypeCombination.h" |
| 34 |
#include "src/gpu/ganesh/vk/GrVkGpu.h" |
| 35 |
#include "src/gpu/ganesh/vk/GrVkImage.h" |
| 36 |
#include "src/gpu/ganesh/vk/GrVkRenderPass.h" |
| 37 |
#include "src/gpu/ganesh/vk/GrVkRenderTarget.h" |
| 38 |
#include "src/gpu/ganesh/vk/GrVkSampler.h" |
| 39 |
#include "src/gpu/ganesh/vk/GrVkTexture.h" |
| 40 |
#include "src/gpu/ganesh/vk/GrVkUniformHandler.h" |
| 41 |
#include "src/gpu/ganesh/vk/GrVkUtil.h" |
| 42 |
#include "src/gpu/vk/VulkanUtilsPriv.h" |
| 43 |
|
| 44 |
#include <limits.h> |
| 45 |
#include <algorithm> |
| 46 |
#include <cstring> |
| 47 |
#include <memory> |
| 48 |
|
| 49 |
#ifdef SK_BUILD_FOR_ANDROID |
| 50 |
#include <sys/system_properties.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, |
| 54 |
const skgpu::VulkanInterface* vkInterface, |
| 55 |
VkPhysicalDevice physDev, |
| 56 |
const VkPhysicalDeviceFeatures2& features, |
| 57 |
uint32_t instanceVersion, |
| 58 |
uint32_t physicalDeviceVersion, |
| 59 |
const skgpu::VulkanExtensions& extensions, |
| 60 |
GrProtected isProtected) |
| 61 |
: INHERITED(contextOptions) { |
| 62 |
/************************************************************************** |
| 63 |
* GrCaps fields |
| 64 |
**************************************************************************/ |
| 65 |
fMipmapSupport = true; // always available in Vulkan |
| 66 |
fAnisoSupport = true; // always available in Vulkan |
| 67 |
fNPOTTextureTileSupport = true; // always available in Vulkan |
| 68 |
fReuseScratchTextures = true; //TODO: figure this out |
| 69 |
fGpuTracingSupport = false; //TODO: figure this out |
| 70 |
fOversizedStencilSupport = false; //TODO: figure this out |
| 71 |
fDrawInstancedSupport = true; |
| 72 |
|
| 73 |
fSemaphoreSupport = true; // always available in Vulkan |
| 74 |
fBackendSemaphoreSupport = true; |
| 75 |
fFinishedProcAsyncCallbackSupport = true; |
| 76 |
fCrossContextTextureSupport = true; |
| 77 |
fHalfFloatVertexAttributeSupport = true; |
| 78 |
|
| 79 |
// We always copy in/out of a transfer buffer so it's trivial to support row bytes. |
| 80 |
fReadPixelsRowBytesSupport = true; |
| 81 |
fWritePixelsRowBytesSupport = true; |
| 82 |
|
| 83 |
fTransferFromBufferToTextureSupport = true; |
| 84 |
fTransferFromSurfaceToBufferSupport = true; |
| 85 |
fTransferFromBufferToBufferSupport = true; |
| 86 |
|
| 87 |
fMaxRenderTargetSize = 4096; // minimum required by spec |
| 88 |
fMaxTextureSize = 4096; // minimum required by spec |
| 89 |
|
| 90 |
fDynamicStateArrayGeometryProcessorTextureSupport = true; |
| 91 |
|
| 92 |
fTextureBarrierSupport = true; |
| 93 |
|
| 94 |
fShaderCaps = std::make_unique<GrShaderCaps>(); |
| 95 |
|
| 96 |
this->init(contextOptions, vkInterface, physDev, features, physicalDeviceVersion, extensions, |
| 97 |
isProtected); |
| 98 |
} |
| 99 |
|
| 100 |
namespace { |
| 101 |
/** |
| 102 |
* This comes from section 37.1.6 of the Vulkan spec. Format is |
| 103 |
* (<bits>|<tag>)_<block_size>_<texels_per_block>. |
| 104 |
*/ |
| 105 |
enum class FormatCompatibilityClass { |
| 106 |
k8_1_1, |
| 107 |
k16_2_1, |
| 108 |
k24_3_1, |
| 109 |
k32_4_1, |
| 110 |
k64_8_1, |
| 111 |
k10x6_64_6_1, |
| 112 |
kBC1_RGB_8_16_1, |
| 113 |
kBC1_RGBA_8_16, |
| 114 |
kETC2_RGB_8_16, |
| 115 |
}; |
| 116 |
} // anonymous namespace |
| 117 |
|
| 118 |
static FormatCompatibilityClass format_compatibility_class(VkFormat format) { |
| 119 |
switch (format) { |
| 120 |
case VK_FORMAT_B8G8R8A8_UNORM: |
| 121 |
case VK_FORMAT_R8G8B8A8_UNORM: |
| 122 |
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: |
| 123 |
case VK_FORMAT_A2R10G10B10_UNORM_PACK32: |
| 124 |
case VK_FORMAT_R8G8B8A8_SRGB: |
| 125 |
case VK_FORMAT_R16G16_UNORM: |
| 126 |
case VK_FORMAT_R16G16_SFLOAT: |
| 127 |
return FormatCompatibilityClass::k32_4_1; |
| 128 |
|
| 129 |
case VK_FORMAT_R8_UNORM: |
| 130 |
return FormatCompatibilityClass::k8_1_1; |
| 131 |
|
| 132 |
case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 133 |
case VK_FORMAT_B5G6R5_UNORM_PACK16: |
| 134 |
case VK_FORMAT_R16_SFLOAT: |
| 135 |
case VK_FORMAT_R8G8_UNORM: |
| 136 |
case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
| 137 |
case VK_FORMAT_R4G4B4A4_UNORM_PACK16: |
| 138 |
case VK_FORMAT_R16_UNORM: |
| 139 |
return FormatCompatibilityClass::k16_2_1; |
| 140 |
|
| 141 |
case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 142 |
case VK_FORMAT_R16G16B16A16_UNORM: |
| 143 |
return FormatCompatibilityClass::k64_8_1; |
| 144 |
|
| 145 |
case VK_FORMAT_R8G8B8_UNORM: |
| 146 |
return FormatCompatibilityClass::k24_3_1; |
| 147 |
|
| 148 |
case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16: |
| 149 |
return FormatCompatibilityClass::k10x6_64_6_1; |
| 150 |
|
| 151 |
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 152 |
return FormatCompatibilityClass::kETC2_RGB_8_16; |
| 153 |
|
| 154 |
case VK_FORMAT_BC1_RGB_UNORM_BLOCK: |
| 155 |
return FormatCompatibilityClass::kBC1_RGB_8_16_1; |
| 156 |
|
| 157 |
case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: |
| 158 |
return FormatCompatibilityClass::kBC1_RGBA_8_16; |
| 159 |
|
| 160 |
default: |
| 161 |
SK_ABORT("Unsupported VkFormat"); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
bool GrVkCaps::canCopyImage(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 166 |
VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
| 167 |
if ((dstSampleCnt > 1 || srcSampleCnt > 1) && dstSampleCnt != srcSampleCnt) { |
| 168 |
return false; |
| 169 |
} |
| 170 |
|
| 171 |
if (dstHasYcbcr || srcHasYcbcr) { |
| 172 |
return false; |
| 173 |
} |
| 174 |
|
| 175 |
// We require that all Vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 176 |
// as image usage flags. |
| 177 |
return format_compatibility_class(srcFormat) == format_compatibility_class(dstFormat); |
| 178 |
} |
| 179 |
|
| 180 |
bool GrVkCaps::canCopyAsBlit(VkFormat dstFormat, int dstSampleCnt, bool dstIsLinear, |
| 181 |
bool dstHasYcbcr, VkFormat srcFormat, int srcSampleCnt, |
| 182 |
bool srcIsLinear, bool srcHasYcbcr) const { |
| 183 |
// We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
| 184 |
// as image usage flags. |
| 185 |
if (!this->formatCanBeDstofBlit(dstFormat, dstIsLinear) || |
| 186 |
!this->formatCanBeSrcofBlit(srcFormat, srcIsLinear)) { |
| 187 |
return false; |
| 188 |
} |
| 189 |
|
| 190 |
// We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 191 |
// resolved msaa though. |
| 192 |
if (dstSampleCnt > 1 || srcSampleCnt > 1) { |
| 193 |
return false; |
| 194 |
} |
| 195 |
|
| 196 |
if (dstHasYcbcr || srcHasYcbcr) { |
| 197 |
return false; |
| 198 |
} |
| 199 |
|
| 200 |
return true; |
| 201 |
} |
| 202 |
|
| 203 |
bool GrVkCaps::canCopyAsResolve(VkFormat dstFormat, int dstSampleCnt, bool dstHasYcbcr, |
| 204 |
VkFormat srcFormat, int srcSampleCnt, bool srcHasYcbcr) const { |
| 205 |
// The src surface must be multisampled. |
| 206 |
if (srcSampleCnt <= 1) { |
| 207 |
return false; |
| 208 |
} |
| 209 |
|
| 210 |
// The dst must not be multisampled. |
| 211 |
if (dstSampleCnt > 1) { |
| 212 |
return false; |
| 213 |
} |
| 214 |
|
| 215 |
// Surfaces must have the same format. |
| 216 |
if (srcFormat != dstFormat) { |
| 217 |
return false; |
| 218 |
} |
| 219 |
|
| 220 |
if (dstHasYcbcr || srcHasYcbcr) { |
| 221 |
return false; |
| 222 |
} |
| 223 |
|
| 224 |
return true; |
| 225 |
} |
| 226 |
|
| 227 |
bool GrVkCaps::onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect, |
| 228 |
const GrSurfaceProxy* src, const SkIRect& srcRect) const { |
| 229 |
if (src->isProtected() == GrProtected::kYes && dst->isProtected() != GrProtected::kYes) { |
| 230 |
return false; |
| 231 |
} |
| 232 |
|
| 233 |
// TODO: Figure out a way to track if we've wrapped a linear texture in a proxy (e.g. |
| 234 |
// PromiseImage which won't get instantiated right away. Does this need a similar thing like the |
| 235 |
// tracking of external or rectangle textures in GL? For now we don't create linear textures |
| 236 |
// internally, and I don't believe anyone is wrapping them. |
| 237 |
bool srcIsLinear = false; |
| 238 |
bool dstIsLinear = false; |
| 239 |
|
| 240 |
int dstSampleCnt = 0; |
| 241 |
int srcSampleCnt = 0; |
| 242 |
if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) { |
| 243 |
// Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 244 |
// since they would require us to know the VkImage, which we don't have, as well as need us |
| 245 |
// to stop and start the VkRenderPass which we don't have access to. |
| 246 |
if (rtProxy->wrapsVkSecondaryCB()) { |
| 247 |
return false; |
| 248 |
} |
| 249 |
if (this->preferDiscardableMSAAAttachment() && dst->asTextureProxy() && |
| 250 |
rtProxy->supportsVkInputAttachment()) { |
| 251 |
dstSampleCnt = 1; |
| 252 |
} else { |
| 253 |
dstSampleCnt = rtProxy->numSamples(); |
| 254 |
} |
| 255 |
} |
| 256 |
if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) { |
| 257 |
// Copying to or from render targets that wrap a secondary command buffer is not allowed |
| 258 |
// since they would require us to know the VkImage, which we don't have, as well as need us |
| 259 |
// to stop and start the VkRenderPass which we don't have access to. |
| 260 |
if (rtProxy->wrapsVkSecondaryCB()) { |
| 261 |
return false; |
| 262 |
} |
| 263 |
if (this->preferDiscardableMSAAAttachment() && src->asTextureProxy() && |
| 264 |
rtProxy->supportsVkInputAttachment()) { |
| 265 |
srcSampleCnt = 1; |
| 266 |
} else { |
| 267 |
srcSampleCnt = rtProxy->numSamples(); |
| 268 |
} |
| 269 |
} |
| 270 |
SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy())); |
| 271 |
SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy())); |
| 272 |
|
| 273 |
bool dstHasYcbcr = false; |
| 274 |
if (auto ycbcr = GrBackendFormats::GetVkYcbcrConversionInfo(dst->backendFormat())) { |
| 275 |
if (ycbcr->isValid()) { |
| 276 |
dstHasYcbcr = true; |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
bool srcHasYcbcr = false; |
| 281 |
if (auto ycbcr = GrBackendFormats::GetVkYcbcrConversionInfo(src->backendFormat())) { |
| 282 |
if (ycbcr->isValid()) { |
| 283 |
srcHasYcbcr = true; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
VkFormat dstFormat, srcFormat; |
| 288 |
SkAssertResult(GrBackendFormats::AsVkFormat(dst->backendFormat(), &dstFormat)); |
| 289 |
SkAssertResult(GrBackendFormats::AsVkFormat(src->backendFormat(), &srcFormat)); |
| 290 |
|
| 291 |
// Only blits support scaling, but since we've already clamped the src and dst rects, |
| 292 |
// the dimensions of the scaled blit aren't important to know if it's allowed. |
| 293 |
const bool copyScales = srcRect.size() != dstRect.size(); |
| 294 |
if (!copyScales && (this->canCopyImage(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 295 |
srcFormat, srcSampleCnt, srcHasYcbcr) || |
| 296 |
this->canCopyAsResolve(dstFormat, dstSampleCnt, dstHasYcbcr, |
| 297 |
srcFormat, srcSampleCnt, srcHasYcbcr))) { |
| 298 |
return true; |
| 299 |
} |
| 300 |
return this->canCopyAsBlit(dstFormat, dstSampleCnt, dstIsLinear, dstHasYcbcr, |
| 301 |
srcFormat, srcSampleCnt, srcIsLinear, srcHasYcbcr); |
| 302 |
|
| 303 |
} |
| 304 |
|
| •305 |
namespace { |
| 306 |
bool is_tiler_gpu(uint32_t vendorId) { |
| 307 |
return vendorId == skgpu::kARM_VkVendor || |
| 308 |
vendorId == skgpu::kQualcomm_VkVendor || |
| 309 |
vendorId == skgpu::kImagination_VkVendor; |
| 310 |
} |
| 311 |
} // anonymous namespace |
| 312 |
void GrVkCaps::init(const GrContextOptions& contextOptions, |
| 313 |
const skgpu::VulkanInterface* vkInterface, |
| 314 |
VkPhysicalDevice physDev, |
| 315 |
const VkPhysicalDeviceFeatures2& features, |
| 316 |
uint32_t physicalDeviceVersion, |
| 317 |
const skgpu::VulkanExtensions& extensions, |
| 318 |
GrProtected isProtected) { |
| 319 |
VkPhysicalDeviceProperties properties; |
| 320 |
GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
| 321 |
|
| 322 |
#if defined(GPU_TEST_UTILS) |
| 323 |
this->setDeviceName(properties.deviceName); |
| 324 |
#endif |
| 325 |
|
| 326 |
VkPhysicalDeviceMemoryProperties memoryProperties; |
| 327 |
GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryProperties)); |
| 328 |
|
| 329 |
SkASSERT(physicalDeviceVersion <= properties.apiVersion); |
| 330 |
|
| 331 |
if (extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 1)) { |
| 332 |
fSupportsSwapchain = true; |
| 333 |
} |
| 334 |
|
| 335 |
#ifdef SK_BUILD_FOR_ANDROID |
| 336 |
// Currently Adreno devices are not supporting the QUEUE_FAMILY_FOREIGN_EXTENSION, so until they |
| 337 |
// do we don't explicitly require it here even the spec says it is required. |
| 338 |
if (extensions.hasExtension(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, |
| 339 |
2) |
| 340 |
/* && extensions.hasExtension(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, 1)*/ |
| 341 |
) { |
| 342 |
fSupportsAndroidHWBExternalMemory = true; |
| 343 |
fSupportsAHardwareBufferImages = true; |
| 344 |
} |
| 345 |
#endif |
| 346 |
|
| 347 |
const auto ycbcrFeatures = |
| 348 |
skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>( |
| 349 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES); |
| 350 |
const auto vk11Features = skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceVulkan11Features>( |
| 351 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES); |
| 352 |
fSupportsYcbcrConversion = (ycbcrFeatures && ycbcrFeatures->samplerYcbcrConversion) || |
| 353 |
(vk11Features && vk11Features->samplerYcbcrConversion); |
| 354 |
|
| 355 |
// We always push back the default skgpu::VulkanYcbcrConversionInfo so that the case of no |
| 356 |
// conversion will return a key of 0. |
| 357 |
fYcbcrInfos.push_back(skgpu::VulkanYcbcrConversionInfo()); |
| 358 |
|
| 359 |
// Ganesh requires Vulkan version 1.1 or later, which always has protected support. The |
| 360 |
// protectedMemory feature is assumed enabled if isProtected is true. |
| 361 |
if (isProtected == GrProtected::kYes) { |
| 362 |
fSupportsProtectedContent = true; |
| 363 |
fAvoidUpdateBuffers = true; |
| 364 |
fShouldAlwaysUseDedicatedImageMemory = true; |
| 365 |
} |
| 366 |
|
| 367 |
if (extensions.hasExtension(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, 1)) { |
| 368 |
fSupportsDRMFormatModifiers = true; |
| 369 |
} |
| 370 |
|
| 371 |
const auto deviceFaultFeatures = |
| 372 |
skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceFaultFeaturesEXT>( |
| 373 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FAULT_FEATURES_EXT); |
| 374 |
fSupportsDeviceFaultInfo = deviceFaultFeatures && deviceFaultFeatures->deviceFault; |
| 375 |
|
| 376 |
const auto frameBoundaryFeatures = |
| 377 |
skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceFrameBoundaryFeaturesEXT>( |
| 378 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT); |
| 379 |
fSupportsFrameBoundary = frameBoundaryFeatures && frameBoundaryFeatures->frameBoundary; |
| 380 |
|
| 381 |
const auto cacheControlFeatures = |
| 382 |
skgpu::GetExtensionFeatureStruct<VkPhysicalDevicePipelineCreationCacheControlFeatures>( |
| 383 |
features, |
| 384 |
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES); |
| 385 |
const auto vk13Features = skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceVulkan13Features>( |
| 386 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES); |
| 387 |
fSupportsPipelineCreationCacheControl = |
| 388 |
(cacheControlFeatures && cacheControlFeatures->pipelineCreationCacheControl) || |
| 389 |
(vk13Features && vk13Features->pipelineCreationCacheControl); |
| 390 |
|
| 391 |
fMaxInputAttachmentDescriptors = properties.limits.maxDescriptorSetInputAttachments; |
| 392 |
|
| 393 |
fMaxSamplerAnisotropy = properties.limits.maxSamplerAnisotropy; |
| 394 |
|
| 395 |
// On desktop GPUs we have found that this does not provide much benefit. The perf results show |
| 396 |
// a mix of regressions, some improvements, and lots of no changes. Thus it is not worth |
| 397 |
// enabling this (especially with the rendering artifacts) on desktop. |
| 398 |
// |
| 399 |
// On Adreno devices we were expecting to see perf gains. But instead there were actually a lot |
| 400 |
// of perf regressions and only a few perf wins. This needs some follow up with qualcomm since |
| 401 |
// we do expect this to be a big win on tilers. |
| 402 |
// |
| 403 |
// On ARM devices we are seeing an average perf win of around 50%-60% across the board. |
| 404 |
if (skgpu::kARM_VkVendor == properties.vendorID) { |
| 405 |
VkMemoryPropertyFlags requiredLazyFlags = VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; |
| 406 |
if (fSupportsProtectedContent) { |
| 407 |
// If we have a protected context we can only use memoryless images if they also support |
| 408 |
// being protected. With current devices we don't actually expect this combination to be |
| 409 |
// supported, but this at least covers us for future devices that may allow it. |
| 410 |
requiredLazyFlags |= VK_MEMORY_PROPERTY_PROTECTED_BIT; |
| 411 |
} |
| 412 |
for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) { |
| 413 |
const uint32_t& supportedFlags = memoryProperties.memoryTypes[i].propertyFlags; |
| 414 |
if ((supportedFlags & requiredLazyFlags) == requiredLazyFlags) { |
| 415 |
fPreferDiscardableMSAAAttachment = true; |
| 416 |
fSupportsMemorylessAttachments = true; |
| 417 |
break; |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions); |
| 423 |
this->initShaderCaps(properties, features); |
| 424 |
|
| •425 |
if (is_tiler_gpu(properties.vendorID)) { |
| 426 |
// A "clear" load for atlases runs faster on tiler GPUs than a "discard" load followed by a |
| 427 |
// scissored clear. |
| 428 |
fPreferFullscreenClears = true; |
| •429 |
fDiscardStencilValuesAfterRenderPass = true; |
| 430 |
fClearsAreFasterThanLoads = true; |
| 431 |
} |
| 432 |
|
| 433 |
if (properties.vendorID == skgpu::kNvidia_VkVendor || |
| 434 |
properties.vendorID == skgpu::kAMD_VkVendor) { |
| 435 |
// On discrete GPUs it can be faster to read gpu only memory compared to memory that is also |
| 436 |
// mappable on the host. |
| 437 |
fGpuOnlyBuffersMorePerformant = true; |
| 438 |
|
| 439 |
// On discrete GPUs we try to use special DEVICE_LOCAL and HOST_VISIBLE memory for our |
| 440 |
// cpu write, gpu read buffers. This memory is not ideal to be kept persistently mapped. |
| 441 |
// Some discrete GPUs do not expose this special memory, however we still disable |
| 442 |
// persistently mapped buffers for all of them since most GPUs with updated drivers do |
| 443 |
// expose it. If this becomes an issue we can try to be more fine grained. |
| 444 |
fShouldPersistentlyMapCpuToGpuBuffers = false; |
| 445 |
} |
| 446 |
|
| 447 |
if (skgpu::kQualcomm_VkVendor == properties.vendorID) { |
| 448 |
// On Qualcomm it looks like using vkCmdUpdateBuffer is slower than using a transfer buffer |
| 449 |
// even for small sizes. |
| 450 |
fAvoidUpdateBuffers = true; |
| 451 |
} |
| 452 |
|
| 453 |
fNativeDrawIndirectSupport = features.features.drawIndirectFirstInstance; |
| 454 |
if (properties.vendorID == skgpu::kQualcomm_VkVendor) { |
| 455 |
// Indirect draws seem slow on QC. Disable until we can investigate. skbug.com/40042512 |
| 456 |
fNativeDrawIndirectSupport = false; |
| 457 |
} |
| 458 |
|
| 459 |
if (fNativeDrawIndirectSupport) { |
| 460 |
fMaxDrawIndirectDrawCount = properties.limits.maxDrawIndirectCount; |
| 461 |
SkASSERT(fMaxDrawIndirectDrawCount == 1 || features.features.multiDrawIndirect); |
| 462 |
} |
| 463 |
|
| 464 |
#ifdef SK_BUILD_FOR_UNIX |
| 465 |
if (skgpu::kNvidia_VkVendor == properties.vendorID) { |
| 466 |
// On nvidia linux we see a big perf regression when not using dedicated image allocations. |
| 467 |
fShouldAlwaysUseDedicatedImageMemory = true; |
| 468 |
} |
| 469 |
#endif |
| 470 |
|
| 471 |
this->initFormatTable(contextOptions, vkInterface, physDev, properties, features, extensions); |
| 472 |
this->initStencilFormat(vkInterface, physDev); |
| 473 |
|
| 474 |
if (contextOptions.fMaxCachedVulkanSecondaryCommandBuffers >= 0) { |
| 475 |
fMaxPerPoolCachedSecondaryCommandBuffers = |
| 476 |
contextOptions.fMaxCachedVulkanSecondaryCommandBuffers; |
| 477 |
} |
| 478 |
|
| 479 |
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 480 |
this->applyDriverCorrectnessWorkarounds(properties); |
| 481 |
} |
| 482 |
|
| 483 |
this->finishInitialization(contextOptions); |
| 484 |
} |
| 485 |
|
| 486 |
void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties& properties) { |
| 487 |
#if defined(SK_BUILD_FOR_WIN) |
| 488 |
if (skgpu::kNvidia_VkVendor == properties.vendorID || |
| 489 |
skgpu::kIntel_VkVendor == properties.vendorID) { |
| 490 |
fMustSyncCommandBuffersWithQueue = true; |
| 491 |
} |
| 492 |
#elif defined(SK_BUILD_FOR_ANDROID) |
| 493 |
if (skgpu::kImagination_VkVendor == properties.vendorID) { |
| 494 |
fMustSyncCommandBuffersWithQueue = true; |
| 495 |
} |
| 496 |
#endif |
| 497 |
|
| 498 |
// Defaults to zero since all our workaround checks that use this consider things "fixed" once |
| 499 |
// above a certain api level. So this will just default to it being less which will enable |
| 500 |
// workarounds. |
| 501 |
int androidAPIVersion = 0; |
| 502 |
#if defined(SK_BUILD_FOR_ANDROID) |
| 503 |
char androidAPIVersionStr[PROP_VALUE_MAX]; |
| 504 |
int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersionStr); |
| 505 |
// Defaults to zero since most checks care if it is greater than a specific value. So this will |
| 506 |
// just default to it being less. |
| 507 |
androidAPIVersion = (strLength == 0) ? 0 : atoi(androidAPIVersionStr); |
| 508 |
#endif |
| 509 |
|
| 510 |
// Protected memory features have problems in Android P and earlier. |
| 511 |
if (fSupportsProtectedContent && (skgpu::kQualcomm_VkVendor == properties.vendorID)) { |
| 512 |
if (androidAPIVersion <= 28) { |
| 513 |
fSupportsProtectedContent = false; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
// On Mali galaxy s7 we see lots of rendering issues when we suballocate VkImages. |
| 518 |
if (skgpu::kARM_VkVendor == properties.vendorID && androidAPIVersion <= 28) { |
| 519 |
fShouldAlwaysUseDedicatedImageMemory = true; |
| 520 |
} |
| 521 |
|
| 522 |
// On Mali galaxy s7 and s9 we see lots of rendering issues with image filters dropping out when |
| 523 |
// using only primary command buffers. We also see issues on the P30 running android 28. |
| 524 |
if (skgpu::kARM_VkVendor == properties.vendorID && androidAPIVersion <= 28) { |
| 525 |
fPreferPrimaryOverSecondaryCommandBuffers = false; |
| 526 |
// If we are using secondary command buffers our code isn't setup to insert barriers into |
| 527 |
// the secondary cb so we need to disable support for them. |
| 528 |
fTextureBarrierSupport = false; |
| 529 |
fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 530 |
} |
| 531 |
|
| 532 |
// We've seen numerous driver bugs on qualcomm devices running on android P (api 28) or earlier |
| 533 |
// when trying to using discardable msaa attachments and loading from resolve. So we disable the |
| 534 |
// feature for those devices. |
| 535 |
if (properties.vendorID == skgpu::kQualcomm_VkVendor && androidAPIVersion <= 28) { |
| 536 |
fPreferDiscardableMSAAAttachment = false; |
| 537 |
fSupportsDiscardableMSAAForDMSAA = false; |
| 538 |
} |
| 539 |
|
| 540 |
// On the Mali G76 and T880, the Perlin noise code needs to aggressively snap to multiples |
| 541 |
// of 1/255 to avoid artifacts in the double table lookup. |
| 542 |
if (skgpu::kARM_VkVendor == properties.vendorID) { |
| 543 |
fShaderCaps->fPerlinNoiseRoundingFix = true; |
| 544 |
} |
| 545 |
|
| 546 |
// On various devices, when calling vkCmdClearAttachments on a primary command buffer, it |
| 547 |
// corrupts the bound buffers on the command buffer. As a workaround we invalidate our knowledge |
| 548 |
// of bound buffers so that we will rebind them on the next draw. |
| 549 |
if (skgpu::kQualcomm_VkVendor == properties.vendorID || |
| 550 |
skgpu::kAMD_VkVendor == properties.vendorID) { |
| 551 |
fMustInvalidatePrimaryCmdBufferStateAfterClearAttachments = true; |
| 552 |
} |
| 553 |
|
| 554 |
// On Qualcomm and Arm the gpu resolves an area larger than the render pass bounds when using |
| 555 |
// discardable msaa attachments. This causes the resolve to resolve uninitialized data from the |
| 556 |
// msaa image into the resolve image. |
| 557 |
// This also occurs on swiftshader: b/303705884 |
| 558 |
if (properties.vendorID == skgpu::kQualcomm_VkVendor || |
| 559 |
properties.vendorID == skgpu::kARM_VkVendor || |
| 560 |
(properties.vendorID == skgpu::kGoogle_VkVendor && |
| 561 |
properties.deviceID == kSwiftshader_DeviceID)) { |
| 562 |
fMustLoadFullImageWithDiscardableMSAA = true; |
| 563 |
} |
| 564 |
|
| 565 |
// There seems to be bug in swiftshader when we reuse scratch buffers for uploads. We end up |
| 566 |
// with very slight pixel diffs. For example: |
| 567 |
// (https://ci.chromium.org/ui/p/chromium/builders/try/linux-rel/1585128/overview). |
| 568 |
// Since swiftshader is only really used for testing, to try and make things more stable we |
| 569 |
// disable the reuse of buffers. |
| 570 |
if (properties.vendorID == skgpu::kGoogle_VkVendor && |
| 571 |
properties.deviceID == kSwiftshader_DeviceID) { |
| 572 |
fReuseScratchBuffers = false; |
| 573 |
} |
| 574 |
|
| 575 |
//////////////////////////////////////////////////////////////////////////// |
| 576 |
// GrCaps workarounds |
| 577 |
//////////////////////////////////////////////////////////////////////////// |
| 578 |
|
| 579 |
if (skgpu::kARM_VkVendor == properties.vendorID) { |
| 580 |
fAvoidWritePixelsFastPath = true; // bugs.skia.org/8064 |
| 581 |
} |
| 582 |
|
| 583 |
// AMD advertises support for MAX_UINT vertex input attributes, but in reality only supports 32. |
| 584 |
if (skgpu::kAMD_VkVendor == properties.vendorID) { |
| 585 |
fMaxVertexAttributes = std::min(fMaxVertexAttributes, 32); |
| 586 |
} |
| 587 |
|
| 588 |
// Adreno devices fail when trying to read the dest using an input attachment and texture |
| 589 |
// barriers. |
| 590 |
if (skgpu::kQualcomm_VkVendor == properties.vendorID) { |
| 591 |
fTextureBarrierSupport = false; |
| 592 |
} |
| 593 |
|
| 594 |
#ifdef SK_BUILD_FOR_WIN |
| 595 |
// Gen 12 Intel devices running on windows has issues using barriers for dst reads. This is seen |
| 596 |
// when running the unit tests SkRuntimeEffect_Blender_GPU and DMSAA_aa_dst_read_after_dmsaa. |
| 597 |
// |
| 598 |
// Additionally, as of 2023-01-19 the latest driver compatible with Intel Iris Graphics 540 |
| 599 |
// (9th gen Skylake microarchitecture) produce SkRuntimeEffect_Blender and DMSAA deltas that |
| 600 |
// are unacceptable and break our tests. The drivers in question are version 31.0.101.2115 and |
| 601 |
// can be downloaded from |
| 602 |
// https://www.intel.com/content/www/us/en/download/762755/intel-6th-10th-gen-processor-graphics-windows.html. |
| 603 |
// This is likely due to bugs in the driver. As a temporary workaround, we disable texture |
| 604 |
// barrier support in Skylake and newer generations (i.e. 9th gen or newer). |
| 605 |
if (skgpu::kIntel_VkVendor == properties.vendorID && |
| 606 |
GetIntelGen(GetIntelGPUType(properties.deviceID)) >= 9) { |
| 607 |
fTextureBarrierSupport = false; |
| 608 |
} |
| 609 |
#endif |
| 610 |
|
| 611 |
// On ARM indirect draws are broken on Android 9 and earlier. This was tested on a P30 and |
| 612 |
// Mate 20x running android 9. |
| 613 |
if (properties.vendorID == skgpu::kARM_VkVendor && androidAPIVersion <= 28) { |
| 614 |
fNativeDrawIndirectSupport = false; |
| 615 |
} |
| 616 |
|
| 617 |
//////////////////////////////////////////////////////////////////////////// |
| 618 |
// GrShaderCaps workarounds |
| 619 |
//////////////////////////////////////////////////////////////////////////// |
| 620 |
|
| 621 |
if (skgpu::kImagination_VkVendor == properties.vendorID) { |
| 622 |
fShaderCaps->fAtan2ImplementedAsAtanYOverX = true; |
| 623 |
} |
| 624 |
|
| 625 |
// ARM GPUs calculate `matrix * vector` in SPIR-V at full precision, even when the inputs are |
| 626 |
// RelaxedPrecision. Rewriting the multiply as a sum of vector*scalar fixes this. (skbug.com/40042841) |
| 627 |
if (skgpu::kARM_VkVendor == properties.vendorID) { |
| 628 |
fShaderCaps->fRewriteMatrixVectorMultiply = true; |
| 629 |
} |
| 630 |
|
| 631 |
// Avoid RelaxedPrecision with OpImageSampleImplicitLod due to driver bug with YCbCr sampling. |
| 632 |
// (skbug.com/421927604) |
| 633 |
if (skgpu::kNvidia_VkVendor == properties.vendorID) { |
| 634 |
fShaderCaps->fCannotUseRelaxedPrecisionOnImageSample = true; |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
void GrVkCaps::initGrCaps(const skgpu::VulkanInterface* vkInterface, |
| 639 |
VkPhysicalDevice physDev, |
| 640 |
const VkPhysicalDeviceProperties& properties, |
| 641 |
const VkPhysicalDeviceMemoryProperties& memoryProperties, |
| 642 |
const VkPhysicalDeviceFeatures2& features, |
| 643 |
const skgpu::VulkanExtensions& extensions) { |
| 644 |
// So GPUs, like AMD, are reporting MAX_INT support vertex attributes. In general, there is no |
| 645 |
// need for us ever to support that amount, and it makes tests which tests all the vertex |
| 646 |
// attribs timeout looping over that many. For now, we'll cap this at 64 max and can raise it if |
| 647 |
// we ever find that need. |
| 648 |
static const uint32_t kMaxVertexAttributes = 64; |
| 649 |
fMaxVertexAttributes = std::min(properties.limits.maxVertexInputAttributes, |
| 650 |
kMaxVertexAttributes); |
| 651 |
|
| 652 |
// GrCaps::fSampleLocationsSupport refers to the ability to *query* the sample locations (not |
| 653 |
// program them). For now we just set this to true if the device uses standard locations, and |
| 654 |
// return the standard locations back when queried. |
| 655 |
if (properties.limits.standardSampleLocations) { |
| 656 |
fSampleLocationsSupport = true; |
| 657 |
} |
| 658 |
|
| 659 |
if (extensions.hasExtension(VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME, 1)) { |
| 660 |
fConservativeRasterSupport = true; |
| 661 |
} |
| 662 |
|
| 663 |
fWireframeSupport = true; |
| 664 |
|
| 665 |
// We could actually query and get a max size for each config, however maxImageDimension2D will |
| 666 |
// give the minimum max size across all configs. So for simplicity we will use that for now. |
| 667 |
fMaxRenderTargetSize = std::min(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 668 |
fMaxTextureSize = std::min(properties.limits.maxImageDimension2D, (uint32_t)INT_MAX); |
| 669 |
|
| 670 |
// TODO: check if RT's larger than 4k incur a performance cost on ARM. |
| 671 |
fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 672 |
|
| 673 |
fMaxPushConstantsSize = std::min(properties.limits.maxPushConstantsSize, (uint32_t)INT_MAX); |
| 674 |
|
| 675 |
// Assuming since we will always map in the end to upload the data we might as well just map |
| 676 |
// from the get go. There is no hard data to suggest this is faster or slower. |
| 677 |
fBufferMapThreshold = 0; |
| 678 |
|
| 679 |
fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag | kAsyncRead_MapFlag; |
| 680 |
|
| 681 |
fOversizedStencilSupport = true; |
| 682 |
|
| 683 |
if (extensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2)) { |
| 684 |
VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendProps; |
| 685 |
blendProps.sType = |
| 686 |
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT; |
| 687 |
blendProps.pNext = nullptr; |
| 688 |
|
| 689 |
VkPhysicalDeviceProperties2 props; |
| 690 |
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; |
| 691 |
props.pNext = &blendProps; |
| 692 |
|
| 693 |
GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties2(physDev, &props)); |
| 694 |
|
| 695 |
if (blendProps.advancedBlendAllOperations == VK_TRUE) { |
| 696 |
fShaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
| 697 |
|
| 698 |
auto blendFeatures = skgpu::GetExtensionFeatureStruct< |
| 699 |
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>( |
| 700 |
features, |
| 701 |
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT |
| 702 |
); |
| 703 |
if (blendFeatures && blendFeatures->advancedBlendCoherentOperations == VK_TRUE) { |
| 704 |
fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 705 |
} else { |
| 706 |
fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 707 |
} |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
if (skgpu::kARM_VkVendor == properties.vendorID) { |
| 712 |
fShouldCollapseSrcOverToSrcWhenAble = true; |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, |
| 717 |
const VkPhysicalDeviceFeatures2& features) { |
| 718 |
GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 719 |
shaderCaps->fVersionDeclString = "#version 330\n"; |
| 720 |
|
| 721 |
// Ganesh + Vulkan always emits `sk_Clockwise` to avoid some Adreno rendering errors. |
| 722 |
shaderCaps->fMustDeclareFragmentFrontFacing = true; |
| 723 |
|
| 724 |
shaderCaps->fFlatInterpolationSupport = true; // Supported because Vulkan is based on ES 3.0 |
| 725 |
// Flat interpolation appears to be slow on Qualcomm GPUs. This was tested in GL and is assumed |
| 726 |
// to be true with Vulkan as well. |
| 727 |
shaderCaps->fPreferFlatInterpolation = skgpu::kQualcomm_VkVendor != properties.vendorID; |
| 728 |
|
| 729 |
shaderCaps->fSampleMaskSupport = true; |
| 730 |
|
| 731 |
shaderCaps->fShaderDerivativeSupport = true; |
| 732 |
shaderCaps->fExplicitTextureLodSupport = true; |
| 733 |
|
| 734 |
shaderCaps->fDualSourceBlendingSupport = features.features.dualSrcBlend; |
| 735 |
|
| 736 |
shaderCaps->fIntegerSupport = true; |
| 737 |
shaderCaps->fNonsquareMatrixSupport = true; |
| 738 |
shaderCaps->fInverseHyperbolicSupport = true; |
| 739 |
shaderCaps->fVertexIDSupport = true; |
| 740 |
shaderCaps->fInfinitySupport = true; |
| 741 |
shaderCaps->fNonconstantArrayIndexSupport = true; |
| 742 |
shaderCaps->fBitManipulationSupport = true; |
| 743 |
|
| 744 |
// Assume the minimum precisions mandated by the SPIR-V spec. |
| 745 |
shaderCaps->fFloatIs32Bits = true; |
| 746 |
shaderCaps->fHalfIs32Bits = false; |
| 747 |
|
| 748 |
shaderCaps->fMaxFragmentSamplers = std::min( |
| 749 |
std::min(properties.limits.maxPerStageDescriptorSampledImages, |
| 750 |
properties.limits.maxPerStageDescriptorSamplers), |
| 751 |
(uint32_t)INT_MAX); |
| 752 |
} |
| 753 |
|
| 754 |
bool stencil_format_supported(const skgpu::VulkanInterface* interface, |
| 755 |
VkPhysicalDevice physDev, |
| 756 |
VkFormat format) { |
| 757 |
VkFormatProperties props; |
| 758 |
memset(&props, 0, sizeof(VkFormatProperties)); |
| 759 |
GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 760 |
return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optimalTilingFeatures); |
| 761 |
} |
| 762 |
|
| 763 |
void GrVkCaps::initStencilFormat(const skgpu::VulkanInterface* interface, |
| 764 |
VkPhysicalDevice physDev) { |
| 765 |
if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
| 766 |
fPreferredStencilFormat = VK_FORMAT_S8_UINT; |
| 767 |
} else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_S8_UINT)) { |
| 768 |
fPreferredStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; |
| 769 |
} else { |
| 770 |
SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLOAT_S8_UINT)); |
| 771 |
fPreferredStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
static bool format_is_srgb(VkFormat format) { |
| 776 |
SkASSERT(GrVkFormatIsSupported(format)); |
| 777 |
|
| 778 |
switch (format) { |
| 779 |
case VK_FORMAT_R8G8B8A8_SRGB: |
| 780 |
return true; |
| 781 |
default: |
| 782 |
return false; |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
// These are all the valid VkFormats that we support in Skia. They are roughly ordered from most |
| 787 |
// frequently used to least to improve look up times in arrays. |
| 788 |
static constexpr VkFormat kVkFormats[] = { |
| 789 |
VK_FORMAT_R8G8B8A8_UNORM, |
| 790 |
VK_FORMAT_R8_UNORM, |
| 791 |
VK_FORMAT_B8G8R8A8_UNORM, |
| 792 |
VK_FORMAT_R5G6B5_UNORM_PACK16, |
| 793 |
VK_FORMAT_B5G6R5_UNORM_PACK16, |
| 794 |
VK_FORMAT_R16G16B16A16_SFLOAT, |
| 795 |
VK_FORMAT_R16_SFLOAT, |
| 796 |
VK_FORMAT_R8G8B8_UNORM, |
| 797 |
VK_FORMAT_R8G8_UNORM, |
| 798 |
VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
| 799 |
VK_FORMAT_A2R10G10B10_UNORM_PACK32, |
| 800 |
VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, |
| 801 |
VK_FORMAT_B4G4R4A4_UNORM_PACK16, |
| 802 |
VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
| 803 |
VK_FORMAT_R8G8B8A8_SRGB, |
| 804 |
VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, |
| 805 |
VK_FORMAT_BC1_RGB_UNORM_BLOCK, |
| 806 |
VK_FORMAT_BC1_RGBA_UNORM_BLOCK, |
| 807 |
VK_FORMAT_R16_UNORM, |
| 808 |
VK_FORMAT_R16G16_UNORM, |
| 809 |
VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, |
| 810 |
VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, |
| 811 |
VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16, |
| 812 |
VK_FORMAT_R16G16B16A16_UNORM, |
| 813 |
VK_FORMAT_R16G16_SFLOAT, |
| 814 |
}; |
| 815 |
|
| 816 |
void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) { |
| 817 |
#ifdef SK_DEBUG |
| 818 |
for (size_t i = 0; i < kNumVkFormats; ++i) { |
| 819 |
const auto& formatInfo = fFormatTable[i]; |
| 820 |
for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) { |
| 821 |
const auto& ctInfo = formatInfo.fColorTypeInfos[j]; |
| 822 |
if (ctInfo.fColorType == colorType && |
| 823 |
!SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) { |
| 824 |
bool found = false; |
| 825 |
for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 826 |
if (kVkFormats[i] == *it) { |
| 827 |
found = true; |
| 828 |
} |
| 829 |
} |
| 830 |
SkASSERT(found); |
| 831 |
} |
| 832 |
} |
| 833 |
} |
| 834 |
#endif |
| 835 |
int idx = static_cast<int>(colorType); |
| 836 |
for (auto it = formats.begin(); it != formats.end(); ++it) { |
| 837 |
const auto& info = this->getFormatInfo(*it); |
| 838 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 839 |
if (info.fColorTypeInfos[i].fColorType == colorType) { |
| 840 |
fColorTypeToFormatTable[idx] = *it; |
| 841 |
return; |
| 842 |
} |
| 843 |
} |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const { |
| 848 |
GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this); |
| 849 |
return nonConstThis->getFormatInfo(format); |
| 850 |
} |
| 851 |
|
| 852 |
GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) { |
| 853 |
static_assert(std::size(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 854 |
"Size of VkFormats array must match static value in header"); |
| 855 |
for (size_t i = 0; i < std::size(kVkFormats); ++i) { |
| 856 |
if (kVkFormats[i] == format) { |
| 857 |
return fFormatTable[i]; |
| 858 |
} |
| 859 |
} |
| 860 |
static FormatInfo kInvalidFormat; |
| 861 |
return kInvalidFormat; |
| 862 |
} |
| 863 |
|
| 864 |
void GrVkCaps::initFormatTable(const GrContextOptions& contextOptions, |
| 865 |
const skgpu::VulkanInterface* interface, |
| 866 |
VkPhysicalDevice physDev, |
| 867 |
const VkPhysicalDeviceProperties& properties, |
| 868 |
const VkPhysicalDeviceFeatures2& features, |
| 869 |
const skgpu::VulkanExtensions& extensions) { |
| 870 |
static_assert(std::size(kVkFormats) == GrVkCaps::kNumVkFormats, |
| 871 |
"Size of VkFormats array must match static value in header"); |
| 872 |
|
| 873 |
std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED); |
| 874 |
|
| 875 |
// Go through all the formats and init their support surface and data GrColorTypes. |
| 876 |
// Format: VK_FORMAT_R8G8B8A8_UNORM |
| 877 |
{ |
| 878 |
constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM; |
| 879 |
auto& info = this->getFormatInfo(format); |
| 880 |
info.init(contextOptions, interface, physDev, properties, format); |
| 881 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 882 |
info.fColorTypeInfoCount = 2; |
| 883 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 884 |
int ctIdx = 0; |
| 885 |
// Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888 |
| 886 |
{ |
| 887 |
constexpr GrColorType ct = GrColorType::kRGBA_8888; |
| 888 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 889 |
ctInfo.fColorType = ct; |
| 890 |
ctInfo.fTransferColorType = ct; |
| 891 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 892 |
} |
| 893 |
// Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x |
| 894 |
{ |
| 895 |
constexpr GrColorType ct = GrColorType::kRGB_888x; |
| 896 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 897 |
ctInfo.fColorType = ct; |
| 898 |
ctInfo.fTransferColorType = ct; |
| 899 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 900 |
ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1(); |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
// Format: VK_FORMAT_R8_UNORM |
| 906 |
{ |
| 907 |
constexpr VkFormat format = VK_FORMAT_R8_UNORM; |
| 908 |
auto& info = this->getFormatInfo(format); |
| 909 |
info.init(contextOptions, interface, physDev, properties, format); |
| 910 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 911 |
info.fColorTypeInfoCount = 3; |
| 912 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 913 |
int ctIdx = 0; |
| 914 |
// Format: VK_FORMAT_R8_UNORM, Surface: kR_8 |
| 915 |
{ |
| 916 |
constexpr GrColorType ct = GrColorType::kR_8; |
| 917 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 918 |
ctInfo.fColorType = ct; |
| 919 |
ctInfo.fTransferColorType = ct; |
| 920 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 921 |
} |
| 922 |
// Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8 |
| 923 |
{ |
| 924 |
constexpr GrColorType ct = GrColorType::kAlpha_8; |
| 925 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 926 |
ctInfo.fColorType = ct; |
| 927 |
ctInfo.fTransferColorType = ct; |
| 928 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 929 |
ctInfo.fReadSwizzle = skgpu::Swizzle("000r"); |
| 930 |
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000"); |
| 931 |
} |
| 932 |
// Format: VK_FORMAT_R8_UNORM, Surface: kGray_8 |
| 933 |
{ |
| 934 |
constexpr GrColorType ct = GrColorType::kGray_8; |
| 935 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 936 |
ctInfo.fColorType = ct; |
| 937 |
ctInfo.fTransferColorType = ct; |
| 938 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 939 |
ctInfo.fReadSwizzle = skgpu::Swizzle("rrr1"); |
| 940 |
} |
| 941 |
} |
| 942 |
} |
| 943 |
// Format: VK_FORMAT_B8G8R8A8_UNORM |
| 944 |
{ |
| 945 |
constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM; |
| 946 |
auto& info = this->getFormatInfo(format); |
| 947 |
info.init(contextOptions, interface, physDev, properties, format); |
| 948 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 949 |
info.fColorTypeInfoCount = 2; |
| 950 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 951 |
int ctIdx = 0; |
| 952 |
// Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888 |
| 953 |
{ |
| 954 |
constexpr GrColorType ct = GrColorType::kBGRA_8888; |
| 955 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 956 |
ctInfo.fColorType = ct; |
| 957 |
ctInfo.fTransferColorType = ct; |
| 958 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 959 |
} |
| 960 |
// Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kRGB_888x |
| 961 |
// TODO: add and use kBGR_888X instead |
| 962 |
{ |
| 963 |
constexpr GrColorType ct = GrColorType::kRGB_888x; |
| 964 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 965 |
ctInfo.fColorType = ct; |
| 966 |
ctInfo.fTransferColorType = GrColorType::kBGRA_8888; |
| 967 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 968 |
ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1(); |
| 969 |
} |
| 970 |
} |
| 971 |
} |
| 972 |
// Format: VK_FORMAT_R5G6B5_UNORM_PACK16 |
| 973 |
{ |
| 974 |
constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
| 975 |
auto& info = this->getFormatInfo(format); |
| 976 |
info.init(contextOptions, interface, physDev, properties, format); |
| 977 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 978 |
info.fColorTypeInfoCount = 1; |
| 979 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 980 |
int ctIdx = 0; |
| 981 |
// Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565 |
| 982 |
{ |
| 983 |
constexpr GrColorType ct = GrColorType::kBGR_565; |
| 984 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 985 |
ctInfo.fColorType = ct; |
| 986 |
ctInfo.fTransferColorType = ct; |
| 987 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 988 |
} |
| 989 |
} |
| 990 |
} |
| 991 |
// Format: VK_FORMAT_B5G6R5_UNORM_PACK16 |
| 992 |
{ |
| 993 |
constexpr VkFormat format = VK_FORMAT_B5G6R5_UNORM_PACK16; |
| 994 |
auto& info = this->getFormatInfo(format); |
| 995 |
info.init(contextOptions, interface, physDev, properties, format); |
| 996 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 997 |
info.fColorTypeInfoCount = 2; |
| 998 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 999 |
int ctIdx = 0; |
| 1000 |
// Format: VK_FORMAT_B5G6R5_UNORM_PACK16, Surface: kRGB_565 |
| 1001 |
{ |
| 1002 |
constexpr GrColorType ct = GrColorType::kRGB_565; |
| 1003 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1004 |
ctInfo.fColorType = ct; |
| 1005 |
ctInfo.fTransferColorType = ct; |
| 1006 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1007 |
} |
| 1008 |
// Format: VK_FORMAT_B5G6R5_UNORM_PACK16, Surface: kBGR_565 |
| 1009 |
// We need this because there is no kBGR_565_SkColorType. |
| 1010 |
{ |
| 1011 |
constexpr GrColorType ct = GrColorType::kBGR_565; |
| 1012 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1013 |
ctInfo.fColorType = ct; |
| 1014 |
ctInfo.fTransferColorType = GrColorType::kRGB_565; |
| 1015 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 1016 |
} |
| 1017 |
} |
| 1018 |
} |
| 1019 |
// Format: VK_FORMAT_R16G16B16A16_SFLOAT |
| 1020 |
{ |
| 1021 |
constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT; |
| 1022 |
auto& info = this->getFormatInfo(format); |
| 1023 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1024 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1025 |
info.fColorTypeInfoCount = 3; |
| 1026 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1027 |
int ctIdx = 0; |
| 1028 |
// Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16 |
| 1029 |
{ |
| 1030 |
constexpr GrColorType ct = GrColorType::kRGBA_F16; |
| 1031 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1032 |
ctInfo.fColorType = ct; |
| 1033 |
ctInfo.fTransferColorType = ct; |
| 1034 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1035 |
} |
| 1036 |
// Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped |
| 1037 |
{ |
| 1038 |
constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped; |
| 1039 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1040 |
ctInfo.fColorType = ct; |
| 1041 |
ctInfo.fTransferColorType = ct; |
| 1042 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1043 |
} |
| 1044 |
// Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGB_F16F16F16x |
| 1045 |
{ |
| 1046 |
constexpr GrColorType ct = GrColorType::kRGB_F16F16F16x; |
| 1047 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1048 |
ctInfo.fColorType = ct; |
| 1049 |
ctInfo.fTransferColorType = ct; |
| 1050 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 1051 |
ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1(); |
| 1052 |
} |
| 1053 |
} |
| 1054 |
} |
| 1055 |
// Format: VK_FORMAT_R16_SFLOAT |
| 1056 |
{ |
| 1057 |
constexpr VkFormat format = VK_FORMAT_R16_SFLOAT; |
| 1058 |
auto& info = this->getFormatInfo(format); |
| 1059 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1060 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1061 |
info.fColorTypeInfoCount = 1; |
| 1062 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1063 |
int ctIdx = 0; |
| 1064 |
// Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16 |
| 1065 |
{ |
| 1066 |
constexpr GrColorType ct = GrColorType::kAlpha_F16; |
| 1067 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1068 |
ctInfo.fColorType = ct; |
| 1069 |
ctInfo.fTransferColorType = ct; |
| 1070 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1071 |
ctInfo.fReadSwizzle = skgpu::Swizzle("000r"); |
| 1072 |
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000"); |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
// Format: VK_FORMAT_R8G8B8_UNORM |
| 1077 |
{ |
| 1078 |
constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM; |
| 1079 |
auto& info = this->getFormatInfo(format); |
| 1080 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1081 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1082 |
info.fColorTypeInfoCount = 1; |
| 1083 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1084 |
int ctIdx = 0; |
| 1085 |
// Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x |
| 1086 |
{ |
| 1087 |
constexpr GrColorType ct = GrColorType::kRGB_888x; |
| 1088 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1089 |
ctInfo.fColorType = ct; |
| 1090 |
// The Vulkan format is 3 bpp so we must convert to/from that when transferring. |
| 1091 |
ctInfo.fTransferColorType = GrColorType::kRGB_888; |
| 1092 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
// Format: VK_FORMAT_R8G8_UNORM |
| 1097 |
{ |
| 1098 |
constexpr VkFormat format = VK_FORMAT_R8G8_UNORM; |
| 1099 |
auto& info = this->getFormatInfo(format); |
| 1100 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1101 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1102 |
info.fColorTypeInfoCount = 1; |
| 1103 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1104 |
int ctIdx = 0; |
| 1105 |
// Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88 |
| 1106 |
{ |
| 1107 |
constexpr GrColorType ct = GrColorType::kRG_88; |
| 1108 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1109 |
ctInfo.fColorType = ct; |
| 1110 |
ctInfo.fTransferColorType = ct; |
| 1111 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1112 |
} |
| 1113 |
} |
| 1114 |
} |
| 1115 |
// Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32 |
| 1116 |
{ |
| 1117 |
constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32; |
| 1118 |
auto& info = this->getFormatInfo(format); |
| 1119 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1120 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1121 |
info.fColorTypeInfoCount = 2; |
| 1122 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1123 |
int ctIdx = 0; |
| 1124 |
// Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102 |
| 1125 |
{ |
| 1126 |
constexpr GrColorType ct = GrColorType::kRGBA_1010102; |
| 1127 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1128 |
ctInfo.fColorType = ct; |
| 1129 |
ctInfo.fTransferColorType = ct; |
| 1130 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1131 |
} |
| 1132 |
// Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGB_101010x |
| 1133 |
{ |
| 1134 |
constexpr GrColorType ct = GrColorType::kRGB_101010x; |
| 1135 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1136 |
ctInfo.fColorType = ct; |
| 1137 |
ctInfo.fTransferColorType = ct; |
| 1138 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| 1139 |
ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1(); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
} |
| 1143 |
// Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32 |
| 1144 |
{ |
| 1145 |
constexpr VkFormat format = VK_FORMAT_A2R10G10B10_UNORM_PACK32; |
| 1146 |
auto& info = this->getFormatInfo(format); |
| 1147 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1148 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1149 |
info.fColorTypeInfoCount = 1; |
| 1150 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1151 |
int ctIdx = 0; |
| 1152 |
// Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32, Surface: kBGRA_1010102 |
| 1153 |
{ |
| 1154 |
constexpr GrColorType ct = GrColorType::kBGRA_1010102; |
| 1155 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1156 |
ctInfo.fColorType = ct; |
| 1157 |
ctInfo.fTransferColorType = ct; |
| 1158 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1159 |
} |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
// Format: VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16 |
| 1164 |
// Technically without this extension and enabled feature we could still use this format to |
| 1165 |
// sample with a ycbcr sampler. But for simplicity until we have clients requesting that, we |
| 1166 |
// limit the use of this format to cases where we have the extension supported. |
| 1167 |
const auto rgba10x6Feature = |
| 1168 |
skgpu::GetExtensionFeatureStruct<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>( |
| 1169 |
features, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT); |
| 1170 |
if (rgba10x6Feature && rgba10x6Feature->formatRgba10x6WithoutYCbCrSampler) { |
| 1171 |
constexpr VkFormat format = VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16; |
| 1172 |
auto& info = this->getFormatInfo(format); |
| 1173 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1174 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1175 |
info.fColorTypeInfoCount = 1; |
| 1176 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1177 |
int ctIdx = 0; |
| 1178 |
// Format: VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, Surface: kRGBA_10x6 |
| 1179 |
{ |
| 1180 |
constexpr GrColorType ct = GrColorType::kRGBA_10x6; |
| 1181 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1182 |
ctInfo.fColorType = ct; |
| 1183 |
ctInfo.fTransferColorType = ct; |
| 1184 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1185 |
} |
| 1186 |
} |
| 1187 |
} |
| 1188 |
|
| 1189 |
// Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16 |
| 1190 |
{ |
| 1191 |
constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16; |
| 1192 |
auto& info = this->getFormatInfo(format); |
| 1193 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1194 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1195 |
info.fColorTypeInfoCount = 1; |
| 1196 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1197 |
int ctIdx = 0; |
| 1198 |
// Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 1199 |
{ |
| 1200 |
constexpr GrColorType ct = GrColorType::kABGR_4444; |
| 1201 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1202 |
ctInfo.fColorType = ct; |
| 1203 |
ctInfo.fTransferColorType = ct; |
| 1204 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1205 |
ctInfo.fReadSwizzle = skgpu::Swizzle::BGRA(); |
| 1206 |
ctInfo.fWriteSwizzle = skgpu::Swizzle::BGRA(); |
| 1207 |
} |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
// Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16 |
| 1212 |
{ |
| 1213 |
constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16; |
| 1214 |
auto& info = this->getFormatInfo(format); |
| 1215 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1216 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1217 |
info.fColorTypeInfoCount = 1; |
| 1218 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1219 |
int ctIdx = 0; |
| 1220 |
// Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444 |
| 1221 |
{ |
| 1222 |
constexpr GrColorType ct = GrColorType::kABGR_4444; |
| 1223 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1224 |
ctInfo.fColorType = ct; |
| 1225 |
ctInfo.fTransferColorType = ct; |
| 1226 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1227 |
} |
| 1228 |
} |
| 1229 |
} |
| 1230 |
// Format: VK_FORMAT_R8G8B8A8_SRGB |
| 1231 |
{ |
| 1232 |
constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB; |
| 1233 |
auto& info = this->getFormatInfo(format); |
| 1234 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1235 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1236 |
info.fColorTypeInfoCount = 1; |
| 1237 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1238 |
int ctIdx = 0; |
| 1239 |
// Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB |
| 1240 |
{ |
| 1241 |
constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB; |
| 1242 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1243 |
ctInfo.fColorType = ct; |
| 1244 |
ctInfo.fTransferColorType = ct; |
| 1245 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1246 |
} |
| 1247 |
} |
| 1248 |
} |
| 1249 |
// Format: VK_FORMAT_R16_UNORM |
| 1250 |
{ |
| 1251 |
constexpr VkFormat format = VK_FORMAT_R16_UNORM; |
| 1252 |
auto& info = this->getFormatInfo(format); |
| 1253 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1254 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1255 |
info.fColorTypeInfoCount = 2; |
| 1256 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1257 |
int ctIdx = 0; |
| 1258 |
// Format: VK_FORMAT_R16_UNORM, Surface: kAlpha_16 |
| 1259 |
{ |
| 1260 |
constexpr GrColorType ct = GrColorType::kAlpha_16; |
| 1261 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1262 |
ctInfo.fColorType = ct; |
| 1263 |
ctInfo.fTransferColorType = ct; |
| 1264 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1265 |
ctInfo.fReadSwizzle = skgpu::Swizzle("000r"); |
| 1266 |
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000"); |
| 1267 |
} |
| 1268 |
// Format: VK_FORMAT_R16_UNORM, Surface: kR16_unorm |
| 1269 |
{ |
| 1270 |
constexpr GrColorType ct = GrColorType::kR_16; |
| 1271 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1272 |
ctInfo.fColorType = ct; |
| 1273 |
ctInfo.fTransferColorType = ct; |
| 1274 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1275 |
} |
| 1276 |
} |
| 1277 |
} |
| 1278 |
// Format: VK_FORMAT_R16G16_UNORM |
| 1279 |
{ |
| 1280 |
constexpr VkFormat format = VK_FORMAT_R16G16_UNORM; |
| 1281 |
auto& info = this->getFormatInfo(format); |
| 1282 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1283 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1284 |
info.fColorTypeInfoCount = 1; |
| 1285 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1286 |
int ctIdx = 0; |
| 1287 |
// Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616 |
| 1288 |
{ |
| 1289 |
constexpr GrColorType ct = GrColorType::kRG_1616; |
| 1290 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1291 |
ctInfo.fColorType = ct; |
| 1292 |
ctInfo.fTransferColorType = ct; |
| 1293 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
// Format: VK_FORMAT_R16G16B16A16_UNORM |
| 1298 |
{ |
| 1299 |
constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM; |
| 1300 |
auto& info = this->getFormatInfo(format); |
| 1301 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1302 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1303 |
info.fColorTypeInfoCount = 1; |
| 1304 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1305 |
int ctIdx = 0; |
| 1306 |
// Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616 |
| 1307 |
{ |
| 1308 |
constexpr GrColorType ct = GrColorType::kRGBA_16161616; |
| 1309 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1310 |
ctInfo.fColorType = ct; |
| 1311 |
ctInfo.fTransferColorType = ct; |
| 1312 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1313 |
} |
| 1314 |
} |
| 1315 |
} |
| 1316 |
// Format: VK_FORMAT_R16G16_SFLOAT |
| 1317 |
{ |
| 1318 |
constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT; |
| 1319 |
auto& info = this->getFormatInfo(format); |
| 1320 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1321 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1322 |
info.fColorTypeInfoCount = 1; |
| 1323 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1324 |
int ctIdx = 0; |
| 1325 |
// Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16 |
| 1326 |
{ |
| 1327 |
constexpr GrColorType ct = GrColorType::kRG_F16; |
| 1328 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1329 |
ctInfo.fColorType = ct; |
| 1330 |
ctInfo.fTransferColorType = ct; |
| 1331 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| 1332 |
} |
| 1333 |
} |
| 1334 |
} |
| 1335 |
// Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM |
| 1336 |
{ |
| 1337 |
constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM; |
| 1338 |
auto& info = this->getFormatInfo(format); |
| 1339 |
if (fSupportsYcbcrConversion) { |
| 1340 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1341 |
} |
| 1342 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1343 |
info.fColorTypeInfoCount = 1; |
| 1344 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1345 |
int ctIdx = 0; |
| 1346 |
// Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x |
| 1347 |
{ |
| 1348 |
constexpr GrColorType ct = GrColorType::kRGB_888x; |
| 1349 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1350 |
ctInfo.fColorType = ct; |
| 1351 |
ctInfo.fTransferColorType = ct; |
| 1352 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
| 1353 |
} |
| 1354 |
} |
| 1355 |
} |
| 1356 |
// Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM |
| 1357 |
{ |
| 1358 |
constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; |
| 1359 |
auto& info = this->getFormatInfo(format); |
| 1360 |
if (fSupportsYcbcrConversion) { |
| 1361 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1362 |
} |
| 1363 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1364 |
info.fColorTypeInfoCount = 1; |
| 1365 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1366 |
int ctIdx = 0; |
| 1367 |
// Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x |
| 1368 |
{ |
| 1369 |
constexpr GrColorType ct = GrColorType::kRGB_888x; |
| 1370 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1371 |
ctInfo.fColorType = ct; |
| 1372 |
ctInfo.fTransferColorType = ct; |
| 1373 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
| 1374 |
} |
| 1375 |
} |
| 1376 |
} |
| 1377 |
// Format: VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 |
| 1378 |
{ |
| 1379 |
constexpr VkFormat format = VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16; |
| 1380 |
auto& info = this->getFormatInfo(format); |
| 1381 |
if (fSupportsYcbcrConversion) { |
| 1382 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1383 |
} |
| 1384 |
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { |
| 1385 |
info.fColorTypeInfoCount = 1; |
| 1386 |
info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount); |
| 1387 |
int ctIdx = 0; |
| 1388 |
// Format: VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16, Surface: kRGBA_1010102 |
| 1389 |
{ |
| 1390 |
constexpr GrColorType ct = GrColorType::kRGBA_1010102; |
| 1391 |
auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| 1392 |
ctInfo.fColorType = ct; |
| 1393 |
ctInfo.fTransferColorType = ct; |
| 1394 |
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
} |
| 1398 |
// Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK |
| 1399 |
{ |
| 1400 |
constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 1401 |
auto& info = this->getFormatInfo(format); |
| 1402 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1403 |
// Setting this to texel block size |
| 1404 |
// No supported GrColorTypes. |
| 1405 |
} |
| 1406 |
|
| 1407 |
// Format: VK_FORMAT_BC1_RGB_UNORM_BLOCK |
| 1408 |
{ |
| 1409 |
constexpr VkFormat format = VK_FORMAT_BC1_RGB_UNORM_BLOCK; |
| 1410 |
auto& info = this->getFormatInfo(format); |
| 1411 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1412 |
// Setting this to texel block size |
| 1413 |
// No supported GrColorTypes. |
| 1414 |
} |
| 1415 |
|
| 1416 |
// Format: VK_FORMAT_BC1_RGBA_UNORM_BLOCK |
| 1417 |
{ |
| 1418 |
constexpr VkFormat format = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; |
| 1419 |
auto& info = this->getFormatInfo(format); |
| 1420 |
info.init(contextOptions, interface, physDev, properties, format); |
| 1421 |
// Setting this to texel block size |
| 1422 |
// No supported GrColorTypes. |
| 1423 |
} |
| 1424 |
|
| 1425 |
//////////////////////////////////////////////////////////////////////////// |
| 1426 |
// Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats |
| 1427 |
// are passed into the setColorType function indicates the priority in selecting which format |
| 1428 |
// we use for a given GrcolorType. |
| 1429 |
|
| 1430 |
this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM }); |
| 1431 |
this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16, |
| 1432 |
VK_FORMAT_B5G6R5_UNORM_PACK16 }); |
| 1433 |
this->setColorType(GrColorType::kRGB_565, { VK_FORMAT_B5G6R5_UNORM_PACK16 }); |
| 1434 |
this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16, |
| 1435 |
VK_FORMAT_B4G4R4A4_UNORM_PACK16 }); |
| 1436 |
this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM }); |
| 1437 |
this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB }); |
| 1438 |
this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM, |
| 1439 |
VK_FORMAT_R8G8B8A8_UNORM, |
| 1440 |
VK_FORMAT_B8G8R8A8_UNORM, }); |
| 1441 |
this->setColorType(GrColorType::kR_8, { VK_FORMAT_R8_UNORM }); |
| 1442 |
this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM }); |
| 1443 |
this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM }); |
| 1444 |
this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 }); |
| 1445 |
this->setColorType(GrColorType::kBGRA_1010102, { VK_FORMAT_A2R10G10B10_UNORM_PACK32 }); |
| 1446 |
this->setColorType(GrColorType::kRGB_101010x, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 }); |
| 1447 |
this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM }); |
| 1448 |
this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT }); |
| 1449 |
this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
| 1450 |
this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT }); |
| 1451 |
this->setColorType(GrColorType::kRGB_F16F16F16x, { VK_FORMAT_R16G16B16A16_SFLOAT}); |
| 1452 |
this->setColorType(GrColorType::kAlpha_16, { VK_FORMAT_R16_UNORM }); |
| 1453 |
this->setColorType(GrColorType::kR_16, { VK_FORMAT_R16_UNORM }); |
| 1454 |
this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM }); |
| 1455 |
this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM }); |
| 1456 |
this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT }); |
| 1457 |
this->setColorType(GrColorType::kRGBA_10x6, { VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16}); |
| 1458 |
} |
| 1459 |
|
| 1460 |
void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { |
| 1461 |
if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 1462 |
SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 1463 |
*flags = *flags | kTexturable_Flag; |
| 1464 |
|
| 1465 |
// Ganesh assumes that all renderable surfaces are also texturable |
| 1466 |
if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
| 1467 |
*flags = *flags | kRenderable_Flag; |
| 1468 |
} |
| 1469 |
} |
| 1470 |
// TODO: For Vk w/ VK_KHR_maintenance1 extension support, check |
| 1471 |
// VK_FORMAT_FEATURE_TRANSFER_[SRC|DST]_BIT_KHR explicitly to set copy flags |
| 1472 |
// Can do similar check for VK_KHR_sampler_ycbcr_conversion added bits |
| 1473 |
|
| 1474 |
if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 1475 |
*flags = *flags | kBlitSrc_Flag; |
| 1476 |
} |
| 1477 |
|
| 1478 |
if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 1479 |
*flags = *flags | kBlitDst_Flag; |
| 1480 |
} |
| 1481 |
} |
| 1482 |
|
| 1483 |
void GrVkCaps::FormatInfo::initSampleCounts(const GrContextOptions& contextOptions, |
| 1484 |
const skgpu::VulkanInterface* interface, |
| 1485 |
VkPhysicalDevice physDev, |
| 1486 |
const VkPhysicalDeviceProperties& physProps, |
| 1487 |
VkFormat format) { |
| 1488 |
VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 1489 |
VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 1490 |
VK_IMAGE_USAGE_SAMPLED_BIT | |
| 1491 |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 1492 |
VkImageFormatProperties properties; |
| 1493 |
VkResult result = GR_VK_CALL(interface, |
| 1494 |
GetPhysicalDeviceImageFormatProperties(physDev, |
| 1495 |
format, |
| 1496 |
VK_IMAGE_TYPE_2D, |
| 1497 |
VK_IMAGE_TILING_OPTIMAL, |
| 1498 |
usage, |
| 1499 |
0, // createFlags |
| 1500 |
&properties)); |
| 1501 |
if (result != VK_SUCCESS) { |
| 1502 |
return; |
| 1503 |
} |
| 1504 |
VkSampleCountFlags flags = properties.sampleCounts; |
| 1505 |
if (flags & VK_SAMPLE_COUNT_1_BIT) { |
| 1506 |
fColorSampleCounts.push_back(1); |
| 1507 |
} |
| 1508 |
if (skgpu::kImagination_VkVendor == physProps.vendorID) { |
| 1509 |
// MSAA does not work on imagination |
| 1510 |
return; |
| 1511 |
} |
| 1512 |
if (skgpu::kIntel_VkVendor == physProps.vendorID) { |
| 1513 |
if (GetIntelGen(GetIntelGPUType(physProps.deviceID)) < 12 || |
| 1514 |
!contextOptions.fAllowMSAAOnNewIntel) { |
| 1515 |
// MSAA doesn't work well on Intel GPUs chromium:527565, chromium:983926 |
| 1516 |
return; |
| 1517 |
} |
| 1518 |
} |
| 1519 |
if (flags & VK_SAMPLE_COUNT_2_BIT) { |
| 1520 |
fColorSampleCounts.push_back(2); |
| 1521 |
} |
| 1522 |
if (flags & VK_SAMPLE_COUNT_4_BIT) { |
| 1523 |
fColorSampleCounts.push_back(4); |
| 1524 |
} |
| 1525 |
if (flags & VK_SAMPLE_COUNT_8_BIT) { |
| 1526 |
fColorSampleCounts.push_back(8); |
| 1527 |
} |
| 1528 |
if (flags & VK_SAMPLE_COUNT_16_BIT) { |
| 1529 |
fColorSampleCounts.push_back(16); |
| 1530 |
} |
| 1531 |
// Standard sample locations are not defined for more than 16 samples, and we don't need more |
| 1532 |
// than 16. Omit 32 and 64. |
| 1533 |
} |
| 1534 |
|
| 1535 |
void GrVkCaps::FormatInfo::init(const GrContextOptions& contextOptions, |
| 1536 |
const skgpu::VulkanInterface* interface, |
| 1537 |
VkPhysicalDevice physDev, |
| 1538 |
const VkPhysicalDeviceProperties& properties, |
| 1539 |
VkFormat format) { |
| 1540 |
VkFormatProperties props; |
| 1541 |
memset(&props, 0, sizeof(VkFormatProperties)); |
| 1542 |
GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &props)); |
| 1543 |
InitFormatFlags(props.linearTilingFeatures, &fLinearFlags); |
| 1544 |
InitFormatFlags(props.optimalTilingFeatures, &fOptimalFlags); |
| 1545 |
if (fOptimalFlags & kRenderable_Flag) { |
| 1546 |
this->initSampleCounts(contextOptions, interface, physDev, properties, format); |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
// For many checks in caps, we need to know whether the GrBackendFormat is external or not. If it is |
| 1551 |
// external the VkFormat will be VK_NULL_HANDLE which is not handled by our various format |
| 1552 |
// capability checks. |
| 1553 |
static bool backend_format_is_external(const GrBackendFormat& format) { |
| 1554 |
const skgpu::VulkanYcbcrConversionInfo* ycbcrInfo = |
| 1555 |
GrBackendFormats::GetVkYcbcrConversionInfo(format); |
| 1556 |
SkASSERT(ycbcrInfo); |
| 1557 |
|
| 1558 |
// All external formats have a valid ycbcrInfo used for sampling and a non zero external format. |
| 1559 |
if (ycbcrInfo->isValid() && ycbcrInfo->hasExternalFormat()) { |
| 1560 |
#ifdef SK_DEBUG |
| 1561 |
VkFormat vkFormat; |
| 1562 |
SkAssertResult(GrBackendFormats::AsVkFormat(format, &vkFormat)); |
| 1563 |
SkASSERT(vkFormat == VK_FORMAT_UNDEFINED); |
| 1564 |
#endif |
| 1565 |
return true; |
| 1566 |
} |
| 1567 |
return false; |
| 1568 |
} |
| 1569 |
|
| 1570 |
bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const { |
| 1571 |
VkFormat vkFormat; |
| 1572 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1573 |
return false; |
| 1574 |
} |
| 1575 |
if (backend_format_is_external(format)) { |
| 1576 |
return false; |
| 1577 |
} |
| 1578 |
|
| 1579 |
return format_is_srgb(vkFormat); |
| 1580 |
} |
| 1581 |
|
| 1582 |
bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { |
| 1583 |
VkFormat vkFormat; |
| 1584 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1585 |
return false; |
| 1586 |
} |
| 1587 |
if (backend_format_is_external(format)) { |
| 1588 |
// We can always texture from an external format (assuming we have the ycbcr conversion |
| 1589 |
// info which we require to be passed in). |
| 1590 |
return true; |
| 1591 |
} |
| 1592 |
return this->isVkFormatTexturable(vkFormat); |
| 1593 |
} |
| 1594 |
|
| 1595 |
bool GrVkCaps::isVkFormatTexturable(VkFormat format) const { |
| 1596 |
const FormatInfo& info = this->getFormatInfo(format); |
| 1597 |
return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags); |
| 1598 |
} |
| 1599 |
|
| 1600 |
bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 1601 |
int sampleCount) const { |
| 1602 |
if (!this->isFormatRenderable(format, sampleCount)) { |
| 1603 |
return false; |
| 1604 |
} |
| 1605 |
VkFormat vkFormat; |
| 1606 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1607 |
return false; |
| 1608 |
} |
| 1609 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1610 |
if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) { |
| 1611 |
return false; |
| 1612 |
} |
| 1613 |
return true; |
| 1614 |
} |
| 1615 |
|
| 1616 |
bool GrVkCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const { |
| 1617 |
VkFormat vkFormat; |
| 1618 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1619 |
return false; |
| 1620 |
} |
| 1621 |
return this->isFormatRenderable(vkFormat, sampleCount); |
| 1622 |
} |
| 1623 |
|
| 1624 |
bool GrVkCaps::isFormatRenderable(VkFormat format, int sampleCount) const { |
| 1625 |
return sampleCount <= this->maxRenderTargetSampleCount(format); |
| 1626 |
} |
| 1627 |
|
| 1628 |
int GrVkCaps::getRenderTargetSampleCount(int requestedCount, |
| 1629 |
const GrBackendFormat& format) const { |
| 1630 |
VkFormat vkFormat; |
| 1631 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1632 |
return 0; |
| 1633 |
} |
| 1634 |
|
| 1635 |
return this->getRenderTargetSampleCount(requestedCount, vkFormat); |
| 1636 |
} |
| 1637 |
|
| 1638 |
int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const { |
| 1639 |
requestedCount = std::max(1, requestedCount); |
| 1640 |
|
| 1641 |
const FormatInfo& info = this->getFormatInfo(format); |
| 1642 |
|
| 1643 |
int count = info.fColorSampleCounts.size(); |
| 1644 |
|
| 1645 |
if (!count) { |
| 1646 |
return 0; |
| 1647 |
} |
| 1648 |
|
| 1649 |
if (1 == requestedCount) { |
| 1650 |
SkASSERT(!info.fColorSampleCounts.empty() && info.fColorSampleCounts[0] == 1); |
| 1651 |
return 1; |
| 1652 |
} |
| 1653 |
|
| 1654 |
for (int i = 0; i < count; ++i) { |
| 1655 |
if (info.fColorSampleCounts[i] >= requestedCount) { |
| 1656 |
return info.fColorSampleCounts[i]; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
return 0; |
| 1660 |
} |
| 1661 |
|
| 1662 |
int GrVkCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
| 1663 |
VkFormat vkFormat; |
| 1664 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1665 |
return 0; |
| 1666 |
} |
| 1667 |
return this->maxRenderTargetSampleCount(vkFormat); |
| 1668 |
} |
| 1669 |
|
| 1670 |
int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const { |
| 1671 |
const FormatInfo& info = this->getFormatInfo(format); |
| 1672 |
|
| 1673 |
const auto& table = info.fColorSampleCounts; |
| 1674 |
if (table.empty()) { |
| 1675 |
return 0; |
| 1676 |
} |
| 1677 |
return table[table.size() - 1]; |
| 1678 |
} |
| 1679 |
|
| 1680 |
static inline size_t align_to_4(size_t v) { |
| 1681 |
switch (v & 0b11) { |
| 1682 |
// v is already a multiple of 4. |
| 1683 |
case 0: return v; |
| 1684 |
// v is a multiple of 2 but not 4. |
| 1685 |
case 2: return 2 * v; |
| 1686 |
// v is not a multiple of 2. |
| 1687 |
default: return 4 * v; |
| 1688 |
} |
| 1689 |
} |
| 1690 |
|
| 1691 |
GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfaceColorType, |
| 1692 |
const GrBackendFormat& surfaceFormat, |
| 1693 |
GrColorType srcColorType) const { |
| 1694 |
VkFormat vkFormat; |
| 1695 |
if (!GrBackendFormats::AsVkFormat(surfaceFormat, &vkFormat)) { |
| 1696 |
return {GrColorType::kUnknown, 0}; |
| 1697 |
} |
| 1698 |
|
| 1699 |
// We don't support the ability to upload to external formats or formats that require a ycbcr |
| 1700 |
// sampler. In general these types of formats are only used for sampling in a shader. |
| 1701 |
if (backend_format_is_external(surfaceFormat) || skgpu::VkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1702 |
return {GrColorType::kUnknown, 0}; |
| 1703 |
} |
| 1704 |
|
| 1705 |
// The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
| 1706 |
size_t offsetAlignment = align_to_4(skgpu::VkFormatBytesPerBlock(vkFormat)); |
| 1707 |
|
| 1708 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1709 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1710 |
const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1711 |
if (ctInfo.fColorType == surfaceColorType) { |
| 1712 |
return {ctInfo.fTransferColorType, offsetAlignment}; |
| 1713 |
} |
| 1714 |
} |
| 1715 |
return {GrColorType::kUnknown, 0}; |
| 1716 |
} |
| 1717 |
|
| 1718 |
GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels( |
| 1719 |
const GrSurface* surface) const { |
| 1720 |
if (surface->isProtected()) { |
| 1721 |
return SurfaceReadPixelsSupport::kUnsupported; |
| 1722 |
} |
| 1723 |
if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 1724 |
auto texImage = tex->textureImage(); |
| 1725 |
if (!texImage) { |
| 1726 |
return SurfaceReadPixelsSupport::kUnsupported; |
| 1727 |
} |
| 1728 |
// We can't directly read from a VkImage that has a ycbcr sampler. |
| 1729 |
if (texImage->ycbcrConversionInfo().isValid()) { |
| 1730 |
return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1731 |
} |
| 1732 |
// We can't directly read from a compressed format |
| 1733 |
if (skgpu::VkFormatIsCompressed(texImage->imageFormat())) { |
| 1734 |
return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1735 |
} |
| 1736 |
return SurfaceReadPixelsSupport::kSupported; |
| 1737 |
} else if (auto rt = surface->asRenderTarget()) { |
| 1738 |
if (rt->numSamples() > 1) { |
| 1739 |
return SurfaceReadPixelsSupport::kCopyToTexture2D; |
| 1740 |
} |
| 1741 |
return SurfaceReadPixelsSupport::kSupported; |
| 1742 |
} |
| 1743 |
return SurfaceReadPixelsSupport::kUnsupported; |
| 1744 |
} |
| 1745 |
|
| 1746 |
GrColorType GrVkCaps::transferColorType(VkFormat vkFormat, GrColorType surfaceColorType) const { |
| 1747 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1748 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1749 |
if (info.fColorTypeInfos[i].fColorType == surfaceColorType) { |
| 1750 |
return info.fColorTypeInfos[i].fTransferColorType; |
| 1751 |
} |
| 1752 |
} |
| 1753 |
return GrColorType::kUnknown; |
| 1754 |
} |
| 1755 |
|
| 1756 |
bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const { |
| 1757 |
if (auto rt = surface->asRenderTarget()) { |
| 1758 |
return rt->numSamples() <= 1 && SkToBool(surface->asTexture()); |
| 1759 |
} |
| 1760 |
// We can't write to a texture that has a ycbcr sampler. |
| 1761 |
if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { |
| 1762 |
auto texImage = tex->textureImage(); |
| 1763 |
if (!texImage) { |
| 1764 |
return false; |
| 1765 |
} |
| 1766 |
// We can't directly read from a VkImage that has a ycbcr sampler. |
| 1767 |
if (texImage->ycbcrConversionInfo().isValid()) { |
| 1768 |
return false; |
| 1769 |
} |
| 1770 |
} |
| 1771 |
return true; |
| 1772 |
} |
| 1773 |
|
| 1774 |
bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 1775 |
const GrBackendFormat& format) const { |
| 1776 |
VkFormat vkFormat; |
| 1777 |
if (!GrBackendFormats::AsVkFormat(format, &vkFormat)) { |
| 1778 |
return false; |
| 1779 |
} |
| 1780 |
const skgpu::VulkanYcbcrConversionInfo* ycbcrInfo = |
| 1781 |
GrBackendFormats::GetVkYcbcrConversionInfo(format); |
| 1782 |
SkASSERT(ycbcrInfo); |
| 1783 |
|
| 1784 |
if (ycbcrInfo->isValid() && !skgpu::VkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1785 |
// Format may be undefined for external images, which are required to have YCbCr conversion. |
| 1786 |
if (VK_FORMAT_UNDEFINED == vkFormat && ycbcrInfo->hasExternalFormat()) { |
| 1787 |
return true; |
| 1788 |
} |
| 1789 |
return false; |
| 1790 |
} |
| 1791 |
|
| 1792 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1793 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1794 |
if (info.fColorTypeInfos[i].fColorType == ct) { |
| 1795 |
return true; |
| 1796 |
} |
| 1797 |
} |
| 1798 |
return false; |
| 1799 |
} |
| 1800 |
|
| 1801 |
GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct) const { |
| 1802 |
VkFormat format = this->getFormatFromColorType(ct); |
| 1803 |
if (format == VK_FORMAT_UNDEFINED) { |
| 1804 |
return {}; |
| 1805 |
} |
| 1806 |
return GrBackendFormats::MakeVk(format); |
| 1807 |
} |
| 1808 |
|
| 1809 |
bool GrVkCaps::onSupportsDynamicMSAA(const GrRenderTargetProxy* rtProxy) const { |
| 1810 |
// We must be able to use the rtProxy as an input attachment to load into the discardable msaa |
| 1811 |
// attachment. Also the rtProxy should have a sample count of 1 so that it can be used as a |
| 1812 |
// resolve attachment. |
| 1813 |
return this->supportsDiscardableMSAAForDMSAA() && |
| 1814 |
rtProxy->supportsVkInputAttachment() && |
| 1815 |
rtProxy->numSamples() == 1; |
| 1816 |
} |
| 1817 |
|
| 1818 |
bool GrVkCaps::renderTargetSupportsDiscardableMSAA(const GrVkRenderTarget* rt) const { |
| 1819 |
return rt->resolveAttachment() && |
| 1820 |
rt->resolveAttachment()->supportsInputAttachmentUsage() && |
| 1821 |
((rt->numSamples() > 1 && this->preferDiscardableMSAAAttachment()) || |
| 1822 |
(rt->numSamples() == 1 && this->supportsDiscardableMSAAForDMSAA())); |
| 1823 |
} |
| 1824 |
|
| 1825 |
bool GrVkCaps::programInfoWillUseDiscardableMSAA(const GrProgramInfo& programInfo) const { |
| 1826 |
return programInfo.targetHasVkResolveAttachmentWithInput() && |
| 1827 |
programInfo.numSamples() > 1 && |
| 1828 |
((programInfo.targetsNumSamples() > 1 && this->preferDiscardableMSAAAttachment()) || |
| 1829 |
(programInfo.targetsNumSamples() == 1 && this->supportsDiscardableMSAAForDMSAA())); |
| 1830 |
} |
| 1831 |
|
| 1832 |
GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType( |
| 1833 |
SkTextureCompressionType compressionType) const { |
| 1834 |
switch (compressionType) { |
| 1835 |
case SkTextureCompressionType::kNone: |
| 1836 |
return {}; |
| 1837 |
case SkTextureCompressionType::kETC2_RGB8_UNORM: |
| 1838 |
if (this->isVkFormatTexturable(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)) { |
| 1839 |
return GrBackendFormats::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK); |
| 1840 |
} |
| 1841 |
return {}; |
| 1842 |
case SkTextureCompressionType::kBC1_RGB8_UNORM: |
| 1843 |
if (this->isVkFormatTexturable(VK_FORMAT_BC1_RGB_UNORM_BLOCK)) { |
| 1844 |
return GrBackendFormats::MakeVk(VK_FORMAT_BC1_RGB_UNORM_BLOCK); |
| 1845 |
} |
| 1846 |
return {}; |
| 1847 |
case SkTextureCompressionType::kBC1_RGBA8_UNORM: |
| 1848 |
if (this->isVkFormatTexturable(VK_FORMAT_BC1_RGBA_UNORM_BLOCK)) { |
| 1849 |
return GrBackendFormats::MakeVk(VK_FORMAT_BC1_RGBA_UNORM_BLOCK); |
| 1850 |
} |
| 1851 |
return {}; |
| 1852 |
} |
| 1853 |
|
| 1854 |
SkUNREACHABLE; |
| 1855 |
} |
| 1856 |
|
| 1857 |
skgpu::Swizzle GrVkCaps::onGetReadSwizzle(const GrBackendFormat& format, |
| 1858 |
GrColorType colorType) const { |
| 1859 |
VkFormat vkFormat; |
| 1860 |
SkAssertResult(GrBackendFormats::AsVkFormat(format, &vkFormat)); |
| 1861 |
const skgpu::VulkanYcbcrConversionInfo* ycbcrInfo = |
| 1862 |
GrBackendFormats::GetVkYcbcrConversionInfo(format); |
| 1863 |
SkASSERT(ycbcrInfo); |
| 1864 |
if (ycbcrInfo->isValid() && ycbcrInfo->hasExternalFormat()) { |
| 1865 |
// We allow these to work with any color type and never swizzle. See |
| 1866 |
// onAreColorTypeAndFormatCompatible. |
| 1867 |
return skgpu::Swizzle{"rgba"}; |
| 1868 |
} |
| 1869 |
|
| 1870 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1871 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1872 |
const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1873 |
if (ctInfo.fColorType == colorType) { |
| 1874 |
return ctInfo.fReadSwizzle; |
| 1875 |
} |
| 1876 |
} |
| 1877 |
SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", |
| 1878 |
(int)colorType, (int)vkFormat); |
| 1879 |
return {}; |
| 1880 |
} |
| 1881 |
|
| 1882 |
skgpu::Swizzle GrVkCaps::getWriteSwizzle(const GrBackendFormat& format, |
| 1883 |
GrColorType colorType) const { |
| 1884 |
VkFormat vkFormat; |
| 1885 |
SkAssertResult(GrBackendFormats::AsVkFormat(format, &vkFormat)); |
| 1886 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1887 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1888 |
const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1889 |
if (ctInfo.fColorType == colorType) { |
| 1890 |
return ctInfo.fWriteSwizzle; |
| 1891 |
} |
| 1892 |
} |
| 1893 |
SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", |
| 1894 |
(int)colorType, (int)vkFormat); |
| 1895 |
return {}; |
| 1896 |
} |
| 1897 |
|
| 1898 |
GrDstSampleFlags GrVkCaps::onGetDstSampleFlagsForProxy(const GrRenderTargetProxy* rt) const { |
| 1899 |
bool isMSAAWithResolve = rt->numSamples() > 1 && rt->asTextureProxy(); |
| 1900 |
// TODO: Currently if we have an msaa rt with a resolve, the supportsVkInputAttachment call |
| 1901 |
// references whether the resolve is supported as an input attachment. We need to add a check to |
| 1902 |
// allow checking the color attachment (msaa or not) supports input attachment specifically. |
| 1903 |
if (!isMSAAWithResolve && rt->supportsVkInputAttachment()) { |
| 1904 |
return GrDstSampleFlags::kRequiresTextureBarrier | GrDstSampleFlags::kAsInputAttachment; |
| 1905 |
} |
| 1906 |
return GrDstSampleFlags::kNone; |
| 1907 |
} |
| 1908 |
|
| 1909 |
uint64_t GrVkCaps::computeFormatKey(const GrBackendFormat& format) const { |
| 1910 |
VkFormat vkFormat; |
| 1911 |
SkAssertResult(GrBackendFormats::AsVkFormat(format, &vkFormat)); |
| 1912 |
|
| 1913 |
#ifdef SK_DEBUG |
| 1914 |
// We should never be trying to compute a key for an external format |
| 1915 |
const skgpu::VulkanYcbcrConversionInfo* ycbcrInfo = |
| 1916 |
GrBackendFormats::GetVkYcbcrConversionInfo(format); |
| 1917 |
SkASSERT(ycbcrInfo); |
| 1918 |
SkASSERT(!ycbcrInfo->isValid() || !ycbcrInfo->hasExternalFormat()); |
| 1919 |
#endif |
| 1920 |
|
| 1921 |
// A VkFormat has a size of 64 bits. |
| 1922 |
return (uint64_t)vkFormat; |
| 1923 |
} |
| 1924 |
|
| 1925 |
GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType( |
| 1926 |
GrColorType srcColorType, const GrBackendFormat& srcBackendFormat, |
| 1927 |
GrColorType dstColorType) const { |
| 1928 |
VkFormat vkFormat; |
| 1929 |
if (!GrBackendFormats::AsVkFormat(srcBackendFormat, &vkFormat)) { |
| 1930 |
return {GrColorType::kUnknown, 0}; |
| 1931 |
} |
| 1932 |
|
| 1933 |
if (skgpu::VkFormatNeedsYcbcrSampler(vkFormat)) { |
| 1934 |
return {GrColorType::kUnknown, 0}; |
| 1935 |
} |
| 1936 |
|
| 1937 |
SkTextureCompressionType compression = GrBackendFormatToCompressionType(srcBackendFormat); |
| 1938 |
if (compression != SkTextureCompressionType::kNone) { |
| 1939 |
return { SkTextureCompressionTypeIsOpaque(compression) ? GrColorType::kRGB_888x |
| 1940 |
: GrColorType::kRGBA_8888, 0 }; |
| 1941 |
} |
| 1942 |
|
| 1943 |
// The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel. |
| 1944 |
size_t offsetAlignment = align_to_4(skgpu::VkFormatBytesPerBlock(vkFormat)); |
| 1945 |
|
| 1946 |
const auto& info = this->getFormatInfo(vkFormat); |
| 1947 |
for (int i = 0; i < info.fColorTypeInfoCount; ++i) { |
| 1948 |
const auto& ctInfo = info.fColorTypeInfos[i]; |
| 1949 |
if (ctInfo.fColorType == srcColorType) { |
| 1950 |
return {ctInfo.fTransferColorType, offsetAlignment}; |
| 1951 |
} |
| 1952 |
} |
| 1953 |
return {GrColorType::kUnknown, 0}; |
| 1954 |
} |
| 1955 |
|
| 1956 |
int GrVkCaps::getFragmentUniformBinding() const { |
| 1957 |
return GrVkUniformHandler::kUniformBinding; |
| 1958 |
} |
| 1959 |
|
| 1960 |
int GrVkCaps::getFragmentUniformSet() const { |
| 1961 |
return GrVkUniformHandler::kUniformBufferDescSet; |
| 1962 |
} |
| 1963 |
|
| 1964 |
void GrVkCaps::addExtraSamplerKey(skgpu::KeyBuilder* b, |
| 1965 |
GrSamplerState samplerState, |
| 1966 |
const GrBackendFormat& format) const { |
| 1967 |
const skgpu::VulkanYcbcrConversionInfo* ycbcrInfo = |
| 1968 |
GrBackendFormats::GetVkYcbcrConversionInfo(format); |
| 1969 |
if (!ycbcrInfo) { |
| 1970 |
return; |
| 1971 |
} |
| 1972 |
|
| 1973 |
GrVkSampler::Key key = GrVkSampler::GenerateKey(samplerState, *ycbcrInfo); |
| 1974 |
|
| 1975 |
constexpr size_t numInts = (sizeof(key) + 3) / 4; |
| 1976 |
uint32_t tmp[numInts]; |
| 1977 |
memcpy(tmp, &key, sizeof(key)); |
| 1978 |
|
| 1979 |
for (size_t i = 0; i < numInts; ++i) { |
| 1980 |
b->add32(tmp[i]); |
| 1981 |
} |
| 1982 |
} |
| 1983 |
|
| 1984 |
/** |
| 1985 |
* For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all |
| 1986 |
* the information needed to differentiate one pipeline from another. |
| 1987 |
* |
| 1988 |
* The GrProgramDesc contains all the information need to create the actual shaders for the |
| 1989 |
* pipeline. |
| 1990 |
* |
| 1991 |
* For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the |
| 1992 |
* pipline. This includes stencil settings, blending information, render pass format, draw face |
| 1993 |
* information, and primitive type. Note that some state is set dynamically on the pipeline for |
| 1994 |
* each draw and thus is not included in this descriptor. This includes the viewport, scissor, |
| 1995 |
* and blend constant. |
| 1996 |
*/ |
| 1997 |
GrProgramDesc GrVkCaps::makeDesc(GrRenderTarget* rt, |
| 1998 |
const GrProgramInfo& programInfo, |
| 1999 |
ProgramDescOverrideFlags overrideFlags) const { |
| 2000 |
GrProgramDesc desc; |
| 2001 |
GrProgramDesc::Build(&desc, programInfo, *this); |
| 2002 |
|
| 2003 |
skgpu::KeyBuilder b(desc.key()); |
| 2004 |
|
| 2005 |
// This will become part of the sheared off key used to persistently cache |
| 2006 |
// the SPIRV code. It needs to be added right after the base key so that, |
| 2007 |
// when the base-key is sheared off, the shearing code can include it in the |
| 2008 |
// reduced key (c.f. the +4s in the SkData::MakeWithCopy calls in |
| 2009 |
// GrVkPipelineStateBuilder.cpp). |
| 2010 |
b.add32(GrVkGpu::kShader_PersistentCacheKeyType); |
| 2011 |
|
| 2012 |
GrVkRenderPass::SelfDependencyFlags selfDepFlags = GrVkRenderPass::SelfDependencyFlags::kNone; |
| 2013 |
if (programInfo.renderPassBarriers() & GrXferBarrierFlags::kBlend) { |
| 2014 |
selfDepFlags |= GrVkRenderPass::SelfDependencyFlags::kForNonCoherentAdvBlend; |
| 2015 |
} |
| 2016 |
if (programInfo.renderPassBarriers() & GrXferBarrierFlags::kTexture) { |
| 2017 |
selfDepFlags |= GrVkRenderPass::SelfDependencyFlags::kForInputAttachment; |
| 2018 |
} |
| 2019 |
|
| 2020 |
bool needsResolve = this->programInfoWillUseDiscardableMSAA(programInfo); |
| 2021 |
|
| 2022 |
bool forceLoadFromResolve = |
| 2023 |
overrideFlags & GrCaps::ProgramDescOverrideFlags::kVulkanHasResolveLoadSubpass; |
| 2024 |
SkASSERT(!forceLoadFromResolve || needsResolve); |
| 2025 |
|
| 2026 |
GrVkRenderPass::LoadFromResolve loadFromResolve = GrVkRenderPass::LoadFromResolve::kNo; |
| 2027 |
if (needsResolve && (programInfo.colorLoadOp() == GrLoadOp::kLoad || forceLoadFromResolve)) { |
| 2028 |
loadFromResolve = GrVkRenderPass::LoadFromResolve::kLoad; |
| 2029 |
} |
| 2030 |
|
| 2031 |
if (rt) { |
| 2032 |
GrVkRenderTarget* vkRT = (GrVkRenderTarget*) rt; |
| 2033 |
|
| 2034 |
SkASSERT(!needsResolve || (vkRT->resolveAttachment() && |
| 2035 |
vkRT->resolveAttachment()->supportsInputAttachmentUsage())); |
| 2036 |
|
| 2037 |
bool needsStencil = programInfo.needsStencil() || programInfo.isStencilEnabled(); |
| 2038 |
// TODO: support failure in getSimpleRenderPass |
| 2039 |
auto rp = vkRT->getSimpleRenderPass(needsResolve, needsStencil, selfDepFlags, |
| 2040 |
loadFromResolve); |
| 2041 |
SkASSERT(rp); |
| 2042 |
rp->genKey(&b); |
| 2043 |
|
| 2044 |
#ifdef SK_DEBUG |
| 2045 |
if (!rp->isExternal()) { |
| 2046 |
// This is to ensure ReconstructAttachmentsDescriptor keeps matching |
| 2047 |
// getSimpleRenderPass' result |
| 2048 |
GrVkRenderPass::AttachmentsDescriptor attachmentsDescriptor; |
| 2049 |
GrVkRenderPass::AttachmentFlags attachmentFlags; |
| 2050 |
GrVkRenderTarget::ReconstructAttachmentsDescriptor(*this, programInfo, |
| 2051 |
&attachmentsDescriptor, |
| 2052 |
&attachmentFlags); |
| 2053 |
SkASSERT(rp->isCompatible(attachmentsDescriptor, attachmentFlags, selfDepFlags, |
| 2054 |
loadFromResolve)); |
| 2055 |
} |
| 2056 |
#endif |
| 2057 |
} else { |
| 2058 |
GrVkRenderPass::AttachmentsDescriptor attachmentsDescriptor; |
| 2059 |
GrVkRenderPass::AttachmentFlags attachmentFlags; |
| 2060 |
GrVkRenderTarget::ReconstructAttachmentsDescriptor(*this, programInfo, |
| 2061 |
&attachmentsDescriptor, |
| 2062 |
&attachmentFlags); |
| 2063 |
|
| 2064 |
// kExternal_AttachmentFlag is only set for wrapped secondary command buffers - which |
| 2065 |
// will always go through the above 'rt' path (i.e., we can always pass 0 as the final |
| 2066 |
// parameter to GenKey). |
| 2067 |
GrVkRenderPass::GenKey(&b, attachmentFlags, attachmentsDescriptor, selfDepFlags, |
| 2068 |
loadFromResolve, 0); |
| 2069 |
} |
| 2070 |
|
| 2071 |
GrStencilSettings stencil = programInfo.nonGLStencilSettings(); |
| 2072 |
stencil.genKey(&b, true); |
| 2073 |
|
| 2074 |
programInfo.pipeline().genKey(&b, *this); |
| 2075 |
b.add32(programInfo.numSamples()); |
| 2076 |
|
| 2077 |
// Vulkan requires the full primitive type as part of its key |
| 2078 |
b.add32(programInfo.primitiveTypeKey()); |
| 2079 |
|
| 2080 |
b.flush(); |
| 2081 |
return desc; |
| 2082 |
} |
| 2083 |
|
| 2084 |
GrInternalSurfaceFlags GrVkCaps::getExtraSurfaceFlagsForDeferredRT() const { |
| 2085 |
// We always create vulkan RT with the input attachment flag; |
| 2086 |
return GrInternalSurfaceFlags::kVkRTSupportsInputAttachment; |
| 2087 |
} |
| 2088 |
|
| 2089 |
VkShaderStageFlags GrVkCaps::getPushConstantStageFlags() const { |
| 2090 |
VkShaderStageFlags stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; |
| 2091 |
return stageFlags; |
| 2092 |
} |
| 2093 |
|
| 2094 |
GrVkCaps::IntelGPUType GrVkCaps::GetIntelGPUType(uint32_t deviceID) { |
| 2095 |
// Some common Intel GPU models, currently we cover SKL, ICL, JSL, and Gen12+ up to PTL. |
| 2096 |
// Referenced from the following Mesa source file: |
| 2097 |
// https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/include/pci_ids/iris_pci_ids.h |
| 2098 |
// |
| 2099 |
// Generally, only the top two bytes define the GPU type. MTL/ARL are an uncommon exception. |
| 2100 |
switch (deviceID & 0xFF00) { |
| 2101 |
case 0x1900: |
| 2102 |
return IntelGPUType::kSkyLake; |
| 2103 |
case 0x8A00: |
| 2104 |
return IntelGPUType::kIceLake; |
| 2105 |
case 0x4E00: |
| 2106 |
return IntelGPUType::kJasperLake; |
| 2107 |
case 0x4C00: |
| 2108 |
return IntelGPUType::kRocketLake; |
| 2109 |
case 0x9A00: |
| 2110 |
return IntelGPUType::kTigerLake; |
| 2111 |
case 0x4600: |
| 2112 |
return IntelGPUType::kAlderLake; |
| 2113 |
case 0xA700: |
| 2114 |
return IntelGPUType::kRaptorLake; |
| 2115 |
case 0xB600: |
| 2116 |
return IntelGPUType::kArrowLake; |
| 2117 |
case 0x5600: |
| 2118 |
return IntelGPUType::kAlchemist; |
| 2119 |
case 0x6400: |
| 2120 |
return IntelGPUType::kLunarLake; |
| 2121 |
case 0xE200: |
| 2122 |
return IntelGPUType::kBattlemage; |
| 2123 |
case 0xB000: |
| 2124 |
return IntelGPUType::kPantherLake; |
| 2125 |
case 0x7D00: |
| 2126 |
if (deviceID == 0x7D41 || deviceID == 0x7D51 || deviceID == 0x7D67 || |
| 2127 |
deviceID == 0x7DD1) { |
| 2128 |
return IntelGPUType::kArrowLake; |
| 2129 |
} |
| 2130 |
return IntelGPUType::kMeteorLake; |
| 2131 |
} |
| 2132 |
return IntelGPUType::kOther; |
| 2133 |
} |
| 2134 |
|
| 2135 |
#if defined(GPU_TEST_UTILS) |
| 2136 |
std::vector<GrTest::TestFormatColorTypeCombination> GrVkCaps::getTestingCombinations() const { |
| 2137 |
std::vector<GrTest::TestFormatColorTypeCombination> combos = { |
| 2138 |
{ GrColorType::kAlpha_8, GrBackendFormats::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 2139 |
{ GrColorType::kBGR_565, GrBackendFormats::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16) }, |
| 2140 |
{ GrColorType::kRGB_565, GrBackendFormats::MakeVk(VK_FORMAT_B5G6R5_UNORM_PACK16) }, |
| 2141 |
{ GrColorType::kABGR_4444, GrBackendFormats::MakeVk(VK_FORMAT_R4G4B4A4_UNORM_PACK16)}, |
| 2142 |
{ GrColorType::kABGR_4444, GrBackendFormats::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16)}, |
| 2143 |
{ GrColorType::kRGBA_8888, GrBackendFormats::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 2144 |
{ GrColorType::kRGBA_8888_SRGB, GrBackendFormats::MakeVk(VK_FORMAT_R8G8B8A8_SRGB) }, |
| 2145 |
{ GrColorType::kRGB_888x, GrBackendFormats::MakeVk(VK_FORMAT_R8G8B8A8_UNORM) }, |
| 2146 |
{ GrColorType::kRGB_888x, GrBackendFormats::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) }, |
| 2147 |
{ GrColorType::kRGB_888x, GrBackendFormats::MakeVk(VK_FORMAT_R8G8B8_UNORM) }, |
| 2148 |
{ GrColorType::kR_8, GrBackendFormats::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 2149 |
{ GrColorType::kRG_88, GrBackendFormats::MakeVk(VK_FORMAT_R8G8_UNORM) }, |
| 2150 |
{ GrColorType::kBGRA_8888, GrBackendFormats::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) }, |
| 2151 |
{ GrColorType::kRGBA_1010102, GrBackendFormats::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)}, |
| 2152 |
{ GrColorType::kBGRA_1010102, GrBackendFormats::MakeVk(VK_FORMAT_A2R10G10B10_UNORM_PACK32)}, |
| 2153 |
{ GrColorType::kRGB_101010x, GrBackendFormats::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)}, |
| 2154 |
{ GrColorType::kRGBA_10x6, |
| 2155 |
GrBackendFormats::MakeVk(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16)}, |
| 2156 |
{ GrColorType::kGray_8, GrBackendFormats::MakeVk(VK_FORMAT_R8_UNORM) }, |
| 2157 |
{ GrColorType::kAlpha_F16, GrBackendFormats::MakeVk(VK_FORMAT_R16_SFLOAT) }, |
| 2158 |
{ GrColorType::kRGBA_F16, GrBackendFormats::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 2159 |
{ GrColorType::kRGBA_F16_Clamped, GrBackendFormats::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 2160 |
{ GrColorType::kRGB_F16F16F16x, GrBackendFormats::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) }, |
| 2161 |
{ GrColorType::kAlpha_16, GrBackendFormats::MakeVk(VK_FORMAT_R16_UNORM) }, |
| 2162 |
{ GrColorType::kR_16, GrBackendFormats::MakeVk(VK_FORMAT_R16_UNORM) }, |
| 2163 |
{ GrColorType::kRG_1616, GrBackendFormats::MakeVk(VK_FORMAT_R16G16_UNORM) }, |
| 2164 |
{ GrColorType::kRGBA_16161616, GrBackendFormats::MakeVk(VK_FORMAT_R16G16B16A16_UNORM) }, |
| 2165 |
{ GrColorType::kRG_F16, GrBackendFormats::MakeVk(VK_FORMAT_R16G16_SFLOAT) }, |
| 2166 |
// These two compressed formats both have an effective colorType of kRGB_888x |
| 2167 |
{ GrColorType::kRGB_888x, GrBackendFormats::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)}, |
| 2168 |
{ GrColorType::kRGB_888x, GrBackendFormats::MakeVk(VK_FORMAT_BC1_RGB_UNORM_BLOCK) }, |
| 2169 |
{ GrColorType::kRGBA_8888, GrBackendFormats::MakeVk(VK_FORMAT_BC1_RGBA_UNORM_BLOCK)}, |
| 2170 |
}; |
| 2171 |
|
| 2172 |
return combos; |
| 2173 |
} |
| 2174 |
#endif |