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 #include "compiler/translator/Initialize.h"
8 
9 namespace sh
10 {
11 
InitExtensionBehavior(const ShBuiltInResources & resources,TExtensionBehavior & extBehavior)12 void InitExtensionBehavior(const ShBuiltInResources &resources, TExtensionBehavior &extBehavior)
13 {
14     if (resources.OES_standard_derivatives)
15     {
16         extBehavior[TExtension::OES_standard_derivatives] = EBhUndefined;
17     }
18     if (resources.OES_EGL_image_external)
19     {
20         extBehavior[TExtension::OES_EGL_image_external] = EBhUndefined;
21     }
22     if (resources.OES_EGL_image_external_essl3)
23     {
24         extBehavior[TExtension::OES_EGL_image_external_essl3] = EBhUndefined;
25     }
26     if (resources.NV_EGL_stream_consumer_external)
27     {
28         extBehavior[TExtension::NV_EGL_stream_consumer_external] = EBhUndefined;
29     }
30     if (resources.ARB_texture_rectangle)
31     {
32         // Special: ARB_texture_rectangle extension does not follow the standard for #extension
33         // directives - it is enabled by default. An extension directive may still disable it.
34         extBehavior[TExtension::ARB_texture_rectangle] = EBhEnable;
35     }
36     if (resources.EXT_blend_func_extended)
37     {
38         extBehavior[TExtension::EXT_blend_func_extended] = EBhUndefined;
39     }
40     if (resources.EXT_draw_buffers)
41     {
42         extBehavior[TExtension::EXT_draw_buffers] = EBhUndefined;
43     }
44     if (resources.EXT_frag_depth)
45     {
46         extBehavior[TExtension::EXT_frag_depth] = EBhUndefined;
47     }
48     if (resources.EXT_shader_texture_lod)
49     {
50         extBehavior[TExtension::EXT_shader_texture_lod] = EBhUndefined;
51     }
52     if (resources.EXT_shader_framebuffer_fetch)
53     {
54         extBehavior[TExtension::EXT_shader_framebuffer_fetch] = EBhUndefined;
55     }
56     if (resources.NV_shader_framebuffer_fetch)
57     {
58         extBehavior[TExtension::NV_shader_framebuffer_fetch] = EBhUndefined;
59     }
60     if (resources.NV_shader_noperspective_interpolation)
61     {
62         extBehavior[TExtension::NV_shader_noperspective_interpolation] = EBhUndefined;
63     }
64     if (resources.ARM_shader_framebuffer_fetch)
65     {
66         extBehavior[TExtension::ARM_shader_framebuffer_fetch] = EBhUndefined;
67     }
68     if (resources.OVR_multiview)
69     {
70         extBehavior[TExtension::OVR_multiview] = EBhUndefined;
71     }
72     if (resources.OVR_multiview2)
73     {
74         extBehavior[TExtension::OVR_multiview2] = EBhUndefined;
75     }
76     if (resources.EXT_YUV_target)
77     {
78         extBehavior[TExtension::EXT_YUV_target] = EBhUndefined;
79     }
80     if (resources.EXT_geometry_shader)
81     {
82         extBehavior[TExtension::EXT_geometry_shader] = EBhUndefined;
83     }
84     if (resources.EXT_gpu_shader5)
85     {
86         extBehavior[TExtension::EXT_gpu_shader5] = EBhUndefined;
87     }
88     if (resources.EXT_shader_non_constant_global_initializers)
89     {
90         extBehavior[TExtension::EXT_shader_non_constant_global_initializers] = EBhUndefined;
91     }
92     if (resources.OES_texture_storage_multisample_2d_array)
93     {
94         extBehavior[TExtension::OES_texture_storage_multisample_2d_array] = EBhUndefined;
95     }
96     if (resources.OES_texture_3D)
97     {
98         extBehavior[TExtension::OES_texture_3D] = EBhUndefined;
99     }
100     if (resources.ANGLE_texture_multisample)
101     {
102         extBehavior[TExtension::ANGLE_texture_multisample] = EBhUndefined;
103     }
104     if (resources.ANGLE_multi_draw)
105     {
106         extBehavior[TExtension::ANGLE_multi_draw] = EBhUndefined;
107     }
108     if (resources.ANGLE_base_vertex_base_instance)
109     {
110         extBehavior[TExtension::ANGLE_base_vertex_base_instance] = EBhUndefined;
111     }
112     if (resources.WEBGL_video_texture)
113     {
114         extBehavior[TExtension::WEBGL_video_texture] = EBhUndefined;
115     }
116     if (resources.APPLE_clip_distance)
117     {
118         extBehavior[TExtension::APPLE_clip_distance] = EBhUndefined;
119     }
120     if (resources.OES_texture_cube_map_array)
121     {
122         extBehavior[TExtension::OES_texture_cube_map_array] = EBhUndefined;
123     }
124     if (resources.EXT_texture_cube_map_array)
125     {
126         extBehavior[TExtension::EXT_texture_cube_map_array] = EBhUndefined;
127     }
128     if (resources.EXT_shadow_samplers)
129     {
130         extBehavior[TExtension::EXT_shadow_samplers] = EBhUndefined;
131     }
132     if (resources.OES_shader_multisample_interpolation)
133     {
134         extBehavior[TExtension::OES_shader_multisample_interpolation] = EBhUndefined;
135     }
136     if (resources.OES_shader_image_atomic)
137     {
138         extBehavior[TExtension::OES_shader_image_atomic] = EBhUndefined;
139     }
140     if (resources.OES_texture_buffer)
141     {
142         extBehavior[TExtension::OES_texture_buffer] = EBhUndefined;
143     }
144     if (resources.EXT_texture_buffer)
145     {
146         extBehavior[TExtension::EXT_texture_buffer] = EBhUndefined;
147     }
148 }
149 
ResetExtensionBehavior(const ShBuiltInResources & resources,TExtensionBehavior & extBehavior,const ShCompileOptions compileOptions)150 void ResetExtensionBehavior(const ShBuiltInResources &resources,
151                             TExtensionBehavior &extBehavior,
152                             const ShCompileOptions compileOptions)
153 {
154     for (auto &ext : extBehavior)
155     {
156         ext.second = EBhUndefined;
157     }
158     if (resources.ARB_texture_rectangle)
159     {
160         if (compileOptions & SH_DISABLE_ARB_TEXTURE_RECTANGLE)
161         {
162             // Remove ARB_texture_rectangle so it can't be enabled by extension directives.
163             extBehavior.erase(TExtension::ARB_texture_rectangle);
164         }
165         else
166         {
167             // Restore ARB_texture_rectangle in case it was removed during an earlier reset.  As
168             // noted above, it doesn't follow the standard for extension directives and is
169             // enabled by default.
170             extBehavior[TExtension::ARB_texture_rectangle] = EBhEnable;
171         }
172     }
173 }
174 
175 }  // namespace sh
176