• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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->NV_shader_noperspective_interpolation       = 0;
172     resources->OES_texture_storage_multisample_2d_array    = 0;
173     resources->OES_texture_3D                              = 0;
174     resources->ANGLE_texture_multisample                   = 0;
175     resources->ANGLE_multi_draw                            = 0;
176     resources->ANGLE_base_vertex_base_instance             = 0;
177     resources->WEBGL_video_texture                         = 0;
178 
179     resources->NV_draw_buffers = 0;
180 
181     // Disable highp precision in fragment shader by default.
182     resources->FragmentPrecisionHigh = 0;
183 
184     // GLSL ES 3.0 constants.
185     resources->MaxVertexOutputVectors  = 16;
186     resources->MaxFragmentInputVectors = 15;
187     resources->MinProgramTexelOffset   = -8;
188     resources->MaxProgramTexelOffset   = 7;
189 
190     // Extensions constants.
191     resources->MaxDualSourceDrawBuffers = 0;
192 
193     resources->MaxViewsOVR = 4;
194 
195     // Disable name hashing by default.
196     resources->HashFunction = nullptr;
197 
198     resources->ArrayIndexClampingStrategy = SH_CLAMP_WITH_CLAMP_INTRINSIC;
199 
200     resources->MaxExpressionComplexity = 256;
201     resources->MaxCallStackDepth       = 256;
202     resources->MaxFunctionParameters   = 1024;
203 
204     // ES 3.1 Revision 4, 7.2 Built-in Constants
205 
206     // ES 3.1, Revision 4, 8.13 Texture minification
207     // "The value of MIN_PROGRAM_TEXTURE_GATHER_OFFSET must be less than or equal to the value of
208     // MIN_PROGRAM_TEXEL_OFFSET. The value of MAX_PROGRAM_TEXTURE_GATHER_OFFSET must be greater than
209     // or equal to the value of MAX_PROGRAM_TEXEL_OFFSET"
210     resources->MinProgramTextureGatherOffset = -8;
211     resources->MaxProgramTextureGatherOffset = 7;
212 
213     resources->MaxImageUnits            = 4;
214     resources->MaxVertexImageUniforms   = 0;
215     resources->MaxFragmentImageUniforms = 0;
216     resources->MaxComputeImageUniforms  = 4;
217     resources->MaxCombinedImageUniforms = 4;
218 
219     resources->MaxUniformLocations = 1024;
220 
221     resources->MaxCombinedShaderOutputResources = 4;
222 
223     resources->MaxComputeWorkGroupCount[0] = 65535;
224     resources->MaxComputeWorkGroupCount[1] = 65535;
225     resources->MaxComputeWorkGroupCount[2] = 65535;
226     resources->MaxComputeWorkGroupSize[0]  = 128;
227     resources->MaxComputeWorkGroupSize[1]  = 128;
228     resources->MaxComputeWorkGroupSize[2]  = 64;
229     resources->MaxComputeUniformComponents = 512;
230     resources->MaxComputeTextureImageUnits = 16;
231 
232     resources->MaxComputeAtomicCounters       = 8;
233     resources->MaxComputeAtomicCounterBuffers = 1;
234 
235     resources->MaxVertexAtomicCounters   = 0;
236     resources->MaxFragmentAtomicCounters = 0;
237     resources->MaxCombinedAtomicCounters = 8;
238     resources->MaxAtomicCounterBindings  = 1;
239 
240     resources->MaxVertexAtomicCounterBuffers   = 0;
241     resources->MaxFragmentAtomicCounterBuffers = 0;
242     resources->MaxCombinedAtomicCounterBuffers = 1;
243     resources->MaxAtomicCounterBufferSize      = 32;
244 
245     resources->MaxUniformBufferBindings       = 32;
246     resources->MaxShaderStorageBufferBindings = 4;
247 
248     resources->MaxGeometryUniformComponents     = 1024;
249     resources->MaxGeometryUniformBlocks         = 12;
250     resources->MaxGeometryInputComponents       = 64;
251     resources->MaxGeometryOutputComponents      = 64;
252     resources->MaxGeometryOutputVertices        = 256;
253     resources->MaxGeometryTotalOutputComponents = 1024;
254     resources->MaxGeometryTextureImageUnits     = 16;
255     resources->MaxGeometryAtomicCounterBuffers  = 0;
256     resources->MaxGeometryAtomicCounters        = 0;
257     resources->MaxGeometryShaderStorageBlocks   = 0;
258     resources->MaxGeometryShaderInvocations     = 32;
259     resources->MaxGeometryImageUniforms         = 0;
260 
261     resources->SubPixelBits = 8;
262 }
263 
264 //
265 // Driver calls these to create and destroy compiler objects.
266 //
ConstructCompiler(sh::GLenum type,ShShaderSpec spec,ShShaderOutput output,const ShBuiltInResources * resources)267 ShHandle ConstructCompiler(sh::GLenum type,
268                            ShShaderSpec spec,
269                            ShShaderOutput output,
270                            const ShBuiltInResources *resources)
271 {
272     TShHandleBase *base = static_cast<TShHandleBase *>(ConstructCompiler(type, spec, output));
273     if (base == nullptr)
274     {
275         return 0;
276     }
277 
278     TCompiler *compiler = base->getAsCompiler();
279     if (compiler == nullptr)
280     {
281         return 0;
282     }
283 
284     // Generate built-in symbol table.
285     if (!compiler->Init(*resources))
286     {
287         Destruct(base);
288         return 0;
289     }
290 
291     return base;
292 }
293 
Destruct(ShHandle handle)294 void Destruct(ShHandle handle)
295 {
296     if (handle == 0)
297         return;
298 
299     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
300 
301     if (base->getAsCompiler())
302         DeleteCompiler(base->getAsCompiler());
303 }
304 
GetBuiltInResourcesString(const ShHandle handle)305 const std::string &GetBuiltInResourcesString(const ShHandle handle)
306 {
307     TCompiler *compiler = GetCompilerFromHandle(handle);
308     ASSERT(compiler);
309     return compiler->getBuiltInResourcesString();
310 }
311 
312 //
313 // Do an actual compile on the given strings.  The result is left
314 // in the given compile object.
315 //
316 // Return:  The return value of ShCompile is really boolean, indicating
317 // success or failure.
318 //
Compile(const ShHandle handle,const char * const shaderStrings[],size_t numStrings,ShCompileOptions compileOptions)319 bool Compile(const ShHandle handle,
320              const char *const shaderStrings[],
321              size_t numStrings,
322              ShCompileOptions compileOptions)
323 {
324     TCompiler *compiler = GetCompilerFromHandle(handle);
325     ASSERT(compiler);
326 
327     return compiler->compile(shaderStrings, numStrings, compileOptions);
328 }
329 
ClearResults(const ShHandle handle)330 void ClearResults(const ShHandle handle)
331 {
332     TCompiler *compiler = GetCompilerFromHandle(handle);
333     ASSERT(compiler);
334     compiler->clearResults();
335 }
336 
GetShaderVersion(const ShHandle handle)337 int GetShaderVersion(const ShHandle handle)
338 {
339     TCompiler *compiler = GetCompilerFromHandle(handle);
340     ASSERT(compiler);
341     return compiler->getShaderVersion();
342 }
343 
GetShaderOutputType(const ShHandle handle)344 ShShaderOutput GetShaderOutputType(const ShHandle handle)
345 {
346     TCompiler *compiler = GetCompilerFromHandle(handle);
347     ASSERT(compiler);
348     return compiler->getOutputType();
349 }
350 
351 //
352 // Return any compiler log of messages for the application.
353 //
GetInfoLog(const ShHandle handle)354 const std::string &GetInfoLog(const ShHandle handle)
355 {
356     TCompiler *compiler = GetCompilerFromHandle(handle);
357     ASSERT(compiler);
358 
359     TInfoSink &infoSink = compiler->getInfoSink();
360     return infoSink.info.str();
361 }
362 
363 //
364 // Return any object code.
365 //
GetObjectCode(const ShHandle handle)366 const std::string &GetObjectCode(const ShHandle handle)
367 {
368     TCompiler *compiler = GetCompilerFromHandle(handle);
369     ASSERT(compiler);
370 
371     TInfoSink &infoSink = compiler->getInfoSink();
372     return infoSink.obj.str();
373 }
374 
GetNameHashingMap(const ShHandle handle)375 const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle)
376 {
377     TCompiler *compiler = GetCompilerFromHandle(handle);
378     ASSERT(compiler);
379     return &(compiler->getNameMap());
380 }
381 
GetUniforms(const ShHandle handle)382 const std::vector<ShaderVariable> *GetUniforms(const ShHandle handle)
383 {
384     TCompiler *compiler = GetCompilerFromHandle(handle);
385     if (!compiler)
386     {
387         return nullptr;
388     }
389     return &compiler->getUniforms();
390 }
391 
GetInputVaryings(const ShHandle handle)392 const std::vector<ShaderVariable> *GetInputVaryings(const ShHandle handle)
393 {
394     TCompiler *compiler = GetCompilerFromHandle(handle);
395     if (compiler == nullptr)
396     {
397         return nullptr;
398     }
399     return &compiler->getInputVaryings();
400 }
401 
GetOutputVaryings(const ShHandle handle)402 const std::vector<ShaderVariable> *GetOutputVaryings(const ShHandle handle)
403 {
404     TCompiler *compiler = GetCompilerFromHandle(handle);
405     if (compiler == nullptr)
406     {
407         return nullptr;
408     }
409     return &compiler->getOutputVaryings();
410 }
411 
GetVaryings(const ShHandle handle)412 const std::vector<ShaderVariable> *GetVaryings(const ShHandle handle)
413 {
414     TCompiler *compiler = GetCompilerFromHandle(handle);
415     if (compiler == nullptr)
416     {
417         return nullptr;
418     }
419 
420     switch (compiler->getShaderType())
421     {
422         case GL_VERTEX_SHADER:
423             return &compiler->getOutputVaryings();
424         case GL_FRAGMENT_SHADER:
425             return &compiler->getInputVaryings();
426         case GL_COMPUTE_SHADER:
427             ASSERT(compiler->getOutputVaryings().empty() && compiler->getInputVaryings().empty());
428             return &compiler->getOutputVaryings();
429         // Since geometry shaders have both input and output varyings, we shouldn't call GetVaryings
430         // on a geometry shader.
431         default:
432             return nullptr;
433     }
434 }
435 
GetAttributes(const ShHandle handle)436 const std::vector<ShaderVariable> *GetAttributes(const ShHandle handle)
437 {
438     TCompiler *compiler = GetCompilerFromHandle(handle);
439     if (!compiler)
440     {
441         return nullptr;
442     }
443     return &compiler->getAttributes();
444 }
445 
GetOutputVariables(const ShHandle handle)446 const std::vector<ShaderVariable> *GetOutputVariables(const ShHandle handle)
447 {
448     TCompiler *compiler = GetCompilerFromHandle(handle);
449     if (!compiler)
450     {
451         return nullptr;
452     }
453     return &compiler->getOutputVariables();
454 }
455 
GetInterfaceBlocks(const ShHandle handle)456 const std::vector<InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle)
457 {
458     return GetShaderVariables<InterfaceBlock>(handle);
459 }
460 
GetUniformBlocks(const ShHandle handle)461 const std::vector<InterfaceBlock> *GetUniformBlocks(const ShHandle handle)
462 {
463     ASSERT(handle);
464     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
465     TCompiler *compiler = base->getAsCompiler();
466     ASSERT(compiler);
467 
468     return &compiler->getUniformBlocks();
469 }
470 
GetShaderStorageBlocks(const ShHandle handle)471 const std::vector<InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle)
472 {
473     ASSERT(handle);
474     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
475     TCompiler *compiler = base->getAsCompiler();
476     ASSERT(compiler);
477 
478     return &compiler->getShaderStorageBlocks();
479 }
480 
GetComputeShaderLocalGroupSize(const ShHandle handle)481 WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle)
482 {
483     ASSERT(handle);
484 
485     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
486     TCompiler *compiler = base->getAsCompiler();
487     ASSERT(compiler);
488 
489     return compiler->getComputeShaderLocalSize();
490 }
491 
GetVertexShaderNumViews(const ShHandle handle)492 int GetVertexShaderNumViews(const ShHandle handle)
493 {
494     ASSERT(handle);
495     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
496     TCompiler *compiler = base->getAsCompiler();
497     ASSERT(compiler);
498 
499     return compiler->getNumViews();
500 }
501 
HasEarlyFragmentTestsOptimization(const ShHandle handle)502 bool HasEarlyFragmentTestsOptimization(const ShHandle handle)
503 {
504     TCompiler *compiler = GetCompilerFromHandle(handle);
505     if (compiler == nullptr)
506     {
507         return false;
508     }
509     return compiler->isEarlyFragmentTestsOptimized();
510 }
511 
CheckVariablesWithinPackingLimits(int maxVectors,const std::vector<ShaderVariable> & variables)512 bool CheckVariablesWithinPackingLimits(int maxVectors, const std::vector<ShaderVariable> &variables)
513 {
514     return CheckVariablesInPackingLimits(maxVectors, variables);
515 }
516 
GetShaderStorageBlockRegister(const ShHandle handle,const std::string & shaderStorageBlockName,unsigned int * indexOut)517 bool GetShaderStorageBlockRegister(const ShHandle handle,
518                                    const std::string &shaderStorageBlockName,
519                                    unsigned int *indexOut)
520 {
521 #ifdef ANGLE_ENABLE_HLSL
522     ASSERT(indexOut);
523 
524     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
525     ASSERT(translator);
526 
527     if (!translator->hasShaderStorageBlock(shaderStorageBlockName))
528     {
529         return false;
530     }
531 
532     *indexOut = translator->getShaderStorageBlockRegister(shaderStorageBlockName);
533     return true;
534 #else
535     return false;
536 #endif  // ANGLE_ENABLE_HLSL
537 }
538 
GetUniformBlockRegister(const ShHandle handle,const std::string & uniformBlockName,unsigned int * indexOut)539 bool GetUniformBlockRegister(const ShHandle handle,
540                              const std::string &uniformBlockName,
541                              unsigned int *indexOut)
542 {
543 #ifdef ANGLE_ENABLE_HLSL
544     ASSERT(indexOut);
545 
546     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
547     ASSERT(translator);
548 
549     if (!translator->hasUniformBlock(uniformBlockName))
550     {
551         return false;
552     }
553 
554     *indexOut = translator->getUniformBlockRegister(uniformBlockName);
555     return true;
556 #else
557     return false;
558 #endif  // ANGLE_ENABLE_HLSL
559 }
560 
ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,const std::string & uniformBlockName)561 bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,
562                                            const std::string &uniformBlockName)
563 {
564 #ifdef ANGLE_ENABLE_HLSL
565     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
566     ASSERT(translator);
567 
568     return translator->shouldUniformBlockUseStructuredBuffer(uniformBlockName);
569 #else
570     return false;
571 #endif  // ANGLE_ENABLE_HLSL
572 }
573 
GetUniformRegisterMap(const ShHandle handle)574 const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle)
575 {
576 #ifdef ANGLE_ENABLE_HLSL
577     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
578     ASSERT(translator);
579 
580     return translator->getUniformRegisterMap();
581 #else
582     return nullptr;
583 #endif  // ANGLE_ENABLE_HLSL
584 }
585 
GetReadonlyImage2DRegisterIndex(const ShHandle handle)586 unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle)
587 {
588 #ifdef ANGLE_ENABLE_HLSL
589     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
590     ASSERT(translator);
591 
592     return translator->getReadonlyImage2DRegisterIndex();
593 #else
594     return 0;
595 #endif  // ANGLE_ENABLE_HLSL
596 }
597 
GetImage2DRegisterIndex(const ShHandle handle)598 unsigned int GetImage2DRegisterIndex(const ShHandle handle)
599 {
600 #ifdef ANGLE_ENABLE_HLSL
601     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
602     ASSERT(translator);
603 
604     return translator->getImage2DRegisterIndex();
605 #else
606     return 0;
607 #endif  // ANGLE_ENABLE_HLSL
608 }
609 
GetUsedImage2DFunctionNames(const ShHandle handle)610 const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle)
611 {
612 #ifdef ANGLE_ENABLE_HLSL
613     TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
614     ASSERT(translator);
615 
616     return translator->getUsedImage2DFunctionNames();
617 #else
618     return nullptr;
619 #endif  // ANGLE_ENABLE_HLSL
620 }
621 
HasValidGeometryShaderInputPrimitiveType(const ShHandle handle)622 bool HasValidGeometryShaderInputPrimitiveType(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->getGeometryShaderInputPrimitiveType() != EptUndefined;
631 }
632 
HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle)633 bool HasValidGeometryShaderOutputPrimitiveType(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->getGeometryShaderOutputPrimitiveType() != EptUndefined;
642 }
643 
HasValidGeometryShaderMaxVertices(const ShHandle handle)644 bool HasValidGeometryShaderMaxVertices(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 compiler->getGeometryShaderMaxVertices() >= 0;
653 }
654 
GetGeometryShaderInputPrimitiveType(const ShHandle handle)655 GLenum GetGeometryShaderInputPrimitiveType(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->getGeometryShaderInputPrimitiveType());
664 }
665 
GetGeometryShaderOutputPrimitiveType(const ShHandle handle)666 GLenum GetGeometryShaderOutputPrimitiveType(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 GetGeometryShaderPrimitiveTypeEnum(compiler->getGeometryShaderOutputPrimitiveType());
675 }
676 
GetGeometryShaderInvocations(const ShHandle handle)677 int GetGeometryShaderInvocations(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     return compiler->getGeometryShaderInvocations();
686 }
687 
GetGeometryShaderMaxVertices(const ShHandle handle)688 int GetGeometryShaderMaxVertices(const ShHandle handle)
689 {
690     ASSERT(handle);
691 
692     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
693     TCompiler *compiler = base->getAsCompiler();
694     ASSERT(compiler);
695 
696     int maxVertices = compiler->getGeometryShaderMaxVertices();
697     ASSERT(maxVertices >= 0);
698     return maxVertices;
699 }
700 
GetShaderSharedMemorySize(const ShHandle handle)701 unsigned int GetShaderSharedMemorySize(const ShHandle handle)
702 {
703     ASSERT(handle);
704 
705     TShHandleBase *base = static_cast<TShHandleBase *>(handle);
706     TCompiler *compiler = base->getAsCompiler();
707     ASSERT(compiler);
708 
709     unsigned int sharedMemorySize = compiler->getSharedMemorySize();
710     return sharedMemorySize;
711 }
712 
713 // Can't prefix with just _ because then we might introduce a double underscore, which is not safe
714 // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
715 // use by the underlying implementation). u is short for user-defined.
716 const char kUserDefinedNamePrefix[] = "_u";
717 
718 namespace vk
719 {
720 // Interface block name containing the aggregate default uniforms
721 const char kDefaultUniformsNameVS[]  = "defaultUniformsVS";
722 const char kDefaultUniformsNameTCS[] = "defaultUniformsTCS";
723 const char kDefaultUniformsNameTES[] = "defaultUniformsTES";
724 const char kDefaultUniformsNameGS[]  = "defaultUniformsGS";
725 const char kDefaultUniformsNameFS[]  = "defaultUniformsFS";
726 const char kDefaultUniformsNameCS[]  = "defaultUniformsCS";
727 
728 // Interface block and variable names containing driver uniforms
729 const char kDriverUniformsBlockName[] = "ANGLEUniformBlock";
730 const char kDriverUniformsVarName[]   = "ANGLEUniforms";
731 
732 // Interface block array name used for atomic counter emulation
733 const char kAtomicCountersBlockName[] = "ANGLEAtomicCounters";
734 
735 const char kLineRasterEmulationPosition[] = "ANGLEPosition";
736 
737 }  // namespace vk
738 
739 }  // namespace sh
740