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

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

Issue 619723008: Switch to use ANGLE's new APIs to query shader variables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win build fix Created 6 years, 2 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "gpu/gpu_export.h" 15 #include "gpu/gpu_export.h"
16 #include "third_party/angle/include/GLSLANG/ShaderLang.h" 16 #include "third_party/angle/include/GLSLANG/ShaderLang.h"
17 17
18 namespace gpu { 18 namespace gpu {
19 namespace gles2 { 19 namespace gles2 {
20 20
21 // Mapping between variable name and info.
22 typedef base::hash_map<std::string, sh::Attribute> AttributeMap;
23 typedef base::hash_map<std::string, sh::Uniform> UniformMap;
24 typedef base::hash_map<std::string, sh::Varying> VaryingMap;
25 // Mapping between hashed name and original name.
26 typedef base::hash_map<std::string, std::string> NameMap;
27
21 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just 28 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just
22 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. 29 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation.
23 class ShaderTranslatorInterface { 30 class ShaderTranslatorInterface {
24 public: 31 public:
25 enum GlslImplementationType { 32 enum GlslImplementationType {
26 kGlsl, 33 kGlsl,
27 kGlslES 34 kGlslES
28 }; 35 };
29 36
30 struct VariableInfo {
31 VariableInfo()
32 : type(0),
33 size(0),
34 precision(SH_PRECISION_UNDEFINED),
35 static_use(0) {
36 }
37
38 VariableInfo(int _type, int _size, int _precision,
39 int _static_use, std::string _name)
40 : type(_type),
41 size(_size),
42 precision(_precision),
43 static_use(_static_use),
44 name(_name) {
45 }
46 bool operator==(
47 const ShaderTranslatorInterface::VariableInfo& other) const {
48 return type == other.type &&
49 size == other.size &&
50 precision == other.precision &&
51 strcmp(name.c_str(), other.name.c_str()) == 0;
52 }
53
54 int type;
55 int size;
56 int precision;
57 int static_use;
58 std::string name; // name in the original shader source.
59 };
60
61 // Mapping between variable name and info.
62 typedef base::hash_map<std::string, VariableInfo> VariableMap;
63 // Mapping between hashed name and original name.
64 typedef base::hash_map<std::string, std::string> NameMap;
65
66 // Initializes the translator. 37 // Initializes the translator.
67 // Must be called once before using the translator object. 38 // Must be called once before using the translator object.
68 virtual bool Init( 39 virtual bool Init(
69 sh::GLenum shader_type, 40 sh::GLenum shader_type,
70 ShShaderSpec shader_spec, 41 ShShaderSpec shader_spec,
71 const ShBuiltInResources* resources, 42 const ShBuiltInResources* resources,
72 GlslImplementationType glsl_implementation_type, 43 GlslImplementationType glsl_implementation_type,
73 ShCompileOptions driver_bug_workarounds) = 0; 44 ShCompileOptions driver_bug_workarounds) = 0;
74 45
75 // Translates the given shader source. 46 // Translates the given shader source.
76 // Returns true if translation is successful, false otherwise. 47 // Returns true if translation is successful, false otherwise.
77 // Always fill |info_log| if it's non-null. 48 // Always fill |info_log| if it's non-null.
78 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|, 49 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|,
79 // |varying_map|, and |name_map| if they are non-null. 50 // |varying_map|, and |name_map| if they are non-null.
80 virtual bool Translate(const std::string& shader_source, 51 virtual bool Translate(const std::string& shader_source,
81 std::string* info_log, 52 std::string* info_log,
82 std::string* translated_shader, 53 std::string* translated_shader,
83 VariableMap* attrib_map, 54 AttributeMap* attrib_map,
84 VariableMap* uniform_map, 55 UniformMap* uniform_map,
85 VariableMap* varying_map, 56 VaryingMap* varying_map,
86 NameMap* name_map) const = 0; 57 NameMap* name_map) const = 0;
87 58
88 // Return a string that is unique for a specfic set of options that would 59 // Return a string that is unique for a specfic set of options that would
89 // possibly affect compilation. 60 // possibly affect compilation.
90 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0; 61 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0;
91 62
92 protected: 63 protected:
93 virtual ~ShaderTranslatorInterface() {} 64 virtual ~ShaderTranslatorInterface() {}
94 }; 65 };
95 66
(...skipping 20 matching lines...) Expand all
116 sh::GLenum shader_type, 87 sh::GLenum shader_type,
117 ShShaderSpec shader_spec, 88 ShShaderSpec shader_spec,
118 const ShBuiltInResources* resources, 89 const ShBuiltInResources* resources,
119 GlslImplementationType glsl_implementation_type, 90 GlslImplementationType glsl_implementation_type,
120 ShCompileOptions driver_bug_workarounds) override; 91 ShCompileOptions driver_bug_workarounds) override;
121 92
122 // Overridden from ShaderTranslatorInterface. 93 // Overridden from ShaderTranslatorInterface.
123 virtual bool Translate(const std::string& shader_source, 94 virtual bool Translate(const std::string& shader_source,
124 std::string* info_log, 95 std::string* info_log,
125 std::string* translated_source, 96 std::string* translated_source,
126 VariableMap* attrib_map, 97 AttributeMap* attrib_map,
127 VariableMap* uniform_map, 98 UniformMap* uniform_map,
128 VariableMap* varying_map, 99 VaryingMap* varying_map,
129 NameMap* name_map) const override; 100 NameMap* name_map) const override;
130 101
131 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const 102 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const
132 override; 103 override;
133 104
134 void AddDestructionObserver(DestructionObserver* observer); 105 void AddDestructionObserver(DestructionObserver* observer);
135 void RemoveDestructionObserver(DestructionObserver* observer); 106 void RemoveDestructionObserver(DestructionObserver* observer);
136 107
137 private: 108 private:
138 friend class base::RefCounted<ShaderTranslator>; 109 friend class base::RefCounted<ShaderTranslator>;
139 110
140 virtual ~ShaderTranslator(); 111 virtual ~ShaderTranslator();
141 int GetCompileOptions() const; 112 int GetCompileOptions() const;
142 113
143 ShHandle compiler_; 114 ShHandle compiler_;
144 ShBuiltInResources compiler_options_; 115 ShBuiltInResources compiler_options_;
145 bool implementation_is_glsl_es_; 116 bool implementation_is_glsl_es_;
146 ShCompileOptions driver_bug_workarounds_; 117 ShCompileOptions driver_bug_workarounds_;
147 ObserverList<DestructionObserver> destruction_observers_; 118 ObserverList<DestructionObserver> destruction_observers_;
148 119
149 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator); 120 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator);
150 }; 121 };
151 122
152 } // namespace gles2 123 } // namespace gles2
153 } // namespace gpu 124 } // namespace gpu
154 125
155 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ 126 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
156 127
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_manager_unittest.cc ('k') | gpu/command_buffer/service/shader_translator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698