Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
SkSLCompileBench Class Reference
Inheritance diagram for SkSLCompileBench:
Benchmark SkRefCnt SkRefCntBase

Public Member Functions

 SkSLCompileBench (std::string name, const char *src, bool optimize, Output output)
 
- Public Member Functions inherited from Benchmark
 Benchmark ()
 
const char * getName ()
 
const char * getUniqueName ()
 
SkISize getSize ()
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual bool shouldLoop () const
 
void delayedSetup ()
 
void perCanvasPreDraw (SkCanvas *)
 
void perCanvasPostDraw (SkCanvas *)
 
void preDraw (SkCanvas *)
 
void postDraw (SkCanvas *)
 
void draw (int loops, SkCanvas *)
 
virtual void getGpuStats (SkCanvas *, skia_private::TArray< SkString > *keys, skia_private::TArray< double > *values)
 
virtual bool getDMSAAStats (GrRecordingContext *)
 
int getUnits () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static const char * output_string (Output output)
 

Protected Member Functions

const char * onGetName () override
 
bool isSuitableFor (Backend backend) override
 
bool usesRuntimeShader () const
 
bool usesGraphite () const
 
void fixUpSource ()
 
void onDraw (int loops, SkCanvas *canvas) override
 
- Protected Member Functions inherited from Benchmark
void setUnits (int units)
 
virtual void setupPaint (SkPaint *paint)
 
virtual const char * onGetUniqueName ()
 
virtual void onDelayedSetup ()
 
virtual void onPerCanvasPreDraw (SkCanvas *)
 
virtual void onPerCanvasPostDraw (SkCanvas *)
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 
virtual SkISize onGetSize ()
 

Static Protected Member Functions

static bool CompileToSkRP (const SkSL::Program &program)
 

Additional Inherited Members

- Public Types inherited from Benchmark
enum class  Backend {
  kNonRendering , kRaster , kGanesh , kGraphite ,
  kPDF , kHWUI
}
 

Detailed Description

Definition at line 71 of file SkSLBench.cpp.

Constructor & Destructor Documentation

◆ SkSLCompileBench()

SkSLCompileBench::SkSLCompileBench ( std::string  name,
const char *  src,
bool  optimize,
Output  output 
)
inline

Definition at line 86 of file SkSLBench.cpp.

87 : fName(std::string("sksl_") + (optimize ? "" : "unoptimized_") +
89 , fSrc(src)
91 , fOutput(output) {
92 fSettings.fOptimize = optimize;
93 // The test programs we compile don't follow Vulkan rules and thus produce invalid SPIR-V.
94 // This is harmless, so long as we don't try to validate them.
95 fSettings.fValidateSPIRV = false;
96
97 this->fixUpSource();
98 }
static SkTileMode optimize(SkTileMode tm, int dimension)
static const char * output_string(Output output)
Definition SkSLBench.cpp:73
const char * name
Definition fuchsia.cc:50

Member Function Documentation

◆ CompileToSkRP()

static bool SkSLCompileBench::CompileToSkRP ( const SkSL::Program program)
inlinestaticprotected

Definition at line 185 of file SkSLBench.cpp.

185 {
186 const SkSL::FunctionDeclaration* main = program.getFunction("main");
187 if (!main) {
188 return false;
189 }
190
191 // Compile our program.
192 std::unique_ptr<SkSL::RP::Program> rasterProg = SkSL::MakeRasterPipelineProgram(
193 program, *main->definition(), /*debugTrace=*/nullptr, /*writeTraceOps=*/false);
194 if (!rasterProg) {
195 return false;
196 }
197
198 // We need to supply a valid uniform range, but the uniform values inside don't actually
199 // matter, since we aren't going to run the shader.
200 float uniformBuffer[1024];
201 if (rasterProg->numUniforms() > (int)std::size(uniformBuffer)) {
202 return false;
203 }
204
205 // Append the program to a raster pipeline.
207 SkRasterPipeline pipeline(&alloc);
208 rasterProg->appendStages(&pipeline,
209 &alloc,
210 /*callbacks=*/nullptr,
211 /*uniforms=*/SkSpan{uniformBuffer, rasterProg->numUniforms()});
212 return true;
213 }
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)
Definition main.py:1
const FunctionDeclaration * getFunction(const char *functionName) const

◆ fixUpSource()

void SkSLCompileBench::fixUpSource ( )
inlineprotected

Definition at line 122 of file SkSLBench.cpp.

