restructured SkSL include files

Bug: skia:
Change-Id: I342de85d9602c953c8a8fd0f3891cd86bb5c35eb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215614
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2019-05-24 11:01:59 -04:00 committed by Skia Commit-Bot
parent e92594ae5d
commit 8da1e65602
6 changed files with 64 additions and 38 deletions

View File

@ -36,8 +36,12 @@
#define STRINGIFY(x) #x
static const char* SKSL_INCLUDE =
#include "sksl.inc"
static const char* SKSL_GPU_INCLUDE =
#include "sksl_gpu.inc"
;
static const char* SKSL_INTERP_INCLUDE =
#include "sksl_interp.inc"
;
static const char* SKSL_VERT_INCLUDE =
@ -57,8 +61,8 @@ static const char* SKSL_FP_INCLUDE =
#include "sksl_fp.inc"
;
static const char* SKSL_GENERIC_INCLUDE =
#include "sksl_generic.inc"
static const char* SKSL_PIPELINE_INCLUDE =
#include "sksl_pipeline.inc"
;
namespace SkSL {
@ -219,38 +223,42 @@ Compiler::Compiler(Flags flags)
fIRGenerator->fSymbolTable->add(skArgsName, std::unique_ptr<Symbol>(skArgs));
std::vector<std::unique_ptr<ProgramElement>> ignored;
fIRGenerator->convertProgram(Program::kFragment_Kind, SKSL_INCLUDE, strlen(SKSL_INCLUDE),
*fTypes, &ignored);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
if (fErrorCount) {
printf("Unexpected errors: %s\n", fErrorText.c_str());
}
SkASSERT(!fErrorCount);
Program::Settings settings;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(Program::kFragment_Kind, SKSL_VERT_INCLUDE,
strlen(SKSL_VERT_INCLUDE), *fTypes, &fVertexInclude);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
fVertexSymbolTable = fIRGenerator->fSymbolTable;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(Program::kVertex_Kind, SKSL_FRAG_INCLUDE,
strlen(SKSL_FRAG_INCLUDE), *fTypes, &fFragmentInclude);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
fFragmentSymbolTable = fIRGenerator->fSymbolTable;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(Program::kGeometry_Kind, SKSL_GEOM_INCLUDE,
strlen(SKSL_GEOM_INCLUDE), *fTypes, &fGeometryInclude);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
fGeometrySymbolTable = fIRGenerator->fSymbolTable;
this->processIncludeFile(Program::kFragment_Kind, SKSL_GPU_INCLUDE, strlen(SKSL_GPU_INCLUDE),
symbols, &ignored, &fGpuSymbolTable);
this->processIncludeFile(Program::kVertex_Kind, SKSL_VERT_INCLUDE, strlen(SKSL_VERT_INCLUDE),
fGpuSymbolTable, &fVertexInclude, &fVertexSymbolTable);
this->processIncludeFile(Program::kFragment_Kind, SKSL_FRAG_INCLUDE, strlen(SKSL_FRAG_INCLUDE),
fGpuSymbolTable, &fFragmentInclude, &fFragmentSymbolTable);
this->processIncludeFile(Program::kGeometry_Kind, SKSL_GEOM_INCLUDE, strlen(SKSL_GEOM_INCLUDE),
fGpuSymbolTable, &fGeometryInclude, &fGeometrySymbolTable);
this->processIncludeFile(Program::kPipelineStage_Kind, SKSL_PIPELINE_INCLUDE,
strlen(SKSL_PIPELINE_INCLUDE), fGpuSymbolTable, &fPipelineInclude,
&fPipelineSymbolTable);
this->processIncludeFile(Program::kGeneric_Kind, SKSL_INTERP_INCLUDE,
strlen(SKSL_INTERP_INCLUDE), symbols, &fInterpreterInclude,
&fInterpreterSymbolTable);
}
Compiler::~Compiler() {
delete fIRGenerator;
}
void Compiler::processIncludeFile(Program::Kind kind, const char* src, size_t length,
std::shared_ptr<SymbolTable> base,
std::vector<std::unique_ptr<ProgramElement>>* outElements,
std::shared_ptr<SymbolTable>* outSymbolTable) {
fIRGenerator->fSymbolTable = std::move(base);
Program::Settings settings;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(kind, src, length, *fTypes, outElements);
if (this->fErrorCount) {
printf("Unexpected errors: %s\n", this->fErrorText.c_str());
}
SkASSERT(!fErrorCount);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
*outSymbolTable = fIRGenerator->fSymbolTable;
}
// add the definition created by assigning to the lvalue to the definition set
void Compiler::addDefinition(const Expression* lvalue, std::unique_ptr<Expression>* expr,
DefinitionMap* definitions) {
@ -1268,18 +1276,21 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String tex
break;
case Program::kFragmentProcessor_Kind:
inherited = nullptr;
fIRGenerator->fSymbolTable = fGpuSymbolTable;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(kind, SKSL_FP_INCLUDE, strlen(SKSL_FP_INCLUDE), *fTypes,
&elements);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
break;
case Program::kPipelineStage_Kind: // fall through
case Program::kPipelineStage_Kind:
inherited = &fPipelineInclude;
fIRGenerator->fSymbolTable = fPipelineSymbolTable;
fIRGenerator->start(&settings, inherited);
break;
case Program::kGeneric_Kind:
inherited = nullptr;
fIRGenerator->start(&settings, nullptr);
fIRGenerator->convertProgram(kind, SKSL_GENERIC_INCLUDE,
strlen(SKSL_GENERIC_INCLUDE), *fTypes, &elements);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
inherited = &fInterpreterInclude;
fIRGenerator->fSymbolTable = fInterpreterSymbolTable;
fIRGenerator->start(&settings, inherited);
break;
}
for (auto& element : elements) {

View File

@ -149,6 +149,11 @@ public:
static bool IsAssignment(Token::Kind token);
private:
void processIncludeFile(Program::Kind kind, const char* src, size_t length,
std::shared_ptr<SymbolTable> base,
std::vector<std::unique_ptr<ProgramElement>>* outElements,
std::shared_ptr<SymbolTable>* outSymbolTable);
void addDefinition(const Expression* lvalue, std::unique_ptr<Expression>* expr,
DefinitionMap* definitions);
@ -184,12 +189,17 @@ private:
Position position(int offset);
std::shared_ptr<SymbolTable> fGpuSymbolTable;
std::vector<std::unique_ptr<ProgramElement>> fVertexInclude;
std::shared_ptr<SymbolTable> fVertexSymbolTable;
std::vector<std::unique_ptr<ProgramElement>> fFragmentInclude;
std::shared_ptr<SymbolTable> fFragmentSymbolTable;
std::vector<std::unique_ptr<ProgramElement>> fGeometryInclude;
std::shared_ptr<SymbolTable> fGeometrySymbolTable;
std::vector<std::unique_ptr<ProgramElement>> fPipelineInclude;
std::shared_ptr<SymbolTable> fPipelineSymbolTable;
std::vector<std::unique_ptr<ProgramElement>> fInterpreterInclude;
std::shared_ptr<SymbolTable> fInterpreterSymbolTable;
std::shared_ptr<SymbolTable> fTypes;
IRGenerator* fIRGenerator;

View File

@ -215,7 +215,6 @@ struct Program {
kFragmentProcessor_Kind,
kPipelineStage_Kind,
kGeneric_Kind,
};
Program(Kind kind,

View File

@ -1,6 +1,6 @@
STRINGIFY(
// defines built-in functions supported by SkiaSL
// defines built-in functions supported by SkSL when running on a GPU
$genType radians($genType degrees);
$genType sin($genType angle);

6
src/sksl/sksl_interp.inc Normal file
View File

@ -0,0 +1,6 @@
STRINGIFY(
float sin(float x);
float cos(float y);
float tan(float x);
float sqrt(float x);
)