Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SkSL::Layout Struct Reference

#include <SkSLLayout.h>

Public Member Functions

 Layout (LayoutFlags flags, int location, int offset, int binding, int index, int set, int builtin, int inputAttachmentIndex)
 
constexpr Layout ()=default
 
std::string description () const
 
std::string paddedDescription () const
 
bool checkPermittedLayout (const Context &context, Position pos, LayoutFlags permittedLayoutFlags) const
 
bool operator== (const Layout &other) const
 
bool operator!= (const Layout &other) const
 

Static Public Member Functions

static Layout builtin (int builtin)
 

Public Attributes

LayoutFlags fFlags = LayoutFlag::kNone
 
int fLocation = -1
 
int fOffset = -1
 
int fBinding = -1
 
int fTexture = -1
 
int fSampler = -1
 
int fIndex = -1
 
int fSet = -1
 
int fBuiltin = -1
 
int fInputAttachmentIndex = -1
 
int fLocalSizeX = -1
 
int fLocalSizeY = -1
 
int fLocalSizeZ = -1
 

Detailed Description

Represents a layout block appearing before a variable declaration, as in:

layout (location = 0) int x;

Definition at line 75 of file SkSLLayout.h.

Constructor & Destructor Documentation

◆ Layout() [1/2]

SkSL::Layout::Layout ( LayoutFlags  flags,
int  location,
int  offset,
int  binding,
int  index,
int  set,
int  builtin,
int  inputAttachmentIndex 
)
inline

Definition at line 76 of file SkSLLayout.h.

78 : fFlags(flags)
79 , fLocation(location)
81 , fBinding(binding)
82 , fIndex(index)
83 , fSet(set)
85 , fInputAttachmentIndex(inputAttachmentIndex) {}
FlutterSemanticsFlag flags
Point offset
LayoutFlags fFlags
Definition SkSLLayout.h:112
int fInputAttachmentIndex
Definition SkSLLayout.h:125
static Layout builtin(int builtin)
Definition SkSLLayout.h:89

◆ Layout() [2/2]

constexpr SkSL::Layout::Layout ( )
constexprdefault

Member Function Documentation

◆ builtin()

static Layout SkSL::Layout::builtin ( int  builtin)
inlinestatic

Definition at line 89 of file SkSLLayout.h.

89 {
91 result.fBuiltin = builtin;
92 return result;
93 }
GAsyncResult * result
constexpr Layout()=default

◆ checkPermittedLayout()

bool SkSL::Layout::checkPermittedLayout ( const Context context,
Position  pos,
LayoutFlags  permittedLayoutFlags 
) const

Verifies that only permitted layout flags are included. Reports errors and returns false in the event of a violation.

Definition at line 105 of file SkSLLayout.cpp.

