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

Unified Diff: gpu/command_buffer/client/cmd_buffer_helper.cc

Issue 2550583002: gpu: Thread-safe command buffer state lookup. (Closed)
Patch Set: jbauman's review Created 4 years 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
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.h ('k') | gpu/command_buffer/client/cmd_buffer_helper_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/cmd_buffer_helper.cc
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc
index 0304b8f7e5d1ae6d4322bdd889729477746a822c..7021fa399f4ccf7f887667ab73589d5753206b43 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper.cc
@@ -27,12 +27,14 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
: command_buffer_(command_buffer),
ring_buffer_id_(-1),
ring_buffer_size_(0),
- entries_(NULL),
+ entries_(nullptr),
total_entry_count_(0),
immediate_entry_count_(0),
token_(0),
put_(0),
last_put_sent_(0),
+ cached_last_token_read_(0),
+ cached_get_offset_(0),
#if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK)
commands_issued_(0),
#endif
@@ -40,13 +42,6 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
context_lost_(false),
flush_automatically_(true),
flush_generation_(0) {
- // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
- // Don't register a dump provider in these cases.
- // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
- if (base::ThreadTaskRunnerHandle::IsSet()) {
- base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
- this, "gpu::CommandBufferHelper", base::ThreadTaskRunnerHandle::Get());
- }
}
void CommandBufferHelper::SetAutomaticFlushes(bool enabled) {
@@ -55,9 +50,8 @@ void CommandBufferHelper::SetAutomaticFlushes(bool enabled) {
}
bool CommandBufferHelper::IsContextLost() {
- if (!context_lost_) {
- context_lost_ = error::IsError(command_buffer()->GetLastError());
- }
+ if (!context_lost_)
+ context_lost_ = error::IsError(command_buffer()->GetLastState().error);
return context_lost_;
}
@@ -71,7 +65,7 @@ void CommandBufferHelper::CalcImmediateEntries(int waiting_count) {
}
// Get maximum safe contiguous entries.
- const int32_t curr_get = get_offset();
+ const int32_t curr_get = cached_get_offset_;
if (curr_get > put_) {
immediate_entry_count_ = curr_get - put_ - 1;
} else {
@@ -116,7 +110,7 @@ bool CommandBufferHelper::AllocateRingBuffer() {
command_buffer_->CreateTransferBuffer(ring_buffer_size_, &id);
if (id < 0) {
ClearUsable();
- DCHECK(error::IsError(command_buffer()->GetLastError()));
+ DCHECK(context_lost_);
return false;
}
@@ -128,6 +122,7 @@ bool CommandBufferHelper::AllocateRingBuffer() {
// Call to SetGetBuffer(id) above resets get and put offsets to 0.
// No need to query it through IPC.
put_ = 0;
+ cached_get_offset_ = 0;
CalcImmediateEntries(0);
return true;
}
@@ -143,8 +138,8 @@ void CommandBufferHelper::FreeResources() {
}
void CommandBufferHelper::FreeRingBuffer() {
- CHECK((put_ == get_offset()) ||
- error::IsError(command_buffer_->GetLastState().error));
+ CHECK((put_ == cached_get_offset_) ||
+ error::IsError(command_buffer_->GetLastState().error));
FreeResources();
}
@@ -154,19 +149,25 @@ bool CommandBufferHelper::Initialize(int32_t ring_buffer_size) {
}
CommandBufferHelper::~CommandBufferHelper() {
- base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
- this);
FreeResources();
}
+void CommandBufferHelper::UpdateCachedState(const CommandBuffer::State& state) {
+ cached_get_offset_ = state.get_offset;
+ cached_last_token_read_ = state.token;
+ context_lost_ = error::IsError(state.error);
+}
+
bool CommandBufferHelper::WaitForGetOffsetInRange(int32_t start, int32_t end) {
DCHECK(start >= 0 && start <= total_entry_count_);
DCHECK(end >= 0 && end <= total_entry_count_);
if (!usable()) {
return false;
}
- command_buffer_->WaitForGetOffsetInRange(start, end);
- return command_buffer_->GetLastError() == gpu::error::kNoError;
+ CommandBuffer::State last_state =
+ command_buffer_->WaitForGetOffsetInRange(start, end);
+ UpdateCachedState(last_state);
+ return !context_lost_;
}
void CommandBufferHelper::Flush() {
@@ -213,7 +214,7 @@ bool CommandBufferHelper::Finish() {
return false;
}
// If there is no work just exit.
- if (put_ == get_offset()) {
+ if (put_ == cached_get_offset_) {
return true;
}
DCHECK(HaveRingBuffer() ||
@@ -221,7 +222,7 @@ bool CommandBufferHelper::Finish() {
Flush();
if (!WaitForGetOffsetInRange(put_, put_))
return false;
- DCHECK_EQ(get_offset(), put_);
+ DCHECK_EQ(cached_get_offset_, put_);
CalcImmediateEntries(0);
@@ -246,14 +247,25 @@ int32_t CommandBufferHelper::InsertToken() {
cmd->Init(token_);
if (token_ == 0) {
TRACE_EVENT0("gpu", "CommandBufferHelper::InsertToken(wrapped)");
- // we wrapped
- Finish();
- DCHECK_EQ(token_, last_token_read());
+ bool finished = Finish(); // we wrapped
+ DCHECK(!finished || (cached_last_token_read_ == 0));
}
}
return token_;
}
+bool CommandBufferHelper::HasTokenPassed(int32_t token) {
+ // If token_ wrapped around we Finish'd.
+ if (token > token_)
+ return true;
+ // Don't update state if we don't have to.
+ if (token <= cached_last_token_read_)
+ return true;
+ CommandBuffer::State last_state = command_buffer_->GetLastState();
+ UpdateCachedState(last_state);
+ return token <= cached_last_token_read_;
+}
+
// Waits until the current token value is greater or equal to the value passed
// in argument.
void CommandBufferHelper::WaitForToken(int32_t token) {
@@ -263,11 +275,17 @@ void CommandBufferHelper::WaitForToken(int32_t token) {
// Return immediately if corresponding InsertToken failed.
if (token < 0)
return;
- if (token > token_) return; // we wrapped
- if (last_token_read() >= token)
+ if (token > token_)
+ return; // we wrapped
+ if (cached_last_token_read_ >= token)
+ return;
+ UpdateCachedState(command_buffer_->GetLastState());
+ if (cached_last_token_read_ >= token)
return;
Flush();
- command_buffer_->WaitForTokenInRange(token, token_);
+ CommandBuffer::State last_state =
+ command_buffer_->WaitForTokenInRange(token, token_);
+ UpdateCachedState(last_state);
}
// Waits for available entries, basically waiting until get >= put + count + 1.
@@ -288,13 +306,13 @@ void CommandBufferHelper::WaitForAvailableEntries(int32_t count) {
// but we need to make sure get wraps first, actually that get is 1 or
// more (since put will wrap to 0 after we add the noops).
DCHECK_LE(1, put_);
- int32_t curr_get = get_offset();
+ int32_t curr_get = cached_get_offset_;
if (curr_get > put_ || curr_get == 0) {
TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries");
Flush();
if (!WaitForGetOffsetInRange(1, put_))
return;
- curr_get = get_offset();
+ curr_get = cached_get_offset_;
DCHECK_LE(curr_get, put_);
DCHECK_NE(0, curr_get);
}
@@ -328,7 +346,7 @@ void CommandBufferHelper::WaitForAvailableEntries(int32_t count) {
}
int32_t CommandBufferHelper::GetTotalFreeEntriesNoWaiting() const {
- int32_t current_get_offset = get_offset();
+ int32_t current_get_offset = cached_get_offset_;
if (current_get_offset > put_) {
return current_get_offset - put_ - 1;
} else {
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.h ('k') | gpu/command_buffer/client/cmd_buffer_helper_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698