• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 // ExtensionGLSL.cpp: Implements the TExtensionGLSL class that tracks GLSL extension requirements
7 // of shaders.
8 
9 #include "compiler/translator/ExtensionGLSL.h"
10 
11 #include "compiler/translator/VersionGLSL.h"
12 
13 namespace sh
14 {
15 
TExtensionGLSL(ShShaderOutput output)16 TExtensionGLSL::TExtensionGLSL(ShShaderOutput output)
17     : TIntermTraverser(true, false, false), mTargetVersion(ShaderOutputTypeToGLSLVersion(output))
18 {}
19 
getEnabledExtensions() const20 const std::set<std::string> &TExtensionGLSL::getEnabledExtensions() const
21 {
22     return mEnabledExtensions;
23 }
24 
getRequiredExtensions() const25 const std::set<std::string> &TExtensionGLSL::getRequiredExtensions() const
26 {
27     return mRequiredExtensions;
28 }
29 
visitUnary(Visit,TIntermUnary * node)30 bool TExtensionGLSL::visitUnary(Visit, TIntermUnary *node)
31 {
32     checkOperator(node);
33 
34     return true;
35 }
36 
visitAggregate(Visit,TIntermAggregate * node)37 bool TExtensionGLSL::visitAggregate(Visit, TIntermAggregate *node)
38 {
39     checkOperator(node);
40 
41     return true;
42 }
43 
checkOperator(TIntermOperator * node)44 void TExtensionGLSL::checkOperator(TIntermOperator *node)
45 {
46     if (mTargetVersion < GLSL_VERSION_130)
47     {
48         return;
49     }
50 
51     switch (node->getOp())
52     {
53         case EOpAbs:
54             break;
55 
56         case EOpSign:
57             break;
58 
59         case EOpMix:
60             break;
61 
62         case EOpFloatBitsToInt:
63         case EOpFloatBitsToUint:
64         case EOpIntBitsToFloat:
65         case EOpUintBitsToFloat:
66             if (mTargetVersion < GLSL_VERSION_330)
67             {
68                 // Bit conversion functions cannot be emulated.
69                 mRequiredExtensions.insert("GL_ARB_shader_bit_encoding");
70             }
71             break;
72 
73         case EOpPackSnorm2x16:
74         case EOpPackHalf2x16:
75         case EOpUnpackSnorm2x16:
76         case EOpUnpackHalf2x16:
77             if (mTargetVersion < GLSL_VERSION_420)
78             {
79                 mEnabledExtensions.insert("GL_ARB_shading_language_packing");
80 
81                 if (mTargetVersion < GLSL_VERSION_330)
82                 {
83                     // floatBitsToUint and uintBitsToFloat are needed to emulate
84                     // packHalf2x16 and unpackHalf2x16 respectively and cannot be
85                     // emulated themselves.
86                     mRequiredExtensions.insert("GL_ARB_shader_bit_encoding");
87                 }
88             }
89             break;
90 
91         case EOpPackUnorm2x16:
92         case EOpUnpackUnorm2x16:
93             if (mTargetVersion < GLSL_VERSION_410)
94             {
95                 mEnabledExtensions.insert("GL_ARB_shading_language_packing");
96             }
97             break;
98 
99         default:
100             break;
101     }
102 }
103 
104 }  // namespace sh
105