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

Side by Side Diff: gpu/command_buffer/client/cmd_buffer_helper.cc

Issue 6862002: Merge gpu_trace_event back into base/debug/trace_event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge to 84062 Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains the implementation of the command buffer helper class. 5 // This file contains the implementation of the command buffer helper class.
6 6
7 #include "../client/cmd_buffer_helper.h" 7 #include "../client/cmd_buffer_helper.h"
8 #include "../common/command_buffer.h" 8 #include "../common/command_buffer.h"
9 #include "gpu/common/gpu_trace_event.h" 9 #include "../common/trace_event.h"
10 10
11 namespace gpu { 11 namespace gpu {
12 12
13 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) 13 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
14 : command_buffer_(command_buffer), 14 : command_buffer_(command_buffer),
15 entries_(NULL), 15 entries_(NULL),
16 total_entry_count_(0), 16 total_entry_count_(0),
17 usable_entry_count_(0), 17 usable_entry_count_(0),
18 token_(0), 18 token_(0),
19 last_token_read_(-1), 19 last_token_read_(-1),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 void CommandBufferHelper::Flush() { 57 void CommandBufferHelper::Flush() {
58 last_put_sent_ = put_; 58 last_put_sent_ = put_;
59 command_buffer_->Flush(put_); 59 command_buffer_->Flush(put_);
60 } 60 }
61 61
62 // Calls Flush() and then waits until the buffer is empty. Break early if the 62 // Calls Flush() and then waits until the buffer is empty. Break early if the
63 // error is set. 63 // error is set.
64 bool CommandBufferHelper::Finish() { 64 bool CommandBufferHelper::Finish() {
65 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::Finish"); 65 TRACE_EVENT0("gpu", "CommandBufferHelper::Finish");
66 do { 66 do {
67 // Do not loop forever if the flush fails, meaning the command buffer reader 67 // Do not loop forever if the flush fails, meaning the command buffer reader
68 // has shutdown. 68 // has shutdown.
69 if (!FlushSync()) 69 if (!FlushSync())
70 return false; 70 return false;
71 } while (put_ != get_); 71 } while (put_ != get_);
72 72
73 return true; 73 return true;
74 } 74 }
75 75
76 // Inserts a new token into the command stream. It uses an increasing value 76 // Inserts a new token into the command stream. It uses an increasing value
77 // scheme so that we don't lose tokens (a token has passed if the current token 77 // scheme so that we don't lose tokens (a token has passed if the current token
78 // value is higher than that token). Calls Finish() if the token value wraps, 78 // value is higher than that token). Calls Finish() if the token value wraps,
79 // which will be rare. 79 // which will be rare.
80 int32 CommandBufferHelper::InsertToken() { 80 int32 CommandBufferHelper::InsertToken() {
81 // Increment token as 31-bit integer. Negative values are used to signal an 81 // Increment token as 31-bit integer. Negative values are used to signal an
82 // error. 82 // error.
83 token_ = (token_ + 1) & 0x7FFFFFFF; 83 token_ = (token_ + 1) & 0x7FFFFFFF;
84 cmd::SetToken& cmd = GetCmdSpace<cmd::SetToken>(); 84 cmd::SetToken& cmd = GetCmdSpace<cmd::SetToken>();
85 cmd.Init(token_); 85 cmd.Init(token_);
86 if (token_ == 0) { 86 if (token_ == 0) {
87 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::InsertToken(wrapped)"); 87 TRACE_EVENT0("gpu", "CommandBufferHelper::InsertToken(wrapped)");
88 // we wrapped 88 // we wrapped
89 Finish(); 89 Finish();
90 GPU_DCHECK_EQ(token_, last_token_read_); 90 GPU_DCHECK_EQ(token_, last_token_read_);
91 } 91 }
92 return token_; 92 return token_;
93 } 93 }
94 94
95 // Waits until the current token value is greater or equal to the value passed 95 // Waits until the current token value is greater or equal to the value passed
96 // in argument. 96 // in argument.
97 void CommandBufferHelper::WaitForToken(int32 token) { 97 void CommandBufferHelper::WaitForToken(int32 token) {
98 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForToken"); 98 TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForToken");
99 // Return immediately if corresponding InsertToken failed. 99 // Return immediately if corresponding InsertToken failed.
100 if (token < 0) 100 if (token < 0)
101 return; 101 return;
102 if (token > token_) return; // we wrapped 102 if (token > token_) return; // we wrapped
103 while (last_token_read_ < token) { 103 while (last_token_read_ < token) {
104 if (get_ == put_) { 104 if (get_ == put_) {
105 GPU_LOG(FATAL) << "Empty command buffer while waiting on a token."; 105 GPU_LOG(FATAL) << "Empty command buffer while waiting on a token.";
106 return; 106 return;
107 } 107 }
108 // Do not loop forever if the flush fails, meaning the command buffer reader 108 // Do not loop forever if the flush fails, meaning the command buffer reader
(...skipping 15 matching lines...) Expand all
124 // space may not be available. 124 // space may not be available.
125 void CommandBufferHelper::WaitForAvailableEntries(int32 count) { 125 void CommandBufferHelper::WaitForAvailableEntries(int32 count) {
126 GPU_CHECK(count < usable_entry_count_); 126 GPU_CHECK(count < usable_entry_count_);
127 if (put_ + count > usable_entry_count_) { 127 if (put_ + count > usable_entry_count_) {
128 // There's not enough room between the current put and the end of the 128 // There's not enough room between the current put and the end of the
129 // buffer, so we need to wrap. We will add a jump back to the start, but we 129 // buffer, so we need to wrap. We will add a jump back to the start, but we
130 // need to make sure get wraps first, actually that get is 1 or more (since 130 // need to make sure get wraps first, actually that get is 1 or more (since
131 // put will wrap to 0 after we add the jump). 131 // put will wrap to 0 after we add the jump).
132 GPU_DCHECK_LE(1, put_); 132 GPU_DCHECK_LE(1, put_);
133 if (get_ > put_ || get_ == 0) { 133 if (get_ > put_ || get_ == 0) {
134 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries"); 134 TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries");
135 while (get_ > put_ || get_ == 0) { 135 while (get_ > put_ || get_ == 0) {
136 // Do not loop forever if the flush fails, meaning the command buffer 136 // Do not loop forever if the flush fails, meaning the command buffer
137 // reader has shutdown. 137 // reader has shutdown.
138 if (!FlushSync()) 138 if (!FlushSync())
139 return; 139 return;
140 } 140 }
141 } 141 }
142 // Insert a jump back to the beginning. 142 // Insert a jump back to the beginning.
143 cmd::Jump::Set(&entries_[put_], 0); 143 cmd::Jump::Set(&entries_[put_], 0);
144 put_ = 0; 144 put_ = 0;
145 } 145 }
146 if (AvailableEntries() < count) { 146 if (AvailableEntries() < count) {
147 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries1"); 147 TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries1");
148 while (AvailableEntries() < count) { 148 while (AvailableEntries() < count) {
149 // Do not loop forever if the flush fails, meaning the command buffer 149 // Do not loop forever if the flush fails, meaning the command buffer
150 // reader has shutdown. 150 // reader has shutdown.
151 if (!FlushSync()) 151 if (!FlushSync())
152 return; 152 return;
153 } 153 }
154 } 154 }
155 // Force a flush if the buffer is getting half full, or even earlier if the 155 // Force a flush if the buffer is getting half full, or even earlier if the
156 // reader is known to be idle. 156 // reader is known to be idle.
157 int32 pending = 157 int32 pending =
(...skipping 21 matching lines...) Expand all
179 SynchronizeState(state); 179 SynchronizeState(state);
180 return static_cast<error::Error>(state.error); 180 return static_cast<error::Error>(state.error);
181 } 181 }
182 182
183 void CommandBufferHelper::SynchronizeState(CommandBuffer::State state) { 183 void CommandBufferHelper::SynchronizeState(CommandBuffer::State state) {
184 get_ = state.get_offset; 184 get_ = state.get_offset;
185 last_token_read_ = state.token; 185 last_token_read_ = state.token;
186 } 186 }
187 187
188 } // namespace gpu 188 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698