Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | List of all members
skgpu::graphite::MtlCaps Class Referencefinal

#include <MtlCaps.h>

Inheritance diagram for skgpu::graphite::MtlCaps:
skgpu::graphite::Caps

Public Member Functions

 MtlCaps (const id< MTLDevice >, const ContextOptions &)
 
 ~MtlCaps () override
 
TextureInfo getDefaultSampledTextureInfo (SkColorType, Mipmapped mipmapped, Protected, Renderable) const override
 
TextureInfo getTextureInfoForSampledCopy (const TextureInfo &textureInfo, Mipmapped mipmapped) const override
 
TextureInfo getDefaultCompressedTextureInfo (SkTextureCompressionType, Mipmapped mipmapped, Protected) const override
 
TextureInfo getDefaultMSAATextureInfo (const TextureInfo &singleSampledInfo, Discardable discardable) const override
 
TextureInfo getDefaultDepthStencilTextureInfo (SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const override
 
TextureInfo getDefaultStorageTextureInfo (SkColorType) const override
 
UniqueKey makeGraphicsPipelineKey (const GraphicsPipelineDesc &, const RenderPassDesc &) const override
 
UniqueKey makeComputePipelineKey (const ComputePipelineDesc &) const override
 
bool extractGraphicsDescs (const UniqueKey &, GraphicsPipelineDesc *, RenderPassDesc *, const RendererProvider *) const override
 
uint64_t getRenderPassDescKey (const RenderPassDesc &) const
 
bool isMac () const
 
bool isApple () const
 
uint32_t channelMask (const TextureInfo &) const override
 
bool isRenderable (const TextureInfo &) const override
 
bool isStorage (const TextureInfo &) const override
 
void buildKeyForTexture (SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const override
 
- Public Member Functions inherited from skgpu::graphite::Caps
virtual ~Caps ()
 
const SkSL::ShaderCapsshaderCaps () const
 
sk_sp< SkCapabilitiescapabilities () const
 
virtual SkISize getDepthAttachmentDimensions (const TextureInfo &, const SkISize colorAttachmentDimensions) const
 
virtual GraphiteResourceKey makeSamplerKey (const SamplerDesc &samplerDesc) const
 
bool areColorTypeAndTextureInfoCompatible (SkColorType, const TextureInfo &) const
 
bool isTexturable (const TextureInfo &) const
 
int maxTextureSize () const
 
int defaultMSAASamplesCount () const
 
const ResourceBindingRequirementsresourceBindingRequirements () const
 
size_t requiredUniformBufferAlignment () const
 
size_t requiredStorageBufferAlignment () const
 
size_t requiredTransferBufferAlignment () const
 
size_t getAlignedTextureDataRowBytes (size_t rowBytes) const
 
SkColorType getRenderableColorType (SkColorType) const
 
bool clampToBorderSupport () const
 
bool protectedSupport () const
 
bool semaphoreSupport () const
 
bool allowCpuSync () const
 
bool storageBufferSupport () const
 
bool storageBufferPreferred () const
 
bool drawBufferCanBeMapped () const
 
bool bufferMapsAreAsync () const
 
bool msaaRenderToSingleSampledSupport () const
 
bool computeSupport () const
 
bool supportsAHardwareBufferImages () const
 
skgpu::Swizzle getReadSwizzle (SkColorType, const TextureInfo &) const
 
skgpu::Swizzle getWriteSwizzle (SkColorType, const TextureInfo &) const
 
skgpu::ShaderErrorHandlershaderErrorHandler () const
 
DstReadRequirement getDstReadRequirement () const
 
float minDistanceFieldFontSize () const
 
float glyphsAsPathsFontSize () const
 
size_t glyphCacheTextureMaximumBytes () const
 
int maxPathAtlasTextureSize () const
 
bool allowMultipleAtlasTextures () const
 
bool supportBilerpFromGlyphAtlas () const
 
bool requireOrderedRecordings () const
 
bool fullCompressedUploadSizeMustAlignToBlockDims () const
 
sktext::gpu::SDFTControl getSDFTControl (bool useSDFTForSmallText) const
 

Private Member Functions

const ColorTypeInfogetColorTypeInfo (SkColorType, const TextureInfo &) const override
 
bool onIsTexturable (const TextureInfo &) const override
 
bool supportsWritePixels (const TextureInfo &) const override
 
bool supportsReadPixels (const TextureInfo &) const override
 
std::pair< SkColorType, bool > supportedWritePixelsColorType (SkColorType dstColorType, const TextureInfo &dstTextureInfo, SkColorType srcColorType) const override
 
std::pair< SkColorType, bool > supportedReadPixelsColorType (SkColorType srcColorType, const TextureInfo &srcTextureInfo, SkColorType dstColorType) const override
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::Caps
 Caps ()
 
void finishInitialization (const ContextOptions &)
 
- Static Protected Member Functions inherited from skgpu::graphite::Caps
static uint32_t SamplesToKey (uint32_t numSamples)
 
- Protected Attributes inherited from skgpu::graphite::Caps
int fMaxTextureSize = 0
 
int fDefaultMSAASamples = 4
 
size_t fRequiredUniformBufferAlignment = 0
 
size_t fRequiredStorageBufferAlignment = 0
 
size_t fRequiredTransferBufferAlignment = 0
 
size_t fTextureDataRowBytesAlignment = 1
 
std::unique_ptr< SkSL::ShaderCapsfShaderCaps
 
bool fClampToBorderSupport = true
 
bool fProtectedSupport = false
 
bool fSemaphoreSupport = false
 
bool fAllowCpuSync = true
 
bool fStorageBufferSupport = false
 
bool fStorageBufferPreferred = false
 
bool fDrawBufferCanBeMapped = true
 
bool fBufferMapsAreAsync = false
 
bool fMSAARenderToSingleSampledSupport = false
 
bool fComputeSupport = false
 
bool fSupportsAHardwareBufferImages = false
 
bool fFullCompressedUploadSizeMustAlignToBlockDims = false
 
ResourceBindingRequirements fResourceBindingReqs
 
ShaderErrorHandlerfShaderErrorHandler = nullptr
 
size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4
 
float fMinDistanceFieldFontSize = 18
 
float fGlyphsAsPathsFontSize = 324
 
int fMaxPathAtlasTextureSize = 8192
 
bool fAllowMultipleAtlasTextures = true
 
bool fSupportBilerpFromGlyphAtlas = false
 
bool fRequireOrderedRecordings = false
 

Detailed Description

Definition at line 20 of file MtlCaps.h.

Constructor & Destructor Documentation

◆ MtlCaps()

skgpu::graphite::MtlCaps::MtlCaps ( const id< MTLDevice >  device,
const ContextOptions options 
)

Definition at line 27 of file MtlCaps.mm.

28 : Caps() {
29 this->initGPUFamily(device);
30 this->initCaps(device);
31 this->initShaderCaps();
32
33 this->initFormatTable();
34
35 // Metal-specific MtlCaps
36
38}
const char * options
void finishInitialization(const ContextOptions &)
Definition Caps.cpp:29
VkDevice device
Definition main.cc:53

◆ ~MtlCaps()

skgpu::graphite::MtlCaps::~MtlCaps ( )
inlineoverride

Definition at line 23 of file MtlCaps.h.

23{}

Member Function Documentation

◆ buildKeyForTexture()

void skgpu::graphite::MtlCaps::buildKeyForTexture ( SkISize  dimensions,
const TextureInfo info,
ResourceType  type,
Shareable  shareable,
GraphiteResourceKey key 
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 1214 of file MtlCaps.mm.

1218 {
1219 const MtlTextureSpec& mtlSpec = info.mtlTextureSpec();
1220
1221 SkASSERT(!dimensions.isEmpty());
1222
1223 // A MTLPixelFormat is an NSUInteger type which is documented to be 32 bits in 32 bit
1224 // applications and 64 bits in 64 bit applications. So it should fit in an uint64_t, but adding
1225 // the assert heere to make sure.
1226 static_assert(sizeof(MTLPixelFormat) <= sizeof(uint64_t));
1227 SkASSERT(mtlSpec.fFormat != MTLPixelFormatInvalid);
1228 uint64_t formatKey = static_cast<uint64_t>(mtlSpec.fFormat);
1229
1230 uint32_t samplesKey = SamplesToKey(info.numSamples());
1231 // We don't have to key the number of mip levels because it is inherit in the combination of
1232 // isMipped and dimensions.
1233 bool isMipped = info.mipmapped() == Mipmapped::kYes;
1234 Protected isProtected = info.isProtected();
1235 bool isFBOnly = mtlSpec.fFramebufferOnly;
1236
1237 // Confirm all the below parts of the key can fit in a single uint32_t. The sum of the shift
1238 // amounts in the asserts must be less than or equal to 32.
1239 SkASSERT(samplesKey < (1u << 3));
1240 SkASSERT(static_cast<uint32_t>(isMipped) < (1u << 1));
1241 SkASSERT(static_cast<uint32_t>(isProtected) < (1u << 1));
1242 SkASSERT(mtlSpec.fUsage < (1u << 5));
1243 SkASSERT(mtlSpec.fStorageMode < (1u << 2));
1244 SkASSERT(static_cast<uint32_t>(isFBOnly) < (1u << 1));
1245
1246 // We need two uint32_ts for dimensions, 2 for format, and 1 for the rest of the key;
1247 static int kNum32DataCnt = 2 + 2 + 1;
1248
1249 GraphiteResourceKey::Builder builder(key, type, kNum32DataCnt, shareable);
1250
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) |
1259 (static_cast<uint32_t>(mtlSpec.fStorageMode) << 10)|
1260 (static_cast<uint32_t>(isFBOnly) << 12);
1261
1262}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
static uint32_t SamplesToKey(uint32_t numSamples)
Definition Caps.h:305
Protected
Definition GpuTypes.h:61
bool isEmpty() const
Definition SkSize.h:31
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ channelMask()

uint32_t skgpu::graphite::MtlCaps::channelMask ( const TextureInfo info) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 1082 of file MtlCaps.mm.

1082 {
1083 return skgpu::MtlFormatChannels((MTLPixelFormat)info.mtlTextureSpec().fFormat);
1084}
uint32_t MtlFormatChannels(MTLPixelFormat mtlFormat)
Definition MtlUtils.mm:91

◆ extractGraphicsDescs()

bool skgpu::graphite::MtlCaps::extractGraphicsDescs ( const UniqueKey key,
GraphicsPipelineDesc pipelineDesc,
RenderPassDesc renderPassDesc,
const RendererProvider rendererProvider 
) const
overridevirtual

Reimplemented from skgpu::graphite::Caps.

Definition at line 985 of file MtlCaps.mm.

988 {
989 struct UnpackedKeyData {
990 // From the GraphicsPipelineDesc
991 uint32_t fRenderStepID = 0;
992 UniquePaintParamsID fPaintParamsID;
993
994 // From the RenderPassDesc
995 MtlPixelFormat fColorFormat = 0;
996 uint32_t fColorSampleCount = 1;
997
998 MtlPixelFormat fDSFormat = 0;
999 uint32_t fDSSampleCount = 1;
1000
1001 Swizzle fWriteSwizzle;
1002 } keyData;
1003
1005 SkASSERT(key.dataSize() == 4 * kGraphicsPipelineKeyData32Count);
1006
1007 const uint32_t* rawKeyData = key.data();
1008
1009 keyData.fRenderStepID = rawKeyData[0];
1010 keyData.fPaintParamsID = rawKeyData[1] ? UniquePaintParamsID(rawKeyData[1])
1011 : UniquePaintParamsID::InvalidID();
1012
1013 keyData.fDSFormat = static_cast<MtlPixelFormat>((rawKeyData[2] >> 16) & 0xFFFF);
1014 keyData.fDSSampleCount = rawKeyData[2] & 0xFFFF;
1015
1016 keyData.fColorFormat = static_cast<MtlPixelFormat>((rawKeyData[3] >> 16) & 0xFFFF);
1017 keyData.fColorSampleCount = rawKeyData[3] & 0xFFFF;
1018
1019 keyData.fWriteSwizzle = SwizzleCtorAccessor::Make(rawKeyData[4]);
1020
1021 // Recreate the RenderPassDesc
1022 SkASSERT(keyData.fColorSampleCount == keyData.fDSSampleCount);
1023
1025 MtlFormatToDepthStencilFlags((MTLPixelFormat) keyData.fDSFormat);
1026
1027 MtlTextureInfo mtlInfo(keyData.fColorSampleCount,
1028 skgpu::Mipmapped::kNo,
1029 keyData.fColorFormat,
1030 MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget,
1031 MTLStorageModePrivate,
1032 /* framebufferOnly= */ false);
1033 TextureInfo info(mtlInfo);
1034
1035 *renderPassDesc = RenderPassDesc::Make(this,
1036 info,
1039 dsFlags,
1040 /* clearColor= */ { .0f, .0f, .0f, .0f },
1041 /* requiresMSAA= */ keyData.fColorSampleCount > 1,
1042 keyData.fWriteSwizzle);
1043
1044 // Recreate the GraphicsPipelineDesc
1045 const RenderStep* renderStep = rendererProvider->lookup(keyData.fRenderStepID);
1046
1047 UniquePaintParamsID paintID = renderStep->performsShading() ? keyData.fPaintParamsID
1049
1050 *pipelineDesc = GraphicsPipelineDesc(renderStep, paintID);
1051
1052 return true;
1053}
static Swizzle Make(uint16_t key)
Definition SwizzlePriv.h:21
static UniquePaintParamsID InvalidID()
unsigned int MtlPixelFormat
SkEnumBitMask< DepthStencilFlags > MtlFormatToDepthStencilFlags(MTLPixelFormat format)
static const int kGraphicsPipelineKeyData32Count
Definition MtlCaps.mm:960
static const skgpu::UniqueKey::Domain kGraphicsPipelineDomain
Definition MtlCaps.mm:959
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)

◆ getColorTypeInfo()

const Caps::ColorTypeInfo * skgpu::graphite::MtlCaps::getColorTypeInfo ( SkColorType  ct,
const TextureInfo textureInfo 
) const
overrideprivatevirtual

Implements skgpu::graphite::Caps.

Definition at line 941 of file MtlCaps.mm.

942 {
943 MTLPixelFormat mtlFormat = static_cast<MTLPixelFormat>(textureInfo.mtlTextureSpec().fFormat);
944 if (mtlFormat == MTLPixelFormatInvalid) {
945 return nullptr;
946 }
947
948 const FormatInfo& info = this->getFormatInfo(mtlFormat);
949 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
950 const ColorTypeInfo& ctInfo = info.fColorTypeInfos[i];
951 if (ctInfo.fColorType == ct) {
952 return &ctInfo;
953 }
954 }
955
956 return nullptr;
957}

