SkSL: In the front-end, rename PipelineStage to RuntimeEffect

This maps to usage better, and makes some code simpler to understand.
Note that there is still a PipelineStage *back-end*, which is specific
to the runtime-effect FP. A kRuntimeEffect_Kind program can be used to
generate a PipelineStage (for the GPU backend), or an skvm program (for
the CPU backend).

Change-Id: Id3f535db93a239726c595225aafe9467f0d19817
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/344969
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2020-12-21 13:20:40 -05:00 committed by Skia Commit-Bot
parent 3a8538187d
commit 9194675a3e
12 changed files with 62 additions and 67 deletions

View File

@ -609,8 +609,8 @@ if (skia_compile_processors || skia_compile_sksl_tests) {
"src/sksl/sksl_geom.sksl",
"src/sksl/sksl_gpu.sksl",
"src/sksl/sksl_interp.sksl",
"src/sksl/sksl_pipeline.sksl",
"src/sksl/sksl_public.sksl",
"src/sksl/sksl_runtime.sksl",
"src/sksl/sksl_vert.sksl",
]
outputs = [ "$root_out_dir/{{source_file_part}}" ]

View File

@ -595,7 +595,7 @@ void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
int before = heap_bytes_used();
GrShaderCaps caps(GrContextOptions{});
SkSL::Compiler compiler(&caps);
compiler.moduleForProgramKind(SkSL::Program::kPipelineStage_Kind);
compiler.moduleForProgramKind(SkSL::Program::kRuntimeEffect_Kind);
int after = heap_bytes_used();
bench("sksl_compiler_runtimeeffect", after - before);
}

View File

@ -15,7 +15,7 @@ bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
SkSL::Compiler compiler(caps.get());
SkSL::Program::Settings settings;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
SkSL::Program::kPipelineStage_Kind,
SkSL::Program::kRuntimeEffect_Kind,
SkSL::String((const char*) bytes->data(),
bytes->size()),
settings);

View File

