Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GrMtlPipelineState Class Reference

#include <GrMtlPipelineState.h>

Public Types

using UniformInfoArray = GrMtlPipelineStateDataManager::UniformInfoArray
 
using UniformHandle = GrGLSLProgramDataManager::UniformHandle
 

Public Member Functions

 GrMtlPipelineState (GrMtlGpu *, sk_sp< GrMtlRenderPipeline > pipeline, MTLPixelFormat, const GrGLSLBuiltinUniformHandles &builtinUniformHandles, const UniformInfoArray &uniforms, uint32_t uniformBufferSize, uint32_t numSamplers, std::unique_ptr< GrGeometryProcessor::ProgramImpl >, std::unique_ptr< GrXferProcessor::ProgramImpl >, std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fpImpls)
 
const sk_sp< GrMtlRenderPipeline > & pipeline () const
 
void setData (GrMtlFramebuffer *, const GrProgramInfo &)
 
void setTextures (const GrGeometryProcessor &, const GrPipeline &, const GrSurfaceProxy *const geomProcTextures[])
 
void bindTextures (GrMtlRenderCommandEncoder *renderCmdEncoder)
 
void setDrawState (GrMtlRenderCommandEncoder *, const skgpu::Swizzle &writeSwizzle, const GrXferProcessor &)
 
bool doesntSampleAttachment (const MTLRenderPassAttachmentDescriptor *) const
 

Static Public Member Functions

static void SetDynamicScissorRectState (GrMtlRenderCommandEncoder *renderCmdEncoder, SkISize colorAttachmentDimensions, GrSurfaceOrigin rtOrigin, SkIRect scissorRect)
 

Detailed Description

Wraps a MTLRenderPipelineState object and also contains more info about the pipeline as needed by Ganesh

Definition at line 33 of file GrMtlPipelineState.h.

Member Typedef Documentation

◆ UniformHandle

using GrMtlPipelineState::UniformHandle = GrGLSLProgramDataManager::UniformHandle

Definition at line 36 of file GrMtlPipelineState.h.

◆ UniformInfoArray

Definition at line 35 of file GrMtlPipelineState.h.

Constructor & Destructor Documentation

◆ GrMtlPipelineState()

GrMtlPipelineState::GrMtlPipelineState ( GrMtlGpu gpu,
sk_sp< GrMtlRenderPipeline pipeline,
MTLPixelFormat  pixelFormat,
const GrGLSLBuiltinUniformHandles builtinUniformHandles,
const UniformInfoArray uniforms,
uint32_t  uniformBufferSize,
uint32_t  numSamplers,
std::unique_ptr< GrGeometryProcessor::ProgramImpl gpImpl,
std::unique_ptr< GrXferProcessor::ProgramImpl xpImpl,
std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > >  fpImpls 
)

Definition at line 40 of file GrMtlPipelineState.mm.

51 : fGpu(gpu)
52 , fPipeline(std::move(pipeline))
53 , fPixelFormat(pixelFormat)
54 , fBuiltinUniformHandles(builtinUniformHandles)
55 , fNumSamplers(numSamplers)
56 , fGPImpl(std::move(gpImpl))
57 , fXPImpl(std::move(xpImpl))
58 , fFPImpls(std::move(fpImpls))
59 , fDataManager(uniforms, uniformBufferSize) {
60 (void) fPixelFormat; // Suppress unused-var warning.
61}
const sk_sp< GrMtlRenderPipeline > & pipeline() const

Member Function Documentation

◆ bindTextures()

void GrMtlPipelineState::bindTextures ( GrMtlRenderCommandEncoder renderCmdEncoder)

Definition at line 130 of file GrMtlPipelineState.mm.

130 {
131 SkASSERT(fNumSamplers == fSamplerBindings.size());
132 for (int index = 0; index < fNumSamplers; ++index) {
133 renderCmdEncoder->setFragmentTexture(fSamplerBindings[index].fTexture, index);
134 renderCmdEncoder->setFragmentSamplerState(fSamplerBindings[index].fSampler, index);
135 }
136}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void setFragmentTexture(id< MTLTexture > texture, NSUInteger index)
void setFragmentSamplerState(GrMtlSampler *sampler, NSUInteger index)
int size() const
Definition: SkTArray.h:421

◆ doesntSampleAttachment()

bool GrMtlPipelineState::doesntSampleAttachment ( const MTLRenderPassAttachmentDescriptor *  attachment) const

Definition at line 228 of file GrMtlPipelineState.mm.

229 {
230 for (int i = 0; i < fSamplerBindings.size(); ++i) {
231 if (attachment.texture == fSamplerBindings[i].fTexture ||
232 attachment.resolveTexture == fSamplerBindings[i].fTexture) {
233 return false;
234 }
235 }
236 return true;
237}

◆ pipeline()

const sk_sp< GrMtlRenderPipeline > & GrMtlPipelineState::pipeline ( ) const
inline

Definition at line 49 of file GrMtlPipelineState.h.

49{ return fPipeline; }

◆ setData()

void GrMtlPipelineState::setData ( GrMtlFramebuffer framebuffer,
const GrProgramInfo programInfo 
)

Definition at line 63 of file GrMtlPipelineState.mm.

