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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: [WIP] Review comments follow-up Created 6 years, 11 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/query_manager.h" 5 #include "gpu/command_buffer/service/query_manager.h"
6 6
7 #include "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h" 13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" 14 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/error_state.h" 16 #include "gpu/command_buffer/service/error_state.h"
16 #include "gpu/command_buffer/service/feature_info.h" 17 #include "gpu/command_buffer/service/feature_info.h"
17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
18 19
19 namespace gpu { 20 namespace gpu {
20 namespace gles2 { 21 namespace gles2 {
21 22
22 namespace { 23 namespace {
23 24
24 class AsyncPixelTransferCompletionObserverImpl 25 class AsyncPixelTransferCompletionObserverImpl
25 : public AsyncPixelTransferCompletionObserver { 26 : public AsyncPixelTransferCompletionObserver {
26 public: 27 public:
27 AsyncPixelTransferCompletionObserverImpl(uint32 submit_count) 28 AsyncPixelTransferCompletionObserverImpl(
28 : submit_count_(submit_count), 29 base::WeakPtr<QueryManager> manager,
30 scoped_refptr<base::MessageLoopProxy> proxy,
31 uint32 submit_count,
32 uint32 serial)
33 : manager_(manager),
34 proxy_(proxy),
35 submit_count_(submit_count),
36 serial_(serial),
29 cancelled_(false) {} 37 cancelled_(false) {}
30 38
31 void Cancel() { 39 void Cancel() {
32 base::AutoLock locked(lock_); 40 base::AutoLock locked(lock_);
33 cancelled_ = true; 41 cancelled_ = true;
34 } 42 }
35 43
36 virtual void DidComplete(const AsyncMemoryParams& mem_params) OVERRIDE { 44 virtual void DidComplete(const AsyncMemoryParams& mem_params) OVERRIDE {
37 base::AutoLock locked(lock_); 45 base::AutoLock locked(lock_);
38 if (!cancelled_) { 46 if (!cancelled_) {
39 DCHECK(mem_params.shared_memory); 47 DCHECK(mem_params.shared_memory);
40 DCHECK(mem_params.shared_memory->memory()); 48 DCHECK(mem_params.shared_memory->memory());
41 void* data = static_cast<int8*>(mem_params.shared_memory->memory()) + 49 void* data = static_cast<int8*>(mem_params.shared_memory->memory()) +
42 mem_params.shm_data_offset; 50 mem_params.shm_data_offset;
43 QuerySync* sync = static_cast<QuerySync*>(data); 51 QuerySync* sync = static_cast<QuerySync*>(data);
44 52
45 // Need a MemoryBarrier here to ensure that upload completed before 53 // Need a MemoryBarrier here to ensure that upload completed before
46 // submit_count was written to sync->process_count. 54 // submit_count was written to sync->process_count.
47 base::subtle::MemoryBarrier(); 55 base::subtle::MemoryBarrier();
48 sync->process_count = submit_count_; 56 sync->process_count = submit_count_;
57
58 if (serial_) {
59 proxy_->PostTask(
60 FROM_HERE,
61 base::Bind(&AsyncPixelTransferCompletionObserverImpl::SetSerial,
62 this));
63 }
49 } 64 }
50 } 65 }
51 66
52 private: 67 private:
53 virtual ~AsyncPixelTransferCompletionObserverImpl() {} 68 virtual ~AsyncPixelTransferCompletionObserverImpl() {}
54 69
70 void SetSerial() {
71 if (!manager_.get())
72 return;
73
74 manager_->decoder()->engine()->set_serial(serial_);
75 }
76
77 base::WeakPtr<QueryManager> manager_;
78 scoped_refptr<base::MessageLoopProxy> proxy_;
79
55 uint32 submit_count_; 80 uint32 submit_count_;
81 uint32 serial_;
56 82
57 base::Lock lock_; 83 base::Lock lock_;
58 bool cancelled_; 84 bool cancelled_;
59 85
60 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferCompletionObserverImpl); 86 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferCompletionObserverImpl);
61 }; 87 };
62 88
63 class AsyncPixelTransfersCompletedQuery 89 class AsyncPixelTransfersCompletedQuery
64 : public QueryManager::Query, 90 : public QueryManager::Query,
65 public base::SupportsWeakPtr<AsyncPixelTransfersCompletedQuery> { 91 public base::SupportsWeakPtr<AsyncPixelTransfersCompletedQuery> {
(...skipping 26 matching lines...) Expand all
92 // Get the real shared memory since it might need to be duped to prevent 118 // Get the real shared memory since it might need to be duped to prevent
93 // use-after-free of the memory. 119 // use-after-free of the memory.
94 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id()); 120 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id());
95 if (!buffer.shared_memory) 121 if (!buffer.shared_memory)
96 return false; 122 return false;
97 mem_params.shared_memory = buffer.shared_memory; 123 mem_params.shared_memory = buffer.shared_memory;
98 mem_params.shm_size = buffer.size; 124 mem_params.shm_size = buffer.size;
99 mem_params.shm_data_offset = shm_offset(); 125 mem_params.shm_data_offset = shm_offset();
100 mem_params.shm_data_size = sizeof(QuerySync); 126 mem_params.shm_data_size = sizeof(QuerySync);
101 127
102 observer_ = new AsyncPixelTransferCompletionObserverImpl(submit_count); 128 scoped_refptr<base::MessageLoopProxy> proxy =
129 base::MessageLoop::current()->message_loop_proxy();
130 observer_ = new AsyncPixelTransferCompletionObserverImpl(
131 manager()->AsWeakPtr(), proxy, submit_count, serial());
103 132
104 // Ask AsyncPixelTransferDelegate to run completion callback after all 133 // Ask AsyncPixelTransferDelegate to run completion callback after all
105 // previous async transfers are done. No guarantee that callback is run 134 // previous async transfers are done. No guarantee that callback is run
106 // on the current thread. 135 // on the current thread.
107 manager()->decoder()->GetAsyncPixelTransferManager() 136 manager()->decoder()->GetAsyncPixelTransferManager()
108 ->AsyncNotifyCompletion(mem_params, observer_); 137 ->AsyncNotifyCompletion(mem_params, observer_);
109 138
110 return AddToPendingTransferQueue(submit_count); 139 return AddToPendingTransferQueue(submit_count);
111 } 140 }
112 141
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 bool QueryManager::EndQuery(Query* query, uint32 submit_count) { 700 bool QueryManager::EndQuery(Query* query, uint32 submit_count) {
672 DCHECK(query); 701 DCHECK(query);
673 if (!RemovePendingQuery(query)) { 702 if (!RemovePendingQuery(query)) {
674 return false; 703 return false;
675 } 704 }
676 return query->End(submit_count); 705 return query->End(submit_count);
677 } 706 }
678 707
679 } // namespace gles2 708 } // namespace gles2
680 } // namespace gpu 709 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698