Rewrite CheckModifiers to reduce code bloat
On my Linux-Release build, this cuts out 13K of code. Change-Id: I4f470b148816441850400cafacd9fdf6c845ac0d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438221 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
8477dd24c8
commit
b5de6be2a8
@ -729,56 +729,59 @@ void IRGenerator::CheckModifiers(const Context& context,
|
||||
const Modifiers& modifiers,
|
||||
int permittedModifierFlags,
|
||||
int permittedLayoutFlags) {
|
||||
ErrorReporter& errorReporter = context.fErrors;
|
||||
int flags = modifiers.fFlags;
|
||||
auto checkModifier = [&](Modifiers::Flag flag, const char* name) {
|
||||
if (flags & flag) {
|
||||
if (!(permittedModifierFlags & flag)) {
|
||||
errorReporter.error(offset, "'" + String(name) + "' is not permitted here");
|
||||
}
|
||||
flags &= ~flag;
|
||||
}
|
||||
static constexpr struct { Modifiers::Flag flag; const char* name; } kModifierFlags[] = {
|
||||
{ Modifiers::kConst_Flag, "const" },
|
||||
{ Modifiers::kIn_Flag, "in" },
|
||||
{ Modifiers::kOut_Flag, "out" },
|
||||
{ Modifiers::kUniform_Flag, "uniform" },
|
||||
{ Modifiers::kFlat_Flag, "flat" },
|
||||
{ Modifiers::kNoPerspective_Flag, "noperspective" },
|
||||
{ Modifiers::kHasSideEffects_Flag, "sk_has_side_effects" },
|
||||
{ Modifiers::kInline_Flag, "inline" },
|
||||
{ Modifiers::kNoInline_Flag, "noinline" },
|
||||
{ Modifiers::kHighp_Flag, "highp" },
|
||||
{ Modifiers::kMediump_Flag, "mediump" },
|
||||
{ Modifiers::kLowp_Flag, "lowp" },
|
||||
};
|
||||
|
||||
checkModifier(Modifiers::kConst_Flag, "const");
|
||||
checkModifier(Modifiers::kIn_Flag, "in");
|
||||
checkModifier(Modifiers::kOut_Flag, "out");
|
||||
checkModifier(Modifiers::kUniform_Flag, "uniform");
|
||||
checkModifier(Modifiers::kFlat_Flag, "flat");
|
||||
checkModifier(Modifiers::kNoPerspective_Flag, "noperspective");
|
||||
checkModifier(Modifiers::kHasSideEffects_Flag, "sk_has_side_effects");
|
||||
checkModifier(Modifiers::kInline_Flag, "inline");
|
||||
checkModifier(Modifiers::kNoInline_Flag, "noinline");
|
||||
checkModifier(Modifiers::kHighp_Flag, "highp");
|
||||
checkModifier(Modifiers::kMediump_Flag, "mediump");
|
||||
checkModifier(Modifiers::kLowp_Flag, "lowp");
|
||||
SkASSERT(flags == 0);
|
||||
int modifierFlags = modifiers.fFlags;
|
||||
for (const auto& f : kModifierFlags) {
|
||||
if (modifierFlags & f.flag) {
|
||||
if (!(permittedModifierFlags & f.flag)) {
|
||||
context.fErrors.error(offset, "'" + String(f.name) + "' is not permitted here");
|
||||
}
|
||||
modifierFlags &= ~f.flag;
|
||||
}
|
||||
}
|
||||
SkASSERT(modifierFlags == 0);
|
||||
|
||||
static constexpr struct { Layout::Flag flag; const char* name; } kLayoutFlags[] = {
|
||||
{ Layout::kOriginUpperLeft_Flag, "origin_upper_left"},
|
||||
{ Layout::kPushConstant_Flag, "push_constant"},
|
||||
{ Layout::kBlendSupportAllEquations_Flag, "blend_support_all_equations"},
|
||||
{ Layout::kSRGBUnpremul_Flag, "srgb_unpremul"},
|
||||
{ Layout::kLocation_Flag, "location"},
|
||||
{ Layout::kOffset_Flag, "offset"},
|
||||
{ Layout::kBinding_Flag, "binding"},
|
||||
{ Layout::kIndex_Flag, "index"},
|
||||
{ Layout::kSet_Flag, "set"},
|
||||
{ Layout::kBuiltin_Flag, "builtin"},
|
||||
{ Layout::kInputAttachmentIndex_Flag, "input_attachment_index"},
|
||||
{ Layout::kPrimitive_Flag, "primitive-type"},
|
||||
{ Layout::kMaxVertices_Flag, "max_vertices"},
|
||||
{ Layout::kInvocations_Flag, "invocations"},
|
||||
};
|
||||
|
||||
int layoutFlags = modifiers.fLayout.fFlags;
|
||||
auto checkLayout = [&](Layout::Flag flag, const char* name) {
|
||||
if (layoutFlags & flag) {
|
||||
if (!(permittedLayoutFlags & flag)) {
|
||||
errorReporter.error(offset, "layout qualifier '" + String(name) +
|
||||
"' is not permitted here");
|
||||
for (const auto& lf : kLayoutFlags) {
|
||||
if (layoutFlags & lf.flag) {
|
||||
if (!(permittedLayoutFlags & lf.flag)) {
|
||||
context.fErrors.error(
|
||||
offset, "layout qualifier '" + String(lf.name) + "' is not permitted here");
|
||||
}
|
||||
layoutFlags &= ~flag;
|
||||
layoutFlags &= ~lf.flag;
|
||||
}
|
||||
};
|
||||
|
||||
checkLayout(Layout::kOriginUpperLeft_Flag, "origin_upper_left");
|
||||
checkLayout(Layout::kPushConstant_Flag, "push_constant");
|
||||
checkLayout(Layout::kBlendSupportAllEquations_Flag, "blend_support_all_equations");
|
||||
checkLayout(Layout::kSRGBUnpremul_Flag, "srgb_unpremul");
|
||||
checkLayout(Layout::kLocation_Flag, "location");
|
||||
checkLayout(Layout::kOffset_Flag, "offset");
|
||||
checkLayout(Layout::kBinding_Flag, "binding");
|
||||
checkLayout(Layout::kIndex_Flag, "index");
|
||||
checkLayout(Layout::kSet_Flag, "set");
|
||||
checkLayout(Layout::kBuiltin_Flag, "builtin");
|
||||
checkLayout(Layout::kInputAttachmentIndex_Flag, "input_attachment_index");
|
||||
checkLayout(Layout::kPrimitive_Flag, "primitive-type");
|
||||
checkLayout(Layout::kMaxVertices_Flag, "max_vertices");
|
||||
checkLayout(Layout::kInvocations_Flag, "invocations");
|
||||
}
|
||||
SkASSERT(layoutFlags == 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user