Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
GrMtlResourceProvider Class Reference

#include <GrMtlResourceProvider.h>

Public Member Functions

 GrMtlResourceProvider (GrMtlGpu *gpu)
 
GrMtlPipelineStatefindOrCreateCompatiblePipelineState (const GrProgramDesc &, const GrProgramInfo &, GrThreadSafePipelineBuilder::Stats::ProgramCacheResult *stat=nullptr)
 
bool precompileShader (const SkData &key, const SkData &data)
 
GrMtlDepthStencilfindOrCreateCompatibleDepthStencilState (const GrStencilSettings &, GrSurfaceOrigin)
 
GrMtlSamplerfindOrCreateCompatibleSampler (GrSamplerState)
 
const GrMtlRenderPipelinefindOrCreateMSAALoadPipeline (MTLPixelFormat colorFormat, int sampleCount, MTLPixelFormat stencilFormat)
 
void destroyResources ()
 

Detailed Description

Definition at line 28 of file GrMtlResourceProvider.h.

Constructor & Destructor Documentation

◆ GrMtlResourceProvider()

GR_NORETAIN_BEGIN GrMtlResourceProvider::GrMtlResourceProvider ( GrMtlGpu gpu)

Definition at line 28 of file GrMtlResourceProvider.mm.

29 : fGpu(gpu) {
30 fPipelineStateCache = std::make_unique<PipelineStateCache>(gpu);
31}

Member Function Documentation

◆ destroyResources()

void GrMtlResourceProvider::destroyResources ( )

Definition at line 157 of file GrMtlResourceProvider.mm.

157 {
158 fMSAALoadLibrary = nil;
159 fMSAALoadPipelines.clear();
160
161 fSamplers.foreach([&](GrMtlSampler* sampler) { sampler->unref(); });
162 fSamplers.reset();
163
164 fDepthStencilStates.foreach([&](GrMtlDepthStencil* stencil) { stencil->unref(); });
165 fDepthStencilStates.reset();
166
167 fPipelineStateCache->release();
168}
void foreach(Fn &&fn)

◆ findOrCreateCompatibleDepthStencilState()

GrMtlDepthStencil * GrMtlResourceProvider::findOrCreateCompatibleDepthStencilState ( const GrStencilSettings stencil,
GrSurfaceOrigin  origin 
)

Definition at line 46 of file GrMtlResourceProvider.mm.

47 {
48 GrMtlDepthStencil* depthStencilState;
50 depthStencilState = fDepthStencilStates.find(key);
51 if (!depthStencilState) {
52 depthStencilState = GrMtlDepthStencil::Create(fGpu, stencil, origin);
53 fDepthStencilStates.add(depthStencilState);
54 }
55 SkASSERT(depthStencilState);
56 return depthStencilState;
57}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static Key GenerateKey(const GrStencilSettings &, GrSurfaceOrigin)
static GrMtlDepthStencil * Create(const GrMtlGpu *, const GrStencilSettings &, GrSurfaceOrigin)
T * find(const Key &key) const
void add(T *entry)

◆ findOrCreateCompatiblePipelineState()

GrMtlPipelineState * GrMtlResourceProvider::findOrCreateCompatiblePipelineState ( const GrProgramDesc programDesc,
const GrProgramInfo programInfo,
GrThreadSafePipelineBuilder::Stats::ProgramCacheResult stat = nullptr 
)

Definition at line 33 of file GrMtlResourceProvider.mm.

36 {
37 return fPipelineStateCache->refPipelineState(programDesc, programInfo, stat);
38}

◆ findOrCreateCompatibleSampler()

GrMtlSampler * GrMtlResourceProvider::findOrCreateCompatibleSampler ( GrSamplerState  params)

Definition at line 59 of file GrMtlResourceProvider.mm.

59 {
60 GrMtlSampler* sampler;
61 sampler = fSamplers.find(GrMtlSampler::GenerateKey(params));
62 if (!sampler) {
63 sampler = GrMtlSampler::Create(fGpu, params);
64 fSamplers.add(sampler);
65 }
66 SkASSERT(sampler);
67 return sampler;
68}
static Key GenerateKey(GrSamplerState)
Definition: GrMtlSampler.mm:85
static GrMtlSampler * Create(const GrMtlGpu *gpu, GrSamplerState)
Definition: GrMtlSampler.mm:45
const EmbeddedViewParams * params

◆ findOrCreateMSAALoadPipeline()

const GrMtlRenderPipeline * GrMtlResourceProvider::findOrCreateMSAALoadPipeline ( MTLPixelFormat  colorFormat,
int  sampleCount,
MTLPixelFormat  stencilFormat 
)

Definition at line 70 of file GrMtlResourceProvider.mm.

