Require DSL variables to have names.

The DSLVar class hierarchy had many constructor variations to support
the idea of creating DSL variables without explicitly assigning a name
to them. Instead, name-mangling would automatically assign them a name
like `_123_var`. This was designed to make it easlier to write a
complete shader in DSL.

We no longer have DSL name-mangling, or intend to create complete
programs in pure DSL. In the absence of name-mangling, these
constructors aren't useful (every variable would be named `var`).
They have been removed.

Change-Id: If533e479cc04c5a6ced9a7e880dcc56063f29374
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/542138
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2022-05-19 10:57:29 -04:00 committed by SkCQ
parent 16f1505498
commit a6178be7d1
4 changed files with 12 additions and 59 deletions

View File

@ -38,22 +38,14 @@ public:
DSLVarBase() : fType(kVoid_Type) {}
/**
* Constructs a new variable with the specified type and name. The name is used (in mangled
* form) in the resulting shader code; it is not otherwise important. Since mangling prevents
* name conflicts and the variable's name is only important when debugging shaders, the name
* parameter is optional.
* Constructs a new variable with the specified type and name.
*/
DSLVarBase(DSLType type, std::string_view name, DSLExpression initialValue, Position pos,
Position namePos);
DSLVarBase(DSLType type, DSLExpression initialValue, Position pos, Position namePos);
DSLVarBase(const DSLModifiers& modifiers, DSLType type, std::string_view name,
DSLExpression initialValue, Position pos, Position namePos);
DSLVarBase(const DSLModifiers& modifiers, DSLType type, DSLExpression initialValue,
Position pos, Position namePos);
DSLVarBase(DSLVarBase&&) = default;
virtual ~DSLVarBase();
@ -159,26 +151,15 @@ private:
public:
DSLVar() = default;
DSLVar(DSLType type, std::string_view name = "var",
DSLVar(DSLType type, std::string_view name,
DSLExpression initialValue = DSLExpression(),
Position pos = {}, Position namePos = {})
: INHERITED(type, name, std::move(initialValue), pos, namePos) {}
DSLVar(DSLType type, const char* name, DSLExpression initialValue = DSLExpression(),
Position pos = {}, Position namePos = {})
: DSLVar(type, std::string_view(name), std::move(initialValue), pos, namePos) {}
DSLVar(DSLType type, DSLExpression initialValue, Position pos = {}, Position namePos = {})
: INHERITED(type, std::move(initialValue), pos, namePos) {}
DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name = "var",
DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name,
DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {})
: INHERITED(modifiers, type, name, std::move(initialValue), pos, namePos) {}
DSLVar(const DSLModifiers& modifiers, DSLType type, const char* name,
DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {})
: DSLVar(modifiers, type, std::string_view(name), std::move(initialValue), pos, namePos) {}
DSLVar(DSLVar&&) = default;
VariableStorage storage() const override;
@ -207,27 +188,14 @@ private:
public:
DSLGlobalVar() = default;
DSLGlobalVar(DSLType type, std::string_view name = "var",
DSLGlobalVar(DSLType type, std::string_view name,
DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {})
: INHERITED(type, name, std::move(initialValue), pos, namePos) {}
DSLGlobalVar(DSLType type, const char* name, DSLExpression initialValue = DSLExpression(),
Position pos = {}, Position namePos = {})
: DSLGlobalVar(type, std::string_view(name), std::move(initialValue), pos, namePos) {}
DSLGlobalVar(DSLType type, DSLExpression initialValue,
Position pos = {}, Position namePos = {})
: INHERITED(type, std::move(initialValue), pos, namePos) {}
DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name = "var",
DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name,
DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {})
: INHERITED(modifiers, type, name, std::move(initialValue), pos, namePos) {}
DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, const char* name,
DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {})
: DSLGlobalVar(modifiers, type, std::string_view(name), std::move(initialValue), pos,
namePos) {}
DSLGlobalVar(const char* name);
DSLGlobalVar(DSLGlobalVar&&) = default;
@ -277,21 +245,13 @@ private:
public:
DSLParameter() = default;
DSLParameter(DSLType type, std::string_view name = "var",
Position pos = {}, Position namePos = {})
DSLParameter(DSLType type, std::string_view name, Position pos = {}, Position namePos = {})
: INHERITED(type, name, DSLExpression(), pos, namePos) {}
DSLParameter(DSLType type, const char* name, Position pos = {}, Position namePos = {})
: DSLParameter(type, std::string_view(name), pos, namePos) {}
DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name = "var",
DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name,
Position pos = {}, Position namePos = {})
: INHERITED(modifiers, type, name, DSLExpression(), pos, namePos) {}
DSLParameter(const DSLModifiers& modifiers, DSLType type, const char* name,
Position pos = {}, Position namePos = {})
: DSLParameter(modifiers, type, std::string_view(name), pos, namePos) {}
DSLParameter(DSLParameter&&) = default;
VariableStorage storage() const override;

View File

@ -30,13 +30,6 @@ DSLVarBase::DSLVarBase(DSLType type, std::string_view name, DSLExpression initia
Position pos, Position namePos)
: DSLVarBase(DSLModifiers(), std::move(type), name, std::move(initialValue), pos, namePos) {}
DSLVarBase::DSLVarBase(DSLType type, DSLExpression initialValue, Position pos, Position namePos)
: DSLVarBase(type, "var", std::move(initialValue), pos, namePos) {}
DSLVarBase::DSLVarBase(const DSLModifiers& modifiers, DSLType type, DSLExpression initialValue,
Position pos, Position namePos)
: DSLVarBase(modifiers, type, "var", std::move(initialValue), pos, namePos) {}
DSLVarBase::DSLVarBase(const DSLModifiers& modifiers, DSLType type, std::string_view name,
DSLExpression initialValue, Position pos, Position namePos)
: fModifiers(std::move(modifiers))

View File

@ -24,7 +24,7 @@ void StartDSL(const sk_gpu_test::ContextInfo ctxInfo);
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLImportOnly, r, ctxInfo) {
StartDSL(ctxInfo);
Parameter x(kInt_Type);
Parameter x(kInt_Type, "x");
Function(kInt_Type, "test", x).define(
If(x >= 0,
Block(Return(x)),

View File

@ -578,7 +578,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLType, r, ctxInfo) {
REPORTER_ASSERT(r, DSLType(Array(kFloat_Type, 2)).isArray());
REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isStruct());
Var x(kFloat_Type);
Var x(kFloat_Type, "x");
DSLExpression e = x + 1;
REPORTER_ASSERT(r, e.type().isFloat());
e.release();
@ -722,7 +722,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLPlus, r, ctxInfo) {
{
ExpectError error(r, "'+' cannot operate on 'bool'");
Var c(kBool_Type);
Var c(kBool_Type, "c");
DSLExpression(+c).release();
}
}
@ -761,7 +761,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLMinus, r, ctxInfo) {
{
ExpectError error(r, "'-' cannot operate on 'bool'");
Var c(kBool_Type);
Var c(kBool_Type, "c");
DSLExpression(-c).release();
}
}
@ -1677,7 +1677,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSwitch, r, ctxInfo) {
{
ExpectError error(r, "case value must be a constant integer");
Var c(kInt_Type);
Var c(kInt_Type, "c");
DSLStatement(Switch(0, Case(c))).release();
}
}