blob: d51ca5b4c08b3225fdd02605eee84682186bfda9 [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
Olli Etuahoe7c28572017-10-23 16:29:33 +030037ShaderVariable::ShaderVariable(GLenum typeIn)
38 : type(typeIn), precision(0), arraySize(0), staticUse(false)
39{
40}
41
Jamie Madill6a729792014-07-18 10:33:14 -040042ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn)
Jamie Madilld7b1ab52016-12-12 14:42:19 -050043 : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false)
44{
Olli Etuahoe7c28572017-10-23 16:29:33 +030045 ASSERT(arraySizeIn != 0);
Jamie Madilld7b1ab52016-12-12 14:42:19 -050046}
Jamie Madill6a729792014-07-18 10:33:14 -040047
48ShaderVariable::~ShaderVariable()
Jamie Madilld7b1ab52016-12-12 14:42:19 -050049{
50}
Jamie Madill6a729792014-07-18 10:33:14 -040051
52ShaderVariable::ShaderVariable(const ShaderVariable &other)
53 : type(other.type),
54 precision(other.precision),
55 name(other.name),
56 mappedName(other.mappedName),
57 arraySize(other.arraySize),
Jamie Madill42bcf322014-08-25 16:20:46 -040058 staticUse(other.staticUse),
59 fields(other.fields),
60 structName(other.structName)
Jamie Madilld7b1ab52016-12-12 14:42:19 -050061{
62}
Jamie Madill6a729792014-07-18 10:33:14 -040063
64ShaderVariable &ShaderVariable::operator=(const ShaderVariable &other)
65{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050066 type = other.type;
67 precision = other.precision;
68 name = other.name;
Jamie Madill6a729792014-07-18 10:33:14 -040069 mappedName = other.mappedName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -050070 arraySize = other.arraySize;
71 staticUse = other.staticUse;
72 fields = other.fields;
Jamie Madill42bcf322014-08-25 16:20:46 -040073 structName = other.structName;
Jamie Madill6a729792014-07-18 10:33:14 -040074 return *this;
75}
76
Zhenyao Moed136362014-10-03 13:23:01 -070077bool ShaderVariable::operator==(const ShaderVariable &other) const
78{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050079 if (type != other.type || precision != other.precision || name != other.name ||
80 mappedName != other.mappedName || arraySize != other.arraySize ||
81 staticUse != other.staticUse || fields.size() != other.fields.size() ||
Zhenyao Moed136362014-10-03 13:23:01 -070082 structName != other.structName)
83 {
84 return false;
85 }
86 for (size_t ii = 0; ii < fields.size(); ++ii)
87 {
88 if (fields[ii] != other.fields[ii])
89 return false;
90 }
91 return true;
92}
93
Jamie Madilld7b1ab52016-12-12 14:42:19 -050094bool ShaderVariable::findInfoByMappedName(const std::string &mappedFullName,
95 const ShaderVariable **leafVar,
96 std::string *originalFullName) const
Zhenyao Moed136362014-10-03 13:23:01 -070097{
98 ASSERT(leafVar && originalFullName);
99 // There are three cases:
100 // 1) the top variable is of struct type;
101 // 2) the top variable is an array;
102 // 3) otherwise.
103 size_t pos = mappedFullName.find_first_of(".[");
Zhenyao Moed136362014-10-03 13:23:01 -0700104
105 if (pos == std::string::npos)
106 {
107 // Case 3.
108 if (mappedFullName != this->mappedName)
109 return false;
110 *originalFullName = this->name;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500111 *leafVar = this;
Zhenyao Moed136362014-10-03 13:23:01 -0700112 return true;
113 }
114 else
115 {
116 std::string topName = mappedFullName.substr(0, pos);
117 if (topName != this->mappedName)
118 return false;
119 std::string originalName = this->name;
120 std::string remaining;
121 if (mappedFullName[pos] == '[')
122 {
123 // Case 2.
124 size_t closePos = mappedFullName.find_first_of(']');
125 if (closePos < pos || closePos == std::string::npos)
126 return false;
127 // Append '[index]'.
128 originalName += mappedFullName.substr(pos, closePos - pos + 1);
129 if (closePos + 1 == mappedFullName.size())
130 {
131 *originalFullName = originalName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500132 *leafVar = this;
Zhenyao Moed136362014-10-03 13:23:01 -0700133 return true;
134 }
135 else
136 {
137 // In the form of 'a[0].b', so after ']', '.' is expected.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500138 if (mappedFullName[closePos + 1] != '.')
Zhenyao Moed136362014-10-03 13:23:01 -0700139 return false;
140 remaining = mappedFullName.substr(closePos + 2); // Skip "]."
141 }
142 }
143 else
144 {
145 // Case 1.
146 remaining = mappedFullName.substr(pos + 1); // Skip "."
147 }
148 for (size_t ii = 0; ii < this->fields.size(); ++ii)
149 {
Yunchao Hed7297bf2017-04-19 15:27:10 +0800150 const ShaderVariable *fieldVar = nullptr;
Zhenyao Moed136362014-10-03 13:23:01 -0700151 std::string originalFieldName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500152 bool found = fields[ii].findInfoByMappedName(remaining, &fieldVar, &originalFieldName);
Zhenyao Moed136362014-10-03 13:23:01 -0700153 if (found)
154 {
155 *originalFullName = originalName + "." + originalFieldName;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500156 *leafVar = fieldVar;
Zhenyao Moed136362014-10-03 13:23:01 -0700157 return true;
158 }
159 }
160 return false;
161 }
162}
163
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500164bool ShaderVariable::isSameVariableAtLinkTime(const ShaderVariable &other,
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800165 bool matchPrecision,
166 bool matchName) const
Zhenyao Moed136362014-10-03 13:23:01 -0700167{
168 if (type != other.type)
169 return false;
170 if (matchPrecision && precision != other.precision)
171 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800172 if (matchName && name != other.name)
Zhenyao Moed136362014-10-03 13:23:01 -0700173 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800174 ASSERT(!matchName || mappedName == other.mappedName);
Zhenyao Moed136362014-10-03 13:23:01 -0700175 if (arraySize != other.arraySize)
176 return false;
177 if (fields.size() != other.fields.size())
178 return false;
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800179
180 // [OpenGL ES 3.1 SPEC Chapter 7.4.1]
181 // Variables declared as structures are considered to match in type if and only if structure
182 // members match in name, type, qualification, and declaration order.
Zhenyao Moed136362014-10-03 13:23:01 -0700183 for (size_t ii = 0; ii < fields.size(); ++ii)
184 {
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800185 if (!fields[ii].isSameVariableAtLinkTime(other.fields[ii], matchPrecision, true))
Zhenyao Moed136362014-10-03 13:23:01 -0700186 {
187 return false;
188 }
189 }
190 if (structName != other.structName)
191 return false;
192 return true;
193}
194
jchen104cdac9e2017-05-08 11:01:20 +0800195Uniform::Uniform() : binding(-1), offset(-1)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500196{
197}
Jamie Madill6a729792014-07-18 10:33:14 -0400198
199Uniform::~Uniform()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500200{
201}
Jamie Madill6a729792014-07-18 10:33:14 -0400202
jchen104cdac9e2017-05-08 11:01:20 +0800203Uniform::Uniform(const Uniform &other)
204 : VariableWithLocation(other), binding(other.binding), offset(other.offset)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500205{
206}
Jamie Madill6a729792014-07-18 10:33:14 -0400207
208Uniform &Uniform::operator=(const Uniform &other)
209{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000210 VariableWithLocation::operator=(other);
Olli Etuaho547cbd42017-02-27 11:54:00 +0200211 binding = other.binding;
jchen104cdac9e2017-05-08 11:01:20 +0800212 offset = other.offset;
Jamie Madill6a729792014-07-18 10:33:14 -0400213 return *this;
214}
215
Zhenyao Moed136362014-10-03 13:23:01 -0700216bool Uniform::operator==(const Uniform &other) const
217{
jchen104cdac9e2017-05-08 11:01:20 +0800218 return VariableWithLocation::operator==(other) && binding == other.binding &&
219 offset == other.offset;
Zhenyao Moed136362014-10-03 13:23:01 -0700220}
221
222bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const
223{
jchen10eaef1e52017-06-13 10:44:11 +0800224 // Enforce a consistent match.
225 // https://cvs.khronos.org/bugzilla/show_bug.cgi?id=16261
226 if (binding != -1 && other.binding != -1 && binding != other.binding)
Olli Etuaho547cbd42017-02-27 11:54:00 +0200227 {
228 return false;
229 }
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000230 if (location != -1 && other.location != -1 && location != other.location)
231 {
232 return false;
233 }
jchen104cdac9e2017-05-08 11:01:20 +0800234 if (offset != other.offset)
235 {
236 return false;
237 }
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800238 return VariableWithLocation::isSameVariableAtLinkTime(other, true, true);
Zhenyao Moed136362014-10-03 13:23:01 -0700239}
240
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000241VariableWithLocation::VariableWithLocation() : location(-1)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500242{
243}
Jamie Madill6a729792014-07-18 10:33:14 -0400244
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000245VariableWithLocation::~VariableWithLocation()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500246{
247}
Jamie Madill6a729792014-07-18 10:33:14 -0400248
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000249VariableWithLocation::VariableWithLocation(const VariableWithLocation &other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400250 : ShaderVariable(other), location(other.location)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500251{
252}
Jamie Madill6a729792014-07-18 10:33:14 -0400253
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000254VariableWithLocation &VariableWithLocation::operator=(const VariableWithLocation &other)
Jamie Madill6a729792014-07-18 10:33:14 -0400255{
256 ShaderVariable::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500257 location = other.location;
Jamie Madill6a729792014-07-18 10:33:14 -0400258 return *this;
259}
260
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000261bool VariableWithLocation::operator==(const VariableWithLocation &other) const
Zhenyao Moed136362014-10-03 13:23:01 -0700262{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500263 return (ShaderVariable::operator==(other) && location == other.location);
Zhenyao Moed136362014-10-03 13:23:01 -0700264}
265
Jamie Madilla0a9e122015-09-02 15:54:30 -0400266Attribute::Attribute()
267{
268}
269
270Attribute::~Attribute()
271{
272}
273
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000274Attribute::Attribute(const Attribute &other) : VariableWithLocation(other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400275{
276}
277
278Attribute &Attribute::operator=(const Attribute &other)
279{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000280 VariableWithLocation::operator=(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400281 return *this;
282}
283
284bool Attribute::operator==(const Attribute &other) const
285{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000286 return VariableWithLocation::operator==(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400287}
288
289OutputVariable::OutputVariable()
290{
291}
292
293OutputVariable::~OutputVariable()
294{
295}
296
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000297OutputVariable::OutputVariable(const OutputVariable &other) : VariableWithLocation(other)
Jamie Madilla0a9e122015-09-02 15:54:30 -0400298{
299}
300
301OutputVariable &OutputVariable::operator=(const OutputVariable &other)
302{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000303 VariableWithLocation::operator=(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400304 return *this;
305}
306
307bool OutputVariable::operator==(const OutputVariable &other) const
308{
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000309 return VariableWithLocation::operator==(other);
Jamie Madilla0a9e122015-09-02 15:54:30 -0400310}
311
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500312InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false)
313{
314}
Jamie Madill6a729792014-07-18 10:33:14 -0400315
316InterfaceBlockField::~InterfaceBlockField()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500317{
318}
Jamie Madill6a729792014-07-18 10:33:14 -0400319
320InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500321 : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout)
322{
323}
Jamie Madill6a729792014-07-18 10:33:14 -0400324
325InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other)
326{
327 ShaderVariable::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500328 isRowMajorLayout = other.isRowMajorLayout;
Jamie Madill6a729792014-07-18 10:33:14 -0400329 return *this;
330}
331
Zhenyao Moed136362014-10-03 13:23:01 -0700332bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const
333{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500334 return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout);
Zhenyao Moed136362014-10-03 13:23:01 -0700335}
336
337bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime(
338 const InterfaceBlockField &other) const
339{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800340 return (ShaderVariable::isSameVariableAtLinkTime(other, true, true) &&
Zhenyao Moed136362014-10-03 13:23:01 -0700341 isRowMajorLayout == other.isRowMajorLayout);
342}
343
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500344Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false)
345{
346}
Jamie Madill6a729792014-07-18 10:33:14 -0400347
348Varying::~Varying()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500349{
350}
Jamie Madill6a729792014-07-18 10:33:14 -0400351
352Varying::Varying(const Varying &other)
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800353 : VariableWithLocation(other),
354 interpolation(other.interpolation),
355 isInvariant(other.isInvariant)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500356{
357}
Jamie Madill6a729792014-07-18 10:33:14 -0400358
359Varying &Varying::operator=(const Varying &other)
360{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800361 VariableWithLocation::operator=(other);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500362 interpolation = other.interpolation;
363 isInvariant = other.isInvariant;
Jamie Madill6a729792014-07-18 10:33:14 -0400364 return *this;
365}
366
Zhenyao Moed136362014-10-03 13:23:01 -0700367bool Varying::operator==(const Varying &other) const
368{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800369 return (VariableWithLocation::operator==(other) && interpolation == other.interpolation &&
Zhenyao Moed136362014-10-03 13:23:01 -0700370 isInvariant == other.isInvariant);
371}
372
Jamie Madill9e64edc2015-05-07 14:08:06 +0000373bool Varying::isSameVaryingAtLinkTime(const Varying &other) const
Zhenyao Moed136362014-10-03 13:23:01 -0700374{
Olli Etuaho37ad4742015-04-27 13:18:50 +0300375 return isSameVaryingAtLinkTime(other, 100);
376}
377
378bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const
379{
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800380 return (ShaderVariable::isSameVariableAtLinkTime(other, false, false) &&
Corentin Wallez84954982016-07-12 15:42:18 -0400381 InterpolationTypesMatch(interpolation, other.interpolation) &&
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800382 (shaderVersion >= 300 || isInvariant == other.isInvariant) &&
383 (location == other.location) &&
384 (name == other.name || (shaderVersion >= 310 && location >= 0)));
Zhenyao Moed136362014-10-03 13:23:01 -0700385}
386
Jamie Madill6a729792014-07-18 10:33:14 -0400387InterfaceBlock::InterfaceBlock()
jchen10af713a22017-04-19 09:10:56 +0800388 : arraySize(0),
389 layout(BLOCKLAYOUT_PACKED),
390 isRowMajorLayout(false),
391 binding(-1),
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800392 staticUse(false),
393 blockType(BlockType::BLOCK_UNIFORM)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500394{
395}
Jamie Madill6a729792014-07-18 10:33:14 -0400396
397InterfaceBlock::~InterfaceBlock()
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500398{
399}
Jamie Madill6a729792014-07-18 10:33:14 -0400400
401InterfaceBlock::InterfaceBlock(const InterfaceBlock &other)
402 : name(other.name),
403 mappedName(other.mappedName),
Jamie Madill42bcf322014-08-25 16:20:46 -0400404 instanceName(other.instanceName),
Jamie Madill6a729792014-07-18 10:33:14 -0400405 arraySize(other.arraySize),
406 layout(other.layout),
407 isRowMajorLayout(other.isRowMajorLayout),
jchen10af713a22017-04-19 09:10:56 +0800408 binding(other.binding),
Jamie Madill6a729792014-07-18 10:33:14 -0400409 staticUse(other.staticUse),
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800410 blockType(other.blockType),
Jamie Madill6a729792014-07-18 10:33:14 -0400411 fields(other.fields)
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500412{
413}
Jamie Madill6a729792014-07-18 10:33:14 -0400414
415InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other)
416{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500417 name = other.name;
418 mappedName = other.mappedName;
419 instanceName = other.instanceName;
420 arraySize = other.arraySize;
421 layout = other.layout;
Jamie Madill6a729792014-07-18 10:33:14 -0400422 isRowMajorLayout = other.isRowMajorLayout;
jchen10af713a22017-04-19 09:10:56 +0800423 binding = other.binding;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500424 staticUse = other.staticUse;
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800425 blockType = other.blockType;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500426 fields = other.fields;
Jamie Madill6a729792014-07-18 10:33:14 -0400427 return *this;
428}
429
Jamie Madill39046162016-02-08 15:05:17 -0500430std::string InterfaceBlock::fieldPrefix() const
431{
432 return instanceName.empty() ? "" : name;
Jamie Madill6a729792014-07-18 10:33:14 -0400433}
Jamie Madill39046162016-02-08 15:05:17 -0500434
Olli Etuaho855d9642017-05-17 14:05:06 +0300435std::string InterfaceBlock::fieldMappedPrefix() const
436{
437 return instanceName.empty() ? "" : mappedName;
438}
439
Corentin Wallez84954982016-07-12 15:42:18 -0400440bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const
441{
442 if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize ||
443 layout != other.layout || isRowMajorLayout != other.isRowMajorLayout ||
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800444 binding != other.binding || blockType != other.blockType ||
445 fields.size() != other.fields.size())
Corentin Wallez84954982016-07-12 15:42:18 -0400446 {
447 return false;
448 }
449
450 for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex)
451 {
452 if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex]))
453 {
454 return false;
455 }
456 }
457
458 return true;
459}
460
Martin Radev4c4c8e72016-08-04 12:25:34 +0300461void WorkGroupSize::fill(int fillValue)
462{
463 localSizeQualifiers[0] = fillValue;
464 localSizeQualifiers[1] = fillValue;
465 localSizeQualifiers[2] = fillValue;
466}
467
468void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ)
469{
470 localSizeQualifiers[0] = localSizeX;
471 localSizeQualifiers[1] = localSizeY;
472 localSizeQualifiers[2] = localSizeZ;
473}
474
475// check that if one of them is less than 1, then all of them are.
476// Or if one is positive, then all of them are positive.
477bool WorkGroupSize::isLocalSizeValid() const
478{
479 return (
480 (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) ||
481 (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0));
482}
483
484bool WorkGroupSize::isAnyValueSet() const
485{
486 return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0;
487}
488
489bool WorkGroupSize::isDeclared() const
490{
491 bool localSizeDeclared = localSizeQualifiers[0] > 0;
492 ASSERT(isLocalSizeValid());
493 return localSizeDeclared;
494}
495
496bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const
497{
498 for (size_t i = 0u; i < size(); ++i)
499 {
500 bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] ||
501 (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) ||
502 (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1));
503 if (!result)
504 {
505 return false;
506 }
507 }
508 return true;
509}
510
511int &WorkGroupSize::operator[](size_t index)
512{
513 ASSERT(index < size());
514 return localSizeQualifiers[index];
515}
516
517int WorkGroupSize::operator[](size_t index) const
518{
519 ASSERT(index < size());
520 return localSizeQualifiers[index];
521}
522
523size_t WorkGroupSize::size() const
524{
525 return 3u;
526}
527
Jamie Madill39046162016-02-08 15:05:17 -0500528} // namespace sh