Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | List of all members
SkSL::WGSLCodeGenerator Class Reference
Inheritance diagram for SkSL::WGSLCodeGenerator:
SkSL::CodeGenerator

Classes

class  LValue
 
class  PointerLValue
 
struct  ProgramRequirements
 
class  SwizzleLValue
 
class  VectorComponentLValue
 

Public Types

enum class  Builtin {
  kVertexIndex , kInstanceIndex , kPosition , kLastFragColor ,
  kFrontFacing , kSampleIndex , kFragDepth , kSampleMaskIn ,
  kSampleMask , kLocalInvocationId , kLocalInvocationIndex , kGlobalInvocationId ,
  kWorkgroupId , kNumWorkgroups
}
 
enum class  Delimiter { kComma , kSemicolon , kNone }
 

Public Member Functions

 WGSLCodeGenerator (const Context *context, const ShaderCaps *caps, const Program *program, OutputStream *out)
 
bool generateCode () override
 
- Public Member Functions inherited from SkSL::CodeGenerator
 CodeGenerator (const Context *context, const ShaderCaps *caps, const Program *program, OutputStream *stream)
 
virtual ~CodeGenerator ()=default
 
virtual bool generateCode ()=0
 
OutputStreamoutputStream ()
 
void setOutputStream (OutputStream *output)
 

Additional Inherited Members

- Protected Attributes inherited from SkSL::CodeGenerator
const ProgramfProgram
 
Context fContext
 
const ShaderCapsfCaps
 
OutputStreamfOut
 
- Static Protected Attributes inherited from SkSL::CodeGenerator
static constexpr float kSharpenTexturesBias = -.475f
 

Detailed Description

Definition at line 120 of file SkSLWGSLCodeGenerator.cpp.

Member Enumeration Documentation

◆ Builtin

Enumerator
kVertexIndex 
kInstanceIndex 
kPosition 
kLastFragColor 
kFrontFacing 
kSampleIndex 
kFragDepth 
kSampleMaskIn 
kSampleMask 
kLocalInvocationId 
kLocalInvocationIndex 
kGlobalInvocationId 
kWorkgroupId 
kNumWorkgroups 

Definition at line 123 of file SkSLWGSLCodeGenerator.cpp.

123 {
124 // Vertex stage:
125 kVertexIndex, // input
126 kInstanceIndex, // input
127 kPosition, // output, fragment stage input
128
129 // Fragment stage:
130 kLastFragColor, // input
131 kFrontFacing, // input
132 kSampleIndex, // input
133 kFragDepth, // output
134 kSampleMaskIn, // input
135 kSampleMask, // output
136
137 // Compute stage:
138 kLocalInvocationId, // input
139 kLocalInvocationIndex, // input
140 kGlobalInvocationId, // input
141 kWorkgroupId, // input
142 kNumWorkgroups, // input
143 };

◆ Delimiter

Enumerator
kComma 
kSemicolon 
kNone 

Definition at line 150 of file SkSLWGSLCodeGenerator.cpp.

150 {
151 kComma,
152 kSemicolon,
153 kNone,
154 };
@ kNone
Definition: layer.h:53

Constructor & Destructor Documentation

◆ WGSLCodeGenerator()

SkSL::WGSLCodeGenerator::WGSLCodeGenerator ( const Context context,
const ShaderCaps caps,
const Program program,
OutputStream out 
)
inline

Definition at line 168 of file SkSLWGSLCodeGenerator.cpp.

172 : INHERITED(context, caps, program, out) {}

Member Function Documentation

◆ generateCode()

bool SkSL::WGSLCodeGenerator::generateCode ( )
overridevirtual

Implements SkSL::CodeGenerator.

Definition at line 1291 of file SkSLWGSLCodeGenerator.cpp.

1291 {
1292 // The resources of a WGSL program are structured in the following way:
1293 // - Stage attribute inputs and outputs are bundled inside synthetic structs called
1294 // VSIn/VSOut/FSIn/FSOut/CSIn.
1295 // - All uniform and storage type resources are declared in global scope.
1296 this->preprocessProgram();
1297
1298 {
1299 AutoOutputStream outputToHeader(this, &fHeader, &fIndentation);
1300 this->writeEnables();
1301 this->writeStageInputStruct();
1302 this->writeStageOutputStruct();
1303 this->writeUniformsAndBuffers();
1304 this->writeNonBlockUniformsForTests();
1305 }
1306 StringStream body;
1307 {
1308 // Emit the program body.
1309 AutoOutputStream outputToBody(this, &body, &fIndentation);
1310 const FunctionDefinition* mainFunc = nullptr;
1311 for (const ProgramElement* e : fProgram.elements()) {
1312 this->writeProgramElement(*e);
1313
1314 if (e->is<FunctionDefinition>()) {
1315 const FunctionDefinition& func = e->as<FunctionDefinition>();
1316 if (func.declaration().isMain()) {
1317 mainFunc = &func;
1318 }
1319 }
1320 }
1321
1322 // At the bottom of the program body, emit the entrypoint function.
1323 // The entrypoint relies on state that has been collected while we emitted the rest of the
1324 // program, so it's important to do it last to make sure we don't miss anything.
1325 if (mainFunc) {
1326 this->writeEntryPoint(*mainFunc);
1327 }
1328 }
1329
1330 write_stringstream(fHeader, *fOut);
1331 write_stringstream(body, *fOut);
1332
1333 this->writeUniformPolyfills();
1334
1335 return fContext.fErrors->errorCount() == 0;
1336}
const Program & fProgram
ErrorReporter * fErrors
Definition: SkSLContext.h:36
void write_stringstream(const StringStream &s, OutputStream &out)
Definition: SkSLUtil.cpp:42
ElementsCollection elements() const
Definition: SkSLProgram.h:140

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