diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-08-16 16:41:30 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-16 23:05:15 +0000 |
commit | 88d99c63878c2d3d340120f0321676f72afcb4f0 (patch) | |
tree | 5b957dbf2f78ef7a15aa3810f8922c915508683f /src/sksl/SkSLCPPCodeGenerator.cpp | |
parent | a26d219a929f4e70f8597dfd57a53348c4bba905 (diff) |
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>
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 17bcf0d11f..eda251212d 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -51,16 +51,14 @@ void CPPCodeGenerator::writef(const char* s, ...) { void CPPCodeGenerator::writeHeader() { } -void CPPCodeGenerator::writePrecisionModifier() { +bool CPPCodeGenerator::usesPrecisionModifiers() const { + return false; } -void CPPCodeGenerator::writeType(const Type& type) { - if (type.kind() == Type::kStruct_Kind) { - INHERITED::writeType(type); - } else { - this->write(type.name()); - } +String CPPCodeGenerator::getTypeName(const Type& type) { + return type.name(); } + void CPPCodeGenerator::writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence) { if (b.fOperator == Token::PERCENT) { @@ -117,20 +115,13 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) { INHERITED::writeIndexExpression(i); } -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)"; +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"); } - ABORT("unsupported default_value type\n"); } static bool is_private(const Variable& var) { @@ -141,7 +132,7 @@ static bool is_private(const Variable& var) { } void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode) { - if (type == *fContext.fFloat_Type) { + if (type.isFloat()) { this->write("%f"); fFormatArgs.push_back(cppCode); } else if (type == *fContext.fInt_Type) { @@ -150,8 +141,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) { - this->write("float2(%f, %f)"); + } else if (type == *fContext.fFloat2_Type || type == *fContext.fHalf2_Type) { + this->write(type.fName + "(%f, %f)"); fFormatArgs.push_back(cppCode + ".fX"); fFormatArgs.push_back(cppCode + ".fY"); } else { @@ -189,7 +180,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 : \"float4(1)\"")); + fFormatArgs.push_back(String("args.fInputColor ? args.fInputColor : \"half4(1)\"")); break; case SK_OUTCOLOR_BUILTIN: this->write("%s"); @@ -211,7 +202,7 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { var = String::printf("fColorSpaceHelper.isValid() ? " "args.fUniformHandler->getUniformCStr(" "fColorSpaceHelper.gamutXformUniform()) : \"%s\"", - default_value(ref.fVariable.fType)); + default_value(ref.fVariable.fType).c_str()); } else { var = String::printf("args.fUniformHandler->getUniformCStr(%sVar)", HCodeGenerator::FieldName(name.c_str()).c_str()); @@ -221,7 +212,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)); + default_value(ref.fVariable.fType).c_str()); } else { code = var; } @@ -253,7 +244,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 += "float4 " + tmpVar + ";"; + fFunctionHeader += "half4 " + tmpVar + ";"; ASSERT(c.fArguments.size() == 2); this->write("%s"); fFormatArgs.push_back("fColorSpaceHelper.isValid() ? \"(" + tmpVar + " = \" : \"\""); @@ -262,7 +253,7 @@ void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) { String xform("args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform())"); this->write("%s"); fFormatArgs.push_back("fColorSpaceHelper.isValid() ? SkStringPrintf(\", " - "float4(clamp((%s * float4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + + "half4(clamp((%s * half4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + tmpVar + ".a), " + tmpVar + ".a))\", " + xform + ").c_str() : \"\""); return; } @@ -349,14 +340,22 @@ void CPPCodeGenerator::addUniform(const Variable& var) { } const char* type; if (var.fType == *fContext.fFloat_Type) { - type = "kFloat_GrSLType"; + type = "kHighFloat_GrSLType"; + } else if (var.fType == *fContext.fHalf_Type) { + type = "kHalf_GrSLType"; } else if (var.fType == *fContext.fFloat2_Type) { - type = "kVec2f_GrSLType"; + type = "kHighFloat2_GrSLType"; + } else if (var.fType == *fContext.fHalf2_Type) { + type = "kHalf2_GrSLType"; } else if (var.fType == *fContext.fFloat4_Type) { - type = "kVec4f_GrSLType"; + type = "kHighFloat4_GrSLType"; + } else if (var.fType == *fContext.fHalf4_Type) { + type = "kHalf4_GrSLType"; } else if (var.fType == *fContext.fFloat4x4_Type || var.fType == *fContext.fColorSpaceXform_Type) { - type = "kMat44f_GrSLType"; + type = "kHighFloat4x4_GrSLType"; + } else if (var.fType == *fContext.fHalf4x4_Type) { + type = "kHalf4x4_GrSLType"; } else { ABORT("unsupported uniform type: %s %s;\n", var.fType.name().c_str(), var.fName.c_str()); } @@ -454,11 +453,12 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) { this->writef(" {\n"); } const char* name = u->fName.c_str(); - if (u->fType == *fContext.fFloat4_Type) { + if (u->fType == *fContext.fFloat4_Type || u->fType == *fContext.fHalf4_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) { + } else if (u->fType == *fContext.fFloat4x4_Type || + u->fType == *fContext.fHalf4x4_Type) { this->writef(" float %sValue[16];\n" " _outer.%s().asColMajorf(%sValue);\n" " %s.setMatrix4f(%sVar, %sValue);\n", |