Flutter Engine
The Flutter Engine
SkSLModifiersDeclaration.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
16
17#include <cstdint>
18
19namespace SkSL {
20
21enum class ProgramKind : int8_t;
22
23std::unique_ptr<ModifiersDeclaration> ModifiersDeclaration::Convert(const Context& context,
24 const Modifiers& modifiers) {
28 context.fErrors->error(modifiers.fPosition,
29 "layout qualifiers are not allowed in this kind of program");
30 return nullptr;
31 }
32
33 if (modifiers.fLayout.fLocalSizeX >= 0 ||
34 modifiers.fLayout.fLocalSizeY >= 0 ||
35 modifiers.fLayout.fLocalSizeZ >= 0) {
36 if (modifiers.fLayout.fLocalSizeX == 0 ||
37 modifiers.fLayout.fLocalSizeY == 0 ||
38 modifiers.fLayout.fLocalSizeZ == 0) {
39 context.fErrors->error(modifiers.fPosition, "local size qualifiers cannot be zero");
40 return nullptr;
41 }
43 context.fErrors->error(
44 modifiers.fPosition,
45 "local size layout qualifiers are only allowed in a compute program");
46 return nullptr;
47 }
48 if (modifiers.fFlags != ModifierFlag::kIn) {
49 context.fErrors->error(
50 modifiers.fPosition,
51 "local size layout qualifiers must be defined using an 'in' declaration");
52 return nullptr;
53 }
54 }
55
56 return ModifiersDeclaration::Make(context, modifiers);
57}
58
59std::unique_ptr<ModifiersDeclaration> ModifiersDeclaration::Make(const Context& context,
60 const Modifiers& modifiers) {
61 [[maybe_unused]] SkSL::ProgramKind kind = context.fConfig->fKind;
64
65 return std::make_unique<ModifiersDeclaration>(modifiers.fPosition,
66 modifiers.fLayout,
67 modifiers.fFlags);
68}
69
70} // namespace SkSL
#define SkASSERT(cond)
Definition: SkAssert.h:116
ErrorReporter * fErrors
Definition: SkSLContext.h:36
ProgramConfig * fConfig
Definition: SkSLContext.h:33
void error(Position position, std::string_view msg)
static std::unique_ptr< ModifiersDeclaration > Make(const Context &context, const Modifiers &modifiers)
static std::unique_ptr< ModifiersDeclaration > Convert(const Context &context, const Modifiers &modifiers)
SkSL::Layout fLayout
Definition: SkSLModifiers.h:19
Position fPosition
Definition: SkSLModifiers.h:18
SkSL::ModifierFlags fFlags
Definition: SkSLModifiers.h:20
static bool IsVertex(ProgramKind kind)
static bool IsFragment(ProgramKind kind)
static bool IsCompute(ProgramKind kind)