| OLD | NEW |
| 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_manager.h" | 5 #include "gpu/command_buffer/service/shader_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 source_for_driver = translated_source_.c_str(); | 74 source_for_driver = translated_source_.c_str(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 glShaderSource(service_id_, 1, &source_for_driver, NULL); | 77 glShaderSource(service_id_, 1, &source_for_driver, NULL); |
| 78 glCompileShader(service_id_); | 78 glCompileShader(service_id_); |
| 79 if (source_type_ == kANGLE) { | 79 if (source_type_ == kANGLE) { |
| 80 GLint max_len = 0; | 80 GLint max_len = 0; |
| 81 glGetShaderiv(service_id_, | 81 glGetShaderiv(service_id_, |
| 82 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, | 82 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, |
| 83 &max_len); | 83 &max_len); |
| 84 source_for_driver = "\0"; | |
| 85 translated_source_.resize(max_len); | 84 translated_source_.resize(max_len); |
| 86 if (max_len) { | 85 GLint len = 0; |
| 87 GLint len = 0; | 86 glGetTranslatedShaderSourceANGLE( |
| 88 glGetTranslatedShaderSourceANGLE( | 87 service_id_, translated_source_.size(), |
| 89 service_id_, translated_source_.size(), | 88 &len, &translated_source_.at(0)); |
| 90 &len, &translated_source_.at(0)); | 89 DCHECK(max_len == 0 || len < max_len); |
| 91 DCHECK(max_len == 0 || len < max_len); | 90 DCHECK(len == 0 || translated_source_[len] == '\0'); |
| 92 DCHECK(len == 0 || translated_source_[len] == '\0'); | 91 translated_source_.resize(len); |
| 93 translated_source_.resize(len); | 92 source_for_driver = translated_source_.c_str(); |
| 94 source_for_driver = translated_source_.c_str(); | |
| 95 } | |
| 96 } | 93 } |
| 97 | 94 |
| 98 GLint status = GL_FALSE; | 95 GLint status = GL_FALSE; |
| 99 glGetShaderiv(service_id_, GL_COMPILE_STATUS, &status); | 96 glGetShaderiv(service_id_, GL_COMPILE_STATUS, &status); |
| 100 if (status == GL_TRUE) { | 97 if (status == GL_TRUE) { |
| 101 valid_ = true; | 98 valid_ = true; |
| 102 } else { | 99 } else { |
| 103 valid_ = false; | |
| 104 | |
| 105 // We cannot reach here if we are using the shader translator. | 100 // We cannot reach here if we are using the shader translator. |
| 106 // All invalid shaders must be rejected by the translator. | 101 // All invalid shaders must be rejected by the translator. |
| 107 // All translated shaders must compile. | 102 // All translated shaders must compile. |
| 108 GLint max_len = 0; | 103 GLint max_len = 0; |
| 109 glGetShaderiv(service_id_, GL_INFO_LOG_LENGTH, &max_len); | 104 glGetShaderiv(service_id_, GL_INFO_LOG_LENGTH, &max_len); |
| 110 log_info_.resize(max_len); | 105 log_info_.resize(max_len); |
| 111 if (max_len) { | 106 GLint len = 0; |
| 112 GLint len = 0; | 107 glGetShaderInfoLog(service_id_, log_info_.size(), &len, &log_info_.at(0)); |
| 113 glGetShaderInfoLog(service_id_, log_info_.size(), &len, &log_info_.at(0)); | 108 DCHECK(max_len == 0 || len < max_len); |
| 114 DCHECK(max_len == 0 || len < max_len); | 109 DCHECK(len == 0 || log_info_[len] == '\0'); |
| 115 DCHECK(len == 0 || log_info_[len] == '\0'); | 110 valid_ = false; |
| 116 log_info_.resize(len); | 111 log_info_.resize(len); |
| 117 } | |
| 118 LOG_IF(ERROR, translator) | 112 LOG_IF(ERROR, translator) |
| 119 << "Shader translator allowed/produced an invalid shader " | 113 << "Shader translator allowed/produced an invalid shader " |
| 120 << "unless the driver is buggy:" | 114 << "unless the driver is buggy:" |
| 121 << "\n--original-shader--\n" << last_compiled_source_ | 115 << "\n--original-shader--\n" << last_compiled_source_ |
| 122 << "\n--translated-shader--\n" << source_for_driver | 116 << "\n--translated-shader--\n" << source_for_driver |
| 123 << "\n--info-log--\n" << log_info_; | 117 << "\n--info-log--\n" << log_info_; |
| 124 } | 118 } |
| 125 } | 119 } |
| 126 | 120 |
| 127 void Shader::IncUseCount() { | 121 void Shader::IncUseCount() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 DCHECK(shader); | 258 DCHECK(shader); |
| 265 DCHECK(IsOwned(shader)); | 259 DCHECK(IsOwned(shader)); |
| 266 shader->DecUseCount(); | 260 shader->DecUseCount(); |
| 267 RemoveShader(shader); | 261 RemoveShader(shader); |
| 268 } | 262 } |
| 269 | 263 |
| 270 } // namespace gles2 | 264 } // namespace gles2 |
| 271 } // namespace gpu | 265 } // namespace gpu |
| 272 | 266 |
| 273 | 267 |
| OLD | NEW |