OLD | NEW |
---|---|
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 Loading... | |
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 // Inserts a new async token to the command buffer. One can then check if the | |
103 // token has passed using HasAsyncTokenPassed(). It is guaranteed that the | |
104 // order of returned async tokens is the same as inserted, but it is | |
105 // implementation specific when a token is returned. | |
106 // | |
107 // NOTE: A async token is asynchronous in a way that Finish():ing the command | |
108 // buffer does mean it has passed. | |
epenner
2014/01/23 02:52:44
Nit: 'doesn't'
| |
109 uint32 InsertAsyncToken(); | |
110 | |
111 // Returns true if the async token has passed. | |
112 // | |
113 // NOTE: This will detect wrapped async tokens by checking if the most | |
114 // significant bit of async token to check is 1 but the last read is 0, i.e. | |
115 // the uint32 wrapped. | |
116 // | |
117 // Parameters: | |
118 // the value of the async token to check whether it has passed | |
119 bool HasAsyncTokenPassed(uint32 token) const { | |
120 uint32 last_async_token = last_async_token_read(); | |
121 if (token <= last_async_token) | |
122 return true; | |
123 if (token & 0x80000000 && !(last_async_token & 0x80000000)) | |
124 return true; // we wrapped | |
125 return false; | |
126 } | |
127 | |
93 // Called prior to each command being issued. Waits for a certain amount of | 128 // Called prior to each command being issued. Waits for a certain amount of |
94 // space to be available. Returns address of space. | 129 // space to be available. Returns address of space. |
95 CommandBufferEntry* GetSpace(uint32 entries); | 130 CommandBufferEntry* GetSpace(uint32 entries); |
96 | 131 |
97 // Typed version of GetSpace. Gets enough room for the given type and returns | 132 // Typed version of GetSpace. Gets enough room for the given type and returns |
98 // a reference to it. | 133 // a reference to it. |
99 template <typename T> | 134 template <typename T> |
100 T* GetCmdSpace() { | 135 T* GetCmdSpace() { |
101 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); | 136 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); |
102 uint32 space_needed = ComputeNumEntries(sizeof(T)); | 137 uint32 space_needed = ComputeNumEntries(sizeof(T)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 void WaitForGetChange(); | 272 void WaitForGetChange(); |
238 | 273 |
239 // Returns the number of available entries (they may not be contiguous). | 274 // Returns the number of available entries (they may not be contiguous). |
240 int32 AvailableEntries() { | 275 int32 AvailableEntries() { |
241 return (get_offset() - put_ - 1 + total_entry_count_) % total_entry_count_; | 276 return (get_offset() - put_ - 1 + total_entry_count_) % total_entry_count_; |
242 } | 277 } |
243 | 278 |
244 bool AllocateRingBuffer(); | 279 bool AllocateRingBuffer(); |
245 void FreeResources(); | 280 void FreeResources(); |
246 | 281 |
282 // Get the async token number last read by the command buffer. | |
283 uint32 last_async_token_read() const { | |
284 return command_buffer_->GetLastState().async_token; | |
285 } | |
286 | |
247 CommandBuffer* command_buffer_; | 287 CommandBuffer* command_buffer_; |
248 int32 ring_buffer_id_; | 288 int32 ring_buffer_id_; |
249 int32 ring_buffer_size_; | 289 int32 ring_buffer_size_; |
250 Buffer ring_buffer_; | 290 Buffer ring_buffer_; |
251 CommandBufferEntry* entries_; | 291 CommandBufferEntry* entries_; |
252 int32 total_entry_count_; // the total number of entries | 292 int32 total_entry_count_; // the total number of entries |
253 int32 token_; | 293 int32 token_; |
294 uint32 async_token_; | |
254 int32 put_; | 295 int32 put_; |
255 int32 last_put_sent_; | 296 int32 last_put_sent_; |
256 int commands_issued_; | 297 int commands_issued_; |
257 bool usable_; | 298 bool usable_; |
258 bool context_lost_; | 299 bool context_lost_; |
259 bool flush_automatically_; | 300 bool flush_automatically_; |
260 | 301 |
261 // Using C runtime instead of base because this file cannot depend on base. | 302 // Using C runtime instead of base because this file cannot depend on base. |
262 clock_t last_flush_time_; | 303 clock_t last_flush_time_; |
263 | 304 |
264 friend class CommandBufferHelperTest; | 305 friend class CommandBufferHelperTest; |
265 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); | 306 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); |
266 }; | 307 }; |
267 | 308 |
268 } // namespace gpu | 309 } // namespace gpu |
269 | 310 |
270 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ | 311 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
OLD | NEW |