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 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 ShaderTranslator::DestructionObserver::DestructionObserver() { | 93 ShaderTranslator::DestructionObserver::DestructionObserver() { |
94 } | 94 } |
95 | 95 |
96 ShaderTranslator::DestructionObserver::~DestructionObserver() { | 96 ShaderTranslator::DestructionObserver::~DestructionObserver() { |
97 } | 97 } |
98 | 98 |
99 ShaderTranslator::ShaderTranslator() | 99 ShaderTranslator::ShaderTranslator() |
100 : compiler_(NULL), | 100 : compiler_(NULL), |
101 implementation_is_glsl_es_(false), | |
102 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { | 101 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { |
103 } | 102 } |
104 | 103 |
105 bool ShaderTranslator::Init( | 104 bool ShaderTranslator::Init(GLenum shader_type, |
106 GLenum shader_type, | 105 ShShaderSpec shader_spec, |
107 ShShaderSpec shader_spec, | 106 const ShBuiltInResources* resources, |
108 const ShBuiltInResources* resources, | 107 ShShaderOutput shader_output_language, |
109 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, | 108 ShCompileOptions driver_bug_workarounds) { |
110 ShCompileOptions driver_bug_workarounds) { | |
111 // Make sure Init is called only once. | 109 // Make sure Init is called only once. |
112 DCHECK(compiler_ == NULL); | 110 DCHECK(compiler_ == NULL); |
113 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER); | 111 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER); |
114 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC || | 112 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC || |
115 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC); | 113 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC); |
116 DCHECK(resources != NULL); | 114 DCHECK(resources != NULL); |
117 | 115 |
118 g_translator_initializer.Get(); | 116 g_translator_initializer.Get(); |
119 | 117 |
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 | 118 |
135 { | 119 { |
136 TRACE_EVENT0("gpu", "ShConstructCompiler"); | 120 TRACE_EVENT0("gpu", "ShConstructCompiler"); |
137 compiler_ = ShConstructCompiler( | 121 compiler_ = ShConstructCompiler(shader_type, shader_spec, |
138 shader_type, shader_spec, shader_output, resources); | 122 shader_output_language, resources); |
139 } | 123 } |
140 implementation_is_glsl_es_ = (glsl_implementation_type == kGlslES); | |
141 driver_bug_workarounds_ = driver_bug_workarounds; | 124 driver_bug_workarounds_ = driver_bug_workarounds; |
142 return compiler_ != NULL; | 125 return compiler_ != NULL; |
143 } | 126 } |
144 | 127 |
145 int ShaderTranslator::GetCompileOptions() const { | 128 int ShaderTranslator::GetCompileOptions() const { |
146 int compile_options = | 129 int compile_options = |
147 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS | | 130 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS | |
148 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | | 131 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | |
149 SH_CLAMP_INDIRECT_ARRAY_BOUNDS; | 132 SH_CLAMP_INDIRECT_ARRAY_BOUNDS; |
150 | 133 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 destruction_observers_, | 207 destruction_observers_, |
225 OnDestruct(this)); | 208 OnDestruct(this)); |
226 | 209 |
227 if (compiler_ != NULL) | 210 if (compiler_ != NULL) |
228 ShDestruct(compiler_); | 211 ShDestruct(compiler_); |
229 } | 212 } |
230 | 213 |
231 } // namespace gles2 | 214 } // namespace gles2 |
232 } // namespace gpu | 215 } // namespace gpu |
233 | 216 |
OLD | NEW |