OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 common parts of command buffer formats. | 5 // This file contains the common parts of command buffer formats. |
6 | 6 |
7 #ifndef GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ | 7 #ifndef GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ |
8 #define GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ | 8 #define GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Rounds up to a multiple of entries in bytes. | 31 // Rounds up to a multiple of entries in bytes. |
32 inline size_t RoundSizeToMultipleOfEntries(size_t size_in_bytes) { | 32 inline size_t RoundSizeToMultipleOfEntries(size_t size_in_bytes) { |
33 return ComputeNumEntries(size_in_bytes) * sizeof(uint32); // NOLINT | 33 return ComputeNumEntries(size_in_bytes) * sizeof(uint32); // NOLINT |
34 } | 34 } |
35 | 35 |
36 // Struct that defines the command header in the command buffer. | 36 // Struct that defines the command header in the command buffer. |
37 struct CommandHeader { | 37 struct CommandHeader { |
38 Uint32 size:21; | 38 Uint32 size:21; |
39 Uint32 command:11; | 39 Uint32 command:11; |
40 | 40 |
41 void Init(uint32 _command, uint32 _size) { | 41 static const int32 kMaxSize = (1 << 21) - 1; |
42 DCHECK_LE(_size, 1u << 22); | 42 |
| 43 void Init(uint32 _command, int32 _size) { |
| 44 DCHECK_LE(_size, kMaxSize); |
43 command = _command; | 45 command = _command; |
44 size = _size; | 46 size = _size; |
45 } | 47 } |
46 | 48 |
47 // Sets the header based on the passed in command. Can not be used for | 49 // Sets the header based on the passed in command. Can not be used for |
48 // variable sized commands like immediate commands or Noop. | 50 // variable sized commands like immediate commands or Noop. |
49 template <typename T> | 51 template <typename T> |
50 void SetCmd() { | 52 void SetCmd() { |
51 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); | 53 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); |
52 Init(T::kCmdId, ComputeNumEntries(sizeof(T))); // NOLINT | 54 Init(T::kCmdId, ComputeNumEntries(sizeof(T))); // NOLINT |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 175 |
174 const char* GetCommandName(CommandId id); | 176 const char* GetCommandName(CommandId id); |
175 | 177 |
176 // A Noop command. | 178 // A Noop command. |
177 struct Noop { | 179 struct Noop { |
178 typedef Noop ValueType; | 180 typedef Noop ValueType; |
179 static const CommandId kCmdId = kNoop; | 181 static const CommandId kCmdId = kNoop; |
180 static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; | 182 static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; |
181 | 183 |
182 void SetHeader(uint32 skip_count) { | 184 void SetHeader(uint32 skip_count) { |
183 header.Init(kCmdId, skip_count + 1); | 185 DCHECK_GT(skip_count, 0u); |
| 186 header.Init(kCmdId, skip_count); |
184 } | 187 } |
185 | 188 |
186 void Init(uint32 skip_count) { | 189 void Init(uint32 skip_count) { |
187 SetHeader(skip_count); | 190 SetHeader(skip_count); |
188 } | 191 } |
189 | 192 |
190 static void* Set(void* cmd, uint32 skip_count) { | 193 static void* Set(void* cmd, uint32 skip_count) { |
191 static_cast<ValueType*>(cmd)->Init(skip_count); | 194 static_cast<ValueType*>(cmd)->Init(skip_count); |
192 return NextImmediateCmdAddress<ValueType>( | 195 return NextImmediateCmdAddress<ValueType>( |
193 cmd, skip_count * sizeof(CommandBufferEntry)); // NOLINT | 196 cmd, skip_count * sizeof(CommandBufferEntry)); // NOLINT |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // The Jump command jumps to another place in the command buffer. | 235 // The Jump command jumps to another place in the command buffer. |
233 struct Jump { | 236 struct Jump { |
234 typedef Jump ValueType; | 237 typedef Jump ValueType; |
235 static const CommandId kCmdId = kJump; | 238 static const CommandId kCmdId = kJump; |
236 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 239 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
237 | 240 |
238 void SetHeader() { | 241 void SetHeader() { |
239 header.SetCmd<ValueType>(); | 242 header.SetCmd<ValueType>(); |
240 } | 243 } |
241 | 244 |
242 void Init(uint32 _shared_memory_id, uint32 _shared_memory_offset) { | 245 void Init(uint32 _offset) { |
243 SetHeader(); | 246 SetHeader(); |
244 shared_memory_id = _shared_memory_id; | 247 offset = _offset; |
245 shared_memory_offset = _shared_memory_offset; | |
246 } | 248 } |
247 static void* Set( | 249 static void* Set( |
248 void* cmd, uint32 _shared_memory_id, uint32 _shared_memory_offset) { | 250 void* cmd, uint32 _offset) { |
249 static_cast<ValueType*>(cmd)->Init( | 251 static_cast<ValueType*>(cmd)->Init(_offset); |
250 _shared_memory_id, _shared_memory_offset); | |
251 return NextCmdAddress<ValueType>(cmd); | 252 return NextCmdAddress<ValueType>(cmd); |
252 } | 253 } |
253 | 254 |
254 CommandHeader header; | 255 CommandHeader header; |
255 uint32 shared_memory_id; | 256 uint32 offset; |
256 uint32 shared_memory_offset; | |
257 }; | 257 }; |
258 | 258 |
259 COMPILE_ASSERT(sizeof(Jump) == 12, Sizeof_Jump_is_not_12); | 259 COMPILE_ASSERT(sizeof(Jump) == 8, Sizeof_Jump_is_not_8); |
260 COMPILE_ASSERT(offsetof(Jump, header) == 0, | 260 COMPILE_ASSERT(offsetof(Jump, header) == 0, |
261 Offsetof_Jump_header_not_0); | 261 Offsetof_Jump_header_not_0); |
262 COMPILE_ASSERT(offsetof(Jump, shared_memory_id) == 4, | 262 COMPILE_ASSERT(offsetof(Jump, offset) == 4, |
263 Offsetof_Jump_shared_memory_id_not_4); | 263 Offsetof_Jump_offset_not_4); |
264 COMPILE_ASSERT(offsetof(Jump, shared_memory_offset) == 8, | |
265 Offsetof_Jump_shared_memory_offset_not_8); | |
266 | 264 |
267 // The JumpRelative command jumps to another place in the command buffer | 265 // The JumpRelative command jumps to another place in the command buffer |
268 // relative to the end of this command. In other words. JumpRelative with an | 266 // relative to the end of this command. In other words. JumpRelative with an |
269 // offset of zero is effectively a noop. | 267 // offset of zero is effectively a noop. |
270 struct JumpRelative { | 268 struct JumpRelative { |
271 typedef JumpRelative ValueType; | 269 typedef JumpRelative ValueType; |
272 static const CommandId kCmdId = kJumpRelative; | 270 static const CommandId kCmdId = kJumpRelative; |
273 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 271 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
274 | 272 |
275 void SetHeader() { | 273 void SetHeader() { |
(...skipping 23 matching lines...) Expand all Loading... |
299 // Return command. | 297 // Return command. |
300 struct Call { | 298 struct Call { |
301 typedef Call ValueType; | 299 typedef Call ValueType; |
302 static const CommandId kCmdId = kCall; | 300 static const CommandId kCmdId = kCall; |
303 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 301 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
304 | 302 |
305 void SetHeader() { | 303 void SetHeader() { |
306 header.SetCmd<ValueType>(); | 304 header.SetCmd<ValueType>(); |
307 } | 305 } |
308 | 306 |
309 void Init(uint32 _shared_memory_id, uint32 _shared_memory_offset) { | 307 void Init(uint32 _offset) { |
310 SetHeader(); | 308 SetHeader(); |
311 shared_memory_id = _shared_memory_id; | 309 offset = _offset; |
312 shared_memory_offset = _shared_memory_offset; | |
313 } | 310 } |
314 static void* Set( | 311 static void* Set(void* cmd, uint32 _offset) { |
315 void* cmd, uint32 _shared_memory_id, uint32 _shared_memory_offset) { | 312 static_cast<ValueType*>(cmd)->Init(_offset); |
316 static_cast<ValueType*>(cmd)->Init( | |
317 _shared_memory_id, _shared_memory_offset); | |
318 return NextCmdAddress<ValueType>(cmd); | 313 return NextCmdAddress<ValueType>(cmd); |
319 } | 314 } |
320 | 315 |
321 CommandHeader header; | 316 CommandHeader header; |
322 uint32 shared_memory_id; | 317 uint32 offset; |
323 uint32 shared_memory_offset; | |
324 }; | 318 }; |
325 | 319 |
326 COMPILE_ASSERT(sizeof(Call) == 12, Sizeof_Call_is_not_12); | 320 COMPILE_ASSERT(sizeof(Call) == 8, Sizeof_Call_is_not_8); |
327 COMPILE_ASSERT(offsetof(Call, header) == 0, | 321 COMPILE_ASSERT(offsetof(Call, header) == 0, |
328 Offsetof_Call_header_not_0); | 322 Offsetof_Call_header_not_0); |
329 COMPILE_ASSERT(offsetof(Call, shared_memory_id) == 4, | 323 COMPILE_ASSERT(offsetof(Call, offset) == 4, |
330 Offsetof_Call_shared_memory_id_not_4); | 324 Offsetof_Call_offset_not_4); |
331 COMPILE_ASSERT(offsetof(Call, shared_memory_offset) == 8, | |
332 Offsetof_Call_shared_memory_offset_not_8); | |
333 | 325 |
334 // The CallRelative command jumps to a subroutine using a relative offset. The | 326 // The CallRelative command jumps to a subroutine using a relative offset. The |
335 // offset is relative to the end of this command.. | 327 // offset is relative to the end of this command.. |
336 struct CallRelative { | 328 struct CallRelative { |
337 typedef CallRelative ValueType; | 329 typedef CallRelative ValueType; |
338 static const CommandId kCmdId = kCallRelative; | 330 static const CommandId kCmdId = kCallRelative; |
339 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 331 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
340 | 332 |
341 void SetHeader() { | 333 void SetHeader() { |
342 header.SetCmd<ValueType>(); | 334 header.SetCmd<ValueType>(); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 Offsetof_GetBucketData_shared_memory_offset_not_20); | 641 Offsetof_GetBucketData_shared_memory_offset_not_20); |
650 | 642 |
651 } // namespace cmd | 643 } // namespace cmd |
652 | 644 |
653 #pragma pack(pop) | 645 #pragma pack(pop) |
654 | 646 |
655 } // namespace gpu | 647 } // namespace gpu |
656 | 648 |
657 #endif // GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ | 649 #endif // GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ |
658 | 650 |
OLD | NEW |