Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | List of all members
GrMtlCaps Class Reference

#include <GrMtlCaps.h>

Inheritance diagram for GrMtlCaps:
GrCaps SkCapabilities SkRefCnt SkRefCntBase

Public Member Functions

 GrMtlCaps (const GrContextOptions &contextOptions, id< MTLDevice > device)
 
bool isFormatSRGB (const GrBackendFormat &) const override
 
bool isFormatTexturable (const GrBackendFormat &, GrTextureType) const override
 
bool isFormatTexturable (MTLPixelFormat) const
 
bool isFormatCopyable (const GrBackendFormat &) const override
 
bool isFormatAsColorTypeRenderable (GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
 
bool isFormatRenderable (const GrBackendFormat &format, int sampleCount) const override
 
bool isFormatRenderable (MTLPixelFormat, int sampleCount) const
 
int getRenderTargetSampleCount (int requestedCount, const GrBackendFormat &) const override
 
int getRenderTargetSampleCount (int requestedCount, MTLPixelFormat) const
 
int maxRenderTargetSampleCount (const GrBackendFormat &) const override
 
int maxRenderTargetSampleCount (MTLPixelFormat) const
 
SupportedWrite supportedWritePixelsColorType (GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const override
 
SurfaceReadPixelsSupport surfaceSupportsReadPixels (const GrSurface *) const override
 
DstCopyRestrictions getDstCopyRestrictions (const GrRenderTargetProxy *src, GrColorType ct) const override
 
MTLPixelFormat preferredStencilFormat () const
 
bool canCopyAsBlit (MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
 
bool canCopyAsResolve (MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, bool srcIsRenderTarget, const SkISize srcDimensions, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
 
GrBackendFormat getBackendFormatFromCompressionType (SkTextureCompressionType) const override
 
MTLPixelFormat getFormatFromColorType (GrColorType colorType) const
 
skgpu::Swizzle getWriteSwizzle (const GrBackendFormat &, GrColorType) const override
 
uint64_t computeFormatKey (const GrBackendFormat &) const override
 
GrProgramDesc makeDesc (GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
 
MTLPixelFormat getStencilPixelFormat (const GrProgramDesc &desc) const
 
bool isMac () const
 
bool isApple () const
 
size_t getMinBufferAlignment () const
 
bool storeAndMultisampleResolveSupport () const
 
bool renderTargetSupportsDiscardableMSAA (const GrMtlRenderTarget *) const
 
void onDumpJSON (SkJSONWriter *) const override
 
- Public Member Functions inherited from GrCaps
 GrCaps (const GrContextOptions &)
 
void dumpJSON (SkJSONWriter *) const
 
const GrShaderCapsshaderCaps () const
 
bool npotTextureTileSupport () const
 
bool mipmapSupport () const
 
bool anisoSupport () const
 
bool gpuTracingSupport () const
 
bool oversizedStencilSupport () const
 
bool textureBarrierSupport () const
 
bool sampleLocationsSupport () const
 
bool drawInstancedSupport () const
 
bool nativeDrawIndirectSupport () const
 
bool useClientSideIndirectBuffers () const
 
bool conservativeRasterSupport () const
 
bool wireframeSupport () const
 
bool msaaResolvesAutomatically () const
 
bool preferDiscardableMSAAAttachment () const
 
bool halfFloatVertexAttributeSupport () const
 
bool usePrimitiveRestart () const
 
bool preferClientSideDynamicBuffers () const
 
bool preferFullscreenClears () const
 
bool discardStencilValuesAfterRenderPass () const
 
bool twoSidedStencilRefsAndMasksMustMatch () const
 
bool preferVRAMUseOverFlushes () const
 
bool avoidStencilBuffers () const
 
bool avoidWritePixelsFastPath () const
 
bool nativeDrawIndexedIndirectIsBroken () const
 
BlendEquationSupport blendEquationSupport () const
 
bool advancedBlendEquationSupport () const
 
bool advancedCoherentBlendEquationSupport () const
 
bool isAdvancedBlendEquationDisabled (skgpu::BlendEquation equation) const
 
bool shouldCollapseSrcOverToSrcWhenAble () const
 
bool mustSyncGpuDuringAbandon () const
 
bool reducedShaderMode () const
 
uint32_t mapBufferFlags () const
 
bool reuseScratchTextures () const
 
bool reuseScratchBuffers () const
 
int maxVertexAttributes () const
 maximum number of attribute values per vertex
 
int maxRenderTargetSize () const
 
int maxPreferredRenderTargetSize () const
 
int maxTextureSize () const
 
int maxWindowRectangles () const
 
bool isWindowRectanglesSupportedForRT (const GrBackendRenderTarget &rt) const
 
uint32_t maxPushConstantsSize () const
 
size_t transferBufferRowBytesAlignment () const
 
size_t transferFromBufferToBufferAlignment () const
 
size_t bufferUpdateDataPreserveAlignment () const
 
bool isFormatCompressed (const GrBackendFormat &format) const
 
int internalMultisampleCount (const GrBackendFormat &format) const
 
bool surfaceSupportsWritePixels (const GrSurface *) const
 
SupportedRead supportedReadPixelsColorType (GrColorType srcColorType, const GrBackendFormat &srcFormat, GrColorType dstColorType) const
 
bool writePixelsRowBytesSupport () const
 
bool transferPixelsToRowBytesSupport () const
 
bool readPixelsRowBytesSupport () const
 
bool transferFromSurfaceToBufferSupport () const
 
bool transferFromBufferToTextureSupport () const
 
bool transferFromBufferToBufferSupport () const
 
bool suppressPrints () const
 
size_t bufferMapThreshold () const
 
bool mustClearUploadedBufferData () const
 
bool shouldInitializeTextures () const
 
bool buffersAreInitiallyZero () const
 
bool supportsAHardwareBufferImages () const
 
bool wireframeMode () const
 
bool semaphoreSupport () const
 
bool backendSemaphoreSupport () const
 
bool finishedProcAsyncCallbackSupport () const
 
bool crossContextTextureSupport () const
 
bool canCopySurface (const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const
 
bool dynamicStateArrayGeometryProcessorTextureSupport () const
 
bool supportsProtectedContent () const
 
bool performPartialClearsAsDraws () const
 
bool performColorClearsAsDraws () const
 
bool avoidLargeIndexBufferDraws () const
 
bool performStencilClearsAsDraws () const
 
bool disableTessellationPathRenderer () const
 
GrDstSampleFlags getDstSampleFlagsForProxy (const GrRenderTargetProxy *, bool drawUsesMSAA) const
 
bool validateSurfaceParams (const SkISize &, const GrBackendFormat &, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped, GrTextureType) const
 
bool areColorTypeAndFormatCompatible (GrColorType grCT, const GrBackendFormat &format) const
 
GrBackendFormat getDefaultBackendFormat (GrColorType, GrRenderable) const
 
bool clampToBorderSupport () const
 
skgpu::Swizzle getReadSwizzle (const GrBackendFormat &format, GrColorType colorType) const
 
const GrDriverBugWorkaroundsworkarounds () const
 
virtual void addExtraSamplerKey (skgpu::KeyBuilder *, GrSamplerState, const GrBackendFormat &) const
 
 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS (ProgramDescOverrideFlags)
 
virtual GrInternalSurfaceFlags getExtraSurfaceFlagsForDeferredRT () const
 
bool supportsDynamicMSAA (const GrRenderTargetProxy *) const
 
virtual bool dmsaaResolveCanBeUsedAsTextureInSameRenderPass () const
 
bool avoidReorderingRenderTasks () const
 
bool avoidDithering () const
 
bool disablePerspectiveSDFText () const
 
bool avoidLineDraws () const
 
std::tuple< GrColorType, GrBackendFormatgetFallbackColorTypeAndFormat (GrColorType, int sampleCount) const
 
- Public Member Functions inherited from SkCapabilities
SkSL::Version skslVersion () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Private Member Functions

bool onSurfaceSupportsWritePixels (const GrSurface *) const override
 
bool onCanCopySurface (const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const override
 
GrBackendFormat onGetDefaultBackendFormat (GrColorType) const override
 
bool onAreColorTypeAndFormatCompatible (GrColorType, const GrBackendFormat &) const override
 
SupportedRead onSupportedReadPixelsColorType (GrColorType, const GrBackendFormat &, GrColorType) const override
 
skgpu::Swizzle onGetReadSwizzle (const GrBackendFormat &, GrColorType) const override
 

Additional Inherited Members

- Public Types inherited from GrCaps
enum  BlendEquationSupport { kBasic_BlendEquationSupport , kAdvanced_BlendEquationSupport , kAdvancedCoherent_BlendEquationSupport , kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport }
 
enum  MapFlags { kNone_MapFlags = 0x0 , kCanMap_MapFlag = 0x1 , kSubset_MapFlag = 0x2 , kAsyncRead_MapFlag = 0x4 }
 
enum class  SurfaceReadPixelsSupport { kSupported , kCopyToTexture2D , kUnsupported }
 
enum class  ProgramDescOverrideFlags { kNone = 0 , kVulkanHasResolveLoadSubpass = 0x1 }
 
- Static Public Member Functions inherited from SkCapabilities
static sk_sp< const SkCapabilitiesRasterBackend ()
 
- Protected Member Functions inherited from GrCaps
void finishInitialization (const GrContextOptions &options)
 
virtual bool onSupportsDynamicMSAA (const GrRenderTargetProxy *) const
 
- Protected Member Functions inherited from SkCapabilities
 SkCapabilities ()=default
 
void initSkCaps (const SkSL::ShaderCaps *)
 
- Protected Attributes inherited from GrCaps
std::unique_ptr< GrShaderCapsfShaderCaps
 
bool fNPOTTextureTileSupport: 1
 
bool fMipmapSupport: 1
 
bool fAnisoSupport: 1
 
bool fReuseScratchTextures: 1
 
bool fReuseScratchBuffers: 1
 
bool fGpuTracingSupport: 1
 
bool fOversizedStencilSupport: 1
 
bool fTextureBarrierSupport: 1
 
bool fSampleLocationsSupport: 1
 
bool fDrawInstancedSupport: 1
 
bool fNativeDrawIndirectSupport: 1
 
bool fUseClientSideIndirectBuffers: 1
 
bool fConservativeRasterSupport: 1
 
bool fWireframeSupport: 1
 
bool fMSAAResolvesAutomatically: 1
 
bool fPreferDiscardableMSAAAttachment: 1
 
bool fUsePrimitiveRestart: 1
 
bool fPreferClientSideDynamicBuffers: 1
 
bool fPreferFullscreenClears: 1
 
bool fTwoSidedStencilRefsAndMasksMustMatch: 1
 
bool fMustClearUploadedBufferData: 1
 
bool fBuffersAreInitiallyZero: 1
 
bool fShouldInitializeTextures: 1
 
bool fSupportsAHardwareBufferImages: 1
 
bool fHalfFloatVertexAttributeSupport: 1
 
bool fClampToBorderSupport: 1
 
bool fPerformPartialClearsAsDraws: 1
 
bool fPerformColorClearsAsDraws: 1
 
bool fAvoidLargeIndexBufferDraws: 1
 
bool fPerformStencilClearsAsDraws: 1
 
bool fTransferFromBufferToTextureSupport: 1
 
bool fTransferFromSurfaceToBufferSupport: 1
 
bool fTransferFromBufferToBufferSupport: 1
 
bool fWritePixelsRowBytesSupport: 1
 
bool fTransferPixelsToRowBytesSupport: 1
 
bool fReadPixelsRowBytesSupport: 1
 
bool fShouldCollapseSrcOverToSrcWhenAble: 1
 
bool fMustSyncGpuDuringAbandon: 1
 
bool fDisableTessellationPathRenderer: 1
 
bool fAvoidStencilBuffers: 1
 
bool fAvoidWritePixelsFastPath: 1
 
bool fNativeDrawIndexedIndirectIsBroken: 1
 
bool fAvoidReorderingRenderTasks: 1
 
bool fAvoidDithering: 1
 
bool fDisablePerspectiveSDFText: 1
 
bool fAvoidLineDraws: 1
 
bool fPreferVRAMUseOverFlushes: 1
 
bool fSemaphoreSupport: 1
 
bool fBackendSemaphoreSupport: 1
 
bool fFinishedProcAsyncCallbackSupport: 1
 
bool fCrossContextTextureSupport: 1
 
bool fDynamicStateArrayGeometryProcessorTextureSupport: 1
 
bool fSupportsProtectedContent: 1
 
BlendEquationSupport fBlendEquationSupport
 
uint32_t fAdvBlendEqDisableFlags
 
uint32_t fMapBufferFlags
 
int fBufferMapThreshold
 
int fMaxRenderTargetSize
 
int fMaxPreferredRenderTargetSize
 
int fMaxVertexAttributes
 
int fMaxTextureSize
 
int fMaxWindowRectangles
 
int fInternalMultisampleCount
 
uint32_t fMaxPushConstantsSize = 0
 
size_t fTransferBufferRowBytesAlignment = 1
 
size_t fTransferFromBufferToBufferAlignment = 1
 
size_t fBufferUpdateDataPreserveAlignment = 1
 
GrDriverBugWorkarounds fDriverBugWorkarounds
 
- Protected Attributes inherited from SkCapabilities
SkSL::Version fSkSLVersion = SkSL::Version::k100
 

Detailed Description

Stores some capabilities of a Mtl backend.

Definition at line 23 of file GrMtlCaps.h.

Constructor & Destructor Documentation

◆ GrMtlCaps()

GR_NORETAIN_BEGIN GrMtlCaps::GrMtlCaps ( const GrContextOptions contextOptions,
id< MTLDevice >  device 
)

Definition at line 40 of file GrMtlCaps.mm.

41 : INHERITED(contextOptions) {
42 fShaderCaps = std::make_unique<GrShaderCaps>();
43
44 this->initGPUFamily(device);
45 this->initGrCaps(device);
46 this->initShaderCaps();
47 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
48 this->applyDriverCorrectnessWorkarounds(contextOptions, device);
49 }
50
51 this->initFormatTable();
52 this->initStencilFormat(device);
53
54 // TODO: appears to be slow with Mac msaa8, disabled for now
55 fStoreAndMultisampleResolveSupport = (fGPUFamily == GPUFamily::kApple &&
56 fFamilyGroup >= 3);
57 // Also slow with non-Apple silicon
58 fPreferDiscardableMSAAAttachment = (fGPUFamily == GPUFamily::kApple);
59
60 this->finishInitialization(contextOptions);
61}
std::unique_ptr< GrShaderCaps > fShaderCaps
Definition GrCaps.h:584
void finishInitialization(const GrContextOptions &options)
Definition GrCaps.cpp:107
bool fPreferDiscardableMSAAAttachment
Definition GrCaps.h:601
VkDevice device
Definition main.cc:53
bool fDisableDriverCorrectnessWorkarounds

Member Function Documentation

◆ canCopyAsBlit()

bool GrMtlCaps::canCopyAsBlit ( MTLPixelFormat  dstFormat,
int  dstSampleCount,
MTLPixelFormat  srcFormat,
int  srcSampleCount,
const SkIRect srcRect,
const SkIPoint dstPoint,
bool  areDstSrcSameObj 
) const

Definition at line 268 of file GrMtlCaps.mm.

271 {
272 if (!dstFormat || dstFormat != srcFormat) {
273 return false;
274 }
275 if ((dstSampleCount > 1 || srcSampleCount > 1) && (dstSampleCount != srcSampleCount)) {
276 return false;
277 }
278 if (areDstSrcSameObj) {
279 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.x(), dstPoint.y(),
280 srcRect.width(), srcRect.height());
281 if (dstRect.intersect(srcRect)) {
282 return false;
283 }
284 }
285 return true;
286}
constexpr int32_t y() const
constexpr int32_t x() const
bool intersect(const SkIRect &r)
Definition SkRect.h:513
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104

◆ canCopyAsResolve()

bool GrMtlCaps::canCopyAsResolve ( MTLPixelFormat  dstFormat,
int  dstSampleCount,
MTLPixelFormat  srcFormat,
int  srcSampleCount,
bool  srcIsRenderTarget,
const SkISize  srcDimensions,
const SkIRect srcRect,
const SkIPoint dstPoint,
bool  areDstSrcSameObj 
) const

Definition at line 288 of file GrMtlCaps.mm.

293 {
294 if (areDstSrcSameObj) {
295 return false;
296 }
297 if (dstFormat != srcFormat) {
298 return false;
299 }
300 if (dstSampleCount > 1 || srcSampleCount == 1 || !srcIsRenderTarget) {
301 return false;
302 }
303
304 // TODO: Support copying subrectangles
305 if (dstPoint != SkIPoint::Make(0, 0)) {
306 return false;
307 }
308 if (srcRect != SkIRect::MakeSize(srcDimensions)) {
309 return false;
310 }
311
312 return true;
313}
static constexpr SkIPoint Make(int32_t x, int32_t y)
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ computeFormatKey()

uint64_t GrMtlCaps::computeFormatKey ( const GrBackendFormat format) const
overridevirtual

Implements GrCaps.

Definition at line 1147 of file GrMtlCaps.mm.

1147 {
1148 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
1149 SkASSERT(mtlFormat != MTLPixelFormatInvalid);
1150 // A MTLPixelFormat is an NSUInteger type which is documented to be 32 bits in 32 bit
1151 // applications and 64 bits in 64 bit applications. So it should fit in an uint64_t, but adding
1152 // the assert heere to make sure.
1153 static_assert(sizeof(MTLPixelFormat) <= sizeof(uint64_t));
1154 return (uint64_t)mtlFormat;
1155}
static MTLPixelFormat GrBackendFormatAsMTLPixelFormat(const GrBackendFormat &format)
Definition GrMtlUtil.h:106
#define SkASSERT(cond)
Definition SkAssert.h:116
uint32_t uint32_t * format

◆ getBackendFormatFromCompressionType()

GrBackendFormat GrMtlCaps::getBackendFormatFromCompressionType ( SkTextureCompressionType  compressionType) const
overridevirtual

Implements GrCaps.

Definition at line 1082 of file GrMtlCaps.mm.

1083 {
1084 switch (compressionType) {
1086 return {};
1088 if (@available(macOS 11.0, *)) {
1089 if (this->isApple()) {
1090 return GrBackendFormats::MakeMtl(MTLPixelFormatETC2_RGB8);
1091 } else {
1092 return {};
1093 }
1094 } else {
1095 return {};
1096 }
1098 // Metal only supports the RGBA BC1 variant (see following)
1099 return {};
1101#ifdef SK_BUILD_FOR_MAC
1102 if (this->isMac()) {
1103 return GrBackendFormats::MakeMtl(MTLPixelFormatBC1_RGBA);
1104 } else {
1105 return {};
1106 }
1107#else
1108 return {};
1109#endif
1110
1111 }
1112 SK_ABORT("Invalid compression type");
1113}
#define SK_ABORT(message,...)
Definition SkAssert.h:70
bool isApple() const
Definition GrMtlCaps.h:90
bool isMac() const
Definition GrMtlCaps.h:89
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)

◆ getDstCopyRestrictions()

GrCaps::DstCopyRestrictions GrMtlCaps::getDstCopyRestrictions ( const GrRenderTargetProxy src,
GrColorType  ct 
) const
overridevirtual

Reimplemented from GrCaps.

Definition at line 1046 of file GrMtlCaps.mm.

1047 {
1048 // If the src is a MSAA RT then the only supported copy action (not considering falling back
1049 // to a draw) is to resolve from the MSAA src to the non-MSAA dst. Currently we only support
1050 // resolving the entire texture to a resolve buffer of the same size.
1051 DstCopyRestrictions restrictions = {};
1052 if (auto rtProxy = src->asRenderTargetProxy()) {
1053 if (rtProxy->numSamples() > 1) {
1054 restrictions.fMustCopyWholeSrc = true;
1055 restrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
1056 }
1057 }
1058 return restrictions;
1059}

◆ getFormatFromColorType()

MTLPixelFormat GrMtlCaps::getFormatFromColorType ( GrColorType  colorType) const
inline

Definition at line 75 of file GrMtlCaps.h.

75 {
76 int idx = static_cast<int>(colorType);
77 return fColorTypeToFormatTable[idx];
78 }
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)

◆ getMinBufferAlignment()

size_t GrMtlCaps::getMinBufferAlignment ( ) const
inline

Definition at line 92 of file GrMtlCaps.h.

92{ return this->isMac() ? 4 : 1; }

◆ getRenderTargetSampleCount() [1/2]

int GrMtlCaps::getRenderTargetSampleCount ( int  requestedCount,
const GrBackendFormat format 
) const
overridevirtual

Implements GrCaps.

Definition at line 512 of file GrMtlCaps.mm.

513 {
514 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
515
516 return this->getRenderTargetSampleCount(requestedCount, mtlFormat);
517}
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const override
Definition GrMtlCaps.mm:512

◆ getRenderTargetSampleCount() [2/2]

int GrMtlCaps::getRenderTargetSampleCount ( int  requestedCount,
MTLPixelFormat  format 
) const

Definition at line 519 of file GrMtlCaps.mm.

519 {
520 requestedCount = std::max(requestedCount, 1);
521 const FormatInfo& formatInfo = this->getFormatInfo(format);
522 if (!(formatInfo.fFlags & FormatInfo::kRenderable_Flag)) {
523 return 0;
524 }
525 if (formatInfo.fFlags & FormatInfo::kMSAA_Flag) {
526 int count = fSampleCounts.size();
527 for (int i = 0; i < count; ++i) {
528 if (fSampleCounts[i] >= requestedCount) {
529 return fSampleCounts[i];
530 }
531 }
532 }
533 return 1 == requestedCount ? 1 : 0;
534}
int count
int size() const
Definition SkTDArray.h:138

◆ getStencilPixelFormat()

MTLPixelFormat GrMtlCaps::getStencilPixelFormat ( const GrProgramDesc desc) const

Definition at line 1239 of file GrMtlCaps.mm.

1239 {
1240 // Set up read buffer to point to platform-dependent part of the key
1241 SkReadBuffer readBuffer(desc.asKey() + desc.initialKeyLength()/sizeof(uint32_t),
1242 desc.keyLength() - desc.initialKeyLength());
1243 // skip backend format
1244 readBuffer.readUInt();
1245 // skip raster samples
1246 readBuffer.readUInt();
1247
1248 return (MTLPixelFormat) readBuffer.readUInt();
1249}

◆ getWriteSwizzle()

skgpu::Swizzle GrMtlCaps::getWriteSwizzle ( const GrBackendFormat ,
GrColorType   
) const
overridevirtual

Returns the skgpu::Swizzle to use when writing colors to a surface with the passed in GrBackendFormat and GrColorType.

Implements GrCaps.

Definition at line 1131 of file GrMtlCaps.mm.

1132 {
1133 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
1134 SkASSERT(mtlFormat != MTLPixelFormatInvalid);
1135 const auto& info = this->getFormatInfo(mtlFormat);
1136 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1137 const auto& ctInfo = info.fColorTypeInfos[i];
1138 if (ctInfo.fColorType == colorType) {
1139 return ctInfo.fWriteSwizzle;
1140 }
1141 }
1142 SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", (int)colorType,
1143 static_cast<int>(mtlFormat));
1144 return {};
1145}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119

◆ isApple()

bool GrMtlCaps::isApple ( ) const
inline

Definition at line 90 of file GrMtlCaps.h.

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

◆ isFormatAsColorTypeRenderable()

bool GrMtlCaps::isFormatAsColorTypeRenderable ( GrColorType  ct,
const GrBackendFormat format,
int  sampleCount = 1 
) const
overridevirtual

Implements GrCaps.

Definition at line 476 of file GrMtlCaps.mm.

477 {
478 if (!this->isFormatRenderable(format, sampleCount)) {
479 return false;
480 }
481 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
482 SkASSERT(mtlFormat != MTLPixelFormatInvalid);
483 const auto& info = this->getFormatInfo(mtlFormat);
484 if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
485 return false;
486 }
487 return true;
488}
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
Definition GrMtlCaps.mm:490