@ -156,7 +156,7 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
SkSL::Program::Settings settings;
settings.fInlineThreshold = compiler.getInlineThreshold();
settings.fAllowNarrowingConversions = true;
auto program = compiler->convertProgram(SkSL::Program::kPipelineStage_Kind,
auto program = compiler->convertProgram(SkSL::Program::kRuntimeEffect_Kind,
SkSL::String(sksl.c_str(), sksl.size()),
settings);
// TODO: Many errors aren't caught until we process the generated Program here. Catching those

View File

@ -60,8 +60,8 @@
#include "src/sksl/generated/sksl_geom.dehydrated.sksl"
#include "src/sksl/generated/sksl_gpu.dehydrated.sksl"
#include "src/sksl/generated/sksl_interp.dehydrated.sksl"
#include "src/sksl/generated/sksl_pipeline.dehydrated.sksl"
#include "src/sksl/generated/sksl_public.dehydrated.sksl"
#include "src/sksl/generated/sksl_runtime.dehydrated.sksl"
#include "src/sksl/generated/sksl_vert.dehydrated.sksl"
#define MODULE_DATA(name) MakeModuleData(SKSL_INCLUDE_sksl_##name,\
@ -227,39 +227,39 @@ const ParsedModule& Compiler::loadPublicModule() {
return fPublicModule;
}
const ParsedModule& Compiler::loadPipelineModule() {
if (!fPipelineModule.fSymbols) {
fPipelineModule = this->parseModule(Program::kPipelineStage_Kind, MODULE_DATA(pipeline),
this->loadPublicModule());
const ParsedModule& Compiler::loadRuntimeEffectModule() {
if (!fRuntimeEffectModule.fSymbols) {
fRuntimeEffectModule = this->parseModule(Program::kRuntimeEffect_Kind, MODULE_DATA(runtime),
this->loadPublicModule());
// Add some aliases to the pipeline module so that it's friendlier, and more like GLSL
fPipelineModule.fSymbols->addAlias("shader", fContext->fFragmentProcessor_Type.get());
// Add some aliases to the runtime effect module so that it's friendlier, and more like GLSL
fRuntimeEffectModule.fSymbols->addAlias("shader", fContext->fFragmentProcessor_Type.get());
fPipelineModule.fSymbols->addAlias("vec2", fContext->fFloat2_Type.get());
fPipelineModule.fSymbols->addAlias("vec3", fContext->fFloat3_Type.get());
fPipelineModule.fSymbols->addAlias("vec4", fContext->fFloat4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("vec2", fContext->fFloat2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("vec3", fContext->fFloat3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("vec4", fContext->fFloat4_Type.get());
fPipelineModule.fSymbols->addAlias("bvec2", fContext->fBool2_Type.get());
fPipelineModule.fSymbols->addAlias("bvec3", fContext->fBool3_Type.get());
fPipelineModule.fSymbols->addAlias("bvec4", fContext->fBool4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("bvec2", fContext->fBool2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("bvec3", fContext->fBool3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("bvec4", fContext->fBool4_Type.get());
fPipelineModule.fSymbols->addAlias("mat2", fContext->fFloat2x2_Type.get());
fPipelineModule.fSymbols->addAlias("mat3", fContext->fFloat3x3_Type.get());
fPipelineModule.fSymbols->addAlias("mat4", fContext->fFloat4x4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat2", fContext->fFloat2x2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat3", fContext->fFloat3x3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat4", fContext->fFloat4x4_Type.get());
fPipelineModule.fSymbols->addAlias("mat2x2", fContext->fFloat2x2_Type.get());
fPipelineModule.fSymbols->addAlias("mat2x3", fContext->fFloat2x3_Type.get());
fPipelineModule.fSymbols->addAlias("mat2x4", fContext->fFloat2x4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat2x2", fContext->fFloat2x2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat2x3", fContext->fFloat2x3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat2x4", fContext->fFloat2x4_Type.get());
fPipelineModule.fSymbols->addAlias("mat3x2", fContext->fFloat3x2_Type.get());
fPipelineModule.fSymbols->addAlias("mat3x3", fContext->fFloat3x3_Type.get());
fPipelineModule.fSymbols->addAlias("mat3x4", fContext->fFloat3x4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat3x2", fContext->fFloat3x2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat3x3", fContext->fFloat3x3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat3x4", fContext->fFloat3x4_Type.get());
fPipelineModule.fSymbols->addAlias("mat4x2", fContext->fFloat4x2_Type.get());
fPipelineModule.fSymbols->addAlias("mat4x3", fContext->fFloat4x3_Type.get());
fPipelineModule.fSymbols->addAlias("mat4x4", fContext->fFloat4x4_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat4x2", fContext->fFloat4x2_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat4x3", fContext->fFloat4x3_Type.get());
fRuntimeEffectModule.fSymbols->addAlias("mat4x4", fContext->fFloat4x4_Type.get());
}
return fPipelineModule;
return fRuntimeEffectModule;
}
const ParsedModule& Compiler::loadInterpreterModule() {
@ -272,12 +272,12 @@ const ParsedModule& Compiler::loadInterpreterModule() {
const ParsedModule& Compiler::moduleForProgramKind(Program::Kind kind) {
switch (kind) {
case Program::kVertex_Kind: return this->loadVertexModule(); break;
case Program::kFragment_Kind: return this->loadFragmentModule(); break;
case Program::kGeometry_Kind: return this->loadGeometryModule(); break;
case Program::kFragmentProcessor_Kind: return this->loadFPModule(); break;
case Program::kPipelineStage_Kind: return this->loadPipelineModule(); break;
case Program::kGeneric_Kind: return this->loadInterpreterModule(); break;
case Program::kVertex_Kind: return this->loadVertexModule(); break;
case Program::kFragment_Kind: return this->loadFragmentModule(); break;
case Program::kGeometry_Kind: return this->loadGeometryModule(); break;
case Program::kFragmentProcessor_Kind: return this->loadFPModule(); break;
case Program::kRuntimeEffect_Kind: return this->loadRuntimeEffectModule(); break;
case Program::kGeneric_Kind: return this->loadInterpreterModule(); break;
}
SkUNREACHABLE;
}

View File

@ -232,7 +232,7 @@ private:
const ParsedModule& loadGeometryModule();
const ParsedModule& loadPublicModule();
const ParsedModule& loadInterpreterModule();
const ParsedModule& loadPipelineModule();
const ParsedModule& loadRuntimeEffectModule();
void addDefinition(const Expression* lvalue, std::unique_ptr<Expression>* expr,
DefinitionMap* definitions);
@ -279,18 +279,18 @@ private:
std::shared_ptr<SymbolTable> fRootSymbolTable;
std::shared_ptr<SymbolTable> fPrivateSymbolTable;
ParsedModule fRootModule; // Core types
ParsedModule fRootModule; // Core types
ParsedModule fPrivateModule; // [Root] + Internal types
ParsedModule fGPUModule; // [Private] + GPU intrinsics, helper functions
ParsedModule fVertexModule; // [GPU] + Vertex stage decls
ParsedModule fFragmentModule; // [GPU] + Fragment stage decls
ParsedModule fGeometryModule; // [GPU] + Geometry stage decls
ParsedModule fFPModule; // [GPU] + FP features
ParsedModule fPrivateModule; // [Root] + Internal types
ParsedModule fGPUModule; // [Private] + GPU intrinsics, helper functions
ParsedModule fVertexModule; // [GPU] + Vertex stage decls
ParsedModule fFragmentModule; // [GPU] + Fragment stage decls
ParsedModule fGeometryModule; // [GPU] + Geometry stage decls
ParsedModule fFPModule; // [GPU] + FP features
ParsedModule fPublicModule; // [Root] + Public features
ParsedModule fInterpreterModule; // [Public] + Interpreter-only decls
ParsedModule fPipelineModule; // [Public] + Runtime effect decls
ParsedModule fPublicModule; // [Root] + Public features
ParsedModule fInterpreterModule; // [Public] + Interpreter-only decls
ParsedModule fRuntimeEffectModule; // [Public] + Runtime effect decls
// holds ModifiersPools belonging to the core includes for lifetime purposes
std::vector<std::unique_ptr<ModifiersPool>> fModifiers;

View File

@ -1069,10 +1069,6 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) {
fSetupFragPositionLocal = false;
fSetupFragCoordWorkaround = false;
// The pipeline-stage code generator can't use functions written this way, so make sure we don't
// accidentally end up here.
SkASSERT(fProgramKind != Program::kPipelineStage_Kind);
this->writeFunctionDeclaration(f.declaration());
this->writeLine(" {");
fIndentation++;

View File

@ -301,7 +301,7 @@ StatementArray IRGenerator::convertVarDeclarations(const ASTNode& decls,
fErrors.error(decls.fOffset, "'key' is only permitted within fragment processors");
}
}
if (fKind == Program::kPipelineStage_Kind) {
if (fKind == Program::kRuntimeEffect_Kind) {
if ((modifiers.fFlags & Modifiers::kIn_Flag) &&
baseType->nonnullable() != *fContext.fFragmentProcessor_Type) {
fErrors.error(decls.fOffset, "'in' variables not permitted in runtime effects");
@ -311,7 +311,7 @@ StatementArray IRGenerator::convertVarDeclarations(const ASTNode& decls,
fErrors.error(decls.fOffset, "'key' is not permitted on 'uniform' variables");
}
if (modifiers.fLayout.fMarker.fLength) {
if (fKind != Program::kPipelineStage_Kind) {
if (fKind != Program::kRuntimeEffect_Kind) {
fErrors.error(decls.fOffset, "'marker' is only permitted in runtime effects");
}
if (!(modifiers.fFlags & Modifiers::kUniform_Flag)) {
@ -322,7 +322,7 @@ StatementArray IRGenerator::convertVarDeclarations(const ASTNode& decls,
}
}
if (modifiers.fLayout.fFlags & Layout::kSRGBUnpremul_Flag) {
if (fKind != Program::kPipelineStage_Kind) {
if (fKind != Program::kRuntimeEffect_Kind) {
fErrors.error(decls.fOffset, "'srgb_unpremul' is only permitted in runtime effects");
}
if (!(modifiers.fFlags & Modifiers::kUniform_Flag)) {
@ -341,7 +341,7 @@ StatementArray IRGenerator::convertVarDeclarations(const ASTNode& decls,
}
}
if (modifiers.fFlags & Modifiers::kVarying_Flag) {
if (fKind != Program::kPipelineStage_Kind) {
if (fKind != Program::kRuntimeEffect_Kind) {
fErrors.error(decls.fOffset, "'varying' is only permitted in runtime effects");
}
if (!baseType->isFloat() &&
@ -879,7 +879,7 @@ void IRGenerator::convertFunction(const ASTNode& f) {
return true;
#else
GrSLType unusedSLType;
return fKind != Program::kPipelineStage_Kind ||
return fKind != Program::kRuntimeEffect_Kind ||
type_to_grsltype(fContext, *t, &unusedSLType);
#endif
};
@ -917,7 +917,7 @@ void IRGenerator::convertFunction(const ASTNode& f) {
}
Modifiers m = pd.fModifiers;
if (funcData.fName == "main" && (fKind == Program::kPipelineStage_Kind ||
if (funcData.fName == "main" && (fKind == Program::kRuntimeEffect_Kind ||
fKind == Program::kFragmentProcessor_Kind)) {
if (i == 0) {
// We verify that the type is correct later, for now, if there is a parameter to
@ -940,7 +940,7 @@ void IRGenerator::convertFunction(const ASTNode& f) {
if (funcData.fName == "main") {
switch (fKind) {
case Program::kPipelineStage_Kind: {
case Program::kRuntimeEffect_Kind: {
// (half4|float4) main() -or- (half4|float4) main(float2)
if (*returnType != *fContext.fHalf4_Type && *returnType != *fContext.fFloat4_Type) {
fErrors.error(f.fOffset, "'main' must return: 'vec4', 'float4', or 'half4'");
@ -1225,7 +1225,7 @@ void IRGenerator::convertGlobalVarDeclarations(const ASTNode& decl) {
}
void IRGenerator::convertEnum(const ASTNode& e) {
if (fKind == Program::kPipelineStage_Kind) {
if (fKind == Program::kRuntimeEffect_Kind) {
fErrors.error(e.fOffset, "enum is not allowed here");
return;
}
@ -2129,7 +2129,7 @@ std::unique_ptr<Expression> IRGenerator::call(int offset,
fErrors.error(offset, msg);
return nullptr;
}
if (fKind == Program::kPipelineStage_Kind && !function.definition() && !function.isBuiltin()) {
if (fKind == Program::kRuntimeEffect_Kind && !function.definition() && !function.isBuiltin()) {
String msg = "call to undefined function '" + function.name() + "'";
fErrors.error(offset, msg);
return nullptr;

View File

@ -253,11 +253,10 @@ ResultCode processCommand(std::vector<SkSL::String>& args) {
kind = SkSL::Program::kGeometry_Kind;
} else if (inputPath.endsWith(".fp")) {
kind = SkSL::Program::kFragmentProcessor_Kind;
} else if (inputPath.endsWith(".stage")) {
kind = SkSL::Program::kPipelineStage_Kind;
} else if (inputPath.endsWith(".rte")) {
kind = SkSL::Program::kRuntimeEffect_Kind;
} else {
printf("input filename must end in '.vert', '.frag', '.geom', '.fp', '.stage', or "
"'.sksl'\n");
printf("input filename must end in '.vert', '.frag', '.geom', '.fp', '.rte', or '.sksl'\n");
return ResultCode::kInputError;
}

View File

@ -1,4 +1,4 @@
static uint8_t SKSL_INCLUDE_sksl_pipeline[] = {87,0,
static uint8_t SKSL_INCLUDE_sksl_runtime[] = {87,0,
12,115,107,95,70,114,97,103,67,111,111,114,100,
6,102,108,111,97,116,52,
2,102,112,
@ -53,4 +53,4 @@ static uint8_t SKSL_INCLUDE_sksl_pipeline[] = {87,0,
42,2,0,0,
52,
13,};
static constexpr size_t SKSL_INCLUDE_sksl_pipeline_LENGTH = sizeof(SKSL_INCLUDE_sksl_pipeline);
static constexpr size_t SKSL_INCLUDE_sksl_runtime_LENGTH = sizeof(SKSL_INCLUDE_sksl_runtime);

View File

@ -176,7 +176,7 @@ struct Program {
kVertex_Kind,
kGeometry_Kind,
kFragmentProcessor_Kind,
kPipelineStage_Kind,
kRuntimeEffect_Kind,
kGeneric_Kind,
};