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

Side by Side Diff: gpu/command_buffer/client/query_tracker.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/client/query_tracker.h" 5 #include "gpu/command_buffer/client/query_tracker.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h> 9 #include <GLES2/gl2extchromium.h>
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 QueryTracker::Query::Query(GLuint id, GLenum target, 87 QueryTracker::Query::Query(GLuint id, GLenum target,
88 const QuerySyncManager::QueryInfo& info) 88 const QuerySyncManager::QueryInfo& info)
89 : id_(id), 89 : id_(id),
90 target_(target), 90 target_(target),
91 info_(info), 91 info_(info),
92 state_(kUninitialized), 92 state_(kUninitialized),
93 submit_count_(0), 93 submit_count_(0),
94 token_(0), 94 token_(0),
95 flushed_(false), 95 flushed_(false),
96 serial_(0),
96 client_begin_time_us_(0), 97 client_begin_time_us_(0),
97 result_(0) { 98 result_(0) {
98 } 99 }
99 100
100 101
101 void QueryTracker::Query::Begin(GLES2Implementation* gl) { 102 void QueryTracker::Query::Begin(GLES2Implementation* gl) {
102 // init memory, inc count 103 // init memory, inc count
103 MarkAsActive(); 104 MarkAsActive();
104 105
105 switch (target()) { 106 switch (target()) {
106 case GL_GET_ERROR_QUERY_CHROMIUM: 107 case GL_GET_ERROR_QUERY_CHROMIUM:
107 // To nothing on begin for error queries. 108 // To nothing on begin for error queries.
108 break; 109 break;
109 case GL_LATENCY_QUERY_CHROMIUM: 110 case GL_LATENCY_QUERY_CHROMIUM:
110 client_begin_time_us_ = MicrosecondsSinceOriginOfTime(); 111 client_begin_time_us_ = MicrosecondsSinceOriginOfTime();
111 // tell service about id, shared memory and count 112 // tell service about id, shared memory and count
112 gl->helper()->BeginQueryEXT(target(), id(), shm_id(), shm_offset()); 113 gl->helper()->BeginQueryEXT(
114 target(), id(), serial(), shm_id(), shm_offset());
113 break; 115 break;
114 case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: 116 case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM:
115 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: 117 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM:
116 default: 118 default:
117 // tell service about id, shared memory and count 119 // tell service about id, shared memory and count
118 gl->helper()->BeginQueryEXT(target(), id(), shm_id(), shm_offset()); 120 gl->helper()->BeginQueryEXT(
121 target(), id(), serial(), shm_id(), shm_offset());
119 break; 122 break;
120 } 123 }
121 } 124 }
122 125
123 void QueryTracker::Query::End(GLES2Implementation* gl) { 126 void QueryTracker::Query::End(GLES2Implementation* gl) {
124 switch (target()) { 127 switch (target()) {
125 case GL_GET_ERROR_QUERY_CHROMIUM: { 128 case GL_GET_ERROR_QUERY_CHROMIUM: {
126 GLenum error = gl->GetClientSideGLError(); 129 GLenum error = gl->GetClientSideGLError();
127 if (error == GL_NO_ERROR) { 130 if (error == GL_NO_ERROR) {
128 // There was no error so start the query on the serivce. 131 // There was no error so start the query on the serivce.
129 // it will end immediately. 132 // it will end immediately.
130 gl->helper()->BeginQueryEXT(target(), id(), shm_id(), shm_offset()); 133 gl->helper()->BeginQueryEXT(
134 target(), id(), serial(), shm_id(), shm_offset());
131 } else { 135 } else {
132 // There's an error on the client, no need to bother the service. just 136 // There's an error on the client, no need to bother the service. just
133 // set the query as completed and return the error. 137 // set the query as completed and return the error.
134 if (error != GL_NO_ERROR) { 138 if (error != GL_NO_ERROR) {
135 state_ = kComplete; 139 state_ = kComplete;
136 result_ = error; 140 result_ = error;
137 return; 141 return;
138 } 142 }
139 } 143 }
140 } 144 }
141 } 145 }
142 gl->helper()->EndQueryEXT(target(), submit_count()); 146 gl->helper()->EndQueryEXT(target(), serial(), submit_count());
143 MarkAsPending(gl->helper()->InsertToken()); 147 MarkAsPending(gl->helper()->InsertToken());
144 } 148 }
145 149
146 bool QueryTracker::Query::CheckResultsAvailable( 150 bool QueryTracker::Query::CheckResultsAvailable(
147 CommandBufferHelper* helper) { 151 CommandBufferHelper* helper) {
148 if (Pending()) { 152 if (Pending()) {
149 if (info_.sync->process_count == submit_count_ || 153 if (info_.sync->process_count == submit_count_ ||
150 helper->IsContextLost()) { 154 helper->IsContextLost()) {
151 // Need a MemoryBarrier here so that sync->result read after 155 // Need a MemoryBarrier here so that sync->result read after
152 // sync->process_count. 156 // sync->process_count.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 188 }
185 return state_ == kComplete; 189 return state_ == kComplete;
186 } 190 }
187 191
188 uint32 QueryTracker::Query::GetResult() const { 192 uint32 QueryTracker::Query::GetResult() const {
189 DCHECK(state_ == kComplete || state_ == kUninitialized); 193 DCHECK(state_ == kComplete || state_ == kUninitialized);
190 return result_; 194 return result_;
191 } 195 }
192 196
193 QueryTracker::QueryTracker(MappedMemoryManager* manager) 197 QueryTracker::QueryTracker(MappedMemoryManager* manager)
194 : query_sync_manager_(manager) { 198 : query_sync_manager_(manager),
199 next_serial_(1) {
195 } 200 }
196 201
197 QueryTracker::~QueryTracker() { 202 QueryTracker::~QueryTracker() {
198 while (!queries_.empty()) { 203 while (!queries_.empty()) {
199 delete queries_.begin()->second; 204 delete queries_.begin()->second;
200 queries_.erase(queries_.begin()); 205 queries_.erase(queries_.begin());
201 } 206 }
202 while (!removed_queries_.empty()) { 207 while (!removed_queries_.empty()) {
203 delete removed_queries_.front(); 208 delete removed_queries_.front();
204 removed_queries_.pop_front(); 209 removed_queries_.pop_front();
205 } 210 }
206 } 211 }
207 212
208 QueryTracker::Query* QueryTracker::CreateQuery(GLuint id, GLenum target) { 213 QueryTracker::Query* QueryTracker::CreateQuery(
214 GLuint id, GLenum target) {
209 DCHECK_NE(0u, id); 215 DCHECK_NE(0u, id);
210 FreeCompletedQueries(); 216 FreeCompletedQueries();
211 QuerySyncManager::QueryInfo info; 217 QuerySyncManager::QueryInfo info;
212 if (!query_sync_manager_.Alloc(&info)) { 218 if (!query_sync_manager_.Alloc(&info)) {
213 return NULL; 219 return NULL;
214 } 220 }
215 Query* query = new Query(id, target, info); 221 Query* query = new Query(id, target, info);
216 std::pair<QueryMap::iterator, bool> result = 222 std::pair<QueryMap::iterator, bool> result =
217 queries_.insert(std::make_pair(id, query)); 223 queries_.insert(std::make_pair(id, query));
218 DCHECK(result.second); 224 DCHECK(result.second);
219 return query; 225 return query;
220 } 226 }
221 227
228 QueryTracker::Query* QueryTracker::CreateInternalQuery(
229 GLuint id, GLenum target) {
230 Query* query = CreateQuery(id, target);
231 query->set_serial(NextSerial());
232 return query;
233 }
234
222 QueryTracker::Query* QueryTracker::GetQuery( 235 QueryTracker::Query* QueryTracker::GetQuery(
223 GLuint client_id) { 236 GLuint client_id) {
224 QueryMap::iterator it = queries_.find(client_id); 237 QueryMap::iterator it = queries_.find(client_id);
225 return it != queries_.end() ? it->second : NULL; 238 return it != queries_.end() ? it->second : NULL;
226 } 239 }
227 240
228 void QueryTracker::RemoveQuery(GLuint client_id) { 241 void QueryTracker::RemoveQuery(GLuint client_id) {
229 QueryMap::iterator it = queries_.find(client_id); 242 QueryMap::iterator it = queries_.find(client_id);
230 if (it != queries_.end()) { 243 if (it != queries_.end()) {
231 Query* query = it->second; 244 Query* query = it->second;
(...skipping 21 matching lines...) Expand all
253 ++it; 266 ++it;
254 continue; 267 continue;
255 } 268 }
256 269
257 query_sync_manager_.Free(query->info_); 270 query_sync_manager_.Free(query->info_);
258 it = removed_queries_.erase(it); 271 it = removed_queries_.erase(it);
259 delete query; 272 delete query;
260 } 273 }
261 } 274 }
262 275
276 uint32 QueryTracker::NextSerial() {
277 uint32 serial = next_serial_++;
278 if (serial == 0)
279 return NextSerial();
280 return serial;
281 }
282
263 } // namespace gles2 283 } // namespace gles2
264 } // namespace gpu 284 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698