1 //
2 // Copyright 2002 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 //
6
7 //
8 // Implement the top-level of interface to the compiler,
9 // as defined in ShaderLang.h
10 //
11
12 #include "GLSLANG/ShaderLang.h"
13
14 #include "compiler/translator/Compiler.h"
15 #include "compiler/translator/InitializeDll.h"
16 #include "compiler/translator/length_limits.h"
17 #ifdef ANGLE_ENABLE_HLSL
18 # include "compiler/translator/TranslatorHLSL.h"
19 #endif // ANGLE_ENABLE_HLSL
20 #include "angle_gl.h"
21 #include "compiler/translator/VariablePacker.h"
22
23 namespace sh
24 {
25
26 namespace
27 {
28
29 bool isInitialized = false;
30
31 //
32 // This is the platform independent interface between an OGL driver
33 // and the shading language compiler.
34 //
35
36 template <typename VarT>
37 const std::vector<VarT> *GetVariableList(const TCompiler *compiler);
38
39 template <>
GetVariableList(const TCompiler * compiler)40 const std::vector<InterfaceBlock> *GetVariableList(const TCompiler *compiler)
41 {
42 return &compiler->getInterfaceBlocks();
43 }
44
GetCompilerFromHandle(ShHandle handle)45 TCompiler *GetCompilerFromHandle(ShHandle handle)
46 {
47 if (!handle)
48 {
49 return nullptr;
50 }
51
52 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
53 return base->getAsCompiler();
54 }
55
56 template <typename VarT>
GetShaderVariables(const ShHandle handle)57 const std::vector<VarT> *GetShaderVariables(const ShHandle handle)
58 {
59 TCompiler *compiler = GetCompilerFromHandle(handle);
60 if (!compiler)
61 {
62 return nullptr;
63 }
64
65 return GetVariableList<VarT>(compiler);
66 }
67
68 #ifdef ANGLE_ENABLE_HLSL
GetTranslatorHLSLFromHandle(ShHandle handle)69 TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
70 {
71 if (!handle)
72 return nullptr;
73 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
74 return base->getAsTranslatorHLSL();
75 }
76 #endif // ANGLE_ENABLE_HLSL
77
GetGeometryShaderPrimitiveTypeEnum(sh::TLayoutPrimitiveType primitiveType)78 GLenum GetGeometryShaderPrimitiveTypeEnum(sh::TLayoutPrimitiveType primitiveType)
79 {
80 switch (primitiveType)
81 {
82 case EptPoints:
83 return GL_POINTS;
84 case EptLines:
85 return GL_LINES;
86 case EptLinesAdjacency:
87 return GL_LINES_ADJACENCY_EXT;
88 case EptTriangles:
89 return GL_TRIANGLES;
90 case EptTrianglesAdjacency:
91 return GL_TRIANGLES_ADJACENCY_EXT;
92
93 case EptLineStrip:
94 return GL_LINE_STRIP;
95 case EptTriangleStrip:
96 return GL_TRIANGLE_STRIP;
97
98 case EptUndefined:
99 default:
100 UNREACHABLE();
101 return GL_INVALID_VALUE;
102 }
103 }
104
105 } // anonymous namespace
106
107 //
108 // Driver must call this first, once, before doing any other compiler operations.
109 // Subsequent calls to this function are no-op.
110 //
Initialize()111 bool Initialize()
112 {
113 if (!isInitialized)
114 {
115 isInitialized = InitProcess();
116 }
117 return isInitialized;
118 }
119
120 //
121 // Cleanup symbol tables
122 //
Finalize()123 bool Finalize()
124 {
125 if (isInitialized)
126 {
127 DetachProcess();
128 isInitialized = false;
129 }
130 return true;
131 }
132
133 //
134 // Initialize built-in resources with minimum expected values.
135 //
InitBuiltInResources(ShBuiltInResources * resources)136 void InitBuiltInResources(ShBuiltInResources *resources)
137 {
138 // Make comparable.
139 memset(resources, 0, sizeof(*resources));
140
141 // Constants.
142 resources->MaxVertexAttribs = 8;
143 resources->MaxVertexUniformVectors = 128;
144 resources->MaxVaryingVectors = 8;
145 resources->MaxVertexTextureImageUnits = 0;
146 resources->MaxCombinedTextureImageUnits = 8;
147 resources->MaxTextureImageUnits = 8;
148 resources->MaxFragmentUniformVectors = 16;
149 resources->MaxDrawBuffers = 1;
150
151 // Extensions.
152 resources->OES_standard_derivatives = 0;
153 resources->OES_EGL_image_external = 0;
154 resources->OES_EGL_image_external_essl3 = 0;
155 resources->NV_EGL_stream_consumer_external = 0;
156 resources->ARB_texture_rectangle = 0;
157 resources->EXT_blend_func_extended = 0;
158 resources->EXT_draw_buffers = 0;
159 resources->EXT_frag_depth = 0;
160 resources->EXT_shader_texture_lod = 0;
161 resources->WEBGL_debug_shader_precision = 0;
162 resources->EXT_shader_framebuffer_fetch = 0;
163 resources->NV_shader_framebuffer_fetch = 0;
164 resources->ARM_shader_framebuffer_fetch = 0;
165 resources->OVR_multiview = 0;
166 resources->OVR_multiview2 = 0;
167 resources->EXT_YUV_target = 0;
168 resources->EXT_geometry_shader = 0;
169 resources->EXT_gpu_shader5 = 0;
170 resources->EXT_shader_non_constant_global_initializers = 0;
171 resources->OES_texture_storage_multisample_2d_array = 0;
172 resources->OES_texture_3D = 0;
173 resources->ANGLE_texture_multisample = 0;
174 resources->ANGLE_multi_draw = 0;
175 resources->ANGLE_base_vertex_base_instance = 0;
176 resources->WEBGL_video_texture = 0;
177
178 resources->NV_draw_buffers = 0;
179
180 // Disable highp precision in fragment shader by default.
181 resources->FragmentPrecisionHigh = 0;
182
183 // GLSL ES 3.0 constants.
184 resources->MaxVertexOutputVectors = 16;
185 resources->MaxFragmentInputVectors = 15;
186 resources->MinProgramTexelOffset = -8;
187 resources->MaxProgramTexelOffset = 7;
188
189 // Extensions constants.
190 resources->MaxDualSourceDrawBuffers = 0;
191
192 resources->MaxViewsOVR = 4;
193
194 // Disable name hashing by default.
195 resources->HashFunction = nullptr;
196
197 resources->ArrayIndexClampingStrategy = SH_CLAMP_WITH_CLAMP_INTRINSIC;
198
199 resources->MaxExpressionComplexity = 256;
200 resources->MaxCallStackDepth = 256;
201 resources->MaxFunctionParameters = 1024;
202
203 // ES 3.1 Revision 4, 7.2 Built-in Constants
204
205 // ES 3.1, Revision 4, 8.13 Texture minification
206 // "The value of MIN_PROGRAM_TEXTURE_GATHER_OFFSET must be less than or equal to the value of
207 // MIN_PROGRAM_TEXEL_OFFSET. The value of MAX_PROGRAM_TEXTURE_GATHER_OFFSET must be greater than
208 // or equal to the value of MAX_PROGRAM_TEXEL_OFFSET"
209 resources->MinProgramTextureGatherOffset = -8;
210 resources->MaxProgramTextureGatherOffset = 7;
211
212 resources->MaxImageUnits = 4;
213 resources->MaxVertexImageUniforms = 0;
214 resources->MaxFragmentImageUniforms = 0;
215 resources->MaxComputeImageUniforms = 4;
216 resources->MaxCombinedImageUniforms = 4;
217
218 resources->MaxUniformLocations = 1024;
219
220 resources->MaxCombinedShaderOutputResources = 4;
221
222 resources->MaxComputeWorkGroupCount[0] = 65535;
223 resources->MaxComputeWorkGroupCount[1] = 65535;
224 resources->MaxComputeWorkGroupCount[2] = 65535;
225 resources->MaxComputeWorkGroupSize[0] = 128;
226 resources->MaxComputeWorkGroupSize[1] = 128;
227 resources->MaxComputeWorkGroupSize[2] = 64;
228 resources->MaxComputeUniformComponents = 512;
229 resources->MaxComputeTextureImageUnits = 16;
230
231 resources->MaxComputeAtomicCounters = 8;
232 resources->MaxComputeAtomicCounterBuffers = 1;
233
234 resources->MaxVertexAtomicCounters = 0;
235 resources->MaxFragmentAtomicCounters = 0;
236 resources->MaxCombinedAtomicCounters = 8;
237 resources->MaxAtomicCounterBindings = 1;
238
239 resources->MaxVertexAtomicCounterBuffers = 0;
240 resources->MaxFragmentAtomicCounterBuffers = 0;
241 resources->MaxCombinedAtomicCounterBuffers = 1;
242 resources->MaxAtomicCounterBufferSize = 32;
243
244 resources->MaxUniformBufferBindings = 32;
245 resources->MaxShaderStorageBufferBindings = 4;
246
247 resources->MaxGeometryUniformComponents = 1024;
248 resources->MaxGeometryUniformBlocks = 12;
249 resources->MaxGeometryInputComponents = 64;
250 resources->MaxGeometryOutputComponents = 64;
251 resources->MaxGeometryOutputVertices = 256;
252 resources->MaxGeometryTotalOutputComponents = 1024;
253 resources->MaxGeometryTextureImageUnits = 16;
254 resources->MaxGeometryAtomicCounterBuffers = 0;
255 resources->MaxGeometryAtomicCounters = 0;
256 resources->MaxGeometryShaderStorageBlocks = 0;
257 resources->MaxGeometryShaderInvocations = 32;
258 resources->MaxGeometryImageUniforms = 0;
259
260 resources->SubPixelBits = 8;
261 }
262
263 //
264 // Driver calls these to create and destroy compiler objects.
265 //
ConstructCompiler(sh::GLenum type,ShShaderSpec spec,ShShaderOutput output,const ShBuiltInResources * resources)266 ShHandle ConstructCompiler(sh::GLenum type,
267 ShShaderSpec spec,
268 ShShaderOutput output,
269 const ShBuiltInResources *resources)
270 {
271 TShHandleBase *base = static_cast<TShHandleBase *>(ConstructCompiler(type, spec, output));
272 if (base == nullptr)
273 {
274 return 0;
275 }
276
277 TCompiler *compiler = base->getAsCompiler();
278 if (compiler == nullptr)
279 {
280 return 0;
281 }
282
283 // Generate built-in symbol table.
284 if (!compiler->Init(*resources))
285 {
286 Destruct(base);
287 return 0;
288 }
289
290 return base;
291 }
292
Destruct(ShHandle handle)293 void Destruct(ShHandle handle)
294 {
295 if (handle == 0)
296 return;
297
298 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
299
300 if (base->getAsCompiler())
301 DeleteCompiler(base->getAsCompiler());
302 }
303
GetBuiltInResourcesString(const ShHandle handle)304 const std::string &GetBuiltInResourcesString(const ShHandle handle)
305 {
306 TCompiler *compiler = GetCompilerFromHandle(handle);
307 ASSERT(compiler);
308 return compiler->getBuiltInResourcesString();
309 }
310
311 //
312 // Do an actual compile on the given strings. The result is left
313 // in the given compile object.
314 //
315 // Return: The return value of ShCompile is really boolean, indicating
316 // success or failure.
317 //
Compile(const ShHandle handle,const char * const shaderStrings[],size_t numStrings,ShCompileOptions compileOptions)318 bool Compile(const ShHandle handle,
319 const char *const shaderStrings[],
320 size_t numStrings,
321 ShCompileOptions compileOptions)
322 {
323 TCompiler *compiler = GetCompilerFromHandle(handle);
324 ASSERT(compiler);
325
326 return compiler->compile(shaderStrings, numStrings, compileOptions);
327 }
328
ClearResults(const ShHandle handle)329 void ClearResults(const ShHandle handle)
330 {
331 TCompiler *compiler = GetCompilerFromHandle(handle);
332 ASSERT(compiler);
333 compiler->clearResults();
334 }
335
GetShaderVersion(const ShHandle handle)336 int GetShaderVersion(const ShHandle handle)
337 {
338 TCompiler *compiler = GetCompilerFromHandle(handle);
339 ASSERT(compiler);
340 return compiler->getShaderVersion();
341 }
342
GetShaderOutputType(const ShHandle handle)343 ShShaderOutput GetShaderOutputType(const ShHandle handle)
344 {
345 TCompiler *compiler = GetCompilerFromHandle(handle);
346 ASSERT(compiler);
347 return compiler->getOutputType();
348 }
349
350 //
351 // Return any compiler log of messages for the application.
352 //
GetInfoLog(const ShHandle handle)353 const std::string &GetInfoLog(const ShHandle handle)
354 {
355 TCompiler *compiler = GetCompilerFromHandle(handle);
356 ASSERT(compiler);
357
358 TInfoSink &infoSink = compiler->getInfoSink();
359 return infoSink.info.str();
360 }
361
362 //
363 // Return any object code.
364 //
GetObjectCode(const ShHandle handle)365 const std::string &GetObjectCode(const ShHandle handle)
366 {
367 TCompiler *compiler = GetCompilerFromHandle(handle);
368 ASSERT(compiler);
369
370 TInfoSink &infoSink = compiler->getInfoSink();
371 return infoSink.obj.str();
372 }
373
GetNameHashingMap(const ShHandle handle)374 const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle)
375 {
376 TCompiler *compiler = GetCompilerFromHandle(handle);
377 ASSERT(compiler);
378 return &(compiler->getNameMap());
379 }
380
GetUniforms(const ShHandle handle)381 const std::vector<ShaderVariable> *GetUniforms(const ShHandle handle)
382 {
383 TCompiler *compiler = GetCompilerFromHandle(handle);
384 if (!compiler)
385 {
386 return nullptr;
387 }
388 return &compiler->getUniforms();
389 }
390
GetInputVaryings(const ShHandle handle)391 const std::vector<ShaderVariable> *GetInputVaryings(const ShHandle handle)
392 {
393 TCompiler *compiler = GetCompilerFromHandle(handle);
394 if (compiler == nullptr)
395 {
396 return nullptr;
397 }
398 return &compiler->getInputVaryings();
399 }
400
GetOutputVaryings(const ShHandle handle)401 const std::vector<ShaderVariable> *GetOutputVaryings(const ShHandle handle)
402 {
403 TCompiler *compiler = GetCompilerFromHandle(handle);
404 if (compiler == nullptr)
405 {
406 return nullptr;
407 }
408 return &compiler->getOutputVaryings();
409 }
410
GetVaryings(const ShHandle handle)411 const std::vector<ShaderVariable> *GetVaryings(const ShHandle handle)
412 {
413 TCompiler *compiler = GetCompilerFromHandle(handle);
414 if (compiler == nullptr)
415 {
416 return nullptr;
417 }
418
419 switch (compiler->getShaderType())
420 {
421 case GL_VERTEX_SHADER:
422 return &compiler->getOutputVaryings();
423 case GL_FRAGMENT_SHADER:
424 return &compiler->getInputVaryings();
425 case GL_COMPUTE_SHADER:
426 ASSERT(compiler->getOutputVaryings().empty() && compiler->getInputVaryings().empty());
427 return &compiler->getOutputVaryings();
428 // Since geometry shaders have both input and output varyings, we shouldn't call GetVaryings
429 // on a geometry shader.
430 default:
431 return nullptr;
432 }
433 }
434
GetAttributes(const ShHandle handle)435 const std::vector<ShaderVariable> *GetAttributes(const ShHandle handle)
436 {
437 TCompiler *compiler = GetCompilerFromHandle(handle);
438 if (!compiler)
439 {
440 return nullptr;
441 }
442 return &compiler->getAttributes();
443 }
444
GetOutputVariables(const ShHandle handle)445 const std::vector<ShaderVariable> *GetOutputVariables(const ShHandle handle)
446 {
447 TCompiler *compiler = GetCompilerFromHandle(handle);
448 if (!compiler)
449 {
450 return nullptr;
451 }
452 return &compiler->getOutputVariables();
453 }
454
GetInterfaceBlocks(const ShHandle handle)455 const std::vector<InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle)
456 {
457 return GetShaderVariables<InterfaceBlock>(handle);
458 }
459
GetUniformBlocks(const ShHandle handle)460 const std::vector<InterfaceBlock> *GetUniformBlocks(const ShHandle handle)
461 {
462 ASSERT(handle);
463 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
464 TCompiler *compiler = base->getAsCompiler();
465 ASSERT(compiler);
466
467 return &compiler->getUniformBlocks();
468 }
469
GetShaderStorageBlocks(const ShHandle handle)470 const std::vector<InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle)
471 {
472 ASSERT(handle);
473 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
474 TCompiler *compiler = base->getAsCompiler();
475 ASSERT(compiler);
476
477 return &compiler->getShaderStorageBlocks();
478 }
479
GetComputeShaderLocalGroupSize(const ShHandle handle)480 WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle)
481 {
482 ASSERT(handle);
483
484 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
485 TCompiler *compiler = base->getAsCompiler();
486 ASSERT(compiler);
487
488 return compiler->getComputeShaderLocalSize();
489 }
490
GetVertexShaderNumViews(const ShHandle handle)491 int GetVertexShaderNumViews(const ShHandle handle)
492 {
493 ASSERT(handle);
494 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
495 TCompiler *compiler = base->getAsCompiler();
496 ASSERT(compiler);
497
498 return compiler->getNumViews();
499 }
500
CheckVariablesWithinPackingLimits(int maxVectors,const std::vector<ShaderVariable> & variables)501 bool CheckVariablesWithinPackingLimits(int maxVectors, const std::vector<ShaderVariable> &variables)
502 {
503 return CheckVariablesInPackingLimits(maxVectors, variables);
504 }
505
GetShaderStorageBlockRegister(const ShHandle handle,const std::string & shaderStorageBlockName,unsigned int * indexOut)506 bool GetShaderStorageBlockRegister(const ShHandle handle,
507 const std::string &shaderStorageBlockName,
508 unsigned int *indexOut)
509 {
510 #ifdef ANGLE_ENABLE_HLSL
511 ASSERT(indexOut);
512
513 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
514 ASSERT(translator);
515
516 if (!translator->hasShaderStorageBlock(shaderStorageBlockName))
517 {
518 return false;
519 }
520
521 *indexOut = translator->getShaderStorageBlockRegister(shaderStorageBlockName);
522 return true;
523 #else
524 return false;
525 #endif // ANGLE_ENABLE_HLSL
526 }
527
GetUniformBlockRegister(const ShHandle handle,const std::string & uniformBlockName,unsigned int * indexOut)528 bool GetUniformBlockRegister(const ShHandle handle,
529 const std::string &uniformBlockName,
530 unsigned int *indexOut)
531 {
532 #ifdef ANGLE_ENABLE_HLSL
533 ASSERT(indexOut);
534
535 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
536 ASSERT(translator);
537
538 if (!translator->hasUniformBlock(uniformBlockName))
539 {
540 return false;
541 }
542
543 *indexOut = translator->getUniformBlockRegister(uniformBlockName);
544 return true;
545 #else
546 return false;
547 #endif // ANGLE_ENABLE_HLSL
548 }
549
ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,const std::string & uniformBlockName)550 bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,
551 const std::string &uniformBlockName)
552 {
553 #ifdef ANGLE_ENABLE_HLSL
554 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
555 ASSERT(translator);
556
557 return translator->shouldUniformBlockUseStructuredBuffer(uniformBlockName);
558 #else
559 return false;
560 #endif // ANGLE_ENABLE_HLSL
561 }
562
GetUniformRegisterMap(const ShHandle handle)563 const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle)
564 {
565 #ifdef ANGLE_ENABLE_HLSL
566 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
567 ASSERT(translator);
568
569 return translator->getUniformRegisterMap();
570 #else
571 return nullptr;
572 #endif // ANGLE_ENABLE_HLSL
573 }
574
GetReadonlyImage2DRegisterIndex(const ShHandle handle)575 unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle)
576 {
577 #ifdef ANGLE_ENABLE_HLSL
578 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
579 ASSERT(translator);
580
581 return translator->getReadonlyImage2DRegisterIndex();
582 #else
583 return 0;
584 #endif // ANGLE_ENABLE_HLSL
585 }
586
GetImage2DRegisterIndex(const ShHandle handle)587 unsigned int GetImage2DRegisterIndex(const ShHandle handle)
588 {
589 #ifdef ANGLE_ENABLE_HLSL
590 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
591 ASSERT(translator);
592
593 return translator->getImage2DRegisterIndex();
594 #else
595 return 0;
596 #endif // ANGLE_ENABLE_HLSL
597 }
598
GetUsedImage2DFunctionNames(const ShHandle handle)599 const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle)
600 {
601 #ifdef ANGLE_ENABLE_HLSL
602 TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
603 ASSERT(translator);
604
605 return translator->getUsedImage2DFunctionNames();
606 #else
607 return nullptr;
608 #endif // ANGLE_ENABLE_HLSL
609 }
610
HasValidGeometryShaderInputPrimitiveType(const ShHandle handle)611 bool HasValidGeometryShaderInputPrimitiveType(const ShHandle handle)
612 {
613 ASSERT(handle);
614
615 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
616 TCompiler *compiler = base->getAsCompiler();
617 ASSERT(compiler);
618
619 return compiler->getGeometryShaderInputPrimitiveType() != EptUndefined;
620 }
621
HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle)622 bool HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle)
623 {
624 ASSERT(handle);
625
626 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
627 TCompiler *compiler = base->getAsCompiler();
628 ASSERT(compiler);
629
630 return compiler->getGeometryShaderOutputPrimitiveType() != EptUndefined;
631 }
632
HasValidGeometryShaderMaxVertices(const ShHandle handle)633 bool HasValidGeometryShaderMaxVertices(const ShHandle handle)
634 {
635 ASSERT(handle);
636
637 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
638 TCompiler *compiler = base->getAsCompiler();
639 ASSERT(compiler);
640
641 return compiler->getGeometryShaderMaxVertices() >= 0;
642 }
643
GetGeometryShaderInputPrimitiveType(const ShHandle handle)644 GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle)
645 {
646 ASSERT(handle);
647
648 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
649 TCompiler *compiler = base->getAsCompiler();
650 ASSERT(compiler);
651
652 return GetGeometryShaderPrimitiveTypeEnum(compiler->getGeometryShaderInputPrimitiveType());
653 }
654
GetGeometryShaderOutputPrimitiveType(const ShHandle handle)655 GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle)
656 {
657 ASSERT(handle);
658
659 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
660 TCompiler *compiler = base->getAsCompiler();
661 ASSERT(compiler);
662
663 return GetGeometryShaderPrimitiveTypeEnum(compiler->getGeometryShaderOutputPrimitiveType());
664 }
665
GetGeometryShaderInvocations(const ShHandle handle)666 int GetGeometryShaderInvocations(const ShHandle handle)
667 {
668 ASSERT(handle);
669
670 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
671 TCompiler *compiler = base->getAsCompiler();
672 ASSERT(compiler);
673
674 return compiler->getGeometryShaderInvocations();
675 }
676
GetGeometryShaderMaxVertices(const ShHandle handle)677 int GetGeometryShaderMaxVertices(const ShHandle handle)
678 {
679 ASSERT(handle);
680
681 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
682 TCompiler *compiler = base->getAsCompiler();
683 ASSERT(compiler);
684
685 int maxVertices = compiler->getGeometryShaderMaxVertices();
686 ASSERT(maxVertices >= 0);
687 return maxVertices;
688 }
689
GetShaderSharedMemorySize(const ShHandle handle)690 unsigned int GetShaderSharedMemorySize(const ShHandle handle)
691 {
692 ASSERT(handle);
693
694 TShHandleBase *base = static_cast<TShHandleBase *>(handle);
695 TCompiler *compiler = base->getAsCompiler();
696 ASSERT(compiler);
697
698 unsigned int sharedMemorySize = compiler->getSharedMemorySize();
699 return sharedMemorySize;
700 }
701
702 // Can't prefix with just _ because then we might introduce a double underscore, which is not safe
703 // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
704 // use by the underlying implementation). u is short for user-defined.
705 const char kUserDefinedNamePrefix[] = "_u";
706
707 namespace vk
708 {
709 // Interface block name containing the aggregate default uniforms
710 const char kDefaultUniformsNameVS[] = "defaultUniformsVS";
711 const char kDefaultUniformsNameTCS[] = "defaultUniformsTCS";
712 const char kDefaultUniformsNameTES[] = "defaultUniformsTES";
713 const char kDefaultUniformsNameGS[] = "defaultUniformsGS";
714 const char kDefaultUniformsNameFS[] = "defaultUniformsFS";
715 const char kDefaultUniformsNameCS[] = "defaultUniformsCS";
716
717 // Interface block and variable names containing driver uniforms
718 const char kDriverUniformsBlockName[] = "ANGLEUniformBlock";
719 const char kDriverUniformsVarName[] = "ANGLEUniforms";
720
721 // Interface block array name used for atomic counter emulation
722 const char kAtomicCountersBlockName[] = "ANGLEAtomicCounters";
723
724 const char kLineRasterEmulationPosition[] = "ANGLEPosition";
725
726 } // namespace vk
727
728 } // namespace sh
729