◆ isFormatCopyable()

bool GrMtlCaps::isFormatCopyable ( const GrBackendFormat ) const
inlineoverridevirtual

Implements GrCaps.

Definition at line 32 of file GrMtlCaps.h.

32{ return true; }

◆ isFormatRenderable() [1/2]

bool GrMtlCaps::isFormatRenderable ( const GrBackendFormat format,
int  sampleCount 
) const
overridevirtual

Implements GrCaps.

Definition at line 490 of file GrMtlCaps.mm.

490 {
491 return this->isFormatRenderable(GrBackendFormatAsMTLPixelFormat(format), sampleCount);
492}

◆ isFormatRenderable() [2/2]

bool GrMtlCaps::isFormatRenderable ( MTLPixelFormat  format,
int  sampleCount 
) const

Definition at line 494 of file GrMtlCaps.mm.

494 {
495 return sampleCount <= this->maxRenderTargetSampleCount(format);
496}
int maxRenderTargetSampleCount(const GrBackendFormat &) const override
Definition GrMtlCaps.mm:498

◆ isFormatSRGB()

bool GrMtlCaps::isFormatSRGB ( const GrBackendFormat format) const
overridevirtual

Implements GrCaps.

Definition at line 462 of file GrMtlCaps.mm.

462 {
464}
static bool format_is_srgb(MTLPixelFormat format)
Definition GrMtlCaps.mm:452

