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"
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
24 // GL types are forward declared to avoid including the GL headers. The problem
25 // is determining which GL headers to include from code that is common to the
26 // client and service sides (GLES2 or one of several GL implementations).
27 typedef unsigned int GLenum
;
28 typedef unsigned int GLbitfield
;
29 typedef unsigned int GLuint
;
32 typedef unsigned char GLboolean
;
33 typedef signed char GLbyte
;
34 typedef short GLshort
;
35 typedef unsigned char GLubyte
;
36 typedef unsigned short GLushort
;
37 typedef unsigned long GLulong
;
38 typedef float GLfloat
;
39 typedef float GLclampf
;
40 typedef double GLdouble
;
41 typedef double GLclampd
;
43 typedef khronos_intptr_t GLintptr
;
44 typedef khronos_ssize_t GLsizeiptr
;
45 typedef struct __GLsync
*GLsync
;
46 typedef int64_t GLint64
;
47 typedef uint64_t GLuint64
;
52 // Command buffer is GPU_COMMAND_BUFFER_ENTRY_ALIGNMENT byte aligned.
53 #pragma pack(push, GPU_COMMAND_BUFFER_ENTRY_ALIGNMENT)
55 namespace id_namespaces
{
57 // These are used when contexts share resources.
73 enum RangeIdNamespaces
{ kPaths
, kNumRangeIdNamespaces
};
75 // These numbers must not change
76 static_assert(kBuffers
== 0, "kBuffers should equal 0");
77 static_assert(kFramebuffers
== 1, "kFramebuffers should equal 1");
78 static_assert(kProgramsAndShaders
== 2, "kProgramsAndShaders should equal 2");
79 static_assert(kRenderbuffers
== 3, "kRenderbuffers should equal 3");
80 static_assert(kTextures
== 4, "kTextures should equal 4");
81 static_assert(kPaths
== 0, "kPaths should equal 0");
83 } // namespace id_namespaces
85 // Used for some glGetXXX commands that return a result through a pointer. We
86 // need to know if the command succeeded or not and the size of the result. If
87 // the command failed its result size will 0.
93 return static_cast<T
*>(static_cast<void*>(&data
));
96 // Returns the total size in bytes of the SizedResult for a given number of
97 // results including the size field.
98 static size_t ComputeSize(size_t num_results
) {
99 return sizeof(T
) * num_results
+ sizeof(uint32_t); // NOLINT
102 // Returns the maximum number of results for a given buffer size.
103 static uint32_t ComputeMaxResults(size_t size_of_buffer
) {
104 return (size_of_buffer
>= sizeof(uint32_t)) ?
105 ((size_of_buffer
- sizeof(uint32_t)) / sizeof(T
)) : 0; // NOLINT
108 // Set the size for a given number of results.
109 void SetNumResults(size_t num_results
) {
110 size
= sizeof(T
) * num_results
; // NOLINT
113 // Get the number of elements in the result
114 int32_t GetNumResults() const {
115 return size
/ sizeof(T
); // NOLINT
119 void CopyResult(void* dst
) const {
120 memcpy(dst
, &data
, size
);
123 uint32_t size
; // in bytes.
124 int32_t data
; // this is just here to get an offset.
127 static_assert(sizeof(SizedResult
<int8_t>) == 8,
128 "size of SizedResult<int8_t> should be 8");
129 static_assert(offsetof(SizedResult
<int8_t>, size
) == 0,
130 "offset of SizedResult<int8_t>.size should be 0");
131 static_assert(offsetof(SizedResult
<int8_t>, data
) == 4,
132 "offset of SizedResult<int8_t>.data should be 4");
134 // The data for one attrib or uniform from GetProgramInfoCHROMIUM.
135 struct ProgramInput
{
136 uint32_t type
; // The type (GL_VEC3, GL_MAT3, GL_SAMPLER_2D, etc.
137 int32_t size
; // The size (how big the array is for uniforms)
138 uint32_t location_offset
; // offset from ProgramInfoHeader to 'size'
139 // locations for uniforms, 1 for attribs.
140 uint32_t name_offset
; // offset from ProgrmaInfoHeader to start of name.
141 uint32_t name_length
; // length of the name.
144 // The format of the bucket filled out by GetProgramInfoCHROMIUM
145 struct ProgramInfoHeader
{
146 uint32_t link_status
;
147 uint32_t num_attribs
;
148 uint32_t num_uniforms
;
149 // ProgramInput inputs[num_attribs + num_uniforms];
152 // The data for one UniformBlock from GetProgramInfoCHROMIUM
153 struct UniformBlockInfo
{
154 uint32_t binding
; // UNIFORM_BLOCK_BINDING
155 uint32_t data_size
; // UNIFORM_BLOCK_DATA_SIZE
156 uint32_t name_offset
; // offset from UniformBlocksHeader to start of name.
157 uint32_t name_length
; // UNIFORM_BLOCK_NAME_LENGTH
158 uint32_t active_uniforms
; // UNIFORM_BLOCK_ACTIVE_UNIFORMS
159 // offset from UniformBlocksHeader to |active_uniforms| indices.
160 uint32_t active_uniform_offset
;
161 // UNIFORM_BLOCK_REFERENDED_BY_VERTEX_SHADER
162 uint32_t referenced_by_vertex_shader
;
163 // UNIFORM_BLOCK_REFERENDED_BY_FRAGMENT_SHADER
164 uint32_t referenced_by_fragment_shader
;
167 // The format of the bucket filled out by GetUniformBlocksCHROMIUM
168 struct UniformBlocksHeader
{
169 uint32_t num_uniform_blocks
;
170 // UniformBlockInfo uniform_blocks[num_uniform_blocks];
173 // The data for one TransformFeedbackVarying from
174 // GetTransformFeedbackVaringCHROMIUM.
175 struct TransformFeedbackVaryingInfo
{
178 uint32_t name_offset
; // offset from Header to start of name.
179 uint32_t name_length
; // including the null terminator.
182 // The format of the bucket filled out by GetTransformFeedbackVaryingsCHROMIUM
183 struct TransformFeedbackVaryingsHeader
{
184 uint32_t transform_feedback_buffer_mode
;
185 uint32_t num_transform_feedback_varyings
;
186 // TransformFeedbackVaryingInfo varyings[num_transform_feedback_varyings];
189 // Parameters of a uniform that can be queried through glGetActiveUniformsiv,
190 // but not through glGetActiveUniform.
191 struct UniformES3Info
{
194 int32_t array_stride
;
195 int32_t matrix_stride
;
196 int32_t is_row_major
;
199 // The format of the bucket filled out by GetUniformsivES3CHROMIUM
200 struct UniformsES3Header
{
201 uint32_t num_uniforms
;
202 // UniformES3Info uniforms[num_uniforms];
205 // The format of QuerySync used by EXT_occlusion_query_boolean
212 base::subtle::Atomic32 process_count
;
216 struct AsyncUploadSync
{
218 base::subtle::Release_Store(&async_upload_token
, 0);
221 void SetAsyncUploadToken(uint32_t token
) {
222 DCHECK_NE(token
, 0u);
223 base::subtle::Release_Store(&async_upload_token
, token
);
226 bool HasAsyncUploadTokenPassed(uint32_t token
) {
227 DCHECK_NE(token
, 0u);
228 uint32_t current_token
= base::subtle::Acquire_Load(&async_upload_token
);
229 return (current_token
- token
< 0x80000000);
232 base::subtle::Atomic32 async_upload_token
;
235 struct DisjointValueSync
{
237 base::subtle::Release_Store(&disjoint_count
, 0);
240 void SetDisjointCount(uint32_t token
) {
241 DCHECK_NE(token
, 0u);
242 base::subtle::Release_Store(&disjoint_count
, token
);
245 uint32_t GetDisjointCount() {
246 return base::subtle::Acquire_Load(&disjoint_count
);
249 base::subtle::Atomic32 disjoint_count
;
252 static_assert(sizeof(ProgramInput
) == 20, "size of ProgramInput should be 20");
253 static_assert(offsetof(ProgramInput
, type
) == 0,
254 "offset of ProgramInput.type should be 0");
255 static_assert(offsetof(ProgramInput
, size
) == 4,
256 "offset of ProgramInput.size should be 4");
257 static_assert(offsetof(ProgramInput
, location_offset
) == 8,
258 "offset of ProgramInput.location_offset should be 8");
259 static_assert(offsetof(ProgramInput
, name_offset
) == 12,
260 "offset of ProgramInput.name_offset should be 12");
261 static_assert(offsetof(ProgramInput
, name_length
) == 16,
262 "offset of ProgramInput.name_length should be 16");
264 static_assert(sizeof(ProgramInfoHeader
) == 12,
265 "size of ProgramInfoHeader should be 12");
266 static_assert(offsetof(ProgramInfoHeader
, link_status
) == 0,
267 "offset of ProgramInfoHeader.link_status should be 0");
268 static_assert(offsetof(ProgramInfoHeader
, num_attribs
) == 4,
269 "offset of ProgramInfoHeader.num_attribs should be 4");
270 static_assert(offsetof(ProgramInfoHeader
, num_uniforms
) == 8,
271 "offset of ProgramInfoHeader.num_uniforms should be 8");
273 static_assert(sizeof(UniformBlockInfo
) == 32,
274 "size of UniformBlockInfo should be 32");
275 static_assert(offsetof(UniformBlockInfo
, binding
) == 0,
276 "offset of UniformBlockInfo.binding should be 0");
277 static_assert(offsetof(UniformBlockInfo
, data_size
) == 4,
278 "offset of UniformBlockInfo.data_size should be 4");
279 static_assert(offsetof(UniformBlockInfo
, name_offset
) == 8,
280 "offset of UniformBlockInfo.name_offset should be 8");
281 static_assert(offsetof(UniformBlockInfo
, name_length
) == 12,
282 "offset of UniformBlockInfo.name_length should be 12");
283 static_assert(offsetof(UniformBlockInfo
, active_uniforms
) == 16,
284 "offset of UniformBlockInfo.active_uniforms should be 16");
285 static_assert(offsetof(UniformBlockInfo
, active_uniform_offset
) == 20,
286 "offset of UniformBlockInfo.active_uniform_offset should be 20");
287 static_assert(offsetof(UniformBlockInfo
, referenced_by_vertex_shader
) == 24,
288 "offset of UniformBlockInfo.referenced_by_vertex_shader "
290 static_assert(offsetof(UniformBlockInfo
, referenced_by_fragment_shader
) == 28,
291 "offset of UniformBlockInfo.referenced_by_fragment_shader "
294 static_assert(sizeof(UniformBlocksHeader
) == 4,
295 "size of UniformBlocksHeader should be 4");
296 static_assert(offsetof(UniformBlocksHeader
, num_uniform_blocks
) == 0,
297 "offset of UniformBlocksHeader.num_uniform_blocks should be 0");
301 #include "../common/gles2_cmd_format_autogen.h"
303 // These are hand written commands.
304 // TODO(gman): Attempt to make these auto-generated.
306 struct GenMailboxCHROMIUM
{
307 typedef GenMailboxCHROMIUM ValueType
;
308 static const CommandId kCmdId
= kGenMailboxCHROMIUM
;
309 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
310 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
311 CommandHeader header
;
314 struct InsertSyncPointCHROMIUM
{
315 typedef InsertSyncPointCHROMIUM ValueType
;
316 static const CommandId kCmdId
= kInsertSyncPointCHROMIUM
;
317 static const cmd::ArgFlags kArgFlags
= cmd::kFixed
;
318 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(3);
319 CommandHeader header
;
322 struct CreateAndConsumeTextureCHROMIUMImmediate
{
323 typedef CreateAndConsumeTextureCHROMIUMImmediate ValueType
;
324 static const CommandId kCmdId
= kCreateAndConsumeTextureCHROMIUMImmediate
;
325 static const cmd::ArgFlags kArgFlags
= cmd::kAtLeastN
;
326 static const uint8 cmd_flags
= CMD_FLAG_SET_TRACE_LEVEL(1);
328 static uint32_t ComputeDataSize() {
329 return static_cast<uint32_t>(sizeof(GLbyte
) * 64); // NOLINT
332 static uint32_t ComputeSize() {
333 return static_cast<uint32_t>(sizeof(ValueType
) +
334 ComputeDataSize()); // NOLINT
337 void SetHeader(uint32_t size_in_bytes
) {
338 header
.SetCmdByTotalSize
<ValueType
>(size_in_bytes
);
341 void Init(GLenum _target
, uint32_t _client_id
, const GLbyte
* _mailbox
) {
342 SetHeader(ComputeSize());
344 client_id
= _client_id
;
345 memcpy(ImmediateDataAddress(this), _mailbox
, ComputeDataSize());
351 const GLbyte
* _mailbox
) {
352 static_cast<ValueType
*>(cmd
)->Init(_target
, _client_id
, _mailbox
);
353 const uint32_t size
= ComputeSize();
354 return NextImmediateCmdAddressTotalSize
<ValueType
>(cmd
, size
);
357 gpu::CommandHeader header
;
362 static_assert(sizeof(CreateAndConsumeTextureCHROMIUMImmediate
) == 12,
363 "size of CreateAndConsumeTextureCHROMIUMImmediate should be 12");
364 static_assert(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, header
) == 0,
365 "offset of CreateAndConsumeTextureCHROMIUMImmediate.header "
367 static_assert(offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, target
) == 4,
368 "offset of CreateAndConsumeTextureCHROMIUMImmediate.target "
371 offsetof(CreateAndConsumeTextureCHROMIUMImmediate
, client_id
) == 8,
372 "offset of CreateAndConsumeTextureCHROMIUMImmediate.client_id should be 8");
381 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_