2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-11-28 16:23:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_MODIFIERS
|
|
|
|
#define SKSL_MODIFIERS
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLLayout.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
2021-10-14 13:38:06 +00:00
|
|
|
class Context;
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
/**
|
2016-11-28 16:23:23 +00:00
|
|
|
* A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration.
|
2016-07-01 15:22:01 +00:00
|
|
|
*/
|
|
|
|
struct Modifiers {
|
2021-10-01 18:21:09 +00:00
|
|
|
/**
|
|
|
|
* OpenGL requires modifiers to be in a strict order:
|
|
|
|
* - invariant-qualifier: (invariant)
|
|
|
|
* - interpolation-qualifier: flat, noperspective, (smooth)
|
|
|
|
* - storage-qualifier: const, uniform
|
|
|
|
* - parameter-qualifier: in, out, inout
|
|
|
|
* - precision-qualifier: highp, mediump, lowp
|
|
|
|
*
|
|
|
|
* SkSL does not have `invariant` or `smooth`.
|
|
|
|
*/
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
enum Flag {
|
2017-04-20 23:31:52 +00:00
|
|
|
kNo_Flag = 0,
|
2021-10-01 18:21:09 +00:00
|
|
|
// Real GLSL modifiers
|
|
|
|
kFlat_Flag = 1 << 0,
|
|
|
|
kNoPerspective_Flag = 1 << 1,
|
|
|
|
kConst_Flag = 1 << 2,
|
2019-03-07 18:19:18 +00:00
|
|
|
kUniform_Flag = 1 << 3,
|
2021-10-01 18:21:09 +00:00
|
|
|
kIn_Flag = 1 << 4,
|
|
|
|
kOut_Flag = 1 << 5,
|
|
|
|
kHighp_Flag = 1 << 6,
|
|
|
|
kMediump_Flag = 1 << 7,
|
|
|
|
kLowp_Flag = 1 << 8,
|
|
|
|
// SkSL extensions, not present in GLSL
|
|
|
|
kES3_Flag = 1 << 9,
|
|
|
|
kHasSideEffects_Flag = 1 << 10,
|
|
|
|
kInline_Flag = 1 << 11,
|
|
|
|
kNoInline_Flag = 1 << 12,
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 20:59:48 +00:00
|
|
|
Modifiers()
|
|
|
|
: fLayout(Layout())
|
|
|
|
, fFlags(0) {}
|
|
|
|
|
2018-09-07 17:44:21 +00:00
|
|
|
Modifiers(const Layout& layout, int flags)
|
2016-07-01 15:22:01 +00:00
|
|
|
: fLayout(layout)
|
|
|
|
, fFlags(flags) {}
|
|
|
|
|
2022-02-02 21:51:18 +00:00
|
|
|
std::string description() const {
|
|
|
|
std::string result = fLayout.description();
|
2021-10-01 18:21:09 +00:00
|
|
|
|
|
|
|
// SkSL extensions
|
2021-08-13 03:06:24 +00:00
|
|
|
if (fFlags & kES3_Flag) {
|
|
|
|
result += "$es3 ";
|
|
|
|
}
|
2021-10-01 18:21:09 +00:00
|
|
|
if (fFlags & kHasSideEffects_Flag) {
|
|
|
|
result += "sk_has_side_effects ";
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
2021-10-01 18:21:09 +00:00
|
|
|
if (fFlags & kNoInline_Flag) {
|
|
|
|
result += "noinline ";
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
2021-10-01 18:21:09 +00:00
|
|
|
|
|
|
|
// Real GLSL qualifiers (must be specified in order in GLSL 4.1 and below)
|
2016-08-03 19:43:36 +00:00
|
|
|
if (fFlags & kFlat_Flag) {
|
|
|
|
result += "flat ";
|
|
|
|
}
|
|
|
|
if (fFlags & kNoPerspective_Flag) {
|
|
|
|
result += "noperspective ";
|
|
|
|
}
|
2021-10-01 18:21:09 +00:00
|
|
|
if (fFlags & kConst_Flag) {
|
|
|
|
result += "const ";
|
2017-04-20 23:31:52 +00:00
|
|
|
}
|
2021-10-01 18:21:09 +00:00
|
|
|
if (fFlags & kUniform_Flag) {
|
|
|
|
result += "uniform ";
|
|
|
|
}
|
|
|
|
if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
|
|
|
|
result += "inout ";
|
|
|
|
} else if (fFlags & kIn_Flag) {
|
|
|
|
result += "in ";
|
|
|
|
} else if (fFlags & kOut_Flag) {
|
|
|
|
result += "out ";
|
2021-03-10 03:14:27 +00:00
|
|
|
}
|
2021-08-04 20:03:12 +00:00
|
|
|
if (fFlags & kHighp_Flag) {
|
|
|
|
result += "highp ";
|
|
|
|
}
|
|
|
|
if (fFlags & kMediump_Flag) {
|
|
|
|
result += "mediump ";
|
|
|
|
}
|
|
|
|
if (fFlags & kLowp_Flag) {
|
|
|
|
result += "lowp ";
|
|
|
|
}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Modifiers& other) const {
|
|
|
|
return fLayout == other.fLayout && fFlags == other.fFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Modifiers& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2021-10-14 13:38:06 +00:00
|
|
|
/**
|
|
|
|
* Verifies that only permitted modifiers and layout flags are included. Reports errors and
|
|
|
|
* returns false in the event of a violation.
|
|
|
|
*/
|
|
|
|
bool checkPermitted(const Context& context, int line, int permittedModifierFlags,
|
|
|
|
int permittedLayoutFlags) const;
|
|
|
|
|
2016-08-03 19:43:36 +00:00
|
|
|
Layout fLayout;
|
|
|
|
int fFlags;
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<SkSL::Modifiers> {
|
|
|
|
size_t operator()(const SkSL::Modifiers& key) const {
|
2021-03-04 19:30:25 +00:00
|
|
|
return (size_t) key.fFlags ^ ((size_t) key.fLayout.fFlags << 8) ^
|
|
|
|
((size_t) key.fLayout.fBuiltin << 16);
|
2020-10-07 20:42:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|