Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private 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< TexturecreateWrappedTexture (const BackendTexture &) 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 &, skgpu::Budgeted)
 
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)
 

Private Member Functions

sk_sp< GraphicsPipelinecreateGraphicsPipeline (const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &) override
 
sk_sp< ComputePipelinecreateComputePipeline (const ComputePipelineDesc &) override
 
sk_sp< TexturecreateTexture (SkISize, const TextureInfo &, skgpu::Budgeted) override
 
sk_sp< BuffercreateBuffer (size_t size, BufferType type, AccessPattern, std::string_view label) override
 
sk_sp< SamplercreateSampler (const SamplerDesc &) override
 
BackendTexture onCreateBackendTexture (SkISize dimensions, const TextureInfo &) override
 
void onDeleteBackendTexture (const BackendTexture &) override
 

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) {}

◆ ~MtlResourceProvider()

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

Definition at line 29 of file MtlResourceProvider.h.

29{}

Member Function Documentation

◆ createBuffer()

sk_sp< Buffer > skgpu::graphite::MtlResourceProvider::createBuffer ( size_t  size,
BufferType  type,
AccessPattern  accessPattern,
std::string_view  label 
)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 258 of file MtlResourceProvider.mm.

263 {

◆ createComputePipeline()

sk_sp< ComputePipeline > skgpu::graphite::MtlResourceProvider::createComputePipeline ( const ComputePipelineDesc pipelineDesc)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 197 of file MtlResourceProvider.mm.

200 {
201 sk_cfp<id<MTLLibrary>> library;
202 std::string entryPointName;
203 ShaderErrorHandler* errorHandler = fSharedContext->caps()->shaderErrorHandler();
204 if (pipelineDesc.computeStep()->supportsNativeShader()) {
205 auto nativeShader = pipelineDesc.computeStep()->nativeShaderSource(
207 library = MtlCompileShaderLibrary(this->mtlSharedContext(),
208 pipelineDesc.computeStep()->name(),
209 nativeShader.fSource,
210 errorHandler);
211 if (library == nil) {
212 return nullptr;
213 }
214 entryPointName = std::move(nativeShader.fEntryPoint);
215 } else {
216 std::string msl;
217 SkSL::Program::Interface interface;
219
220 SkSL::Compiler skslCompiler;
221 std::string sksl = BuildComputeSkSL(fSharedContext->caps(), pipelineDesc.computeStep());
223 sksl,
225 settings,
226 &msl,
227 &interface,
228 errorHandler)) {
229 return nullptr;
230 }
231 library = MtlCompileShaderLibrary(this->mtlSharedContext(),
232 pipelineDesc.computeStep()->name(),
233 msl,
234 errorHandler);
235 entryPointName = "computeMain";
236 }
237 return MtlComputePipeline::Make(this->mtlSharedContext(),
238 pipelineDesc.computeStep()->name(),
skgpu::ShaderErrorHandler * shaderErrorHandler() const
Definition Caps.h:266
const SkSL::ShaderCaps * shaderCaps() const
Definition Caps.h:74
static sk_sp< MtlComputePipeline > Make(const MtlSharedContext *, const std::string &label, MSLFunction computeMain)
const Caps * caps() const
std::string BuildComputeSkSL(const Caps *caps, const ComputeStep *step)
sk_cfp< id< MTLLibrary > > MtlCompileShaderLibrary(const MtlSharedContext *sharedContext, std::string_view label, std::string_view msl, ShaderErrorHandler *errorHandler)
bool SkSLToMSL(const SkSL::ShaderCaps *caps, const std::string &sksl, SkSL::ProgramKind programKind, const SkSL::ProgramSettings &settings, std::string *msl, SkSL::ProgramInterface *outInterface, ShaderErrorHandler *errorHandler)

◆ createGraphicsPipeline()

sk_sp< GraphicsPipeline > skgpu::graphite::MtlResourceProvider::createGraphicsPipeline ( const RuntimeEffectDictionary runtimeDict,
const GraphicsPipelineDesc pipelineDesc,
const RenderPassDesc renderPassDesc 
)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 110 of file MtlResourceProvider.mm.

115 {
116 std::string vsMSL, fsMSL;
117 SkSL::Program::Interface vsInterface, fsInterface;
119
120 settings.fForceNoRTFlip = true;
121
122 SkSL::Compiler skslCompiler;
123 ShaderErrorHandler* errorHandler = fSharedContext->caps()->shaderErrorHandler();
124
125 const RenderStep* step =
126 fSharedContext->rendererProvider()->lookup(pipelineDesc.renderStepID());
127 const bool useStorageBuffers = fSharedContext->caps()->storageBufferPreferred();
128
129 UniquePaintParamsID paintID = pipelineDesc.paintParamsID();
130 FragSkSLInfo fsSkSLInfo = BuildFragmentSkSL(fSharedContext->caps(),
132 runtimeDict,
133 step,
134 paintID,
135 useStorageBuffers,
136 renderPassDesc.fWriteSwizzle);
137 std::string& fsSkSL = fsSkSLInfo.fSkSL;
138 const BlendInfo& blendInfo = fsSkSLInfo.fBlendInfo;
139 const bool localCoordsNeeded = fsSkSLInfo.fRequiresLocalCoords;
141 fsSkSL,
143 settings,
144 &fsMSL,
145 &fsInterface,
146 errorHandler)) {
147 return nullptr;
148 }
149
150 VertSkSLInfo vsSkSLInfo = BuildVertexSkSL(fSharedContext->caps()->resourceBindingRequirements(),
151 step,
152 useStorageBuffers,
153 localCoordsNeeded);
154 const std::string& vsSkSL = vsSkSLInfo.fSkSL;
156 vsSkSL,
158 settings,
159 &vsMSL,
160 &vsInterface,
161 errorHandler)) {
162 return nullptr;
163 }
164
165 auto vsLibrary = MtlCompileShaderLibrary(
166 this->mtlSharedContext(), vsSkSLInfo.fLabel, vsMSL, errorHandler);
167 auto fsLibrary = MtlCompileShaderLibrary(
168 this->mtlSharedContext(), fsSkSLInfo.fLabel, fsMSL, errorHandler);
169
170 sk_cfp<id<MTLDepthStencilState>> dss =
171 this->findOrCreateCompatibleDepthStencilState(step->depthStencilSettings());
172
173#if defined(GRAPHITE_TEST_UTILS)
174 GraphicsPipeline::PipelineInfo pipelineInfo = {pipelineDesc.renderStepID(),
175 pipelineDesc.paintParamsID(),
176 std::move(vsSkSL),
177 std::move(fsSkSL),
178 std::move(vsMSL),
179 std::move(fsMSL) };
180 GraphicsPipeline::PipelineInfo* pipelineInfoPtr = &pipelineInfo;
181#else
182 GraphicsPipeline::PipelineInfo* pipelineInfoPtr = nullptr;
183#endif
184 std::string pipelineLabel =
185 GetPipelineLabel(fSharedContext->shaderCodeDictionary(), renderPassDesc, step, paintID);
186 return MtlGraphicsPipeline::Make(this->mtlSharedContext(),
187 pipelineLabel,
188 {vsLibrary.get(), "vertexMain"},
189 step->vertexAttributes(),
190 step->instanceAttributes(),
191 {fsLibrary.get(), "fragmentMain"},
192 std::move(dss),
193 step->depthStencilSettings().fStencilReferenceValue,
194 blendInfo,
195 renderPassDesc,
static int step(int x, SkScalar min, SkScalar max)
Definition BlurTest.cpp:215
const ResourceBindingRequirements & resourceBindingRequirements() const
Definition Caps.h:143
bool storageBufferPreferred() const
Definition Caps.h:232
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 RenderStep * lookup(uint32_t uniqueID) const
ShaderCodeDictionary * shaderCodeDictionary()
const RendererProvider * rendererProvider() const
VertSkSLInfo BuildVertexSkSL(const ResourceBindingRequirements &bindingReqs, const RenderStep *step, bool useStorageBuffers, bool defineLocalCoordsVarying)
FragSkSLInfo BuildFragmentSkSL(const Caps *caps, const ShaderCodeDictionary *dict, const RuntimeEffectDictionary *rteDict, const RenderStep *step, UniquePaintParamsID paintID, bool useStorageBuffers, skgpu::Swizzle writeSwizzle)
std::string GetPipelineLabel(const ShaderCodeDictionary *dict, const RenderPassDesc &renderPassDesc, const RenderStep *renderStep, UniquePaintParamsID paintID)

◆ createSampler()

sk_sp< Sampler > skgpu::graphite::MtlResourceProvider::createSampler ( const SamplerDesc samplerDesc)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 265 of file MtlResourceProvider.mm.

267 {
268 return MtlSampler::Make(this->mtlSharedContext(),
269 samplerDesc.samplingOptions(),
270 samplerDesc.tileModeX(),
static sk_sp< MtlSampler > Make(const MtlSharedContext *, const SkSamplingOptions &samplingOptions, SkTileMode xTileMode, SkTileMode yTileMode)
Definition MtlSampler.mm:47

◆ createTexture()

sk_sp< Texture > skgpu::graphite::MtlResourceProvider::createTexture ( SkISize  dimensions,
const TextureInfo info,
skgpu::Budgeted  budgeted 
)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 240 of file MtlResourceProvider.mm.

244 {

◆ createWrappedTexture()

sk_sp< Texture > skgpu::graphite::MtlResourceProvider::createWrappedTexture ( const BackendTexture texture)
overridevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 246 of file MtlResourceProvider.mm.

248 {
249 CFTypeRef mtlHandleTexture = texture.getMtlTexture();
250 if (!mtlHandleTexture) {
251 return nullptr;
252 }
253 sk_cfp<id<MTLTexture>> mtlTexture = sk_ret_cfp((id<MTLTexture>)mtlHandleTexture);
254 return MtlTexture::MakeWrapped(this->mtlSharedContext(),
255 texture.dimensions(),
256 texture.info(),
static sk_sp< Texture > MakeWrapped(const MtlSharedContext *, SkISize dimensions, const TextureInfo &, sk_cfp< id< MTLTexture > >)
FlTexture * texture

◆ 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
uint64_t getRenderPassDescKey(const RenderPassDesc &) const
Definition MtlCaps.mm:1055
const MtlCaps & mtlCaps() const

◆ onCreateBackendTexture()

BackendTexture skgpu::graphite::MtlResourceProvider::onCreateBackendTexture ( SkISize  dimensions,
const TextureInfo info 
)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 352 of file MtlResourceProvider.mm.

355 {
356 sk_cfp<id<MTLTexture>> texture = MtlTexture::MakeMtlTexture(this->mtlSharedContext(),
357 dimensions,
358 info);
359 if (!texture) {
360 return {};
361 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static sk_cfp< id< MTLTexture > > MakeMtlTexture(const MtlSharedContext *, SkISize dimensions, const TextureInfo &)
Definition MtlTexture.mm:20

◆ onDeleteBackendTexture()

void skgpu::graphite::MtlResourceProvider::onDeleteBackendTexture ( const BackendTexture texture)
overrideprivatevirtual

Implements skgpu::graphite::ResourceProvider.

Definition at line 363 of file MtlResourceProvider.mm.

365 {
366 SkASSERT(texture.backend() == BackendApi::kMetal);
367 CFTypeRef texHandle = texture.getMtlTexture();
#define SkASSERT(cond)
Definition SkAssert.h:116

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