blob: 7a6e1817585230b7f9f48c4cf0a9b8adf67346f7 [file] [log] [blame]
Jamie Madill6a729792014-07-18 10:33:14 -04001//
2// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
Jamie Madilla2ad4e82014-07-17 14:16:32 -04006// ShaderVars.cpp:
Jamie Madill6a729792014-07-18 10:33:14 -04007// Methods for GL variable types (varyings, uniforms, etc)
8//
9
Jamie Madille294bb82014-07-17 14:16:26 -040010#include <GLSLANG/ShaderLang.h>
Jamie Madill6a729792014-07-18 10:33:14 -040011
Olli Etuahod57e0db2015-04-24 15:05:08 +030012#include "common/debug.h"
Zhenyao Moed136362014-10-03 13:23:01 -070013
Jamie Madill6a729792014-07-18 10:33:14 -040014namespace sh
15{
16
Jamie Madille9cc4692015-02-19 16:00:13 -050017namespace
18{
19
20InterpolationType GetNonAuxiliaryInterpolationType(InterpolationType interpolation)
21{
22 return (interpolation == INTERPOLATION_CENTROID ? INTERPOLATION_SMOOTH : interpolation);
23}
Jamie Madille9cc4692015-02-19 16:00:13 -050024}
25// The ES 3.0 spec is not clear on this point, but the ES 3.1 spec, and discussion
26// on Khronos.org, clarifies that a smooth/flat mismatch produces a link error,
27// but auxiliary qualifier mismatch (centroid) does not.
28bool InterpolationTypesMatch(InterpolationType a, InterpolationType b)
29{
30 return (GetNonAuxiliaryInterpolationType(a) == GetNonAuxiliaryInterpolationType(b));
31}
32
Jamie Madilld7b1ab52016-12-12 14:42:19 -050033ShaderVariable::ShaderVariable() : type(0), precision(0), arraySize(0), staticUse(false)
34{
35}
Jamie Madill6a729792014-07-18 10:33:14 -040036
37ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn)
Jamie Madilld7b1ab52016-12-12 14:42:19 -050038 : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false)
39{
40}
Jamie Madill6a729792014-07-18 10:33:14 -040041
42ShaderVariable::~ShaderVariable()
Jamie Madilld7b1ab52016-12-12 14:42:19 -050043{
44}
Jamie Madill6a729792014-07-18 10:33:14 -040045
46ShaderVariable::ShaderVariable(const ShaderVariable &other)
47 : type(other.type),
48 precision(other.precision),
49 name(other.name),
50 mappedName(other.mappedName),
51 arraySize(other.arraySize),
Jamie Madill42bcf322014-08-25 16:20:46 -040052 staticUse(other.staticUse),
53 fields(other.fields),
54 structName(other.structName)
Jamie Madilld7b1ab52016-12-12 14:42:19 -050055{
56}
Jamie Madill6a729792014-07-18 10:33:14 -040057
58ShaderVariable &ShaderVariable::operator=(const ShaderVariable &other)
59{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050060 type = other.type;
61 precision = other.precision;
62 name = other.name;
Jamie Madill6a729792014-07-18 10:33:14 -040063 mappedName = other.mappedName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -050064 arraySize = other.arraySize;
65 staticUse = other.staticUse;
66 fields = other.fields;
Jamie Madill42bcf322014-08-25 16:20:46 -040067 structName = other.structName;
Jamie Madill6a729792014-07-18 10:33:14 -040068 return *this;
69}
70
Zhenyao Moed136362014-10-03 13:23:01 -070071bool ShaderVariable::operator==(const ShaderVariable &other) const
72{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050073 if (type != other.type || precision != other.precision || name != other.name ||
74 mappedName != other.mappedName || arraySize != other.arraySize ||
75 staticUse != other.staticUse || fields.size() != other.fields.size() ||
Zhenyao Moed136362014-10-03 13:23:01 -070076 structName != other.structName)
77 {
78 return false;
79 }
80 for (size_t ii = 0; ii < fields.size(); ++ii)
81 {
82 if (fields[ii] != other.fields[ii])
83 return false;
84 }
85 return true;
86}
87
Jamie Madilld7b1ab52016-12-12 14:42:19 -050088bool ShaderVariable::findInfoByMappedName(const std::string &mappedFullName,
89 const ShaderVariable **leafVar,
90 std::string *originalFullName) const
Zhenyao Moed136362014-10-03 13:23:01 -070091{
92 ASSERT(leafVar && originalFullName);
93 // There are three cases:
94 // 1) the top variable is of struct type;
95 // 2) the top variable is an array;
96 // 3) otherwise.
97 size_t pos = mappedFullName.find_first_of(".[");
Zhenyao Moed136362014-10-03 13:23:01 -070098
99 if (pos == std::string::npos)
100 {
101 // Case 3.
102 if (mappedFullName != this->mappedName)
103 return false;
104 *originalFullName = this->name;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500105 *leafVar = this;
Zhenyao Moed136362014-10-03 13:23:01 -0700106 return true;
107 }
108 else
109 {
110 std::string topName = mappedFullName.substr(0, pos);
111 if (topName != this->mappedName)
112 return false;
113 std::string originalName = this->name;
114 std::string remaining;
115 if (mappedFullName[pos] == '[')
116 {
117 // Case 2.
118 size_t closePos = mappedFullName.find_first_of(']');
119 if (closePos < pos || closePos == std::string::npos)
120 return false;
121 // Append '[index]'.
122 originalName += mappedFullName.substr(pos, closePos - pos + 1);
123 if (closePos + 1 == mappedFullName.size())
124 {
125 *originalFullName = originalName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500126 *leafVar = this;
Zhenyao Moed136362014-10-03 13:23:01 -0700127 return true;
128 }
129 else
130 {
131 // In the form of 'a[0].b', so after ']', '.' is expected.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500132 if (mappedFullName[closePos + 1] != '.')
Zhenyao Moed136362014-10-03 13:23:01 -0700133 return false;
134 remaining = mappedFullName.substr(closePos + 2); // Skip "]."
135 }
136 }
137 else
138 {
139 // Case 1.
140 remaining = mappedFullName.substr(pos + 1); // Skip "."
141 }
142 for (size_t ii = 0; ii < this->fields.size(); ++ii)
143 {
Yunchao Hed7297bf2017-04-19 15:27:10 +0800144 const ShaderVariable *fieldVar = nullptr;
Zhenyao Moed136362014-10-03 13:23:01 -0700145 std::string originalFieldName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500146 bool found = fields[ii].findInfoByMappedName(remaining, &fieldVar, &originalFieldName);
Zhenyao Moed136362014-10-03 13:23:01 -0700147 if (found)
148 {
149 *originalFullName = originalName + "." + originalFieldName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500150 *leafVar = fieldVar;
Zhenyao Moed136362014-10-03 13:23:01 -0700151 return true;
152 }
153 }
154 return false;
155 }
156}
157
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500158bool ShaderVariable::isSameVariableAtLinkTime(const ShaderVariable &other,
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800159 bool matchPrecision,
160 bool matchName) const
Zhenyao Moed136362014-10-03 13:23:01 -0700161{
162 if (type != other.type)
163 return false;
164 if (matchPrecision && precision != other.precision)
165 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800166 if (matchName && name != other.name)
Zhenyao Moed136362014-10-03 13:23:01 -0700167 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800168 ASSERT(!matchName || mappedName == other.mappedName);
Zhenyao Moed136362014-10-03 13:23:01 -0700169 if (arraySize != other.arraySize)
170 return false;
171 if (fields.size() != other.fields.size())
172 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800173
174 // [OpenGL ES 3.1 SPEC Chapter 7.4.1]
175 // Variables declared as structures are considered to match in type if and only if structure
176 // members match in name, type, qualification, and declaration order.
Zhenyao Moed136362014-10-03 13:23:01 -0700177 for (size_t ii = 0; ii < fields.size(); ++ii)
178 {
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800179 if (!fields[ii].isSameVariableAtLinkTime(other.fields[ii], matchPrecision, true))
Zhenyao Moed136362014-10-03 13:23:01 -0700180 {
181 return false;
182 }
183 }
184 if (structName != other.structName)
185 return false;
186 return true;
187}
188
jchen104cdac9e2017-05-08 11:01:20 +0800189Uniform::Uniform() : binding(-1), offset(-1)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500190{
191}
Jamie Madill6a729792014-07-18 10:33:14 -0400192
193Uniform::~Uniform()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500194{
195}
Jamie Madill6a729792014-07-18 10:33:14 -0400196
jchen104cdac9e2017-05-08 11:01:20 +0800197Uniform::Uniform(const Uniform &other)
198 : VariableWithLocation(other), binding(other.binding), offset(other.offset)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500199{
200}
Jamie Madill6a729792014-07-18 10:33:14 -0400201
202Uniform &Uniform::operator=(const Uniform &other)
203{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000204 VariableWithLocation::operator=(other);
Olli Etuaho547cbd42017-02-27 11:54:00 +0200205 binding = other.binding;
jchen104cdac9e2017-05-08 11:01:20 +0800206 offset = other.offset;
Jamie Madill6a729792014-07-18 10:33:14 -0400207 return *this;
208}
209
Zhenyao Moed136362014-10-03 13:23:01 -0700210bool Uniform::operator==(const Uniform &other) const
211{
jchen104cdac9e2017-05-08 11:01:20 +0800212 return VariableWithLocation::operator==(other) && binding == other.binding &&
213 offset == other.offset;
Zhenyao Moed136362014-10-03 13:23:01 -0700214}
215
216bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const
217{
jchen10eaef1e52017-06-13 10:44:11 +0800218 // Enforce a consistent match.
219 // https://cvs.khronos.org/bugzilla/show_bug.cgi?id=16261
220 if (binding != -1 && other.binding != -1 && binding != other.binding)
Olli Etuaho547cbd42017-02-27 11:54:00 +0200221 {
222 return false;
223 }
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000224 if (location != -1 && other.location != -1 && location != other.location)
225 {
226 return false;
227 }
jchen104cdac9e2017-05-08 11:01:20 +0800228 if (offset != other.offset)
229 {
230 return false;
231 }
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800232 return VariableWithLocation::isSameVariableAtLinkTime(other, true, true);
Zhenyao Moed136362014-10-03 13:23:01 -0700233}
234
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000235VariableWithLocation::VariableWithLocation() : location(-1)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500236{
237}
Jamie Madill6a729792014-07-18 10:33:14 -0400238
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000239VariableWithLocation::~VariableWithLocation()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500240{
241}
Jamie Madill6a729792014-07-18 10:33:14 -0400242
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000243VariableWithLocation::VariableWithLocation(const VariableWithLocation &other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400244 : ShaderVariable(other), location(other.location)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500245{
246}
Jamie Madill6a729792014-07-18 10:33:14 -0400247
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000248VariableWithLocation &VariableWithLocation::operator=(const VariableWithLocation &other)
Jamie Madill6a729792014-07-18 10:33:14 -0400249{
250 ShaderVariable::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500251 location = other.location;
Jamie Madill6a729792014-07-18 10:33:14 -0400252 return *this;
253}
254
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000255bool VariableWithLocation::operator==(const VariableWithLocation &other) const
Zhenyao Moed136362014-10-03 13:23:01 -0700256{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500257 return (ShaderVariable::operator==(other) && location == other.location);
Zhenyao Moed136362014-10-03 13:23:01 -0700258}
259
Jamie Madilla0a9e122015-09-02 15:54:30 -0400260Attribute::Attribute()
261{
262}
263
264Attribute::~Attribute()
265{
266}
267
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000268Attribute::Attribute(const Attribute &other) : VariableWithLocation(other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400269{
270}
271
272Attribute &Attribute::operator=(const Attribute &other)
273{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000274 VariableWithLocation::operator=(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400275 return *this;
276}
277
278bool Attribute::operator==(const Attribute &other) const
279{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000280 return VariableWithLocation::operator==(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400281}
282
283OutputVariable::OutputVariable()
284{
285}
286
287OutputVariable::~OutputVariable()
288{
289}
290
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000291OutputVariable::OutputVariable(const OutputVariable &other) : VariableWithLocation(other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400292{
293}
294
295OutputVariable &OutputVariable::operator=(const OutputVariable &other)
296{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000297 VariableWithLocation::operator=(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400298 return *this;
299}
300
301bool OutputVariable::operator==(const OutputVariable &other) const
302{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000303 return VariableWithLocation::operator==(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400304}
305
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500306InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false)
307{
308}
Jamie Madill6a729792014-07-18 10:33:14 -0400309
310InterfaceBlockField::~InterfaceBlockField()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500311{
312}
Jamie Madill6a729792014-07-18 10:33:14 -0400313
314InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500315 : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout)
316{
317}
Jamie Madill6a729792014-07-18 10:33:14 -0400318
319InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other)
320{
321 ShaderVariable::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500322 isRowMajorLayout = other.isRowMajorLayout;
Jamie Madill6a729792014-07-18 10:33:14 -0400323 return *this;
324}
325
Zhenyao Moed136362014-10-03 13:23:01 -0700326bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const
327{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500328 return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout);
Zhenyao Moed136362014-10-03 13:23:01 -0700329}
330
331bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime(
332 const InterfaceBlockField &other) const
333{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800334 return (ShaderVariable::isSameVariableAtLinkTime(other, true, true) &&
Zhenyao Moed136362014-10-03 13:23:01 -0700335 isRowMajorLayout == other.isRowMajorLayout);
336}
337
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500338Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false)
339{
340}
Jamie Madill6a729792014-07-18 10:33:14 -0400341
342Varying::~Varying()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500343{
344}
Jamie Madill6a729792014-07-18 10:33:14 -0400345
346Varying::Varying(const Varying &other)
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800347 : VariableWithLocation(other),
348 interpolation(other.interpolation),
349 isInvariant(other.isInvariant)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500350{
351}
Jamie Madill6a729792014-07-18 10:33:14 -0400352
353Varying &Varying::operator=(const Varying &other)
354{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800355 VariableWithLocation::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500356 interpolation = other.interpolation;
357 isInvariant = other.isInvariant;
Jamie Madill6a729792014-07-18 10:33:14 -0400358 return *this;
359}
360
Zhenyao Moed136362014-10-03 13:23:01 -0700361bool Varying::operator==(const Varying &other) const
362{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800363 return (VariableWithLocation::operator==(other) && interpolation == other.interpolation &&
Zhenyao Moed136362014-10-03 13:23:01 -0700364 isInvariant == other.isInvariant);
365}
366
Jamie Madill9e64edc2015-05-07 14:08:06 +0000367bool Varying::isSameVaryingAtLinkTime(const Varying &other) const
Zhenyao Moed136362014-10-03 13:23:01 -0700368{
Olli Etuaho37ad4742015-04-27 13:18:50 +0300369 return isSameVaryingAtLinkTime(other, 100);
370}
371
372bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const
373{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800374 return (ShaderVariable::isSameVariableAtLinkTime(other, false, false) &&
Corentin Wallez84954982016-07-12 15:42:18 -0400375 InterpolationTypesMatch(interpolation, other.interpolation) &&
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800376 (shaderVersion >= 300 || isInvariant == other.isInvariant) &&
377 (location == other.location) &&
378 (name == other.name || (shaderVersion >= 310 && location >= 0)));
Zhenyao Moed136362014-10-03 13:23:01 -0700379}
380
Jamie Madill6a729792014-07-18 10:33:14 -0400381InterfaceBlock::InterfaceBlock()
jchen10af713a22017-04-19 09:10:56 +0800382 : arraySize(0),
383 layout(BLOCKLAYOUT_PACKED),
384 isRowMajorLayout(false),
385 binding(-1),
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800386 staticUse(false),
387 blockType(BlockType::BLOCK_UNIFORM)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500388{
389}
Jamie Madill6a729792014-07-18 10:33:14 -0400390
391InterfaceBlock::~InterfaceBlock()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500392{
393}
Jamie Madill6a729792014-07-18 10:33:14 -0400394
395InterfaceBlock::InterfaceBlock(const InterfaceBlock &other)
396 : name(other.name),
397 mappedName(other.mappedName),
Jamie Madill42bcf322014-08-25 16:20:46 -0400398 instanceName(other.instanceName),
Jamie Madill6a729792014-07-18 10:33:14 -0400399 arraySize(other.arraySize),
400 layout(other.layout),
401 isRowMajorLayout(other.isRowMajorLayout),
jchen10af713a22017-04-19 09:10:56 +0800402 binding(other.binding),
Jamie Madill6a729792014-07-18 10:33:14 -0400403 staticUse(other.staticUse),
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800404 blockType(other.blockType),
Jamie Madill6a729792014-07-18 10:33:14 -0400405 fields(other.fields)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500406{
407}
Jamie Madill6a729792014-07-18 10:33:14 -0400408
409InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other)
410{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500411 name = other.name;
412 mappedName = other.mappedName;
413 instanceName = other.instanceName;
414 arraySize = other.arraySize;
415 layout = other.layout;
Jamie Madill6a729792014-07-18 10:33:14 -0400416 isRowMajorLayout = other.isRowMajorLayout;
jchen10af713a22017-04-19 09:10:56 +0800417 binding = other.binding;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500418 staticUse = other.staticUse;
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800419 blockType = other.blockType;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500420 fields = other.fields;
Jamie Madill6a729792014-07-18 10:33:14 -0400421 return *this;
422}
423
Jamie Madill39046162016-02-08 15:05:17 -0500424std::string InterfaceBlock::fieldPrefix() const
425{
426 return instanceName.empty() ? "" : name;
Jamie Madill6a729792014-07-18 10:33:14 -0400427}
Jamie Madill39046162016-02-08 15:05:17 -0500428
Olli Etuaho855d9642017-05-17 14:05:06 +0300429std::string InterfaceBlock::fieldMappedPrefix() const
430{
431 return instanceName.empty() ? "" : mappedName;
432}
433
Corentin Wallez84954982016-07-12 15:42:18 -0400434bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const
435{
436 if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize ||
437 layout != other.layout || isRowMajorLayout != other.isRowMajorLayout ||
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800438 binding != other.binding || blockType != other.blockType ||
439 fields.size() != other.fields.size())
Corentin Wallez84954982016-07-12 15:42:18 -0400440 {
441 return false;
442 }
443
444 for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex)
445 {
446 if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex]))
447 {
448 return false;
449 }
450 }
451
452 return true;
453}
454
Martin Radev4c4c8e72016-08-04 12:25:34 +0300455void WorkGroupSize::fill(int fillValue)
456{
457 localSizeQualifiers[0] = fillValue;
458 localSizeQualifiers[1] = fillValue;
459 localSizeQualifiers[2] = fillValue;
460}
461
462void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ)
463{
464 localSizeQualifiers[0] = localSizeX;
465 localSizeQualifiers[1] = localSizeY;
466 localSizeQualifiers[2] = localSizeZ;
467}
468
469// check that if one of them is less than 1, then all of them are.
470// Or if one is positive, then all of them are positive.
471bool WorkGroupSize::isLocalSizeValid() const
472{
473 return (
474 (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) ||
475 (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0));
476}
477
478bool WorkGroupSize::isAnyValueSet() const
479{
480 return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0;
481}
482
483bool WorkGroupSize::isDeclared() const
484{
485 bool localSizeDeclared = localSizeQualifiers[0] > 0;
486 ASSERT(isLocalSizeValid());
487 return localSizeDeclared;
488}
489
490bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const
491{
492 for (size_t i = 0u; i < size(); ++i)
493 {
494 bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] ||
495 (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) ||
496 (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1));
497 if (!result)
498 {
499 return false;
500 }
501 }
502 return true;
503}
504
505int &WorkGroupSize::operator[](size_t index)
506{
507 ASSERT(index < size());
508 return localSizeQualifiers[index];
509}
510
511int WorkGroupSize::operator[](size_t index) const
512{
513 ASSERT(index < size());
514 return localSizeQualifiers[index];
515}
516
517size_t WorkGroupSize::size() const
518{
519 return 3u;
520}
521
Jamie Madill39046162016-02-08 15:05:17 -0500522} // namespace sh