Broke DSLWriter into two separate classes
As DSLWriter evolved, it ended up performing two unrelated duties:
1. Holding per-thread state which is referenced throughout SkSL
(including non-DSL code)
2. DSL-specific utility functions
There's no reason for those to be contained in the same class, and
there's also no reason the per-thread state should be held in a
DSL-specific class. This breaks out an SkSL::ThreadContext class to hold
the state info, leaving the DSL utility functions behind in DSLWriter
(which should perhaps be renamed, but that's a job for a future CL).
Change-Id: Iccd45314bd9b37d4a1d3e27920e32a50c0b07d7c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/456736
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
index 8e8f552..980b8d4 100644
--- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
@@ -12,7 +12,7 @@
#include "include/sksl/DSLCore.h"
#include "src/sksl/SkSLCompiler.h"
#include "src/sksl/SkSLOperators.h"
-#include "src/sksl/dsl/priv/DSLWriter.h"
+#include "src/sksl/SkSLThreadContext.h"
#include "src/sksl/ir/SkSLBlock.h"
#include "src/sksl/ir/SkSLConstructorArrayCast.h"
#include "src/sksl/ir/SkSLExpressionStatement.h"
@@ -1095,8 +1095,8 @@
this->writeWord(fn, out);
this->addRTFlipUniform(c.fLine);
using namespace dsl;
- DSLExpression rtFlip(DSLWriter::IRGenerator().convertIdentifier(/*line=*/-1,
- SKSL_RTFLIP_NAME));
+ DSLExpression rtFlip(ThreadContext::IRGenerator().convertIdentifier(/*line=*/-1,
+ SKSL_RTFLIP_NAME));
SpvId rtFlipY = this->vectorize(*rtFlip.y().release(), callType.columns(), out);
SpvId flipped = this->nextId(&callType);
this->writeInstruction(SpvOpFMul, this->getType(callType), flipped, result, rtFlipY,
@@ -2111,12 +2111,12 @@
// Use sk_RTAdjust to compute the flipped coordinate
using namespace dsl;
const char* DEVICE_COORDS_NAME = "__device_FragCoords";
- SymbolTable& symbols = *dsl::DSLWriter::SymbolTable();
+ SymbolTable& symbols = *ThreadContext::SymbolTable();
// Use a uniform to flip the Y coordinate. The new expression will be written in
// terms of __device_FragCoords, which is a fake variable that means "access the
// underlying fragcoords directly without flipping it".
- DSLExpression rtFlip(DSLWriter::IRGenerator().convertIdentifier(/*line=*/-1,
- SKSL_RTFLIP_NAME));
+ DSLExpression rtFlip(ThreadContext::IRGenerator().convertIdentifier(/*line=*/-1,
+ SKSL_RTFLIP_NAME));
if (!symbols[DEVICE_COORDS_NAME]) {
AutoAttachPoolToThread attach(fProgram.fPool.get());
Modifiers modifiers;
@@ -2146,12 +2146,12 @@
this->addRTFlipUniform(ref.fLine);
using namespace dsl;
const char* DEVICE_CLOCKWISE_NAME = "__device_Clockwise";
- SymbolTable& symbols = *dsl::DSLWriter::SymbolTable();
+ SymbolTable& symbols = *ThreadContext::SymbolTable();
// Use a uniform to flip the Y coordinate. The new expression will be written in
// terms of __device_Clockwise, which is a fake variable that means "access the
// underlying FrontFacing directly".
- DSLExpression rtFlip(DSLWriter::IRGenerator().convertIdentifier(/*line=*/-1,
- SKSL_RTFLIP_NAME));
+ DSLExpression rtFlip(ThreadContext::IRGenerator().convertIdentifier(/*line=*/-1,
+ SKSL_RTFLIP_NAME));
if (!symbols[DEVICE_CLOCKWISE_NAME]) {
AutoAttachPoolToThread attach(fProgram.fPool.get());
Modifiers modifiers;