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

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

Issue 3035028: Bumped ANGLE rev in which shader translator API changed. Updated shader trans... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 1136
1137 // The copy that is saved when SwapBuffers is called. 1137 // The copy that is saved when SwapBuffers is called.
1138 scoped_ptr<Texture> offscreen_saved_color_texture_; 1138 scoped_ptr<Texture> offscreen_saved_color_texture_;
1139 1139
1140 scoped_ptr<Callback0::Type> swap_buffers_callback_; 1140 scoped_ptr<Callback0::Type> swap_buffers_callback_;
1141 1141
1142 // The last error message set. 1142 // The last error message set.
1143 std::string last_error_; 1143 std::string last_error_;
1144 1144
1145 bool use_shader_translator_; 1145 bool use_shader_translator_;
1146 void* vertex_compiler_;
1147 void* fragment_compiler_;
1146 1148
1147 // Cached from the context group. 1149 // Cached from the context group.
1148 const Validators* validators_; 1150 const Validators* validators_;
1149 1151
1150 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); 1152 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl);
1151 }; 1153 };
1152 1154
1153 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) 1155 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder)
1154 : decoder_(decoder) { 1156 : decoder_(decoder) {
1155 decoder_->CopyRealGLErrorsToWrapper(); 1157 decoder_->CopyRealGLErrorsToWrapper();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 util_(0), // TODO(gman): Set to actual num compress texture formats. 1403 util_(0), // TODO(gman): Set to actual num compress texture formats.
1402 pack_alignment_(4), 1404 pack_alignment_(4),
1403 unpack_alignment_(4), 1405 unpack_alignment_(4),
1404 attrib_0_buffer_id_(0), 1406 attrib_0_buffer_id_(0),
1405 attrib_0_size_(0), 1407 attrib_0_size_(0),
1406 active_texture_unit_(0), 1408 active_texture_unit_(0),
1407 black_2d_texture_id_(0), 1409 black_2d_texture_id_(0),
1408 black_cube_texture_id_(0), 1410 black_cube_texture_id_(0),
1409 anti_aliased_(false), 1411 anti_aliased_(false),
1410 use_shader_translator_(true), 1412 use_shader_translator_(true),
1413 vertex_compiler_(NULL),
1414 fragment_compiler_(NULL),
1411 validators_(group->validators()) { 1415 validators_(group->validators()) {
1412 attrib_0_value_.v[0] = 0.0f; 1416 attrib_0_value_.v[0] = 0.0f;
1413 attrib_0_value_.v[1] = 0.0f; 1417 attrib_0_value_.v[1] = 0.0f;
1414 attrib_0_value_.v[2] = 0.0f; 1418 attrib_0_value_.v[2] = 0.0f;
1415 attrib_0_value_.v[3] = 1.0f; 1419 attrib_0_value_.v[3] = 1.0f;
1416 1420
1417 // The shader translator is not needed for EGL because it already uses the 1421 // The shader translator is not needed for EGL because it already uses the
1418 // GLSL ES syntax. It is translated for the unit tests because 1422 // GLSL ES syntax. It is translated for the unit tests because
1419 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the empty 1423 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the empty
1420 // string to CompileShader and this is not a valid shader. TODO(apatrick): 1424 // string to CompileShader and this is not a valid shader. TODO(apatrick):
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 // OpenGL ES 2.0 implicitly enables the desktop GL capability 1546 // OpenGL ES 2.0 implicitly enables the desktop GL capability
1543 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact 1547 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact
1544 // isn't well documented; it was discovered in the Khronos OpenGL ES 1548 // isn't well documented; it was discovered in the Khronos OpenGL ES
1545 // mailing list archives. 1549 // mailing list archives.
1546 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 1550 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
1547 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 1551 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
1548 } 1552 }
1549 1553
1550 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER) 1554 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER)
1551 // Initialize GLSL ES to GLSL translator. 1555 // Initialize GLSL ES to GLSL translator.
1552 static bool glsl_translator_initialized = false; 1556 if (!ShInitialize()) {
1553 if (!glsl_translator_initialized) { 1557 DLOG(ERROR) << "Could not initialize GLSL translator.";
1554 if (!ShInitialize()) { 1558 Destroy();
1555 DLOG(ERROR) << "Could not initialize GLSL translator."; 1559 return false;
1560 }
1561
1562 TBuiltInResource resources;
1563 resources.maxVertexAttribs = group_->max_vertex_attribs();
1564 resources.maxVertexUniformVectors =
1565 group_->max_vertex_uniform_vectors();
1566 resources.maxVaryingVectors = group_->max_varying_vectors();
1567 resources.maxVertexTextureImageUnits =
1568 group_->max_vertex_texture_image_units();
1569 resources.maxCombinedTextureImageUnits = group_->max_texture_units();
1570 resources.maxTextureImageUnits = group_->max_texture_image_units();
1571 resources.maxFragmentUniformVectors =
1572 group_->max_fragment_uniform_vectors();
1573 resources.maxDrawBuffers = 1;
1574 vertex_compiler_ = ShConstructCompiler(EShLangVertex, EShSpecGLES2,
1575 &resources);
1576 if (vertex_compiler_ == NULL) {
1577 DLOG(ERROR) << "Could not create vertex shader translator.";
1556 Destroy(); 1578 Destroy();
1557 return false; 1579 return false;
1558 }
1559 glsl_translator_initialized = true;
1560 } 1580 }
1581 fragment_compiler_ = ShConstructCompiler(EShLangFragment, EShSpecGLES2,
1582 &resources);
1583 if (fragment_compiler_ == NULL) {
1584 DLOG(ERROR) << "Could not create fragment shader translator.";
1585 Destroy();
1586 return false;
1587 }
1588
1561 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER 1589 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER
1562 1590
1563 return true; 1591 return true;
1564 } 1592 }
1565 1593
1566 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { 1594 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) {
1567 for (GLsizei ii = 0; ii < n; ++ii) { 1595 for (GLsizei ii = 0; ii < n; ++ii) {
1568 if (GetBufferInfo(client_ids[ii])) { 1596 if (GetBufferInfo(client_ids[ii])) {
1569 return false; 1597 return false;
1570 } 1598 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 } 1904 }
1877 1905
1878 return true; 1906 return true;
1879 } 1907 }
1880 1908
1881 void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) { 1909 void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
1882 swap_buffers_callback_.reset(callback); 1910 swap_buffers_callback_.reset(callback);
1883 } 1911 }
1884 1912
1885 void GLES2DecoderImpl::Destroy() { 1913 void GLES2DecoderImpl::Destroy() {
1914 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER)
1915 if (vertex_compiler_ != NULL) {
1916 ShDestruct(vertex_compiler_);
1917 vertex_compiler_ = NULL;
1918 }
1919 if (fragment_compiler_ != NULL) {
1920 ShDestruct(fragment_compiler_);
1921 fragment_compiler_ = NULL;
1922 }
1923 ShFinalize();
1924 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER)
1925
1886 if (context_.get()) { 1926 if (context_.get()) {
1887 MakeCurrent(); 1927 MakeCurrent();
1888 1928
1889 if (black_2d_texture_id_) { 1929 if (black_2d_texture_id_) {
1890 glDeleteTextures(1, &black_2d_texture_id_); 1930 glDeleteTextures(1, &black_2d_texture_id_);
1891 } 1931 }
1892 if (black_cube_texture_id_) { 1932 if (black_cube_texture_id_) {
1893 glDeleteTextures(1, &black_cube_texture_id_); 1933 glDeleteTextures(1, &black_cube_texture_id_);
1894 } 1934 }
1895 if (attrib_0_buffer_id_) { 1935 if (attrib_0_buffer_id_) {
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { 3318 void GLES2DecoderImpl::DoCompileShader(GLuint client_id) {
3279 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( 3319 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram(
3280 client_id, "glCompileShader"); 3320 client_id, "glCompileShader");
3281 if (!info) { 3321 if (!info) {
3282 return; 3322 return;
3283 } 3323 }
3284 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to 3324 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to
3285 // glShaderSource and then glCompileShader. 3325 // glShaderSource and then glCompileShader.
3286 const char* shader_src = info->source().c_str(); 3326 const char* shader_src = info->source().c_str();
3287 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER) 3327 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER)
3288 ShHandle compiler = 0;
3289 if (use_shader_translator_) { 3328 if (use_shader_translator_) {
3290 int dbg_options = 0; 3329 int dbg_options = 0;
3291 EShLanguage language = info->shader_type() == GL_VERTEX_SHADER ? 3330 ShHandle compiler = info->shader_type() == GL_VERTEX_SHADER ?
3292 EShLangVertex : EShLangFragment; 3331 vertex_compiler_ : fragment_compiler_;
3293 TBuiltInResource resources; 3332
3294 resources.maxVertexAttribs = group_->max_vertex_attribs(); 3333 if (!ShCompile(compiler, &shader_src, 1, EShOptNone, dbg_options)) {
3295 resources.maxVertexUniformVectors =
3296 group_->max_vertex_uniform_vectors();
3297 resources.maxVaryingVectors = group_->max_varying_vectors();
3298 resources.maxVertexTextureImageUnits =
3299 group_->max_vertex_texture_image_units();
3300 resources.maxCombinedTextureImageUnits = group_->max_texture_units();
3301 resources.maxTextureImageUnits = group_->max_texture_image_units();
3302 resources.maxFragmentUniformVectors =
3303 group_->max_fragment_uniform_vectors();
3304 resources.maxDrawBuffers = 1;
3305 compiler = ShConstructCompiler(language, dbg_options);
3306 if (!ShCompile(compiler, &shader_src, 1, EShOptNone, &resources,
3307 dbg_options)) {
3308 info->SetStatus(false, ShGetInfoLog(compiler)); 3334 info->SetStatus(false, ShGetInfoLog(compiler));
3309 ShDestruct(compiler);
3310 return; 3335 return;
3311 } 3336 }
3312 shader_src = ShGetObjectCode(compiler); 3337 shader_src = ShGetObjectCode(compiler);
3313 } 3338 }
3314 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER 3339 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER
3315 3340
3316 glShaderSource(info->service_id(), 1, &shader_src, NULL); 3341 glShaderSource(info->service_id(), 1, &shader_src, NULL);
3317 glCompileShader(info->service_id()); 3342 glCompileShader(info->service_id());
3318 GLint status = GL_FALSE; 3343 GLint status = GL_FALSE;
3319 glGetShaderiv(info->service_id(), GL_COMPILE_STATUS, &status); 3344 glGetShaderiv(info->service_id(), GL_COMPILE_STATUS, &status);
3320 if (status) { 3345 if (status) {
3321 info->SetStatus(true, ""); 3346 info->SetStatus(true, "");
3322 } else { 3347 } else {
3323 GLint len = 0; 3348 GLint len = 0;
3324 glGetShaderiv(info->service_id(), GL_INFO_LOG_LENGTH, &len); 3349 glGetShaderiv(info->service_id(), GL_INFO_LOG_LENGTH, &len);
3325 scoped_array<char> temp(new char[len]); 3350 scoped_array<char> temp(new char[len]);
3326 glGetShaderInfoLog(info->service_id(), len, &len, temp.get()); 3351 glGetShaderInfoLog(info->service_id(), len, &len, temp.get());
3327 info->SetStatus(false, std::string(temp.get(), len)); 3352 info->SetStatus(false, std::string(temp.get(), len));
3328 } 3353 }
3329 #ifdef GLES2_GPU_SERVICE_TRANSLATE_SHADER
3330 if (use_shader_translator_) {
3331 ShDestruct(compiler);
3332 }
3333 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER
3334 }; 3354 };
3335 3355
3336 void GLES2DecoderImpl::DoGetShaderiv( 3356 void GLES2DecoderImpl::DoGetShaderiv(
3337 GLuint shader, GLenum pname, GLint* params) { 3357 GLuint shader, GLenum pname, GLint* params) {
3338 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( 3358 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram(
3339 shader, "glGetShaderiv"); 3359 shader, "glGetShaderiv");
3340 if (!info) { 3360 if (!info) {
3341 return; 3361 return;
3342 } 3362 }
3343 switch (pname) { 3363 switch (pname) {
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4796 return error::kNoError; 4816 return error::kNoError;
4797 } 4817 }
4798 4818
4799 // Include the auto-generated part of this file. We split this because it means 4819 // Include the auto-generated part of this file. We split this because it means
4800 // we can easily edit the non-auto generated parts right here in this file 4820 // we can easily edit the non-auto generated parts right here in this file
4801 // instead of having to edit some template or the code generator. 4821 // instead of having to edit some template or the code generator.
4802 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 4822 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
4803 4823
4804 } // namespace gles2 4824 } // namespace gles2
4805 } // namespace gpu 4825 } // namespace gpu
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698