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

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

Issue 2127001: Makes shader translation a runtime switch.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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) 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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 void DoBufferData( 797 void DoBufferData(
798 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); 798 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
799 799
800 // Wrapper for glBufferSubData. 800 // Wrapper for glBufferSubData.
801 void DoBufferSubData( 801 void DoBufferSubData(
802 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); 802 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data);
803 803
804 // Wrapper for glCheckFramebufferStatus 804 // Wrapper for glCheckFramebufferStatus
805 GLenum DoCheckFramebufferStatus(GLenum target); 805 GLenum DoCheckFramebufferStatus(GLenum target);
806 806
807 // Helper for CommandBufferEnable cmd.
808 void DoCommandBufferEnable(GLenum pname, GLboolean enable);
809
810 // Wrapper for glCompileShader. 807 // Wrapper for glCompileShader.
811 void DoCompileShader(GLuint shader); 808 void DoCompileShader(GLuint shader);
812 809
813 // Helper for DeleteSharedIds commands. 810 // Helper for DeleteSharedIds commands.
814 void DoDeleteSharedIds(GLuint namespace_id, GLsizei n, const GLuint* ids); 811 void DoDeleteSharedIds(GLuint namespace_id, GLsizei n, const GLuint* ids);
815 812
816 // Wrapper for glDetachShader 813 // Wrapper for glDetachShader
817 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); 814 void DoDetachShader(GLuint client_program_id, GLint client_shader_id);
818 815
819 // Wrapper for glDrawArrays. 816 // Wrapper for glDrawArrays.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 scoped_ptr<RenderBuffer> offscreen_target_depth_stencil_render_buffer_; 1069 scoped_ptr<RenderBuffer> offscreen_target_depth_stencil_render_buffer_;
1073 1070
1074 // The copy that is saved when SwapBuffers is called. 1071 // The copy that is saved when SwapBuffers is called.
1075 scoped_ptr<Texture> offscreen_saved_color_texture_; 1072 scoped_ptr<Texture> offscreen_saved_color_texture_;
1076 1073
1077 scoped_ptr<Callback0::Type> swap_buffers_callback_; 1074 scoped_ptr<Callback0::Type> swap_buffers_callback_;
1078 1075
1079 // The last error message set. 1076 // The last error message set.
1080 std::string last_error_; 1077 std::string last_error_;
1081 1078
1079 bool use_shader_translator_;
1080
1082 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); 1081 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl);
1083 }; 1082 };
1084 1083
1085 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) 1084 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder)
1086 : decoder_(decoder) { 1085 : decoder_(decoder) {
1087 decoder_->CopyRealGLErrorsToWrapper(); 1086 decoder_->CopyRealGLErrorsToWrapper();
1088 } 1087 }
1089 1088
1090 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { 1089 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() {
1091 decoder_->ClearRealGLErrors(); 1090 decoder_->ClearRealGLErrors();
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) 1333 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group)
1335 : GLES2Decoder(group), 1334 : GLES2Decoder(group),
1336 context_(NULL), 1335 context_(NULL),
1337 error_bits_(0), 1336 error_bits_(0),
1338 util_(0), // TODO(gman): Set to actual num compress texture formats. 1337 util_(0), // TODO(gman): Set to actual num compress texture formats.
1339 pack_alignment_(4), 1338 pack_alignment_(4),
1340 unpack_alignment_(4), 1339 unpack_alignment_(4),
1341 active_texture_unit_(0), 1340 active_texture_unit_(0),
1342 black_2d_texture_id_(0), 1341 black_2d_texture_id_(0),
1343 black_cube_texture_id_(0), 1342 black_cube_texture_id_(0),
1344 anti_aliased_(false) { 1343 anti_aliased_(false),
1344 use_shader_translator_(true) {
1345 } 1345 }
1346 1346
1347 bool GLES2DecoderImpl::Initialize(gfx::GLContext* context, 1347 bool GLES2DecoderImpl::Initialize(gfx::GLContext* context,
1348 const gfx::Size& size, 1348 const gfx::Size& size,
1349 GLES2Decoder* parent, 1349 GLES2Decoder* parent,
1350 uint32 parent_client_texture_id) { 1350 uint32 parent_client_texture_id) {
1351 DCHECK(context); 1351 DCHECK(context);
1352 DCHECK(!context_); 1352 DCHECK(!context_);
1353 context_ = context; 1353 context_ = context;
1354 1354
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 program, "glBindAttribLocation"); 2348 program, "glBindAttribLocation");
2349 if (!info) { 2349 if (!info) {
2350 return error::kNoError; 2350 return error::kNoError;
2351 } 2351 }
2352 GLuint index = static_cast<GLuint>(c.index); 2352 GLuint index = static_cast<GLuint>(c.index);
2353 Bucket* bucket = GetBucket(c.name_bucket_id); 2353 Bucket* bucket = GetBucket(c.name_bucket_id);
2354 if (!bucket || bucket->size() == 0) { 2354 if (!bucket || bucket->size() == 0) {
2355 return error::kInvalidArguments; 2355 return error::kInvalidArguments;
2356 } 2356 }
2357 std::string name_str; 2357 std::string name_str;
2358 bucket->GetAsString(&name_str); 2358 if (!bucket->GetAsString(&name_str)) {
2359 return error::kInvalidArguments;
2360 }
2359 glBindAttribLocation(info->service_id(), index, name_str.c_str()); 2361 glBindAttribLocation(info->service_id(), index, name_str.c_str());
2360 return error::kNoError; 2362 return error::kNoError;
2361 } 2363 }
2362 2364
2363 error::Error GLES2DecoderImpl::HandleDeleteShader( 2365 error::Error GLES2DecoderImpl::HandleDeleteShader(
2364 uint32 immediate_data_size, const gles2::DeleteShader& c) { 2366 uint32 immediate_data_size, const gles2::DeleteShader& c) {
2365 GLuint client_id = c.shader; 2367 GLuint client_id = c.shader;
2366 if (client_id) { 2368 if (client_id) {
2367 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); 2369 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id);
2368 if (info) { 2370 if (info) {
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( 3063 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram(
3062 client_id, "glCompileShader"); 3064 client_id, "glCompileShader");
3063 if (!info) { 3065 if (!info) {
3064 return; 3066 return;
3065 } 3067 }
3066 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to 3068 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to
3067 // glShaderSource and then glCompileShader. 3069 // glShaderSource and then glCompileShader.
3068 const char* shader_src = info->source().c_str(); 3070 const char* shader_src = info->source().c_str();
3069 #if !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) && !defined(UNIT_TEST) 3071 #if !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) && !defined(UNIT_TEST)
3070 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER) 3072 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER)
3071 int dbg_options = 0; 3073 ShHandle compiler;
3072 EShLanguage language = info->shader_type() == GL_VERTEX_SHADER ? 3074 if (use_shader_translator_) {
3073 EShLangVertex : EShLangFragment; 3075 int dbg_options = 0;
3074 TBuiltInResource resources; 3076 EShLanguage language = info->shader_type() == GL_VERTEX_SHADER ?
3075 // TODO(alokp): Ask gman how to get appropriate values. 3077 EShLangVertex : EShLangFragment;
3076 resources.maxVertexAttribs = 8; 3078 TBuiltInResource resources;
3077 resources.maxVertexUniformVectors = 128; 3079 // TODO(alokp): Ask gman how to get appropriate values.
3078 resources.maxVaryingVectors = 8; 3080 resources.maxVertexAttribs = group_->max_vertex_attribs();
3079 resources.maxVertexTextureImageUnits = 0; 3081 resources.maxVertexUniformVectors = 128;
3080 resources.maxCombinedTextureImageUnits = 8; 3082 resources.maxVaryingVectors = 8;
3081 resources.maxTextureImageUnits = 8; 3083 resources.maxVertexTextureImageUnits = 0;
3082 resources.maxFragmentUniformVectors = 16; 3084 resources.maxCombinedTextureImageUnits = group_->max_texture_units();
3083 resources.maxDrawBuffers = 1; 3085 resources.maxTextureImageUnits = 8;
3084 ShHandle compiler = ShConstructCompiler(language, dbg_options); 3086 resources.maxFragmentUniformVectors = 16;
3085 if (!ShCompile(compiler, &shader_src, 1, EShOptNone, &resources, 3087 resources.maxDrawBuffers = 1;
3086 dbg_options)) { 3088 compiler = ShConstructCompiler(language, dbg_options);
3087 // TODO(alokp): Ask gman where to set compile-status and info-log. 3089 if (!ShCompile(compiler, &shader_src, 1, EShOptNone, &resources,
3088 // May be add member variables to ShaderManager::ShaderInfo? 3090 dbg_options)) {
3089 //const char* info_log = ShGetInfoLog(compiler); 3091 // TODO(alokp): Ask gman where to set compile-status and info-log.
3090 ShDestruct(compiler); 3092 // May be add member variables to ShaderManager::ShaderInfo?
3091 return; 3093 // const char* info_log = ShGetInfoLog(compiler);
3094 ShDestruct(compiler);
3095 return;
3096 }
3097 shader_src = ShGetObjectCode(compiler);
3092 } 3098 }
3093 shader_src = ShGetObjectCode(compiler);
3094 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER 3099 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER
3095 #endif // GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2 3100 #endif // GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2
3096 3101
3097 shader_src = info->source().c_str(); 3102 shader_src = info->source().c_str();
3098 glShaderSource(info->service_id(), 1, &shader_src, NULL); 3103 glShaderSource(info->service_id(), 1, &shader_src, NULL);
3099 glCompileShader(info->service_id()); 3104 glCompileShader(info->service_id());
3100 3105
3101 #if !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) && !defined(UNIT_TEST) 3106 #if !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) && !defined(UNIT_TEST)
3102 #ifdef GLES2_GPU_SERVICE_TRANSLATE_SHADER 3107 #ifdef GLES2_GPU_SERVICE_TRANSLATE_SHADER
3103 ShDestruct(compiler); 3108 if (use_shader_translator_) {
3109 ShDestruct(compiler);
3110 }
3104 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER 3111 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER
3105 #endif // GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2 3112 #endif // GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2
3106 }; 3113 };
3107 3114
3108 void GLES2DecoderImpl::DoGetShaderiv( 3115 void GLES2DecoderImpl::DoGetShaderiv(
3109 GLuint shader, GLenum pname, GLint* params) { 3116 GLuint shader, GLenum pname, GLint* params) {
3110 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( 3117 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram(
3111 shader, "glGetShaderiv"); 3118 shader, "glGetShaderiv");
3112 if (!info) { 3119 if (!info) {
3113 return; 3120 return;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 c.program, c.location_shm_id, c.location_shm_offset, name_str); 3494 c.program, c.location_shm_id, c.location_shm_offset, name_str);
3488 } 3495 }
3489 3496
3490 error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( 3497 error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket(
3491 uint32 immediate_data_size, const gles2::GetAttribLocationBucket& c) { 3498 uint32 immediate_data_size, const gles2::GetAttribLocationBucket& c) {
3492 Bucket* bucket = GetBucket(c.name_bucket_id); 3499 Bucket* bucket = GetBucket(c.name_bucket_id);
3493 if (!bucket) { 3500 if (!bucket) {
3494 return error::kInvalidArguments; 3501 return error::kInvalidArguments;
3495 } 3502 }
3496 std::string name_str; 3503 std::string name_str;
3497 bucket->GetAsString(&name_str); 3504 if (!bucket->GetAsString(&name_str)) {
3505 return error::kInvalidArguments;
3506 }
3498 return GetAttribLocationHelper( 3507 return GetAttribLocationHelper(
3499 c.program, c.location_shm_id, c.location_shm_offset, name_str); 3508 c.program, c.location_shm_id, c.location_shm_offset, name_str);
3500 } 3509 }
3501 3510
3502 error::Error GLES2DecoderImpl::GetUniformLocationHelper( 3511 error::Error GLES2DecoderImpl::GetUniformLocationHelper(
3503 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, 3512 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset,
3504 const std::string& name_str) { 3513 const std::string& name_str) {
3505 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 3514 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
3506 client_id, "glUniformLocation"); 3515 client_id, "glUniformLocation");
3507 if (!info) { 3516 if (!info) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3552 c.program, c.location_shm_id, c.location_shm_offset, name_str); 3561 c.program, c.location_shm_id, c.location_shm_offset, name_str);
3553 } 3562 }
3554 3563
3555 error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket( 3564 error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket(
3556 uint32 immediate_data_size, const gles2::GetUniformLocationBucket& c) { 3565 uint32 immediate_data_size, const gles2::GetUniformLocationBucket& c) {
3557 Bucket* bucket = GetBucket(c.name_bucket_id); 3566 Bucket* bucket = GetBucket(c.name_bucket_id);
3558 if (!bucket) { 3567 if (!bucket) {
3559 return error::kInvalidArguments; 3568 return error::kInvalidArguments;
3560 } 3569 }
3561 std::string name_str; 3570 std::string name_str;
3562 bucket->GetAsString(&name_str); 3571 if (!bucket->GetAsString(&name_str)) {
3572 return error::kInvalidArguments;
3573 }
3563 return GetUniformLocationHelper( 3574 return GetUniformLocationHelper(
3564 c.program, c.location_shm_id, c.location_shm_offset, name_str); 3575 c.program, c.location_shm_id, c.location_shm_offset, name_str);
3565 } 3576 }
3566 3577
3567 error::Error GLES2DecoderImpl::HandleGetString( 3578 error::Error GLES2DecoderImpl::HandleGetString(
3568 uint32 immediate_data_size, const gles2::GetString& c) { 3579 uint32 immediate_data_size, const gles2::GetString& c) {
3569 GLenum name = static_cast<GLenum>(c.name); 3580 GLenum name = static_cast<GLenum>(c.name);
3570 if (!ValidateGLenumStringType(name)) { 3581 if (!ValidateGLenumStringType(name)) {
3571 SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM"); 3582 SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM");
3572 return error::kNoError; 3583 return error::kNoError;
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
4271 // glReadPixels. After the callback runs, the multisampled frame buffer 4282 // glReadPixels. After the callback runs, the multisampled frame buffer
4272 // needs to be bound again. 4283 // needs to be bound again.
4273 4284
4274 if (swap_buffers_callback_.get()) { 4285 if (swap_buffers_callback_.get()) {
4275 swap_buffers_callback_->Run(); 4286 swap_buffers_callback_->Run();
4276 } 4287 }
4277 4288
4278 return error::kNoError; 4289 return error::kNoError;
4279 } 4290 }
4280 4291
4281 void GLES2DecoderImpl::DoCommandBufferEnable(GLenum pname, GLboolean enable) { 4292 error::Error GLES2DecoderImpl::HandleCommandBufferEnable(
4282 switch (pname) { 4293 uint32 immediate_data_size, const gles2::CommandBufferEnable& c) {
4283 case GLES2_ALLOW_BUFFERS_ON_MULTIPLE_TARGETS: 4294 Bucket* bucket = GetBucket(c.bucket_id);
4284 buffer_manager()->set_allow_buffers_on_multiple_targets(enable != 0); 4295 typedef gles2::CommandBufferEnable::Result Result;
4285 break; 4296 Result* result = GetSharedMemoryAs<Result*>(
4286 default: 4297 c.result_shm_id, c.result_shm_offset, sizeof(*result));
4287 break; 4298 if (!result) {
4299 return error::kOutOfBounds;
4288 } 4300 }
4301 // Check that the client initialized the result.
4302 if (*result != 0) {
4303 return error::kInvalidArguments;
4304 }
4305 std::string feature_str;
4306 if (!bucket->GetAsString(&feature_str)) {
4307 return error::kInvalidArguments;
4308 }
4309
4310 // TODO(gman): make this some kind of table to function pointer thingy.
4311 if (feature_str.compare(PEPPER3D_ALLOW_BUFFERS_ON_MULTIPLE_TARGETS) == 0) {
4312 buffer_manager()->set_allow_buffers_on_multiple_targets(true);
4313 } else if (feature_str.compare(PEPPER3D_SKIP_GLSL_TRANSLATION) == 0) {
4314 use_shader_translator_ = false;
4315 } else {
4316 return error::kNoError;
4317 }
4318
4319 *result = 1; // true.
4320 return error::kNoError;
4289 } 4321 }
4290 4322
4291 // Include the auto-generated part of this file. We split this because it means 4323 // Include the auto-generated part of this file. We split this because it means
4292 // we can easily edit the non-auto generated parts right here in this file 4324 // we can easily edit the non-auto generated parts right here in this file
4293 // instead of having to edit some template or the code generator. 4325 // instead of having to edit some template or the code generator.
4294 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 4326 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
4295 4327
4296 } // namespace gles2 4328 } // namespace gles2
4297 } // namespace gpu 4329 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/docs/gles2_cmd_format_docs.txt ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698