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

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: Rebased Created 6 years, 9 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"
23 #include "base/numerics/safe_math.h"
22 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 25 #include "base/strings/string_split.h"
24 #include "build/build_config.h" 26 #include "build/build_config.h"
25 #define GLES2_GPU_SERVICE 1 27 #define GLES2_GPU_SERVICE 1
26 #include "gpu/command_buffer/common/debug_marker_manager.h" 28 #include "gpu/command_buffer/common/debug_marker_manager.h"
27 #include "gpu/command_buffer/common/gles2_cmd_format.h" 29 #include "gpu/command_buffer/common/gles2_cmd_format.h"
28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 30 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
29 #include "gpu/command_buffer/common/id_allocator.h" 31 #include "gpu/command_buffer/common/id_allocator.h"
30 #include "gpu/command_buffer/common/mailbox.h" 32 #include "gpu/command_buffer/common/mailbox.h"
31 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 33 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 513
512 struct FenceCallback { 514 struct FenceCallback {
513 explicit FenceCallback() 515 explicit FenceCallback()
514 : fence(gfx::GLFence::Create()) { 516 : fence(gfx::GLFence::Create()) {
515 DCHECK(fence); 517 DCHECK(fence);
516 } 518 }
517 std::vector<base::Closure> callbacks; 519 std::vector<base::Closure> callbacks;
518 scoped_ptr<gfx::GLFence> fence; 520 scoped_ptr<gfx::GLFence> fence;
519 }; 521 };
520 522
523 class AsyncUploadTokenCompletionObserver
524 : public AsyncPixelTransferCompletionObserver {
525 public:
526 explicit AsyncUploadTokenCompletionObserver(uint32 async_upload_token)
527 : async_upload_token_(async_upload_token) {
528 }
529
530 virtual void DidComplete(const AsyncMemoryParams& mem_params) OVERRIDE {
531 DCHECK(mem_params.buffer());
532 void* data = mem_params.GetDataAddress();
533 AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data);
534 sync->SetAsyncUploadToken(async_upload_token_);
535 }
536
537 private:
538 virtual ~AsyncUploadTokenCompletionObserver() {
539 }
540
541 uint32 async_upload_token_;
542
543 DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver);
544 };
545
521 // } // anonymous namespace. 546 // } // anonymous namespace.
522 547
523 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, 548 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id,
524 uint32* service_texture_id) { 549 uint32* service_texture_id) {
525 return false; 550 return false;
526 } 551 }
527 552
528 GLES2Decoder::GLES2Decoder() 553 GLES2Decoder::GLES2Decoder()
529 : initialized_(false), 554 : initialized_(false),
530 debug_(false), 555 debug_(false),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); 731 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids);
707 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); 732 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids);
708 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); 733 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids);
709 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 734 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
710 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 735 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
711 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 736 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
712 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 737 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
713 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 738 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
714 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 739 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
715 740
741 // Helper for async upload token completion notification callback.
742 base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token,
743 uint32 sync_data_shm_id,
744 uint32 sync_data_shm_offset);
745
746
747
716 // Workarounds 748 // Workarounds
717 void OnFboChanged() const; 749 void OnFboChanged() const;
718 void OnUseFramebuffer() const; 750 void OnUseFramebuffer() const;
719 751
720 // TODO(gman): Cache these pointers? 752 // TODO(gman): Cache these pointers?
721 BufferManager* buffer_manager() { 753 BufferManager* buffer_manager() {
722 return group_->buffer_manager(); 754 return group_->buffer_manager();
723 } 755 }
724 756
725 RenderbufferManager* renderbuffer_manager() { 757 RenderbufferManager* renderbuffer_manager() {
(...skipping 9596 matching lines...) Expand 10 before | Expand all | Expand 10 after
10322 if (!texture_ref || 10354 if (!texture_ref ||
10323 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { 10355 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) {
10324 LOCAL_SET_GL_ERROR( 10356 LOCAL_SET_GL_ERROR(
10325 GL_INVALID_OPERATION, 10357 GL_INVALID_OPERATION,
10326 function_name, "transfer already in progress"); 10358 function_name, "transfer already in progress");
10327 return false; 10359 return false;
10328 } 10360 }
10329 return true; 10361 return true;
10330 } 10362 }
10331 10363
10364 base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure(
10365 uint32 async_upload_token,
10366 uint32 sync_data_shm_id,
10367 uint32 sync_data_shm_offset) {
10368 AsyncMemoryParams mem_params(GetSharedMemoryBuffer(sync_data_shm_id),
10369 sync_data_shm_offset,
10370 sizeof(AsyncUploadSync));
10371
10372 base::CheckedNumeric<uint32> end = mem_params.data_offset();
10373 end += mem_params.data_size();
10374 if (!end.IsValid() || end.ValueOrDie() > mem_params.buffer()->size())
piman 2014/03/27 17:43:05 nit: do this check before creating the AsyncMemory
10375 return base::Closure();
10376
10377 scoped_refptr<AsyncUploadTokenCompletionObserver> observer(
10378 new AsyncUploadTokenCompletionObserver(async_upload_token));
10379
10380 return base::Bind(
10381 &AsyncPixelTransferManager::AsyncNotifyCompletion,
10382 base::Unretained(GetAsyncPixelTransferManager()),
10383 mem_params,
10384 observer);
10385 }
10386
10332 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( 10387 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
10333 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { 10388 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) {
10334 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); 10389 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM");
10335 GLenum target = static_cast<GLenum>(c.target); 10390 GLenum target = static_cast<GLenum>(c.target);
10336 GLint level = static_cast<GLint>(c.level); 10391 GLint level = static_cast<GLint>(c.level);
10337 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use 10392 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use
10338 // unsigned integer for internalformat. 10393 // unsigned integer for internalformat.
10339 GLenum internal_format = static_cast<GLenum>(c.internalformat); 10394 GLenum internal_format = static_cast<GLenum>(c.internalformat);
10340 GLsizei width = static_cast<GLsizei>(c.width); 10395 GLsizei width = static_cast<GLsizei>(c.width);
10341 GLsizei height = static_cast<GLsizei>(c.height); 10396 GLsizei height = static_cast<GLsizei>(c.height);
10342 GLint border = static_cast<GLint>(c.border); 10397 GLint border = static_cast<GLint>(c.border);
10343 GLenum format = static_cast<GLenum>(c.format); 10398 GLenum format = static_cast<GLenum>(c.format);
10344 GLenum type = static_cast<GLenum>(c.type); 10399 GLenum type = static_cast<GLenum>(c.type);
10345 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); 10400 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id);
10346 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); 10401 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset);
10347 uint32 pixels_size; 10402 uint32 pixels_size;
10403 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10404 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10405 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10406
10407 base::ScopedClosureRunner scoped_completion_callback;
10408 if (async_upload_token) {
10409 base::Closure completion_closure =
10410 AsyncUploadTokenCompletionClosure(async_upload_token,
10411 sync_data_shm_id,
10412 sync_data_shm_offset);
10413 if (completion_closure.is_null())
10414 return error::kInvalidArguments;
10415
10416 scoped_completion_callback.Reset(completion_closure);
10417 }
10348 10418
10349 // TODO(epenner): Move this and copies of this memory validation 10419 // TODO(epenner): Move this and copies of this memory validation
10350 // into ValidateTexImage2D step. 10420 // into ValidateTexImage2D step.
10351 if (!GLES2Util::ComputeImageDataSizes( 10421 if (!GLES2Util::ComputeImageDataSizes(
10352 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, 10422 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL,
10353 NULL)) { 10423 NULL)) {
10354 return error::kOutOfBounds; 10424 return error::kOutOfBounds;
10355 } 10425 }
10356 const void* pixels = NULL; 10426 const void* pixels = NULL;
10357 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 10427 if (pixels_shm_id != 0 || pixels_shm_offset != 0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
10424 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { 10494 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) {
10425 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 10495 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
10426 GLenum target = static_cast<GLenum>(c.target); 10496 GLenum target = static_cast<GLenum>(c.target);
10427 GLint level = static_cast<GLint>(c.level); 10497 GLint level = static_cast<GLint>(c.level);
10428 GLint xoffset = static_cast<GLint>(c.xoffset); 10498 GLint xoffset = static_cast<GLint>(c.xoffset);
10429 GLint yoffset = static_cast<GLint>(c.yoffset); 10499 GLint yoffset = static_cast<GLint>(c.yoffset);
10430 GLsizei width = static_cast<GLsizei>(c.width); 10500 GLsizei width = static_cast<GLsizei>(c.width);
10431 GLsizei height = static_cast<GLsizei>(c.height); 10501 GLsizei height = static_cast<GLsizei>(c.height);
10432 GLenum format = static_cast<GLenum>(c.format); 10502 GLenum format = static_cast<GLenum>(c.format);
10433 GLenum type = static_cast<GLenum>(c.type); 10503 GLenum type = static_cast<GLenum>(c.type);
10504 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10505 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10506 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10507
10508 base::ScopedClosureRunner scoped_completion_callback;
10509 if (async_upload_token) {
10510 base::Closure completion_closure =
10511 AsyncUploadTokenCompletionClosure(async_upload_token,
10512 sync_data_shm_id,
10513 sync_data_shm_offset);
10514 if (completion_closure.is_null())
10515 return error::kInvalidArguments;
10516
10517 scoped_completion_callback.Reset(completion_closure);
10518 }
10434 10519
10435 // TODO(epenner): Move this and copies of this memory validation 10520 // TODO(epenner): Move this and copies of this memory validation
10436 // into ValidateTexSubImage2D step. 10521 // into ValidateTexSubImage2D step.
10437 uint32 data_size; 10522 uint32 data_size;
10438 if (!GLES2Util::ComputeImageDataSizes( 10523 if (!GLES2Util::ComputeImageDataSizes(
10439 width, height, format, type, state_.unpack_alignment, &data_size, 10524 width, height, format, type, state_.unpack_alignment, &data_size,
10440 NULL, NULL)) { 10525 NULL, NULL)) {
10441 return error::kOutOfBounds; 10526 return error::kOutOfBounds;
10442 } 10527 }
10443 const void* pixels = GetSharedMemoryAs<const void*>( 10528 const void* pixels = GetSharedMemoryAs<const void*>(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
10526 LOCAL_SET_GL_ERROR( 10611 LOCAL_SET_GL_ERROR(
10527 GL_INVALID_OPERATION, 10612 GL_INVALID_OPERATION,
10528 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); 10613 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started");
10529 return error::kNoError; 10614 return error::kNoError;
10530 } 10615 }
10531 delegate->WaitForTransferCompletion(); 10616 delegate->WaitForTransferCompletion();
10532 ProcessFinishedAsyncTransfers(); 10617 ProcessFinishedAsyncTransfers();
10533 return error::kNoError; 10618 return error::kNoError;
10534 } 10619 }
10535 10620
10621 error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM(
10622 uint32 immediate_data_size, const cmds::WaitAllAsyncTexImage2DCHROMIUM& c) {
10623 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM");
10624
10625 GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D();
10626 ProcessFinishedAsyncTransfers();
10627 return error::kNoError;
10628 }
10629
10536 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( 10630 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer(
10537 TextureRef* texture_ref) { 10631 TextureRef* texture_ref) {
10538 Texture* texture = texture_ref->texture(); 10632 Texture* texture = texture_ref->texture();
10539 DoDidUseTexImageIfNeeded(texture, texture->target()); 10633 DoDidUseTexImageIfNeeded(texture, texture->target());
10540 } 10634 }
10541 10635
10542 // Include the auto-generated part of this file. We split this because it means 10636 // Include the auto-generated part of this file. We split this because it means
10543 // we can easily edit the non-auto generated parts right here in this file 10637 // we can easily edit the non-auto generated parts right here in this file
10544 // instead of having to edit some template or the code generator. 10638 // instead of having to edit some template or the code generator.
10545 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10639 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10546 10640
10547 } // namespace gles2 10641 } // namespace gles2
10548 } // namespace gpu 10642 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698