Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkSL::InterfaceBlock Class Referencefinal

#include <SkSLInterfaceBlock.h>

Inheritance diagram for SkSL::InterfaceBlock:
SkSL::ProgramElement SkSL::IRNode SkSL::Poolable

Public Member Functions

 InterfaceBlock (Position pos, Variable *var)
 
 ~InterfaceBlock () override
 
Variablevar () const
 
void detachDeadVariable ()
 
std::string_view typeName () const
 
std::string_view instanceName () const
 
int arraySize () const
 
std::string description () const override
 
- Public Member Functions inherited from SkSL::ProgramElement
 ProgramElement (Position pos, Kind kind)
 
Kind kind () const
 
- Public Member Functions inherited from SkSL::IRNode
virtual ~IRNode ()
 
virtual std::string description () const =0
 
 IRNode (const IRNode &)=delete
 
IRNodeoperator= (const IRNode &)=delete
 
Position position () const
 
void setPosition (Position p)
 
template<typename T >
bool is () const
 
template<typename T >
const Tas () const
 
template<typename T >
Tas ()
 

Static Public Member Functions

static std::unique_ptr< InterfaceBlockConvert (const Context &context, Position pos, const Modifiers &modifiers, std::string_view typeName, skia_private::TArray< Field > fields, std::string_view varName, int arraySize)
 
static std::unique_ptr< InterfaceBlockMake (const Context &context, Position pos, Variable *variable)
 
- Static Public Member Functions inherited from SkSL::Poolable
static void * operator new (const size_t size)
 
static void operator delete (void *ptr)
 

Static Public Attributes

static constexpr Kind kIRNodeKind = Kind::kInterfaceBlock
 

Additional Inherited Members

- Public Types inherited from SkSL::ProgramElement
using Kind = ProgramElementKind
 
- Public Attributes inherited from SkSL::IRNode
Position fPosition
 
- Protected Member Functions inherited from SkSL::IRNode
 IRNode (Position position, int kind)
 
- Protected Attributes inherited from SkSL::IRNode
int fKind
 

Detailed Description

An interface block, as in:

out sk_PerVertex { layout(builtin=0) float4 sk_Position; layout(builtin=1) float sk_PointSize; };

At the IR level, this is represented by a single variable of struct type.

Definition at line 38 of file SkSLInterfaceBlock.h.

Constructor & Destructor Documentation

◆ InterfaceBlock()

SkSL::InterfaceBlock::InterfaceBlock ( Position  pos,
Variable var 
)
inline

Definition at line 42 of file SkSLInterfaceBlock.h.

43 : INHERITED(pos, kIRNodeKind)
44 , fVariable(var) {
46 fVariable->setInterfaceBlock(this);
47 }
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr Kind kIRNodeKind
Variable * var() const
const Type & type() const
Definition: SkSLSymbol.h:42
virtual const Type & componentType() const
Definition: SkSLType.h:404
virtual bool isInterfaceBlock() const
Definition: SkSLType.h:544
virtual void setInterfaceBlock(InterfaceBlock *)
Definition: SkSLVariable.h:127

◆ ~InterfaceBlock()

SkSL::InterfaceBlock::~InterfaceBlock ( )
override

Definition at line 34 of file SkSLInterfaceBlock.cpp.

34 {
35 // Unhook this InterfaceBlock from its associated Variable, since we're being deleted.
36 if (fVariable) {
37 fVariable->detachDeadInterfaceBlock();
38 }
39}
virtual void detachDeadInterfaceBlock()
Definition: SkSLVariable.h:129

Member Function Documentation

◆ arraySize()

int SkSL::InterfaceBlock::arraySize ( ) const
inline

Definition at line 88 of file SkSLInterfaceBlock.h.

88 {
89 return fVariable->type().isArray() ? fVariable->type().columns() : 0;
90 }
virtual bool isArray() const
Definition: SkSLType.h:532
virtual int columns() const
Definition: SkSLType.h:429

◆ Convert()

std::unique_ptr< InterfaceBlock > SkSL::InterfaceBlock::Convert ( const Context context,
Position  pos,
const Modifiers modifiers,
std::string_view  typeName,
skia_private::TArray< Field fields,
std::string_view  varName,
int  arraySize 
)
static

Definition at line 52 of file SkSLInterfaceBlock.cpp.

