blob: 5b5dc580e9a258fc8d7224654cd4058ec1953586 [file] [log] [blame]
Geoff Lang91dbc182015-06-17 16:19:29 -07001//
2// Copyright (c) 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
Jamie Madill45bcc782016-11-07 13:58:48 -050013namespace sh
14{
15
Geoff Lang91dbc182015-06-17 16:19:29 -070016TExtensionGLSL::TExtensionGLSL(ShShaderOutput output)
17 : TIntermTraverser(true, false, false), mTargetVersion(ShaderOutputTypeToGLSLVersion(output))
18{
19}
20
21const std::set<std::string> &TExtensionGLSL::getEnabledExtensions() const
22{
23 return mEnabledExtensions;
24}
25
26const std::set<std::string> &TExtensionGLSL::getRequiredExtensions() const
27{
28 return mRequiredExtensions;
29}
30
31bool TExtensionGLSL::visitUnary(Visit, TIntermUnary *node)
32{
33 checkOperator(node);
34
35 return true;
36}
37
38bool TExtensionGLSL::visitAggregate(Visit, TIntermAggregate *node)
39{
40 checkOperator(node);
41
42 return true;
43}
44
45void TExtensionGLSL::checkOperator(TIntermOperator *node)
46{
47 if (mTargetVersion < GLSL_VERSION_130)
48 {
49 return;
50 }
51
52 switch (node->getOp())
53 {
54 case EOpAbs:
55 break;
56
57 case EOpSign:
58 break;
59
60 case EOpMix:
61 break;
62
63 case EOpFloatBitsToInt:
64 case EOpFloatBitsToUint:
65 case EOpIntBitsToFloat:
66 case EOpUintBitsToFloat:
67 if (mTargetVersion < GLSL_VERSION_330)
68 {
69 // Bit conversion functions cannot be emulated.
70 mRequiredExtensions.insert("GL_ARB_shader_bit_encoding");
71 }
72 break;
73
74 case EOpPackSnorm2x16:
75 case EOpPackHalf2x16:
76 case EOpUnpackSnorm2x16:
77 case EOpUnpackHalf2x16:
78 if (mTargetVersion < GLSL_VERSION_420)
79 {
80 mEnabledExtensions.insert("GL_ARB_shading_language_packing");
81
82 if (mTargetVersion < GLSL_VERSION_330)
83 {
84 // floatBitsToUint and uintBitsToFloat are needed to emulate
85 // packHalf2x16 and unpackHalf2x16 respectively and cannot be
86 // emulated themselves.
87 mRequiredExtensions.insert("GL_ARB_shader_bit_encoding");
88 }
89 }
90 break;
91
92 case EOpPackUnorm2x16:
93 case EOpUnpackUnorm2x16:
94 if (mTargetVersion < GLSL_VERSION_410)
95 {
96 mEnabledExtensions.insert("GL_ARB_shading_language_packing");
97 }
98 break;
99
100 default:
101 break;
102 }
103}
Jamie Madill45bcc782016-11-07 13:58:48 -0500104
105} // namespace sh