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