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 <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 ShaderTranslator::DestructionObserver::DestructionObserver() { | 112 ShaderTranslator::DestructionObserver::DestructionObserver() { |
113 } | 113 } |
114 | 114 |
115 ShaderTranslator::DestructionObserver::~DestructionObserver() { | 115 ShaderTranslator::DestructionObserver::~DestructionObserver() { |
116 } | 116 } |
117 | 117 |
118 ShaderTranslator::ShaderTranslator() | 118 ShaderTranslator::ShaderTranslator() |
119 : compiler_(NULL), | 119 : compiler_(NULL), |
120 implementation_is_glsl_es_(false), | 120 implementation_is_glsl_es_(false), |
121 needs_built_in_function_emulation_(false) { | 121 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { |
122 } | 122 } |
123 | 123 |
124 bool ShaderTranslator::Init( | 124 bool ShaderTranslator::Init( |
125 ShShaderType shader_type, | 125 ShShaderType shader_type, |
126 ShShaderSpec shader_spec, | 126 ShShaderSpec shader_spec, |
127 const ShBuiltInResources* resources, | 127 const ShBuiltInResources* resources, |
128 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, | 128 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, |
129 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior | 129 ShCompileOptions driver_bug_workarounds) { |
130 glsl_built_in_function_behavior) { | |
131 // Make sure Init is called only once. | 130 // Make sure Init is called only once. |
132 DCHECK(compiler_ == NULL); | 131 DCHECK(compiler_ == NULL); |
133 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER); | 132 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER); |
134 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC); | 133 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC); |
135 DCHECK(resources != NULL); | 134 DCHECK(resources != NULL); |
136 | 135 |
137 if (!InitializeShaderTranslator()) | 136 if (!InitializeShaderTranslator()) |
138 return false; | 137 return false; |
139 | 138 |
140 ShShaderOutput shader_output = | 139 ShShaderOutput shader_output = |
141 (glsl_implementation_type == kGlslES ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT); | 140 (glsl_implementation_type == kGlslES ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT); |
142 | 141 |
143 { | 142 { |
144 TRACE_EVENT0("gpu", "ShConstructCompiler"); | 143 TRACE_EVENT0("gpu", "ShConstructCompiler"); |
145 compiler_ = ShConstructCompiler( | 144 compiler_ = ShConstructCompiler( |
146 shader_type, shader_spec, shader_output, resources); | 145 shader_type, shader_spec, shader_output, resources); |
147 } | 146 } |
148 compiler_options_ = *resources; | 147 compiler_options_ = *resources; |
149 implementation_is_glsl_es_ = (glsl_implementation_type == kGlslES); | 148 implementation_is_glsl_es_ = (glsl_implementation_type == kGlslES); |
150 needs_built_in_function_emulation_ = | 149 driver_bug_workarounds_ = driver_bug_workarounds; |
151 (glsl_built_in_function_behavior == kGlslBuiltInFunctionEmulated); | |
152 return compiler_ != NULL; | 150 return compiler_ != NULL; |
153 } | 151 } |
154 | 152 |
155 int ShaderTranslator::GetCompileOptions() const { | 153 int ShaderTranslator::GetCompileOptions() const { |
156 int compile_options = | 154 int compile_options = |
157 SH_OBJECT_CODE | SH_VARIABLES | | 155 SH_OBJECT_CODE | SH_VARIABLES | |
158 SH_MAP_LONG_VARIABLE_NAMES | SH_ENFORCE_PACKING_RESTRICTIONS | | 156 SH_MAP_LONG_VARIABLE_NAMES | SH_ENFORCE_PACKING_RESTRICTIONS | |
159 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH; | 157 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH; |
160 | 158 |
161 compile_options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS; | 159 compile_options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS; |
162 | 160 |
163 if (needs_built_in_function_emulation_) | 161 compile_options |= driver_bug_workarounds_; |
164 compile_options |= SH_EMULATE_BUILT_IN_FUNCTIONS; | |
165 | 162 |
166 return compile_options; | 163 return compile_options; |
167 } | 164 } |
168 | 165 |
169 bool ShaderTranslator::Translate(const char* shader) { | 166 bool ShaderTranslator::Translate(const char* shader) { |
170 // Make sure this instance is initialized. | 167 // Make sure this instance is initialized. |
171 DCHECK(compiler_ != NULL); | 168 DCHECK(compiler_ != NULL); |
172 DCHECK(shader != NULL); | 169 DCHECK(shader != NULL); |
173 ClearResults(); | 170 ClearResults(); |
174 | 171 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 info_log_.reset(); | 311 info_log_.reset(); |
315 attrib_map_.clear(); | 312 attrib_map_.clear(); |
316 uniform_map_.clear(); | 313 uniform_map_.clear(); |
317 varying_map_.clear(); | 314 varying_map_.clear(); |
318 name_map_.clear(); | 315 name_map_.clear(); |
319 } | 316 } |
320 | 317 |
321 } // namespace gles2 | 318 } // namespace gles2 |
322 } // namespace gpu | 319 } // namespace gpu |
323 | 320 |
OLD | NEW |