◆ isFormatTexturable() [1/2]

bool GrMtlCaps::isFormatTexturable ( const GrBackendFormat format,
GrTextureType   
) const
overridevirtual

Implements GrCaps.

Definition at line 466 of file GrMtlCaps.mm.

466 {
467 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
468 return this->isFormatTexturable(mtlFormat);
469}
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
Definition GrMtlCaps.mm:466

◆ isFormatTexturable() [2/2]

bool GrMtlCaps::isFormatTexturable ( MTLPixelFormat  format) const

Definition at line 471 of file GrMtlCaps.mm.

471 {
472 const FormatInfo& formatInfo = this->getFormatInfo(format);
473 return SkToBool(FormatInfo::kTexturable_Flag & formatInfo.fFlags);
474}

◆ isMac()

bool GrMtlCaps::isMac ( ) const
inline

Definition at line 89 of file GrMtlCaps.h.

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

◆ makeDesc()

GrProgramDesc GrMtlCaps::makeDesc ( GrRenderTarget ,
const GrProgramInfo programInfo,
ProgramDescOverrideFlags  overrideFlags 
) const
overridevirtual

For Metal we want to cache the entire pipeline for reuse of draws. The Desc here holds all the information needed to differentiate one pipeline from another.

The GrProgramDesc contains all the information need to create the actual shaders for the pipeline.

