OLD | NEW |
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 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 // shutdown. | 76 // shutdown. |
77 int32 InsertToken(); | 77 int32 InsertToken(); |
78 | 78 |
79 // Waits until the token of a particular value has passed through the command | 79 // Waits until the token of a particular value has passed through the command |
80 // stream (i.e. commands inserted before that token have been executed). | 80 // stream (i.e. commands inserted before that token have been executed). |
81 // NOTE: This will call Flush if it needs to block. | 81 // NOTE: This will call Flush if it needs to block. |
82 // Parameters: | 82 // Parameters: |
83 // the value of the token to wait for. | 83 // the value of the token to wait for. |
84 void WaitForToken(int32 token); | 84 void WaitForToken(int32 token); |
85 | 85 |
86 // Inserts a yield command, signaling the scheduler that this is a good point | |
87 // to update the state and schedule other command buffers. This is | |
88 // particularly useful after inserting a token that will be waited on. | |
89 void YieldScheduler(); | |
90 | |
91 // Called prior to each command being issued. Waits for a certain amount of | 86 // Called prior to each command being issued. Waits for a certain amount of |
92 // space to be available. Returns address of space. | 87 // space to be available. Returns address of space. |
93 CommandBufferEntry* GetSpace(uint32 entries); | 88 CommandBufferEntry* GetSpace(uint32 entries); |
94 | 89 |
95 // Typed version of GetSpace. Gets enough room for the given type and returns | 90 // Typed version of GetSpace. Gets enough room for the given type and returns |
96 // a reference to it. | 91 // a reference to it. |
97 template <typename T> | 92 template <typename T> |
98 T& GetCmdSpace() { | 93 T& GetCmdSpace() { |
99 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); | 94 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); |
100 uint32 space_needed = ComputeNumEntries(sizeof(T)); | 95 uint32 space_needed = ComputeNumEntries(sizeof(T)); |
(...skipping 13 matching lines...) Expand all Loading... |
114 // Typed version of GetSpace for immediate commands. | 109 // Typed version of GetSpace for immediate commands. |
115 template <typename T> | 110 template <typename T> |
116 T& GetImmediateCmdSpaceTotalSize(size_t total_space) { | 111 T& GetImmediateCmdSpaceTotalSize(size_t total_space) { |
117 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); | 112 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); |
118 uint32 space_needed = ComputeNumEntries(total_space); | 113 uint32 space_needed = ComputeNumEntries(total_space); |
119 void* data = GetSpace(space_needed); | 114 void* data = GetSpace(space_needed); |
120 return *reinterpret_cast<T*>(data); | 115 return *reinterpret_cast<T*>(data); |
121 } | 116 } |
122 | 117 |
123 int32 last_token_read() const { | 118 int32 last_token_read() const { |
124 return last_token_read_; | 119 return command_buffer_->GetLastState().token; |
| 120 } |
| 121 |
| 122 int32 get_offset() const { |
| 123 return command_buffer_->GetLastState().get_offset; |
125 } | 124 } |
126 | 125 |
127 error::Error GetError(); | 126 error::Error GetError(); |
128 | 127 |
129 // Common Commands | 128 // Common Commands |
130 void Noop(uint32 skip_count) { | 129 void Noop(uint32 skip_count) { |
131 cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( | 130 cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( |
132 skip_count * sizeof(CommandBufferEntry)); | 131 skip_count * sizeof(CommandBufferEntry)); |
133 cmd.Init(skip_count); | 132 cmd.Init(skip_count); |
134 } | 133 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 CommandBuffer* command_buffer() const { | 213 CommandBuffer* command_buffer() const { |
215 return command_buffer_; | 214 return command_buffer_; |
216 } | 215 } |
217 | 216 |
218 private: | 217 private: |
219 // Waits until get changes, updating the value of get_. | 218 // Waits until get changes, updating the value of get_. |
220 void WaitForGetChange(); | 219 void WaitForGetChange(); |
221 | 220 |
222 // Returns the number of available entries (they may not be contiguous). | 221 // Returns the number of available entries (they may not be contiguous). |
223 int32 AvailableEntries() { | 222 int32 AvailableEntries() { |
224 return (get_ - put_ - 1 + usable_entry_count_) % usable_entry_count_; | 223 return (get_offset() - put_ - 1 + usable_entry_count_) % |
| 224 usable_entry_count_; |
225 } | 225 } |
226 | 226 |
227 // Synchronize with current service state. | |
228 void SynchronizeState(const CommandBuffer::State& state); | |
229 | |
230 CommandBuffer* command_buffer_; | 227 CommandBuffer* command_buffer_; |
231 Buffer ring_buffer_; | 228 Buffer ring_buffer_; |
232 CommandBufferEntry *entries_; | 229 CommandBufferEntry *entries_; |
233 int32 total_entry_count_; // the total number of entries | 230 int32 total_entry_count_; // the total number of entries |
234 int32 usable_entry_count_; // the usable number (ie, minus space for jump) | 231 int32 usable_entry_count_; // the usable number (ie, minus space for jump) |
235 int32 token_; | 232 int32 token_; |
236 int32 last_token_read_; | |
237 int32 get_; | |
238 int32 put_; | 233 int32 put_; |
239 int32 last_put_sent_; | 234 int32 last_put_sent_; |
240 int commands_issued_; | 235 int commands_issued_; |
241 | 236 |
242 // Using C runtime instead of base because this file cannot depend on base. | 237 // Using C runtime instead of base because this file cannot depend on base. |
243 time_t last_flush_time_; | 238 time_t last_flush_time_; |
244 | 239 |
245 friend class CommandBufferHelperTest; | 240 friend class CommandBufferHelperTest; |
246 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); | 241 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); |
247 }; | 242 }; |
248 | 243 |
249 } // namespace gpu | 244 } // namespace gpu |
250 | 245 |
251 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ | 246 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
OLD | NEW |