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

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; removed unnecessary barrier; use CheckedNumeric 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 void* data = static_cast<int8*>(mem_params.shared_memory->memory()) +
532 mem_params.shm_data_offset;
533 AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data);
534 sync->SetAsyncUploadToken(async_upload_token_);
535 }
536
537 private:
538 uint32 async_upload_token_;
539
540 DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver);
541 };
542
521 // } // anonymous namespace. 543 // } // anonymous namespace.
522 544
523 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, 545 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id,
524 uint32* service_texture_id) { 546 uint32* service_texture_id) {
525 return false; 547 return false;
526 } 548 }
527 549
528 GLES2Decoder::GLES2Decoder() 550 GLES2Decoder::GLES2Decoder()
529 : initialized_(false), 551 : initialized_(false),
530 debug_(false), 552 debug_(false),
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); 724 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids);
703 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); 725 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids);
704 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); 726 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids);
705 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 727 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
706 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 728 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
707 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 729 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
708 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); 730 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
709 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 731 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
710 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); 732 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids);
711 733
734 // Helper for async upload token completion notification callback.
735 base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token,
736 uint32 sync_data_shm_id,
737 uint32 sync_data_shm_offset);
738
739
740
712 // Workarounds 741 // Workarounds
713 void OnFboChanged() const; 742 void OnFboChanged() const;
714 void OnUseFramebuffer() const; 743 void OnUseFramebuffer() const;
715 744
716 // TODO(gman): Cache these pointers? 745 // TODO(gman): Cache these pointers?
717 BufferManager* buffer_manager() { 746 BufferManager* buffer_manager() {
718 return group_->buffer_manager(); 747 return group_->buffer_manager();
719 } 748 }
720 749
721 RenderbufferManager* renderbuffer_manager() { 750 RenderbufferManager* renderbuffer_manager() {
(...skipping 9589 matching lines...) Expand 10 before | Expand all | Expand 10 after
10311 if (!texture_ref || 10340 if (!texture_ref ||
10312 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { 10341 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) {
10313 LOCAL_SET_GL_ERROR( 10342 LOCAL_SET_GL_ERROR(
10314 GL_INVALID_OPERATION, 10343 GL_INVALID_OPERATION,
10315 function_name, "transfer already in progress"); 10344 function_name, "transfer already in progress");
10316 return false; 10345 return false;
10317 } 10346 }
10318 return true; 10347 return true;
10319 } 10348 }
10320 10349
10350 base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure(
10351 uint32 async_upload_token,
10352 uint32 sync_data_shm_id,
10353 uint32 sync_data_shm_offset) {
10354 AsyncMemoryParams mem_params;
10355 gpu::Buffer buffer = GetSharedMemoryBuffer(sync_data_shm_id);
10356 if (!buffer.shared_memory)
10357 return base::Closure();
10358 mem_params.shared_memory = buffer.shared_memory;
10359 mem_params.shm_size = buffer.size;
10360 mem_params.shm_data_offset = sync_data_shm_offset;
10361 mem_params.shm_data_size = sizeof(AsyncUploadSync);
10362
10363 base::CheckedNumeric<uint32> end = mem_params.shm_data_offset;
10364 end += mem_params.shm_data_size;
10365 if (!end.IsValid() || end.ValueOrDie() > mem_params.shm_size)
10366 return base::Closure();
10367
10368 scoped_refptr<AsyncUploadTokenCompletionObserver> observer(
10369 new AsyncUploadTokenCompletionObserver(async_upload_token));
10370
10371 return base::Bind(
10372 &AsyncPixelTransferManager::AsyncNotifyCompletion,
10373 base::Unretained(GetAsyncPixelTransferManager()),
10374 mem_params,
10375 observer);
10376 }
10377
10321 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( 10378 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
10322 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { 10379 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) {
10323 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); 10380 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM");
10324 GLenum target = static_cast<GLenum>(c.target); 10381 GLenum target = static_cast<GLenum>(c.target);
10325 GLint level = static_cast<GLint>(c.level); 10382 GLint level = static_cast<GLint>(c.level);
10326 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use 10383 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use
10327 // unsigned integer for internalformat. 10384 // unsigned integer for internalformat.
10328 GLenum internal_format = static_cast<GLenum>(c.internalformat); 10385 GLenum internal_format = static_cast<GLenum>(c.internalformat);
10329 GLsizei width = static_cast<GLsizei>(c.width); 10386 GLsizei width = static_cast<GLsizei>(c.width);
10330 GLsizei height = static_cast<GLsizei>(c.height); 10387 GLsizei height = static_cast<GLsizei>(c.height);
10331 GLint border = static_cast<GLint>(c.border); 10388 GLint border = static_cast<GLint>(c.border);
10332 GLenum format = static_cast<GLenum>(c.format); 10389 GLenum format = static_cast<GLenum>(c.format);
10333 GLenum type = static_cast<GLenum>(c.type); 10390 GLenum type = static_cast<GLenum>(c.type);
10334 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); 10391 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id);
10335 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); 10392 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset);
10336 uint32 pixels_size; 10393 uint32 pixels_size;
10394 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10395 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10396 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10397
10398 base::ScopedClosureRunner scoped_completion_callback;
10399 if (async_upload_token) {
10400 base::Closure completion_closure =
10401 AsyncUploadTokenCompletionClosure(async_upload_token,
10402 sync_data_shm_id,
10403 sync_data_shm_offset);
10404 if (completion_closure.is_null())
10405 return error::kInvalidArguments;
10406
10407 scoped_completion_callback.Reset(completion_closure);
10408 }
10337 10409
10338 // TODO(epenner): Move this and copies of this memory validation 10410 // TODO(epenner): Move this and copies of this memory validation
10339 // into ValidateTexImage2D step. 10411 // into ValidateTexImage2D step.
10340 if (!GLES2Util::ComputeImageDataSizes( 10412 if (!GLES2Util::ComputeImageDataSizes(
10341 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, 10413 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL,
10342 NULL)) { 10414 NULL)) {
10343 return error::kOutOfBounds; 10415 return error::kOutOfBounds;
10344 } 10416 }
10345 const void* pixels = NULL; 10417 const void* pixels = NULL;
10346 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 10418 if (pixels_shm_id != 0 || pixels_shm_offset != 0) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
10421 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { 10493 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) {
10422 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 10494 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
10423 GLenum target = static_cast<GLenum>(c.target); 10495 GLenum target = static_cast<GLenum>(c.target);
10424 GLint level = static_cast<GLint>(c.level); 10496 GLint level = static_cast<GLint>(c.level);
10425 GLint xoffset = static_cast<GLint>(c.xoffset); 10497 GLint xoffset = static_cast<GLint>(c.xoffset);
10426 GLint yoffset = static_cast<GLint>(c.yoffset); 10498 GLint yoffset = static_cast<GLint>(c.yoffset);
10427 GLsizei width = static_cast<GLsizei>(c.width); 10499 GLsizei width = static_cast<GLsizei>(c.width);
10428 GLsizei height = static_cast<GLsizei>(c.height); 10500 GLsizei height = static_cast<GLsizei>(c.height);
10429 GLenum format = static_cast<GLenum>(c.format); 10501 GLenum format = static_cast<GLenum>(c.format);
10430 GLenum type = static_cast<GLenum>(c.type); 10502 GLenum type = static_cast<GLenum>(c.type);
10503 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token);
10504 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id);
10505 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
10506
10507 base::ScopedClosureRunner scoped_completion_callback;
10508 if (async_upload_token) {
10509 base::Closure completion_closure =
10510 AsyncUploadTokenCompletionClosure(async_upload_token,
10511 sync_data_shm_id,
10512 sync_data_shm_offset);
10513 if (completion_closure.is_null())
10514 return error::kInvalidArguments;
10515
10516 scoped_completion_callback.Reset(completion_closure);
10517 }
10431 10518
10432 // TODO(epenner): Move this and copies of this memory validation 10519 // TODO(epenner): Move this and copies of this memory validation
10433 // into ValidateTexSubImage2D step. 10520 // into ValidateTexSubImage2D step.
10434 uint32 data_size; 10521 uint32 data_size;
10435 if (!GLES2Util::ComputeImageDataSizes( 10522 if (!GLES2Util::ComputeImageDataSizes(
10436 width, height, format, type, state_.unpack_alignment, &data_size, 10523 width, height, format, type, state_.unpack_alignment, &data_size,
10437 NULL, NULL)) { 10524 NULL, NULL)) {
10438 return error::kOutOfBounds; 10525 return error::kOutOfBounds;
10439 } 10526 }
10440 const void* pixels = GetSharedMemoryAs<const void*>( 10527 const void* pixels = GetSharedMemoryAs<const void*>(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
10531 LOCAL_SET_GL_ERROR( 10618 LOCAL_SET_GL_ERROR(
10532 GL_INVALID_OPERATION, 10619 GL_INVALID_OPERATION,
10533 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); 10620 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started");
10534 return error::kNoError; 10621 return error::kNoError;
10535 } 10622 }
10536 delegate->WaitForTransferCompletion(); 10623 delegate->WaitForTransferCompletion();
10537 ProcessFinishedAsyncTransfers(); 10624 ProcessFinishedAsyncTransfers();
10538 return error::kNoError; 10625 return error::kNoError;
10539 } 10626 }
10540 10627
10628 error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM(
10629 uint32 immediate_data_size, const cmds::WaitAllAsyncTexImage2DCHROMIUM& c) {
10630 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM");
10631
10632 GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D();
10633 ProcessFinishedAsyncTransfers();
10634 return error::kNoError;
10635 }
10636
10541 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( 10637 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer(
10542 TextureRef* texture_ref) { 10638 TextureRef* texture_ref) {
10543 Texture* texture = texture_ref->texture(); 10639 Texture* texture = texture_ref->texture();
10544 DoDidUseTexImageIfNeeded(texture, texture->target()); 10640 DoDidUseTexImageIfNeeded(texture, texture->target());
10545 } 10641 }
10546 10642
10547 // Include the auto-generated part of this file. We split this because it means 10643 // Include the auto-generated part of this file. We split this because it means
10548 // we can easily edit the non-auto generated parts right here in this file 10644 // we can easily edit the non-auto generated parts right here in this file
10549 // instead of having to edit some template or the code generator. 10645 // instead of having to edit some template or the code generator.
10550 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10646 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10551 10647
10552 } // namespace gles2 10648 } // namespace gles2
10553 } // namespace gpu 10649 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698