◆ getDefaultCompressedTextureInfo()

TextureInfo skgpu::graphite::MtlCaps::getDefaultCompressedTextureInfo ( SkTextureCompressionType  compression,
Mipmapped  mipmapped,
Protected   
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 847 of file MtlCaps.mm.

849 {
850 MTLTextureUsage usage = MTLTextureUsageShaderRead;
851
852 MtlPixelFormat format = format_from_compression(compression);
853 if (format == MTLPixelFormatInvalid) {
854 return {};
855 }
856
857 MtlTextureInfo info;
858 info.fSampleCount = 1;
859 info.fMipmapped = mipmapped;
860 info.fFormat = format;
861 info.fUsage = usage;
862 info.fStorageMode = MTLStorageModePrivate;
863 info.fFramebufferOnly = false;
864
865 return info;
866}
uint32_t uint32_t * format
static void usage(char *argv0)

◆ getDefaultDepthStencilTextureInfo()

TextureInfo skgpu::graphite::MtlCaps::getDefaultDepthStencilTextureInfo ( SkEnumBitMask< DepthStencilFlags depthStencilType,
uint32_t  sampleCount,
Protected   
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 902 of file MtlCaps.mm.

905 {
906 MtlTextureInfo info;
907 info.fSampleCount = sampleCount;
908 info.fMipmapped = Mipmapped::kNo;
909 info.fFormat = MtlDepthStencilFlagsToFormat(depthStencilType);
910 info.fUsage = MTLTextureUsageRenderTarget;
911 info.fStorageMode = this->getDefaultMSAAStorageMode(Discardable::kYes);
912 info.fFramebufferOnly = false;
913
914 return info;
915}
MTLPixelFormat MtlDepthStencilFlagsToFormat(SkEnumBitMask< DepthStencilFlags > mask)

◆ getDefaultMSAATextureInfo()

TextureInfo skgpu::graphite::MtlCaps::getDefaultMSAATextureInfo ( const TextureInfo singleSampledInfo,
Discardable  discardable 
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 879 of file MtlCaps.mm.

880 {
881 if (fDefaultMSAASamples <= 1) {
882 return {};
883 }
884 const MtlTextureSpec& singleSpec = singleSampledInfo.mtlTextureSpec();
885 if (!this->isRenderable((MTLPixelFormat)singleSpec.fFormat, fDefaultMSAASamples)) {
886 return {};
887 }
888
889 MTLTextureUsage usage = MTLTextureUsageRenderTarget;
890
891 MtlTextureInfo info;
892 info.fSampleCount = fDefaultMSAASamples;
893 info.fMipmapped = Mipmapped::kNo;
894 info.fFormat = singleSpec.fFormat;
895 info.fUsage = usage;
896 info.fStorageMode = this->getDefaultMSAAStorageMode(discardable);
897 info.fFramebufferOnly = false;
898
899 return info;
900}
bool isRenderable(const TextureInfo &) const override
Definition MtlCaps.mm:1104

◆ getDefaultSampledTextureInfo()

TextureInfo skgpu::graphite::MtlCaps::getDefaultSampledTextureInfo ( SkColorType  colorType,
Mipmapped  mipmapped,
Protected  ,
Renderable  renderable 
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 791 of file MtlCaps.mm.

794 {
795 MTLTextureUsage usage = MTLTextureUsageShaderRead;
796 if (renderable == Renderable::kYes) {
797 usage |= MTLTextureUsageRenderTarget;
798 }
799
800 MtlPixelFormat format = this->getFormatFromColorType(colorType);
801 if (format == MTLPixelFormatInvalid) {
802 return {};
803 }
804
805 MtlTextureInfo info;
806 info.fSampleCount = 1;
807 info.fMipmapped = mipmapped;
808 info.fFormat = format;
809 info.fUsage = usage;
810 info.fStorageMode = MTLStorageModePrivate;
811 info.fFramebufferOnly = false;
812
813 return info;
814}
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)

◆ getDefaultStorageTextureInfo()

TextureInfo skgpu::graphite::MtlCaps::getDefaultStorageTextureInfo ( SkColorType  colorType) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 917 of file MtlCaps.mm.

917 {
918 // Storage textures are currently always sampleable from a shader.
919 MTLPixelFormat format = static_cast<MTLPixelFormat>(this->getFormatFromColorType(colorType));
920 if (format == MTLPixelFormatInvalid) {
921 return {};
922 }
923
924 const FormatInfo& formatInfo = this->getFormatInfo(format);
925 if (!SkToBool(FormatInfo::kStorage_Flag & formatInfo.fFlags)) {
926 return {};
927 }
928
929 MTLTextureUsage usage = MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead;
930 MtlTextureInfo info;
931 info.fSampleCount = 1;
932 info.fMipmapped = Mipmapped::kNo;
933 info.fFormat = format;
934 info.fUsage = usage;
935 info.fStorageMode = MTLStorageModePrivate;
936 info.fFramebufferOnly = false;
937
938 return info;
939}
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ getRenderPassDescKey()

uint64_t skgpu::graphite::MtlCaps::getRenderPassDescKey ( const RenderPassDesc renderPassDesc) const

Definition at line 1055 of file MtlCaps.mm.

1055 {
1056 MtlTextureInfo colorInfo, depthStencilInfo;
1057 renderPassDesc.fColorAttachment.fTextureInfo.getMtlTextureInfo(&colorInfo);
1058 renderPassDesc.fDepthStencilAttachment.fTextureInfo.getMtlTextureInfo(&depthStencilInfo);
1059 SkASSERT(colorInfo.fFormat < 65535 && depthStencilInfo.fFormat < 65535);
1060 uint32_t colorAttachmentKey = colorInfo.fFormat << 16 | colorInfo.fSampleCount;
1061 uint32_t dsAttachmentKey = depthStencilInfo.fFormat << 16 | depthStencilInfo.fSampleCount;
1062 return (((uint64_t) colorAttachmentKey) << 32) | dsAttachmentKey;
1063}

◆ getTextureInfoForSampledCopy()

TextureInfo skgpu::graphite::MtlCaps::getTextureInfoForSampledCopy ( const TextureInfo textureInfo,
Mipmapped  mipmapped 
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 816 of file MtlCaps.mm.

817 {
818 MtlTextureInfo info;
819 if (!textureInfo.getMtlTextureInfo(&info)) {
820 return {};
821 }
822
823 info.fSampleCount = 1;
824 info.fMipmapped = mipmapped;
825 info.fUsage = MTLTextureUsageShaderRead;
826 info.fStorageMode = MTLStorageModePrivate;
827 info.fFramebufferOnly = false;
828
829 return info;
830}

◆ isApple()

bool skgpu::graphite::MtlCaps::isApple ( ) const
inline

Definition at line 60 of file MtlCaps.h.

60{ return fGPUFamily == GPUFamily::kApple; }

◆ isMac()

bool skgpu::graphite::MtlCaps::isMac ( ) const
inline

Definition at line 59 of file MtlCaps.h.

59{ return fGPUFamily == GPUFamily::kMac; }

◆ isRenderable()

bool skgpu::graphite::MtlCaps::isRenderable ( const TextureInfo info) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 1104 of file MtlCaps.mm.

1104 {
1105 return info.isValid() &&
1106 (info.mtlTextureSpec().fUsage & MTLTextureUsageRenderTarget) &&
1107 this->isRenderable((MTLPixelFormat)info.mtlTextureSpec().fFormat, info.numSamples());
1108}

◆ isStorage()

bool skgpu::graphite::MtlCaps::isStorage ( const TextureInfo info) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 1114 of file MtlCaps.mm.

1114 {
1115 if (!info.isValid()) {
1116 return false;
1117 }
1118 if (!(info.mtlTextureSpec().fUsage & MTLTextureUsageShaderWrite)) {
1119 return false;
1120 }
1121 if (info.mtlTextureSpec().fFramebufferOnly) {
1122 return false;
1123 }
1124 const FormatInfo& formatInfo =
1125 this->getFormatInfo((MTLPixelFormat)info.mtlTextureSpec().fFormat);
1126 return info.numSamples() == 1 && SkToBool(FormatInfo::kStorage_Flag & formatInfo.fFlags);
1127}

◆ makeComputePipelineKey()

UniqueKey skgpu::graphite::MtlCaps::makeComputePipelineKey ( const ComputePipelineDesc pipelineDesc) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 1065 of file MtlCaps.mm.

1065 {
1066 UniqueKey pipelineKey;
1067 {
1068 static const skgpu::UniqueKey::Domain kComputePipelineDomain = UniqueKey::GenerateDomain();
1069 // The key is made up of a single uint32_t corresponding to the compute step ID.
1070 UniqueKey::Builder builder(&pipelineKey, kComputePipelineDomain, 1, "ComputePipeline");
1071 builder[0] = pipelineDesc.computeStep()->uniqueID();
1072
1073 // TODO(b/240615224): The local work group size should factor into the key on platforms
1074 // that don't support specialization constants and require the workgroup/threadgroup size to
1075 // be specified in the shader text (D3D12, Vulkan 1.0, and OpenGL).
1076
1077 builder.finish();
1078 }
1079 return pipelineKey;
1080}
static Domain GenerateDomain()

◆ makeGraphicsPipelineKey()

UniqueKey skgpu::graphite::MtlCaps::makeGraphicsPipelineKey ( const GraphicsPipelineDesc pipelineDesc,
const RenderPassDesc renderPassDesc 
) const
overridevirtual

Implements skgpu::graphite::Caps.

Definition at line 962 of file MtlCaps.mm.

963 {
964 UniqueKey pipelineKey;
965 {
966 // 5 uint32_t's (render step id, paint id, uint64 renderpass desc, uint16 write swizzle key)
967 UniqueKey::Builder builder(&pipelineKey, kGraphicsPipelineDomain,
968 kGraphicsPipelineKeyData32Count, "GraphicsPipeline");
969 // add GraphicsPipelineDesc key
970 builder[0] = pipelineDesc.renderStepID();
971 builder[1] = pipelineDesc.paintParamsID().asUInt();
972
973 // add RenderPassDesc key
974 uint64_t renderPassKey = this->getRenderPassDescKey(renderPassDesc);
975 builder[2] = renderPassKey & 0xFFFFFFFF;
976 builder[3] = (renderPassKey >> 32) & 0xFFFFFFFF;
977 builder[4] = renderPassDesc.fWriteSwizzle.asKey();
978
979 builder.finish();
980 }
981
982 return pipelineKey;
983}
uint64_t getRenderPassDescKey(const RenderPassDesc &) const
Definition MtlCaps.mm:1055

◆ onIsTexturable()

bool skgpu::graphite::MtlCaps::onIsTexturable ( const TextureInfo info) const
overrideprivatevirtual

Implements skgpu::graphite::Caps.

Definition at line 1086 of file MtlCaps.mm.

1086 {
1087 if (!info.isValid()) {
1088 return false;
1089 }
1090 if (!(info.mtlTextureSpec().fUsage & MTLTextureUsageShaderRead)) {
1091 return false;
1092 }
1093 if (info.mtlTextureSpec().fFramebufferOnly) {
1094 return false;
1095 }
1096 return this->isTexturable((MTLPixelFormat)info.mtlTextureSpec().fFormat);
1097}

◆ supportedReadPixelsColorType()

std::pair< SkColorType, bool > skgpu::graphite::MtlCaps::supportedReadPixelsColorType ( SkColorType  srcColorType,
const TextureInfo srcTextureInfo,
SkColorType  dstColorType 
) const
overrideprivatevirtual

Given a src surface's color type and its texture info as well as a color type the caller would like read into, this provides a legal color type that the caller can use for readPixels. The returned color type may differ from the passed dstColorType, in which case the caller must convert the read pixel data (see GrConvertPixels). When converting to dstColorType the swizzle in the returned struct should be applied. The caller must check the returned color type for kUnknown.

We currently don't have an SkColorType for a 3 channel RGB format. Additionally the current implementation of raster pipeline requires power of 2 channels, so it is not easy to add such an SkColorType. Thus we need to check for data that is 3 channels using the isRGBFormat return value and handle it manually

Implements skgpu::graphite::Caps.

Definition at line 1191 of file MtlCaps.mm.

1194 {
1195 MtlTextureInfo mtlInfo;
1196 srcTextureInfo.getMtlTextureInfo(&mtlInfo);
1197
1198 // TODO: handle compressed formats
1199 if (MtlFormatIsCompressed((MTLPixelFormat)mtlInfo.fFormat)) {
1200 SkASSERT(this->isTexturable((MTLPixelFormat)mtlInfo.fFormat));
1201 return {kUnknown_SkColorType, false};
1202 }
1203
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};
1209 }
1210 }
1211 return {kUnknown_SkColorType, false};
1212}
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
bool MtlFormatIsCompressed(MTLPixelFormat mtlFormat)
Definition MtlUtils.mm:49

◆ supportedWritePixelsColorType()

std::pair< SkColorType, bool > skgpu::graphite::MtlCaps::supportedWritePixelsColorType ( SkColorType  dstColorType,
const TextureInfo dstTextureInfo,
SkColorType  srcColorType 
) const
overrideprivatevirtual

Given a dst pixel config and a src color type what color type must the caller coax the the data into in order to use writePixels.

We currently don't have an SkColorType for a 3 channel RGB format. Additionally the current implementation of raster pipeline requires power of 2 channels, so it is not easy to add such an SkColorType. Thus we need to check for data that is 3 channels using the isRGBFormat return value and handle it manually

Implements skgpu::graphite::Caps.

Definition at line 1174 of file MtlCaps.mm.

1177 {
1178 MtlTextureInfo mtlInfo;
1179 dstTextureInfo.getMtlTextureInfo(&mtlInfo);
1180
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};
1186 }
1187 }
1188 return {kUnknown_SkColorType, false};
1189}

