blob: bef61ae3ff257f9c0b2461438df9009fbcb16acd [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// utilities.cpp: Conversion functions and other utility routines.
8
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +00009#include "common/utilities.h"
jchen108225e732017-11-14 16:29:03 +080010#include <GLSLANG/ShaderVars.h>
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000011#include "common/mathutil.h"
Geoff Lang44fa7592014-05-30 11:50:07 -040012#include "common/platform.h"
Geoff Lang83217792014-01-16 09:52:38 -050013
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000014#include <set>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
Cooper Partin88d3b8c2014-10-08 10:41:56 -070016#if defined(ANGLE_ENABLE_WINDOWS_STORE)
Jamie Madill493f9572018-05-24 19:52:15 -040017#include <windows.applicationmodel.core.h>
18#include <windows.graphics.display.h>
19#include <wrl.h>
20#include <wrl/wrappers/corewrappers.h>
Cooper Partin88d3b8c2014-10-08 10:41:56 -070021#endif
22
Geoff Lang3edfe032015-09-04 16:38:24 -040023namespace
24{
25
26template <class IndexType>
27gl::IndexRange ComputeTypedIndexRange(const IndexType *indices,
28 size_t count,
29 bool primitiveRestartEnabled,
30 GLuint primitiveRestartIndex)
31{
32 ASSERT(count > 0);
33
34 IndexType minIndex = 0;
35 IndexType maxIndex = 0;
36 size_t nonPrimitiveRestartIndices = 0;
37
38 if (primitiveRestartEnabled)
39 {
40 // Find the first non-primitive restart index to initialize the min and max values
41 size_t i = 0;
42 for (; i < count; i++)
43 {
44 if (indices[i] != primitiveRestartIndex)
45 {
46 minIndex = indices[i];
47 maxIndex = indices[i];
48 nonPrimitiveRestartIndices++;
49 break;
50 }
51 }
52
53 // Loop over the rest of the indices
54 for (; i < count; i++)
55 {
56 if (indices[i] != primitiveRestartIndex)
57 {
58 if (minIndex > indices[i])
59 {
60 minIndex = indices[i];
61 }
62 if (maxIndex < indices[i])
63 {
64 maxIndex = indices[i];
65 }
66 nonPrimitiveRestartIndices++;
67 }
68 }
69 }
70 else
71 {
72 minIndex = indices[0];
73 maxIndex = indices[0];
74 nonPrimitiveRestartIndices = count;
75
76 for (size_t i = 1; i < count; i++)
77 {
78 if (minIndex > indices[i])
79 {
80 minIndex = indices[i];
81 }
82 if (maxIndex < indices[i])
83 {
84 maxIndex = indices[i];
85 }
86 }
87 }
88
89 return gl::IndexRange(static_cast<size_t>(minIndex), static_cast<size_t>(maxIndex),
90 nonPrimitiveRestartIndices);
91}
92
93} // anonymous namespace
94
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +000095namespace gl
96{
97
Jamie Madillf2575982014-06-25 16:04:54 -040098int VariableComponentCount(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +000099{
Jamie Madillaa72d782014-07-02 15:31:19 -0400100 return VariableRowCount(type) * VariableColumnCount(type);
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000101}
102
Jamie Madillf2575982014-06-25 16:04:54 -0400103GLenum VariableComponentType(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000104{
Jamie Madill493f9572018-05-24 19:52:15 -0400105 switch (type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000106 {
Jamie Madill493f9572018-05-24 19:52:15 -0400107 case GL_BOOL:
108 case GL_BOOL_VEC2:
109 case GL_BOOL_VEC3:
110 case GL_BOOL_VEC4:
111 return GL_BOOL;
112 case GL_FLOAT:
113 case GL_FLOAT_VEC2:
114 case GL_FLOAT_VEC3:
115 case GL_FLOAT_VEC4:
116 case GL_FLOAT_MAT2:
117 case GL_FLOAT_MAT3:
118 case GL_FLOAT_MAT4:
119 case GL_FLOAT_MAT2x3:
120 case GL_FLOAT_MAT3x2:
121 case GL_FLOAT_MAT2x4:
122 case GL_FLOAT_MAT4x2:
123 case GL_FLOAT_MAT3x4:
124 case GL_FLOAT_MAT4x3:
125 return GL_FLOAT;
126 case GL_INT:
127 case GL_SAMPLER_2D:
128 case GL_SAMPLER_2D_RECT_ANGLE:
129 case GL_SAMPLER_3D:
130 case GL_SAMPLER_CUBE:
131 case GL_SAMPLER_2D_ARRAY:
132 case GL_SAMPLER_EXTERNAL_OES:
133 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300134 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400135 case GL_INT_SAMPLER_2D:
136 case GL_INT_SAMPLER_3D:
137 case GL_INT_SAMPLER_CUBE:
138 case GL_INT_SAMPLER_2D_ARRAY:
139 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300140 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400141 case GL_UNSIGNED_INT_SAMPLER_2D:
142 case GL_UNSIGNED_INT_SAMPLER_3D:
143 case GL_UNSIGNED_INT_SAMPLER_CUBE:
144 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
145 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300146 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400147 case GL_SAMPLER_2D_SHADOW:
148 case GL_SAMPLER_CUBE_SHADOW:
149 case GL_SAMPLER_2D_ARRAY_SHADOW:
150 case GL_INT_VEC2:
151 case GL_INT_VEC3:
152 case GL_INT_VEC4:
153 case GL_IMAGE_2D:
154 case GL_INT_IMAGE_2D:
155 case GL_UNSIGNED_INT_IMAGE_2D:
156 case GL_IMAGE_3D:
157 case GL_INT_IMAGE_3D:
158 case GL_UNSIGNED_INT_IMAGE_3D:
159 case GL_IMAGE_2D_ARRAY:
160 case GL_INT_IMAGE_2D_ARRAY:
161 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
162 case GL_IMAGE_CUBE:
163 case GL_INT_IMAGE_CUBE:
164 case GL_UNSIGNED_INT_IMAGE_CUBE:
165 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
166 return GL_INT;
167 case GL_UNSIGNED_INT:
168 case GL_UNSIGNED_INT_VEC2:
169 case GL_UNSIGNED_INT_VEC3:
170 case GL_UNSIGNED_INT_VEC4:
171 return GL_UNSIGNED_INT;
172 default:
173 UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000174 }
175
176 return GL_NONE;
177}
178
Jamie Madillf2575982014-06-25 16:04:54 -0400179size_t VariableComponentSize(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000180{
Jamie Madill493f9572018-05-24 19:52:15 -0400181 switch (type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000182 {
Jamie Madill493f9572018-05-24 19:52:15 -0400183 case GL_BOOL:
184 return sizeof(GLint);
185 case GL_FLOAT:
186 return sizeof(GLfloat);
187 case GL_INT:
188 return sizeof(GLint);
189 case GL_UNSIGNED_INT:
190 return sizeof(GLuint);
191 default:
192 UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000193 }
194
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000195 return 0;
196}
197
Jamie Madillf2575982014-06-25 16:04:54 -0400198size_t VariableInternalSize(GLenum type)
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000199{
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +0000200 // Expanded to 4-element vectors
Jamie Madillf2575982014-06-25 16:04:54 -0400201 return VariableComponentSize(VariableComponentType(type)) * VariableRowCount(type) * 4;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000202}
203
Jamie Madillf2575982014-06-25 16:04:54 -0400204size_t VariableExternalSize(GLenum type)
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000205{
Jamie Madillf2575982014-06-25 16:04:54 -0400206 return VariableComponentSize(VariableComponentType(type)) * VariableComponentCount(type);
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000207}
208
Jamie Madillf2575982014-06-25 16:04:54 -0400209GLenum VariableBoolVectorType(GLenum type)
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000210{
211 switch (type)
212 {
Jamie Madill493f9572018-05-24 19:52:15 -0400213 case GL_FLOAT:
214 case GL_INT:
215 case GL_UNSIGNED_INT:
216 return GL_BOOL;
217 case GL_FLOAT_VEC2:
218 case GL_INT_VEC2:
219 case GL_UNSIGNED_INT_VEC2:
220 return GL_BOOL_VEC2;
221 case GL_FLOAT_VEC3:
222 case GL_INT_VEC3:
223 case GL_UNSIGNED_INT_VEC3:
224 return GL_BOOL_VEC3;
225 case GL_FLOAT_VEC4:
226 case GL_INT_VEC4:
227 case GL_UNSIGNED_INT_VEC4:
228 return GL_BOOL_VEC4;
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000229
Jamie Madill493f9572018-05-24 19:52:15 -0400230 default:
231 UNREACHABLE();
232 return GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000233 }
234}
235
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000236int VariableRowCount(GLenum type)
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000237{
238 switch (type)
239 {
Jamie Madill493f9572018-05-24 19:52:15 -0400240 case GL_NONE:
241 return 0;
242 case GL_BOOL:
243 case GL_FLOAT:
244 case GL_INT:
245 case GL_UNSIGNED_INT:
246 case GL_BOOL_VEC2:
247 case GL_FLOAT_VEC2:
248 case GL_INT_VEC2:
249 case GL_UNSIGNED_INT_VEC2:
250 case GL_BOOL_VEC3:
251 case GL_FLOAT_VEC3:
252 case GL_INT_VEC3:
253 case GL_UNSIGNED_INT_VEC3:
254 case GL_BOOL_VEC4:
255 case GL_FLOAT_VEC4:
256 case GL_INT_VEC4:
257 case GL_UNSIGNED_INT_VEC4:
258 case GL_SAMPLER_2D:
259 case GL_SAMPLER_3D:
260 case GL_SAMPLER_CUBE:
261 case GL_SAMPLER_2D_ARRAY:
262 case GL_SAMPLER_EXTERNAL_OES:
263 case GL_SAMPLER_2D_RECT_ANGLE:
264 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300265 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400266 case GL_INT_SAMPLER_2D:
267 case GL_INT_SAMPLER_3D:
268 case GL_INT_SAMPLER_CUBE:
269 case GL_INT_SAMPLER_2D_ARRAY:
270 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300271 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400272 case GL_UNSIGNED_INT_SAMPLER_2D:
273 case GL_UNSIGNED_INT_SAMPLER_3D:
274 case GL_UNSIGNED_INT_SAMPLER_CUBE:
275 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
276 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300277 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400278 case GL_SAMPLER_2D_SHADOW:
279 case GL_SAMPLER_CUBE_SHADOW:
280 case GL_SAMPLER_2D_ARRAY_SHADOW:
281 case GL_IMAGE_2D:
282 case GL_INT_IMAGE_2D:
283 case GL_UNSIGNED_INT_IMAGE_2D:
284 case GL_IMAGE_2D_ARRAY:
285 case GL_INT_IMAGE_2D_ARRAY:
286 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
287 case GL_IMAGE_3D:
288 case GL_INT_IMAGE_3D:
289 case GL_UNSIGNED_INT_IMAGE_3D:
290 case GL_IMAGE_CUBE:
291 case GL_INT_IMAGE_CUBE:
292 case GL_UNSIGNED_INT_IMAGE_CUBE:
293 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
294 return 1;
295 case GL_FLOAT_MAT2:
296 case GL_FLOAT_MAT3x2:
297 case GL_FLOAT_MAT4x2:
298 return 2;
299 case GL_FLOAT_MAT3:
300 case GL_FLOAT_MAT2x3:
301 case GL_FLOAT_MAT4x3:
302 return 3;
303 case GL_FLOAT_MAT4:
304 case GL_FLOAT_MAT2x4:
305 case GL_FLOAT_MAT3x4:
306 return 4;
307 default:
308 UNREACHABLE();
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000309 }
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000310
311 return 0;
312}
313
314int VariableColumnCount(GLenum type)
315{
316 switch (type)
317 {
Jamie Madill493f9572018-05-24 19:52:15 -0400318 case GL_NONE:
319 return 0;
320 case GL_BOOL:
321 case GL_FLOAT:
322 case GL_INT:
323 case GL_UNSIGNED_INT:
324 case GL_SAMPLER_2D:
325 case GL_SAMPLER_3D:
326 case GL_SAMPLER_CUBE:
327 case GL_SAMPLER_2D_ARRAY:
328 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300329 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400330 case GL_INT_SAMPLER_2D:
331 case GL_INT_SAMPLER_3D:
332 case GL_INT_SAMPLER_CUBE:
333 case GL_INT_SAMPLER_2D_ARRAY:
334 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300335 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400336 case GL_SAMPLER_EXTERNAL_OES:
337 case GL_SAMPLER_2D_RECT_ANGLE:
338 case GL_UNSIGNED_INT_SAMPLER_2D:
339 case GL_UNSIGNED_INT_SAMPLER_3D:
340 case GL_UNSIGNED_INT_SAMPLER_CUBE:
341 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
342 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300343 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400344 case GL_SAMPLER_2D_SHADOW:
345 case GL_SAMPLER_CUBE_SHADOW:
346 case GL_SAMPLER_2D_ARRAY_SHADOW:
347 case GL_IMAGE_2D:
348 case GL_INT_IMAGE_2D:
349 case GL_UNSIGNED_INT_IMAGE_2D:
350 case GL_IMAGE_3D:
351 case GL_INT_IMAGE_3D:
352 case GL_UNSIGNED_INT_IMAGE_3D:
353 case GL_IMAGE_2D_ARRAY:
354 case GL_INT_IMAGE_2D_ARRAY:
355 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
356 case GL_IMAGE_CUBE:
357 case GL_INT_IMAGE_CUBE:
358 case GL_UNSIGNED_INT_IMAGE_CUBE:
359 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
360 return 1;
361 case GL_BOOL_VEC2:
362 case GL_FLOAT_VEC2:
363 case GL_INT_VEC2:
364 case GL_UNSIGNED_INT_VEC2:
365 case GL_FLOAT_MAT2:
366 case GL_FLOAT_MAT2x3:
367 case GL_FLOAT_MAT2x4:
368 return 2;
369 case GL_BOOL_VEC3:
370 case GL_FLOAT_VEC3:
371 case GL_INT_VEC3:
372 case GL_UNSIGNED_INT_VEC3:
373 case GL_FLOAT_MAT3:
374 case GL_FLOAT_MAT3x2:
375 case GL_FLOAT_MAT3x4:
376 return 3;
377 case GL_BOOL_VEC4:
378 case GL_FLOAT_VEC4:
379 case GL_INT_VEC4:
380 case GL_UNSIGNED_INT_VEC4:
381 case GL_FLOAT_MAT4:
382 case GL_FLOAT_MAT4x2:
383 case GL_FLOAT_MAT4x3:
384 return 4;
385 default:
386 UNREACHABLE();
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000387 }
388
389 return 0;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000390}
391
Geoff Lang2ec386b2014-12-03 14:44:38 -0500392bool IsSamplerType(GLenum type)
Nicolas Capense6050882013-07-08 10:43:10 -0400393{
394 switch (type)
395 {
Jamie Madill493f9572018-05-24 19:52:15 -0400396 case GL_SAMPLER_2D:
397 case GL_SAMPLER_3D:
398 case GL_SAMPLER_CUBE:
399 case GL_SAMPLER_2D_ARRAY:
400 case GL_SAMPLER_EXTERNAL_OES:
401 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300402 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400403 case GL_SAMPLER_2D_RECT_ANGLE:
404 case GL_INT_SAMPLER_2D:
405 case GL_INT_SAMPLER_3D:
406 case GL_INT_SAMPLER_CUBE:
407 case GL_INT_SAMPLER_2D_ARRAY:
408 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300409 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400410 case GL_UNSIGNED_INT_SAMPLER_2D:
411 case GL_UNSIGNED_INT_SAMPLER_3D:
412 case GL_UNSIGNED_INT_SAMPLER_CUBE:
413 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
414 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300415 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400416 case GL_SAMPLER_2D_SHADOW:
417 case GL_SAMPLER_CUBE_SHADOW:
418 case GL_SAMPLER_2D_ARRAY_SHADOW:
419 return true;
Nicolas Capense6050882013-07-08 10:43:10 -0400420 }
421
422 return false;
423}
424
Olli Etuahoceb10482017-02-13 12:31:03 +0000425bool IsImageType(GLenum type)
426{
427 switch (type)
428 {
429 case GL_IMAGE_2D:
430 case GL_INT_IMAGE_2D:
431 case GL_UNSIGNED_INT_IMAGE_2D:
432 case GL_IMAGE_3D:
433 case GL_INT_IMAGE_3D:
434 case GL_UNSIGNED_INT_IMAGE_3D:
435 case GL_IMAGE_2D_ARRAY:
436 case GL_INT_IMAGE_2D_ARRAY:
437 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
438 case GL_IMAGE_CUBE:
439 case GL_INT_IMAGE_CUBE:
440 case GL_UNSIGNED_INT_IMAGE_CUBE:
441 return true;
442 }
443 return false;
444}
445
jchen104cdac9e2017-05-08 11:01:20 +0800446bool IsAtomicCounterType(GLenum type)
447{
448 return type == GL_UNSIGNED_INT_ATOMIC_COUNTER;
449}
450
Olli Etuahoceb10482017-02-13 12:31:03 +0000451bool IsOpaqueType(GLenum type)
452{
453 // ESSL 3.10 section 4.1.7 defines opaque types as: samplers, images and atomic counters.
jchen104cdac9e2017-05-08 11:01:20 +0800454 return IsImageType(type) || IsSamplerType(type) || IsAtomicCounterType(type);
Olli Etuahoceb10482017-02-13 12:31:03 +0000455}
456
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000457bool IsMatrixType(GLenum type)
458{
459 return VariableRowCount(type) > 1;
460}
461
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000462GLenum TransposeMatrixType(GLenum type)
463{
464 if (!IsMatrixType(type))
465 {
466 return type;
467 }
468
469 switch (type)
470 {
Jamie Madill493f9572018-05-24 19:52:15 -0400471 case GL_FLOAT_MAT2:
472 return GL_FLOAT_MAT2;
473 case GL_FLOAT_MAT3:
474 return GL_FLOAT_MAT3;
475 case GL_FLOAT_MAT4:
476 return GL_FLOAT_MAT4;
477 case GL_FLOAT_MAT2x3:
478 return GL_FLOAT_MAT3x2;
479 case GL_FLOAT_MAT3x2:
480 return GL_FLOAT_MAT2x3;
481 case GL_FLOAT_MAT2x4:
482 return GL_FLOAT_MAT4x2;
483 case GL_FLOAT_MAT4x2:
484 return GL_FLOAT_MAT2x4;
485 case GL_FLOAT_MAT3x4:
486 return GL_FLOAT_MAT4x3;
487 case GL_FLOAT_MAT4x3:
488 return GL_FLOAT_MAT3x4;
489 default:
490 UNREACHABLE();
491 return GL_NONE;
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000492 }
493}
494
Jamie Madill8c6befc2013-06-20 11:55:55 -0400495int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix)
496{
497 ASSERT(IsMatrixType(type));
498 return isRowMajorMatrix ? VariableRowCount(type) : VariableColumnCount(type);
499}
500
501int MatrixComponentCount(GLenum type, bool isRowMajorMatrix)
502{
503 ASSERT(IsMatrixType(type));
504 return isRowMajorMatrix ? VariableColumnCount(type) : VariableRowCount(type);
505}
506
Jamie Madillf2575982014-06-25 16:04:54 -0400507int VariableRegisterCount(GLenum type)
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000508{
509 return IsMatrixType(type) ? VariableColumnCount(type) : 1;
510}
511
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000512int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize)
513{
514 ASSERT(allocationSize <= bitsSize);
515
Jamie Madill493f9572018-05-24 19:52:15 -0400516 unsigned int mask = std::numeric_limits<unsigned int>::max() >>
517 (std::numeric_limits<unsigned int>::digits - allocationSize);
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000518
519 for (unsigned int i = 0; i < bitsSize - allocationSize + 1; i++)
520 {
521 if ((*bits & mask) == 0)
522 {
523 *bits |= mask;
524 return i;
525 }
526
527 mask <<= 1;
528 }
529
530 return -1;
531}
532
Geoff Lang3edfe032015-09-04 16:38:24 -0400533IndexRange ComputeIndexRange(GLenum indexType,
534 const GLvoid *indices,
535 size_t count,
536 bool primitiveRestartEnabled)
Geoff Lang831b1952015-05-05 11:02:27 -0400537{
538 switch (indexType)
539 {
Geoff Lang3edfe032015-09-04 16:38:24 -0400540 case GL_UNSIGNED_BYTE:
541 return ComputeTypedIndexRange(static_cast<const GLubyte *>(indices), count,
542 primitiveRestartEnabled,
543 GetPrimitiveRestartIndex(indexType));
544 case GL_UNSIGNED_SHORT:
545 return ComputeTypedIndexRange(static_cast<const GLushort *>(indices), count,
546 primitiveRestartEnabled,
547 GetPrimitiveRestartIndex(indexType));
548 case GL_UNSIGNED_INT:
549 return ComputeTypedIndexRange(static_cast<const GLuint *>(indices), count,
550 primitiveRestartEnabled,
551 GetPrimitiveRestartIndex(indexType));
552 default:
553 UNREACHABLE();
554 return IndexRange();
555 }
556}
557
558GLuint GetPrimitiveRestartIndex(GLenum indexType)
559{
560 switch (indexType)
561 {
562 case GL_UNSIGNED_BYTE:
563 return 0xFF;
564 case GL_UNSIGNED_SHORT:
565 return 0xFFFF;
566 case GL_UNSIGNED_INT:
567 return 0xFFFFFFFF;
568 default:
569 UNREACHABLE();
570 return 0;
Geoff Lang831b1952015-05-05 11:02:27 -0400571 }
572}
573
Jamie Madill493f9572018-05-24 19:52:15 -0400574bool IsTriangleMode(PrimitiveMode drawMode)
daniel@transgaming.com97c852b2012-12-20 20:56:23 +0000575{
576 switch (drawMode)
577 {
Jamie Madill493f9572018-05-24 19:52:15 -0400578 case PrimitiveMode::Triangles:
579 case PrimitiveMode::TriangleFan:
580 case PrimitiveMode::TriangleStrip:
581 return true;
582 case PrimitiveMode::Points:
583 case PrimitiveMode::Lines:
584 case PrimitiveMode::LineLoop:
585 case PrimitiveMode::LineStrip:
586 return false;
587 default:
588 UNREACHABLE();
daniel@transgaming.com97c852b2012-12-20 20:56:23 +0000589 }
590
591 return false;
592}
593
Geoff Lang4f0e0032017-05-01 16:04:35 -0400594bool IsIntegerFormat(GLenum unsizedFormat)
595{
596 switch (unsizedFormat)
597 {
598 case GL_RGBA_INTEGER:
599 case GL_RGB_INTEGER:
600 case GL_RG_INTEGER:
601 case GL_RED_INTEGER:
602 return true;
603
604 default:
605 return false;
606 }
607}
608
Jamie Madill865d1452014-07-02 15:31:20 -0400609// [OpenGL ES SL 3.00.4] Section 11 p. 120
610// Vertex Outs/Fragment Ins packing priorities
611int VariableSortOrder(GLenum type)
612{
613 switch (type)
614 {
Jamie Madill493f9572018-05-24 19:52:15 -0400615 // 1. Arrays of mat4 and mat4
616 // Non-square matrices of type matCxR consume the same space as a square
617 // matrix of type matN where N is the greater of C and R
618 case GL_FLOAT_MAT4:
619 case GL_FLOAT_MAT2x4:
620 case GL_FLOAT_MAT3x4:
621 case GL_FLOAT_MAT4x2:
622 case GL_FLOAT_MAT4x3:
623 return 0;
Jamie Madill865d1452014-07-02 15:31:20 -0400624
Jamie Madill493f9572018-05-24 19:52:15 -0400625 // 2. Arrays of mat2 and mat2 (since they occupy full rows)
626 case GL_FLOAT_MAT2:
627 return 1;
Jamie Madill865d1452014-07-02 15:31:20 -0400628
Jamie Madill493f9572018-05-24 19:52:15 -0400629 // 3. Arrays of vec4 and vec4
630 case GL_FLOAT_VEC4:
631 case GL_INT_VEC4:
632 case GL_BOOL_VEC4:
633 case GL_UNSIGNED_INT_VEC4:
634 return 2;
Jamie Madill865d1452014-07-02 15:31:20 -0400635
Jamie Madill493f9572018-05-24 19:52:15 -0400636 // 4. Arrays of mat3 and mat3
637 case GL_FLOAT_MAT3:
638 case GL_FLOAT_MAT2x3:
639 case GL_FLOAT_MAT3x2:
640 return 3;
Jamie Madill865d1452014-07-02 15:31:20 -0400641
Jamie Madill493f9572018-05-24 19:52:15 -0400642 // 5. Arrays of vec3 and vec3
643 case GL_FLOAT_VEC3:
644 case GL_INT_VEC3:
645 case GL_BOOL_VEC3:
646 case GL_UNSIGNED_INT_VEC3:
647 return 4;
Jamie Madill865d1452014-07-02 15:31:20 -0400648
Jamie Madill493f9572018-05-24 19:52:15 -0400649 // 6. Arrays of vec2 and vec2
650 case GL_FLOAT_VEC2:
651 case GL_INT_VEC2:
652 case GL_BOOL_VEC2:
653 case GL_UNSIGNED_INT_VEC2:
654 return 5;
Jamie Madill865d1452014-07-02 15:31:20 -0400655
Jamie Madill493f9572018-05-24 19:52:15 -0400656 // 7. Single component types
657 case GL_FLOAT:
658 case GL_INT:
659 case GL_BOOL:
660 case GL_UNSIGNED_INT:
661 case GL_SAMPLER_2D:
662 case GL_SAMPLER_CUBE:
663 case GL_SAMPLER_EXTERNAL_OES:
664 case GL_SAMPLER_2D_RECT_ANGLE:
665 case GL_SAMPLER_2D_ARRAY:
666 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300667 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400668 case GL_SAMPLER_3D:
669 case GL_INT_SAMPLER_2D:
670 case GL_INT_SAMPLER_3D:
671 case GL_INT_SAMPLER_CUBE:
672 case GL_INT_SAMPLER_2D_ARRAY:
673 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300674 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400675 case GL_UNSIGNED_INT_SAMPLER_2D:
676 case GL_UNSIGNED_INT_SAMPLER_3D:
677 case GL_UNSIGNED_INT_SAMPLER_CUBE:
678 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
679 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300680 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400681 case GL_SAMPLER_2D_SHADOW:
682 case GL_SAMPLER_2D_ARRAY_SHADOW:
683 case GL_SAMPLER_CUBE_SHADOW:
684 case GL_IMAGE_2D:
685 case GL_INT_IMAGE_2D:
686 case GL_UNSIGNED_INT_IMAGE_2D:
687 case GL_IMAGE_3D:
688 case GL_INT_IMAGE_3D:
689 case GL_UNSIGNED_INT_IMAGE_3D:
690 case GL_IMAGE_2D_ARRAY:
691 case GL_INT_IMAGE_2D_ARRAY:
692 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
693 case GL_IMAGE_CUBE:
694 case GL_INT_IMAGE_CUBE:
695 case GL_UNSIGNED_INT_IMAGE_CUBE:
696 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
697 return 6;
Jamie Madill865d1452014-07-02 15:31:20 -0400698
Jamie Madill493f9572018-05-24 19:52:15 -0400699 default:
700 UNREACHABLE();
701 return 0;
Jamie Madill865d1452014-07-02 15:31:20 -0400702 }
703}
704
Olli Etuahoc8538042017-09-27 11:20:15 +0300705std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400706{
Olli Etuahoc8538042017-09-27 11:20:15 +0300707 if (outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400708 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300709 outSubscripts->clear();
Geoff Langcfaeaa92015-04-14 13:41:02 -0400710 }
Olli Etuahoc8538042017-09-27 11:20:15 +0300711 // Strip any trailing array indexing operators and retrieve the subscripts.
712 size_t baseNameLength = name.length();
713 bool hasIndex = true;
714 while (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400715 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300716 size_t open = name.find_last_of('[', baseNameLength - 1);
717 size_t close = name.find_last_of(']', baseNameLength - 1);
718 hasIndex = (open != std::string::npos) && (close == baseNameLength - 1);
719 if (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400720 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300721 baseNameLength = open;
722 if (outSubscripts)
723 {
724 int index = atoi(name.substr(open + 1).c_str());
725 if (index >= 0)
726 {
727 outSubscripts->push_back(index);
728 }
729 else
730 {
731 outSubscripts->push_back(GL_INVALID_INDEX);
732 }
733 }
Geoff Langcfaeaa92015-04-14 13:41:02 -0400734 }
735 }
736
Olli Etuahoc8538042017-09-27 11:20:15 +0300737 return name.substr(0, baseNameLength);
Geoff Langcfaeaa92015-04-14 13:41:02 -0400738}
739
jchen108225e732017-11-14 16:29:03 +0800740const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var,
741 const std::string &fullName)
742{
743 if (var.fields.empty())
744 {
745 return nullptr;
746 }
747 size_t pos = fullName.find_first_of(".");
748 if (pos == std::string::npos)
749 {
750 return nullptr;
751 }
752 std::string topName = fullName.substr(0, pos);
753 if (topName != var.name)
754 {
755 return nullptr;
756 }
757 std::string fieldName = fullName.substr(pos + 1);
758 if (fieldName.empty())
759 {
760 return nullptr;
761 }
762 for (const auto &field : var.fields)
763 {
764 if (field.name == fieldName)
765 {
766 return &field;
767 }
768 }
769 return nullptr;
770}
771
Olli Etuaho465835d2017-09-26 13:34:10 +0300772unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes)
773{
774 unsigned int arraySizeProduct = 1u;
775 for (unsigned int arraySize : arraySizes)
776 {
777 arraySizeProduct *= arraySize;
778 }
779 return arraySizeProduct;
780}
781
Olli Etuahod2551232017-10-26 20:03:33 +0300782unsigned int ParseArrayIndex(const std::string &name, size_t *nameLengthWithoutArrayIndexOut)
Jamie Madill4a3c2342015-10-08 12:58:45 -0400783{
Olli Etuahod2551232017-10-26 20:03:33 +0300784 ASSERT(nameLengthWithoutArrayIndexOut != nullptr);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400785
786 // Strip any trailing array operator and retrieve the subscript
Olli Etuahod2551232017-10-26 20:03:33 +0300787 size_t open = name.find_last_of('[');
788 if (open != std::string::npos && name.back() == ']')
Jamie Madill4a3c2342015-10-08 12:58:45 -0400789 {
Olli Etuahod2551232017-10-26 20:03:33 +0300790 bool indexIsValidDecimalNumber = true;
791 for (size_t i = open + 1; i < name.length() - 1u; ++i)
792 {
793 if (!isdigit(name[i]))
794 {
795 indexIsValidDecimalNumber = false;
796 break;
797 }
798 }
799 if (indexIsValidDecimalNumber)
800 {
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800801 errno = 0; // reset global error flag.
802 unsigned long subscript =
803 strtoul(name.c_str() + open + 1, /*endptr*/ nullptr, /*radix*/ 10);
804
805 // Check if resulting integer is out-of-range or conversion error.
806 if ((subscript <= static_cast<unsigned long>(UINT_MAX)) &&
807 !(subscript == ULONG_MAX && errno == ERANGE) && !(errno != 0 && subscript == 0))
808 {
809 *nameLengthWithoutArrayIndexOut = open;
810 return static_cast<unsigned int>(subscript);
811 }
Olli Etuahod2551232017-10-26 20:03:33 +0300812 }
Jamie Madill4a3c2342015-10-08 12:58:45 -0400813 }
814
Olli Etuahod2551232017-10-26 20:03:33 +0300815 *nameLengthWithoutArrayIndexOut = name.length();
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800816 return GL_INVALID_INDEX;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000817}
818
Geoff Langee6884e2017-11-09 16:51:11 -0500819const char *GetGenericErrorMessage(GLenum error)
820{
821 switch (error)
822 {
823 case GL_NO_ERROR:
824 return "";
825 case GL_INVALID_ENUM:
826 return "Invalid enum.";
827 case GL_INVALID_VALUE:
828 return "Invalid value.";
829 case GL_INVALID_OPERATION:
830 return "Invalid operation.";
831 case GL_STACK_OVERFLOW:
832 return "Stack overflow.";
833 case GL_STACK_UNDERFLOW:
834 return "Stack underflow.";
835 case GL_OUT_OF_MEMORY:
836 return "Out of memory.";
837 case GL_INVALID_FRAMEBUFFER_OPERATION:
838 return "Invalid framebuffer operation.";
839 default:
840 UNREACHABLE();
841 return "Unknown error.";
842 }
843}
844
Jamie Madill8957b6c2017-11-14 12:40:38 -0500845unsigned int ElementTypeSize(GLenum elementType)
846{
847 switch (elementType)
848 {
849 case GL_UNSIGNED_BYTE:
850 return sizeof(GLubyte);
851 case GL_UNSIGNED_SHORT:
852 return sizeof(GLushort);
853 case GL_UNSIGNED_INT:
854 return sizeof(GLuint);
855 default:
856 UNREACHABLE();
857 return 0;
858 }
859}
860
Jamie Madill4a3c2342015-10-08 12:58:45 -0400861} // namespace gl
862
Geoff Langa8406172015-07-21 16:53:39 -0400863namespace egl
864{
865static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 1,
866 "Unexpected EGL cube map enum value.");
867static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 2,
868 "Unexpected EGL cube map enum value.");
869static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 3,
870 "Unexpected EGL cube map enum value.");
871static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 4,
872 "Unexpected EGL cube map enum value.");
873static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 5,
874 "Unexpected EGL cube map enum value.");
875
876bool IsCubeMapTextureTarget(EGLenum target)
877{
878 return (target >= FirstCubeMapTextureTarget && target <= LastCubeMapTextureTarget);
879}
880
881size_t CubeMapTextureTargetToLayerIndex(EGLenum target)
882{
883 ASSERT(IsCubeMapTextureTarget(target));
884 return target - static_cast<size_t>(FirstCubeMapTextureTarget);
885}
886
887EGLenum LayerIndexToCubeMapTextureTarget(size_t index)
888{
889 ASSERT(index <= (LastCubeMapTextureTarget - FirstCubeMapTextureTarget));
890 return FirstCubeMapTextureTarget + static_cast<GLenum>(index);
891}
892
893bool IsTextureTarget(EGLenum target)
894{
895 switch (target)
896 {
897 case EGL_GL_TEXTURE_2D_KHR:
898 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
899 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
900 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
901 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
902 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
903 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
904 case EGL_GL_TEXTURE_3D_KHR:
905 return true;
906
907 default:
908 return false;
909 }
910}
911
912bool IsRenderbufferTarget(EGLenum target)
913{
914 return target == EGL_GL_RENDERBUFFER_KHR;
915}
Geoff Langee6884e2017-11-09 16:51:11 -0500916
917const char *GetGenericErrorMessage(EGLint error)
918{
919 switch (error)
920 {
921 case EGL_SUCCESS:
922 return "";
923 case EGL_NOT_INITIALIZED:
924 return "Not initialized.";
925 case EGL_BAD_ACCESS:
926 return "Bad access.";
927 case EGL_BAD_ALLOC:
928 return "Bad allocation.";
929 case EGL_BAD_ATTRIBUTE:
930 return "Bad attribute.";
931 case EGL_BAD_CONFIG:
932 return "Bad config.";
933 case EGL_BAD_CONTEXT:
934 return "Bad context.";
935 case EGL_BAD_CURRENT_SURFACE:
936 return "Bad current surface.";
937 case EGL_BAD_DISPLAY:
938 return "Bad display.";
939 case EGL_BAD_MATCH:
940 return "Bad match.";
941 case EGL_BAD_NATIVE_WINDOW:
942 return "Bad native window.";
943 case EGL_BAD_PARAMETER:
944 return "Bad parameter.";
945 case EGL_BAD_SURFACE:
946 return "Bad surface.";
947 case EGL_CONTEXT_LOST:
948 return "Context lost.";
949 case EGL_BAD_STREAM_KHR:
950 return "Bad stream.";
951 case EGL_BAD_STATE_KHR:
952 return "Bad state.";
953 case EGL_BAD_DEVICE_EXT:
954 return "Bad device.";
955 default:
956 UNREACHABLE();
957 return "Unknown error.";
958 }
959}
960
Jamie Madill8b9b7922016-05-19 13:13:37 -0400961} // namespace egl
Geoff Langa8406172015-07-21 16:53:39 -0400962
963namespace egl_gl
964{
Geoff Langa8406172015-07-21 16:53:39 -0400965GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer)
966{
967 return static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
968}
Jamie Madill8b9b7922016-05-19 13:13:37 -0400969} // namespace egl_gl
Geoff Langa8406172015-07-21 16:53:39 -0400970
Geoff Langc5a2a172017-01-13 15:55:07 -0500971namespace gl_egl
972{
973EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType)
974{
975 switch (glComponentType)
976 {
977 case GL_FLOAT:
978 return EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
979
980 case GL_UNSIGNED_NORMALIZED:
981 return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
982
983 default:
984 UNREACHABLE();
985 return EGL_NONE;
986 }
987}
Geoff Langdbd16122018-07-19 11:30:21 -0400988
989EGLClientBuffer GLObjectHandleToEGLClientBuffer(GLuint handle)
990{
991 return reinterpret_cast<EGLClientBuffer>(static_cast<uintptr_t>(handle));
992}
993
Geoff Langc5a2a172017-01-13 15:55:07 -0500994} // namespace gl_egl
995
Austin Kinross922a9fb2014-10-21 14:26:33 -0700996#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000997std::string getTempPath()
998{
Shannon Woodsfb839472014-06-16 13:21:41 -0400999#ifdef ANGLE_PLATFORM_WINDOWS
Austin Kinross922a9fb2014-10-21 14:26:33 -07001000 char path[MAX_PATH];
1001 DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path);
1002 if (pathLen == 0)
1003 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001004 UNREACHABLE();
1005 return std::string();
Austin Kinross922a9fb2014-10-21 14:26:33 -07001006 }
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001007
Austin Kinross922a9fb2014-10-21 14:26:33 -07001008 UINT unique = GetTempFileNameA(path, "sh", 0, path);
1009 if (unique == 0)
1010 {
1011 UNREACHABLE();
1012 return std::string();
1013 }
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +00001014
Austin Kinross922a9fb2014-10-21 14:26:33 -07001015 return path;
Geoff Lang83217792014-01-16 09:52:38 -05001016#else
1017 UNIMPLEMENTED();
1018 return "";
1019#endif
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001020}
1021
Jamie Madill493f9572018-05-24 19:52:15 -04001022void writeFile(const char *path, const void *content, size_t size)
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001023{
Jamie Madill493f9572018-05-24 19:52:15 -04001024 FILE *file = fopen(path, "w");
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001025 if (!file)
1026 {
1027 UNREACHABLE();
1028 return;
1029 }
1030
1031 fwrite(content, sizeof(char), size, file);
1032 fclose(file);
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001033}
Jamie Madill493f9572018-05-24 19:52:15 -04001034#endif // !ANGLE_ENABLE_WINDOWS_STORE
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001035
Jamie Madill493f9572018-05-24 19:52:15 -04001036#if defined(ANGLE_PLATFORM_WINDOWS)
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001037
Cooper Partin1edac3b2014-11-20 13:49:27 -08001038// Causes the thread to relinquish the remainder of its time slice to any
1039// other thread that is ready to run.If there are no other threads ready
1040// to run, the function returns immediately, and the thread continues execution.
1041void ScheduleYield()
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001042{
Geoff Lange5f735f2015-09-17 13:26:59 -04001043 Sleep(0);
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001044}
1045
Kenneth Russellb23deb22014-11-21 14:53:56 -08001046#endif