For Metal we need to add to the GrProgramDesc to include the rest of the state on the pipeline. This includes blending information and primitive type. The pipeline is immutable so any remaining dynamic state is set via the MtlRenderCmdEncoder.

Implements GrCaps.

Definition at line 1214 of file GrMtlCaps.mm.

1215 {
1216 SkASSERT(overrideFlags == ProgramDescOverrideFlags::kNone);
1218 GrProgramDesc::Build(&desc, programInfo, *this);
1219
1220 skgpu::KeyBuilder b(desc.key());
1221
1222 // If ordering here is changed, update getStencilPixelFormat() below
1223 b.add32(GrBackendFormats::AsMtlFormat(programInfo.backendFormat()));
1224
1225 b.add32(programInfo.numSamples());
1226
1227 b.add32(programInfo.needsStencil() ? this->preferredStencilFormat() : MTLPixelFormatInvalid);
1228 b.add32((uint32_t)programInfo.isStencilEnabled());
1229 // Stencil samples don't seem to be tracked in the MTLRenderPipeline
1230
1231 programInfo.pipeline().genKey(&b, *this);
1232
1233 b.add32(programInfo.primitiveTypeKey());
1234
1235 b.flush();
1236 return desc;
1237}
void genKey(skgpu::KeyBuilder *, const GrCaps &) const
static void Build(GrProgramDesc *, const GrProgramInfo &, const GrCaps &)
uint16_t primitiveTypeKey() const
int numSamples() const
const GrPipeline & pipeline() const
bool isStencilEnabled() const
int needsStencil() const
const GrBackendFormat & backendFormat() const
static bool b
SK_API GrMTLPixelFormat AsMtlFormat(const GrBackendFormat &)

