diff options
author | 2017-09-18 14:10:39 -0400 | |
---|---|---|
committer | 2017-09-18 18:32:13 +0000 | |
commit | f7b8820dc813d1eb0b6b43fe4581dded0da38caf (patch) | |
tree | 518d313a9fa571a9f9ca26af7c381664694a4706 /src/sksl/ir | |
parent | 47a540f503bc722393b61c4b822e95b17f200125 (diff) |
re-land of new SkSL precisions
Bug: skia:
Change-Id: Ic1deb3db2cbda6ca45f93dee99832971a36a2119
Reviewed-on: https://skia-review.googlesource.com/47841
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/ir')
-rw-r--r-- | src/sksl/ir/SkSLConstructor.h | 6 | ||||
-rw-r--r-- | src/sksl/ir/SkSLIRNode.h | 2 | ||||
-rw-r--r-- | src/sksl/ir/SkSLIndexExpression.h | 9 | ||||
-rw-r--r-- | src/sksl/ir/SkSLProgram.h | 6 | ||||
-rw-r--r-- | src/sksl/ir/SkSLSwizzle.h | 18 | ||||
-rw-r--r-- | src/sksl/ir/SkSLSymbol.h | 2 | ||||
-rw-r--r-- | src/sksl/ir/SkSLType.cpp | 54 | ||||
-rw-r--r-- | src/sksl/ir/SkSLType.h | 39 |
8 files changed, 113 insertions, 23 deletions
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h index 32fc0fb2e7..cea5265cea 100644 --- a/src/sksl/ir/SkSLConstructor.h +++ b/src/sksl/ir/SkSLConstructor.h @@ -32,13 +32,15 @@ struct Constructor : public Expression { std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, const DefinitionMap& definitions) override { if (fArguments.size() == 1 && fArguments[0]->fKind == Expression::kIntLiteral_Kind) { - if (fType == *irGenerator.fContext.fFloat_Type) { + if (fType == *irGenerator.fContext.fFloat_Type || + fType == *irGenerator.fContext.fHalf_Type) { // promote float(1) to 1.0 int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, fOffset, intValue)); - } else if (fType == *irGenerator.fContext.fUInt_Type) { + } else if (fType == *irGenerator.fContext.fUInt_Type || + fType == *irGenerator.fContext.fUShort_Type) { // promote uint(1) to 1u int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, diff --git a/src/sksl/ir/SkSLIRNode.h b/src/sksl/ir/SkSLIRNode.h index 5ada50607e..20b901d4a7 100644 --- a/src/sksl/ir/SkSLIRNode.h +++ b/src/sksl/ir/SkSLIRNode.h @@ -26,7 +26,7 @@ struct IRNode { // character offset of this element within the program being compiled, for error reporting // purposes - const int fOffset; + int fOffset; }; } // namespace diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h index 2daf1b552a..803d5ff8b0 100644 --- a/src/sksl/ir/SkSLIndexExpression.h +++ b/src/sksl/ir/SkSLIndexExpression.h @@ -26,8 +26,15 @@ static const Type& index_type(const Context& context, const Type& type) { case 4: return *context.fFloat4_Type; default: ASSERT(false); } + } else if (type.componentType() == *context.fHalf_Type) { + switch (type.rows()) { + case 2: return *context.fHalf2_Type; + case 3: return *context.fHalf3_Type; + case 4: return *context.fHalf4_Type; + default: ASSERT(false); + } } else { - ASSERT(type.componentType() == *context.fDouble_Type); + ASSERT(type.componentType() == *context.fDouble_Type); switch (type.rows()) { case 2: return *context.fDouble2_Type; case 3: return *context.fDouble3_Type; diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h index 639e09b16a..3184547476 100644 --- a/src/sksl/ir/SkSLProgram.h +++ b/src/sksl/ir/SkSLProgram.h @@ -74,6 +74,8 @@ struct Program { // if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their // constant equivalents during compilation bool fReplaceSettings = true; + // if true, all halfs are forced to be floats + bool fForceHighPrecision = false; std::unordered_map<String, Value> fArgs; }; @@ -105,7 +107,6 @@ struct Program { Program(Kind kind, std::unique_ptr<String> source, Settings settings, - Modifiers::Flag defaultPrecision, Context* context, std::vector<std::unique_ptr<ProgramElement>> elements, std::shared_ptr<SymbolTable> symbols, @@ -113,7 +114,6 @@ struct Program { : fKind(kind) , fSource(std::move(source)) , fSettings(settings) - , fDefaultPrecision(defaultPrecision) , fContext(context) , fSymbols(symbols) , fElements(std::move(elements)) @@ -122,8 +122,6 @@ struct Program { Kind fKind; std::unique_ptr<String> fSource; Settings fSettings; - // FIXME handle different types; currently it assumes this is for floats - Modifiers::Flag fDefaultPrecision; Context* fContext; // it's important to keep fElements defined after (and thus destroyed before) fSymbols, // because destroying elements can modify reference counts in symbols diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h index 3256ef211a..5512c852b3 100644 --- a/src/sksl/ir/SkSLSwizzle.h +++ b/src/sksl/ir/SkSLSwizzle.h @@ -32,6 +32,12 @@ static const Type& get_type(const Context& context, Expression& value, size_t co case 3: return *context.fFloat3_Type; case 4: return *context.fFloat4_Type; } + } else if (base == *context.fHalf_Type) { + switch (count) { + case 2: return *context.fHalf2_Type; + case 3: return *context.fHalf3_Type; + case 4: return *context.fHalf4_Type; + } } else if (base == *context.fDouble_Type) { switch (count) { case 2: return *context.fDouble2_Type; @@ -44,12 +50,24 @@ static const Type& get_type(const Context& context, Expression& value, size_t co case 3: return *context.fInt3_Type; case 4: return *context.fInt4_Type; } + } else if (base == *context.fShort_Type) { + switch (count) { + case 2: return *context.fShort2_Type; + case 3: return *context.fShort3_Type; + case 4: return *context.fShort4_Type; + } } else if (base == *context.fUInt_Type) { switch (count) { case 2: return *context.fUInt2_Type; case 3: return *context.fUInt3_Type; case 4: return *context.fUInt4_Type; } + } else if (base == *context.fUShort_Type) { + switch (count) { + case 2: return *context.fUShort2_Type; + case 3: return *context.fUShort3_Type; + case 4: return *context.fUShort4_Type; + } } else if (base == *context.fBool_Type) { switch (count) { case 2: return *context.fBool2_Type; diff --git a/src/sksl/ir/SkSLSymbol.h b/src/sksl/ir/SkSLSymbol.h index f4c675319b..4ec8f156cc 100644 --- a/src/sksl/ir/SkSLSymbol.h +++ b/src/sksl/ir/SkSLSymbol.h @@ -29,7 +29,7 @@ struct Symbol : public IRNode { , fKind(kind) , fName(name) {} - const Kind fKind; + Kind fKind; StringFragment fName; typedef IRNode INHERITED; diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp index 1fdc9bb68a..19bc58e2f0 100644 --- a/src/sksl/ir/SkSLType.cpp +++ b/src/sksl/ir/SkSLType.cpp @@ -80,6 +80,38 @@ const Type& Type::toCompound(const Context& context, int columns, int rows) cons } default: ABORT("unsupported row count (%d)", rows); } + } else if (*this == *context.fHalf_Type) { + switch (rows) { + case 1: + switch (columns) { + case 2: return *context.fHalf2_Type; + case 3: return *context.fHalf3_Type; + case 4: return *context.fHalf4_Type; + default: ABORT("unsupported vector column count (%d)", columns); + } + case 2: + switch (columns) { + case 2: return *context.fHalf2x2_Type; + case 3: return *context.fHalf3x2_Type; + case 4: return *context.fHalf4x2_Type; + default: ABORT("unsupported matrix column count (%d)", columns); + } + case 3: + switch (columns) { + case 2: return *context.fHalf2x3_Type; + case 3: return *context.fHalf3x3_Type; + case 4: return *context.fHalf4x3_Type; + default: ABORT("unsupported matrix column count (%d)", columns); + } + case 4: + switch (columns) { + case 2: return *context.fHalf2x4_Type; + case 3: return *context.fHalf3x4_Type; + case 4: return *context.fHalf4x4_Type; + default: ABORT("unsupported matrix column count (%d)", columns); + } + default: ABORT("unsupported row count (%d)", rows); + } } else if (*this == *context.fDouble_Type) { switch (rows) { case 1: @@ -123,6 +155,17 @@ const Type& Type::toCompound(const Context& context, int columns, int rows) cons } default: ABORT("unsupported row count (%d)", rows); } + } else if (*this == *context.fShort_Type) { + switch (rows) { + case 1: + switch (columns) { + case 2: return *context.fShort2_Type; + case 3: return *context.fShort3_Type; + case 4: return *context.fShort4_Type; + default: ABORT("unsupported vector column count (%d)", columns); + } + default: ABORT("unsupported row count (%d)", rows); + } } else if (*this == *context.fUInt_Type) { switch (rows) { case 1: @@ -134,6 +177,17 @@ const Type& Type::toCompound(const Context& context, int columns, int rows) cons } default: ABORT("unsupported row count (%d)", rows); } + } else if (*this == *context.fUShort_Type) { + switch (rows) { + case 1: + switch (columns) { + case 2: return *context.fUShort2_Type; + case 3: return *context.fUShort3_Type; + case 4: return *context.fUShort4_Type; + default: ABORT("unsupported vector column count (%d)", columns); + } + default: ABORT("unsupported row count (%d)", rows); + } } else if (*this == *context.fBool_Type) { switch (rows) { case 1: diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index b0474216c1..ed5e076e73 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -93,11 +93,12 @@ public: } // Create a scalar type. - Type(String name, NumberKind numberKind) + Type(String name, NumberKind numberKind, int priority) : INHERITED(-1, kType_Kind, StringFragment()) , fNameString(std::move(name)) , fTypeKind(kScalar_Kind) , fNumberKind(numberKind) + , fPriority(priority) , fColumns(1) , fRows(1) { fName.fChars = fNameString.c_str(); @@ -105,11 +106,12 @@ public: } // Create a scalar type which can be coerced to the listed types. - Type(String name, NumberKind numberKind, std::vector<const Type*> coercibleTypes) + Type(String name, NumberKind numberKind, int priority, std::vector<const Type*> coercibleTypes) : INHERITED(-1, kType_Kind, StringFragment()) , fNameString(std::move(name)) , fTypeKind(kScalar_Kind) , fNumberKind(numberKind) + , fPriority(priority) , fCoercibleTypes(std::move(coercibleTypes)) , fColumns(1) , fRows(1) { @@ -224,6 +226,14 @@ public: } /** + * Returns the "priority" of a number type, in order of double > float > half > int > short. + * When operating on two number types, the result is the higher-priority type. + */ + int priority() const { + return fPriority; + } + + /** * Returns true if an instance of this type can be freely coerced (implicitly converted) to * another type. */ @@ -315,20 +325,21 @@ public: private: typedef Symbol INHERITED; - const String fNameString; - const Kind fTypeKind; + String fNameString; + Kind fTypeKind; // always kNonnumeric_NumberKind for non-scalar values - const NumberKind fNumberKind; + NumberKind fNumberKind; + int fPriority = -1; const Type* fComponentType = nullptr; - const std::vector<const Type*> fCoercibleTypes; - const int fColumns = -1; - const int fRows = -1; - const std::vector<Field> fFields; - const SpvDim_ fDimensions = SpvDim1D; - const bool fIsDepth = false; - const bool fIsArrayed = false; - const bool fIsMultisampled = false; - const bool fIsSampled = false; + std::vector<const Type*> fCoercibleTypes; + int fColumns = -1; + int fRows = -1; + std::vector<Field> fFields; + SpvDim_ fDimensions = SpvDim1D; + bool fIsDepth = false; + bool fIsArrayed = false; + bool fIsMultisampled = false; + bool fIsSampled = false; }; } // namespace |