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