◆ maxRenderTargetSampleCount() [1/2]

int GrMtlCaps::maxRenderTargetSampleCount ( const GrBackendFormat format) const
overridevirtual

Implements GrCaps.

Definition at line 498 of file GrMtlCaps.mm.

498 {
500}

◆ maxRenderTargetSampleCount() [2/2]

int GrMtlCaps::maxRenderTargetSampleCount ( MTLPixelFormat  format) const

Definition at line 502 of file GrMtlCaps.mm.

502 {
503 const FormatInfo& formatInfo = this->getFormatInfo(format);
504 if (formatInfo.fFlags & FormatInfo::kMSAA_Flag) {
505 return fSampleCounts[fSampleCounts.size() - 1];
506 } else if (formatInfo.fFlags & FormatInfo::kRenderable_Flag) {
507 return 1;
508 }
509 return 0;
510}

◆ onAreColorTypeAndFormatCompatible()

bool GrMtlCaps::onAreColorTypeAndFormatCompatible ( GrColorType  ct,
const GrBackendFormat format 
) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 1061 of file GrMtlCaps.mm.

1062 {
1063 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
1064
1065 const auto& info = this->getFormatInfo(mtlFormat);
1066 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1067 if (info.fColorTypeInfos[i].fColorType == ct) {
1068 return true;
1069 }
1070 }
1071 return false;
1072}

