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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added glWaitAllAsyncTexImage2DCHROMIUM; other review issues addressed Created 6 years, 10 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 #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>
11 #include <map> 11 #include <map>
12 #include <stack> 12 #include <stack>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/at_exit.h" 16 #include "base/at_exit.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/callback_helpers.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
19 #include "base/debug/trace_event.h" 20 #include "base/debug/trace_event.h"
20 #include "base/debug/trace_event_synthetic_delay.h" 21 #include "base/debug/trace_event_synthetic_delay.h"
21 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #define GLES2_GPU_SERVICE 1 26 #define GLES2_GPU_SERVICE 1
26 #include "gpu/command_buffer/common/debug_marker_manager.h" 27 #include "gpu/command_buffer/common/debug_marker_manager.h"
27 #include "gpu/command_buffer/common/gles2_cmd_format.h" 28 #include "gpu/command_buffer/common/gles2_cmd_format.h"
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 473
473 struct FenceCallback { 474 struct FenceCallback {
474 explicit FenceCallback() 475 explicit FenceCallback()
475 : fence(gfx::GLFence::Create()) { 476 : fence(gfx::GLFence::Create()) {
476 DCHECK(fence); 477 DCHECK(fence);
477 } 478 }
478 std::vector<base::Closure> callbacks; 479 std::vector<base::Closure> callbacks;
479 scoped_ptr<gfx::GLFence> fence; 480 scoped_ptr<gfx::GLFence> fence;
480 }; 481 };
481 482
483 class AsyncUploadTokenCompletionObserver
484 : public AsyncPixelTransferCompletionObserver {
485 public:
486 AsyncUploadTokenCompletionObserver(uint32 async_upload_token)
piman 2014/02/20 01:52:37 nit: explicit
487 : async_upload_token_(async_upload_token) {
488 }
489
490 virtual void DidComplete(const AsyncMemoryParams& mem_params) OVERRIDE {
491 void* data = static_cast<int8*>(mem_params.shared_memory->memory()) +
492 mem_params.shm_data_offset;
493 AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data);
494 sync->SetAsyncUploadToken(async_upload_token_);
495 }
496
497 private:
498 uint32 async_upload_token_;
piman 2014/02/20 01:52:37 nit: DISALLOW_COPY_AND_ASSIGN
499 };
500
482 // } // anonymous namespace. 501 // } // anonymous namespace.
483 502
484 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, 503 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id,
485 uint32* service_texture_id) { 504 uint32* service_texture_id) {
486 return false; 505 return false;
487 } 506 }
488 507
489 GLES2Decoder::GLES2Decoder() 508 GLES2Decoder::GLES2Decoder()
490 : initialized_(false), 509 : initialized_(false),
491 debug_(false), 510 debug_(false),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); 685 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids);
667 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); 686 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids);
668 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); 687 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids);
669 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 688 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
670 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 689 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
671 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 690 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
672 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 691 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
673 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 692 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
674 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 693 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
675 694
695 // Helper for async upload token completion notification callback.
696 base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token,
697 uint32 sync_data_shm_id,
698 uint32 sync_data_shm_offset);
699
700
701
676 // Workarounds 702 // Workarounds
677 void OnFboChanged() const; 703 void OnFboChanged() const;
678 void OnUseFramebuffer() const; 704 void OnUseFramebuffer() const;
679 705
680 // TODO(gman): Cache these pointers? 706 // TODO(gman): Cache these pointers?
681 BufferManager* buffer_manager() { 707 BufferManager* buffer_manager() {
682 return group_->buffer_manager(); 708 return group_->buffer_manager();
683 } 709 }
684 710
685 RenderbufferManager* renderbuffer_manager() { 711 RenderbufferManager* renderbuffer_manager() {
(...skipping 9597 matching lines...) Expand 10 before | Expand all | Expand 10 after
10283 if (!texture_ref || 10309 if (!texture_ref ||
10284 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { 10310 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) {
10285 LOCAL_SET_GL_ERROR( 10311 LOCAL_SET_GL_ERROR(
10286 GL_INVALID_OPERATION, 10312 GL_INVALID_OPERATION,
10287 function_name, "transfer already in progress"); 10313 function_name, "transfer already in progress");
10288 return false; 10314 return false;
10289 } 10315 }
10290 return true; 10316 return true;
10291 } 10317 }
10292 10318
10319 base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure(
10320 uint32 async_upload_token,
10321 uint32 sync_data_shm_id,
10322 uint32 sync_data_shm_offset) {
10323 AsyncMemoryParams mem_params;
10324 gpu::Buffer buffer = GetSharedMemoryBuffer(sync_data_shm_id);
10325 if (!buffer.shared_memory)
10326 return base::Closure();
10327 mem_params.shared_memory = buffer.shared_memory;
10328 mem_params.shm_size = buffer.size;
10329 mem_params.shm_data_offset = sync_data_shm_offset;
10330 mem_params.shm_data_size = sizeof(AsyncUploadSync);
piman 2014/02/20 01:52:37 There's a DCHECK in AsyncNotifyCompletion that say
jadahl 2014/02/20 10:24:22 This seems to be missing for the mem_params passed
epennerAtGoogle 2014/02/20 19:15:06 It's checked in in ValidateTexSubImage2D. The 'pix
epennerAtGoogle 2014/02/20 19:20:07 It's in GetSharedMemoryAs: https://code.google.com
10331
10332 scoped_refptr<AsyncUploadTokenCompletionObserver> observer(
10333 new AsyncUploadTokenCompletionObserver(async_upload_token));
10334
10335 return base::Bind(
10336 &AsyncPixelTransferManager::AsyncNotifyCompletion,
10337 base::Unretained(GetAsyncPixelTransferManager()),
10338 mem_params,
10339 observer);
10340 }
10341
10293 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( 10342 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
10294 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { 10343 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) {
10295 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); 10344 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM");
10296 GLenum target = static_cast<GLenum>(c.target); 10345 GLenum target = static_cast<GLenum>(c.target);
10297 GLint level = static_cast<GLint>(c.level); 10346 GLint level = static_cast<GLint>(c.level);
10298 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use 10347 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use
10299 // unsigned integer for internalformat. 10348 // unsigned integer for internalformat.
10300 GLenum internal_format = static_cast<GLenum>(c.internalformat); 10349 GLenum internal_format = static_cast<GLenum>(c.internalformat);
10301 GLsizei width = static_cast<GLsizei>(c.width); 10350 GLsizei width = static_cast<GLsizei>(c.width);
10302 GLsizei height = static_cast<GLsizei>(c.height); 10351 GLsizei height = static_cast<GLsizei>(c.height);
10303 GLint border = static_cast<GLint>(c.border); 10352 GLint border = static_cast<GLint>(c.border);
10304 GLenum format = static_cast<GLenum>(c.format); 10353 GLenum format = static_cast<GLenum>(c.format);
10305 GLenum type = static_cast<GLenum>(c.type); 10354 GLenum type = static_cast<GLenum>(c.type);
10306 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); 10355 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id);
10307 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); 10356 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset);
10308 uint32 pixels_size; 10357 uint32 pixels_size;
10358 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10359 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10360 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10361
10362 base::ScopedClosureRunner scoped_completion_callback;
10363 if (async_upload_token) {
10364 base::Closure completion_closure =
10365 AsyncUploadTokenCompletionClosure(async_upload_token,
10366 sync_data_shm_id,
10367 sync_data_shm_offset);
10368 if (completion_closure.is_null())
10369 return error::kInvalidArguments;
10370
10371 scoped_completion_callback.Reset(completion_closure);
10372 }
10309 10373
10310 // TODO(epenner): Move this and copies of this memory validation 10374 // TODO(epenner): Move this and copies of this memory validation
10311 // into ValidateTexImage2D step. 10375 // into ValidateTexImage2D step.
10312 if (!GLES2Util::ComputeImageDataSizes( 10376 if (!GLES2Util::ComputeImageDataSizes(
10313 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, 10377 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL,
10314 NULL)) { 10378 NULL)) {
10315 return error::kOutOfBounds; 10379 return error::kOutOfBounds;
10316 } 10380 }
10317 const void* pixels = NULL; 10381 const void* pixels = NULL;
10318 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 10382 if (pixels_shm_id != 0 || pixels_shm_offset != 0) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
10393 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { 10457 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) {
10394 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 10458 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
10395 GLenum target = static_cast<GLenum>(c.target); 10459 GLenum target = static_cast<GLenum>(c.target);
10396 GLint level = static_cast<GLint>(c.level); 10460 GLint level = static_cast<GLint>(c.level);
10397 GLint xoffset = static_cast<GLint>(c.xoffset); 10461 GLint xoffset = static_cast<GLint>(c.xoffset);
10398 GLint yoffset = static_cast<GLint>(c.yoffset); 10462 GLint yoffset = static_cast<GLint>(c.yoffset);
10399 GLsizei width = static_cast<GLsizei>(c.width); 10463 GLsizei width = static_cast<GLsizei>(c.width);
10400 GLsizei height = static_cast<GLsizei>(c.height); 10464 GLsizei height = static_cast<GLsizei>(c.height);
10401 GLenum format = static_cast<GLenum>(c.format); 10465 GLenum format = static_cast<GLenum>(c.format);
10402 GLenum type = static_cast<GLenum>(c.type); 10466 GLenum type = static_cast<GLenum>(c.type);
10467 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10468 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10469 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10470
10471 base::ScopedClosureRunner scoped_completion_callback;
10472 if (async_upload_token) {
10473 base::Closure completion_closure =
10474 AsyncUploadTokenCompletionClosure(async_upload_token,
10475 sync_data_shm_id,
10476 sync_data_shm_offset);
10477 if (completion_closure.is_null())
10478 return error::kInvalidArguments;
10479
10480 scoped_completion_callback.Reset(completion_closure);
10481 }
10403 10482
10404 // TODO(epenner): Move this and copies of this memory validation 10483 // TODO(epenner): Move this and copies of this memory validation
10405 // into ValidateTexSubImage2D step. 10484 // into ValidateTexSubImage2D step.
10406 uint32 data_size; 10485 uint32 data_size;
10407 if (!GLES2Util::ComputeImageDataSizes( 10486 if (!GLES2Util::ComputeImageDataSizes(
10408 width, height, format, type, state_.unpack_alignment, &data_size, 10487 width, height, format, type, state_.unpack_alignment, &data_size,
10409 NULL, NULL)) { 10488 NULL, NULL)) {
10410 return error::kOutOfBounds; 10489 return error::kOutOfBounds;
10411 } 10490 }
10412 const void* pixels = GetSharedMemoryAs<const void*>( 10491 const void* pixels = GetSharedMemoryAs<const void*>(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
10503 LOCAL_SET_GL_ERROR( 10582 LOCAL_SET_GL_ERROR(
10504 GL_INVALID_OPERATION, 10583 GL_INVALID_OPERATION,
10505 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); 10584 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started");
10506 return error::kNoError; 10585 return error::kNoError;
10507 } 10586 }
10508 delegate->WaitForTransferCompletion(); 10587 delegate->WaitForTransferCompletion();
10509 ProcessFinishedAsyncTransfers(); 10588 ProcessFinishedAsyncTransfers();
10510 return error::kNoError; 10589 return error::kNoError;
10511 } 10590 }
10512 10591
10592 error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM(
10593 uint32 immediate_data_size, const cmds::WaitAllAsyncTexImage2DCHROMIUM& c) {
10594 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM");
10595
10596 GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D();
10597 ProcessFinishedAsyncTransfers();
10598 return error::kNoError;
10599 }
10600
10513 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( 10601 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer(
10514 TextureRef* texture_ref) { 10602 TextureRef* texture_ref) {
10515 Texture* texture = texture_ref->texture(); 10603 Texture* texture = texture_ref->texture();
10516 DoDidUseTexImageIfNeeded(texture, texture->target()); 10604 DoDidUseTexImageIfNeeded(texture, texture->target());
10517 } 10605 }
10518 10606
10519 // Include the auto-generated part of this file. We split this because it means 10607 // Include the auto-generated part of this file. We split this because it means
10520 // we can easily edit the non-auto generated parts right here in this file 10608 // we can easily edit the non-auto generated parts right here in this file
10521 // instead of having to edit some template or the code generator. 10609 // instead of having to edit some template or the code generator.
10522 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10610 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10523 10611
10524 } // namespace gles2 10612 } // namespace gles2
10525 } // namespace gpu 10613 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698