Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / common / gles2_cmd_format.h
blobd1ad74005c58d78e79b052dc104c90f67abef39e
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>
13 #include <stdint.h>
14 #include <string.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;
30 typedef int GLint;
31 typedef int GLsizei;
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;
42 typedef void GLvoid;
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;
49 namespace gpu {
50 namespace gles2 {
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.
58 enum IdNamespaces {
59 kBuffers,
60 kFramebuffers,
61 kProgramsAndShaders,
62 kRenderbuffers,
63 kTextures,
64 kQueries,
65 kVertexArrays,
66 kValuebuffers,
67 kSamplers,
68 kTransformFeedbacks,
69 kSyncs,
70 kNumIdNamespaces
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.
88 template <typename T>
89 struct SizedResult {
90 typedef T Type;
92 T* GetData() {
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
118 // Copy the result.
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 {
176 uint32_t size;
177 uint32_t type;
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 num_transform_feedback_varyings;
185 // TransformFeedbackVaryingInfo varyings[num_transform_feedback_varyings];
188 // Parameters of a uniform that can be queried through glGetActiveUniformsiv,
189 // but not through glGetActiveUniform.
190 struct UniformES3Info {
191 int32_t block_index;
192 int32_t offset;
193 int32_t array_stride;
194 int32_t matrix_stride;
195 int32_t is_row_major;
198 // The format of the bucket filled out by GetUniformsivES3CHROMIUM
199 struct UniformsES3Header {
200 uint32_t num_uniforms;
201 // UniformES3Info uniforms[num_uniforms];
204 // The format of QuerySync used by EXT_occlusion_query_boolean
205 struct QuerySync {
206 void Reset() {
207 process_count = 0;
208 result = 0;
211 base::subtle::Atomic32 process_count;
212 uint64_t result;
215 struct AsyncUploadSync {
216 void Reset() {
217 base::subtle::Release_Store(&async_upload_token, 0);
220 void SetAsyncUploadToken(uint32_t token) {
221 DCHECK_NE(token, 0u);
222 base::subtle::Release_Store(&async_upload_token, token);
225 bool HasAsyncUploadTokenPassed(uint32_t token) {
226 DCHECK_NE(token, 0u);
227 uint32_t current_token = base::subtle::Acquire_Load(&async_upload_token);
228 return (current_token - token < 0x80000000);
231 base::subtle::Atomic32 async_upload_token;
234 struct DisjointValueSync {
235 void Reset() {
236 base::subtle::Release_Store(&disjoint_count, 0);
239 void SetDisjointCount(uint32_t token) {
240 DCHECK_NE(token, 0u);
241 base::subtle::Release_Store(&disjoint_count, token);
244 uint32_t GetDisjointCount() {
245 return base::subtle::Acquire_Load(&disjoint_count);
248 base::subtle::Atomic32 disjoint_count;
251 static_assert(sizeof(ProgramInput) == 20, "size of ProgramInput should be 20");
252 static_assert(offsetof(ProgramInput, type) == 0,
253 "offset of ProgramInput.type should be 0");
254 static_assert(offsetof(ProgramInput, size) == 4,
255 "offset of ProgramInput.size should be 4");
256 static_assert(offsetof(ProgramInput, location_offset) == 8,
257 "offset of ProgramInput.location_offset should be 8");
258 static_assert(offsetof(ProgramInput, name_offset) == 12,
259 "offset of ProgramInput.name_offset should be 12");
260 static_assert(offsetof(ProgramInput, name_length) == 16,
261 "offset of ProgramInput.name_length should be 16");
263 static_assert(sizeof(ProgramInfoHeader) == 12,
264 "size of ProgramInfoHeader should be 12");
265 static_assert(offsetof(ProgramInfoHeader, link_status) == 0,
266 "offset of ProgramInfoHeader.link_status should be 0");
267 static_assert(offsetof(ProgramInfoHeader, num_attribs) == 4,
268 "offset of ProgramInfoHeader.num_attribs should be 4");
269 static_assert(offsetof(ProgramInfoHeader, num_uniforms) == 8,
270 "offset of ProgramInfoHeader.num_uniforms should be 8");
272 static_assert(sizeof(UniformBlockInfo) == 32,
273 "size of UniformBlockInfo should be 32");
274 static_assert(offsetof(UniformBlockInfo, binding) == 0,
275 "offset of UniformBlockInfo.binding should be 0");
276 static_assert(offsetof(UniformBlockInfo, data_size) == 4,
277 "offset of UniformBlockInfo.data_size should be 4");
278 static_assert(offsetof(UniformBlockInfo, name_offset) == 8,
279 "offset of UniformBlockInfo.name_offset should be 8");
280 static_assert(offsetof(UniformBlockInfo, name_length) == 12,
281 "offset of UniformBlockInfo.name_length should be 12");
282 static_assert(offsetof(UniformBlockInfo, active_uniforms) == 16,
283 "offset of UniformBlockInfo.active_uniforms should be 16");
284 static_assert(offsetof(UniformBlockInfo, active_uniform_offset) == 20,
285 "offset of UniformBlockInfo.active_uniform_offset should be 20");
286 static_assert(offsetof(UniformBlockInfo, referenced_by_vertex_shader) == 24,
287 "offset of UniformBlockInfo.referenced_by_vertex_shader "
288 "should be 24");
289 static_assert(offsetof(UniformBlockInfo, referenced_by_fragment_shader) == 28,
290 "offset of UniformBlockInfo.referenced_by_fragment_shader "
291 "should be 28");
293 static_assert(sizeof(UniformBlocksHeader) == 4,
294 "size of UniformBlocksHeader should be 4");
295 static_assert(offsetof(UniformBlocksHeader, num_uniform_blocks) == 0,
296 "offset of UniformBlocksHeader.num_uniform_blocks should be 0");
298 namespace cmds {
300 #include "../common/gles2_cmd_format_autogen.h"
302 // These are hand written commands.
303 // TODO(gman): Attempt to make these auto-generated.
305 struct GenMailboxCHROMIUM {
306 typedef GenMailboxCHROMIUM ValueType;
307 static const CommandId kCmdId = kGenMailboxCHROMIUM;
308 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
309 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
310 CommandHeader header;
313 struct InsertSyncPointCHROMIUM {
314 typedef InsertSyncPointCHROMIUM ValueType;
315 static const CommandId kCmdId = kInsertSyncPointCHROMIUM;
316 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
317 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
318 CommandHeader header;
321 struct CreateAndConsumeTextureCHROMIUMImmediate {
322 typedef CreateAndConsumeTextureCHROMIUMImmediate ValueType;
323 static const CommandId kCmdId = kCreateAndConsumeTextureCHROMIUMImmediate;
324 static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN;
325 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(1);
327 static uint32_t ComputeDataSize() {
328 return static_cast<uint32_t>(sizeof(GLbyte) * 64); // NOLINT
331 static uint32_t ComputeSize() {
332 return static_cast<uint32_t>(sizeof(ValueType) +
333 ComputeDataSize()); // NOLINT
336 void SetHeader(uint32_t size_in_bytes) {
337 header.SetCmdByTotalSize<ValueType>(size_in_bytes);
340 void Init(GLenum _target, uint32_t _client_id, const GLbyte* _mailbox) {
341 SetHeader(ComputeSize());
342 target = _target;
343 client_id = _client_id;
344 memcpy(ImmediateDataAddress(this), _mailbox, ComputeDataSize());
347 void* Set(void* cmd,
348 GLenum _target,
349 uint32_t _client_id,
350 const GLbyte* _mailbox) {
351 static_cast<ValueType*>(cmd)->Init(_target, _client_id, _mailbox);
352 const uint32_t size = ComputeSize();
353 return NextImmediateCmdAddressTotalSize<ValueType>(cmd, size);
356 gpu::CommandHeader header;
357 uint32_t target;
358 uint32_t client_id;
361 static_assert(sizeof(CreateAndConsumeTextureCHROMIUMImmediate) == 12,
362 "size of CreateAndConsumeTextureCHROMIUMImmediate should be 12");
363 static_assert(offsetof(CreateAndConsumeTextureCHROMIUMImmediate, header) == 0,
364 "offset of CreateAndConsumeTextureCHROMIUMImmediate.header "
365 "should be 0");
366 static_assert(offsetof(CreateAndConsumeTextureCHROMIUMImmediate, target) == 4,
367 "offset of CreateAndConsumeTextureCHROMIUMImmediate.target "
368 "should be 4");
369 static_assert(
370 offsetof(CreateAndConsumeTextureCHROMIUMImmediate, client_id) == 8,
371 "offset of CreateAndConsumeTextureCHROMIUMImmediate.client_id should be 8");
374 #pragma pack(pop)
376 } // namespace cmd
377 } // namespace gles2
378 } // namespace gpu
380 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_