gles2_cmd_format.h revision 3551c9c881056c480085172ff9840cab31610854
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// found in the LICENSE file. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This file defines the GLES2 command buffer commands. 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_ 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_ 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <KHR/khrplatform.h> 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <string.h> 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "base/safe_numerics.h" 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "gpu/command_buffer/common/bitfield_helpers.h" 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "gpu/command_buffer/common/cmd_buffer_common.h" 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "gpu/command_buffer/common/gles2_cmd_ids.h" 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "gpu/command_buffer/common/types.h" 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// GL types are forward declared to avoid including the GL headers. The problem 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// is determining which GL headers to include from code that is common to the 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch// client and service sides (GLES2 or one of several GL implementations). 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef unsigned int GLenum; 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef unsigned int GLbitfield; 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef unsigned int GLuint; 27bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)typedef int GLint; 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef int GLsizei; 29bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)typedef unsigned char GLboolean; 3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)typedef signed char GLbyte; 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)typedef short GLshort; 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef unsigned char GLubyte; 33c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)typedef unsigned short GLushort; 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef unsigned long GLulong; 35bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)typedef float GLfloat; 36bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)typedef float GLclampf; 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef double GLdouble; 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef double GLclampd; 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef void GLvoid; 40bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)typedef khronos_intptr_t GLintptr; 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef khronos_ssize_t GLsizeiptr; 42bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace gpu { 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace gles2 { 45bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma pack(push, 1) 4706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace id_namespaces { 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// These are used when contexts share resources. 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)enum IdNamespaces { 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kBuffers, 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kFramebuffers, 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kProgramsAndShaders, 55bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) kRenderbuffers, 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kTextures, 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kQueries, 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) kVertexArrays, 598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) kNumIdNamespaces 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 61bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// These numbers must not change 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)COMPILE_ASSERT(kBuffers == 0, kBuffers_is_not_0); 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)COMPILE_ASSERT(kFramebuffers == 1, kFramebuffers_is_not_1); 65bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)COMPILE_ASSERT(kProgramsAndShaders == 2, kProgramsAndShaders_is_not_2); 66926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)COMPILE_ASSERT(kRenderbuffers == 3, kRenderbuffers_is_not_3); 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)COMPILE_ASSERT(kTextures == 4, kTextures_is_not_4); 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace id_namespaces 705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Used for some glGetXXX commands that return a result through a pointer. We 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// need to know if the command succeeded or not and the size of the result. If 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// the command failed its result size will 0. 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)template <typename T> 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct SizedResult { 76bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) typedef T Type; 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) T* GetData() { 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return static_cast<T*>(static_cast<void*>(&data)); 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Returns the total size in bytes of the SizedResult for a given number of 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // results including the size field. 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static size_t ComputeSize(size_t num_results) { 85bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) return sizeof(T) * num_results + sizeof(uint32); // NOLINT 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 8706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Returns the total size in bytes of the SizedResult for a given size of 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // results. 90bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) static size_t ComputeSizeFromBytes(size_t size_of_result_in_bytes) { 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return size_of_result_in_bytes + sizeof(uint32); // NOLINT 925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Returns the maximum number of results for a given buffer size. 9553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) static uint32 ComputeMaxResults(size_t size_of_buffer) { 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return (size_of_buffer >= sizeof(uint32)) ? 975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ((size_of_buffer - sizeof(uint32)) / sizeof(T)) : 0; // NOLINT 98bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) } 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 100f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) // Set the size for a given number of results. 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void SetNumResults(size_t num_results) { 1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) size = sizeof(T) * num_results; // NOLINT 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Get the number of elements in the result 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) int32 GetNumResults() const { 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return size / sizeof(T); // NOLINT 1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 109bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Copy the result. 1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void CopyResult(void* dst) const { 1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) memcpy(dst, &data, size); 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) uint32 size; // in bytes. 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) int32 data; // this is just here to get an offset. 117c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}; 118 119COMPILE_ASSERT(sizeof(SizedResult<int8>) == 8, SizedResult_size_not_8); 120COMPILE_ASSERT(offsetof(SizedResult<int8>, size) == 0, 121 OffsetOf_SizedResult_size_not_0); 122COMPILE_ASSERT(offsetof(SizedResult<int8>, data) == 4, 123 OffsetOf_SizedResult_data_not_4); 124 125// The data for one attrib or uniform from GetProgramInfoCHROMIUM. 126struct 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. 133}; 134 135// The format of the bucket filled out by GetProgramInfoCHROMIUM 136struct ProgramInfoHeader { 137 uint32 link_status; 138 uint32 num_attribs; 139 uint32 num_uniforms; 140 // ProgramInput inputs[num_attribs + num_uniforms]; 141}; 142 143// The format of QuerySync used by EXT_occlusion_query_boolean 144struct QuerySync { 145 void Reset() { 146 process_count = 0; 147 result = 0; 148 } 149 150 uint32 process_count; 151 uint64 result; 152}; 153 154COMPILE_ASSERT(sizeof(ProgramInput) == 20, ProgramInput_size_not_20); 155COMPILE_ASSERT(offsetof(ProgramInput, type) == 0, 156 OffsetOf_ProgramInput_type_not_0); 157COMPILE_ASSERT(offsetof(ProgramInput, size) == 4, 158 OffsetOf_ProgramInput_size_not_4); 159COMPILE_ASSERT(offsetof(ProgramInput, location_offset) == 8, 160 OffsetOf_ProgramInput_location_offset_not_8); 161COMPILE_ASSERT(offsetof(ProgramInput, name_offset) == 12, 162 OffsetOf_ProgramInput_name_offset_not_12); 163COMPILE_ASSERT(offsetof(ProgramInput, name_length) == 16, 164 OffsetOf_ProgramInput_name_length_not_16); 165 166COMPILE_ASSERT(sizeof(ProgramInfoHeader) == 12, ProgramInfoHeader_size_not_12); 167COMPILE_ASSERT(offsetof(ProgramInfoHeader, link_status) == 0, 168 OffsetOf_ProgramInfoHeader_link_status_not_0); 169COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_attribs) == 4, 170 OffsetOf_ProgramInfoHeader_num_attribs_not_4); 171COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_uniforms) == 8, 172 OffsetOf_ProgramInfoHeader_num_uniforms_not_8); 173 174namespace cmds { 175 176#include "../common/gles2_cmd_format_autogen.h" 177 178// These are hand written commands. 179// TODO(gman): Attempt to make these auto-generated. 180 181struct GetAttribLocation { 182 typedef GetAttribLocation ValueType; 183 static const CommandId kCmdId = kGetAttribLocation; 184 static const cmd::ArgFlags kArgFlags = cmd::kFixed; 185 186 typedef GLint Result; 187 188 static uint32 ComputeSize() { 189 return static_cast<uint32>(sizeof(ValueType)); // NOLINT 190 } 191 192 void SetHeader() { 193 header.SetCmd<ValueType>(); 194 } 195 196 void Init( 197 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset, 198 uint32 _location_shm_id, uint32 _location_shm_offset, 199 uint32 _data_size) { 200 SetHeader(); 201 program = _program; 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; 207 } 208 209 void* Set( 210 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset, 211 uint32 _location_shm_id, uint32 _location_shm_offset, 212 uint32 _data_size) { 213 static_cast<ValueType*>( 214 cmd)->Init( 215 _program, _name_shm_id, _name_shm_offset, _location_shm_id, 216 _location_shm_offset, _data_size); 217 return NextCmdAddress<ValueType>(cmd); 218 } 219 220 CommandHeader header; 221 uint32 program; 222 uint32 name_shm_id; 223 uint32 name_shm_offset; 224 uint32 location_shm_id; 225 uint32 location_shm_offset; 226 uint32 data_size; 227}; 228 229COMPILE_ASSERT(sizeof(GetAttribLocation) == 28, 230 Sizeof_GetAttribLocation_is_not_28); 231COMPILE_ASSERT(offsetof(GetAttribLocation, header) == 0, 232 OffsetOf_GetAttribLocation_header_not_0); 233COMPILE_ASSERT(offsetof(GetAttribLocation, program) == 4, 234 OffsetOf_GetAttribLocation_program_not_4); 235COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_id) == 8, 236 OffsetOf_GetAttribLocation_name_shm_id_not_8); 237COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_offset) == 12, 238 OffsetOf_GetAttribLocation_name_shm_offset_not_12); 239COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_id) == 16, 240 OffsetOf_GetAttribLocation_location_shm_id_not_16); 241COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_offset) == 20, 242 OffsetOf_GetAttribLocation_location_shm_offset_not_20); 243COMPILE_ASSERT(offsetof(GetAttribLocation, data_size) == 24, 244 OffsetOf_GetAttribLocation_data_size_not_24); 245 246struct GetAttribLocationImmediate { 247 typedef GetAttribLocationImmediate ValueType; 248 static const CommandId kCmdId = kGetAttribLocationImmediate; 249 static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; 250 251 typedef GLint Result; 252 253 static uint32 ComputeDataSize(const char* s) { 254 return base::checked_numeric_cast<uint32>(strlen(s)); 255 } 256 257 static uint32 ComputeSize(const char* s) { 258 return base::checked_numeric_cast<uint32>(sizeof(ValueType) + 259 ComputeDataSize(s)); 260 } 261 262 void SetHeader(const char* s) { 263 header.SetCmdByTotalSize<ValueType>(ComputeSize(s)); 264 } 265 266 void Init( 267 GLuint _program, const char* _name, 268 uint32 _location_shm_id, uint32 _location_shm_offset) { 269 SetHeader(_name); 270 program = _program; 271 location_shm_id = _location_shm_id; 272 location_shm_offset = _location_shm_offset; 273 data_size = ComputeDataSize(_name); 274 memcpy(ImmediateDataAddress(this), _name, data_size); 275 } 276 277 void* Set( 278 void* cmd, GLuint _program, const char* _name, 279 uint32 _location_shm_id, uint32 _location_shm_offset) { 280 uint32 total_size = ComputeSize(_name); 281 static_cast<ValueType*>( 282 cmd)->Init(_program, _name, _location_shm_id, _location_shm_offset); 283 return NextImmediateCmdAddressTotalSize<ValueType>(cmd, total_size); 284 } 285 286 CommandHeader header; 287 uint32 program; 288 uint32 location_shm_id; 289 uint32 location_shm_offset; 290 uint32 data_size; 291}; 292 293COMPILE_ASSERT(sizeof(GetAttribLocationImmediate) == 20, 294 Sizeof_GetAttribLocationImmediate_is_not_20); 295COMPILE_ASSERT(offsetof(GetAttribLocationImmediate, header) == 0, 296 OffsetOf_GetAttribLocationImmediate_header_not_0); 297COMPILE_ASSERT(offsetof(GetAttribLocationImmediate, program) == 4, 298 OffsetOf_GetAttribLocationImmediate_program_not_4); 299COMPILE_ASSERT(offsetof(GetAttribLocationImmediate, location_shm_id) == 8, 300 OffsetOf_GetAttribLocationImmediate_location_shm_id_not_8); 301COMPILE_ASSERT(offsetof(GetAttribLocationImmediate, location_shm_offset) == 12, 302 OffsetOf_GetAttribLocationImmediate_location_shm_offset_not_12); 303COMPILE_ASSERT(offsetof(GetAttribLocationImmediate, data_size) == 16, 304 OffsetOf_GetAttribLocationImmediate_data_size_not_16); 305 306 307struct GetAttribLocationBucket { 308 typedef GetAttribLocationBucket ValueType; 309 static const CommandId kCmdId = kGetAttribLocationBucket; 310 static const cmd::ArgFlags kArgFlags = cmd::kFixed; 311 312 typedef GLint Result; 313 314 static uint32 ComputeSize() { 315 return static_cast<uint32>(sizeof(ValueType)); // NOLINT 316 } 317 318 void SetHeader() { 319 header.SetCmd<ValueType>(); 320 } 321 322 void Init( 323 GLuint _program, uint32 _name_bucket_id, 324 uint32 _location_shm_id, uint32 _location_shm_offset) { 325 SetHeader(); 326 program = _program; 327 name_bucket_id = _name_bucket_id; 328 location_shm_id = _location_shm_id; 329 location_shm_offset = _location_shm_offset; 330 } 331 332 void* Set( 333 void* cmd, GLuint _program, uint32 _name_bucket_id, 334 uint32 _location_shm_id, uint32 _location_shm_offset) { 335 static_cast<ValueType*>( 336 cmd)->Init( 337 _program, _name_bucket_id, _location_shm_id, 338 _location_shm_offset); 339 return NextCmdAddress<ValueType>(cmd); 340 } 341 342 CommandHeader header; 343 uint32 program; 344 uint32 name_bucket_id; 345 uint32 location_shm_id; 346 uint32 location_shm_offset; 347}; 348 349COMPILE_ASSERT(sizeof(GetAttribLocationBucket) == 20, 350 Sizeof_GetAttribLocationBucket_is_not_24); 351COMPILE_ASSERT(offsetof(GetAttribLocationBucket, header) == 0, 352 OffsetOf_GetAttribLocationBucket_header_not_0); 353COMPILE_ASSERT(offsetof(GetAttribLocationBucket, program) == 4, 354 OffsetOf_GetAttribLocationBucket_program_not_4); 355COMPILE_ASSERT(offsetof(GetAttribLocationBucket, name_bucket_id) == 8, 356 OffsetOf_GetAttribLocationBucket_name_bucket_id_not_8); 357COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_id) == 12, 358 OffsetOf_GetAttribLocationBucket_location_shm_id_not_12); 359COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_offset) == 16, 360 OffsetOf_GetAttribLocationBucket_location_shm_offset_not_16); 361 362struct GetUniformLocation { 363 typedef GetUniformLocation ValueType; 364 static const CommandId kCmdId = kGetUniformLocation; 365 static const cmd::ArgFlags kArgFlags = cmd::kFixed; 366 367 typedef GLint Result; 368 369 static uint32 ComputeSize() { 370 return static_cast<uint32>(sizeof(ValueType)); // NOLINT 371 } 372 373 void SetHeader() { 374 header.SetCmd<ValueType>(); 375 } 376 377 void Init( 378 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset, 379 uint32 _location_shm_id, uint32 _location_shm_offset, 380 uint32 _data_size) { 381 SetHeader(); 382 program = _program; 383 name_shm_id = _name_shm_id; 384 name_shm_offset = _name_shm_offset; 385 location_shm_id = _location_shm_id; 386 location_shm_offset = _location_shm_offset; 387 data_size = _data_size; 388 } 389 390 void* Set( 391 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset, 392 uint32 _location_shm_id, uint32 _location_shm_offset, 393 uint32 _data_size) { 394 static_cast<ValueType*>( 395 cmd)->Init( 396 _program, _name_shm_id, _name_shm_offset, _location_shm_id, 397 _location_shm_offset, _data_size); 398 return NextCmdAddress<ValueType>(cmd); 399 } 400 401 CommandHeader header; 402 uint32 program; 403 uint32 name_shm_id; 404 uint32 name_shm_offset; 405 uint32 location_shm_id; 406 uint32 location_shm_offset; 407 uint32 data_size; 408}; 409 410COMPILE_ASSERT(sizeof(GetUniformLocation) == 28, 411 Sizeof_GetUniformLocation_is_not_28); 412COMPILE_ASSERT(offsetof(GetUniformLocation, header) == 0, 413 OffsetOf_GetUniformLocation_header_not_0); 414COMPILE_ASSERT(offsetof(GetUniformLocation, program) == 4, 415 OffsetOf_GetUniformLocation_program_not_4); 416COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_id) == 8, 417 OffsetOf_GetUniformLocation_name_shm_id_not_8); 418COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_offset) == 12, 419 OffsetOf_GetUniformLocation_name_shm_offset_not_12); 420COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_id) == 16, 421 OffsetOf_GetUniformLocation_location_shm_id_not_16); 422COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_offset) == 20, 423 OffsetOf_GetUniformLocation_location_shm_offset_not_20); 424COMPILE_ASSERT(offsetof(GetUniformLocation, data_size) == 24, 425 OffsetOf_GetUniformLocation_data_size_not_24); 426 427struct GetUniformLocationImmediate { 428 typedef GetUniformLocationImmediate ValueType; 429 static const CommandId kCmdId = kGetUniformLocationImmediate; 430 static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; 431 432 typedef GLint Result; 433 434 static uint32 ComputeDataSize(const char* s) { 435 return base::checked_numeric_cast<uint32>(strlen(s)); 436 } 437 438 static uint32 ComputeSize(const char* s) { 439 return base::checked_numeric_cast<uint32>(sizeof(ValueType) + 440 ComputeDataSize(s)); 441 } 442 443 void SetHeader(const char* s) { 444 header.SetCmdByTotalSize<ValueType>(ComputeSize(s)); 445 } 446 447 void Init( 448 GLuint _program, const char* _name, 449 uint32 _location_shm_id, uint32 _location_shm_offset) { 450 SetHeader(_name); 451 program = _program; 452 location_shm_id = _location_shm_id; 453 location_shm_offset = _location_shm_offset; 454 data_size = ComputeDataSize(_name); 455 memcpy(ImmediateDataAddress(this), _name, data_size); 456 } 457 458 void* Set( 459 void* cmd, GLuint _program, const char* _name, 460 uint32 _location_shm_id, uint32 _location_shm_offset) { 461 uint32 total_size = ComputeSize(_name); 462 static_cast<ValueType*>( 463 cmd)->Init(_program, _name, _location_shm_id, _location_shm_offset); 464 return NextImmediateCmdAddressTotalSize<ValueType>(cmd, total_size); 465 } 466 467 CommandHeader header; 468 uint32 program; 469 uint32 location_shm_id; 470 uint32 location_shm_offset; 471 uint32 data_size; 472}; 473 474COMPILE_ASSERT(sizeof(GetUniformLocationImmediate) == 20, 475 Sizeof_GetUniformLocationImmediate_is_not_20); 476COMPILE_ASSERT(offsetof(GetUniformLocationImmediate, header) == 0, 477 OffsetOf_GetUniformLocationImmediate_header_not_0); 478COMPILE_ASSERT(offsetof(GetUniformLocationImmediate, program) == 4, 479 OffsetOf_GetUniformLocationImmediate_program_not_4); 480COMPILE_ASSERT(offsetof(GetUniformLocationImmediate, location_shm_id) == 8, 481 OffsetOf_GetUniformLocationImmediate_location_shm_id_not_8); 482COMPILE_ASSERT( 483 offsetof(GetUniformLocationImmediate, location_shm_offset) == 12, 484 OffsetOf_GetUniformLocationImmediate_location_shm_offset_not_12); 485COMPILE_ASSERT(offsetof(GetUniformLocationImmediate, data_size) == 16, 486 OffsetOf_GetUniformLocationImmediate_data_size_not_16); 487 488struct GetUniformLocationBucket { 489 typedef GetUniformLocationBucket ValueType; 490 static const CommandId kCmdId = kGetUniformLocationBucket; 491 static const cmd::ArgFlags kArgFlags = cmd::kFixed; 492 493 typedef GLint Result; 494 495 static uint32 ComputeSize() { 496 return static_cast<uint32>(sizeof(ValueType)); // NOLINT 497 } 498 499 void SetHeader() { 500 header.SetCmd<ValueType>(); 501 } 502 503 void Init( 504 GLuint _program, uint32 _name_bucket_id, 505 uint32 _location_shm_id, uint32 _location_shm_offset) { 506 SetHeader(); 507 program = _program; 508 name_bucket_id = _name_bucket_id; 509 location_shm_id = _location_shm_id; 510 location_shm_offset = _location_shm_offset; 511 } 512 513 void* Set( 514 void* cmd, GLuint _program, uint32 _name_bucket_id, 515 uint32 _location_shm_id, uint32 _location_shm_offset) { 516 static_cast<ValueType*>( 517 cmd)->Init( 518 _program, _name_bucket_id, _location_shm_id, 519 _location_shm_offset); 520 return NextCmdAddress<ValueType>(cmd); 521 } 522 523 CommandHeader header; 524 uint32 program; 525 uint32 name_bucket_id; 526 uint32 location_shm_id; 527 uint32 location_shm_offset; 528}; 529 530COMPILE_ASSERT(sizeof(GetUniformLocationBucket) == 20, 531 Sizeof_GetUniformLocationBucket_is_not_24); 532COMPILE_ASSERT(offsetof(GetUniformLocationBucket, header) == 0, 533 OffsetOf_GetUniformLocationBucket_header_not_0); 534COMPILE_ASSERT(offsetof(GetUniformLocationBucket, program) == 4, 535 OffsetOf_GetUniformLocationBucket_program_not_4); 536COMPILE_ASSERT(offsetof(GetUniformLocationBucket, name_bucket_id) == 8, 537 OffsetOf_GetUniformLocationBucket_name_bucket_id_not_8); 538COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_id) == 12, 539 OffsetOf_GetUniformLocationBucket_location_shm_id_not_12); 540COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_offset) == 16, 541 OffsetOf_GetUniformLocationBucket_location_shm_offset_not_16); 542 543struct InsertSyncPointCHROMIUM { 544 typedef InsertSyncPointCHROMIUM ValueType; 545 static const CommandId kCmdId = kInsertSyncPointCHROMIUM; 546 static const cmd::ArgFlags kArgFlags = cmd::kFixed; 547 CommandHeader header; 548}; 549 550#pragma pack(pop) 551 552} // namespace cmd 553} // namespace gles2 554} // namespace gpu 555 556#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_ 557