◆ onCanCopySurface()

bool GrMtlCaps::onCanCopySurface ( const GrSurfaceProxy dst,
const SkIRect dstRect,
const GrSurfaceProxy src,
const SkIRect srcRect 
) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 315 of file GrMtlCaps.mm.

316 {
317 // Metal does not support scaling copies
318 if (srcRect.size() != dstRect.size()) {
319 return false;
320 }
321
322 int dstSampleCnt = 1;
323 int srcSampleCnt = 1;
324 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
325 dstSampleCnt = rtProxy->numSamples();
326 }
327 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
328 srcSampleCnt = rtProxy->numSamples();
329 }
330
331 // TODO: need some way to detect whether the proxy is framebufferOnly
332
333 const SkIPoint dstPoint = dstRect.topLeft();
334 if (this->canCopyAsBlit(GrBackendFormatAsMTLPixelFormat(dst->backendFormat()), dstSampleCnt,
335 GrBackendFormatAsMTLPixelFormat(src->backendFormat()), srcSampleCnt,
336 srcRect, dstPoint, dst == src)) {
337 return true;
338 }
339 bool srcIsRenderTarget = src->asRenderTargetProxy();
340 MTLPixelFormat dstFormat = GrBackendFormatAsMTLPixelFormat(dst->backendFormat());
341 MTLPixelFormat srcFormat = GrBackendFormatAsMTLPixelFormat(src->backendFormat());
342 return this->canCopyAsResolve(dstFormat, dstSampleCnt,
343 srcFormat, srcSampleCnt,
344 srcIsRenderTarget, src->backingStoreDimensions(), srcRect,
345 dstPoint,
346 dst == src);
347}
bool canCopyAsBlit(MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
Definition GrMtlCaps.mm:268
bool canCopyAsResolve(MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, bool srcIsRenderTarget, const SkISize srcDimensions, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
Definition GrMtlCaps.mm:288
const GrBackendFormat & backendFormat() const
dst
Definition cp.py:12
constexpr SkISize size() const
Definition SkRect.h:172
constexpr SkIPoint topLeft() const
Definition SkRect.h:151

◆ onDumpJSON()

void GrMtlCaps::onDumpJSON ( SkJSONWriter writer) const
overridevirtual

Reimplemented from GrCaps.

Definition at line 1324 of file GrMtlCaps.mm.

1324{ }

◆ onGetDefaultBackendFormat()

GrBackendFormat GrMtlCaps::onGetDefaultBackendFormat ( GrColorType  ct) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 1074 of file GrMtlCaps.mm.

1074 {
1075 MTLPixelFormat format = this->getFormatFromColorType(ct);
1076 if (!format) {
1077 return {};
1078 }
1080}
MTLPixelFormat getFormatFromColorType(GrColorType colorType) const
Definition GrMtlCaps.h:75

◆ onGetReadSwizzle()

skgpu::Swizzle GrMtlCaps::onGetReadSwizzle ( const GrBackendFormat format,
GrColorType  colorType 
) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 1115 of file GrMtlCaps.mm.

1116 {
1117 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
1118 SkASSERT(mtlFormat != MTLPixelFormatInvalid);
1119 const auto& info = this->getFormatInfo(mtlFormat);
1120 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1121 const auto& ctInfo = info.fColorTypeInfos[i];
1122 if (ctInfo.fColorType == colorType) {
1123 return ctInfo.fReadSwizzle;
1124 }
1125 }
1126 SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.", (int)colorType,
1127 static_cast<int>(mtlFormat));
1128 return {};
1129}

