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

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

Issue 6969100: Hook up shader long variable name mapping with GPU command buffer port. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 11
12 namespace { 12 namespace {
13 void FinalizeShaderTranslator(void* /* dummy */) { 13 void FinalizeShaderTranslator(void* /* dummy */) {
14 ShFinalize(); 14 ShFinalize();
15 } 15 }
16 16
17 bool InitializeShaderTranslator() { 17 bool InitializeShaderTranslator() {
18 static bool initialized = false; 18 static bool initialized = false;
19 if (!initialized && ShInitialize()) { 19 if (!initialized && ShInitialize()) {
20 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); 20 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL);
21 initialized = true; 21 initialized = true;
22 } 22 }
23 return initialized; 23 return initialized;
24 } 24 }
25 25
26 using gpu::gles2::ShaderTranslator; 26 using gpu::gles2::ShaderTranslator;
27 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type, 27 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type,
28 ShaderTranslator::VariableMap* var_map) { 28 ShaderTranslator::VariableMap* var_map) {
29 int name_len = 0; 29 int name_len = 0, mapped_name_len = 0;
30 switch (var_type) { 30 switch (var_type) {
31 case SH_ACTIVE_ATTRIBUTES: 31 case SH_ACTIVE_ATTRIBUTES:
32 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len); 32 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len);
33 break; 33 break;
34 case SH_ACTIVE_UNIFORMS: 34 case SH_ACTIVE_UNIFORMS:
35 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len); 35 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len);
36 break; 36 break;
37 default: NOTREACHED(); 37 default: NOTREACHED();
38 } 38 }
39 if (name_len <= 1) return; 39 ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mapped_name_len);
40 if (name_len <= 1 || mapped_name_len <= 1) return;
40 scoped_array<char> name(new char[name_len]); 41 scoped_array<char> name(new char[name_len]);
42 scoped_array<char> mapped_name(new char[mapped_name_len]);
41 43
42 int num_vars = 0; 44 int num_vars = 0;
43 ShGetInfo(compiler, var_type, &num_vars); 45 ShGetInfo(compiler, var_type, &num_vars);
44 for (int i = 0; i < num_vars; ++i) { 46 for (int i = 0; i < num_vars; ++i) {
45 int size = 0; 47 int size = 0;
46 ShDataType type = SH_NONE; 48 ShDataType type = SH_NONE;
47 49
48 switch (var_type) { 50 switch (var_type) {
49 case SH_ACTIVE_ATTRIBUTES: 51 case SH_ACTIVE_ATTRIBUTES:
50 ShGetActiveAttrib(compiler, i, NULL, &size, &type, name.get(), NULL); 52 ShGetActiveAttrib(
53 compiler, i, NULL, &size, &type, name.get(), mapped_name.get());
51 break; 54 break;
52 case SH_ACTIVE_UNIFORMS: 55 case SH_ACTIVE_UNIFORMS:
53 ShGetActiveUniform(compiler, i, NULL, &size, &type, name.get(), NULL); 56 ShGetActiveUniform(
57 compiler, i, NULL, &size, &type, name.get(), mapped_name.get());
54 break; 58 break;
55 default: NOTREACHED(); 59 default: NOTREACHED();
56 } 60 }
57 61
58 ShaderTranslator::VariableInfo info(type, size); 62 ShaderTranslator::VariableInfo info(type, size, name.get());
59 (*var_map)[name.get()] = info; 63 (*var_map)[mapped_name.get()] = info;
60 } 64 }
61 } 65 }
62 } // namespace 66 } // namespace
63 67
64 namespace gpu { 68 namespace gpu {
65 namespace gles2 { 69 namespace gles2 {
66 70
67 ShaderTranslator::ShaderTranslator() 71 ShaderTranslator::ShaderTranslator()
68 : compiler_(NULL), 72 : compiler_(NULL),
69 implementation_is_glsl_es_(false) { 73 implementation_is_glsl_es_(false) {
(...skipping 22 matching lines...) Expand all
92 return compiler_ != NULL; 96 return compiler_ != NULL;
93 } 97 }
94 98
95 bool ShaderTranslator::Translate(const char* shader) { 99 bool ShaderTranslator::Translate(const char* shader) {
96 // Make sure this instance is initialized. 100 // Make sure this instance is initialized.
97 DCHECK(compiler_ != NULL); 101 DCHECK(compiler_ != NULL);
98 DCHECK(shader != NULL); 102 DCHECK(shader != NULL);
99 ClearResults(); 103 ClearResults();
100 104
101 bool success = false; 105 bool success = false;
102 int compile_options = SH_OBJECT_CODE | SH_ATTRIBUTES_UNIFORMS; 106 int compile_options =
107 SH_OBJECT_CODE | SH_ATTRIBUTES_UNIFORMS | SH_MAP_LONG_VARIABLE_NAMES;
103 if (ShCompile(compiler_, &shader, 1, compile_options)) { 108 if (ShCompile(compiler_, &shader, 1, compile_options)) {
104 success = true; 109 success = true;
105 if (!implementation_is_glsl_es_) { 110 if (!implementation_is_glsl_es_) {
106 // Get translated shader. 111 // Get translated shader.
107 int obj_code_len = 0; 112 int obj_code_len = 0;
108 ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len); 113 ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len);
109 if (obj_code_len > 1) { 114 if (obj_code_len > 1) {
110 translated_shader_.reset(new char[obj_code_len]); 115 translated_shader_.reset(new char[obj_code_len]);
111 ShGetObjectCode(compiler_, translated_shader_.get()); 116 ShGetObjectCode(compiler_, translated_shader_.get());
112 } 117 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void ShaderTranslator::ClearResults() { 164 void ShaderTranslator::ClearResults() {
160 translated_shader_.reset(); 165 translated_shader_.reset();
161 info_log_.reset(); 166 info_log_.reset();
162 attrib_map_.clear(); 167 attrib_map_.clear();
163 uniform_map_.clear(); 168 uniform_map_.clear();
164 } 169 }
165 170
166 } // namespace gles2 171 } // namespace gles2
167 } // namespace gpu 172 } // namespace gpu
168 173
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_translator.h ('k') | gpu/command_buffer/service/shader_translator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698