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
3 // found in the LICENSE file.
5 // This file defines the GLES2 command buffer commands.
7 #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_
8 #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_
11 #include <KHR/khrplatform.h>
16 #include "base/atomicops.h"
17 #include "base/logging.h"
18 #include "base/macros.h"
19 #include "gpu/command_buffer/common/bitfield_helpers.h"
20 #include "gpu/command_buffer/common/cmd_buffer_common.h"
21 #include "gpu/command_buffer/common/gles2_cmd_ids.h"
23 // GL types are forward declared to avoid including the GL headers. The problem
24 // is determining which GL headers to include from code that is common to the
25 // client and service sides (GLES2 or one of several GL implementations).
26 typedef unsigned int GLenum
;
27 typedef unsigned int GLbitfield
;
28 typedef unsigned int GLuint
;
31 typedef unsigned char GLboolean
;
32 typedef signed char GLbyte
;
33 typedef short GLshort
;
34 typedef unsigned char GLubyte
;
35 typedef unsigned short GLushort
;
36 typedef unsigned long GLulong
;
37 typedef float GLfloat
;
38 typedef float GLclampf
;
39 typedef double GLdouble
;
40 typedef double GLclampd
;
42 typedef khronos_intptr_t GLintptr
;
43 typedef khronos_ssize_t GLsizeiptr
;
48 // Command buffer is GPU_COMMAND_BUFFER_ENTRY_ALIGNMENT byte aligned.
49 #pragma pack(push, GPU_COMMAND_BUFFER_ENTRY_ALIGNMENT)
51 namespace id_namespaces
{
53 // These are used when contexts share resources.
65 // These numbers must not change
66 COMPILE_ASSERT(kBuffers
== 0, kBuffers_is_not_0
);
67 COMPILE_ASSERT(kFramebuffers
== 1, kFramebuffers_is_not_1
);
68 COMPILE_ASSERT(kProgramsAndShaders
== 2, kProgramsAndShaders_is_not_2
);
69 COMPILE_ASSERT(kRenderbuffers
== 3, kRenderbuffers_is_not_3
);
70 COMPILE_ASSERT(kTextures
== 4, kTextures_is_not_4
);
72 } // namespace id_namespaces
74 // Used for some glGetXXX commands that return a result through a pointer. We
75 // need to know if the command succeeded or not and the size of the result. If
76 // the command failed its result size will 0.
82 return static_cast<T
*>(static_cast<void*>(&data
));
85 // Returns the total size in bytes of the SizedResult for a given number of
86 // results including the size field.
87 static size_t ComputeSize(size_t num_results
) {
88 return sizeof(T
) * num_results
+ sizeof(uint32_t); // NOLINT
91 // Returns the total size in bytes of the SizedResult for a given size of
93 static size_t ComputeSizeFromBytes(size_t size_of_result_in_bytes
) {
94 return size_of_result_in_bytes
+ sizeof(uint32_t); // NOLINT
97 // Returns the maximum number of results for a given buffer size.
98 static uint32_t ComputeMaxResults(size_t size_of_buffer
) {
99 return (size_of_buffer
>= sizeof(uint32_t)) ?
100 ((size_of_buffer
- sizeof(uint32_t)) / sizeof(T
)) : 0; // NOLINT
103 // Set the size for a given number of results.
104 void SetNumResults(size_t num_results
) {
105 size
= sizeof(T
) * num_results
; // NOLINT
108 // Get the number of elements in the result
109 int32_t GetNumResults() const {
110 return size
/ sizeof(T
); // NOLINT
114 void CopyResult(void* dst
) const {
115 memcpy(dst
, &data
, size
);
118 uint32_t size
; // in bytes.
119 int32_t data
; // this is just here to get an offset.
122 COMPILE_ASSERT(sizeof(SizedResult
<int8_t>) == 8, SizedResult_size_not_8
);
123 COMPILE_ASSERT(offsetof(SizedResult
<int8_t>, size
) == 0,
124 OffsetOf_SizedResult_size_not_0
);
125 COMPILE_ASSERT(offsetof(SizedResult
<int8_t>, data
) == 4,
126 OffsetOf_SizedResult_data_not_4
);
128 // The data for one attrib or uniform from GetProgramInfoCHROMIUM.
129 struct ProgramInput
{
130 uint32_t type
; // The type (GL_VEC3, GL_MAT3, GL_SAMPLER_2D, etc.
131 int32_t size
; // The size (how big the array is for uniforms)
132 uint32_t location_offset
; // offset from ProgramInfoHeader to 'size'
133 // locations for uniforms, 1 for attribs.
134 uint32_t name_offset
; // offset from ProgrmaInfoHeader to start of name.
135 uint32_t name_length
; // length of the name.
138 // The format of the bucket filled out by GetProgramInfoCHROMIUM
139 struct ProgramInfoHeader
{
140 uint32_t link_status
;
141 uint32_t num_attribs
;
142 uint32_t num_uniforms
;
143 // ProgramInput inputs[num_attribs + num_uniforms];
146 // The format of QuerySync used by EXT_occlusion_query_boolean
153 base::subtle::Atomic32 process_count
;
157 struct AsyncUploadSync
{
159 base::subtle::Release_Store(&async_upload_token
, 0);
162 void SetAsyncUploadToken(uint32_t token
) {
163 DCHECK_NE(token
, 0u);
164 base::subtle::Release_Store(&async_upload_token
, token
);
167 bool HasAsyncUploadTokenPassed(uint32_t token
) {
168 DCHECK_NE(token
, 0u);
169 uint32_t current_token
= base::subtle::Acquire_Load(&async_upload_token
);
170 return (current_token
- token
< 0x80000000);
173 base::subtle::Atomic32 async_upload_token
;
176 COMPILE_ASSERT(sizeof(ProgramInput
) == 20, ProgramInput_size_not_20
);
177 COMPILE_ASSERT(offsetof(ProgramInput
, type
) == 0,
178 OffsetOf_ProgramInput_type_not_0
);
179 COMPILE_ASSERT(offsetof(ProgramInput
, size
) == 4,
180 OffsetOf_ProgramInput_size_not_4
);
181 COMPILE_ASSERT(offsetof(ProgramInput
, location_offset
) == 8,
182 OffsetOf_ProgramInput_location_offset_not_8
);
183 COMPILE_ASSERT(offsetof(ProgramInput
, name_offset
) == 12,
184 OffsetOf_ProgramInput_name_offset_not_12
);
185 COMPILE_ASSERT(offsetof(ProgramInput
, name_length
) == 16,
186 OffsetOf_ProgramInput_name_length_not_16
);
188 COMPILE_ASSERT(sizeof(ProgramInfoHeader
) == 12, ProgramInfoHeader_size_not_12
);
189 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, link_status
) == 0,
190 OffsetOf_ProgramInfoHeader_link_status_not_0
);
191 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, num_attribs
) == 4,
192 OffsetOf_ProgramInfoHeader_num_attribs_not_4
);
193 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, num_uniforms
) == 8,
194 OffsetOf_ProgramInfoHeader_num_uniforms_not_8
);
198 #include "../common/gles2_cmd_format_autogen.h"
200 // These are hand written commands.
201 // TODO(gman): Attempt to make these auto-generated.
203 struct GetAttribLocation
{
204 typedef GetAttribLocation ValueType
;
205 static const CommandId kCmdId
= kGetAttribLocation
;
206 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
207 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
209 typedef GLint Result
;
211 static uint32
ComputeSize() {
212 return static_cast<uint32
>(sizeof(ValueType
)); // NOLINT
216 header
.SetCmd
<ValueType
>();
220 GLuint _program
, uint32 _name_shm_id
, uint32 _name_shm_offset
,
221 uint32 _location_shm_id
, uint32 _location_shm_offset
,
225 name_shm_id
= _name_shm_id
;
226 name_shm_offset
= _name_shm_offset
;
227 location_shm_id
= _location_shm_id
;
228 location_shm_offset
= _location_shm_offset
;
229 data_size
= _data_size
;
233 void* cmd
, GLuint _program
, uint32 _name_shm_id
, uint32 _name_shm_offset
,
234 uint32 _location_shm_id
, uint32 _location_shm_offset
,
236 static_cast<ValueType
*>(
238 _program
, _name_shm_id
, _name_shm_offset
, _location_shm_id
,
239 _location_shm_offset
, _data_size
);
240 return NextCmdAddress
<ValueType
>(cmd
);
243 CommandHeader header
;
246 uint32 name_shm_offset
;
247 uint32 location_shm_id
;
248 uint32 location_shm_offset
;
252 COMPILE_ASSERT(sizeof(GetAttribLocation
) == 28,
253 Sizeof_GetAttribLocation_is_not_28
);
254 COMPILE_ASSERT(offsetof(GetAttribLocation
, header
) == 0,
255 OffsetOf_GetAttribLocation_header_not_0
);
256 COMPILE_ASSERT(offsetof(GetAttribLocation
, program
) == 4,
257 OffsetOf_GetAttribLocation_program_not_4
);
258 COMPILE_ASSERT(offsetof(GetAttribLocation
, name_shm_id
) == 8,
259 OffsetOf_GetAttribLocation_name_shm_id_not_8
);
260 COMPILE_ASSERT(offsetof(GetAttribLocation
, name_shm_offset
) == 12,
261 OffsetOf_GetAttribLocation_name_shm_offset_not_12
);
262 COMPILE_ASSERT(offsetof(GetAttribLocation
, location_shm_id
) == 16,
263 OffsetOf_GetAttribLocation_location_shm_id_not_16
);
264 COMPILE_ASSERT(offsetof(GetAttribLocation
, location_shm_offset
) == 20,
265 OffsetOf_GetAttribLocation_location_shm_offset_not_20
);
266 COMPILE_ASSERT(offsetof(GetAttribLocation
, data_size
) == 24,
267 OffsetOf_GetAttribLocation_data_size_not_24
);
270 struct GetAttribLocationBucket
{
271 typedef GetAttribLocationBucket ValueType
;
272 static const CommandId kCmdId
= kGetAttribLocationBucket
;
273 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
274 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
276 typedef GLint Result
;
278 static uint32
ComputeSize() {
279 return static_cast<uint32
>(sizeof(ValueType
)); // NOLINT
283 header
.SetCmd
<ValueType
>();
287 GLuint _program
, uint32 _name_bucket_id
,
288 uint32 _location_shm_id
, uint32 _location_shm_offset
) {
291 name_bucket_id
= _name_bucket_id
;
292 location_shm_id
= _location_shm_id
;
293 location_shm_offset
= _location_shm_offset
;
297 void* cmd
, GLuint _program
, uint32 _name_bucket_id
,
298 uint32 _location_shm_id
, uint32 _location_shm_offset
) {
299 static_cast<ValueType
*>(
301 _program
, _name_bucket_id
, _location_shm_id
,
302 _location_shm_offset
);
303 return NextCmdAddress
<ValueType
>(cmd
);
306 CommandHeader header
;
308 uint32 name_bucket_id
;
309 uint32 location_shm_id
;
310 uint32 location_shm_offset
;
313 COMPILE_ASSERT(sizeof(GetAttribLocationBucket
) == 20,
314 Sizeof_GetAttribLocationBucket_is_not_24
);
315 COMPILE_ASSERT(offsetof(GetAttribLocationBucket
, header
) == 0,
316 OffsetOf_GetAttribLocationBucket_header_not_0
);
317 COMPILE_ASSERT(offsetof(GetAttribLocationBucket
, program
) == 4,
318 OffsetOf_GetAttribLocationBucket_program_not_4
);
319 COMPILE_ASSERT(offsetof(GetAttribLocationBucket
, name_bucket_id
) == 8,
320 OffsetOf_GetAttribLocationBucket_name_bucket_id_not_8
);
321 COMPILE_ASSERT(offsetof(GetAttribLocationBucket
, location_shm_id
) == 12,
322 OffsetOf_GetAttribLocationBucket_location_shm_id_not_12
);
323 COMPILE_ASSERT(offsetof(GetAttribLocationBucket
, location_shm_offset
) == 16,
324 OffsetOf_GetAttribLocationBucket_location_shm_offset_not_16
);
326 struct GetUniformLocation
{
327 typedef GetUniformLocation ValueType
;
328 static const CommandId kCmdId
= kGetUniformLocation
;
329 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
330 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
332 typedef GLint Result
;
334 static uint32
ComputeSize() {
335 return static_cast<uint32
>(sizeof(ValueType
)); // NOLINT
339 header
.SetCmd
<ValueType
>();
343 GLuint _program
, uint32 _name_shm_id
, uint32 _name_shm_offset
,
344 uint32 _location_shm_id
, uint32 _location_shm_offset
,
348 name_shm_id
= _name_shm_id
;
349 name_shm_offset
= _name_shm_offset
;
350 location_shm_id
= _location_shm_id
;
351 location_shm_offset
= _location_shm_offset
;
352 data_size
= _data_size
;
356 void* cmd
, GLuint _program
, uint32 _name_shm_id
, uint32 _name_shm_offset
,
357 uint32 _location_shm_id
, uint32 _location_shm_offset
,
359 static_cast<ValueType
*>(
361 _program
, _name_shm_id
, _name_shm_offset
, _location_shm_id
,
362 _location_shm_offset
, _data_size
);
363 return NextCmdAddress
<ValueType
>(cmd
);
366 CommandHeader header
;
369 uint32 name_shm_offset
;
370 uint32 location_shm_id
;
371 uint32 location_shm_offset
;
375 COMPILE_ASSERT(sizeof(GetUniformLocation
) == 28,
376 Sizeof_GetUniformLocation_is_not_28
);
377 COMPILE_ASSERT(offsetof(GetUniformLocation
, header
) == 0,
378 OffsetOf_GetUniformLocation_header_not_0
);
379 COMPILE_ASSERT(offsetof(GetUniformLocation
, program
) == 4,
380 OffsetOf_GetUniformLocation_program_not_4
);
381 COMPILE_ASSERT(offsetof(GetUniformLocation
, name_shm_id
) == 8,
382 OffsetOf_GetUniformLocation_name_shm_id_not_8
);
383 COMPILE_ASSERT(offsetof(GetUniformLocation
, name_shm_offset
) == 12,
384 OffsetOf_GetUniformLocation_name_shm_offset_not_12
);
385 COMPILE_ASSERT(offsetof(GetUniformLocation
, location_shm_id
) == 16,
386 OffsetOf_GetUniformLocation_location_shm_id_not_16
);
387 COMPILE_ASSERT(offsetof(GetUniformLocation
, location_shm_offset
) == 20,
388 OffsetOf_GetUniformLocation_location_shm_offset_not_20
);
389 COMPILE_ASSERT(offsetof(GetUniformLocation
, data_size
) == 24,
390 OffsetOf_GetUniformLocation_data_size_not_24
);
392 struct GetUniformLocationBucket
{
393 typedef GetUniformLocationBucket ValueType
;
394 static const CommandId kCmdId
= kGetUniformLocationBucket
;
395 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
396 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
398 typedef GLint Result
;
400 static uint32
ComputeSize() {
401 return static_cast<uint32
>(sizeof(ValueType
)); // NOLINT
405 header
.SetCmd
<ValueType
>();
409 GLuint _program
, uint32 _name_bucket_id
,
410 uint32 _location_shm_id
, uint32 _location_shm_offset
) {
413 name_bucket_id
= _name_bucket_id
;
414 location_shm_id
= _location_shm_id
;
415 location_shm_offset
= _location_shm_offset
;
419 void* cmd
, GLuint _program
, uint32 _name_bucket_id
,
420 uint32 _location_shm_id
, uint32 _location_shm_offset
) {
421 static_cast<ValueType
*>(
423 _program
, _name_bucket_id
, _location_shm_id
,
424 _location_shm_offset
);
425 return NextCmdAddress
<ValueType
>(cmd
);
428 CommandHeader header
;
430 uint32 name_bucket_id
;
431 uint32 location_shm_id
;
432 uint32 location_shm_offset
;
435 COMPILE_ASSERT(sizeof(GetUniformLocationBucket
) == 20,
436 Sizeof_GetUniformLocationBucket_is_not_24
);
437 COMPILE_ASSERT(offsetof(GetUniformLocationBucket
, header
) == 0,
438 OffsetOf_GetUniformLocationBucket_header_not_0
);
439 COMPILE_ASSERT(offsetof(GetUniformLocationBucket
, program
) == 4,
440 OffsetOf_GetUniformLocationBucket_program_not_4
);
441 COMPILE_ASSERT(offsetof(GetUniformLocationBucket
, name_bucket_id
) == 8,
442 OffsetOf_GetUniformLocationBucket_name_bucket_id_not_8
);
443 COMPILE_ASSERT(offsetof(GetUniformLocationBucket
, location_shm_id
) == 12,
444 OffsetOf_GetUniformLocationBucket_location_shm_id_not_12
);
445 COMPILE_ASSERT(offsetof(GetUniformLocationBucket
, location_shm_offset
) == 16,
446 OffsetOf_GetUniformLocationBucket_location_shm_offset_not_16
);
448 struct GenMailboxCHROMIUM
{
449 typedef GenMailboxCHROMIUM ValueType
;
450 static const CommandId kCmdId
= kGenMailboxCHROMIUM
;
451 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
452 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
453 CommandHeader header
;
456 struct InsertSyncPointCHROMIUM
{
457 typedef InsertSyncPointCHROMIUM ValueType
;
458 static const CommandId kCmdId
= kInsertSyncPointCHROMIUM
;
459 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
460 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
461 CommandHeader header
;
464 struct CreateAndConsumeTextureCHROMIUMImmediate
{
465 typedef CreateAndConsumeTextureCHROMIUMImmediate ValueType
;
466 static const CommandId kCmdId
= kCreateAndConsumeTextureCHROMIUMImmediate
;
467 static const cmd::ArgFlags kArgFlags
= cmd::kAtLeastN
;
468 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(1);
470 static uint32_t ComputeDataSize() {
471 return static_cast<uint32_t>(sizeof(GLbyte
) * 64); // NOLINT
474 static uint32_t ComputeSize() {
475 return static_cast<uint32_t>(sizeof(ValueType
) +
476 ComputeDataSize()); // NOLINT
479 void SetHeader(uint32_t size_in_bytes
) {
480 header
.SetCmdByTotalSize
<ValueType
>(size_in_bytes
);
483 void Init(GLenum _target
, uint32_t _client_id
, const GLbyte
* _mailbox
) {
484 SetHeader(ComputeSize());
486 client_id
= _client_id
;
487 memcpy(ImmediateDataAddress(this), _mailbox
, ComputeDataSize());
493 const GLbyte
* _mailbox
) {
494 static_cast<ValueType
*>(cmd
)->Init(_target
, _client_id
, _mailbox
);
495 const uint32_t size
= ComputeSize();
496 return NextImmediateCmdAddressTotalSize
<ValueType
>(cmd
, size
);
499 gpu::CommandHeader header
;
504 COMPILE_ASSERT(sizeof(CreateAndConsumeTextureCHROMIUMImmediate
) == 12,
505 Sizeof_CreateAndConsumeTextureCHROMIUMImmediate_is_not_12
);
506 COMPILE_ASSERT(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, header
) == 0,
507 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_header_not_0
);
508 COMPILE_ASSERT(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, target
) == 4,
509 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_target_not_4
);
511 offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, client_id
) == 8,
512 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_client_id_not_8
);
521 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_