122 {
123 auto fixup = [this](const char* input, const char* replacement) {
124 fSrc = std::regex_replace(fSrc, std::regex(input), replacement);
125 };
126
127 // Runtime shaders have slightly different conventions than fragment shaders.
128 // Perform a handful of fixups to compensate. These are hand-tuned for our current set of
129 // test shaders and will probably need to be updated if we add more.
130 if (this->usesRuntimeShader()) {
131 fixup(R"(void main\‍(\))", "half4 main(float2 xy)");
132 fixup(R"(sk_FragColor =)", "return");
133 fixup(R"(sk_FragCoord)", "_FragCoord");
134 fixup(R"(sampler2D )", "uniform shader ");
135 fixup(R"((flat |noperspective |)in )", "uniform ");
136 fixup(R"(sample\‍(([A-Za-z0-9_]+), ([A-Za-z0-9_]+)\))", "$01.eval($02)");
137 fSrc = "#version 300\nuniform float4 _FragCoord;\n" + fSrc;
138 }
139 }
bool usesRuntimeShader() const

◆ isSuitableFor()

bool SkSLCompileBench::isSuitableFor ( Backend  backend)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 105 of file SkSLBench.cpp.

105 {
106#if !defined(SK_GRAPHITE)
107 if (this->usesGraphite()) {
108 return false;
109 }
110#endif
112 }
const char * backend
bool usesGraphite() const

◆ onDraw()

void SkSLCompileBench::onDraw ( int  loops,
SkCanvas canvas 
)
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 141 of file SkSLBench.cpp.

141 {
143 if (this->usesRuntimeShader()) {
145 } else if (this->usesGraphite()) {
147 } else {
149 }
150 for (int i = 0; i < loops; i++) {
151 std::unique_ptr<SkSL::Program> program = fCompiler.convertProgram(kind, fSrc,
152 fSettings);
153 if (fCompiler.errorCount()) {
154 SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str());
155 }
156 std::string result;
157 switch (fOutput) {
158 case Output::kNone:
159 break;
160
161 case Output::kGLSL:
162 SkAssertResult(SkSL::ToGLSL(*program, fCaps.shaderCaps(), &result));
163 break;
164
165 case Output::kMetal:
166 case Output::kGrMtl:
167 SkAssertResult(SkSL::ToMetal(*program, fCaps.shaderCaps(), &result));
168 break;
169
170 case Output::kSPIRV:
171 SkAssertResult(SkSL::ToSPIRV(*program, fCaps.shaderCaps(), &result));
172 break;
173
174 case Output::kGrWGSL:
175 SkAssertResult(SkSL::ToWGSL(*program, fCaps.shaderCaps(), &result));
176 break;
177
178 case Output::kSkRP:
179 SkAssertResult(CompileToSkRP(*program));
180 break;
181 }
182 }
183 }
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SK_ABORT(message,...)
Definition SkAssert.h:70
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
static bool CompileToSkRP(const SkSL::Program &program)
std::string errorText(bool showCount=true)
int errorCount() const
std::unique_ptr< Program > convertProgram(ProgramKind kind, std::string programSource, const ProgramSettings &settings)
GAsyncResult * result
bool ToSPIRV(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToWGSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToGLSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToMetal(Program &program, const ShaderCaps *caps, OutputStream &out)

◆ onGetName()

const char * SkSLCompileBench::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 101 of file SkSLBench.cpp.

101 {
102 return fName.c_str();
103 }

◆ output_string()

static const char * SkSLCompileBench::output_string ( Output  output)
inlinestatic

Definition at line 73 of file SkSLBench.cpp.

73 {
74 switch (output) {
75 case Output::kNone: return "";
76 case Output::kGLSL: return "glsl_";
77 case Output::kMetal: return "metal_";
78 case Output::kSPIRV: return "spirv_";
79 case Output::kGrMtl: return "grmtl_";
80 case Output::kGrWGSL: return "grwgsl_";
81 case Output::kSkRP: return "skrp_";
82 }
84 }
#define SkUNREACHABLE
Definition SkAssert.h:135

◆ usesGraphite()

bool SkSLCompileBench::usesGraphite ( ) const
inlineprotected

Definition at line 118 of file SkSLBench.cpp.

118 {
119 return fOutput == Output::kGrMtl || fOutput == Output::kGrWGSL;
120 }

◆ usesRuntimeShader()

bool SkSLCompileBench::usesRuntimeShader ( ) const
inlineprotected

Definition at line 114 of file SkSLBench.cpp.

114 {
115 return fOutput == Output::kSkRP;
116 }

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