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

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

Issue 12210057: Added temporary #ifdefs to support incompatible ANGLE API upgrade. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed SH_VERSION macro due to conflict on Android bot. Created 7 years, 10 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 | Annotate | Revision Log
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 <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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace { 13 namespace {
14 14
15 using gpu::gles2::ShaderTranslator; 15 using gpu::gles2::ShaderTranslator;
16 16
17 void FinalizeShaderTranslator(void* /* dummy */) { 17 void FinalizeShaderTranslator(void* /* dummy */) {
18 ShFinalize(); 18 ShFinalize();
19 } 19 }
20 20
21 bool InitializeShaderTranslator() { 21 bool InitializeShaderTranslator() {
22 static bool initialized = false; 22 static bool initialized = false;
23 if (!initialized && ShInitialize()) { 23 if (!initialized && ShInitialize()) {
24 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); 24 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL);
25 initialized = true; 25 initialized = true;
26 } 26 }
27 return initialized; 27 return initialized;
28 } 28 }
29 29
30 #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108
31 typedef int ANGLEGetInfoType;
32 #else
33 typedef size_t ANGLEGetInfoType;
34 #endif
35
30 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type, 36 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type,
31 ShaderTranslator::VariableMap* var_map) { 37 ShaderTranslator::VariableMap* var_map) {
32 int name_len = 0, mapped_name_len = 0; 38 ANGLEGetInfoType name_len = 0, mapped_name_len = 0;
33 switch (var_type) { 39 switch (var_type) {
34 case SH_ACTIVE_ATTRIBUTES: 40 case SH_ACTIVE_ATTRIBUTES:
35 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len); 41 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len);
36 break; 42 break;
37 case SH_ACTIVE_UNIFORMS: 43 case SH_ACTIVE_UNIFORMS:
38 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len); 44 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len);
39 break; 45 break;
40 default: NOTREACHED(); 46 default: NOTREACHED();
41 } 47 }
42 ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mapped_name_len); 48 ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mapped_name_len);
43 if (name_len <= 1 || mapped_name_len <= 1) return; 49 if (name_len <= 1 || mapped_name_len <= 1) return;
44 scoped_array<char> name(new char[name_len]); 50 scoped_array<char> name(new char[name_len]);
45 scoped_array<char> mapped_name(new char[mapped_name_len]); 51 scoped_array<char> mapped_name(new char[mapped_name_len]);
46 52
47 int num_vars = 0; 53 ANGLEGetInfoType num_vars = 0;
48 ShGetInfo(compiler, var_type, &num_vars); 54 ShGetInfo(compiler, var_type, &num_vars);
49 for (int i = 0; i < num_vars; ++i) { 55 for (ANGLEGetInfoType i = 0; i < num_vars; ++i) {
50 int len = 0; 56 ANGLEGetInfoType len = 0;
51 int size = 0; 57 int size = 0;
52 ShDataType type = SH_NONE; 58 ShDataType type = SH_NONE;
53 59
54 switch (var_type) { 60 switch (var_type) {
55 case SH_ACTIVE_ATTRIBUTES: 61 case SH_ACTIVE_ATTRIBUTES:
56 ShGetActiveAttrib( 62 ShGetActiveAttrib(
57 compiler, i, &len, &size, &type, name.get(), mapped_name.get()); 63 compiler, i, &len, &size, &type, name.get(), mapped_name.get());
58 break; 64 break;
59 case SH_ACTIVE_UNIFORMS: 65 case SH_ACTIVE_UNIFORMS:
60 ShGetActiveUniform( 66 ShGetActiveUniform(
61 compiler, i, &len, &size, &type, name.get(), mapped_name.get()); 67 compiler, i, &len, &size, &type, name.get(), mapped_name.get());
62 break; 68 break;
63 default: NOTREACHED(); 69 default: NOTREACHED();
64 } 70 }
65 71
66 // In theory we should CHECK(len <= name_len - 1) here, but ANGLE needs 72 // In theory we should CHECK(len <= name_len - 1) here, but ANGLE needs
67 // to handle long struct field name mapping before we can do this. 73 // to handle long struct field name mapping before we can do this.
68 // Also, we should modify the ANGLE interface to also return a length 74 // Also, we should modify the ANGLE interface to also return a length
69 // for mapped_name. 75 // for mapped_name.
70 std::string name_string(name.get(), std::min(len, name_len - 1)); 76 std::string name_string(name.get(), std::min(len, name_len - 1));
71 mapped_name.get()[mapped_name_len - 1] = '\0'; 77 mapped_name.get()[mapped_name_len - 1] = '\0';
72 78
73 ShaderTranslator::VariableInfo info(type, size, name_string); 79 ShaderTranslator::VariableInfo info(type, size, name_string);
74 (*var_map)[mapped_name.get()] = info; 80 (*var_map)[mapped_name.get()] = info;
75 } 81 }
76 } 82 }
77 83
78 void GetNameHashingInfo( 84 void GetNameHashingInfo(
79 ShHandle compiler, ShaderTranslator::NameMap* name_map) { 85 ShHandle compiler, ShaderTranslator::NameMap* name_map) {
80 int hashed_names_count = 0; 86 ANGLEGetInfoType hashed_names_count = 0;
81 ShGetInfo(compiler, SH_HASHED_NAMES_COUNT, &hashed_names_count); 87 ShGetInfo(compiler, SH_HASHED_NAMES_COUNT, &hashed_names_count);
82 if (hashed_names_count == 0) 88 if (hashed_names_count == 0)
83 return; 89 return;
84 90
85 int name_max_len = 0, hashed_name_max_len = 0; 91 ANGLEGetInfoType name_max_len = 0, hashed_name_max_len = 0;
86 ShGetInfo(compiler, SH_NAME_MAX_LENGTH, &name_max_len); 92 ShGetInfo(compiler, SH_NAME_MAX_LENGTH, &name_max_len);
87 ShGetInfo(compiler, SH_HASHED_NAME_MAX_LENGTH, &hashed_name_max_len); 93 ShGetInfo(compiler, SH_HASHED_NAME_MAX_LENGTH, &hashed_name_max_len);
88 94
89 scoped_array<char> name(new char[name_max_len]); 95 scoped_array<char> name(new char[name_max_len]);
90 scoped_array<char> hashed_name(new char[hashed_name_max_len]); 96 scoped_array<char> hashed_name(new char[hashed_name_max_len]);
91 97
92 for (int i = 0; i < hashed_names_count; ++i) { 98 for (ANGLEGetInfoType i = 0; i < hashed_names_count; ++i) {
93 ShGetNameHashingEntry(compiler, i, name.get(), hashed_name.get()); 99 ShGetNameHashingEntry(compiler, i, name.get(), hashed_name.get());
94 (*name_map)[hashed_name.get()] = name.get(); 100 (*name_map)[hashed_name.get()] = name.get();
95 } 101 }
96 } 102 }
97 103
98 } // namespace 104 } // namespace
99 105
100 namespace gpu { 106 namespace gpu {
101 namespace gles2 { 107 namespace gles2 {
102 108
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SH_OBJECT_CODE | SH_ATTRIBUTES_UNIFORMS | 156 SH_OBJECT_CODE | SH_ATTRIBUTES_UNIFORMS |
151 SH_MAP_LONG_VARIABLE_NAMES | SH_ENFORCE_PACKING_RESTRICTIONS; 157 SH_MAP_LONG_VARIABLE_NAMES | SH_ENFORCE_PACKING_RESTRICTIONS;
152 158
153 compile_options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS; 159 compile_options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
154 160
155 if (needs_built_in_function_emulation_) 161 if (needs_built_in_function_emulation_)
156 compile_options |= SH_EMULATE_BUILT_IN_FUNCTIONS; 162 compile_options |= SH_EMULATE_BUILT_IN_FUNCTIONS;
157 if (ShCompile(compiler_, &shader, 1, compile_options)) { 163 if (ShCompile(compiler_, &shader, 1, compile_options)) {
158 success = true; 164 success = true;
159 // Get translated shader. 165 // Get translated shader.
160 int obj_code_len = 0; 166 ANGLEGetInfoType obj_code_len = 0;
161 ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len); 167 ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len);
162 if (obj_code_len > 1) { 168 if (obj_code_len > 1) {
163 translated_shader_.reset(new char[obj_code_len]); 169 translated_shader_.reset(new char[obj_code_len]);
164 ShGetObjectCode(compiler_, translated_shader_.get()); 170 ShGetObjectCode(compiler_, translated_shader_.get());
165 } 171 }
166 // Get info for attribs and uniforms. 172 // Get info for attribs and uniforms.
167 GetVariableInfo(compiler_, SH_ACTIVE_ATTRIBUTES, &attrib_map_); 173 GetVariableInfo(compiler_, SH_ACTIVE_ATTRIBUTES, &attrib_map_);
168 GetVariableInfo(compiler_, SH_ACTIVE_UNIFORMS, &uniform_map_); 174 GetVariableInfo(compiler_, SH_ACTIVE_UNIFORMS, &uniform_map_);
169 // Get info for name hashing. 175 // Get info for name hashing.
170 GetNameHashingInfo(compiler_, &name_map_); 176 GetNameHashingInfo(compiler_, &name_map_);
171 } 177 }
172 178
173 // Get info log. 179 // Get info log.
174 int info_log_len = 0; 180 ANGLEGetInfoType info_log_len = 0;
175 ShGetInfo(compiler_, SH_INFO_LOG_LENGTH, &info_log_len); 181 ShGetInfo(compiler_, SH_INFO_LOG_LENGTH, &info_log_len);
176 if (info_log_len > 1) { 182 if (info_log_len > 1) {
177 info_log_.reset(new char[info_log_len]); 183 info_log_.reset(new char[info_log_len]);
178 ShGetInfoLog(compiler_, info_log_.get()); 184 ShGetInfoLog(compiler_, info_log_.get());
179 } else { 185 } else {
180 info_log_.reset(); 186 info_log_.reset();
181 } 187 }
182 188
183 return success; 189 return success;
184 } 190 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 translated_shader_.reset(); 235 translated_shader_.reset();
230 info_log_.reset(); 236 info_log_.reset();
231 attrib_map_.clear(); 237 attrib_map_.clear();
232 uniform_map_.clear(); 238 uniform_map_.clear();
233 name_map_.clear(); 239 name_map_.clear();
234 } 240 }
235 241
236 } // namespace gles2 242 } // namespace gles2
237 } // namespace gpu 243 } // namespace gpu
238 244
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | webkit/gpu/webgraphicscontext3d_in_process_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698