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

Side by Side Diff: content/common/gpu/client/command_buffer_proxy_impl.cc

Issue 1331843005: Implemented new fence syncs which replaces the old sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed memory leak Created 5 years, 2 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 "content/common/gpu/client/command_buffer_proxy_impl.h" 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 28 matching lines...) Expand all
39 int32 route_id, 39 int32 route_id,
40 int32 stream_id) 40 int32 stream_id)
41 : lock_(nullptr), 41 : lock_(nullptr),
42 channel_(channel), 42 channel_(channel),
43 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), 43 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)),
44 route_id_(route_id), 44 route_id_(route_id),
45 stream_id_(stream_id), 45 stream_id_(stream_id),
46 flush_count_(0), 46 flush_count_(0),
47 last_put_offset_(-1), 47 last_put_offset_(-1),
48 last_barrier_put_offset_(-1), 48 last_barrier_put_offset_(-1),
49 next_fence_sync_release_(1),
50 flushed_fence_sync_release_(0),
51 verified_fence_sync_release_(0),
49 next_signal_id_(0) { 52 next_signal_id_(0) {
50 DCHECK(channel); 53 DCHECK(channel);
51 } 54 }
52 55
53 CommandBufferProxyImpl::~CommandBufferProxyImpl() { 56 CommandBufferProxyImpl::~CommandBufferProxyImpl() {
54 FOR_EACH_OBSERVER(DeletionObserver, 57 FOR_EACH_OBSERVER(DeletionObserver,
55 deletion_observers_, 58 deletion_observers_,
56 OnWillDeleteImpl()); 59 OnWillDeleteImpl());
57 if (channel_) { 60 if (channel_) {
58 channel_->DestroyCommandBuffer(this); 61 channel_->DestroyCommandBuffer(this);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 TRACE_EVENT1("gpu", 227 TRACE_EVENT1("gpu",
225 "CommandBufferProxyImpl::Flush", 228 "CommandBufferProxyImpl::Flush",
226 "put_offset", 229 "put_offset",
227 put_offset); 230 put_offset);
228 231
229 bool put_offset_changed = last_put_offset_ != put_offset; 232 bool put_offset_changed = last_put_offset_ != put_offset;
230 last_put_offset_ = put_offset; 233 last_put_offset_ = put_offset;
231 last_barrier_put_offset_ = put_offset; 234 last_barrier_put_offset_ = put_offset;
232 235
233 if (channel_) { 236 if (channel_) {
234 channel_->OrderingBarrier(route_id_, stream_id_, put_offset, ++flush_count_, 237 const uint32_t flush_id =
235 latency_info_, put_offset_changed, true); 238 channel_->OrderingBarrier(route_id_, stream_id_, put_offset,
239 ++flush_count_, latency_info_,
240 put_offset_changed, true);
241 if (put_offset_changed) {
242 DCHECK(flush_id);
243 const uint64_t fence_sync_release = next_fence_sync_release_ - 1;
244 if (fence_sync_release > flushed_fence_sync_release_) {
245 flushed_fence_sync_release_ = fence_sync_release;
246 flushed_release_flush_id_.push(std::make_pair(fence_sync_release,
247 flush_id));
248 }
249 }
236 } 250 }
237 251
238 if (put_offset_changed) 252 if (put_offset_changed)
239 latency_info_.clear(); 253 latency_info_.clear();
240 } 254 }
241 255
242 void CommandBufferProxyImpl::OrderingBarrier(int32 put_offset) { 256 void CommandBufferProxyImpl::OrderingBarrier(int32 put_offset) {
243 if (last_state_.error != gpu::error::kNoError) 257 if (last_state_.error != gpu::error::kNoError)
244 return; 258 return;
245 259
246 TRACE_EVENT1("gpu", "CommandBufferProxyImpl::OrderingBarrier", "put_offset", 260 TRACE_EVENT1("gpu", "CommandBufferProxyImpl::OrderingBarrier", "put_offset",
247 put_offset); 261 put_offset);
248 262
249 bool put_offset_changed = last_barrier_put_offset_ != put_offset; 263 bool put_offset_changed = last_barrier_put_offset_ != put_offset;
250 last_barrier_put_offset_ = put_offset; 264 last_barrier_put_offset_ = put_offset;
251 265
252 if (channel_) { 266 if (channel_) {
253 channel_->OrderingBarrier(route_id_, stream_id_, put_offset, ++flush_count_, 267 const uint32_t flush_id =
254 latency_info_, put_offset_changed, false); 268 channel_->OrderingBarrier(route_id_, stream_id_, put_offset,
269 ++flush_count_, latency_info_,
270 put_offset_changed, false);
271 if (put_offset_changed) {
272 DCHECK(flush_id);
273 const uint64_t fence_sync_release = next_fence_sync_release_ - 1;
274 if (fence_sync_release > flushed_fence_sync_release_) {
275 flushed_fence_sync_release_ = fence_sync_release;
276 flushed_release_flush_id_.push(std::make_pair(fence_sync_release,
277 flush_id));
278 }
279 }
255 } 280 }
256 281
257 if (put_offset_changed) 282 if (put_offset_changed)
258 latency_info_.clear(); 283 latency_info_.clear();
259 } 284 }
260 285
261 void CommandBufferProxyImpl::SetLatencyInfo( 286 void CommandBufferProxyImpl::SetLatencyInfo(
262 const std::vector<ui::LatencyInfo>& latency_info) { 287 const std::vector<ui::LatencyInfo>& latency_info) {
263 CheckLock(); 288 CheckLock();
264 for (size_t i = 0; i < latency_info.size(); i++) 289 for (size_t i = 0; i < latency_info.size(); i++)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 510 }
486 511
487 gpu::CommandBufferNamespace CommandBufferProxyImpl::GetNamespaceID() const { 512 gpu::CommandBufferNamespace CommandBufferProxyImpl::GetNamespaceID() const {
488 return gpu::CommandBufferNamespace::GPU_IO; 513 return gpu::CommandBufferNamespace::GPU_IO;
489 } 514 }
490 515
491 uint64_t CommandBufferProxyImpl::GetCommandBufferID() const { 516 uint64_t CommandBufferProxyImpl::GetCommandBufferID() const {
492 return command_buffer_id_; 517 return command_buffer_id_;
493 } 518 }
494 519
520 uint64_t CommandBufferProxyImpl::GenerateFenceSyncRelease() {
521 return next_fence_sync_release_++;
522 }
523
524 bool CommandBufferProxyImpl::IsFenceSyncRelease(uint64_t release) {
525 return release != 0 && release < next_fence_sync_release_;
526 }
527
528 bool CommandBufferProxyImpl::IsFenceSyncFlushed(uint64_t release) {
529 CheckLock();
530 if (last_state_.error != gpu::error::kNoError)
531 return false;
532
533 if (release <= verified_fence_sync_release_)
534 return true;
535
536 // Check if we have actually flushed the fence sync release.
537 if (release <= flushed_fence_sync_release_) {
538 DCHECK(!flushed_release_flush_id_.empty());
539 // Check if it has already been validated by another context.
540 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_));
541 if (release <= verified_fence_sync_release_)
542 return true;
543
544 // Has not been validated, validate it now.
545 UpdateVerifiedReleases(channel_->ValidateFlushIDReachedServer(stream_id_));
546 return (release <= verified_fence_sync_release_);
547 }
548
549 return false;
550 }
551
495 uint32 CommandBufferProxyImpl::InsertSyncPoint() { 552 uint32 CommandBufferProxyImpl::InsertSyncPoint() {
496 CheckLock(); 553 CheckLock();
497 if (last_state_.error != gpu::error::kNoError) 554 if (last_state_.error != gpu::error::kNoError)
498 return 0; 555 return 0;
499 556
500 uint32 sync_point = 0; 557 uint32 sync_point = 0;
501 Send(new GpuCommandBufferMsg_InsertSyncPoint(route_id_, true, &sync_point)); 558 Send(new GpuCommandBufferMsg_InsertSyncPoint(route_id_, true, &sync_point));
502 return sync_point; 559 return sync_point;
503 } 560 }
504 561
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 const GpuConsoleMessageCallback& callback) { 688 const GpuConsoleMessageCallback& callback) {
632 CheckLock(); 689 CheckLock();
633 console_message_callback_ = callback; 690 console_message_callback_ = callback;
634 } 691 }
635 692
636 void CommandBufferProxyImpl::TryUpdateState() { 693 void CommandBufferProxyImpl::TryUpdateState() {
637 if (last_state_.error == gpu::error::kNoError) 694 if (last_state_.error == gpu::error::kNoError)
638 shared_state()->Read(&last_state_); 695 shared_state()->Read(&last_state_);
639 } 696 }
640 697
698 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) {
699 while (!flushed_release_flush_id_.empty()) {
700 const std::pair<uint64_t, uint32_t>& front_item =
701 flushed_release_flush_id_.front();
702 if (front_item.second > verified_flush)
703 break;
704 verified_fence_sync_release_ = front_item.first;
705 flushed_release_flush_id_.pop();
706 }
707 }
708
641 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { 709 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const {
642 return reinterpret_cast<gpu::CommandBufferSharedState*>( 710 return reinterpret_cast<gpu::CommandBufferSharedState*>(
643 shared_state_shm_->memory()); 711 shared_state_shm_->memory());
644 } 712 }
645 713
646 void CommandBufferProxyImpl::OnSwapBuffersCompleted( 714 void CommandBufferProxyImpl::OnSwapBuffersCompleted(
647 const std::vector<ui::LatencyInfo>& latency_info, 715 const std::vector<ui::LatencyInfo>& latency_info,
648 gfx::SwapResult result) { 716 gfx::SwapResult result) {
649 if (!swap_buffers_completion_callback_.is_null()) { 717 if (!swap_buffers_completion_callback_.is_null()) {
650 if (!ui::LatencyInfo::Verify( 718 if (!ui::LatencyInfo::Verify(
651 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { 719 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) {
652 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>(), 720 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>(),
653 result); 721 result);
654 return; 722 return;
655 } 723 }
656 swap_buffers_completion_callback_.Run(latency_info, result); 724 swap_buffers_completion_callback_.Run(latency_info, result);
657 } 725 }
658 } 726 }
659 727
660 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, 728 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase,
661 base::TimeDelta interval) { 729 base::TimeDelta interval) {
662 if (!update_vsync_parameters_completion_callback_.is_null()) 730 if (!update_vsync_parameters_completion_callback_.is_null())
663 update_vsync_parameters_completion_callback_.Run(timebase, interval); 731 update_vsync_parameters_completion_callback_.Run(timebase, interval);
664 } 732 }
665 733
666 } // namespace content 734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698