◆ onSupportedReadPixelsColorType()

GrCaps::SupportedRead GrMtlCaps::onSupportedReadPixelsColorType ( GrColorType  srcColorType,
const GrBackendFormat srcBackendFormat,
GrColorType  dstColorType 
) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 1174 of file GrMtlCaps.mm.

1176 {
1177 SkTextureCompressionType compression = GrBackendFormatToCompressionType(srcBackendFormat);
1178 if (compression != SkTextureCompressionType::kNone) {
1179#ifdef SK_BUILD_FOR_IOS
1180 // Reading back to kRGB_888x doesn't work on Metal/iOS (skbug.com/9839)
1181 return { GrColorType::kUnknown, 0 };
1182#else
1185#endif
1186 }
1187
1188 // Metal requires the destination offset for copyFromTexture to be a multiple of the textures
1189 // pixels size.
1190 size_t offsetAlignment = GrColorTypeBytesPerPixel(srcColorType);
1191 MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(srcBackendFormat);
1192
1193 const auto& info = this->getFormatInfo(mtlFormat);
1194 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1195 const auto& ctInfo = info.fColorTypeInfos[i];
1196 if (ctInfo.fColorType == srcColorType) {
1197 return {srcColorType, offsetAlignment};
1198 }
1199 }
1200 return {GrColorType::kUnknown, 0};
1201}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
static constexpr bool SkTextureCompressionTypeIsOpaque(SkTextureCompressionType compression)

