Reduce the size of DSLType.

This CL removes the TypeConstant member from DSLType. The constructor
which takes a TypeConstant now sets the `fSkSLType` field immediately
instead of saving the value and deferring lookup until `skslType()` is
called.

This caused some ripple-effect issues in type setup code which were
fixable by replacing nullptr with Poison.

Change-Id: I8fa73cdf5f0bcd3de143c9a25ea43392d75c7dec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/545780
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2022-06-01 18:00:43 -04:00 committed by SkCQ
parent f64f211283
commit a98b3a1f0c
3 changed files with 17 additions and 24 deletions

View File

@ -82,9 +82,7 @@ enum TypeConstant : uint8_t {
class DSLType {
public:
DSLType(TypeConstant tc, Position pos = {})
: fTypeConstant(tc)
, fPosition(pos) {}
DSLType(TypeConstant tc, Position pos = {});
DSLType(const SkSL::Type* type, Position pos = {});
@ -169,10 +167,9 @@ public:
static DSLExpression Construct(DSLType type, SkSpan<DSLExpression> argArray);
private:
const SkSL::Type& skslType() const;
const SkSL::Type& skslType() const { return *fSkSLType; }
const SkSL::Type* fSkSLType = nullptr;
TypeConstant fTypeConstant = kPoison_Type;
Position fPosition;
friend DSLType Array(const DSLType& base, int count, Position pos);

View File

@ -75,12 +75,12 @@ static const SkSL::Type* find_type(const Context& context,
Position modifiersPos,
Modifiers* modifiers) {
const Type* type = find_type(context, overallPos, name);
type = type->applyPrecisionQualifiers(context, modifiers, ThreadContext::SymbolTable().get(),
return type->applyPrecisionQualifiers(context, modifiers, ThreadContext::SymbolTable().get(),
modifiersPos);
return type;
}
static const SkSL::Type* get_type_from_type_constant(const Context& context, TypeConstant tc) {
static const SkSL::Type* get_type_from_type_constant(TypeConstant tc) {
const Context& context = ThreadContext::Context();
switch (tc) {
case kBool_Type:
return context.fTypes.fBool.get();
@ -185,6 +185,13 @@ static const SkSL::Type* get_type_from_type_constant(const Context& context, Typ
}
}
DSLType::DSLType(TypeConstant tc, Position pos)
: fSkSLType(verify_type(ThreadContext::Context(),
get_type_from_type_constant(tc),
/*allowPrivateTypes=*/true,
pos))
, fPosition(pos) {}
DSLType::DSLType(std::string_view name, Position pos)
: fSkSLType(find_type(ThreadContext::Context(), pos, name))
, fPosition(pos) {}
@ -246,17 +253,6 @@ bool DSLType::isEffectChild() const {
return this->skslType().isEffectChild();
}
const SkSL::Type& DSLType::skslType() const {
if (fSkSLType) {
return *fSkSLType;
}
const Context& context = ThreadContext::Context();
return *verify_type(context,
get_type_from_type_constant(context, fTypeConstant),
/*allowPrivateTypes=*/true,
Position());
}
DSLExpression DSLType::Construct(DSLType type, SkSpan<DSLExpression> argArray) {
SkSL::ExpressionArray skslArgs;
skslArgs.reserve_back(argArray.size());

View File

@ -637,12 +637,12 @@ const Type* Type::applyPrecisionQualifiers(const Context& context,
// We want to discourage precision modifiers internally. Instead, use the type that
// corresponds to the precision you need. (e.g. half vs float, short vs int)
context.fErrors->error(pos, "precision qualifiers are not allowed");
return nullptr;
return context.fTypes.fPoison.get();
}
if ((int(lowp) + int(mediump) + int(highp)) != 1) {
context.fErrors->error(pos, "only one precision qualifier can be used");
return nullptr;
return context.fTypes.fPoison.get();
}
// We're going to return a whole new type, so the modifier bits can be cleared out.
@ -673,7 +673,7 @@ const Type* Type::applyPrecisionQualifiers(const Context& context,
break;
default:
mediumpType = nullptr;
mediumpType = context.fTypes.fPoison.get();
break;
}
@ -687,7 +687,7 @@ const Type* Type::applyPrecisionQualifiers(const Context& context,
context.fErrors->error(pos, "type '" + this->displayName() +
"' does not support precision qualifiers");
return nullptr;
return context.fTypes.fPoison.get();
}
const Type& Type::toCompound(const Context& context, int columns, int rows) const {