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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: [WIP] Review comments follow-up Created 6 years, 11 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 // 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 <string.h> 10 #include <string.h>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Inserts a new token into the command buffer. This token either has a value 77 // Inserts a new token into the command buffer. This token either has a value
78 // different from previously inserted tokens, or ensures that previously 78 // different from previously inserted tokens, or ensures that previously
79 // inserted tokens with that value have already passed through the command 79 // inserted tokens with that value have already passed through the command
80 // stream. 80 // stream.
81 // Returns: 81 // Returns:
82 // the value of the new token or -1 if the command buffer reader has 82 // the value of the new token or -1 if the command buffer reader has
83 // shutdown. 83 // shutdown.
84 int32 InsertToken(); 84 int32 InsertToken();
85 85
86 // Returns true if the token has passed.
87 // Parameters:
88 // the value of the token to check whether it has passed
89 bool HasTokenPassed(int32 token) const {
90 if (token > token_)
91 return true; // we wrapped
92 return last_token_read() >= token;
93 }
94
86 // Waits until the token of a particular value has passed through the command 95 // Waits until the token of a particular value has passed through the command
87 // stream (i.e. commands inserted before that token have been executed). 96 // stream (i.e. commands inserted before that token have been executed).
88 // NOTE: This will call Flush if it needs to block. 97 // NOTE: This will call Flush if it needs to block.
89 // Parameters: 98 // Parameters:
90 // the value of the token to wait for. 99 // the value of the token to wait for.
91 void WaitForToken(int32 token); 100 void WaitForToken(int32 token);
92 101
102 // Returns true if the serial has passed.
103 //
104 // NOTE: This will detect wrapped serials by checking if the most significant
105 // bit of serial to check is 1 but the last read is 0, i.e. the uint32
106 // wrapped.
107 //
108 // Parameters:
109 // the value of the serial to check whether it has passed
110 bool HasSerialPassed(uint32 serial) const {
111 uint32 last_serial = last_serial_read();
112 if (serial <= last_serial)
113 return true;
114 if (serial & 0x80000000 && !(last_serial & 0x80000000))
115 return true; // we wrapped
116 return false;
117 }
118
93 // Called prior to each command being issued. Waits for a certain amount of 119 // Called prior to each command being issued. Waits for a certain amount of
94 // space to be available. Returns address of space. 120 // space to be available. Returns address of space.
95 CommandBufferEntry* GetSpace(uint32 entries); 121 CommandBufferEntry* GetSpace(uint32 entries);
96 122
97 // Typed version of GetSpace. Gets enough room for the given type and returns 123 // Typed version of GetSpace. Gets enough room for the given type and returns
98 // a reference to it. 124 // a reference to it.
99 template <typename T> 125 template <typename T>
100 T* GetCmdSpace() { 126 T* GetCmdSpace() {
101 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); 127 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed);
102 uint32 space_needed = ComputeNumEntries(sizeof(T)); 128 uint32 space_needed = ComputeNumEntries(sizeof(T));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void WaitForGetChange(); 263 void WaitForGetChange();
238 264
239 // Returns the number of available entries (they may not be contiguous). 265 // Returns the number of available entries (they may not be contiguous).
240 int32 AvailableEntries() { 266 int32 AvailableEntries() {
241 return (get_offset() - put_ - 1 + total_entry_count_) % total_entry_count_; 267 return (get_offset() - put_ - 1 + total_entry_count_) % total_entry_count_;
242 } 268 }
243 269
244 bool AllocateRingBuffer(); 270 bool AllocateRingBuffer();
245 void FreeResources(); 271 void FreeResources();
246 272
273 // Get the serial number last read by the command buffer.
274 uint32 last_serial_read() const {
275 return command_buffer_->GetLastState().serial;
276 }
277
247 CommandBuffer* command_buffer_; 278 CommandBuffer* command_buffer_;
248 int32 ring_buffer_id_; 279 int32 ring_buffer_id_;
249 int32 ring_buffer_size_; 280 int32 ring_buffer_size_;
250 Buffer ring_buffer_; 281 Buffer ring_buffer_;
251 CommandBufferEntry* entries_; 282 CommandBufferEntry* entries_;
252 int32 total_entry_count_; // the total number of entries 283 int32 total_entry_count_; // the total number of entries
253 int32 token_; 284 int32 token_;
254 int32 put_; 285 int32 put_;
255 int32 last_put_sent_; 286 int32 last_put_sent_;
256 int commands_issued_; 287 int commands_issued_;
257 bool usable_; 288 bool usable_;
258 bool context_lost_; 289 bool context_lost_;
259 bool flush_automatically_; 290 bool flush_automatically_;
260 291
261 // Using C runtime instead of base because this file cannot depend on base. 292 // Using C runtime instead of base because this file cannot depend on base.
262 clock_t last_flush_time_; 293 clock_t last_flush_time_;
263 294
264 friend class CommandBufferHelperTest; 295 friend class CommandBufferHelperTest;
265 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); 296 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);
266 }; 297 };
267 298
268 } // namespace gpu 299 } // namespace gpu
269 300
270 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 301 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698