Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions | Friends | List of all members
GrGLSLVaryingHandler Class Referenceabstract

#include <GrGLSLVarying.h>

Inheritance diagram for GrGLSLVaryingHandler:
GrGLVaryingHandler GrMtlVaryingHandler GrSPIRVVaryingHandler GrVkVaryingHandler

Classes

struct  VaryingInfo
 

Public Types

enum class  Interpolation { kInterpolated , kCanBeFlat , kMustBeFlat }
 

Public Member Functions

 GrGLSLVaryingHandler (GrGLSLProgramBuilder *program)
 
virtual ~GrGLSLVaryingHandler ()
 
void setNoPerspective ()
 
void addVarying (const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
 
void addPassThroughAttribute (const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
 
void emitAttributes (const GrGeometryProcessor &)
 
void finalize ()
 
void getVertexDecls (SkString *inputDecls, SkString *outputDecls) const
 
void getFragDecls (SkString *inputDecls, SkString *outputDecls) const
 

Protected Types

typedef SkTBlockList< VaryingInfoVaryingList
 
typedef SkTBlockList< GrShaderVarVarArray
 

Protected Attributes

VaryingList fVaryings
 
VarArray fVertexInputs
 
VarArray fVertexOutputs
 
VarArray fFragInputs
 
VarArray fFragOutputs
 
GrGLSLProgramBuilderfProgramBuilder
 

Private Member Functions

virtual void onFinalize ()=0
 

Friends

class GrGLSLProgramBuilder
 

Detailed Description

Definition at line 91 of file GrGLSLVarying.h.

Member Typedef Documentation

◆ VarArray

Definition at line 157 of file GrGLSLVarying.h.

◆ VaryingList

Definition at line 156 of file GrGLSLVarying.h.

Member Enumeration Documentation

◆ Interpolation

Enumerator
kInterpolated 
kCanBeFlat 
kMustBeFlat 

Definition at line 112 of file GrGLSLVarying.h.

112 {
113 kInterpolated,
114 kCanBeFlat, // Use "flat" if it will be faster.
115 kMustBeFlat // Use "flat" even if it is known to be slow.
116 };

Constructor & Destructor Documentation

◆ GrGLSLVaryingHandler()

GrGLSLVaryingHandler::GrGLSLVaryingHandler ( GrGLSLProgramBuilder program)
inlineexplicit

Definition at line 93 of file GrGLSLVarying.h.

99 , fProgramBuilder(program)
100 , fDefaultInterpolationModifier(nullptr) {}
static const int kVaryingsPerBlock
Definition: GrGLSLVarying.h:89
GrGLSLProgramBuilder * fProgramBuilder

◆ ~GrGLSLVaryingHandler()

virtual GrGLSLVaryingHandler::~GrGLSLVaryingHandler ( )
inlinevirtual

Definition at line 102 of file GrGLSLVarying.h.

102{}

Member Function Documentation

◆ addPassThroughAttribute()

void GrGLSLVaryingHandler::addPassThroughAttribute ( const GrShaderVar vsVar,
const char *  output,
Interpolation  interpolation = Interpolation::kInterpolated 
)

The GP can use these calls to pass a vertex shader variable directly to 'output' in the fragment shader. Though this adds code to vertex and fragment stages, 'output' is expected to be defined in the fragment shader before the call is made. TODO it might be nicer behavior to have a flag to declare output inside these calls

Definition at line 17 of file GrGLSLVarying.cpp.

19 {
21 GrGLSLVarying v(vsVar.getType());
22 this->addVarying(vsVar.c_str(), &v, interpolation);
23 fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), vsVar.c_str());
24 fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
25}
#define SkASSERT(cond)
Definition: SkAssert.h:116
GrGLSLVertexBuilder fVS
GrGLSLFragmentShaderBuilder fFS
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void addVarying(const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
SkSLType getType() const
Definition: GrShaderVar.h:97
const char * c_str() const
Definition: GrShaderVar.h:94

◆ addVarying()

void GrGLSLVaryingHandler::addVarying ( const char *  name,
GrGLSLVarying varying,
Interpolation  interpolation = Interpolation::kInterpolated 
)

addVarying allows fine grained control for setting up varyings between stages. Calling this function will make sure all necessary decls are setup for the client. The client however is responsible for setting up all shader code (e.g "vOut = vIn;") If you just need to take an attribute and pass it through to an output value in a fragment shader, use addPassThroughAttribute. TODO convert most uses of addVarying to addPassThroughAttribute

Definition at line 43 of file GrGLSLVarying.cpp.

44 {
45 SkASSERT(SkSLTypeIsFloatType(varying->type()) || Interpolation::kMustBeFlat == interpolation);
46 VaryingInfo& v = fVaryings.push_back();
47
48 SkASSERT(varying);
49 SkASSERT(SkSLType::kVoid != varying->fType);
50 v.fType = varying->fType;
51 v.fIsFlat = use_flat_interpolation(interpolation, *fProgramBuilder->shaderCaps());
52 v.fVsOut = fProgramBuilder->nameVariable('v', name);
53 v.fVisibility = kNone_GrShaderFlags;
54 if (varying->isInVertexShader()) {
55 varying->fVsOut = v.fVsOut.c_str();
56 v.fVisibility |= kVertex_GrShaderFlag;
57 }
58 if (varying->isInFragmentShader()) {
59 varying->fFsIn = v.fVsOut.c_str();
60 v.fVisibility |= kFragment_GrShaderFlag;
61 }
62}
static bool use_flat_interpolation(GrGLSLVaryingHandler::Interpolation interpolation, const GrShaderCaps &shaderCaps)
@ kVertex_GrShaderFlag
Definition: GrTypesPriv.h:286
@ kNone_GrShaderFlags
Definition: GrTypesPriv.h:285
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
SkString nameVariable(char prefix, const char *name, bool mangle=true)
const GrShaderCaps * shaderCaps() const
bool isInVertexShader() const
Definition: GrGLSLVarying.h:64
bool isInFragmentShader() const
Definition: GrGLSLVarying.h:65
SkSLType type() const
Definition: GrGLSLVarying.h:62
T & push_back()
Definition: SkTBlockList.h:90
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ emitAttributes()

void GrGLSLVaryingHandler::emitAttributes ( const GrGeometryProcessor gp)

Definition at line 64 of file GrGLSLVarying.cpp.

64 {
65 for (auto attr : gp.vertexAttributes()) {
66 this->addAttribute(attr.asShaderVar());
67 }
68 for (auto attr : gp.instanceAttributes()) {
69 this->addAttribute(attr.asShaderVar());
70 }
71}
const AttributeSet & vertexAttributes() const
const AttributeSet & instanceAttributes() const

◆ finalize()

void GrGLSLVaryingHandler::finalize ( )

Definition at line 97 of file GrGLSLVarying.cpp.

97 {
98 for (const VaryingInfo& v : fVaryings.items()) {
99 const char* modifier = v.fIsFlat ? "flat" : fDefaultInterpolationModifier;
100 if (v.fVisibility & kVertex_GrShaderFlag) {
103 }
104 if (v.fVisibility & kFragment_GrShaderFlag) {
105 const char* fsIn = v.fVsOut.c_str();
108 }
109 }
110 this->onFinalize();
111}
virtual void onFinalize()=0
T & emplace_back(Args &&... args)
Definition: SkTBlockList.h:101

◆ getFragDecls()

void GrGLSLVaryingHandler::getFragDecls ( SkString inputDecls,
SkString outputDecls 
) const

Definition at line 125 of file GrGLSLVarying.cpp.

125 {
126 // We should not have any outputs in the fragment shader when using version 1.10
129 this->appendDecls(fFragInputs, inputDecls);
130 this->appendDecls(fFragOutputs, outputDecls);
131}
bool empty() const
Definition: SkTBlockList.h:185
SkSL::GLSLGeneration fGLSLGeneration
Definition: SkSLUtil.h:82

◆ getVertexDecls()

void GrGLSLVaryingHandler::getVertexDecls ( SkString inputDecls,
SkString outputDecls 
) const

Definition at line 120 of file GrGLSLVarying.cpp.

120 {
121 this->appendDecls(fVertexInputs, inputDecls);
122 this->appendDecls(fVertexOutputs, outputDecls);
123}

◆ onFinalize()

virtual void GrGLSLVaryingHandler::onFinalize ( )
privatepure virtual

◆ setNoPerspective()

void GrGLSLVaryingHandler::setNoPerspective ( )

Notifies the varying handler that this shader will never emit geometry in perspective and therefore does not require perspective-correct interpolation. When supported, this allows varyings to use the "noperspective" keyword, which means the GPU can use cheaper math for interpolation.

Definition at line 84 of file GrGLSLVarying.cpp.

84 {
85 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
87 return;
88 }
89 if (const char* extension = caps.noperspectiveInterpolationExtensionString()) {
91 fProgramBuilder->fVS.addFeature(bit, extension);
92 fProgramBuilder->fFS.addFeature(bit, extension);
93 }
94 fDefaultInterpolationModifier = "noperspective";
95}
bool addFeature(uint32_t featureBit, const char *extensionName)
const char * noperspectiveInterpolationExtensionString() const
Definition: GrShaderCaps.h:22
bool fNoPerspectiveInterpolationSupport
Definition: SkSLUtil.h:97

Friends And Related Function Documentation

◆ GrGLSLProgramBuilder

friend class GrGLSLProgramBuilder
friend

Definition at line 178 of file GrGLSLVarying.h.

Member Data Documentation

◆ fFragInputs

VarArray GrGLSLVaryingHandler::fFragInputs
protected

Definition at line 162 of file GrGLSLVarying.h.

◆ fFragOutputs

VarArray GrGLSLVaryingHandler::fFragOutputs
protected

Definition at line 163 of file GrGLSLVarying.h.

◆ fProgramBuilder

GrGLSLProgramBuilder* GrGLSLVaryingHandler::fProgramBuilder
protected

Definition at line 166 of file GrGLSLVarying.h.

◆ fVaryings

VaryingList GrGLSLVaryingHandler::fVaryings
protected

Definition at line 159 of file GrGLSLVarying.h.

◆ fVertexInputs

VarArray GrGLSLVaryingHandler::fVertexInputs
protected

Definition at line 160 of file GrGLSLVarying.h.

◆ fVertexOutputs

VarArray GrGLSLVaryingHandler::fVertexOutputs
protected

Definition at line 161 of file GrGLSLVarying.h.


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