Reland "Add support for uniforms and layout(key)s to DSLCPPCodeGenerator."
This reverts commit289da86e37
. Reason for revert: relanding Original change's description: > Revert "Add support for uniforms and layout(key)s to DSLCPPCodeGenerator." > > This reverts commitf33b061e3b
. > > Reason for revert: Google3 roll and wasm build > > Original change's description: > > Add support for uniforms and layout(key)s to DSLCPPCodeGenerator. > > > > Change-Id: I77c386e3d72fb4a5986e5efb8bc9d409200534d1 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398457 > > Commit-Queue: John Stiles <johnstiles@google.com> > > Auto-Submit: John Stiles <johnstiles@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > TBR=brianosman@google.com,ethannicholas@google.com,johnstiles@google.com > > Change-Id: I006ece639fa6051ff6ef1c496e648db9d5d0b30a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:11854 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399498 > Reviewed-by: John Stiles <johnstiles@google.com> > Commit-Queue: John Stiles <johnstiles@google.com> Bug: skia:11854 Change-Id: I1a4a4db471e2ad0b169b2b77784ca17e6286fbd2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400036 Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
956802335d
commit
47b48bc2be
@ -1,9 +1,11 @@
|
||||
layout(key) in bool shouldLoop; // always equals false
|
||||
|
||||
// (This test code was largely borrowed from shared/DoWhileControlFlow.sksl.)
|
||||
half4 main() {
|
||||
half4 color = half4(1, 1, 1, 1);
|
||||
|
||||
// Simple do-while loop, with no Block.
|
||||
do color.r -= 0.25; while (color.r > 0.5);
|
||||
do color.r -= 0.25; while (shouldLoop);
|
||||
|
||||
// Do-while loop with a Block and Break in the middle.
|
||||
do {
|
||||
|
@ -1,6 +1,8 @@
|
||||
layout(key, ctype=SkPMColor4f) in half4 colorWhite;
|
||||
|
||||
// (This test code was largely borrowed from shared/ForLoopControlFlow.sksl.)
|
||||
half4 main() {
|
||||
half4 color = half4(1);
|
||||
half4 color = colorWhite;
|
||||
|
||||
// A basic for-loop with no block.
|
||||
for (half a = 0; a <= 1; ++a) color.a = a;
|
||||
|
@ -1,8 +1,10 @@
|
||||
layout(key) in half one; // always equals 1.0
|
||||
|
||||
half4 main() {
|
||||
half4 color = half4(0);
|
||||
|
||||
// Basic if statement. (00 == 00: true --> color=0001)
|
||||
if (color.rg == color.ba) color.a = 1;
|
||||
if (color.rg == color.ba) color.a = one;
|
||||
|
||||
// Basic if statement with Block. (00 == 01: false)
|
||||
if (color.rg == color.ba) {
|
||||
@ -15,7 +17,7 @@ half4 main() {
|
||||
if (color.r == color.g) color = color.araa; else color = color.rrra;
|
||||
|
||||
// Chained if-else statements.
|
||||
if (color.r + color.g + color.b + color.a == 1) { // (3 == 1: false)
|
||||
if (color.r + color.g + color.b + color.a == one) { // (3 == 1: false)
|
||||
color = half4(-1);
|
||||
} else if (color.r + color.g + color.b + color.a == 2) { // (3 == 2: false)
|
||||
color = half4(-2);
|
||||
@ -24,14 +26,14 @@ half4 main() {
|
||||
}
|
||||
|
||||
// Nested if-else statements.
|
||||
if (color.r == 1) { // (0 == 1: false)
|
||||
if (color.r == one) { // (0 == 1: false)
|
||||
if (color.r == 2) {
|
||||
color = color.rrrr;
|
||||
} else {
|
||||
color = color.gggg;
|
||||
}
|
||||
} else {
|
||||
if (color.b * color.a == 1) { // (1*1 == 1: true)
|
||||
if (color.b * color.a == one) { // (1*1 == 1: true)
|
||||
color = color.rbga; // (color = 0101)
|
||||
} else {
|
||||
color = color.aaaa;
|
||||
|
@ -1,11 +1,11 @@
|
||||
half4 main() {
|
||||
half4 green = half4(0, 1, 0, 1);
|
||||
half4 red = half4(1, 0, 0, 1);
|
||||
bool t = true;
|
||||
bool f = false;
|
||||
layout(ctype=SkPMColor4f) in uniform half4 colorGreen, colorRed;
|
||||
|
||||
return half4(t ? green.r : red.r, // true -> green.r
|
||||
f ? red.g : green.g, // false -> green.g
|
||||
(green.g == red.r) ? green.b : red.r, // true -> green.b
|
||||
(green.a != red.a) ? red.g : green.a); // false -> green.a
|
||||
half4 main() {
|
||||
bool t = true;
|
||||
bool f = false;
|
||||
|
||||
return half4(t ? colorGreen.r : colorRed.r, // true -> colorGreen.r
|
||||
f ? colorRed.g : colorGreen.g, // false -> colorGreen.g
|
||||
(colorGreen.g == colorRed.r) ? colorGreen.b : colorRed.r, // true -> colorGreen.b
|
||||
(colorGreen.a != colorRed.a) ? colorRed.g : colorGreen.a); // false -> colorGreen.a
|
||||
}
|
||||
|
@ -117,9 +117,9 @@ static bool is_uniform_in(const Variable& var) {
|
||||
}
|
||||
|
||||
String DSLCPPCodeGenerator::formatRuntimeValue(const Type& type,
|
||||
const Layout& layout,
|
||||
const String& cppCode,
|
||||
std::vector<String>* formatArgs) {
|
||||
const Layout& layout,
|
||||
const String& cppCode,
|
||||
std::vector<String>* formatArgs) {
|
||||
if (type.isArray()) {
|
||||
String result("[");
|
||||
const char* separator = "";
|
||||
@ -141,8 +141,8 @@ String DSLCPPCodeGenerator::formatRuntimeValue(const Type& type,
|
||||
return "%d";
|
||||
}
|
||||
if (type == *fContext.fTypes.fBool) {
|
||||
formatArgs->push_back("(" + cppCode + " ? \"true\" : \"false\")");
|
||||
return "%s";
|
||||
formatArgs->push_back("!!(" + cppCode + ")");
|
||||
return "%d";
|
||||
}
|
||||
if (type == *fContext.fTypes.fFloat2 || type == *fContext.fTypes.fHalf2) {
|
||||
formatArgs->push_back(cppCode + ".fX");
|
||||
@ -293,11 +293,6 @@ void DSLCPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
|
||||
fAccessSampleCoordsDirectly = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (var.modifiers().fFlags & Modifiers::kUniform_Flag) {
|
||||
SK_ABORT("not yet implemented: reference to uniform");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this->write(var.name());
|
||||
@ -332,59 +327,6 @@ void DSLCPPCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
||||
SK_ABORT("not yet implemented: helper function support for DSL");
|
||||
}
|
||||
|
||||
static const char* glsltype_string(const Context& context, const Type& type) {
|
||||
// If a new GrSL type is added, this function will need to be updated.
|
||||
static_assert(kGrSLTypeCount == 49);
|
||||
|
||||
if (type == *context.fTypes.fVoid ) { return "kVoid_GrSLType"; }
|
||||
if (type == *context.fTypes.fBool ) { return "kBool_GrSLType"; }
|
||||
if (type == *context.fTypes.fBool2 ) { return "kBool2_GrSLType"; }
|
||||
if (type == *context.fTypes.fBool3 ) { return "kBool3_GrSLType"; }
|
||||
if (type == *context.fTypes.fBool4 ) { return "kBool4_GrSLType"; }
|
||||
if (type == *context.fTypes.fByte ) { return "kByte_GrSLType"; }
|
||||
if (type == *context.fTypes.fByte2 ) { return "kByte2_GrSLType"; }
|
||||
if (type == *context.fTypes.fByte3 ) { return "kByte3_GrSLType"; }
|
||||
if (type == *context.fTypes.fByte4 ) { return "kByte4_GrSLType"; }
|
||||
if (type == *context.fTypes.fUByte ) { return "kUByte_GrSLType"; }
|
||||
if (type == *context.fTypes.fUByte2 ) { return "kUByte2_GrSLType"; }
|
||||
if (type == *context.fTypes.fUByte3 ) { return "kUByte3_GrSLType"; }
|
||||
if (type == *context.fTypes.fUByte4 ) { return "kUByte4_GrSLType"; }
|
||||
if (type == *context.fTypes.fShort ) { return "kShort_GrSLType"; }
|
||||
if (type == *context.fTypes.fShort2 ) { return "kShort2_GrSLType"; }
|
||||
if (type == *context.fTypes.fShort3 ) { return "kShort3_GrSLType"; }
|
||||
if (type == *context.fTypes.fShort4 ) { return "kShort4_GrSLType"; }
|
||||
if (type == *context.fTypes.fUShort ) { return "kUShort_GrSLType"; }
|
||||
if (type == *context.fTypes.fUShort2 ) { return "kUShort2_GrSLType"; }
|
||||
if (type == *context.fTypes.fUShort3 ) { return "kUShort3_GrSLType"; }
|
||||
if (type == *context.fTypes.fUShort4 ) { return "kUShort4_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat ) { return "kFloat_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat2 ) { return "kFloat2_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat3 ) { return "kFloat3_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat4 ) { return "kFloat4_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat2x2) { return "kFloat2x2_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat3x3) { return "kFloat3x3_GrSLType"; }
|
||||
if (type == *context.fTypes.fFloat4x4) { return "kFloat4x4_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf ) { return "kHalf_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf2 ) { return "kHalf2_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf3 ) { return "kHalf3_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf4 ) { return "kHalf4_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf2x2 ) { return "kHalf2x2_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf3x3 ) { return "kHalf3x3_GrSLType"; }
|
||||
if (type == *context.fTypes.fHalf4x4 ) { return "kHalf4x4_GrSLType"; }
|
||||
if (type == *context.fTypes.fInt ) { return "kInt_GrSLType"; }
|
||||
if (type == *context.fTypes.fInt2 ) { return "kInt2_GrSLType"; }
|
||||
if (type == *context.fTypes.fInt3 ) { return "kInt3_GrSLType"; }
|
||||
if (type == *context.fTypes.fInt4 ) { return "kInt4_GrSLType"; }
|
||||
if (type == *context.fTypes.fUInt ) { return "kUint_GrSLType"; }
|
||||
if (type == *context.fTypes.fUInt2 ) { return "kUint2_GrSLType"; }
|
||||
if (type == *context.fTypes.fUInt3 ) { return "kUint3_GrSLType"; }
|
||||
if (type == *context.fTypes.fUInt4 ) { return "kUint4_GrSLType"; }
|
||||
if (type.isEnum()) { return "kInt_GrSLType"; }
|
||||
|
||||
SkDEBUGFAILF("unsupported type: %s", type.description().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DSLCPPCodeGenerator::prepareHelperFunction(const FunctionDeclaration& decl) {
|
||||
if (decl.isBuiltin() || decl.isMain()) {
|
||||
return;
|
||||
@ -653,18 +595,19 @@ String DSLCPPCodeGenerator::getDSLType(const Type& type) {
|
||||
String DSLCPPCodeGenerator::getDSLModifiers(const Modifiers& modifiers) {
|
||||
String text;
|
||||
|
||||
// Uniform variables can have `in uniform` flags in FP file; that's not how they are
|
||||
// represented in DSL, however. Transform `in uniform` modifiers to just `uniform`.
|
||||
if (modifiers.fFlags & Modifiers::kUniform_Flag) {
|
||||
text += "kUniform_Modifier | ";
|
||||
} else if (modifiers.fFlags & Modifiers::kIn_Flag) {
|
||||
text += "kIn_Modifier | ";
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kConst_Flag) {
|
||||
text += "kConst_Modifier | ";
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kIn_Flag) {
|
||||
text += "kIn_Modifier | ";
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kOut_Flag) {
|
||||
text += "kOut_Modifier | ";
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kUniform_Flag) {
|
||||
text += "kUniform_Modifier | ";
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kFlat_Flag) {
|
||||
text += "kFlat_Modifier | ";
|
||||
}
|
||||
@ -772,21 +715,12 @@ void DSLCPPCodeGenerator::addUniform(const Variable& var) {
|
||||
if (var.modifiers().fLayout.fWhen.fLength) {
|
||||
this->writef(" if (%s) {\n ", String(var.modifiers().fLayout.fWhen).c_str());
|
||||
}
|
||||
String name(var.name());
|
||||
if (!var.type().isArray()) {
|
||||
this->writef(" %sVar = args.fUniformHandler->addUniform(&_outer, "
|
||||
"kFragment_GrShaderFlag, %s, \"%s\");\n",
|
||||
HCodeGenerator::FieldName(name.c_str()).c_str(),
|
||||
glsltype_string(fContext, var.type()),
|
||||
name.c_str());
|
||||
} else {
|
||||
this->writef(" %sVar = args.fUniformHandler->addUniformArray(&_outer, "
|
||||
"kFragment_GrShaderFlag, %s, \"%s\", %d);\n",
|
||||
HCodeGenerator::FieldName(name.c_str()).c_str(),
|
||||
glsltype_string(fContext, var.type().componentType()),
|
||||
name.c_str(),
|
||||
var.type().columns());
|
||||
}
|
||||
this->writeVar(var);
|
||||
|
||||
String varName = var.name();
|
||||
this->writef("%sVar = VarUniformHandle(%s);\n",
|
||||
HCodeGenerator::FieldName(varName.c_str()).c_str(), varName.c_str());
|
||||
|
||||
if (var.modifiers().fLayout.fWhen.fLength) {
|
||||
this->write(" }\n");
|
||||
}
|
||||
@ -849,6 +783,13 @@ void DSLCPPCodeGenerator::writePrivateVarValues() {
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_accessible(const Variable& var) {
|
||||
const Type& type = var.type();
|
||||
return !type.isFragmentProcessor() &&
|
||||
Type::TypeKind::kSampler != type.typeKind() &&
|
||||
Type::TypeKind::kOther != type.typeKind();
|
||||
}
|
||||
|
||||
bool DSLCPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
|
||||
this->writef(" void emitCode(EmitArgs& args) override {\n"
|
||||
" const %s& _outer = args.fFp.cast<%s>();\n"
|
||||
@ -857,6 +798,38 @@ bool DSLCPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms)
|
||||
" using namespace SkSL::dsl;\n"
|
||||
" StartFragmentProcessor(this, &args);\n",
|
||||
fFullName.c_str(), fFullName.c_str());
|
||||
for (const ProgramElement* p : fProgram.elements()) {
|
||||
if (p->is<GlobalVarDeclaration>()) {
|
||||
const GlobalVarDeclaration& global = p->as<GlobalVarDeclaration>();
|
||||
const VarDeclaration& decl = global.declaration()->as<VarDeclaration>();
|
||||
const Variable& var = decl.var();
|
||||
if (var.modifiers().fFlags & Modifiers::kUniform_Flag) {
|
||||
continue;
|
||||
}
|
||||
String nameString(var.name());
|
||||
const char* name = nameString.c_str();
|
||||
if (SectionAndParameterHelper::IsParameter(var) && is_accessible(var)) {
|
||||
// `formatRuntimeValue` generates a C++ format string (which we don't need, since
|
||||
// we're not formatting anything at runtime) and a vector of the arguments within
|
||||
// the variable (which we do need, to fill in the Var's initial value).
|
||||
std::vector<String> argumentList;
|
||||
(void) this->formatRuntimeValue(var.type(), var.modifiers().fLayout,
|
||||
"_outer." + var.name(), &argumentList);
|
||||
this->writef("Var %s(kConst_Modifier, %s, \"%s\", %s(",
|
||||
name, this->getDSLType(var.type()).c_str(), name,
|
||||
this->getTypeName(var.type()).c_str());
|
||||
const char* separator = "";
|
||||
for (const String& arg : argumentList) {
|
||||
this->write(separator);
|
||||
this->write(arg);
|
||||
separator = ", ";
|
||||
}
|
||||
this->writef("));\n"
|
||||
"Declare(%s);\n", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->writePrivateVarValues();
|
||||
for (const Variable* u : uniforms) {
|
||||
this->addUniform(*u);
|
||||
|
@ -28,8 +28,11 @@
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
|
||||
template <typename FPClass>
|
||||
static void test_dsl_fp(skiatest::Reporter* r, GrDirectContext* ctx, bool worksInES2) {
|
||||
template <typename FPClass, typename... Uniforms>
|
||||
static void test_dsl_fp(skiatest::Reporter* r,
|
||||
GrDirectContext* ctx,
|
||||
bool worksInES2,
|
||||
Uniforms&&... uniforms) {
|
||||
if (!worksInES2) {
|
||||
// We don't have an ES2 caps bit, so we check for integer support and derivatives support.
|
||||
// Our ES2 bots should return false for these.
|
||||
@ -46,7 +49,8 @@ static void test_dsl_fp(skiatest::Reporter* r, GrDirectContext* ctx, bool worksI
|
||||
/*dimensions=*/{1, 1},
|
||||
SkSurfaceProps{});
|
||||
|
||||
rtCtx->fillRectWithFP(SkIRect::MakeWH(1, 1), FPClass::Make());
|
||||
rtCtx->fillRectWithFP(SkIRect::MakeWH(1, 1),
|
||||
FPClass::Make(std::forward<Uniforms>(uniforms)...));
|
||||
|
||||
SkImageInfo dstInfo = SkImageInfo::Make(/*width=*/1, /*height=*/1, kRGBA_8888_SkColorType,
|
||||
kPremul_SkAlphaType, /*cs=*/nullptr);
|
||||
@ -60,20 +64,23 @@ static void test_dsl_fp(skiatest::Reporter* r, GrDirectContext* ctx, bool worksI
|
||||
GrColorUnpackG(*color), GrColorUnpackB(*color));
|
||||
}
|
||||
|
||||
#define DSL_FP_TEST_ES2(FPClass) \
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
|
||||
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/true); \
|
||||
#define DSL_FP_TEST_ES2(FPClass, ...) \
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
|
||||
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/true, \
|
||||
##__VA_ARGS__); \
|
||||
}
|
||||
#define DSL_FP_TEST(FPClass) \
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
|
||||
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/false); \
|
||||
#define DSL_FP_TEST(FPClass, ...) \
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
|
||||
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/false, \
|
||||
##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
DSL_FP_TEST_ES2(DSLFPTest_IfStatement)
|
||||
DSL_FP_TEST_ES2(DSLFPTest_IfStatement, /*one:*/ 1.0f)
|
||||
DSL_FP_TEST_ES2(DSLFPTest_Swizzle)
|
||||
DSL_FP_TEST_ES2(DSLFPTest_Ternary)
|
||||
DSL_FP_TEST(DSLFPTest_DoStatement)
|
||||
DSL_FP_TEST(DSLFPTest_ForStatement)
|
||||
DSL_FP_TEST_ES2(DSLFPTest_Ternary, /*colorGreen:*/ SkPMColor4f{0, 1, 0, 1},
|
||||
/*colorRed:*/ SkPMColor4f{1, 0, 0, 1})
|
||||
DSL_FP_TEST(DSLFPTest_DoStatement, /*shouldLoop:*/ false)
|
||||
DSL_FP_TEST(DSLFPTest_ForStatement, /*colorWhite:*/ SkPMColor4f{1, 1, 1, 1})
|
||||
DSL_FP_TEST(DSLFPTest_SwitchStatement)
|
||||
DSL_FP_TEST(DSLFPTest_WhileStatement)
|
||||
|
||||
|
@ -29,9 +29,11 @@ public:
|
||||
|
||||
using namespace SkSL::dsl;
|
||||
StartFragmentProcessor(this, &args);
|
||||
Var shouldLoop(kConst_Modifier, DSLType(kBool_Type), "shouldLoop", Bool(!!(_outer.shouldLoop)));
|
||||
Declare(shouldLoop);
|
||||
Var color(kNo_Modifier, DSLType(kHalf4_Type), "color", Half4(1.0, 1.0, 1.0, 1.0));
|
||||
Declare(color);
|
||||
Do(color.x() -= 0.25, /*While:*/ color.x() > 0.5);
|
||||
Do(color.x() -= 0.25, /*While:*/ shouldLoop);
|
||||
Do(Block(color.x() -= 0.25, If(color.x() <= 0.0, /*Then:*/ Break())), /*While:*/ color.w() == 1.0);
|
||||
Do(Block(color.z() -= 0.25, If(color.w() == 1.0, /*Then:*/ Continue()), color.y() = 0.0), /*While:*/ color.z() > 0.0);
|
||||
Return(color);
|
||||
@ -45,14 +47,17 @@ std::unique_ptr<GrGLSLFragmentProcessor> GrDSLFPTest_DoStatement::onMakeProgramI
|
||||
return std::make_unique<GrGLSLDSLFPTest_DoStatement>();
|
||||
}
|
||||
void GrDSLFPTest_DoStatement::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
||||
b->addBool(shouldLoop, "shouldLoop");
|
||||
}
|
||||
bool GrDSLFPTest_DoStatement::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrDSLFPTest_DoStatement& that = other.cast<GrDSLFPTest_DoStatement>();
|
||||
(void) that;
|
||||
if (shouldLoop != that.shouldLoop) return false;
|
||||
return true;
|
||||
}
|
||||
GrDSLFPTest_DoStatement::GrDSLFPTest_DoStatement(const GrDSLFPTest_DoStatement& src)
|
||||
: INHERITED(kGrDSLFPTest_DoStatement_ClassID, src.optimizationFlags()) {
|
||||
: INHERITED(kGrDSLFPTest_DoStatement_ClassID, src.optimizationFlags())
|
||||
, shouldLoop(src.shouldLoop) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_DoStatement::clone() const {
|
||||
@ -60,6 +65,6 @@ std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_DoStatement::clone() const {
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrDSLFPTest_DoStatement::onDumpInfo() const {
|
||||
return SkString();
|
||||
return SkStringPrintf("(shouldLoop=%d)", !!(shouldLoop));
|
||||
}
|
||||
#endif
|
||||
|
@ -14,15 +14,17 @@
|
||||
|
||||
class GrDSLFPTest_DoStatement : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make() {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_DoStatement());
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(bool shouldLoop) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_DoStatement(shouldLoop));
|
||||
}
|
||||
GrDSLFPTest_DoStatement(const GrDSLFPTest_DoStatement& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "DSLFPTest_DoStatement"; }
|
||||
bool shouldLoop;
|
||||
private:
|
||||
GrDSLFPTest_DoStatement()
|
||||
: INHERITED(kGrDSLFPTest_DoStatement_ClassID, kNone_OptimizationFlags) {
|
||||
GrDSLFPTest_DoStatement(bool shouldLoop)
|
||||
: INHERITED(kGrDSLFPTest_DoStatement_ClassID, kNone_OptimizationFlags)
|
||||
, shouldLoop(shouldLoop) {
|
||||
}
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -29,7 +29,9 @@ public:
|
||||
|
||||
using namespace SkSL::dsl;
|
||||
StartFragmentProcessor(this, &args);
|
||||
Var color(kNo_Modifier, DSLType(kHalf4_Type), "color", Half4(1.0));
|
||||
Var colorWhite(kConst_Modifier, DSLType(kHalf4_Type), "colorWhite", Half4(_outer.colorWhite.fR, _outer.colorWhite.fG, _outer.colorWhite.fB, _outer.colorWhite.fA));
|
||||
Declare(colorWhite);
|
||||
Var color(kNo_Modifier, DSLType(kHalf4_Type), "color", colorWhite);
|
||||
Var a(kNo_Modifier, DSLType(kHalf_Type), "a", 0.0);
|
||||
Var r(kNo_Modifier, DSLType(kHalf_Type), "r", -5.0);
|
||||
Var b(kNo_Modifier, DSLType(kHalf_Type), "b", 5.0);
|
||||
@ -48,14 +50,22 @@ std::unique_ptr<GrGLSLFragmentProcessor> GrDSLFPTest_ForStatement::onMakeProgram
|
||||
return std::make_unique<GrGLSLDSLFPTest_ForStatement>();
|
||||
}
|
||||
void GrDSLFPTest_ForStatement::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
||||
uint16_t red = SkFloatToHalf(colorWhite.fR);
|
||||
uint16_t green = SkFloatToHalf(colorWhite.fG);
|
||||
uint16_t blue = SkFloatToHalf(colorWhite.fB);
|
||||
uint16_t alpha = SkFloatToHalf(colorWhite.fA);
|
||||
b->add32(((uint32_t)red << 16) | green, "colorWhite.rg");
|
||||
b->add32(((uint32_t)blue << 16) | alpha, "colorWhite.ba");
|
||||
}
|
||||
bool GrDSLFPTest_ForStatement::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrDSLFPTest_ForStatement& that = other.cast<GrDSLFPTest_ForStatement>();
|
||||
(void) that;
|
||||
if (colorWhite != that.colorWhite) return false;
|
||||
return true;
|
||||
}
|
||||
GrDSLFPTest_ForStatement::GrDSLFPTest_ForStatement(const GrDSLFPTest_ForStatement& src)
|
||||
: INHERITED(kGrDSLFPTest_ForStatement_ClassID, src.optimizationFlags()) {
|
||||
: INHERITED(kGrDSLFPTest_ForStatement_ClassID, src.optimizationFlags())
|
||||
, colorWhite(src.colorWhite) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_ForStatement::clone() const {
|
||||
@ -63,6 +73,6 @@ std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_ForStatement::clone() const {
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrDSLFPTest_ForStatement::onDumpInfo() const {
|
||||
return SkString();
|
||||
return SkStringPrintf("(colorWhite=half4(%f, %f, %f, %f))", colorWhite.fR, colorWhite.fG, colorWhite.fB, colorWhite.fA);
|
||||
}
|
||||
#endif
|
||||
|
@ -14,15 +14,17 @@
|
||||
|
||||
class GrDSLFPTest_ForStatement : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make() {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_ForStatement());
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f colorWhite) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_ForStatement(colorWhite));
|
||||
}
|
||||
GrDSLFPTest_ForStatement(const GrDSLFPTest_ForStatement& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "DSLFPTest_ForStatement"; }
|
||||
SkPMColor4f colorWhite;
|
||||
private:
|
||||
GrDSLFPTest_ForStatement()
|
||||
: INHERITED(kGrDSLFPTest_ForStatement_ClassID, kNone_OptimizationFlags) {
|
||||
GrDSLFPTest_ForStatement(SkPMColor4f colorWhite)
|
||||
: INHERITED(kGrDSLFPTest_ForStatement_ClassID, kNone_OptimizationFlags)
|
||||
, colorWhite(colorWhite) {
|
||||
}
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -29,13 +29,15 @@ public:
|
||||
|
||||
using namespace SkSL::dsl;
|
||||
StartFragmentProcessor(this, &args);
|
||||
Var one(kConst_Modifier, DSLType(kHalf_Type), "one", Half(_outer.one));
|
||||
Declare(one);
|
||||
Var color(kNo_Modifier, DSLType(kHalf4_Type), "color", Half4(0.0));
|
||||
Declare(color);
|
||||
If(Swizzle(color, X, Y) == Swizzle(color, Z, W), /*Then:*/ color.w() = 1.0);
|
||||
If(Swizzle(color, X, Y) == Swizzle(color, Z, W), /*Then:*/ color.w() = one);
|
||||
If(Swizzle(color, X, Y) == Swizzle(color, Z, W), /*Then:*/ Block(color.x() = color.w()));
|
||||
If(color.x() == color.y(), /*Then:*/ color = Swizzle(color, W, X, W, W), /*Else:*/ color = Swizzle(color, X, X, X, W));
|
||||
If(((color.x() + color.y()) + color.z()) + color.w() == 1.0, /*Then:*/ Block(color = Half4(-1.0)), /*Else:*/ If(((color.x() + color.y()) + color.z()) + color.w() == 2.0, /*Then:*/ Block(color = Half4(-2.0)), /*Else:*/ Block(color = Swizzle(color, Y, Y, W, W))));
|
||||
If(color.x() == 1.0, /*Then:*/ Block(If(color.x() == 2.0, /*Then:*/ Block(color = Swizzle(color, X, X, X, X)), /*Else:*/ Block(color = Swizzle(color, Y, Y, Y, Y)))), /*Else:*/ Block(If(color.z() * color.w() == 1.0, /*Then:*/ Block(color = Swizzle(color, X, Z, Y, W)), /*Else:*/ Block(color = Swizzle(color, W, W, W, W)))));
|
||||
If(((color.x() + color.y()) + color.z()) + color.w() == one, /*Then:*/ Block(color = Half4(-1.0)), /*Else:*/ If(((color.x() + color.y()) + color.z()) + color.w() == 2.0, /*Then:*/ Block(color = Half4(-2.0)), /*Else:*/ Block(color = Swizzle(color, Y, Y, W, W))));
|
||||
If(color.x() == one, /*Then:*/ Block(If(color.x() == 2.0, /*Then:*/ Block(color = Swizzle(color, X, X, X, X)), /*Else:*/ Block(color = Swizzle(color, Y, Y, Y, Y)))), /*Else:*/ Block(If(color.z() * color.w() == one, /*Then:*/ Block(color = Swizzle(color, X, Z, Y, W)), /*Else:*/ Block(color = Swizzle(color, W, W, W, W)))));
|
||||
Return(color);
|
||||
EndFragmentProcessor();
|
||||
}
|
||||
@ -47,14 +49,17 @@ std::unique_ptr<GrGLSLFragmentProcessor> GrDSLFPTest_IfStatement::onMakeProgramI
|
||||
return std::make_unique<GrGLSLDSLFPTest_IfStatement>();
|
||||
}
|
||||
void GrDSLFPTest_IfStatement::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
||||
b->add32(sk_bit_cast<uint32_t>(one), "one");
|
||||
}
|
||||
bool GrDSLFPTest_IfStatement::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrDSLFPTest_IfStatement& that = other.cast<GrDSLFPTest_IfStatement>();
|
||||
(void) that;
|
||||
if (one != that.one) return false;
|
||||
return true;
|
||||
}
|
||||
GrDSLFPTest_IfStatement::GrDSLFPTest_IfStatement(const GrDSLFPTest_IfStatement& src)
|
||||
: INHERITED(kGrDSLFPTest_IfStatement_ClassID, src.optimizationFlags()) {
|
||||
: INHERITED(kGrDSLFPTest_IfStatement_ClassID, src.optimizationFlags())
|
||||
, one(src.one) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_IfStatement::clone() const {
|
||||
@ -62,6 +67,6 @@ std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_IfStatement::clone() const {
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrDSLFPTest_IfStatement::onDumpInfo() const {
|
||||
return SkString();
|
||||
return SkStringPrintf("(one=%f)", one);
|
||||
}
|
||||
#endif
|
||||
|
@ -14,15 +14,17 @@
|
||||
|
||||
class GrDSLFPTest_IfStatement : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make() {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_IfStatement());
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(float one) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_IfStatement(one));
|
||||
}
|
||||
GrDSLFPTest_IfStatement(const GrDSLFPTest_IfStatement& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "DSLFPTest_IfStatement"; }
|
||||
float one;
|
||||
private:
|
||||
GrDSLFPTest_IfStatement()
|
||||
: INHERITED(kGrDSLFPTest_IfStatement_ClassID, kNone_OptimizationFlags) {
|
||||
GrDSLFPTest_IfStatement(float one)
|
||||
: INHERITED(kGrDSLFPTest_IfStatement_ClassID, kNone_OptimizationFlags)
|
||||
, one(one) {
|
||||
}
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -29,20 +29,27 @@ public:
|
||||
|
||||
using namespace SkSL::dsl;
|
||||
StartFragmentProcessor(this, &args);
|
||||
Var green(kNo_Modifier, DSLType(kHalf4_Type), "green", Half4(0.0, 1.0, 0.0, 1.0));
|
||||
Var red(kNo_Modifier, DSLType(kHalf4_Type), "red", Half4(1.0, 0.0, 0.0, 1.0));
|
||||
Var colorGreen(kUniform_Modifier, DSLType(kHalf4_Type), "colorGreen");
|
||||
colorGreenVar = VarUniformHandle(colorGreen);
|
||||
Var colorRed(kUniform_Modifier, DSLType(kHalf4_Type), "colorRed");
|
||||
colorRedVar = VarUniformHandle(colorRed);
|
||||
Var t(kNo_Modifier, DSLType(kBool_Type), "t", true);
|
||||
Var f(kNo_Modifier, DSLType(kBool_Type), "f", false);
|
||||
Declare(green);
|
||||
Declare(red);
|
||||
Declare(t);
|
||||
Declare(f);
|
||||
Return(Half4(Select(t, /*If True:*/ green.x(), /*If False:*/ red.x()), Select(f, /*If True:*/ red.y(), /*If False:*/ green.y()), Select(green.y() == red.x(), /*If True:*/ green.z(), /*If False:*/ red.x()), Select(green.w() != red.w(), /*If True:*/ red.y(), /*If False:*/ green.w())));
|
||||
Return(Half4(Select(t, /*If True:*/ colorGreen.x(), /*If False:*/ colorRed.x()), Select(f, /*If True:*/ colorRed.y(), /*If False:*/ colorGreen.y()), Select(colorGreen.y() == colorRed.x(), /*If True:*/ colorGreen.z(), /*If False:*/ colorRed.x()), Select(colorGreen.w() != colorRed.w(), /*If True:*/ colorRed.y(), /*If False:*/ colorGreen.w())));
|
||||
EndFragmentProcessor();
|
||||
}
|
||||
private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
const GrDSLFPTest_Ternary& _outer = _proc.cast<GrDSLFPTest_Ternary>();
|
||||
{
|
||||
pdman.set4fv(colorGreenVar, 1, (_outer.colorGreen).vec());
|
||||
pdman.set4fv(colorRedVar, 1, (_outer.colorRed).vec());
|
||||
}
|
||||
}
|
||||
UniformHandle colorGreenVar;
|
||||
UniformHandle colorRedVar;
|
||||
};
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> GrDSLFPTest_Ternary::onMakeProgramImpl() const {
|
||||
return std::make_unique<GrGLSLDSLFPTest_Ternary>();
|
||||
@ -52,10 +59,14 @@ void GrDSLFPTest_Ternary::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProc
|
||||
bool GrDSLFPTest_Ternary::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrDSLFPTest_Ternary& that = other.cast<GrDSLFPTest_Ternary>();
|
||||
(void) that;
|
||||
if (colorGreen != that.colorGreen) return false;
|
||||
if (colorRed != that.colorRed) return false;
|
||||
return true;
|
||||
}
|
||||
GrDSLFPTest_Ternary::GrDSLFPTest_Ternary(const GrDSLFPTest_Ternary& src)
|
||||
: INHERITED(kGrDSLFPTest_Ternary_ClassID, src.optimizationFlags()) {
|
||||
: INHERITED(kGrDSLFPTest_Ternary_ClassID, src.optimizationFlags())
|
||||
, colorGreen(src.colorGreen)
|
||||
, colorRed(src.colorRed) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_Ternary::clone() const {
|
||||
@ -63,6 +74,6 @@ std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_Ternary::clone() const {
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrDSLFPTest_Ternary::onDumpInfo() const {
|
||||
return SkString();
|
||||
return SkStringPrintf("(colorGreen=half4(%f, %f, %f, %f), colorRed=half4(%f, %f, %f, %f))", colorGreen.fR, colorGreen.fG, colorGreen.fB, colorGreen.fA, colorRed.fR, colorRed.fG, colorRed.fB, colorRed.fA);
|
||||
}
|
||||
#endif
|
||||
|
@ -14,15 +14,19 @@
|
||||
|
||||
class GrDSLFPTest_Ternary : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make() {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_Ternary());
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f colorGreen, SkPMColor4f colorRed) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrDSLFPTest_Ternary(colorGreen, colorRed));
|
||||
}
|
||||
GrDSLFPTest_Ternary(const GrDSLFPTest_Ternary& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "DSLFPTest_Ternary"; }
|
||||
SkPMColor4f colorGreen;
|
||||
SkPMColor4f colorRed;
|
||||
private:
|
||||
GrDSLFPTest_Ternary()
|
||||
: INHERITED(kGrDSLFPTest_Ternary_ClassID, kNone_OptimizationFlags) {
|
||||
GrDSLFPTest_Ternary(SkPMColor4f colorGreen, SkPMColor4f colorRed)
|
||||
: INHERITED(kGrDSLFPTest_Ternary_ClassID, kNone_OptimizationFlags)
|
||||
, colorGreen(colorGreen)
|
||||
, colorRed(colorRed) {
|
||||
}
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user