Replace trio of XxxxLiteral types with a single Literal type.
Throughout SkSL we've begun using doubles as a convenient way to store
any SkSL value (int, float, bool) in a single type. This idea has now
been extended to literals. Rather than having three expression kinds for
integers, floats and boolean literals, we can have just one. These can
be accessed in a type-specific way (`floatValue`, `intValue`, and
`boolValue` return the expected type, or assert if it's not the
matching type), or in a type-agnostic way (`value` will return a double
and works on any type of Literal).
This allows us to remove a complex template trick (Literal<T> is gone),
removes two redundant Expression types, and and lets us reduce our code
size in ConstantFolder, FunctionCall, etc.
Most of the conversion process was pretty straightforward:
* `IntLiteral::Make` becomes `Literal::MakeInt`
* `x.is<IntLiteral>()` becomes `x.isIntLiteral()`
* `x.as<IntLiteral>.value()` becomes `x.as<Literal>.intValue()`
Change-Id: Ic328533611e4551669c7fc9d7f9c03e34699f3f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/447836
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.h b/src/sksl/codegen/SkSLSPIRVCodeGenerator.h
index 5c08c82..0e7b728 100644
--- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.h
+++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.h
@@ -21,7 +21,6 @@
#include "src/sksl/SkSLStringStream.h"
#include "src/sksl/codegen/SkSLCodeGenerator.h"
#include "src/sksl/ir/SkSLBinaryExpression.h"
-#include "src/sksl/ir/SkSLBoolLiteral.h"
#include "src/sksl/ir/SkSLConstructor.h"
#include "src/sksl/ir/SkSLConstructorArray.h"
#include "src/sksl/ir/SkSLConstructorCompound.h"
@@ -33,15 +32,14 @@
#include "src/sksl/ir/SkSLConstructorStruct.h"
#include "src/sksl/ir/SkSLDoStatement.h"
#include "src/sksl/ir/SkSLFieldAccess.h"
-#include "src/sksl/ir/SkSLFloatLiteral.h"
#include "src/sksl/ir/SkSLForStatement.h"
#include "src/sksl/ir/SkSLFunctionCall.h"
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLFunctionDefinition.h"
#include "src/sksl/ir/SkSLIfStatement.h"
#include "src/sksl/ir/SkSLIndexExpression.h"
-#include "src/sksl/ir/SkSLIntLiteral.h"
#include "src/sksl/ir/SkSLInterfaceBlock.h"
+#include "src/sksl/ir/SkSLLiteral.h"
#include "src/sksl/ir/SkSLPostfixExpression.h"
#include "src/sksl/ir/SkSLPrefixExpression.h"
#include "src/sksl/ir/SkSLReturnStatement.h"
@@ -59,7 +57,7 @@
return fValueBits == that.fValueBits &&
fKind == that.fKind;
}
- int64_t fValueBits; // contains either an SKSL_INT or zero-padded bits from an SKSL_FLOAT
+ int32_t fValueBits;
SkSL::Type::NumberKind fKind;
};
@@ -133,8 +131,6 @@
, fDefaultLayout(MemoryLayout::k140_Standard)
, fCapabilities(0)
, fIdCount(1)
- , fBoolTrue(0)
- , fBoolFalse(0)
, fSetupFragPosition(false)
, fCurrentBlock(0)
, fSynthetics(fContext, /*builtin=*/true) {
@@ -388,11 +384,7 @@
SpvId writePostfixExpression(const PostfixExpression& p, OutputStream& out);
- SpvId writeBoolLiteral(const BoolLiteral& b);
-
- SpvId writeIntLiteral(const IntLiteral& i);
-
- SpvId writeFloatLiteral(const FloatLiteral& f);
+ SpvId writeLiteral(const Literal& f);
void writeStatement(const Statement& s, OutputStream& out);
@@ -496,8 +488,6 @@
StringStream fNameBuffer;
StringStream fDecorationBuffer;
- SpvId fBoolTrue;
- SpvId fBoolFalse;
std::unordered_map<SPIRVNumberConstant, SpvId> fNumberConstants;
std::unordered_map<SPIRVVectorConstant, SpvId> fVectorConstants;
bool fSetupFragPosition;