107 {
108 static constexpr struct { LayoutFlag flag; const char* name; } kLayoutFlags[] = {
109 { LayoutFlag::kOriginUpperLeft, "origin_upper_left"},
110 { LayoutFlag::kPushConstant, "push_constant"},
111 { LayoutFlag::kBlendSupportAllEquations, "blend_support_all_equations"},
112 { LayoutFlag::kColor, "color"},
113 { LayoutFlag::kLocation, "location"},
114 { LayoutFlag::kOffset, "offset"},
115 { LayoutFlag::kBinding, "binding"},
116 { LayoutFlag::kTexture, "texture"},
117 { LayoutFlag::kSampler, "sampler"},
118 { LayoutFlag::kIndex, "index"},
119 { LayoutFlag::kSet, "set"},
120 { LayoutFlag::kBuiltin, "builtin"},
121 { LayoutFlag::kInputAttachmentIndex, "input_attachment_index"},
122 { LayoutFlag::kVulkan, "vulkan"},
123 { LayoutFlag::kMetal, "metal"},
124 { LayoutFlag::kWebGPU, "webgpu"},
125 { LayoutFlag::kDirect3D, "direct3d"},
126 { LayoutFlag::kRGBA8, "rgba8"},
127 { LayoutFlag::kRGBA32F, "rgba32f"},
128 { LayoutFlag::kR32F, "r32f"},
129 { LayoutFlag::kLocalSizeX, "local_size_x"},
130 { LayoutFlag::kLocalSizeY, "local_size_y"},
131 { LayoutFlag::kLocalSizeZ, "local_size_z"},
132 };
133
134 bool success = true;
135 LayoutFlags layoutFlags = fFlags;
136
137 LayoutFlags backendFlags = layoutFlags & LayoutFlag::kAllBackends;
138 if (SkPopCount(backendFlags.value()) > 1) {
139 context.fErrors->error(pos, "only one backend qualifier can be used");
140 success = false;
141 }
142
143 LayoutFlags pixelFormatFlags = layoutFlags & LayoutFlag::kAllPixelFormats;
144 if (SkPopCount(pixelFormatFlags.value()) > 1) {
145 context.fErrors->error(pos, "only one pixel format qualifier can be used");
146 success = false;
147 }
148
149 if ((layoutFlags & (LayoutFlag::kTexture | LayoutFlag::kSampler)) &&
150 layoutFlags & LayoutFlag::kBinding) {
151 context.fErrors->error(pos, "'binding' modifier cannot coexist with 'texture'/'sampler'");
152 success = false;
153 }
154 // The `texture` and `sampler` flags are only allowed when targeting Metal, WebGPU or Direct3D.
156 permittedLayoutFlags &= ~LayoutFlag::kTexture;
157 permittedLayoutFlags &= ~LayoutFlag::kSampler;
158 }
159 // The `push_constant` flag is only allowed when targeting Vulkan or WebGPU.
160 if (!(layoutFlags & (LayoutFlag::kVulkan | LayoutFlag::kWebGPU))) {
161 permittedLayoutFlags &= ~LayoutFlag::kPushConstant;
162 }
163 // The `set` flag is not allowed when explicitly targeting Metal.
164 if (layoutFlags & LayoutFlag::kMetal) {
165 permittedLayoutFlags &= ~LayoutFlag::kSet;
166 }
167
168 for (const auto& lf : kLayoutFlags) {
169 if (layoutFlags & lf.flag) {
170 if (!(permittedLayoutFlags & lf.flag)) {
171 context.fErrors->error(pos, "layout qualifier '" + std::string(lf.name) +
172 "' is not permitted here");
173 success = false;
174 }
175 layoutFlags &= ~lf.flag;
176 }
177 }
178 SkASSERT(layoutFlags == LayoutFlag::kNone);
179 return success;
180}
SkPoint pos
#define SkASSERT(cond)
Definition SkAssert.h:116
static int SkPopCount(uint32_t n)
Definition SkMathPriv.h:136
FlutterSemanticsFlag flag
const char * name
Definition fuchsia.cc:50
LayoutFlag
Definition SkSLLayout.h:20
SkEnumBitMask< SkSL::LayoutFlag > LayoutFlags
Definition SkSLLayout.h:68

◆ description()

std::string SkSL::Layout::description ( ) const

Definition at line 97 of file SkSLLayout.cpp.

97 {
98 std::string s = this->paddedDescription();
99 if (!s.empty()) {
100 s.pop_back();
101 }
102 return s;
103}
struct MyStruct s
std::string paddedDescription() const

◆ operator!=()

bool SkSL::Layout::operator!= ( const Layout other) const
inline

Definition at line 108 of file SkSLLayout.h.

108 {
109 return !(*this == other);
110 }

◆ operator==()

bool SkSL::Layout::operator== ( const Layout other) const

Definition at line 182 of file SkSLLayout.cpp.

182 {
183 return fFlags == other.fFlags &&
184 fLocation == other.fLocation &&
185 fOffset == other.fOffset &&
186 fBinding == other.fBinding &&
187 fTexture == other.fTexture &&
188 fSampler == other.fSampler &&
189 fIndex == other.fIndex &&
190 fSet == other.fSet &&
191 fBuiltin == other.fBuiltin &&
192 fInputAttachmentIndex == other.fInputAttachmentIndex &&
193 fLocalSizeX == other.fLocalSizeX &&
194 fLocalSizeY == other.fLocalSizeY &&
195 fLocalSizeZ == other.fLocalSizeZ;
196}

◆ paddedDescription()

