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

Unified Diff: gpu/command_buffer/service/gpu_timing.cc

Issue 940633004: Added disjoint context class which manages disjoints within gpu timing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize disjoint value to proper value Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gpu_timing.cc
diff --git a/gpu/command_buffer/service/gpu_timing.cc b/gpu/command_buffer/service/gpu_timing.cc
index 8716448a4ad507c714a1b7c8a061271763d18906..e8472e04f597e287f9cf642686b54c2db889a345 100644
--- a/gpu/command_buffer/service/gpu_timing.cc
+++ b/gpu/command_buffer/service/gpu_timing.cc
@@ -62,10 +62,42 @@ int64 GPUTimer::GetDeltaElapsed() {
return end - start;
}
+DisjointContext::DisjointContext(GPUTiming* gpu_timing, bool disjoint_value)
+ : gpu_timing_(gpu_timing),
Daniele Castagna 2015/02/19 18:15:32 Can gpu_timing be null? I'd add a DCHECK.
David Yen 2015/02/19 19:00:47 Done.
+ disjoint_value_(disjoint_value) {
+}
+
+bool DisjointContext::CheckAndResetTimerErrors() {
+ if (gpu_timing_) {
Daniele Castagna 2015/02/20 01:38:18 Should we make sure that gpu_timing_ is set here?
+ gpu_timing_->UpdateDisjointContexts();
+ }
+ bool previous_disjoint_value = disjoint_value_;
+ disjoint_value_ = false;
+ return previous_disjoint_value;
+}
+
+void DisjointContext::ResetParentGPUTiming() {
+ gpu_timing_ = NULL;
+}
+
+void DisjointContext::SetDisjoint() {
+ disjoint_value_ = true;
+}
+
+DisjointContext::~DisjointContext() {
+ if (gpu_timing_) {
+ gpu_timing_->RemoveDisjointContext(this);
+ }
+}
+
GPUTiming::GPUTiming() : cpu_time_for_testing_() {
}
GPUTiming::~GPUTiming() {
+ // Notify any disjoint contexts that the parent no longer exists.
+ for (DisjointContext* context_iter : disjoint_contexts_) {
Daniele Castagna 2015/02/19 18:15:32 Do we really need to handle the case where GPUTimi
David Yen 2015/02/19 19:00:47 Unfortunately I think this is necessary because GP
Daniele Castagna 2015/02/19 20:55:52 Isn't the lifetime of those objects completely con
David Yen 2015/02/19 22:48:03 I've added a test for this. I'm not referring to
Daniele Castagna 2015/02/20 01:38:18 Sorry if I insist on this, but I still stand with
David Yen 2015/02/20 02:02:57 We are going to use those objects in that way in g
+ context_iter->ResetParentGPUTiming();
+ }
}
bool GPUTiming::Initialize(gfx::GLContext* gl_context) {
@@ -89,6 +121,11 @@ bool GPUTiming::IsAvailable() {
return timer_type_ != kTimerTypeInvalid;
}
+scoped_refptr<DisjointContext> GPUTiming::CreateDisjointContext() {
+ disjoint_contexts_.push_back(new DisjointContext(this, disjoint_occurred_));
+ return disjoint_contexts_.back();
+}
+
const char* GPUTiming::GetTimerTypeName() const {
switch (timer_type_) {
case kTimerTypeDisjoint:
@@ -100,16 +137,6 @@ const char* GPUTiming::GetTimerTypeName() const {
}
}
-bool GPUTiming::CheckAndResetTimerErrors() {
- if (timer_type_ == kTimerTypeDisjoint) {
- GLint disjoint_value = 0;
- glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
- return disjoint_value != 0;
- } else {
- return false;
- }
-}
-
int64 GPUTiming::CalculateTimerOffset() {
if (!offset_valid_) {
GLint64 gl_now = 0;
@@ -142,4 +169,34 @@ void GPUTiming::SetTimerTypeForTesting(TimerType type) {
timer_type_ = type;
}
+void GPUTiming::UpdateDisjointContexts() {
+ if (timer_type_ == kTimerTypeDisjoint) {
+ GLint disjoint_value = 0;
+ glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
+ if (disjoint_value != 0) {
Daniele Castagna 2015/02/19 18:15:32 I personally like being explicit with != 0, but in
David Yen 2015/02/19 19:00:47 I just moved this code from the previous version l
Daniele Castagna 2015/02/19 20:55:53 It was just FYI, I didn't necessarily expect any a
+ disjoint_occurred_ = true;
+ for (DisjointContext* context_iter : disjoint_contexts_) {
Daniele Castagna 2015/02/19 18:15:32 nit: "context_iter" is not an iterator, I'd rename
David Yen 2015/02/19 19:00:47 Done.
+ context_iter->SetDisjoint();
+ }
+ }
+ }
+}
+
+void GPUTiming::RemoveDisjointContext(DisjointContext* context) {
+ bool item_found = false;
Daniele Castagna 2015/02/19 18:15:32 Assuming we can use algorithms from stl in Chromiu
David Yen 2015/02/19 19:00:47 I was trying to avoid shifting memory because this
Daniele Castagna 2015/02/19 20:55:53 If you want to avoid shifting a few pointers, what
David Yen 2015/02/19 22:48:03 Done.
+ auto last_item = disjoint_contexts_.end() - 1;
+ for (auto context_iter = disjoint_contexts_.begin();
+ context_iter != disjoint_contexts_.end();
+ ++context_iter) {
+ if (*context_iter == context) {
+ item_found = true;
+ if (context_iter != last_item) {
+ std::iter_swap(context_iter, last_item);
+ }
+ }
+ }
+ DCHECK(item_found);
+ disjoint_contexts_.resize(disjoint_contexts_.size()-1);
+}
+
} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698