◆ supportsReadPixels()

bool skgpu::graphite::MtlCaps::supportsReadPixels ( const TextureInfo textureInfo) const
overrideprivatevirtual

Backends may have restrictions on what types of textures support Device::readPixels(). If this returns false then the caller should implement a fallback where a temporary texture is created, the original texture is copied or drawn into it, and then pixels read from the temporary texture.

Implements skgpu::graphite::Caps.

Definition at line 1155 of file MtlCaps.mm.

1155 {
1156 MtlTextureInfo mtlInfo;
1157 texInfo.getMtlTextureInfo(&mtlInfo);
1158 if (mtlInfo.fFramebufferOnly) {
1159 return false;
1160 }
1161
1162 // We disallow reading back directly from compressed textures.
1163 if (MtlFormatIsCompressed((MTLPixelFormat)mtlInfo.fFormat)) {
1164 return false;
1165 }
1166
1167 if (texInfo.numSamples() > 1) {
1168 return false;
1169 }
1170
1171 return true;
1172}

◆ supportsWritePixels()

bool skgpu::graphite::MtlCaps::supportsWritePixels ( const TextureInfo textureInfo) const
overrideprivatevirtual

Backends may have restrictions on what types of textures support Device::writePixels(). If this returns false then the caller should implement a fallback where a temporary texture is created, pixels are written to it, and then that is copied or drawn into the the surface.

Implements skgpu::graphite::Caps.

Definition at line 1141 of file MtlCaps.mm.

1141 {
1142 MtlTextureInfo mtlInfo;
1143 texInfo.getMtlTextureInfo(&mtlInfo);
1144 if (mtlInfo.fFramebufferOnly) {
1145 return false;
1146 }
1147
1148 if (texInfo.numSamples() > 1) {
1149 return false;
1150 }
1151
1152 return true;
1153}

The documentation for this class was generated from the following files: