Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
skgpu::graphite::MtlGraphicsPipeline Class Referencefinal

#include <MtlGraphicsPipeline.h>

Inheritance diagram for skgpu::graphite::MtlGraphicsPipeline:
skgpu::graphite::GraphicsPipeline skgpu::graphite::Resource

Public Types

using MSLFunction = std::pair< id< MTLLibrary >, std::string >
 

Public Member Functions

 ~MtlGraphicsPipeline () override
 
id< MTLRenderPipelineState > mtlPipelineState () const
 
id< MTLDepthStencilState > mtlDepthStencilState () const
 
uint32_t stencilReferenceValue () const
 
- Public Member Functions inherited from skgpu::graphite::GraphicsPipeline
 ~GraphicsPipeline () override
 
const char * getResourceType () const override
 
- Public Member Functions inherited from skgpu::graphite::Resource
 Resource (const Resource &)=delete
 
 Resource (Resource &&)=delete
 
Resourceoperator= (const Resource &)=delete
 
Resourceoperator= (Resource &&)=delete
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
Ownership ownership () const
 
skgpu::Budgeted budgeted () const
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
virtual const char * getResourceType () const =0
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
bool wasDestroyed () const
 
const GraphiteResourceKeykey () const
 
void setKey (const GraphiteResourceKey &key)
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual void prepareForReturnToCache (const std::function< void()> &takeRef)
 

Static Public Member Functions

static sk_sp< MtlGraphicsPipelineMake (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)
 

Static Public Attributes

static constexpr unsigned int kIntrinsicUniformBufferIndex = 0
 
static constexpr unsigned int kRenderStepUniformBufferIndex = 1
 
static constexpr unsigned int kPaintUniformBufferIndex = 2
 
static constexpr unsigned int kVertexBufferIndex = 3
 
static constexpr unsigned int kInstanceBufferIndex = 4
 
static constexpr unsigned int kGradientBufferIndex = 5
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::GraphicsPipeline
 GraphicsPipeline (const SharedContext *, PipelineInfo *)
 
