added DSL Modifiers
Change-Id: Ie1b0b8068b487905691b20e318c7898653763a25 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359757 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
dd29e20904
commit
d6b26e5f06
@ -16,6 +16,7 @@ namespace dsl {
|
||||
|
||||
using Block = DSLBlock;
|
||||
using Expression = DSLExpression;
|
||||
using Modifiers = DSLModifiers;
|
||||
using Statement = DSLStatement;
|
||||
using Var = DSLVar;
|
||||
|
||||
|
45
src/sksl/dsl/DSLModifiers.h
Normal file
45
src/sksl/dsl/DSLModifiers.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SKSL_DSL_MODIFIERS
|
||||
#define SKSL_DSL_MODIFIERS
|
||||
|
||||
#include "src/sksl/ir/SkSLModifiers.h"
|
||||
namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
|
||||
enum Modifier {
|
||||
kNo_Modifier = 0,
|
||||
kConst_Modifier = 1 << 0,
|
||||
kIn_Modifier = 1 << 1,
|
||||
kOut_Modifier = 1 << 2,
|
||||
kInOut_Modifier = kIn_Modifier | kOut_Modifier,
|
||||
kUniform_Modifier = 1 << 3,
|
||||
kFlat_Modifier = 1 << 4,
|
||||
kNoPerspective_Modifier = 1 << 5,
|
||||
};
|
||||
|
||||
class DSLModifiers {
|
||||
public:
|
||||
|
||||
DSLModifiers() {}
|
||||
|
||||
DSLModifiers(int flags)
|
||||
: fModifiers(SkSL::Layout(), flags) {}
|
||||
|
||||
private:
|
||||
SkSL::Modifiers fModifiers;
|
||||
|
||||
friend class DSLVar;
|
||||
};
|
||||
|
||||
} // namespace dsl
|
||||
|
||||
} // namespace SkSL
|
||||
|
||||
#endif
|
@ -8,6 +8,7 @@
|
||||
#include "src/sksl/dsl/DSLVar.h"
|
||||
|
||||
#include "src/sksl/SkSLUtil.h"
|
||||
#include "src/sksl/dsl/DSLModifiers.h"
|
||||
#include "src/sksl/dsl/DSLType.h"
|
||||
#include "src/sksl/dsl/priv/DSLWriter.h"
|
||||
#include "src/sksl/ir/SkSLBinaryExpression.h"
|
||||
@ -27,12 +28,14 @@ DSLVar::DSLVar(const char* name)
|
||||
}
|
||||
|
||||
DSLVar::DSLVar(DSLType type, const char* name)
|
||||
: DSLVar(DSLModifiers(), std::move(type), name) {}
|
||||
|
||||
DSLVar::DSLVar(DSLModifiers modifiers, DSLType type, const char* name)
|
||||
: fName(DSLWriter::Name(name)) {
|
||||
Modifiers modifiers;
|
||||
DSLWriter::IRGenerator().checkVarDeclaration(/*offset=*/-1, modifiers, &type.skslType(),
|
||||
Variable::Storage::kLocal);
|
||||
DSLWriter::IRGenerator().checkVarDeclaration(/*offset=*/-1, modifiers.fModifiers,
|
||||
&type.skslType(), Variable::Storage::kLocal);
|
||||
fDeclaration = DSLWriter::IRGenerator().convertVarDeclaration(/*offset=*/-1,
|
||||
modifiers,
|
||||
modifiers.fModifiers,
|
||||
&type.skslType(),
|
||||
fName,
|
||||
/*isArray=*/false,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define SKSL_DSL_VAR
|
||||
|
||||
#include "src/sksl/dsl/DSLExpression.h"
|
||||
#include "src/sksl/dsl/DSLModifiers.h"
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
@ -28,6 +29,8 @@ public:
|
||||
*/
|
||||
DSLVar(DSLType type, const char* name = "var");
|
||||
|
||||
DSLVar(DSLModifiers modifiers, DSLType type, const char* name = "var");
|
||||
|
||||
DSLVar(DSLVar&&) = delete;
|
||||
|
||||
DSLExpression x() {
|
||||
|
@ -112,6 +112,10 @@ void DSLWriter::ReportError(const char* msg) {
|
||||
}
|
||||
}
|
||||
|
||||
const SkSL::Variable& DSLWriter::Var(const DSLVar& var) {
|
||||
return *var.var();
|
||||
}
|
||||
|
||||
#if !SK_SUPPORT_GPU || defined(SKSL_STANDALONE)
|
||||
|
||||
DSLWriter& DSLWriter::Instance() {
|
||||
|
@ -69,6 +69,11 @@ public:
|
||||
*/
|
||||
static const SkSL::Modifiers* Modifiers(SkSL::Modifiers modifiers);
|
||||
|
||||
/**
|
||||
* Returns the SkSL variable corresponding to a DSLVar.
|
||||
*/
|
||||
static const SkSL::Variable& Var(const DSLVar& var);
|
||||
|
||||
/**
|
||||
* Returns the (possibly mangled) final name that should be used for an entity with the given
|
||||
* raw name.
|
||||
|
@ -1111,3 +1111,38 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBuiltins, r, ctxInfo) {
|
||||
Ceil(a == b).release();
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLModifiers, r, ctxInfo) {
|
||||
AutoDSLContext context(ctxInfo.directContext()->priv().getGpu());
|
||||
|
||||
Var v1(kConst_Modifier, kInt, "v1");
|
||||
Statement d1 = Declare(v1);
|
||||
REPORTER_ASSERT(r, d1.release()->description() == "const int v1;");
|
||||
|
||||
// Most modifiers require an appropriate context to be legal. We can't yet give them that
|
||||
// context, so we can't as yet Declare() variables with these modifiers.
|
||||
// TODO: better tests when able
|
||||
Var v2(kIn_Modifier, kInt, "v2");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v2).modifiers().fFlags == SkSL::Modifiers::kIn_Flag);
|
||||
|
||||
Var v3(kOut_Modifier, kInt, "v3");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v3).modifiers().fFlags == SkSL::Modifiers::kOut_Flag);
|
||||
|
||||
Var v4(kUniform_Modifier, kInt, "v4");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v4).modifiers().fFlags == SkSL::Modifiers::kUniform_Flag);
|
||||
|
||||
Var v5(kFlat_Modifier, kInt, "v5");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v5).modifiers().fFlags == SkSL::Modifiers::kFlat_Flag);
|
||||
|
||||
Var v6(kNoPerspective_Modifier, kInt, "v6");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v6).modifiers().fFlags ==
|
||||
SkSL::Modifiers::kNoPerspective_Flag);
|
||||
|
||||
Var v7(kIn_Modifier | kOut_Modifier, kInt, "v7");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v7).modifiers().fFlags ==
|
||||
(SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag));
|
||||
|
||||
Var v8(kInOut_Modifier, kInt, "v8");
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(v8).modifiers().fFlags ==
|
||||
(SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user