diff options
author | Brian Salomon <bsalomon@google.com> | 2017-08-17 11:07:59 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-17 15:08:17 +0000 |
commit | 1d816b92bb7cf2258007f3f74ffd143b89f25d01 (patch) | |
tree | 07fb1e8e2631208eb007a4abdfe130db91e6cfc2 /src/sksl/SkSLCPPCodeGenerator.cpp | |
parent | 23f92277b916a4bdf11c320799ac9248af60a62e (diff) |
Revert "Switched highp float to highfloat and mediump float to half."
This reverts commit 88d99c63878c2d3d340120f0321676f72afcb4f0.
Reason for revert: Believed to be causing unit test failures in Chrome roll:
https://build.chromium.org/p/tryserver.chromium.android/builders/linux_android_rel_ng/builds/364433
https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Ftryserver.chromium.android%2Flinux_android_rel_ng%2F364433%2F%2B%2Frecipes%2Fsteps%2Fcontent_browsertests__with_patch__on_Android%2F0%2Flogs%2FWebRtcCaptureFromElementBrowserTest.VerifyCanvasWebGLCaptureColor%2F0
Original change's description:
> Switched highp float to highfloat and mediump float to half.
>
> The ultimate goal is to end up with "float" and "half", but this
> intermediate step uses "highfloat" so that it is clear if I missed a
> "float" somewhere. Once this lands, a subsequent CL will switch all
> "highfloats" back to "floats".
>
> Bug: skia:
> Change-Id: Ia13225c7a0a0a2901e07665891c473d2500ddcca
> Reviewed-on: https://skia-review.googlesource.com/31000
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,ethannicholas@google.com
Change-Id: I8bfa97547ac3920d433665f161d27df3f15c83aa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/35705
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.cpp | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp index eda251212d..17bcf0d11f 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -51,14 +51,16 @@ void CPPCodeGenerator::writef(const char* s, ...) { void CPPCodeGenerator::writeHeader() { } -bool CPPCodeGenerator::usesPrecisionModifiers() const { - return false; +void CPPCodeGenerator::writePrecisionModifier() { } -String CPPCodeGenerator::getTypeName(const Type& type) { - return type.name(); +void CPPCodeGenerator::writeType(const Type& type) { + if (type.kind() == Type::kStruct_Kind) { + INHERITED::writeType(type); + } else { + this->write(type.name()); + } } - void CPPCodeGenerator::writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence) { if (b.fOperator == Token::PERCENT) { @@ -115,13 +117,20 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) { INHERITED::writeIndexExpression(i); } -static String default_value(const Type& type) { - switch (type.kind()) { - case Type::kScalar_Kind: return "0"; - case Type::kVector_Kind: return type.fName + "(0)"; - case Type::kMatrix_Kind: return type.fName + "(1)"; - default: ABORT("unsupported default_value type\n"); +static const char* default_value(const Type& type) { + const char* name = type.name().c_str(); + if (!strcmp(name, "float")) { + return "0.0"; + } else if (!strcmp(name, "float2")) { + return "float2(0.0)"; + } else if (!strcmp(name, "float3")) { + return "float30.0)"; + } else if (!strcmp(name, "float4")) { + return "float4(0.0)"; + } else if (!strcmp(name, "floatt4x4") || !strcmp(name, "colorSpaceXform")) { + return "float4x4(1.0)"; } + ABORT("unsupported default_value type\n"); } static bool is_private(const Variable& var) { @@ -132,7 +141,7 @@ static bool is_private(const Variable& var) { } void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode) { - if (type.isFloat()) { + if (type == *fContext.fFloat_Type) { this->write("%f"); fFormatArgs.push_back(cppCode); } else if (type == *fContext.fInt_Type) { @@ -141,8 +150,8 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode } else if (type == *fContext.fBool_Type) { this->write("%s"); fFormatArgs.push_back("(" + cppCode + " ? \"true\" : \"false\")"); - } else if (type == *fContext.fFloat2_Type || type == *fContext.fHalf2_Type) { - this->write(type.fName + "(%f, %f)"); + } else if (type == *fContext.fFloat2_Type) { + this->write("float2(%f, %f)"); fFormatArgs.push_back(cppCode + ".fX"); fFormatArgs.push_back(cppCode + ".fY"); } else { @@ -180,7 +189,7 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { switch (ref.fVariable.fModifiers.fLayout.fBuiltin) { case SK_INCOLOR_BUILTIN: this->write("%s"); - fFormatArgs.push_back(String("args.fInputColor ? args.fInputColor : \"half4(1)\"")); + fFormatArgs.push_back(String("args.fInputColor ? args.fInputColor : \"float4(1)\"")); break; case SK_OUTCOLOR_BUILTIN: this->write("%s"); @@ -202,7 +211,7 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { var = String::printf("fColorSpaceHelper.isValid() ? " "args.fUniformHandler->getUniformCStr(" "fColorSpaceHelper.gamutXformUniform()) : \"%s\"", - default_value(ref.fVariable.fType).c_str()); + default_value(ref.fVariable.fType)); } else { var = String::printf("args.fUniformHandler->getUniformCStr(%sVar)", HCodeGenerator::FieldName(name.c_str()).c_str()); @@ -212,7 +221,7 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { code = String::printf("%sVar.isValid() ? %s : \"%s\"", HCodeGenerator::FieldName(name.c_str()).c_str(), var.c_str(), - default_value(ref.fVariable.fType).c_str()); + default_value(ref.fVariable.fType)); } else { code = var; } @@ -244,7 +253,7 @@ void CPPCodeGenerator::writeSwitchStatement(const SwitchStatement& s) { void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) { if (c.fFunction.fBuiltin && c.fFunction.fName == "COLORSPACE") { String tmpVar = "_tmpVar" + to_string(++fVarCount); - fFunctionHeader += "half4 " + tmpVar + ";"; + fFunctionHeader += "float4 " + tmpVar + ";"; ASSERT(c.fArguments.size() == 2); this->write("%s"); fFormatArgs.push_back("fColorSpaceHelper.isValid() ? \"(" + tmpVar + " = \" : \"\""); @@ -253,7 +262,7 @@ void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) { String xform("args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform())"); this->write("%s"); fFormatArgs.push_back("fColorSpaceHelper.isValid() ? SkStringPrintf(\", " - "half4(clamp((%s * half4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + + "float4(clamp((%s * float4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + tmpVar + ".a), " + tmpVar + ".a))\", " + xform + ").c_str() : \"\""); return; } @@ -340,22 +349,14 @@ void CPPCodeGenerator::addUniform(const Variable& var) { } const char* type; if (var.fType == *fContext.fFloat_Type) { - type = "kHighFloat_GrSLType"; - } else if (var.fType == *fContext.fHalf_Type) { - type = "kHalf_GrSLType"; + type = "kFloat_GrSLType"; } else if (var.fType == *fContext.fFloat2_Type) { - type = "kHighFloat2_GrSLType"; - } else if (var.fType == *fContext.fHalf2_Type) { - type = "kHalf2_GrSLType"; + type = "kVec2f_GrSLType"; } else if (var.fType == *fContext.fFloat4_Type) { - type = "kHighFloat4_GrSLType"; - } else if (var.fType == *fContext.fHalf4_Type) { - type = "kHalf4_GrSLType"; + type = "kVec4f_GrSLType"; } else if (var.fType == *fContext.fFloat4x4_Type || var.fType == *fContext.fColorSpaceXform_Type) { - type = "kHighFloat4x4_GrSLType"; - } else if (var.fType == *fContext.fHalf4x4_Type) { - type = "kHalf4x4_GrSLType"; + type = "kMat44f_GrSLType"; } else { ABORT("unsupported uniform type: %s %s;\n", var.fType.name().c_str(), var.fName.c_str()); } @@ -453,12 +454,11 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) { this->writef(" {\n"); } const char* name = u->fName.c_str(); - if (u->fType == *fContext.fFloat4_Type || u->fType == *fContext.fHalf4_Type) { + if (u->fType == *fContext.fFloat4_Type) { this->writef(" const SkRect %sValue = _outer.%s();\n" " %s.set4fv(%sVar, 1, (float*) &%sValue);\n", name, name, pdman, HCodeGenerator::FieldName(name).c_str(), name); - } else if (u->fType == *fContext.fFloat4x4_Type || - u->fType == *fContext.fHalf4x4_Type) { + } else if (u->fType == *fContext.fFloat4x4_Type) { this->writef(" float %sValue[16];\n" " _outer.%s().asColMajorf(%sValue);\n" " %s.setMatrix4f(%sVar, %sValue);\n", |