- Protected Member Functions inherited from skgpu::graphite::Resource
 Resource (const SharedContext *, Ownership, skgpu::Budgeted, size_t gpuMemorySize, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Detailed Description

Definition at line 32 of file MtlGraphicsPipeline.h.

Member Typedef Documentation

◆ MSLFunction

using skgpu::graphite::MtlGraphicsPipeline::MSLFunction = std::pair<id<MTLLibrary>, std::string>

Definition at line 41 of file MtlGraphicsPipeline.h.

Constructor & Destructor Documentation

◆ ~MtlGraphicsPipeline()

skgpu::graphite::MtlGraphicsPipeline::~MtlGraphicsPipeline ( )
inlineoverride

Definition at line 54 of file MtlGraphicsPipeline.h.

54{}

Member Function Documentation

◆ Make()

sk_sp< MtlGraphicsPipeline > skgpu::graphite::MtlGraphicsPipeline::Make ( const MtlSharedContext sharedContext,
const std::string &  label,
MSLFunction  vertexMain,
SkSpan< const Attribute vertexAttrs,
SkSpan< const Attribute instanceAttrs,
MSLFunction  fragmentMain,
sk_cfp< id< MTLDepthStencilState > >  dss,
uint32_t  stencilRefValue,
const BlendInfo blendInfo,
const RenderPassDesc renderPassDesc,
PipelineInfo *  pipelineInfo 
)
static

Definition at line 256 of file MtlGraphicsPipeline.mm.

266 {
267 id<MTLLibrary> vsLibrary = std::get<0>(vertexMain);
268 id<MTLLibrary> fsLibrary = std::get<0>(fragmentMain);
269 if (!vsLibrary || !fsLibrary) {
270 return nullptr;
271 }
272
273 sk_cfp<MTLRenderPipelineDescriptor*> psoDescriptor([[MTLRenderPipelineDescriptor alloc] init]);
274
275 NSString* labelName = [NSString stringWithUTF8String: label.c_str()];
276 NSString* vsFuncName = [NSString stringWithUTF8String: std::get<1>(vertexMain).c_str()];
277 NSString* fsFuncName = [NSString stringWithUTF8String: std::get<1>(fragmentMain).c_str()];
278
279 (*psoDescriptor).label = labelName;
280 (*psoDescriptor).vertexFunction = [vsLibrary newFunctionWithName: vsFuncName];
281 (*psoDescriptor).fragmentFunction = [fsLibrary newFunctionWithName: fsFuncName];
282
283 // TODO: I *think* this gets cleaned up by the pipelineDescriptor?
284 (*psoDescriptor).vertexDescriptor = create_vertex_descriptor(vertexAttrs, instanceAttrs);
285
286 const MtlTextureSpec& mtlColorSpec =
287 renderPassDesc.fColorAttachment.fTextureInfo.mtlTextureSpec();
288 auto mtlColorAttachment = create_color_attachment((MTLPixelFormat)mtlColorSpec.fFormat,
289 blendInfo);
290 (*psoDescriptor).colorAttachments[0] = mtlColorAttachment;
291
292 (*psoDescriptor).rasterSampleCount =
293 renderPassDesc.fColorAttachment.fTextureInfo.numSamples();
294
295 const MtlTextureSpec& mtlDSSpec =
296 renderPassDesc.fDepthStencilAttachment.fTextureInfo.mtlTextureSpec();
297 MTLPixelFormat depthStencilFormat = (MTLPixelFormat)mtlDSSpec.fFormat;
298 if (MtlFormatIsStencil(depthStencilFormat)) {
299 (*psoDescriptor).stencilAttachmentPixelFormat = depthStencilFormat;
300 } else {
301 (*psoDescriptor).stencilAttachmentPixelFormat = MTLPixelFormatInvalid;
302 }
303 if (MtlFormatIsDepth(depthStencilFormat)) {
304 (*psoDescriptor).depthAttachmentPixelFormat = depthStencilFormat;
305 } else {
306 (*psoDescriptor).depthAttachmentPixelFormat = MTLPixelFormatInvalid;
307 }
308
309 NSError* error;
310 sk_cfp<id<MTLRenderPipelineState>> pso(
311 [sharedContext->device() newRenderPipelineStateWithDescriptor:psoDescriptor.get()
312 error:&error]);
313 if (!pso) {
314 SKGPU_LOG_E("Render pipeline creation failure:\n%s", error.debugDescription.UTF8String);
315 return nullptr;
316 }
317
318 return sk_sp<MtlGraphicsPipeline>(new MtlGraphicsPipeline(sharedContext,
319 pipelineInfo,
320 std::move(pso),
321 std::move(dss),
322 stencilRefValue));
323}
static MTLRenderPipelineColorAttachmentDescriptor * create_color_attachment(MTLPixelFormat format, const GrPipeline &pipeline, SkBinaryWriteBuffer *writer)
static MTLVertexDescriptor * create_vertex_descriptor(const GrGeometryProcessor &geomProc, SkBinaryWriteBuffer *writer)
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
const SharedContext * sharedContext() const
Definition: Resource.h:189
if(end==-1)
const uint8_t uint32_t uint32_t GError ** error
static bool init()
const myers::Point & get< 1 >(const myers::Segment &s)
Definition: Myers.h:81
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80
bool MtlFormatIsStencil(MTLPixelFormat format)
Definition: MtlUtils.mm:47
bool MtlFormatIsDepth(MTLPixelFormat format)
Definition: MtlUtils.mm:33

◆ mtlDepthStencilState()

id< MTLDepthStencilState > skgpu::graphite::MtlGraphicsPipeline::mtlDepthStencilState ( ) const
inline

Definition at line 57 of file MtlGraphicsPipeline.h.

57{ return fDepthStencilState.get(); }

◆ mtlPipelineState()

id< MTLRenderPipelineState > skgpu::graphite::MtlGraphicsPipeline::mtlPipelineState ( ) const
inline

Definition at line 56 of file MtlGraphicsPipeline.h.

56{ return fPipelineState.get(); }

◆ stencilReferenceValue()

uint32_t skgpu::graphite::MtlGraphicsPipeline::stencilReferenceValue ( ) const
inline

Definition at line 58 of file MtlGraphicsPipeline.h.

58{ return fStencilReferenceValue; }

Member Data Documentation

◆ kGradientBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kGradientBufferIndex = 5
inlinestaticconstexpr

Definition at line 39 of file MtlGraphicsPipeline.h.

◆ kInstanceBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kInstanceBufferIndex = 4
inlinestaticconstexpr

Definition at line 38 of file MtlGraphicsPipeline.h.

◆ kIntrinsicUniformBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kIntrinsicUniformBufferIndex = 0
inlinestaticconstexpr

Definition at line 34 of file MtlGraphicsPipeline.h.

◆ kPaintUniformBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kPaintUniformBufferIndex = 2
inlinestaticconstexpr

Definition at line 36 of file MtlGraphicsPipeline.h.

◆ kRenderStepUniformBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kRenderStepUniformBufferIndex = 1
inlinestaticconstexpr

Definition at line 35 of file MtlGraphicsPipeline.h.

◆ kVertexBufferIndex

constexpr unsigned int skgpu::graphite::MtlGraphicsPipeline::kVertexBufferIndex = 3
inlinestaticconstexpr

Definition at line 37 of file MtlGraphicsPipeline.h.


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