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>
15 #include "base/safe_numerics.h"
16 #include "gpu/command_buffer/common/bitfield_helpers.h"
17 #include "gpu/command_buffer/common/cmd_buffer_common.h"
18 #include "gpu/command_buffer/common/gles2_cmd_ids.h"
19 #include "gpu/command_buffer/common/types.h"
21 // GL types are forward declared to avoid including the GL headers. The problem
22 // is determining which GL headers to include from code that is common to the
23 // client and service sides (GLES2 or one of several GL implementations).
24 typedef unsigned int GLenum;
25 typedef unsigned int GLbitfield;
26 typedef unsigned int GLuint;
29 typedef unsigned char GLboolean;
30 typedef signed char GLbyte;
31 typedef short GLshort;
32 typedef unsigned char GLubyte;
33 typedef unsigned short GLushort;
34 typedef unsigned long GLulong;
35 typedef float GLfloat;
36 typedef float GLclampf;
37 typedef double GLdouble;
38 typedef double GLclampd;
40 typedef khronos_intptr_t GLintptr;
41 typedef khronos_ssize_t GLsizeiptr;
48 namespace id_namespaces {
50 // These are used when contexts share resources.
62 // These numbers must not change
63 COMPILE_ASSERT(kBuffers == 0, kBuffers_is_not_0);
64 COMPILE_ASSERT(kFramebuffers == 1, kFramebuffers_is_not_1);
65 COMPILE_ASSERT(kProgramsAndShaders == 2, kProgramsAndShaders_is_not_2);
66 COMPILE_ASSERT(kRenderbuffers == 3, kRenderbuffers_is_not_3);
67 COMPILE_ASSERT(kTextures == 4, kTextures_is_not_4);
69 } // namespace id_namespaces
71 // Used for some glGetXXX commands that return a result through a pointer. We
72 // need to know if the command succeeded or not and the size of the result. If
73 // the command failed its result size will 0.
79 return static_cast<T*>(static_cast<void*>(&data));
82 // Returns the total size in bytes of the SizedResult for a given number of
83 // results including the size field.
84 static size_t ComputeSize(size_t num_results) {
85 return sizeof(T) * num_results + sizeof(uint32); // NOLINT
88 // Returns the total size in bytes of the SizedResult for a given size of
90 static size_t ComputeSizeFromBytes(size_t size_of_result_in_bytes) {
91 return size_of_result_in_bytes + sizeof(uint32); // NOLINT
94 // Returns the maximum number of results for a given buffer size.
95 static uint32 ComputeMaxResults(size_t size_of_buffer) {
96 return (size_of_buffer >= sizeof(uint32)) ?
97 ((size_of_buffer - sizeof(uint32)) / sizeof(T)) : 0; // NOLINT
100 // Set the size for a given number of results.
101 void SetNumResults(size_t num_results) {
102 size = sizeof(T) * num_results; // NOLINT
105 // Get the number of elements in the result
106 int32 GetNumResults() const {
107 return size / sizeof(T); // NOLINT
111 void CopyResult(void* dst) const {
112 memcpy(dst, &data, size);
115 uint32 size; // in bytes.
116 int32 data; // this is just here to get an offset.
119 COMPILE_ASSERT(sizeof(SizedResult<int8>) == 8, SizedResult_size_not_8);
120 COMPILE_ASSERT(offsetof(SizedResult<int8>, size) == 0,
121 OffsetOf_SizedResult_size_not_0);
122 COMPILE_ASSERT(offsetof(SizedResult<int8>, data) == 4,
123 OffsetOf_SizedResult_data_not_4);
125 // The data for one attrib or uniform from GetProgramInfoCHROMIUM.
126 struct ProgramInput {
127 uint32 type; // The type (GL_VEC3, GL_MAT3, GL_SAMPLER_2D, etc.
128 int32 size; // The size (how big the array is for uniforms)
129 uint32 location_offset; // offset from ProgramInfoHeader to 'size' locations
130 // for uniforms, 1 for attribs.
131 uint32 name_offset; // offset from ProgrmaInfoHeader to start of name.
132 uint32 name_length; // length of the name.
135 // The format of the bucket filled out by GetProgramInfoCHROMIUM
136 struct ProgramInfoHeader {
140 // ProgramInput inputs[num_attribs + num_uniforms];
143 // The format of QuerySync used by EXT_occlusion_query_boolean
150 uint32 process_count;
154 COMPILE_ASSERT(sizeof(ProgramInput) == 20, ProgramInput_size_not_20);
155 COMPILE_ASSERT(offsetof(ProgramInput, type) == 0,
156 OffsetOf_ProgramInput_type_not_0);
157 COMPILE_ASSERT(offsetof(ProgramInput, size) == 4,
158 OffsetOf_ProgramInput_size_not_4);
159 COMPILE_ASSERT(offsetof(ProgramInput, location_offset) == 8,
160 OffsetOf_ProgramInput_location_offset_not_8);
161 COMPILE_ASSERT(offsetof(ProgramInput, name_offset) == 12,
162 OffsetOf_ProgramInput_name_offset_not_12);
163 COMPILE_ASSERT(offsetof(ProgramInput, name_length) == 16,
164 OffsetOf_ProgramInput_name_length_not_16);
166 COMPILE_ASSERT(sizeof(ProgramInfoHeader) == 12, ProgramInfoHeader_size_not_12);
167 COMPILE_ASSERT(offsetof(ProgramInfoHeader, link_status) == 0,
168 OffsetOf_ProgramInfoHeader_link_status_not_0);
169 COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_attribs) == 4,
170 OffsetOf_ProgramInfoHeader_num_attribs_not_4);
171 COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_uniforms) == 8,
172 OffsetOf_ProgramInfoHeader_num_uniforms_not_8);
176 #include "../common/gles2_cmd_format_autogen.h"
178 // These are hand written commands.
179 // TODO(gman): Attempt to make these auto-generated.
181 struct GetAttribLocation {
182 typedef GetAttribLocation ValueType;
183 static const CommandId kCmdId = kGetAttribLocation;
184 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
186 typedef GLint Result;
188 static uint32 ComputeSize() {
189 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
193 header.SetCmd<ValueType>();
197 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
198 uint32 _location_shm_id, uint32 _location_shm_offset,
202 name_shm_id = _name_shm_id;
203 name_shm_offset = _name_shm_offset;
204 location_shm_id = _location_shm_id;
205 location_shm_offset = _location_shm_offset;
206 data_size = _data_size;
210 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
211 uint32 _location_shm_id, uint32 _location_shm_offset,
213 static_cast<ValueType*>(
215 _program, _name_shm_id, _name_shm_offset, _location_shm_id,
216 _location_shm_offset, _data_size);
217 return NextCmdAddress<ValueType>(cmd);
220 CommandHeader header;
223 uint32 name_shm_offset;
224 uint32 location_shm_id;
225 uint32 location_shm_offset;
229 COMPILE_ASSERT(sizeof(GetAttribLocation) == 28,
230 Sizeof_GetAttribLocation_is_not_28);
231 COMPILE_ASSERT(offsetof(GetAttribLocation, header) == 0,
232 OffsetOf_GetAttribLocation_header_not_0);
233 COMPILE_ASSERT(offsetof(GetAttribLocation, program) == 4,
234 OffsetOf_GetAttribLocation_program_not_4);
235 COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_id) == 8,
236 OffsetOf_GetAttribLocation_name_shm_id_not_8);
237 COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_offset) == 12,
238 OffsetOf_GetAttribLocation_name_shm_offset_not_12);
239 COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_id) == 16,
240 OffsetOf_GetAttribLocation_location_shm_id_not_16);
241 COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_offset) == 20,
242 OffsetOf_GetAttribLocation_location_shm_offset_not_20);
243 COMPILE_ASSERT(offsetof(GetAttribLocation, data_size) == 24,
244 OffsetOf_GetAttribLocation_data_size_not_24);
247 struct GetAttribLocationBucket {
248 typedef GetAttribLocationBucket ValueType;
249 static const CommandId kCmdId = kGetAttribLocationBucket;
250 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
252 typedef GLint Result;
254 static uint32 ComputeSize() {
255 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
259 header.SetCmd<ValueType>();
263 GLuint _program, uint32 _name_bucket_id,
264 uint32 _location_shm_id, uint32 _location_shm_offset) {
267 name_bucket_id = _name_bucket_id;
268 location_shm_id = _location_shm_id;
269 location_shm_offset = _location_shm_offset;
273 void* cmd, GLuint _program, uint32 _name_bucket_id,
274 uint32 _location_shm_id, uint32 _location_shm_offset) {
275 static_cast<ValueType*>(
277 _program, _name_bucket_id, _location_shm_id,
278 _location_shm_offset);
279 return NextCmdAddress<ValueType>(cmd);
282 CommandHeader header;
284 uint32 name_bucket_id;
285 uint32 location_shm_id;
286 uint32 location_shm_offset;
289 COMPILE_ASSERT(sizeof(GetAttribLocationBucket) == 20,
290 Sizeof_GetAttribLocationBucket_is_not_24);
291 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, header) == 0,
292 OffsetOf_GetAttribLocationBucket_header_not_0);
293 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, program) == 4,
294 OffsetOf_GetAttribLocationBucket_program_not_4);
295 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, name_bucket_id) == 8,
296 OffsetOf_GetAttribLocationBucket_name_bucket_id_not_8);
297 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_id) == 12,
298 OffsetOf_GetAttribLocationBucket_location_shm_id_not_12);
299 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_offset) == 16,
300 OffsetOf_GetAttribLocationBucket_location_shm_offset_not_16);
302 struct GetUniformLocation {
303 typedef GetUniformLocation ValueType;
304 static const CommandId kCmdId = kGetUniformLocation;
305 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
307 typedef GLint Result;
309 static uint32 ComputeSize() {
310 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
314 header.SetCmd<ValueType>();
318 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
319 uint32 _location_shm_id, uint32 _location_shm_offset,
323 name_shm_id = _name_shm_id;
324 name_shm_offset = _name_shm_offset;
325 location_shm_id = _location_shm_id;
326 location_shm_offset = _location_shm_offset;
327 data_size = _data_size;
331 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
332 uint32 _location_shm_id, uint32 _location_shm_offset,
334 static_cast<ValueType*>(
336 _program, _name_shm_id, _name_shm_offset, _location_shm_id,
337 _location_shm_offset, _data_size);
338 return NextCmdAddress<ValueType>(cmd);
341 CommandHeader header;
344 uint32 name_shm_offset;
345 uint32 location_shm_id;
346 uint32 location_shm_offset;
350 COMPILE_ASSERT(sizeof(GetUniformLocation) == 28,
351 Sizeof_GetUniformLocation_is_not_28);
352 COMPILE_ASSERT(offsetof(GetUniformLocation, header) == 0,
353 OffsetOf_GetUniformLocation_header_not_0);
354 COMPILE_ASSERT(offsetof(GetUniformLocation, program) == 4,
355 OffsetOf_GetUniformLocation_program_not_4);
356 COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_id) == 8,
357 OffsetOf_GetUniformLocation_name_shm_id_not_8);
358 COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_offset) == 12,
359 OffsetOf_GetUniformLocation_name_shm_offset_not_12);
360 COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_id) == 16,
361 OffsetOf_GetUniformLocation_location_shm_id_not_16);
362 COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_offset) == 20,
363 OffsetOf_GetUniformLocation_location_shm_offset_not_20);
364 COMPILE_ASSERT(offsetof(GetUniformLocation, data_size) == 24,
365 OffsetOf_GetUniformLocation_data_size_not_24);
367 struct GetUniformLocationBucket {
368 typedef GetUniformLocationBucket ValueType;
369 static const CommandId kCmdId = kGetUniformLocationBucket;
370 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
372 typedef GLint Result;
374 static uint32 ComputeSize() {
375 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
379 header.SetCmd<ValueType>();
383 GLuint _program, uint32 _name_bucket_id,
384 uint32 _location_shm_id, uint32 _location_shm_offset) {
387 name_bucket_id = _name_bucket_id;
388 location_shm_id = _location_shm_id;
389 location_shm_offset = _location_shm_offset;
393 void* cmd, GLuint _program, uint32 _name_bucket_id,
394 uint32 _location_shm_id, uint32 _location_shm_offset) {
395 static_cast<ValueType*>(
397 _program, _name_bucket_id, _location_shm_id,
398 _location_shm_offset);
399 return NextCmdAddress<ValueType>(cmd);
402 CommandHeader header;
404 uint32 name_bucket_id;
405 uint32 location_shm_id;
406 uint32 location_shm_offset;
409 COMPILE_ASSERT(sizeof(GetUniformLocationBucket) == 20,
410 Sizeof_GetUniformLocationBucket_is_not_24);
411 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, header) == 0,
412 OffsetOf_GetUniformLocationBucket_header_not_0);
413 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, program) == 4,
414 OffsetOf_GetUniformLocationBucket_program_not_4);
415 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, name_bucket_id) == 8,
416 OffsetOf_GetUniformLocationBucket_name_bucket_id_not_8);
417 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_id) == 12,
418 OffsetOf_GetUniformLocationBucket_location_shm_id_not_12);
419 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_offset) == 16,
420 OffsetOf_GetUniformLocationBucket_location_shm_offset_not_16);
422 struct GenMailboxCHROMIUM {
423 typedef GenMailboxCHROMIUM ValueType;
424 static const CommandId kCmdId = kGenMailboxCHROMIUM;
425 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
426 CommandHeader header;
429 struct InsertSyncPointCHROMIUM {
430 typedef InsertSyncPointCHROMIUM ValueType;
431 static const CommandId kCmdId = kInsertSyncPointCHROMIUM;
432 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
433 CommandHeader header;
442 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_