33static bool check_valid_uniform_type(Position
pos,
36 bool topLevel =
true) {
37 auto reportError = [&]() {
38 context.fErrors->error(
pos,
"variables of type '" + t->displayName() +
39 "' may not be uniform");
46 if (t->isEffectChild()) {
51 const Type& ct = t->componentType();
52 if (ct.isSigned() && ct.bitWidth() == 32 && (t->isScalar() || t->isVector())) {
59 (t->isScalar() || t->isVector() || (t->isMatrix() && t->rows() == t->columns()))) {
68 Position errorPosition = {};
69 if (!t->isAllowedInUniform(&errorPosition)) {
71 if (errorPosition.valid()) {
72 context.fErrors->error(errorPosition,
"caused by:");
90 result +=
" = " + this->
value()->description();
102 const Type* baseType,
113 context.
fErrors->
error(
pos,
"'in' variables may not have matrix type");
116 context.
fErrors->
error(
pos,
"'in' variables may not have unsized array type");
119 context.
fErrors->
error(
pos,
"'out' variables may not have unsized array type");
125 context.
fErrors->
error(
pos,
"'readonly' and 'writeonly' qualifiers cannot be combined");
128 context.
fErrors->
error(
pos,
"'uniform buffer' variables not permitted");
132 context.
fErrors->
error(
pos,
"in / out variables may not be declared workgroup");
139 "' must be uniform");
142 context.
fErrors->
error(
pos,
"effects are not permitted in mesh vertex shaders");
155 bool isBlockMember = (storage == Variable::Storage::kInterfaceBlock);
156 bool isWritableStorageBuffer = modifierFlags.
isBuffer() && !modifierFlags.
isReadOnly();
160 context.
fErrors->
error(
pos,
"atomics are only permitted in workgroup variables and "
161 "writable storage blocks");
166 context.
fErrors->
error(
pos,
"'layout(color)' is only permitted in runtime effects");
169 context.
fErrors->
error(
pos,
"'layout(color)' is only permitted on 'uniform' variables");
171 auto validColorXformType = [](
const Type& t) {
172 return t.isVector() && t.componentType().isFloat() &&
173 (t.columns() == 3 || t.columns() == 4);
175 if (!validColorXformType(*
baseType)) {
176 context.
fErrors->
error(
pos,
"'layout(color)' is not permitted on variables of type '" +
203 const int illegalRangeEnd =
SkToInt(fields.size()) -
205 for (
int i = 0;
i < illegalRangeEnd; ++
i) {
206 if (fields[
i].fType->isUnsizedArray()) {
209 "unsized array must be the last member of a storage block");
240 context.
fErrors->
error(
pos,
"storage textures must declare a pixel format");
243 permittedLayoutFlags &=
~LayoutFlag::kAllPixelFormats;
271 !permitBindingAndSet)) {
284 permittedLayoutFlags &=
~LayoutFlag::kPushConstant;
295bool VarDeclaration::ErrorCheckAndCoerce(
const Context& context,
297 const Type* baseType,
298 std::unique_ptr<Expression>&
value) {
313 "' cannot use initializer expressions");
318 "'in' variables cannot use initializer expressions");
323 "'uniform' variables cannot use initializer expressions");
326 if (
var.
storage() == Variable::Storage::kInterfaceBlock) {
328 "initializers are not permitted on interface block fields");
332 context.
fErrors->
error(
value->fPosition,
"initializers are not permitted on arrays "
333 "(or structs containing arrays)");
348 "'const' variable initializer must be a constant expression");
352 if (
var.
storage() == Variable::Storage::kInterfaceBlock) {
355 "' is not permitted in an interface block");
362 "global variable initializer must be a constant expression");
374 std::string_view
name,
376 std::unique_ptr<Expression>
value) {
396 std::unique_ptr<Variable> var,
397 std::unique_ptr<Expression>
value) {
414 var->
storage() == Variable::Storage::kInterfaceBlock) {
418 "symbol '" + std::string(
var->
name()) +
"' was already defined");
437 const Type* baseType,
439 std::unique_ptr<Expression>
value) {
constexpr int SkToInt(S x)
const std::unique_ptr< Type > fInvalid
const std::unique_ptr< Type > fFloat4
static constexpr const char RTADJUST_NAME[]
const BuiltinTypes & fTypes
SymbolTable * fSymbolTable
void error(Position position, std::string_view msg)
std::string paddedDescription() const
bool checkPermittedFlags(const Context &context, Position pos, ModifierFlags permittedModifierFlags) const
const Symbol * find(std::string_view name) const
T * add(const Context &context, std::unique_ptr< T > symbol)
std::string_view name() const
const Type & type() const
virtual bool isArray() const
std::unique_ptr< Expression > coerceExpression(std::unique_ptr< Expression > expr, const Context &context) const
bool isEffectChild() const
virtual const Type & componentType() const
virtual bool isInterfaceBlock() const
virtual bool isOrContainsArray() const
virtual SkSpan< const Field > fields() const
bool matches(const Type &other) const
virtual bool isMatrix() const
virtual int columns() const
std::string description() const override
virtual bool isOrContainsAtomic() const
bool isStorageTexture() const
std::string displayName() const
TypeKind typeKind() const
virtual bool isStruct() const
const Type & baseType() const
static std::unique_ptr< VarDeclaration > Convert(const Context &context, Position overallPos, const Modifiers &modifiers, const Type &type, Position namePos, std::string_view name, VariableStorage storage, std::unique_ptr< Expression > value)
std::unique_ptr< Expression > & value()
static void ErrorCheck(const Context &context, Position pos, Position modifiersPosition, const Layout &layout, ModifierFlags modifierFlags, const Type *type, const Type *baseType, Variable::Storage storage)
std::string description() const override
static std::unique_ptr< VarDeclaration > Make(const Context &context, Variable *var, const Type *baseType, int arraySize, std::unique_ptr< Expression > value)
void setVarDeclaration(VarDeclaration *declaration)
Position modifiersPosition() const
static std::unique_ptr< Variable > Convert(const Context &context, Position pos, Position modifiersPos, const Layout &layout, ModifierFlags flags, const Type *type, Position namePos, std::string_view name, Storage storage)
ModifierFlags modifierFlags() const
virtual const Layout & layout() const
bool IsConstantExpression(const Expression &expr)
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
DEF_SWITCHES_START aot vmservice shared library name
std::string paddedDescription() const
bool checkPermittedLayout(const Context &context, Position pos, LayoutFlags permittedLayoutFlags) const
SkSL::ModifierFlags fFlags
static bool IsRuntimeEffect(ProgramKind kind)
bool strictES2Mode() const
static bool IsFragment(ProgramKind kind)
static bool IsCompute(ProgramKind kind)