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.
66 // These numbers must not change
67 COMPILE_ASSERT(kBuffers
== 0, kBuffers_is_not_0
);
68 COMPILE_ASSERT(kFramebuffers
== 1, kFramebuffers_is_not_1
);
69 COMPILE_ASSERT(kProgramsAndShaders
== 2, kProgramsAndShaders_is_not_2
);
70 COMPILE_ASSERT(kRenderbuffers
== 3, kRenderbuffers_is_not_3
);
71 COMPILE_ASSERT(kTextures
== 4, kTextures_is_not_4
);
73 } // namespace id_namespaces
75 // Used for some glGetXXX commands that return a result through a pointer. We
76 // need to know if the command succeeded or not and the size of the result. If
77 // the command failed its result size will 0.
83 return static_cast<T
*>(static_cast<void*>(&data
));
86 // Returns the total size in bytes of the SizedResult for a given number of
87 // results including the size field.
88 static size_t ComputeSize(size_t num_results
) {
89 return sizeof(T
) * num_results
+ sizeof(uint32_t); // NOLINT
92 // Returns the total size in bytes of the SizedResult for a given size of
94 static size_t ComputeSizeFromBytes(size_t size_of_result_in_bytes
) {
95 return size_of_result_in_bytes
+ sizeof(uint32_t); // NOLINT
98 // Returns the maximum number of results for a given buffer size.
99 static uint32_t ComputeMaxResults(size_t size_of_buffer
) {
100 return (size_of_buffer
>= sizeof(uint32_t)) ?
101 ((size_of_buffer
- sizeof(uint32_t)) / sizeof(T
)) : 0; // NOLINT
104 // Set the size for a given number of results.
105 void SetNumResults(size_t num_results
) {
106 size
= sizeof(T
) * num_results
; // NOLINT
109 // Get the number of elements in the result
110 int32_t GetNumResults() const {
111 return size
/ sizeof(T
); // NOLINT
115 void CopyResult(void* dst
) const {
116 memcpy(dst
, &data
, size
);
119 uint32_t size
; // in bytes.
120 int32_t data
; // this is just here to get an offset.
123 COMPILE_ASSERT(sizeof(SizedResult
<int8_t>) == 8, SizedResult_size_not_8
);
124 COMPILE_ASSERT(offsetof(SizedResult
<int8_t>, size
) == 0,
125 OffsetOf_SizedResult_size_not_0
);
126 COMPILE_ASSERT(offsetof(SizedResult
<int8_t>, data
) == 4,
127 OffsetOf_SizedResult_data_not_4
);
129 // The data for one attrib or uniform from GetProgramInfoCHROMIUM.
130 struct ProgramInput
{
131 uint32_t type
; // The type (GL_VEC3, GL_MAT3, GL_SAMPLER_2D, etc.
132 int32_t size
; // The size (how big the array is for uniforms)
133 uint32_t location_offset
; // offset from ProgramInfoHeader to 'size'
134 // locations for uniforms, 1 for attribs.
135 uint32_t name_offset
; // offset from ProgrmaInfoHeader to start of name.
136 uint32_t name_length
; // length of the name.
139 // The format of the bucket filled out by GetProgramInfoCHROMIUM
140 struct ProgramInfoHeader
{
141 uint32_t link_status
;
142 uint32_t num_attribs
;
143 uint32_t num_uniforms
;
144 // ProgramInput inputs[num_attribs + num_uniforms];
147 // The format of QuerySync used by EXT_occlusion_query_boolean
154 base::subtle::Atomic32 process_count
;
158 struct AsyncUploadSync
{
160 base::subtle::Release_Store(&async_upload_token
, 0);
163 void SetAsyncUploadToken(uint32_t token
) {
164 DCHECK_NE(token
, 0u);
165 base::subtle::Release_Store(&async_upload_token
, token
);
168 bool HasAsyncUploadTokenPassed(uint32_t token
) {
169 DCHECK_NE(token
, 0u);
170 uint32_t current_token
= base::subtle::Acquire_Load(&async_upload_token
);
171 return (current_token
- token
< 0x80000000);
174 base::subtle::Atomic32 async_upload_token
;
177 COMPILE_ASSERT(sizeof(ProgramInput
) == 20, ProgramInput_size_not_20
);
178 COMPILE_ASSERT(offsetof(ProgramInput
, type
) == 0,
179 OffsetOf_ProgramInput_type_not_0
);
180 COMPILE_ASSERT(offsetof(ProgramInput
, size
) == 4,
181 OffsetOf_ProgramInput_size_not_4
);
182 COMPILE_ASSERT(offsetof(ProgramInput
, location_offset
) == 8,
183 OffsetOf_ProgramInput_location_offset_not_8
);
184 COMPILE_ASSERT(offsetof(ProgramInput
, name_offset
) == 12,
185 OffsetOf_ProgramInput_name_offset_not_12
);
186 COMPILE_ASSERT(offsetof(ProgramInput
, name_length
) == 16,
187 OffsetOf_ProgramInput_name_length_not_16
);
189 COMPILE_ASSERT(sizeof(ProgramInfoHeader
) == 12, ProgramInfoHeader_size_not_12
);
190 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, link_status
) == 0,
191 OffsetOf_ProgramInfoHeader_link_status_not_0
);
192 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, num_attribs
) == 4,
193 OffsetOf_ProgramInfoHeader_num_attribs_not_4
);
194 COMPILE_ASSERT(offsetof(ProgramInfoHeader
, num_uniforms
) == 8,
195 OffsetOf_ProgramInfoHeader_num_uniforms_not_8
);
199 #include "../common/gles2_cmd_format_autogen.h"
201 // These are hand written commands.
202 // TODO(gman): Attempt to make these auto-generated.
204 struct GenMailboxCHROMIUM
{
205 typedef GenMailboxCHROMIUM ValueType
;
206 static const CommandId kCmdId
= kGenMailboxCHROMIUM
;
207 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
208 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
209 CommandHeader header
;
212 struct InsertSyncPointCHROMIUM
{
213 typedef InsertSyncPointCHROMIUM ValueType
;
214 static const CommandId kCmdId
= kInsertSyncPointCHROMIUM
;
215 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
216 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
217 CommandHeader header
;
220 struct CreateAndConsumeTextureCHROMIUMImmediate
{
221 typedef CreateAndConsumeTextureCHROMIUMImmediate ValueType
;
222 static const CommandId kCmdId
= kCreateAndConsumeTextureCHROMIUMImmediate
;
223 static const cmd::ArgFlags kArgFlags
= cmd::kAtLeastN
;
224 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(1);
226 static uint32_t ComputeDataSize() {
227 return static_cast<uint32_t>(sizeof(GLbyte
) * 64); // NOLINT
230 static uint32_t ComputeSize() {
231 return static_cast<uint32_t>(sizeof(ValueType
) +
232 ComputeDataSize()); // NOLINT
235 void SetHeader(uint32_t size_in_bytes
) {
236 header
.SetCmdByTotalSize
<ValueType
>(size_in_bytes
);
239 void Init(GLenum _target
, uint32_t _client_id
, const GLbyte
* _mailbox
) {
240 SetHeader(ComputeSize());
242 client_id
= _client_id
;
243 memcpy(ImmediateDataAddress(this), _mailbox
, ComputeDataSize());
249 const GLbyte
* _mailbox
) {
250 static_cast<ValueType
*>(cmd
)->Init(_target
, _client_id
, _mailbox
);
251 const uint32_t size
= ComputeSize();
252 return NextImmediateCmdAddressTotalSize
<ValueType
>(cmd
, size
);
255 gpu::CommandHeader header
;
260 COMPILE_ASSERT(sizeof(CreateAndConsumeTextureCHROMIUMImmediate
) == 12,
261 Sizeof_CreateAndConsumeTextureCHROMIUMImmediate_is_not_12
);
262 COMPILE_ASSERT(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, header
) == 0,
263 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_header_not_0
);
264 COMPILE_ASSERT(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, target
) == 4,
265 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_target_not_4
);
267 offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, client_id
) == 8,
268 OffsetOf_CreateAndConsumeTextureCHROMIUMImmediate_client_id_not_8
);
277 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_