64 {
65 SkISize colorAttachmentDimensions = framebuffer->colorAttachment()->dimensions();
66
67 this->setRenderTargetState(colorAttachmentDimensions, programInfo.origin());
68 fGPImpl->setData(fDataManager, *fGpu->caps()->shaderCaps(), programInfo.geomProc());
69
70 for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) {
71 const auto& fp = programInfo.pipeline().getFragmentProcessor(i);
72 fp.visitWithImpls([&](const GrFragmentProcessor& fp,
74 impl.setData(fDataManager, fp);
75 }, *fFPImpls[i]);
76 }
77
78 programInfo.pipeline().setDstTextureUniforms(fDataManager, &fBuiltinUniformHandles);
79 fXPImpl->setData(fDataManager, programInfo.pipeline().getXferProcessor());
80
81 fDataManager.resetDirtyBits();
82
83#ifdef SK_DEBUG
84 if (programInfo.isStencilEnabled()) {
85 SkDEBUGCODE(const GrAttachment* stencil = framebuffer->stencilAttachment());
86 SkASSERT(stencil);
87 SkASSERT(GrBackendFormatStencilBits(stencil->backendFormat()) == 8);
88 }
89#endif
90
91 fStencil = programInfo.nonGLStencilSettings();
92 fGpu->commandBuffer()->addResource(fPipeline);
93}
int GrBackendFormatStencilBits(const GrBackendFormat &format)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
void setData(const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
const GrCaps * caps() const
Definition: GrGpu.h:73
void addResource(const sk_sp< const GrManagedResource > &resource)
GrMtlAttachment * stencilAttachment()
GrMtlAttachment * colorAttachment()
GrMtlCommandBuffer * commandBuffer()
Definition: GrMtlGpu.mm:187
void setDstTextureUniforms(const GrGLSLProgramDataManager &pdm, GrGLSLBuiltinUniformHandles *fBuiltinUniformHandles) const
Definition: GrPipeline.cpp:115
const GrFragmentProcessor & getFragmentProcessor(int idx) const
Definition: GrPipeline.h:157
const GrXferProcessor & getXferProcessor() const
Definition: GrPipeline.h:116
GrSurfaceOrigin origin() const
Definition: GrProgramInfo.h:38
const GrPipeline & pipeline() const
Definition: GrProgramInfo.h:39
const GrGeometryProcessor & geomProc() const
Definition: GrProgramInfo.h:40
bool isStencilEnabled() const
Definition: GrProgramInfo.h:31
GrStencilSettings nonGLStencilSettings() const
SkISize dimensions() const
Definition: GrSurface.h:27
const uint32_t fp
Definition: SkSize.h:16

◆ setDrawState()

void GrMtlPipelineState::setDrawState ( GrMtlRenderCommandEncoder renderCmdEncoder,
const skgpu::Swizzle writeSwizzle,
const GrXferProcessor xferProcessor 
)

Definition at line 118 of file GrMtlPipelineState.mm.

120 {
121 this->bindUniforms(renderCmdEncoder);
122 this->setBlendConstants(renderCmdEncoder, writeSwizzle, xferProcessor);
123 this->setDepthStencilState(renderCmdEncoder);
124}

◆ SetDynamicScissorRectState()

void GrMtlPipelineState::SetDynamicScissorRectState ( GrMtlRenderCommandEncoder renderCmdEncoder,
SkISize  colorAttachmentDimensions,
GrSurfaceOrigin  rtOrigin,
SkIRect  scissorRect 
)
static

Definition at line 202 of file GrMtlPipelineState.mm.

205 {
206 if (!scissorRect.intersect(SkIRect::MakeWH(colorAttachmentDimensions.width(),
207 colorAttachmentDimensions.height()))) {
208 scissorRect.setEmpty();
209 }
210
211 MTLScissorRect scissor;
212 scissor.x = scissorRect.fLeft;
213 scissor.width = scissorRect.width();
214 if (kTopLeft_GrSurfaceOrigin == rtOrigin) {
215 scissor.y = scissorRect.fTop;
216 } else {
218 scissor.y = colorAttachmentDimensions.height() - scissorRect.fBottom;
219 }
220 scissor.height = scissorRect.height();
221
222 SkASSERT(scissor.x >= 0);
223 SkASSERT(scissor.y >= 0);
224
225 renderCmdEncoder->setScissorRect(scissor);
226}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
void setScissorRect(const MTLScissorRect &scissorRect)
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
constexpr int32_t height() const
Definition: SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr int32_t width() const
Definition: SkRect.h:158
void setEmpty()
Definition: SkRect.h:242
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ setTextures()

void GrMtlPipelineState::setTextures ( const GrGeometryProcessor geomProc,
const GrPipeline pipeline,
const GrSurfaceProxy *const  geomProcTextures[] 
)

Definition at line 95 of file GrMtlPipelineState.mm.

97 {
98 fSamplerBindings.clear();
99 for (int i = 0; i < geomProc.numTextureSamplers(); ++i) {
100 SkASSERT(geomProcTextures[i]->asTextureProxy());
101 const auto& sampler = geomProc.textureSampler(i);
102 auto texture = static_cast<GrMtlTexture*>(geomProcTextures[i]->peekTexture());
103 fSamplerBindings.emplace_back(sampler.samplerState(), texture, fGpu);
104 }
105
106 if (GrTextureProxy* dstTextureProxy = pipeline.dstProxyView().asTextureProxy()) {
107 fSamplerBindings.emplace_back(
108 GrSamplerState::Filter::kNearest, dstTextureProxy->peekTexture(), fGpu);
109 }
110
111 pipeline.visitTextureEffects([&](const GrTextureEffect& te) {
112 fSamplerBindings.emplace_back(te.samplerState(), te.texture(), fGpu);
113 });
114
115 SkASSERT(fNumSamplers == fSamplerBindings.size());
116}
const TextureSampler & textureSampler(int index) const
GrTexture * peekTexture() const
GrTexture * texture() const
GrSamplerState samplerState() const
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248
FlTexture * texture

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