◆ onSurfaceSupportsWritePixels()

bool GrMtlCaps::onSurfaceSupportsWritePixels ( const GrSurface surface) const
overrideprivatevirtual

Implements GrCaps.

Definition at line 1022 of file GrMtlCaps.mm.

1022 {
1023 if (auto rt = surface->asRenderTarget()) {
1024 return rt->numSamples() <= 1 && SkToBool(surface->asTexture());
1025 }
1026 return true;
1027}
VkSurfaceKHR surface
Definition main.cc:49

◆ preferredStencilFormat()

MTLPixelFormat GrMtlCaps::preferredStencilFormat ( ) const
inline

Returns both a supported and most prefered stencil format to use in draws.

Definition at line 57 of file GrMtlCaps.h.

57 {
58 return fPreferredStencilFormat;
59 }

◆ renderTargetSupportsDiscardableMSAA()

bool GrMtlCaps::renderTargetSupportsDiscardableMSAA ( const GrMtlRenderTarget rt) const

Definition at line 1251 of file GrMtlCaps.mm.

1251 {
1252 return rt->resolveAttachment() &&
1254 (rt->numSamples() > 1 && this->preferDiscardableMSAAAttachment());
1255}
bool preferDiscardableMSAAAttachment() const
Definition GrCaps.h:107
bool framebufferOnly() const
GrMtlAttachment * resolveAttachment() const
int numSamples() const

◆ storeAndMultisampleResolveSupport()

bool GrMtlCaps::storeAndMultisampleResolveSupport ( ) const
inline

Definition at line 95 of file GrMtlCaps.h.

95{ return fStoreAndMultisampleResolveSupport; }

◆ supportedWritePixelsColorType()

GrCaps::SupportedWrite GrMtlCaps::supportedWritePixelsColorType ( GrColorType  surfaceColorType,
const GrBackendFormat surfaceFormat,
GrColorType  srcColorType 
) const
overridevirtual

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 GrGpu::writePixels().

Implements GrCaps.

Definition at line 1157 of file GrMtlCaps.mm.

1159 {
1160 // Metal requires the destination offset for copyFromTexture to be a multiple of the textures
1161 // pixels size.
1162 size_t offsetAlignment = GrColorTypeBytesPerPixel(surfaceColorType);
1163
1164 const auto& info = this->getFormatInfo(GrBackendFormatAsMTLPixelFormat(surfaceFormat));
1165 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
1166 const auto& ctInfo = info.fColorTypeInfos[i];
1167 if (ctInfo.fColorType == surfaceColorType) {
1168 return {surfaceColorType, offsetAlignment};
1169 }
1170 }
1171 return {GrColorType::kUnknown, 0};
1172}

◆ surfaceSupportsReadPixels()

GrCaps::SurfaceReadPixelsSupport GrMtlCaps::surfaceSupportsReadPixels ( const GrSurface ) const
overridevirtual

Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may either be able to read directly from the surface, read from a copy of the surface, or not read at all.

Implements GrCaps.

Definition at line 1029 of file GrMtlCaps.mm.

1030 {
1031 if (auto tex = static_cast<const GrMtlTexture*>(surface->asTexture())) {
1032 // We disallow reading back directly from compressed textures.
1033 if (skgpu::MtlFormatIsCompressed(tex->attachment()->mtlFormat())) {
1035 }
1036 }
1037
1038 if (auto mtlRT = static_cast<const GrMtlRenderTarget*>(surface->asRenderTarget())) {
1039 if (mtlRT->numSamples() > 1 && !mtlRT->resolveAttachment()) {
1041 }
1042 }
1044}
bool MtlFormatIsCompressed(MTLPixelFormat mtlFormat)
Definition MtlUtils.mm:49

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