Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::graphite::MtlResourceProvider Class Referencefinal

#include <MtlResourceProvider.h>

Inheritance diagram for skgpu::graphite::MtlResourceProvider:
skgpu::graphite::ResourceProvider

Public Member Functions

 MtlResourceProvider (SharedContext *sharedContext, SingleOwner *, uint32_t recorderID, size_t resourceBudget)
 
 ~MtlResourceProvider () override
 
sk_sp< MtlGraphicsPipelinefindOrCreateLoadMSAAPipeline (const RenderPassDesc &)
 
- Public Member Functions inherited from skgpu::graphite::ResourceProvider
virtual ~ResourceProvider ()
 
sk_sp< GraphicsPipelinefindOrCreateGraphicsPipeline (const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)
 
sk_sp< ComputePipelinefindOrCreateComputePipeline (const ComputePipelineDesc &)
 
sk_sp< TexturefindOrCreateScratchTexture (SkISize, const TextureInfo &, std::string_view label, skgpu::Budgeted)
 
sk_sp< TexturecreateWrappedTexture (const BackendTexture &, std::string_view label)
 
sk_sp< TexturefindOrCreateDepthStencilAttachment (SkISize dimensions, const TextureInfo &)
 
sk_sp< TexturefindOrCreateDiscardableMSAAAttachment (SkISize dimensions, const TextureInfo &)
 
sk_sp< BufferfindOrCreateBuffer (size_t size, BufferType type, AccessPattern, std::string_view label)
 
sk_sp< SamplerfindOrCreateCompatibleSampler (const SamplerDesc &)
 
BackendTexture createBackendTexture (SkISize dimensions, const TextureInfo &)
 
void deleteBackendTexture (const BackendTexture &)
 
ProxyCacheproxyCache ()
 
size_t getResourceCacheLimit () const
 
size_t getResourceCacheCurrentBudgetedBytes () const
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
void freeGpuResources ()
 
void purgeResourcesNotUsedSince (StdSteadyClock::time_point purgeTime)
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::ResourceProvider
 ResourceProvider (SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)
 
- Protected Attributes inherited from skgpu::graphite::ResourceProvider
SharedContextfSharedContext
 
sk_sp< ResourceCachefResourceCache
 

Detailed Description

Definition at line 23 of file MtlResourceProvider.h.

Constructor & Destructor Documentation

◆ MtlResourceProvider()

skgpu::graphite::MtlResourceProvider::MtlResourceProvider ( SharedContext sharedContext,
SingleOwner singleOwner,
uint32_t  recorderID,
size_t  resourceBudget 
)

Definition at line 43 of file MtlResourceProvider.mm.

47 : ResourceProvider(sharedContext, singleOwner, recorderID, resourceBudget) {}
ResourceProvider(SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)

◆ ~MtlResourceProvider()

skgpu::graphite::MtlResourceProvider::~MtlResourceProvider ( )
inlineoverride

Definition at line 29 of file MtlResourceProvider.h.

29{}

Member Function Documentation

◆ findOrCreateLoadMSAAPipeline()

sk_sp< MtlGraphicsPipeline > skgpu::graphite::MtlResourceProvider::findOrCreateLoadMSAAPipeline ( const RenderPassDesc renderPassDesc)

Definition at line 53 of file MtlResourceProvider.mm.

54 {
55 uint64_t renderPassKey =
56 this->mtlSharedContext()->mtlCaps().getRenderPassDescKey(renderPassDesc);
57 sk_sp<MtlGraphicsPipeline> pipeline = fLoadMSAAPipelines[renderPassKey];
58 if (!pipeline) {
59 static const char* kLoadMSAAShaderText = R"(
60 #include <metal_stdlib>
61 #include <simd/simd.h>
62 using namespace metal;
63
64 typedef struct {
65 float4 position [[position]];
66 } VertexOutput;
67
68 vertex VertexOutput vertexMain(uint vertexID [[vertex_id]]) {
69 VertexOutput out;
70 float2 position = float2(float(vertexID >> 1), float(vertexID & 1));
71 out.position = float4(2.0 * position - 1.0, 0.0, 1.0);
72 return out;
73 }
74
75 fragment float4 fragmentMain(VertexOutput in [[stage_in]],
76 texture2d<half> colorMap [[texture(0)]]) {
77 uint2 coords = uint2(in.position.x, in.position.y);
78 half4 colorSample = colorMap.read(coords);
79 return float4(colorSample);
80 }
81 )";
82
83 auto mtlLibrary = MtlCompileShaderLibrary(this->mtlSharedContext(),
84 "LoadMSAAFromResolve",
85 kLoadMSAAShaderText,
87 BlendInfo noBlend{}; // default is equivalent to kSrc blending
88 sk_cfp<id<MTLDepthStencilState>> ignoreDS =
89 this->findOrCreateCompatibleDepthStencilState({});
90
91 std::string pipelineLabel = "LoadMSAAFromResolve + ";
92 pipelineLabel += renderPassDesc.toString().c_str();
93 pipeline = MtlGraphicsPipeline::Make(this->mtlSharedContext(),
94 pipelineLabel,
95 {mtlLibrary.get(), "vertexMain"},
96 /*vertexAttrs=*/{},
97 /*instanceAttrs=*/{},
98 {mtlLibrary.get(), "fragmentMain"},
99 std::move(ignoreDS),
100 /*stencilRefValue=*/0,
101 noBlend,
102 renderPassDesc,
103 /*pipelineInfo=*/nullptr);
104 if (pipeline) {
105 fLoadMSAAPipelines.set(renderPassKey, pipeline);
106 }
107 }
108
skgpu::ShaderErrorHandler * shaderErrorHandler() const
Definition: Caps.h:273
uint64_t getRenderPassDescKey(const RenderPassDesc &) const
Definition: MtlCaps.mm:997
static sk_sp< MtlGraphicsPipeline > Make(const MtlSharedContext *, const std::string &label, MSLFunction vertexMain, SkSpan< const Attribute > vertexAttrs, SkSpan< const Attribute > instanceAttrs, MSLFunction fragmentMain, sk_cfp< id< MTLDepthStencilState > >, uint32_t stencilRefValue, const BlendInfo &blendInfo, const RenderPassDesc &, PipelineInfo *pipelineInfo)
const MtlCaps & mtlCaps() const
const Caps * caps() const
Definition: SharedContext.h:39
sk_cfp< id< MTLLibrary > > MtlCompileShaderLibrary(const MtlSharedContext *sharedContext, std::string_view label, std::string_view msl, ShaderErrorHandler *errorHandler)

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