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

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

Issue 2550583002: gpu: Thread-safe command buffer state lookup. (Closed)
Patch Set: 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 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 // This file contains the command buffer helper class. 5 // This file contains the command buffer helper class.
6 6
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 T* GetImmediateCmdSpaceTotalSize(size_t total_space) { 174 T* GetImmediateCmdSpaceTotalSize(size_t total_space) {
175 static_assert(T::kArgFlags == cmd::kAtLeastN, 175 static_assert(T::kArgFlags == cmd::kAtLeastN,
176 "T::kArgFlags should equal cmd::kAtLeastN"); 176 "T::kArgFlags should equal cmd::kAtLeastN");
177 int32_t space_needed = ComputeNumEntries(total_space); 177 int32_t space_needed = ComputeNumEntries(total_space);
178 T* data = static_cast<T*>(GetSpace(space_needed)); 178 T* data = static_cast<T*>(GetSpace(space_needed));
179 return data; 179 return data;
180 } 180 }
181 181
182 int32_t last_token_read() const { return command_buffer_->GetLastToken(); } 182 int32_t last_token_read() const { return command_buffer_->GetLastToken(); }
183 183
184 int32_t get_offset() const {
185 return command_buffer_->GetLastState().get_offset;
186 }
187
188 // Common Commands 184 // Common Commands
189 void Noop(uint32_t skip_count) { 185 void Noop(uint32_t skip_count) {
190 cmd::Noop* cmd = GetImmediateCmdSpace<cmd::Noop>( 186 cmd::Noop* cmd = GetImmediateCmdSpace<cmd::Noop>(
191 (skip_count - 1) * sizeof(CommandBufferEntry)); 187 (skip_count - 1) * sizeof(CommandBufferEntry));
192 if (cmd) { 188 if (cmd) {
193 cmd->Init(skip_count); 189 cmd->Init(skip_count);
194 } 190 }
195 } 191 }
196 192
197 void SetToken(uint32_t token) { 193 void SetToken(uint32_t token) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 CalcImmediateEntries(0); 287 CalcImmediateEntries(0);
292 } 288 }
293 289
294 // Overridden from base::trace_event::MemoryDumpProvider: 290 // Overridden from base::trace_event::MemoryDumpProvider:
295 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 291 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
296 base::trace_event::ProcessMemoryDump* pmd) override; 292 base::trace_event::ProcessMemoryDump* pmd) override;
297 293
298 private: 294 private:
299 // Returns the number of available entries (they may not be contiguous). 295 // Returns the number of available entries (they may not be contiguous).
300 int32_t AvailableEntries() { 296 int32_t AvailableEntries() {
301 return (get_offset() - put_ - 1 + total_entry_count_) % total_entry_count_; 297 return (last_get_ - put_ - 1 + total_entry_count_) % total_entry_count_;
302 } 298 }
303 299
304 void CalcImmediateEntries(int waiting_count); 300 void CalcImmediateEntries(int waiting_count);
305 bool AllocateRingBuffer(); 301 bool AllocateRingBuffer();
306 void FreeResources(); 302 void FreeResources();
307 303
308 // Waits for the get offset to be in a specific range, inclusive. Returns 304 // Waits for the get offset to be in a specific range, inclusive. Returns
309 // false if there was an error. 305 // false if there was an error.
310 bool WaitForGetOffsetInRange(int32_t start, int32_t end); 306 bool WaitForGetOffsetInRange(int32_t start, int32_t end);
311 307
312 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) 308 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK)
313 // Calls Flush if automatic flush conditions are met. 309 // Calls Flush if automatic flush conditions are met.
314 void PeriodicFlushCheck(); 310 void PeriodicFlushCheck();
315 #endif 311 #endif
316 312
317 int32_t GetTotalFreeEntriesNoWaiting() const; 313 int32_t GetTotalFreeEntriesNoWaiting() const;
318 314
319 CommandBuffer* command_buffer_; 315 CommandBuffer* command_buffer_;
320 int32_t ring_buffer_id_; 316 int32_t ring_buffer_id_;
321 int32_t ring_buffer_size_; 317 int32_t ring_buffer_size_;
322 scoped_refptr<gpu::Buffer> ring_buffer_; 318 scoped_refptr<gpu::Buffer> ring_buffer_;
323 CommandBufferEntry* entries_; 319 CommandBufferEntry* entries_;
324 int32_t total_entry_count_; // the total number of entries 320 int32_t total_entry_count_; // the total number of entries
325 int32_t immediate_entry_count_; 321 int32_t immediate_entry_count_;
326 int32_t token_; 322 int32_t token_;
327 int32_t put_; 323 int32_t put_;
324 int32_t last_get_;
sunnyps 2016/12/02 02:52:03 bikeshed: cached_get_offset_?
piman 2016/12/02 19:21:48 I like cached_get_offset_
sunnyps 2016/12/07 03:31:22 Done.
328 int32_t last_put_sent_; 325 int32_t last_put_sent_;
329 int32_t last_barrier_put_sent_; 326 int32_t last_barrier_put_sent_;
330 327
331 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) 328 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK)
332 int commands_issued_; 329 int commands_issued_;
333 #endif 330 #endif
334 331
335 bool usable_; 332 bool usable_;
336 bool context_lost_; 333 bool context_lost_;
337 bool flush_automatically_; 334 bool flush_automatically_;
338 335
339 base::TimeTicks last_flush_time_; 336 base::TimeTicks last_flush_time_;
340 337
341 // Incremented every time the helper flushes the command buffer. 338 // Incremented every time the helper flushes the command buffer.
342 // Can be used to track when prior commands have been flushed. 339 // Can be used to track when prior commands have been flushed.
343 uint32_t flush_generation_; 340 uint32_t flush_generation_;
344 341
345 friend class CommandBufferHelperTest; 342 friend class CommandBufferHelperTest;
346 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); 343 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);
347 }; 344 };
348 345
349 } // namespace gpu 346 } // namespace gpu
350 347
351 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 348 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698