58 {
59 if (SkSL::ProgramKind kind = context.fConfig->fKind; !ProgramConfig::IsFragment(kind) &&
62 context.fErrors->error(pos, "interface blocks are not allowed in this kind of program");
63 return nullptr;
64 }
65 // Find sk_RTAdjust and error out if it's not of type `float4`.
66 std::optional<int> rtAdjustIndex = find_rt_adjust_index(fields);
67 if (rtAdjustIndex.has_value()) {
68 const Field& rtAdjustField = fields[*rtAdjustIndex];
69 if (!rtAdjustField.fType->matches(*context.fTypes.fFloat4)) {
70 context.fErrors->error(rtAdjustField.fPosition, "sk_RTAdjust must have type 'float4'");
71 return nullptr;
72 }
73 }
74 // Build a struct type corresponding to the passed-in fields.
75 const Type* baseType = context.fSymbolTable->add(context,
77 pos,
79 std::move(fields),
80 /*interfaceBlock=*/true));
81 // Array-ify the type if necessary.
82 const Type* type = baseType;
83 if (arraySize > 0) {
84 arraySize = type->convertArraySize(context, pos, pos, arraySize);
85 if (!arraySize) {
86 return nullptr;
87 }
88 type = context.fSymbolTable->addArrayDimension(context, type, arraySize);
89 }
90
91 // Error-check the interface block as if it were being declared as a global variable.
93 pos,
94 modifiers.fPosition,
95 modifiers.fLayout,
96 modifiers.fFlags,
97 type,
98 baseType,
100
101 // Create a global variable for the Interface Block.
102 std::unique_ptr<SkSL::Variable> var = SkSL::Variable::Convert(context,
103 pos,
104 modifiers.fPosition,
105 modifiers.fLayout,
106 modifiers.fFlags,
107 type,
108 pos,
109 varName,
111 return InterfaceBlock::Make(context,
112 pos,
113 context.fSymbolTable->takeOwnershipOfSymbol(std::move(var)));
114}
GLenum type
static std::unique_ptr< InterfaceBlock > Make(const Context &context, Position pos, Variable *variable)
std::string_view typeName() const
static std::unique_ptr< Type > MakeStructType(const Context &context, Position pos, std::string_view name, skia_private::TArray< Field > fields, bool interfaceBlock=false)
static void ErrorCheck(const Context &context, Position pos, Position modifiersPosition, const Layout &layout, ModifierFlags modifierFlags, const Type *type, const Type *baseType, Variable::Storage storage)
static std::unique_ptr< Variable > Convert(const Context &context, Position pos, Position modifiersPos, const Layout &layout, ModifierFlags flags, const Type *type, Position namePos, std::string_view name, Storage storage)
static std::optional< int > find_rt_adjust_index(SkSpan< const Field > fields)
static bool IsVertex(ProgramKind kind)
static bool IsFragment(ProgramKind kind)
static bool IsCompute(ProgramKind kind)

◆ description()

std::string SkSL::InterfaceBlock::description ( ) const
overridevirtual

Implements SkSL::IRNode.

Definition at line 140 of file SkSLInterfaceBlock.cpp.

140 {
141 std::string result = this->var()->layout().description() +
142 this->var()->modifierFlags().description() + ' ' +
143 std::string(this->typeName()) + " {\n";
144 const Type* structType = &this->var()->type();
145 if (structType->isArray()) {
146 structType = &structType->componentType();
147 }
148 for (const auto& f : structType->fields()) {
149 result += f.description() + "\n";
150 }
151 result += "}";
152 if (!this->instanceName().empty()) {
153 result += " " + std::string(this->instanceName());
154 if (this->arraySize() > 0) {
155 String::appendf(&result, "[%d]", this->arraySize());
156 }
157 }
158 return result + ";";
159}
std::string_view instanceName() const
std::string description() const
ModifierFlags modifierFlags() const
Definition: SkSLVariable.h:89
virtual const Layout & layout() const
EMSCRIPTEN_KEEPALIVE void empty()
GAsyncResult * result
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
Definition: SkSLString.cpp:92
std::string description() const

◆ detachDeadVariable()

void SkSL::InterfaceBlock::detachDeadVariable ( )
inline

Definition at line 76 of file SkSLInterfaceBlock.h.

76 {
77 fVariable = nullptr;
78 }

◆ instanceName()

std::string_view SkSL::InterfaceBlock::instanceName ( ) const
inline

Definition at line 84 of file SkSLInterfaceBlock.h.

84 {
85 return fVariable->name();
86 }
std::string_view name() const
Definition: SkSLSymbol.h:51

◆ Make()

std::unique_ptr< InterfaceBlock > SkSL::InterfaceBlock::Make ( const Context context,
Position  pos,
Variable variable 
)
static

Definition at line 116 of file SkSLInterfaceBlock.cpp.

118 {
119 SkASSERT(ProgramConfig::IsFragment(context.fConfig->fKind) ||
120 ProgramConfig::IsVertex(context.fConfig->fKind) ||
121 ProgramConfig::IsCompute(context.fConfig->fKind));
122
123 SkASSERT(variable->type().componentType().isInterfaceBlock());
124 SkSpan<const Field> fields = variable->type().componentType().fields();
125
126 if (variable->name().empty()) {
127 // This interface block is anonymous. Add each field to the top-level symbol table.
128 for (size_t i = 0; i < fields.size(); ++i) {
129 context.fSymbolTable->add(
130 context, std::make_unique<SkSL::FieldSymbol>(fields[i].fPosition, variable, i));
131 }
132 } else {
133 // Add the global variable to the top-level symbol table.
134 context.fSymbolTable->addWithoutOwnership(context, variable);
135 }
136
137 return std::make_unique<SkSL::InterfaceBlock>(pos, variable);
138}
Position fPosition
Definition: SkSLIRNode.h:109
constexpr size_t size() const
Definition: SkSpan_impl.h:95

◆ typeName()

std::string_view SkSL::InterfaceBlock::typeName ( ) const
inline

Definition at line 80 of file SkSLInterfaceBlock.h.

80 {
81 return fVariable->type().componentType().name();
82 }

◆ var()

Variable * SkSL::InterfaceBlock::var ( ) const
inline

Definition at line 72 of file SkSLInterfaceBlock.h.

72 {
73 return fVariable;
74 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::InterfaceBlock::kIRNodeKind = Kind::kInterfaceBlock
inlinestaticconstexpr

Definition at line 40 of file SkSLInterfaceBlock.h.


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