Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1432)

Side by Side Diff: gpu/command_buffer/service/shader_translator.cc

Issue 2852923004: Remove NameMap from shader translator and shader/program managers (Closed)
Patch Set: split CL Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <string.h> 9 #include <string.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 var_map->clear(); 83 var_map->clear();
84 const std::vector<sh::InterfaceBlock>* interface_blocks = 84 const std::vector<sh::InterfaceBlock>* interface_blocks =
85 sh::GetInterfaceBlocks(compiler); 85 sh::GetInterfaceBlocks(compiler);
86 if (interface_blocks) { 86 if (interface_blocks) {
87 for (const auto& block : *interface_blocks) { 87 for (const auto& block : *interface_blocks) {
88 (*var_map)[block.mappedName] = block; 88 (*var_map)[block.mappedName] = block;
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 void GetNameHashingInfo(ShHandle compiler, NameMap* name_map) {
94 if (!name_map)
95 return;
96 name_map->clear();
97
98 typedef std::map<std::string, std::string> NameMapANGLE;
99 const NameMapANGLE* angle_map = sh::GetNameHashingMap(compiler);
100 DCHECK(angle_map);
101
102 for (NameMapANGLE::const_iterator iter = angle_map->begin();
103 iter != angle_map->end(); ++iter) {
104 // Note that in ANGLE, the map is (original_name, hash);
105 // here, we want (hash, original_name).
106 (*name_map)[iter->second] = iter->first;
107 }
108 }
109
110 } // namespace 93 } // namespace
111 94
112 ShShaderOutput ShaderTranslator::GetShaderOutputLanguageForContext( 95 ShShaderOutput ShaderTranslator::GetShaderOutputLanguageForContext(
113 const gl::GLVersionInfo& version_info) { 96 const gl::GLVersionInfo& version_info) {
114 if (version_info.is_es) { 97 if (version_info.is_es) {
115 return SH_ESSL_OUTPUT; 98 return SH_ESSL_OUTPUT;
116 } 99 }
117 100
118 // Determine the GLSL version based on OpenGL specification. 101 // Determine the GLSL version based on OpenGL specification.
119 102
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 break; 185 break;
203 } 186 }
204 187
205 return compiler_ != NULL; 188 return compiler_ != NULL;
206 } 189 }
207 190
208 ShCompileOptions ShaderTranslator::GetCompileOptions() const { 191 ShCompileOptions ShaderTranslator::GetCompileOptions() const {
209 return compile_options_; 192 return compile_options_;
210 } 193 }
211 194
212 bool ShaderTranslator::Translate(const std::string& shader_source, 195 bool ShaderTranslator::Translate(
213 std::string* info_log, 196 const std::string& shader_source,
214 std::string* translated_source, 197 std::string* info_log,
215 int* shader_version, 198 std::string* translated_source,
216 AttributeMap* attrib_map, 199 int* shader_version,
217 UniformMap* uniform_map, 200 AttributeMap* attrib_map,
218 VaryingMap* varying_map, 201 UniformMap* uniform_map,
219 InterfaceBlockMap* interface_block_map, 202 VaryingMap* varying_map,
220 OutputVariableList* output_variable_list, 203 InterfaceBlockMap* interface_block_map,
221 NameMap* name_map) const { 204 OutputVariableList* output_variable_list) const {
222 // Make sure this instance is initialized. 205 // Make sure this instance is initialized.
223 DCHECK(compiler_ != NULL); 206 DCHECK(compiler_ != NULL);
224 207
225 bool success = false; 208 bool success = false;
226 { 209 {
227 TRACE_EVENT0("gpu", "ShCompile"); 210 TRACE_EVENT0("gpu", "ShCompile");
228 const char* const shader_strings[] = { shader_source.c_str() }; 211 const char* const shader_strings[] = { shader_source.c_str() };
229 success = sh::Compile(compiler_, shader_strings, 1, GetCompileOptions()); 212 success = sh::Compile(compiler_, shader_strings, 1, GetCompileOptions());
230 } 213 }
231 if (success) { 214 if (success) {
232 // Get translated shader. 215 // Get translated shader.
233 if (translated_source) { 216 if (translated_source) {
234 *translated_source = sh::GetObjectCode(compiler_); 217 *translated_source = sh::GetObjectCode(compiler_);
235 } 218 }
236 // Get shader version. 219 // Get shader version.
237 *shader_version = sh::GetShaderVersion(compiler_); 220 *shader_version = sh::GetShaderVersion(compiler_);
238 // Get info for attribs, uniforms, varyings and output variables. 221 // Get info for attribs, uniforms, varyings and output variables.
239 GetAttributes(compiler_, attrib_map); 222 GetAttributes(compiler_, attrib_map);
240 GetUniforms(compiler_, uniform_map); 223 GetUniforms(compiler_, uniform_map);
241 GetVaryings(compiler_, varying_map); 224 GetVaryings(compiler_, varying_map);
242 GetInterfaceBlocks(compiler_, interface_block_map); 225 GetInterfaceBlocks(compiler_, interface_block_map);
243 GetOutputVariables(compiler_, output_variable_list); 226 GetOutputVariables(compiler_, output_variable_list);
244 // Get info for name hashing.
245 GetNameHashingInfo(compiler_, name_map);
246 } 227 }
247 228
248 // Get info log. 229 // Get info log.
249 if (info_log) { 230 if (info_log) {
250 *info_log = sh::GetInfoLog(compiler_); 231 *info_log = sh::GetInfoLog(compiler_);
251 } 232 }
252 233
253 // We don't need results in the compiler anymore. 234 // We don't need results in the compiler anymore.
254 sh::ClearResults(compiler_); 235 sh::ClearResults(compiler_);
255 236
(...skipping 22 matching lines...) Expand all
278 for (auto& observer : destruction_observers_) 259 for (auto& observer : destruction_observers_)
279 observer.OnDestruct(this); 260 observer.OnDestruct(this);
280 261
281 if (compiler_ != NULL) 262 if (compiler_ != NULL)
282 sh::Destruct(compiler_); 263 sh::Destruct(compiler_);
283 } 264 }
284 265
285 } // namespace gles2 266 } // namespace gles2
286 } // namespace gpu 267 } // namespace gpu
287 268
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698