OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/shader_translator.h" | 5 #include "gpu/command_buffer/service/shader_translator.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "gpu/command_buffer/service/gpu_switches.h" | 17 #include "gpu/command_buffer/service/gpu_switches.h" |
18 #include "ui/gl/gl_implementation.h" | 18 #include "ui/gl/gl_implementation.h" |
| 19 #include "ui/gl/gl_version_info.h" |
19 | 20 |
20 namespace gpu { | 21 namespace gpu { |
21 namespace gles2 { | 22 namespace gles2 { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class ShaderTranslatorInitializer { | 26 class ShaderTranslatorInitializer { |
26 public: | 27 public: |
27 ShaderTranslatorInitializer() { | 28 ShaderTranslatorInitializer() { |
28 TRACE_EVENT0("gpu", "ShInitialize"); | 29 TRACE_EVENT0("gpu", "ShInitialize"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 for (NameMapANGLE::const_iterator iter = angle_map->begin(); | 84 for (NameMapANGLE::const_iterator iter = angle_map->begin(); |
84 iter != angle_map->end(); ++iter) { | 85 iter != angle_map->end(); ++iter) { |
85 // Note that in ANGLE, the map is (original_name, hash); | 86 // Note that in ANGLE, the map is (original_name, hash); |
86 // here, we want (hash, original_name). | 87 // here, we want (hash, original_name). |
87 (*name_map)[iter->second] = iter->first; | 88 (*name_map)[iter->second] = iter->first; |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
91 } // namespace | 92 } // namespace |
92 | 93 |
| 94 ShShaderOutput ShaderTranslator::GetShaderOutputLanguageForContext( |
| 95 const gfx::GLVersionInfo& version_info) { |
| 96 if (version_info.is_es) { |
| 97 return SH_ESSL_OUTPUT; |
| 98 } |
| 99 |
| 100 // Determine the GLSL version based on OpenGL specification. |
| 101 |
| 102 unsigned context_version = |
| 103 version_info.major_version * 100 + version_info.minor_version * 10; |
| 104 if (context_version >= 450) { |
| 105 // OpenGL specs from 4.2 on specify that the core profile is "also |
| 106 // guaranteed to support all previous versions of the OpenGL Shading |
| 107 // Language back to version 1.40". For simplicity, we assume future |
| 108 // specs do not unspecify this. If they did, they could unspecify |
| 109 // glGetStringi(GL_SHADING_LANGUAGE_VERSION, k), too. |
| 110 // Since current context >= 4.5, use GLSL 4.50 core. |
| 111 return SH_GLSL_450_CORE_OUTPUT; |
| 112 } else if (context_version == 440) { |
| 113 return SH_GLSL_440_CORE_OUTPUT; |
| 114 } else if (context_version == 430) { |
| 115 return SH_GLSL_430_CORE_OUTPUT; |
| 116 } else if (context_version == 420) { |
| 117 return SH_GLSL_420_CORE_OUTPUT; |
| 118 } else if (context_version == 410) { |
| 119 return SH_GLSL_410_CORE_OUTPUT; |
| 120 } else if (context_version == 400) { |
| 121 return SH_GLSL_400_CORE_OUTPUT; |
| 122 } else if (context_version == 330) { |
| 123 return SH_GLSL_330_CORE_OUTPUT; |
| 124 } else if (context_version == 320) { |
| 125 return SH_GLSL_150_CORE_OUTPUT; |
| 126 } else if (context_version == 310) { |
| 127 return SH_GLSL_140_OUTPUT; |
| 128 } else if (context_version == 300) { |
| 129 return SH_GLSL_130_OUTPUT; |
| 130 } |
| 131 |
| 132 // Before OpenGL 3.0 we use compatibility profile. Also for future |
| 133 // specs between OpenGL 3.3 and OpenGL 4.0, at the time of writing, |
| 134 // we use compatibility profile. |
| 135 return SH_GLSL_COMPATIBILITY_OUTPUT; |
| 136 } |
| 137 |
93 ShaderTranslator::DestructionObserver::DestructionObserver() { | 138 ShaderTranslator::DestructionObserver::DestructionObserver() { |
94 } | 139 } |
95 | 140 |
96 ShaderTranslator::DestructionObserver::~DestructionObserver() { | 141 ShaderTranslator::DestructionObserver::~DestructionObserver() { |
97 } | 142 } |
98 | 143 |
99 ShaderTranslator::ShaderTranslator() | 144 ShaderTranslator::ShaderTranslator() |
100 : compiler_(NULL), | 145 : compiler_(NULL), |
101 implementation_is_glsl_es_(false), | |
102 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { | 146 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { |
103 } | 147 } |
104 | 148 |
105 bool ShaderTranslator::Init( | 149 bool ShaderTranslator::Init(GLenum shader_type, |
106 GLenum shader_type, | 150 ShShaderSpec shader_spec, |
107 ShShaderSpec shader_spec, | 151 const ShBuiltInResources* resources, |
108 const ShBuiltInResources* resources, | 152 ShShaderOutput shader_output_language, |
109 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, | 153 ShCompileOptions driver_bug_workarounds) { |
110 ShCompileOptions driver_bug_workarounds) { | |
111 // Make sure Init is called only once. | 154 // Make sure Init is called only once. |
112 DCHECK(compiler_ == NULL); | 155 DCHECK(compiler_ == NULL); |
113 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER); | 156 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER); |
114 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC || | 157 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC || |
115 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC); | 158 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC); |
116 DCHECK(resources != NULL); | 159 DCHECK(resources != NULL); |
117 | 160 |
118 g_translator_initializer.Get(); | 161 g_translator_initializer.Get(); |
119 | 162 |
120 ShShaderOutput shader_output; | |
121 if (glsl_implementation_type == kGlslES) { | |
122 shader_output = SH_ESSL_OUTPUT; | |
123 } else { | |
124 // TODO(kbr): clean up the tests of shader_spec and | |
125 // gfx::GetGLImplementation(). crbug.com/471960 | |
126 if (shader_spec == SH_WEBGL2_SPEC || | |
127 gfx::GetGLImplementation() == | |
128 gfx::kGLImplementationDesktopGLCoreProfile) { | |
129 shader_output = SH_GLSL_410_CORE_OUTPUT; | |
130 } else { | |
131 shader_output = SH_GLSL_COMPATIBILITY_OUTPUT; | |
132 } | |
133 } | |
134 | 163 |
135 { | 164 { |
136 TRACE_EVENT0("gpu", "ShConstructCompiler"); | 165 TRACE_EVENT0("gpu", "ShConstructCompiler"); |
137 compiler_ = ShConstructCompiler( | 166 compiler_ = ShConstructCompiler(shader_type, shader_spec, |
138 shader_type, shader_spec, shader_output, resources); | 167 shader_output_language, resources); |
139 } | 168 } |
140 implementation_is_glsl_es_ = (glsl_implementation_type == kGlslES); | |
141 driver_bug_workarounds_ = driver_bug_workarounds; | 169 driver_bug_workarounds_ = driver_bug_workarounds; |
142 return compiler_ != NULL; | 170 return compiler_ != NULL; |
143 } | 171 } |
144 | 172 |
145 int ShaderTranslator::GetCompileOptions() const { | 173 int ShaderTranslator::GetCompileOptions() const { |
146 int compile_options = | 174 int compile_options = |
147 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS | | 175 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS | |
148 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | | 176 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | |
149 SH_CLAMP_INDIRECT_ARRAY_BOUNDS; | 177 SH_CLAMP_INDIRECT_ARRAY_BOUNDS; |
150 | 178 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 destruction_observers_, | 252 destruction_observers_, |
225 OnDestruct(this)); | 253 OnDestruct(this)); |
226 | 254 |
227 if (compiler_ != NULL) | 255 if (compiler_ != NULL) |
228 ShDestruct(compiler_); | 256 ShDestruct(compiler_); |
229 } | 257 } |
230 | 258 |
231 } // namespace gles2 | 259 } // namespace gles2 |
232 } // namespace gpu | 260 } // namespace gpu |
233 | 261 |
OLD | NEW |