std::string SkSL::Layout::paddedDescription ( ) const

Definition at line 19 of file SkSLLayout.cpp.

19 {
20 std::string result;
21 auto separator = SkSL::String::Separator();
23 result += separator() + "vulkan";
24 }
26 result += separator() + "metal";
27 }
29 result += separator() + "webgpu";
30 }
32 result += separator() + "direct3d";
33 }
35 result += separator() + "rgba8";
36 }
38 result += separator() + "rgba32f";
39 }
41 result += separator() + "r32f";
42 }
43 if (fLocation >= 0) {
44 result += separator() + "location = " + std::to_string(fLocation);
45 }
46 if (fOffset >= 0) {
47 result += separator() + "offset = " + std::to_string(fOffset);
48 }
49 if (fBinding >= 0) {
50 result += separator() + "binding = " + std::to_string(fBinding);
51 }
52 if (fTexture >= 0) {
53 result += separator() + "texture = " + std::to_string(fTexture);
54 }
55 if (fSampler >= 0) {
56 result += separator() + "sampler = " + std::to_string(fSampler);
57 }
58 if (fIndex >= 0) {
59 result += separator() + "index = " + std::to_string(fIndex);
60 }
61 if (fSet >= 0) {
62 result += separator() + "set = " + std::to_string(fSet);
63 }
64 if (fBuiltin >= 0) {
65 result += separator() + "builtin = " + std::to_string(fBuiltin);
66 }
67 if (fInputAttachmentIndex >= 0) {
68 result += separator() + "input_attachment_index = " + std::to_string(fInputAttachmentIndex);
69 }
71 result += separator() + "origin_upper_left";
72 }
74 result += separator() + "blend_support_all_equations";
75 }
77 result += separator() + "push_constant";
78 }
80 result += separator() + "color";
81 }
82 if (fLocalSizeX >= 0) {
83 result += separator() + "local_size_x = " + std::to_string(fLocalSizeX);
84 }
85 if (fLocalSizeY >= 0) {
86 result += separator() + "local_size_y = " + std::to_string(fLocalSizeY);
87 }
88 if (fLocalSizeZ >= 0) {
89 result += separator() + "local_size_z = " + std::to_string(fLocalSizeZ);
90 }
91 if (result.size() > 0) {
92 result = "layout (" + result + ") ";
93 }
94 return result;
95}
std::string void void auto Separator()
Definition SkSLString.h:30

Member Data Documentation

◆ fBinding

int SkSL::Layout::fBinding = -1

Definition at line 115 of file SkSLLayout.h.

◆ fBuiltin

int SkSL::Layout::fBuiltin = -1

Definition at line 122 of file SkSLLayout.h.

◆ fFlags

LayoutFlags SkSL::Layout::fFlags = LayoutFlag::kNone

Definition at line 112 of file SkSLLayout.h.

◆ fIndex

int SkSL::Layout::fIndex = -1

Definition at line 118 of file SkSLLayout.h.

◆ fInputAttachmentIndex

int SkSL::Layout::fInputAttachmentIndex = -1

Definition at line 125 of file SkSLLayout.h.

◆ fLocalSizeX

int SkSL::Layout::fLocalSizeX = -1

Definition at line 128 of file SkSLLayout.h.

◆ fLocalSizeY

int SkSL::Layout::fLocalSizeY = -1

Definition at line 129 of file SkSLLayout.h.

◆ fLocalSizeZ

int SkSL::Layout::fLocalSizeZ = -1

Definition at line 130 of file SkSLLayout.h.

◆ fLocation

int SkSL::Layout::fLocation = -1

Definition at line 113 of file SkSLLayout.h.

◆ fOffset

int SkSL::Layout::fOffset = -1

Definition at line 114 of file SkSLLayout.h.

◆ fSampler

int SkSL::Layout::fSampler = -1

Definition at line 117 of file SkSLLayout.h.

◆ fSet

int SkSL::Layout::fSet = -1

Definition at line 119 of file SkSLLayout.h.

◆ fTexture

int SkSL::Layout::fTexture = -1

Definition at line 116 of file SkSLLayout.h.


The documentation for this struct was generated from the following files: