Index: gpu/command_buffer/service/shader_manager.cc |
diff --git a/gpu/command_buffer/service/shader_manager.cc b/gpu/command_buffer/service/shader_manager.cc |
index 2707b90b92de4105d6b8c9f1dad28a0663158f0e..4b43aa7843145a7fb615c351a27b64bd1168eb0c 100644 |
--- a/gpu/command_buffer/service/shader_manager.cc |
+++ b/gpu/command_buffer/service/shader_manager.cc |
@@ -26,6 +26,7 @@ std::string GetTopVariableName(const std::string& fullname) { |
Shader::Shader(GLuint service_id, GLenum shader_type) |
: use_count_(0), |
+ shader_state_(kShaderStateWaiting), |
service_id_(service_id), |
shader_type_(shader_type), |
valid_(false) { |
@@ -34,13 +35,34 @@ Shader::Shader(GLuint service_id, GLenum shader_type) |
Shader::~Shader() { |
} |
+void Shader::RequestCompile() { |
+ shader_state_ = kShaderStateCompileRequested; |
+ last_compiled_source_ = source_; |
+} |
+ |
void Shader::DoCompile(ShaderTranslatorInterface* translator, |
TranslatedShaderSourceType type) { |
+ // If compile was not requested yet, we assume this is not a deferred compile. |
+ // It is up to the caller of the function to check that the shader state |
+ // is kShaderStateCompileRequested if they want to enforce deferred shader |
+ // compiles. Otherwise calling DoCompile() will just compile the source that |
+ // was last set. For deferred compiles we should compile |
+ // |last_compiled_source_| instead of |source_| because they could have set a |
+ // new shader source after requesting a compile, in which case the shader at |
+ // the time of the compile request is the proper source. |
vmiura
2015/02/04 21:18:56
nit: DCHECK(shader_state_ != kShaderStateCompiled)
David Yen
2015/02/04 22:05:49
After discussing in person, we decided to simplify
|
+ if (shader_state_ != kShaderStateCompileRequested) { |
+ last_compiled_source_ = source_; |
+ } |
+ |
+ // Signify the shader has been compiled, whether or not it is valid |
+ // is dependent on the |valid_| member variable. |
+ shader_state_ = kShaderStateCompiled; |
+ |
// Translate GL ES 2.0 shader to Desktop GL shader and pass that to |
// glShaderSource and then glCompileShader. |
- const char* source_for_driver = source_.c_str(); |
+ const char* source_for_driver = last_compiled_source_.c_str(); |
if (translator) { |
- valid_ = translator->Translate(source_, |
+ valid_ = translator->Translate(last_compiled_source_, |
&log_info_, |
&translated_source_, |
&attrib_map_, |
@@ -50,7 +72,6 @@ void Shader::DoCompile(ShaderTranslatorInterface* translator, |
if (!valid_) { |
return; |
} |
- signature_source_ = source_; |
source_for_driver = translated_source_.c_str(); |
} |
@@ -88,7 +109,7 @@ void Shader::DoCompile(ShaderTranslatorInterface* translator, |
LOG_IF(ERROR, translator) |
<< "Shader translator allowed/produced an invalid shader " |
<< "unless the driver is buggy:" |
- << "\n--original-shader--\n" << source_ |
+ << "\n--original-shader--\n" << last_compiled_source_ |
<< "\n--translated-shader--\n" << source_for_driver |
<< "\n--info-log--\n" << log_info_; |
} |