29 this->initGPUFamily(
device);
31 this->initShaderCaps();
33 this->initFormatTable();
41bool MtlCaps::GetGPUFamilyFromFeatureSet(id<MTLDevice>
device, GPUFamily* gpuFamily,
int* group) {
43#if SKGPU_GRAPHITE_METAL_SDK_VERSION < 300
45#if defined(SK_BUILD_FOR_MAC)
47 *gpuFamily = GPUFamily::kMac;
49 if (@available(macOS 10.14, *)) {
50 if ([
device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily2_v1]) {
54 if ([
device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v4]) {
60 if (@available(macOS 10.13, *)) {
61 if ([
device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v3]) {
67 if (@available(macOS 10.12, *)) {
68 if ([
device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2]) {
74 if (@available(macOS 10.11, *)) {
75 if ([
device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
80#elif defined(SK_BUILD_FOR_IOS)
82 *gpuFamily = GPUFamily::kApple;
84 if (@available(iOS 12.0, tvOS 12.0, *)) {
85 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily5_v1]) {
89 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v2]) {
93 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v4]) {
97 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v5]) {
101 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v5]) {
107 if (@available(iOS 11.0, tvOS 11.0, *)) {
108 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1]) {
112 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v3]) {
116 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v4]) {
120 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v4]) {
126 if (@available(iOS 10.0, tvOS 10.0, *)) {
127 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2]) {
131 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v3]) {
135 if ([
device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3]) {
149bool MtlCaps::GetGPUFamily(id<MTLDevice>
device, GPUFamily* gpuFamily,
int* group) {
150#if SKGPU_GRAPHITE_METAL_SDK_VERSION >= 220
151 if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
153#if SKGPU_GRAPHITE_METAL_SDK_VERSION >= 230
154 if ([
device supportsFamily:MTLGPUFamilyApple7]) {
155 *gpuFamily = GPUFamily::kApple;
160#ifdef SK_BUILD_FOR_IOS
161 if ([
device supportsFamily:MTLGPUFamilyApple6]) {
162 *gpuFamily = GPUFamily::kApple;
166 if ([
device supportsFamily:MTLGPUFamilyApple5]) {
167 *gpuFamily = GPUFamily::kApple;
171 if ([
device supportsFamily:MTLGPUFamilyApple4]) {
172 *gpuFamily = GPUFamily::kApple;
176 if ([
device supportsFamily:MTLGPUFamilyApple3]) {
177 *gpuFamily = GPUFamily::kApple;
181 if ([
device supportsFamily:MTLGPUFamilyApple2]) {
182 *gpuFamily = GPUFamily::kApple;
186 if ([
device supportsFamily:MTLGPUFamilyApple1]) {
187 *gpuFamily = GPUFamily::kApple;
194#if SKGPU_GRAPHITE_METAL_SDK_VERSION >= 300
197 *gpuFamily = GPUFamily::kMac;
203 if ([
device supportsFamily:MTLGPUFamilyMac2] ||
204 [
device supportsFamily:MTLGPUFamilyMacCatalyst2]) {
205 *gpuFamily = GPUFamily::kMac;
209 if ([
device supportsFamily:MTLGPUFamilyMac1] ||
210 [
device supportsFamily:MTLGPUFamilyMacCatalyst1]) {
211 *gpuFamily = GPUFamily::kMac;
223void MtlCaps::initGPUFamily(id<MTLDevice>
device) {
224 if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
225 if (GetGPUFamily(
device, &fGPUFamily, &fFamilyGroup)) {
229 if (GetGPUFamilyFromFeatureSet(
device, &fGPUFamily, &fFamilyGroup)) {
235#ifdef SK_BUILD_FOR_MAC
236 fGPUFamily = GPUFamily::kMac;
239 fGPUFamily = GPUFamily::kApple;
244void MtlCaps::initCaps(
const id<MTLDevice>
device) {
245#if defined(GRAPHITE_TEST_UTILS)
246 this->setDeviceName([[
device name] UTF8String]);
249 if (this->
isMac() || fFamilyGroup >= 3) {
281 if (@available(macOS 10.12, iOS 14.0, tvOS 14.0, *)) {
288 fColorSampleCounts.push_back(1);
289 if (![
device.name containsString:
@"Intel"]) {
290 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
291 for (
auto sampleCnt : {2, 4, 8}) {
292 if ([
device supportsTextureSampleCount:sampleCnt]) {
293 fColorSampleCounts.push_back(sampleCnt);
300void MtlCaps::initShaderCaps() {
304 if (@available(macOS 10.12, iOS 10.0, tvOS 10.0, *)) {
316 if (@available(macOS 11.0, *)) {
333#define kMTLPixelFormatB5G6R5Unorm MTLPixelFormat(40)
334#define kMTLPixelFormatABGR4Unorm MTLPixelFormat(42)
335#define kMTLPixelFormatETC2_RGB8 MTLPixelFormat(180)
340 MTLPixelFormatRGBA8Unorm,
341 MTLPixelFormatR8Unorm,
342 MTLPixelFormatA8Unorm,
343 MTLPixelFormatBGRA8Unorm,
345 MTLPixelFormatRGBA16Float,
346 MTLPixelFormatR16Float,
347 MTLPixelFormatRG8Unorm,
348 MTLPixelFormatRGB10A2Unorm,
351 MTLPixelFormatRGBA8Unorm_sRGB,
352 MTLPixelFormatR16Unorm,
353 MTLPixelFormatRG16Unorm,
355#ifdef SK_BUILD_FOR_MAC
356 MTLPixelFormatBC1_RGBA,
358 MTLPixelFormatRGBA16Unorm,
359 MTLPixelFormatRG16Float,
361 MTLPixelFormatStencil8,
362 MTLPixelFormatDepth32Float,
363 MTLPixelFormatDepth32Float_Stencil8,
365 MTLPixelFormatInvalid,
368void MtlCaps::setColorType(
SkColorType colorType, std::initializer_list<MTLPixelFormat> formats) {
370 for (
auto it = formats.begin(); it != formats.end(); ++it) {
371 const auto&
info = this->getFormatInfo(*it);
372 for (
int i = 0; i <
info.fColorTypeInfoCount; ++i) {
374 fColorTypeToFormatTable[idx] = *it;
381size_t MtlCaps::GetFormatIndex(MTLPixelFormat pixelFormat) {
382 static_assert(std::size(
kMtlFormats) == MtlCaps::kNumMtlFormats,
383 "Size of kMtlFormats array must match static value in header");
384 for (
size_t i = 0; i < MtlCaps::kNumMtlFormats; ++i) {
389 return GetFormatIndex(MTLPixelFormatInvalid);
392void MtlCaps::initFormatTable() {
395 if (@available(macOS 11.0, iOS 8.0, tvOS 9.0, *)) {
404 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRGBA8Unorm)];
405 info->fFlags = FormatInfo::kAllFlags;
406 info->fColorTypeInfoCount = 2;
407 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
411 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
413 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
417 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
419 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
426 info = &fFormatTable[GetFormatIndex(MTLPixelFormatR8Unorm)];
427 info->fFlags = FormatInfo::kAllFlags;
428 info->fColorTypeInfoCount = 3;
429 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
433 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
435 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
439 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
441 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
447 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
449 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
456 info = &fFormatTable[GetFormatIndex(MTLPixelFormatA8Unorm)];
457 info->fFlags = FormatInfo::kTexturable_Flag;
458 info->fColorTypeInfoCount = 1;
459 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
463 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
465 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
471 info = &fFormatTable[GetFormatIndex(MTLPixelFormatBGRA8Unorm)];
472 info->fFlags = FormatInfo::kAllFlags;
473 info->fColorTypeInfoCount = 1;
474 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
478 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
480 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
484 if (@available(macOS 11.0, iOS 8.0, tvOS 9.0, *)) {
488 info = &fFormatTable[GetFormatIndex(MTLPixelFormatB5G6R5Unorm)];
489 info->fFlags = FormatInfo::kAllFlags;
490 info->fColorTypeInfoCount = 1;
491 info->fColorTypeInfos =
492 std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
496 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
498 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag |
499 ColorTypeInfo::kRenderable_Flag;
505 info = &fFormatTable[GetFormatIndex(MTLPixelFormatABGR4Unorm)];
506 info->fFlags = FormatInfo::kAllFlags;
507 info->fColorTypeInfoCount = 1;
508 info->fColorTypeInfos =
509 std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
513 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
515 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag |
516 ColorTypeInfo::kRenderable_Flag;
524 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRGBA8Unorm_sRGB)];
525 info->fFlags = FormatInfo::kAllFlags;
526 info->fColorTypeInfoCount = 1;
527 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
531 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
533 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
539 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRGB10A2Unorm)];
540 if (this->
isMac() || fFamilyGroup >= 3) {
541 info->fFlags = FormatInfo::kAllFlags;
543 info->fFlags = FormatInfo::kTexturable_Flag;
545 info->fColorTypeInfoCount = 1;
546 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
550 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
552 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
558 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRGBA16Float)];
559 info->fFlags = FormatInfo::kAllFlags;
560 info->fColorTypeInfoCount = 2;
561 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
565 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
567 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
571 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
573 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
579 info = &fFormatTable[GetFormatIndex(MTLPixelFormatR16Float)];
580 info->fFlags = FormatInfo::kAllFlags;
581 info->fColorTypeInfoCount = 1;
582 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
586 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
588 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
596 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRG8Unorm)];
597 info->fFlags = FormatInfo::kAllFlags;
598 info->fColorTypeInfoCount = 1;
599 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
603 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
605 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
611 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRGBA16Unorm)];
613 info->fFlags = FormatInfo::kAllFlags;
615 info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag;
617 info->fColorTypeInfoCount = 1;
618 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
622 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
624 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
630 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRG16Float)];
631 info->fFlags = FormatInfo::kAllFlags;
632 info->fColorTypeInfoCount = 1;
633 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
637 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
639 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
645 info = &fFormatTable[GetFormatIndex(MTLPixelFormatR16Unorm)];
647 info->fFlags = FormatInfo::kAllFlags;
649 info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag;
651 info->fColorTypeInfoCount = 1;
652 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
656 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
658 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
666 info = &fFormatTable[GetFormatIndex(MTLPixelFormatRG16Unorm)];
668 info->fFlags = FormatInfo::kAllFlags;
670 info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag;
672 info->fColorTypeInfoCount = 1;
673 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
677 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
679 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
685 if (@available(macOS 11.0, iOS 8.0, tvOS 9.0, *)) {
687 info = &fFormatTable[GetFormatIndex(MTLPixelFormatETC2_RGB8)];
688 info->fFlags = FormatInfo::kTexturable_Flag;
689 info->fColorTypeInfoCount = 1;
690 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
694 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
696 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
704#ifdef SK_BUILD_FOR_MAC
706 info = &fFormatTable[GetFormatIndex(MTLPixelFormatBC1_RGBA)];
707 info->fFlags = FormatInfo::kTexturable_Flag;
708 info->fColorTypeInfoCount = 1;
709 info->fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(
info->fColorTypeInfoCount);
713 auto& ctInfo =
info->fColorTypeInfos[ctIdx++];
715 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
727 info = &fFormatTable[GetFormatIndex(MTLPixelFormatStencil8)];
728 info->fFlags = FormatInfo::kMSAA_Flag;
729 info->fColorTypeInfoCount = 0;
734 info = &fFormatTable[GetFormatIndex(MTLPixelFormatDepth32Float)];
735 info->fFlags = FormatInfo::kMSAA_Flag;
736 if (this->
isMac() || fFamilyGroup >= 3) {
737 info->fFlags |= FormatInfo::kResolve_Flag;
739 info->fColorTypeInfoCount = 0;
744 info = &fFormatTable[GetFormatIndex(MTLPixelFormatDepth32Float_Stencil8)];
745 info->fFlags = FormatInfo::kMSAA_Flag;
746 if (this->
isMac() || fFamilyGroup >= 3) {
747 info->fFlags |= FormatInfo::kResolve_Flag;
749 info->fColorTypeInfoCount = 0;
757 std::fill_n(fColorTypeToFormatTable,
kSkColorTypeCnt, MTLPixelFormatInvalid);
760 MTLPixelFormatA8Unorm });
761 if (@available(macOS 11.0, iOS 8.0, tvOS 9.0, *)) {
795 MTLTextureUsage
usage = MTLTextureUsageShaderRead;
796 if (renderable == Renderable::kYes) {
797 usage |= MTLTextureUsageRenderTarget;
801 if (
format == MTLPixelFormatInvalid) {
807 info.fMipmapped = mipmapped;
810 info.fStorageMode = MTLStorageModePrivate;
811 info.fFramebufferOnly =
false;
819 if (!textureInfo.getMtlTextureInfo(&
info)) {
824 info.fMipmapped = mipmapped;
825 info.fUsage = MTLTextureUsageShaderRead;
826 info.fStorageMode = MTLStorageModePrivate;
827 info.fFramebufferOnly =
false;
834 switch (compression) {
838#ifdef SK_BUILD_FOR_MAC
839 return MTLPixelFormatBC1_RGBA;
842 return MTLPixelFormatInvalid;
850 MTLTextureUsage
usage = MTLTextureUsageShaderRead;
853 if (
format == MTLPixelFormatInvalid) {
859 info.fMipmapped = mipmapped;
862 info.fStorageMode = MTLStorageModePrivate;
863 info.fFramebufferOnly =
false;
868MTLStorageMode MtlCaps::getDefaultMSAAStorageMode(
Discardable discardable)
const {
871 if (@available(macOS 11.0, iOS 10.0, tvOS 10.0, *)) {
872 return MTLStorageModeMemoryless;
876 return MTLStorageModePrivate;
884 const MtlTextureSpec& singleSpec = singleSampledInfo.mtlTextureSpec();
889 MTLTextureUsage
usage = MTLTextureUsageRenderTarget;
893 info.fMipmapped = Mipmapped::kNo;
896 info.fStorageMode = this->getDefaultMSAAStorageMode(discardable);
897 info.fFramebufferOnly =
false;
904 uint32_t sampleCount,
908 info.fMipmapped = Mipmapped::kNo;
910 info.fUsage = MTLTextureUsageRenderTarget;
912 info.fFramebufferOnly =
false;
919 MTLPixelFormat
format =
static_cast<MTLPixelFormat
>(this->getFormatFromColorType(
colorType));
920 if (
format == MTLPixelFormatInvalid) {
924 const FormatInfo& formatInfo = this->getFormatInfo(
format);
925 if (!
SkToBool(FormatInfo::kStorage_Flag & formatInfo.fFlags)) {
929 MTLTextureUsage
usage = MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead;
932 info.fMipmapped = Mipmapped::kNo;
935 info.fStorageMode = MTLStorageModePrivate;
936 info.fFramebufferOnly =
false;
943 MTLPixelFormat mtlFormat =
static_cast<MTLPixelFormat
>(textureInfo.mtlTextureSpec().fFormat);
944 if (mtlFormat == MTLPixelFormatInvalid) {
948 const FormatInfo&
info = this->getFormatInfo(mtlFormat);
949 for (
int i = 0; i <
info.fColorTypeInfoCount; ++i) {
975 builder[2] = renderPassKey & 0xFFFFFFFF;
976 builder[3] = (renderPassKey >> 32) & 0xFFFFFFFF;
989 struct UnpackedKeyData {
991 uint32_t fRenderStepID = 0;
996 uint32_t fColorSampleCount = 1;
999 uint32_t fDSSampleCount = 1;
1007 const uint32_t* rawKeyData =
key.data();
1009 keyData.fRenderStepID = rawKeyData[0];
1013 keyData.fDSFormat =
static_cast<MtlPixelFormat>((rawKeyData[2] >> 16) & 0xFFFF);
1014 keyData.fDSSampleCount = rawKeyData[2] & 0xFFFF;
1016 keyData.fColorFormat =
static_cast<MtlPixelFormat>((rawKeyData[3] >> 16) & 0xFFFF);
1017 keyData.fColorSampleCount = rawKeyData[3] & 0xFFFF;
1022 SkASSERT(keyData.fColorSampleCount == keyData.fDSSampleCount);
1028 skgpu::Mipmapped::kNo,
1029 keyData.fColorFormat,
1030 MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget,
1031 MTLStorageModePrivate,
1040 { .0f, .0f, .0f, .0f },
1041 keyData.fColorSampleCount > 1,
1042 keyData.fWriteSwizzle);
1045 const RenderStep* renderStep = rendererProvider->
lookup(keyData.fRenderStepID);
1061 uint32_t dsAttachmentKey = depthStencilInfo.
fFormat << 16 | depthStencilInfo.
fSampleCount;
1062 return (((uint64_t) colorAttachmentKey) << 32) | dsAttachmentKey;
1070 UniqueKey::Builder builder(&pipelineKey, kComputePipelineDomain, 1,
"ComputePipeline");
1087 if (!
info.isValid()) {
1090 if (!(
info.mtlTextureSpec().fUsage & MTLTextureUsageShaderRead)) {
1093 if (
info.mtlTextureSpec().fFramebufferOnly) {
1096 return this->isTexturable((MTLPixelFormat)
info.mtlTextureSpec().fFormat);
1099bool MtlCaps::isTexturable(MTLPixelFormat
format)
const {
1100 const FormatInfo& formatInfo = this->getFormatInfo(
format);
1101 return SkToBool(FormatInfo::kTexturable_Flag & formatInfo.fFlags);
1105 return info.isValid() &&
1106 (
info.mtlTextureSpec().fUsage & MTLTextureUsageRenderTarget) &&
1111 return sampleCount <= this->maxRenderTargetSampleCount(
format);
1115 if (!
info.isValid()) {
1118 if (!(
info.mtlTextureSpec().fUsage & MTLTextureUsageShaderWrite)) {
1121 if (
info.mtlTextureSpec().fFramebufferOnly) {
1124 const FormatInfo& formatInfo =
1125 this->getFormatInfo((MTLPixelFormat)
info.mtlTextureSpec().fFormat);
1126 return info.numSamples() == 1 &&
SkToBool(FormatInfo::kStorage_Flag & formatInfo.fFlags);
1129uint32_t MtlCaps::maxRenderTargetSampleCount(MTLPixelFormat
format)
const {
1130 const FormatInfo& formatInfo = this->getFormatInfo(
format);
1131 if (!
SkToBool(formatInfo.fFlags & FormatInfo::kRenderable_Flag)) {
1134 if (
SkToBool(formatInfo.fFlags & FormatInfo::kMSAA_Flag)) {
1135 return fColorSampleCounts[fColorSampleCounts.size() - 1];
1143 texInfo.getMtlTextureInfo(&mtlInfo);
1157 texInfo.getMtlTextureInfo(&mtlInfo);
1179 dstTextureInfo.getMtlTextureInfo(&mtlInfo);
1181 const FormatInfo&
info = this->getFormatInfo((MTLPixelFormat)mtlInfo.
fFormat);
1182 for (
int i = 0; i <
info.fColorTypeInfoCount; ++i) {
1183 const auto& ctInfo =
info.fColorTypeInfos[i];
1184 if (ctInfo.fColorType == dstColorType) {
1185 return {dstColorType,
false};
1196 srcTextureInfo.getMtlTextureInfo(&mtlInfo);
1204 const FormatInfo&
info = this->getFormatInfo((MTLPixelFormat)mtlInfo.
fFormat);
1205 for (
int i = 0; i <
info.fColorTypeInfoCount; ++i) {
1206 const auto& ctInfo =
info.fColorTypeInfos[i];
1207 if (ctInfo.fColorType == srcColorType) {
1208 return {srcColorType,
false};
1226 static_assert(
sizeof(MTLPixelFormat) <=
sizeof(uint64_t));
1228 uint64_t formatKey =
static_cast<uint64_t
>(mtlSpec.
fFormat);
1233 bool isMipped =
info.mipmapped() == Mipmapped::kYes;
1240 SkASSERT(
static_cast<uint32_t
>(isMipped) < (1u << 1));
1241 SkASSERT(
static_cast<uint32_t
>(isProtected) < (1u << 1));
1244 SkASSERT(
static_cast<uint32_t
>(isFBOnly) < (1u << 1));
1247 static int kNum32DataCnt = 2 + 2 + 1;
1251 builder[0] = dimensions.
width();
1252 builder[1] = dimensions.
height();
1253 builder[2] = formatKey & 0xFFFFFFFF;
1254 builder[3] = (formatKey >> 32) & 0xFFFFFFFF;
1255 builder[4] = (samplesKey << 0) |
1256 (
static_cast<uint32_t
>(isMipped) << 3) |
1257 (
static_cast<uint32_t
>(isProtected) << 4) |
1258 (
static_cast<uint32_t
>(mtlSpec.
fUsage) << 5) |
1260 (
static_cast<uint32_t
>(isFBOnly) << 12);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define kMTLPixelFormatB5G6R5Unorm
#define kMTLPixelFormatETC2_RGB8
#define kMTLPixelFormatABGR4Unorm
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kSRGBA_8888_SkColorType
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kA16_float_SkColorType
pixel with a half float for alpha
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
@ kUnknown_SkColorType
uninitialized
@ kR16G16_float_SkColorType
pixel with a half float for red and green
static constexpr int kSkColorTypeCnt
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static constexpr bool SkToBool(const T &x)
static Swizzle Make(uint16_t key)
constexpr uint16_t asKey() const
static constexpr Swizzle RGB1()
static Domain GenerateDomain()
size_t fRequiredStorageBufferAlignment
size_t fRequiredUniformBufferAlignment
bool fStorageBufferPreferred
bool fClampToBorderSupport
std::unique_ptr< SkSL::ShaderCaps > fShaderCaps
bool fStorageBufferSupport
static uint32_t SamplesToKey(uint32_t numSamples)
void finishInitialization(const ContextOptions &)
size_t fRequiredTransferBufferAlignment
const SkSL::ShaderCaps * shaderCaps() const
ResourceBindingRequirements fResourceBindingReqs
const ComputeStep * computeStep() const
uint32_t uniqueID() const
UniquePaintParamsID paintParamsID() const
uint32_t renderStepID() const
void buildKeyForTexture(SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const override
TextureInfo getDefaultMSAATextureInfo(const TextureInfo &singleSampledInfo, Discardable discardable) const override
TextureInfo getTextureInfoForSampledCopy(const TextureInfo &textureInfo, Mipmapped mipmapped) const override
TextureInfo getDefaultCompressedTextureInfo(SkTextureCompressionType, Mipmapped mipmapped, Protected) const override
std::pair< SkColorType, bool > supportedWritePixelsColorType(SkColorType dstColorType, const TextureInfo &dstTextureInfo, SkColorType srcColorType) const override
bool extractGraphicsDescs(const UniqueKey &, GraphicsPipelineDesc *, RenderPassDesc *, const RendererProvider *) const override
bool isStorage(const TextureInfo &) const override
bool supportsReadPixels(const TextureInfo &) const override
TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const override
bool onIsTexturable(const TextureInfo &) const override
MtlCaps(const id< MTLDevice >, const ContextOptions &)
bool supportsWritePixels(const TextureInfo &) const override
TextureInfo getDefaultDepthStencilTextureInfo(SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const override
std::pair< SkColorType, bool > supportedReadPixelsColorType(SkColorType srcColorType, const TextureInfo &srcTextureInfo, SkColorType dstColorType) const override
TextureInfo getDefaultStorageTextureInfo(SkColorType) const override
UniqueKey makeComputePipelineKey(const ComputePipelineDesc &) const override
uint64_t getRenderPassDescKey(const RenderPassDesc &) const
bool isRenderable(const TextureInfo &) const override
uint32_t channelMask(const TextureInfo &) const override
UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const override
const ColorTypeInfo * getColorTypeInfo(SkColorType, const TextureInfo &) const override
const RenderStep * lookup(uint32_t uniqueID) const
uint32_t numSamples() const
static UniquePaintParamsID InvalidID()
uint32_t uint32_t * format
unsigned int MtlPixelFormat
SkEnumBitMask< DepthStencilFlags > MtlFormatToDepthStencilFlags(MTLPixelFormat format)
MTLPixelFormat MtlDepthStencilFlagsToFormat(SkEnumBitMask< DepthStencilFlags > mask)
static const int kGraphicsPipelineKeyData32Count
static constexpr MTLPixelFormat kMtlFormats[]
static const skgpu::UniqueKey::Domain kGraphicsPipelineDomain
uint32_t MtlFormatChannels(MTLPixelFormat mtlFormat)
bool MtlFormatIsCompressed(MTLPixelFormat mtlFormat)
static void usage(char *argv0)
constexpr int32_t width() const
constexpr int32_t height() const
bool fDualSourceBlendingSupport
const char * fFBFetchColorName
bool fShaderDerivativeSupport
bool fFlatInterpolationSupport
bool fInverseHyperbolicSupport
bool fNonsquareMatrixSupport
bool fUsesPrecisionModifiers
MtlStorageMode fStorageMode
AttachmentDesc fDepthStencilAttachment
AttachmentDesc fColorAttachment
static RenderPassDesc Make(const Caps *caps, const TextureInfo &targetInfo, LoadOp loadOp, StoreOp storeOp, SkEnumBitMask< DepthStencilFlags > depthStencilFlags, const std::array< float, 4 > &clearColor, bool requiresMSAA, Swizzle writeSwizzle)
Layout fUniformBufferLayout
bool fDistinctIndexRanges
Layout fStorageBufferLayout