71 {
72 if (!fMSAALoadLibrary) {
73 TRACE_EVENT0("skia", TRACE_FUNC);
74
75 std::string shaderText;
76 shaderText.append(
77 "#include <metal_stdlib>\n"
78 "#include <simd/simd.h>\n"
79 "using namespace metal;\n"
80 "\n"
81 "typedef struct {\n"
82 " float4 position [[position]];\n"
83 "} VertexOutput;\n"
84 "\n"
85 "typedef struct {\n"
86 " float4 uPosXform;\n"
87 " uint2 uTextureSize;\n"
88 "} VertexUniforms;\n"
89 "\n"
90 "vertex VertexOutput vertexMain(constant VertexUniforms& uniforms [[buffer(0)]],\n"
91 " uint vertexID [[vertex_id]]) {\n"
92 " VertexOutput out;\n"
93 " float2 position = float2(float(vertexID >> 1), float(vertexID & 1));\n"
94 " out.position.xy = position * uniforms.uPosXform.xy + uniforms.uPosXform.zw;\n"
95 " out.position.zw = float2(0.0, 1.0);\n"
96 " return out;\n"
97 "}\n"
98 "\n"
99 "fragment float4 fragmentMain(VertexOutput in [[stage_in]],\n"
100 " texture2d<half> colorMap [[texture(0)]]) {\n"
101 " uint2 coords = uint2(in.position.x, in.position.y);"
102 " half4 colorSample = colorMap.read(coords);\n"
103 " return float4(colorSample);\n"
104 "}"
105 );
106
107 auto errorHandler = fGpu->getContext()->priv().getShaderErrorHandler();
108 fMSAALoadLibrary = GrCompileMtlShaderLibrary(fGpu, shaderText, errorHandler);
109 if (!fMSAALoadLibrary) {
110 return nullptr;
111 }
112 }
113
114 for (int i = 0; i < fMSAALoadPipelines.size(); ++i) {
115 if (fMSAALoadPipelines[i].fColorFormat == colorFormat &&
116 fMSAALoadPipelines[i].fSampleCount == sampleCount &&
117 fMSAALoadPipelines[i].fStencilFormat == stencilFormat) {
118 return fMSAALoadPipelines[i].fPipeline.get();
119 }
120 }
121
122 auto pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
123
124 pipelineDescriptor.label = @"loadMSAAFromResolve";
125
126 pipelineDescriptor.vertexFunction =
127 [fMSAALoadLibrary newFunctionWithName: @"vertexMain"];
128 pipelineDescriptor.fragmentFunction =
129 [fMSAALoadLibrary newFunctionWithName: @"fragmentMain"];
130
131 auto mtlColorAttachment = [[MTLRenderPipelineColorAttachmentDescriptor alloc] init];
132
133 mtlColorAttachment.pixelFormat = colorFormat;
134 mtlColorAttachment.blendingEnabled = FALSE;
135 mtlColorAttachment.writeMask = MTLColorWriteMaskAll;
136
137 pipelineDescriptor.colorAttachments[0] = mtlColorAttachment;
138 pipelineDescriptor.rasterSampleCount = sampleCount;
139
140 pipelineDescriptor.stencilAttachmentPixelFormat = stencilFormat;
141
142 NSError* error;
143 auto pso =
144 [fGpu->device() newRenderPipelineStateWithDescriptor: pipelineDescriptor
145 error: &error];
146 if (!pso) {
147 SkDebugf("Error creating pipeline: %s\n",
148 [[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]);
149 }
150
151 auto renderPipeline = GrMtlRenderPipeline::Make(pso);
152
153 fMSAALoadPipelines.push_back({renderPipeline, colorFormat, sampleCount, stencilFormat});
154 return fMSAALoadPipelines[fMSAALoadPipelines.size()-1].fPipeline.get();
155}
id< MTLLibrary > GrCompileMtlShaderLibrary(const GrMtlGpu *gpu, const std::string &msl, GrContextOptions::ShaderErrorHandler *errorHandler)
Definition: GrMtlUtil.mm:52
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
GrContextOptions::ShaderErrorHandler * getShaderErrorHandler() const
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition: GrGpu.h:67
id< MTLDevice > device() const
Definition: GrMtlGpu.h:49
static sk_sp< GrMtlRenderPipeline > Make(id< MTLRenderPipelineState > pso)
Definition: GrMtlPipeline.h:20
int size() const
Definition: SkTArray.h:421
const uint8_t uint32_t uint32_t GError ** error
return FALSE
static bool init()
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ precompileShader()

bool GrMtlResourceProvider::precompileShader ( const SkData key,
const SkData data 
)

Definition at line 40 of file GrMtlResourceProvider.mm.

40 {
41 return fPipelineStateCache->precompileShader(key, data);
42}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

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