1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2012 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci/** \file glthread_marshal.h 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci * Declarations of functions related to marshalling GL calls from a client 27bf215546Sopenharmony_ci * thread to a server thread. 28bf215546Sopenharmony_ci */ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#ifndef MARSHAL_H 31bf215546Sopenharmony_ci#define MARSHAL_H 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "main/glthread.h" 34bf215546Sopenharmony_ci#include "main/context.h" 35bf215546Sopenharmony_ci#include "main/macros.h" 36bf215546Sopenharmony_ci#include "marshal_generated.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_cistruct marshal_cmd_base 39bf215546Sopenharmony_ci{ 40bf215546Sopenharmony_ci /** 41bf215546Sopenharmony_ci * Type of command. See enum marshal_dispatch_cmd_id. 42bf215546Sopenharmony_ci */ 43bf215546Sopenharmony_ci uint16_t cmd_id; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci /** 46bf215546Sopenharmony_ci * Number of uint64_t elements used by the command. 47bf215546Sopenharmony_ci */ 48bf215546Sopenharmony_ci uint16_t cmd_size; 49bf215546Sopenharmony_ci}; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_citypedef uint32_t (*_mesa_unmarshal_func)(struct gl_context *ctx, const void *cmd, const uint64_t *last); 52bf215546Sopenharmony_ciextern const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD]; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_cistatic inline void * 55bf215546Sopenharmony_ci_mesa_glthread_allocate_command(struct gl_context *ctx, 56bf215546Sopenharmony_ci uint16_t cmd_id, 57bf215546Sopenharmony_ci unsigned size) 58bf215546Sopenharmony_ci{ 59bf215546Sopenharmony_ci struct glthread_state *glthread = &ctx->GLThread; 60bf215546Sopenharmony_ci const unsigned num_elements = align(size, 8) / 8; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci assert (num_elements <= MARSHAL_MAX_CMD_SIZE / 8); 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci if (unlikely(glthread->used + num_elements > MARSHAL_MAX_CMD_SIZE / 8)) 65bf215546Sopenharmony_ci _mesa_glthread_flush_batch(ctx); 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci struct glthread_batch *next = glthread->next_batch; 68bf215546Sopenharmony_ci struct marshal_cmd_base *cmd_base = 69bf215546Sopenharmony_ci (struct marshal_cmd_base *)&next->buffer[glthread->used]; 70bf215546Sopenharmony_ci glthread->used += num_elements; 71bf215546Sopenharmony_ci cmd_base->cmd_id = cmd_id; 72bf215546Sopenharmony_ci cmd_base->cmd_size = num_elements; 73bf215546Sopenharmony_ci return cmd_base; 74bf215546Sopenharmony_ci} 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_cistatic inline bool 77bf215546Sopenharmony_ci_mesa_glthread_has_no_pack_buffer(const struct gl_context *ctx) 78bf215546Sopenharmony_ci{ 79bf215546Sopenharmony_ci return ctx->GLThread.CurrentPixelPackBufferName == 0; 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_cistatic inline bool 83bf215546Sopenharmony_ci_mesa_glthread_has_no_unpack_buffer(const struct gl_context *ctx) 84bf215546Sopenharmony_ci{ 85bf215546Sopenharmony_ci return ctx->GLThread.CurrentPixelUnpackBufferName == 0; 86bf215546Sopenharmony_ci} 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci/** 89bf215546Sopenharmony_ci * Instead of conditionally handling marshaling immediate index data in draw 90bf215546Sopenharmony_ci * calls (deprecated and removed in GL core), we just disable threading. 91bf215546Sopenharmony_ci */ 92bf215546Sopenharmony_cistatic inline bool 93bf215546Sopenharmony_ci_mesa_glthread_has_non_vbo_vertices_or_indices(const struct gl_context *ctx) 94bf215546Sopenharmony_ci{ 95bf215546Sopenharmony_ci const struct glthread_state *glthread = &ctx->GLThread; 96bf215546Sopenharmony_ci struct glthread_vao *vao = glthread->CurrentVAO; 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci return ctx->API != API_OPENGL_CORE && 99bf215546Sopenharmony_ci (vao->CurrentElementBufferName == 0 || 100bf215546Sopenharmony_ci (vao->UserPointerMask & vao->BufferEnabled)); 101bf215546Sopenharmony_ci} 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_cistatic inline bool 104bf215546Sopenharmony_ci_mesa_glthread_has_non_vbo_vertices(const struct gl_context *ctx) 105bf215546Sopenharmony_ci{ 106bf215546Sopenharmony_ci const struct glthread_state *glthread = &ctx->GLThread; 107bf215546Sopenharmony_ci const struct glthread_vao *vao = glthread->CurrentVAO; 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci return ctx->API != API_OPENGL_CORE && 110bf215546Sopenharmony_ci (vao->UserPointerMask & vao->BufferEnabled); 111bf215546Sopenharmony_ci} 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_cistatic inline bool 114bf215546Sopenharmony_ci_mesa_glthread_has_non_vbo_vertices_or_indirect(const struct gl_context *ctx) 115bf215546Sopenharmony_ci{ 116bf215546Sopenharmony_ci const struct glthread_state *glthread = &ctx->GLThread; 117bf215546Sopenharmony_ci const struct glthread_vao *vao = glthread->CurrentVAO; 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci return ctx->API != API_OPENGL_CORE && 120bf215546Sopenharmony_ci (glthread->CurrentDrawIndirectBufferName == 0 || 121bf215546Sopenharmony_ci (vao->UserPointerMask & vao->BufferEnabled)); 122bf215546Sopenharmony_ci} 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_cistatic inline bool 125bf215546Sopenharmony_ci_mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_context *ctx) 126bf215546Sopenharmony_ci{ 127bf215546Sopenharmony_ci const struct glthread_state *glthread = &ctx->GLThread; 128bf215546Sopenharmony_ci struct glthread_vao *vao = glthread->CurrentVAO; 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci return ctx->API != API_OPENGL_CORE && 131bf215546Sopenharmony_ci (glthread->CurrentDrawIndirectBufferName == 0 || 132bf215546Sopenharmony_ci vao->CurrentElementBufferName == 0 || 133bf215546Sopenharmony_ci (vao->UserPointerMask & vao->BufferEnabled)); 134bf215546Sopenharmony_ci} 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_cibool 138bf215546Sopenharmony_ci_mesa_create_marshal_tables(struct gl_context *ctx); 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_cistatic inline unsigned 141bf215546Sopenharmony_ci_mesa_buffer_enum_to_count(GLenum buffer) 142bf215546Sopenharmony_ci{ 143bf215546Sopenharmony_ci switch (buffer) { 144bf215546Sopenharmony_ci case GL_COLOR: 145bf215546Sopenharmony_ci return 4; 146bf215546Sopenharmony_ci case GL_DEPTH_STENCIL: 147bf215546Sopenharmony_ci return 2; 148bf215546Sopenharmony_ci case GL_STENCIL: 149bf215546Sopenharmony_ci case GL_DEPTH: 150bf215546Sopenharmony_ci return 1; 151bf215546Sopenharmony_ci default: 152bf215546Sopenharmony_ci return 0; 153bf215546Sopenharmony_ci } 154bf215546Sopenharmony_ci} 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_cistatic inline unsigned 157bf215546Sopenharmony_ci_mesa_tex_param_enum_to_count(GLenum pname) 158bf215546Sopenharmony_ci{ 159bf215546Sopenharmony_ci switch (pname) { 160bf215546Sopenharmony_ci case GL_TEXTURE_MIN_FILTER: 161bf215546Sopenharmony_ci case GL_TEXTURE_MAG_FILTER: 162bf215546Sopenharmony_ci case GL_TEXTURE_WRAP_S: 163bf215546Sopenharmony_ci case GL_TEXTURE_WRAP_T: 164bf215546Sopenharmony_ci case GL_TEXTURE_WRAP_R: 165bf215546Sopenharmony_ci case GL_TEXTURE_BASE_LEVEL: 166bf215546Sopenharmony_ci case GL_TEXTURE_MAX_LEVEL: 167bf215546Sopenharmony_ci case GL_GENERATE_MIPMAP_SGIS: 168bf215546Sopenharmony_ci case GL_TEXTURE_COMPARE_MODE_ARB: 169bf215546Sopenharmony_ci case GL_TEXTURE_COMPARE_FUNC_ARB: 170bf215546Sopenharmony_ci case GL_DEPTH_TEXTURE_MODE_ARB: 171bf215546Sopenharmony_ci case GL_DEPTH_STENCIL_TEXTURE_MODE: 172bf215546Sopenharmony_ci case GL_TEXTURE_SRGB_DECODE_EXT: 173bf215546Sopenharmony_ci case GL_TEXTURE_REDUCTION_MODE_EXT: 174bf215546Sopenharmony_ci case GL_TEXTURE_CUBE_MAP_SEAMLESS: 175bf215546Sopenharmony_ci case GL_TEXTURE_SWIZZLE_R: 176bf215546Sopenharmony_ci case GL_TEXTURE_SWIZZLE_G: 177bf215546Sopenharmony_ci case GL_TEXTURE_SWIZZLE_B: 178bf215546Sopenharmony_ci case GL_TEXTURE_SWIZZLE_A: 179bf215546Sopenharmony_ci case GL_TEXTURE_MIN_LOD: 180bf215546Sopenharmony_ci case GL_TEXTURE_MAX_LOD: 181bf215546Sopenharmony_ci case GL_TEXTURE_PRIORITY: 182bf215546Sopenharmony_ci case GL_TEXTURE_MAX_ANISOTROPY_EXT: 183bf215546Sopenharmony_ci case GL_TEXTURE_LOD_BIAS: 184bf215546Sopenharmony_ci case GL_TEXTURE_TILING_EXT: 185bf215546Sopenharmony_ci return 1; 186bf215546Sopenharmony_ci case GL_TEXTURE_CROP_RECT_OES: 187bf215546Sopenharmony_ci case GL_TEXTURE_SWIZZLE_RGBA: 188bf215546Sopenharmony_ci case GL_TEXTURE_BORDER_COLOR: 189bf215546Sopenharmony_ci return 4; 190bf215546Sopenharmony_ci default: 191bf215546Sopenharmony_ci return 0; 192bf215546Sopenharmony_ci } 193bf215546Sopenharmony_ci} 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_cistatic inline unsigned 196bf215546Sopenharmony_ci_mesa_fog_enum_to_count(GLenum pname) 197bf215546Sopenharmony_ci{ 198bf215546Sopenharmony_ci switch (pname) { 199bf215546Sopenharmony_ci case GL_FOG_MODE: 200bf215546Sopenharmony_ci case GL_FOG_DENSITY: 201bf215546Sopenharmony_ci case GL_FOG_START: 202bf215546Sopenharmony_ci case GL_FOG_END: 203bf215546Sopenharmony_ci case GL_FOG_INDEX: 204bf215546Sopenharmony_ci case GL_FOG_COORDINATE_SOURCE_EXT: 205bf215546Sopenharmony_ci case GL_FOG_DISTANCE_MODE_NV: 206bf215546Sopenharmony_ci return 1; 207bf215546Sopenharmony_ci case GL_FOG_COLOR: 208bf215546Sopenharmony_ci return 4; 209bf215546Sopenharmony_ci default: 210bf215546Sopenharmony_ci return 0; 211bf215546Sopenharmony_ci } 212bf215546Sopenharmony_ci} 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_cistatic inline unsigned 215bf215546Sopenharmony_ci_mesa_light_enum_to_count(GLenum pname) 216bf215546Sopenharmony_ci{ 217bf215546Sopenharmony_ci switch (pname) { 218bf215546Sopenharmony_ci case GL_AMBIENT: 219bf215546Sopenharmony_ci case GL_DIFFUSE: 220bf215546Sopenharmony_ci case GL_SPECULAR: 221bf215546Sopenharmony_ci case GL_POSITION: 222bf215546Sopenharmony_ci return 4; 223bf215546Sopenharmony_ci case GL_SPOT_DIRECTION: 224bf215546Sopenharmony_ci return 3; 225bf215546Sopenharmony_ci case GL_SPOT_EXPONENT: 226bf215546Sopenharmony_ci case GL_SPOT_CUTOFF: 227bf215546Sopenharmony_ci case GL_CONSTANT_ATTENUATION: 228bf215546Sopenharmony_ci case GL_LINEAR_ATTENUATION: 229bf215546Sopenharmony_ci case GL_QUADRATIC_ATTENUATION: 230bf215546Sopenharmony_ci return 1; 231bf215546Sopenharmony_ci default: 232bf215546Sopenharmony_ci return 0; 233bf215546Sopenharmony_ci } 234bf215546Sopenharmony_ci} 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cistatic inline unsigned 237bf215546Sopenharmony_ci_mesa_light_model_enum_to_count(GLenum pname) 238bf215546Sopenharmony_ci{ 239bf215546Sopenharmony_ci switch (pname) { 240bf215546Sopenharmony_ci case GL_LIGHT_MODEL_AMBIENT: 241bf215546Sopenharmony_ci return 4; 242bf215546Sopenharmony_ci case GL_LIGHT_MODEL_LOCAL_VIEWER: 243bf215546Sopenharmony_ci case GL_LIGHT_MODEL_TWO_SIDE: 244bf215546Sopenharmony_ci case GL_LIGHT_MODEL_COLOR_CONTROL: 245bf215546Sopenharmony_ci return 1; 246bf215546Sopenharmony_ci default: 247bf215546Sopenharmony_ci return 0; 248bf215546Sopenharmony_ci } 249bf215546Sopenharmony_ci} 250bf215546Sopenharmony_ci 251bf215546Sopenharmony_cistatic inline unsigned 252bf215546Sopenharmony_ci_mesa_texenv_enum_to_count(GLenum pname) 253bf215546Sopenharmony_ci{ 254bf215546Sopenharmony_ci switch (pname) { 255bf215546Sopenharmony_ci case GL_TEXTURE_ENV_MODE: 256bf215546Sopenharmony_ci case GL_COMBINE_RGB: 257bf215546Sopenharmony_ci case GL_COMBINE_ALPHA: 258bf215546Sopenharmony_ci case GL_SOURCE0_RGB: 259bf215546Sopenharmony_ci case GL_SOURCE1_RGB: 260bf215546Sopenharmony_ci case GL_SOURCE2_RGB: 261bf215546Sopenharmony_ci case GL_SOURCE3_RGB_NV: 262bf215546Sopenharmony_ci case GL_SOURCE0_ALPHA: 263bf215546Sopenharmony_ci case GL_SOURCE1_ALPHA: 264bf215546Sopenharmony_ci case GL_SOURCE2_ALPHA: 265bf215546Sopenharmony_ci case GL_SOURCE3_ALPHA_NV: 266bf215546Sopenharmony_ci case GL_OPERAND0_RGB: 267bf215546Sopenharmony_ci case GL_OPERAND1_RGB: 268bf215546Sopenharmony_ci case GL_OPERAND2_RGB: 269bf215546Sopenharmony_ci case GL_OPERAND3_RGB_NV: 270bf215546Sopenharmony_ci case GL_OPERAND0_ALPHA: 271bf215546Sopenharmony_ci case GL_OPERAND1_ALPHA: 272bf215546Sopenharmony_ci case GL_OPERAND2_ALPHA: 273bf215546Sopenharmony_ci case GL_OPERAND3_ALPHA_NV: 274bf215546Sopenharmony_ci case GL_RGB_SCALE: 275bf215546Sopenharmony_ci case GL_ALPHA_SCALE: 276bf215546Sopenharmony_ci case GL_TEXTURE_LOD_BIAS_EXT: 277bf215546Sopenharmony_ci case GL_COORD_REPLACE: 278bf215546Sopenharmony_ci return 1; 279bf215546Sopenharmony_ci case GL_TEXTURE_ENV_COLOR: 280bf215546Sopenharmony_ci return 4; 281bf215546Sopenharmony_ci default: 282bf215546Sopenharmony_ci return 0; 283bf215546Sopenharmony_ci } 284bf215546Sopenharmony_ci} 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_cistatic inline unsigned 287bf215546Sopenharmony_ci_mesa_texgen_enum_to_count(GLenum pname) 288bf215546Sopenharmony_ci{ 289bf215546Sopenharmony_ci switch (pname) { 290bf215546Sopenharmony_ci case GL_TEXTURE_GEN_MODE: 291bf215546Sopenharmony_ci return 1; 292bf215546Sopenharmony_ci case GL_OBJECT_PLANE: 293bf215546Sopenharmony_ci case GL_EYE_PLANE: 294bf215546Sopenharmony_ci return 4; 295bf215546Sopenharmony_ci default: 296bf215546Sopenharmony_ci return 0; 297bf215546Sopenharmony_ci } 298bf215546Sopenharmony_ci} 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_cistatic inline unsigned 301bf215546Sopenharmony_ci_mesa_material_enum_to_count(GLenum pname) 302bf215546Sopenharmony_ci{ 303bf215546Sopenharmony_ci switch (pname) { 304bf215546Sopenharmony_ci case GL_EMISSION: 305bf215546Sopenharmony_ci case GL_AMBIENT: 306bf215546Sopenharmony_ci case GL_DIFFUSE: 307bf215546Sopenharmony_ci case GL_SPECULAR: 308bf215546Sopenharmony_ci case GL_AMBIENT_AND_DIFFUSE: 309bf215546Sopenharmony_ci return 4; 310bf215546Sopenharmony_ci case GL_COLOR_INDEXES: 311bf215546Sopenharmony_ci return 3; 312bf215546Sopenharmony_ci case GL_SHININESS: 313bf215546Sopenharmony_ci return 1; 314bf215546Sopenharmony_ci default: 315bf215546Sopenharmony_ci return 0; 316bf215546Sopenharmony_ci } 317bf215546Sopenharmony_ci} 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_cistatic inline unsigned 320bf215546Sopenharmony_ci_mesa_point_param_enum_to_count(GLenum pname) 321bf215546Sopenharmony_ci{ 322bf215546Sopenharmony_ci switch (pname) { 323bf215546Sopenharmony_ci case GL_DISTANCE_ATTENUATION_EXT: 324bf215546Sopenharmony_ci return 3; 325bf215546Sopenharmony_ci case GL_POINT_SIZE_MIN_EXT: 326bf215546Sopenharmony_ci case GL_POINT_SIZE_MAX_EXT: 327bf215546Sopenharmony_ci case GL_POINT_FADE_THRESHOLD_SIZE_EXT: 328bf215546Sopenharmony_ci case GL_POINT_SPRITE_COORD_ORIGIN: 329bf215546Sopenharmony_ci return 1; 330bf215546Sopenharmony_ci default: 331bf215546Sopenharmony_ci return 0; 332bf215546Sopenharmony_ci } 333bf215546Sopenharmony_ci} 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_cistatic inline unsigned 336bf215546Sopenharmony_ci_mesa_calllists_enum_to_count(GLenum type) 337bf215546Sopenharmony_ci{ 338bf215546Sopenharmony_ci switch (type) { 339bf215546Sopenharmony_ci case GL_BYTE: 340bf215546Sopenharmony_ci case GL_UNSIGNED_BYTE: 341bf215546Sopenharmony_ci return 1; 342bf215546Sopenharmony_ci case GL_SHORT: 343bf215546Sopenharmony_ci case GL_UNSIGNED_SHORT: 344bf215546Sopenharmony_ci case GL_2_BYTES: 345bf215546Sopenharmony_ci return 2; 346bf215546Sopenharmony_ci case GL_3_BYTES: 347bf215546Sopenharmony_ci return 3; 348bf215546Sopenharmony_ci case GL_INT: 349bf215546Sopenharmony_ci case GL_UNSIGNED_INT: 350bf215546Sopenharmony_ci case GL_FLOAT: 351bf215546Sopenharmony_ci case GL_4_BYTES: 352bf215546Sopenharmony_ci return 4; 353bf215546Sopenharmony_ci default: 354bf215546Sopenharmony_ci return 0; 355bf215546Sopenharmony_ci } 356bf215546Sopenharmony_ci} 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_cistatic inline unsigned 359bf215546Sopenharmony_ci_mesa_patch_param_enum_to_count(GLenum pname) 360bf215546Sopenharmony_ci{ 361bf215546Sopenharmony_ci switch (pname) { 362bf215546Sopenharmony_ci case GL_PATCH_DEFAULT_OUTER_LEVEL: 363bf215546Sopenharmony_ci return 4; 364bf215546Sopenharmony_ci case GL_PATCH_DEFAULT_INNER_LEVEL: 365bf215546Sopenharmony_ci return 2; 366bf215546Sopenharmony_ci default: 367bf215546Sopenharmony_ci return 0; 368bf215546Sopenharmony_ci } 369bf215546Sopenharmony_ci} 370bf215546Sopenharmony_ci 371bf215546Sopenharmony_cistatic inline unsigned 372bf215546Sopenharmony_ci_mesa_memobj_enum_to_count(GLenum pname) 373bf215546Sopenharmony_ci{ 374bf215546Sopenharmony_ci switch (pname) { 375bf215546Sopenharmony_ci case GL_DEDICATED_MEMORY_OBJECT_EXT: 376bf215546Sopenharmony_ci return 1; 377bf215546Sopenharmony_ci default: 378bf215546Sopenharmony_ci return 0; 379bf215546Sopenharmony_ci } 380bf215546Sopenharmony_ci} 381bf215546Sopenharmony_ci 382bf215546Sopenharmony_cistatic inline unsigned 383bf215546Sopenharmony_ci_mesa_semaphore_enum_to_count(GLenum pname) 384bf215546Sopenharmony_ci{ 385bf215546Sopenharmony_ci switch (pname) { 386bf215546Sopenharmony_ci /* EXT_semaphore and EXT_semaphore_fd define no parameters */ 387bf215546Sopenharmony_ci default: 388bf215546Sopenharmony_ci return 0; 389bf215546Sopenharmony_ci } 390bf215546Sopenharmony_ci} 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_cistatic inline gl_vert_attrib 393bf215546Sopenharmony_ci_mesa_array_to_attrib(struct gl_context *ctx, GLenum array) 394bf215546Sopenharmony_ci{ 395bf215546Sopenharmony_ci switch (array) { 396bf215546Sopenharmony_ci case GL_VERTEX_ARRAY: 397bf215546Sopenharmony_ci return VERT_ATTRIB_POS; 398bf215546Sopenharmony_ci case GL_NORMAL_ARRAY: 399bf215546Sopenharmony_ci return VERT_ATTRIB_NORMAL; 400bf215546Sopenharmony_ci case GL_COLOR_ARRAY: 401bf215546Sopenharmony_ci return VERT_ATTRIB_COLOR0; 402bf215546Sopenharmony_ci case GL_INDEX_ARRAY: 403bf215546Sopenharmony_ci return VERT_ATTRIB_COLOR_INDEX; 404bf215546Sopenharmony_ci case GL_TEXTURE_COORD_ARRAY: 405bf215546Sopenharmony_ci return VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture); 406bf215546Sopenharmony_ci case GL_EDGE_FLAG_ARRAY: 407bf215546Sopenharmony_ci return VERT_ATTRIB_EDGEFLAG; 408bf215546Sopenharmony_ci case GL_FOG_COORDINATE_ARRAY: 409bf215546Sopenharmony_ci return VERT_ATTRIB_FOG; 410bf215546Sopenharmony_ci case GL_SECONDARY_COLOR_ARRAY: 411bf215546Sopenharmony_ci return VERT_ATTRIB_COLOR1; 412bf215546Sopenharmony_ci case GL_POINT_SIZE_ARRAY_OES: 413bf215546Sopenharmony_ci return VERT_ATTRIB_POINT_SIZE; 414bf215546Sopenharmony_ci case GL_PRIMITIVE_RESTART_NV: 415bf215546Sopenharmony_ci return VERT_ATTRIB_PRIMITIVE_RESTART_NV; 416bf215546Sopenharmony_ci default: 417bf215546Sopenharmony_ci if (array >= GL_TEXTURE0 && array <= GL_TEXTURE7) 418bf215546Sopenharmony_ci return VERT_ATTRIB_TEX(array - GL_TEXTURE0); 419bf215546Sopenharmony_ci return VERT_ATTRIB_MAX; 420bf215546Sopenharmony_ci } 421bf215546Sopenharmony_ci} 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_cistatic inline gl_matrix_index 424bf215546Sopenharmony_ci_mesa_get_matrix_index(struct gl_context *ctx, GLenum mode) 425bf215546Sopenharmony_ci{ 426bf215546Sopenharmony_ci if (mode == GL_MODELVIEW || mode == GL_PROJECTION) 427bf215546Sopenharmony_ci return M_MODELVIEW + (mode - GL_MODELVIEW); 428bf215546Sopenharmony_ci 429bf215546Sopenharmony_ci if (mode == GL_TEXTURE) 430bf215546Sopenharmony_ci return M_TEXTURE0 + ctx->GLThread.ActiveTexture; 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_ci if (mode >= GL_TEXTURE0 && mode <= GL_TEXTURE0 + MAX_TEXTURE_UNITS - 1) 433bf215546Sopenharmony_ci return M_TEXTURE0 + (mode - GL_TEXTURE0); 434bf215546Sopenharmony_ci 435bf215546Sopenharmony_ci if (mode >= GL_MATRIX0_ARB && mode <= GL_MATRIX0_ARB + MAX_PROGRAM_MATRICES - 1) 436bf215546Sopenharmony_ci return M_PROGRAM0 + (mode - GL_MATRIX0_ARB); 437bf215546Sopenharmony_ci 438bf215546Sopenharmony_ci return M_DUMMY; 439bf215546Sopenharmony_ci} 440bf215546Sopenharmony_ci 441bf215546Sopenharmony_cistatic inline void 442bf215546Sopenharmony_ci_mesa_glthread_Enable(struct gl_context *ctx, GLenum cap) 443bf215546Sopenharmony_ci{ 444bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 445bf215546Sopenharmony_ci return; 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci switch (cap) { 448bf215546Sopenharmony_ci case GL_PRIMITIVE_RESTART: 449bf215546Sopenharmony_ci case GL_PRIMITIVE_RESTART_FIXED_INDEX: 450bf215546Sopenharmony_ci _mesa_glthread_set_prim_restart(ctx, cap, true); 451bf215546Sopenharmony_ci break; 452bf215546Sopenharmony_ci case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: 453bf215546Sopenharmony_ci _mesa_glthread_destroy(ctx, "Enable(DEBUG_OUTPUT_SYNCHRONOUS)"); 454bf215546Sopenharmony_ci break; 455bf215546Sopenharmony_ci case GL_DEPTH_TEST: 456bf215546Sopenharmony_ci ctx->GLThread.DepthTest = true; 457bf215546Sopenharmony_ci break; 458bf215546Sopenharmony_ci case GL_CULL_FACE: 459bf215546Sopenharmony_ci ctx->GLThread.CullFace = true; 460bf215546Sopenharmony_ci break; 461bf215546Sopenharmony_ci } 462bf215546Sopenharmony_ci} 463bf215546Sopenharmony_ci 464bf215546Sopenharmony_cistatic inline void 465bf215546Sopenharmony_ci_mesa_glthread_Disable(struct gl_context *ctx, GLenum cap) 466bf215546Sopenharmony_ci{ 467bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 468bf215546Sopenharmony_ci return; 469bf215546Sopenharmony_ci 470bf215546Sopenharmony_ci switch (cap) { 471bf215546Sopenharmony_ci case GL_PRIMITIVE_RESTART: 472bf215546Sopenharmony_ci case GL_PRIMITIVE_RESTART_FIXED_INDEX: 473bf215546Sopenharmony_ci _mesa_glthread_set_prim_restart(ctx, cap, false); 474bf215546Sopenharmony_ci break; 475bf215546Sopenharmony_ci case GL_CULL_FACE: 476bf215546Sopenharmony_ci ctx->GLThread.CullFace = false; 477bf215546Sopenharmony_ci break; 478bf215546Sopenharmony_ci case GL_DEPTH_TEST: 479bf215546Sopenharmony_ci ctx->GLThread.DepthTest = false; 480bf215546Sopenharmony_ci break; 481bf215546Sopenharmony_ci } 482bf215546Sopenharmony_ci} 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_cistatic inline int 485bf215546Sopenharmony_ci_mesa_glthread_IsEnabled(struct gl_context *ctx, GLenum cap) 486bf215546Sopenharmony_ci{ 487bf215546Sopenharmony_ci switch (cap) { 488bf215546Sopenharmony_ci case GL_CULL_FACE: 489bf215546Sopenharmony_ci return ctx->GLThread.CullFace; 490bf215546Sopenharmony_ci case GL_DEPTH_TEST: 491bf215546Sopenharmony_ci return ctx->GLThread.DepthTest; 492bf215546Sopenharmony_ci case GL_VERTEX_ARRAY: 493bf215546Sopenharmony_ci return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_POS); 494bf215546Sopenharmony_ci case GL_NORMAL_ARRAY: 495bf215546Sopenharmony_ci return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_NORMAL); 496bf215546Sopenharmony_ci case GL_COLOR_ARRAY: 497bf215546Sopenharmony_ci return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_COLOR0); 498bf215546Sopenharmony_ci case GL_TEXTURE_COORD_ARRAY: 499bf215546Sopenharmony_ci return !!(ctx->GLThread.CurrentVAO->UserEnabled & 500bf215546Sopenharmony_ci (1 << VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture))); 501bf215546Sopenharmony_ci default: 502bf215546Sopenharmony_ci return -1; /* sync and call _mesa_IsEnabled. */ 503bf215546Sopenharmony_ci } 504bf215546Sopenharmony_ci} 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_cistatic inline void 507bf215546Sopenharmony_ci_mesa_glthread_PushAttrib(struct gl_context *ctx, GLbitfield mask) 508bf215546Sopenharmony_ci{ 509bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 510bf215546Sopenharmony_ci return; 511bf215546Sopenharmony_ci 512bf215546Sopenharmony_ci if (ctx->GLThread.AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) 513bf215546Sopenharmony_ci return; 514bf215546Sopenharmony_ci 515bf215546Sopenharmony_ci struct glthread_attrib_node *attr = 516bf215546Sopenharmony_ci &ctx->GLThread.AttribStack[ctx->GLThread.AttribStackDepth++]; 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_ci attr->Mask = mask; 519bf215546Sopenharmony_ci 520bf215546Sopenharmony_ci if (mask & (GL_POLYGON_BIT | GL_ENABLE_BIT)) 521bf215546Sopenharmony_ci attr->CullFace = ctx->GLThread.CullFace; 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_ci if (mask & (GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT)) 524bf215546Sopenharmony_ci attr->DepthTest = ctx->GLThread.DepthTest; 525bf215546Sopenharmony_ci 526bf215546Sopenharmony_ci if (mask & GL_TEXTURE_BIT) 527bf215546Sopenharmony_ci attr->ActiveTexture = ctx->GLThread.ActiveTexture; 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_ci if (mask & GL_TRANSFORM_BIT) 530bf215546Sopenharmony_ci attr->MatrixMode = ctx->GLThread.MatrixMode; 531bf215546Sopenharmony_ci} 532bf215546Sopenharmony_ci 533bf215546Sopenharmony_cistatic inline void 534bf215546Sopenharmony_ci_mesa_glthread_PopAttrib(struct gl_context *ctx) 535bf215546Sopenharmony_ci{ 536bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 537bf215546Sopenharmony_ci return; 538bf215546Sopenharmony_ci 539bf215546Sopenharmony_ci if (ctx->GLThread.AttribStackDepth == 0) 540bf215546Sopenharmony_ci return; 541bf215546Sopenharmony_ci 542bf215546Sopenharmony_ci struct glthread_attrib_node *attr = 543bf215546Sopenharmony_ci &ctx->GLThread.AttribStack[--ctx->GLThread.AttribStackDepth]; 544bf215546Sopenharmony_ci unsigned mask = attr->Mask; 545bf215546Sopenharmony_ci 546bf215546Sopenharmony_ci if (mask & (GL_POLYGON_BIT | GL_ENABLE_BIT)) 547bf215546Sopenharmony_ci ctx->GLThread.CullFace = attr->CullFace; 548bf215546Sopenharmony_ci 549bf215546Sopenharmony_ci if (mask & (GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT)) 550bf215546Sopenharmony_ci ctx->GLThread.DepthTest = attr->DepthTest; 551bf215546Sopenharmony_ci 552bf215546Sopenharmony_ci if (mask & GL_TEXTURE_BIT) 553bf215546Sopenharmony_ci ctx->GLThread.ActiveTexture = attr->ActiveTexture; 554bf215546Sopenharmony_ci 555bf215546Sopenharmony_ci if (mask & GL_TRANSFORM_BIT) { 556bf215546Sopenharmony_ci ctx->GLThread.MatrixMode = attr->MatrixMode; 557bf215546Sopenharmony_ci ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, attr->MatrixMode); 558bf215546Sopenharmony_ci } 559bf215546Sopenharmony_ci} 560bf215546Sopenharmony_ci 561bf215546Sopenharmony_cistatic bool 562bf215546Sopenharmony_ciis_matrix_stack_full(struct gl_context *ctx, gl_matrix_index idx) 563bf215546Sopenharmony_ci{ 564bf215546Sopenharmony_ci int max_stack_depth = 0; 565bf215546Sopenharmony_ci if (M_MODELVIEW == ctx->GLThread.MatrixIndex) { 566bf215546Sopenharmony_ci max_stack_depth = MAX_MODELVIEW_STACK_DEPTH; 567bf215546Sopenharmony_ci } else if (M_PROJECTION == ctx->GLThread.MatrixIndex) { 568bf215546Sopenharmony_ci max_stack_depth = MAX_PROJECTION_STACK_DEPTH; 569bf215546Sopenharmony_ci } else if (M_PROGRAM_LAST >= ctx->GLThread.MatrixIndex) { 570bf215546Sopenharmony_ci max_stack_depth = MAX_PROGRAM_MATRIX_STACK_DEPTH; 571bf215546Sopenharmony_ci } else if (M_TEXTURE_LAST >= ctx->GLThread.MatrixIndex) { 572bf215546Sopenharmony_ci max_stack_depth = MAX_TEXTURE_STACK_DEPTH; 573bf215546Sopenharmony_ci } 574bf215546Sopenharmony_ci assert(max_stack_depth); 575bf215546Sopenharmony_ci 576bf215546Sopenharmony_ci if (ctx->GLThread.MatrixStackDepth[idx] + 1 >= max_stack_depth) 577bf215546Sopenharmony_ci return true; 578bf215546Sopenharmony_ci 579bf215546Sopenharmony_ci return false; 580bf215546Sopenharmony_ci} 581bf215546Sopenharmony_ci 582bf215546Sopenharmony_cistatic inline void 583bf215546Sopenharmony_ci_mesa_glthread_MatrixPushEXT(struct gl_context *ctx, GLenum matrixMode) 584bf215546Sopenharmony_ci{ 585bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 586bf215546Sopenharmony_ci return; 587bf215546Sopenharmony_ci 588bf215546Sopenharmony_ci if (is_matrix_stack_full(ctx, _mesa_get_matrix_index(ctx, matrixMode))) 589bf215546Sopenharmony_ci return; 590bf215546Sopenharmony_ci 591bf215546Sopenharmony_ci ctx->GLThread.MatrixStackDepth[_mesa_get_matrix_index(ctx, matrixMode)]++; 592bf215546Sopenharmony_ci} 593bf215546Sopenharmony_ci 594bf215546Sopenharmony_cistatic inline void 595bf215546Sopenharmony_ci_mesa_glthread_MatrixPopEXT(struct gl_context *ctx, GLenum matrixMode) 596bf215546Sopenharmony_ci{ 597bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 598bf215546Sopenharmony_ci return; 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_ci if (ctx->GLThread.MatrixStackDepth[_mesa_get_matrix_index(ctx, matrixMode)] == 0) 601bf215546Sopenharmony_ci return; 602bf215546Sopenharmony_ci 603bf215546Sopenharmony_ci ctx->GLThread.MatrixStackDepth[_mesa_get_matrix_index(ctx, matrixMode)]--; 604bf215546Sopenharmony_ci} 605bf215546Sopenharmony_ci 606bf215546Sopenharmony_cistatic inline void 607bf215546Sopenharmony_ci_mesa_glthread_ActiveTexture(struct gl_context *ctx, GLenum texture) 608bf215546Sopenharmony_ci{ 609bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 610bf215546Sopenharmony_ci return; 611bf215546Sopenharmony_ci 612bf215546Sopenharmony_ci ctx->GLThread.ActiveTexture = texture - GL_TEXTURE0; 613bf215546Sopenharmony_ci if (ctx->GLThread.MatrixMode == GL_TEXTURE) 614bf215546Sopenharmony_ci ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, texture); 615bf215546Sopenharmony_ci} 616bf215546Sopenharmony_ci 617bf215546Sopenharmony_cistatic inline void 618bf215546Sopenharmony_ci_mesa_glthread_PushMatrix(struct gl_context *ctx) 619bf215546Sopenharmony_ci{ 620bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 621bf215546Sopenharmony_ci return; 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci if (is_matrix_stack_full(ctx, ctx->GLThread.MatrixIndex)) 624bf215546Sopenharmony_ci return; 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_ci ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex]++; 627bf215546Sopenharmony_ci} 628bf215546Sopenharmony_ci 629bf215546Sopenharmony_cistatic inline void 630bf215546Sopenharmony_ci_mesa_glthread_PopMatrix(struct gl_context *ctx) 631bf215546Sopenharmony_ci{ 632bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 633bf215546Sopenharmony_ci return; 634bf215546Sopenharmony_ci 635bf215546Sopenharmony_ci if (ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex] == 0) 636bf215546Sopenharmony_ci return; 637bf215546Sopenharmony_ci 638bf215546Sopenharmony_ci ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex]--; 639bf215546Sopenharmony_ci} 640bf215546Sopenharmony_ci 641bf215546Sopenharmony_cistatic inline void 642bf215546Sopenharmony_ci_mesa_glthread_MatrixMode(struct gl_context *ctx, GLenum mode) 643bf215546Sopenharmony_ci{ 644bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 645bf215546Sopenharmony_ci return; 646bf215546Sopenharmony_ci 647bf215546Sopenharmony_ci ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, mode); 648bf215546Sopenharmony_ci ctx->GLThread.MatrixMode = mode; 649bf215546Sopenharmony_ci} 650bf215546Sopenharmony_ci 651bf215546Sopenharmony_cistatic inline void 652bf215546Sopenharmony_ci_mesa_glthread_ListBase(struct gl_context *ctx, GLuint base) 653bf215546Sopenharmony_ci{ 654bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 655bf215546Sopenharmony_ci return; 656bf215546Sopenharmony_ci 657bf215546Sopenharmony_ci ctx->GLThread.ListBase = base; 658bf215546Sopenharmony_ci} 659bf215546Sopenharmony_ci 660bf215546Sopenharmony_cistatic inline void 661bf215546Sopenharmony_ci_mesa_glthread_CallList(struct gl_context *ctx, GLuint list) 662bf215546Sopenharmony_ci{ 663bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 664bf215546Sopenharmony_ci return; 665bf215546Sopenharmony_ci 666bf215546Sopenharmony_ci /* Wait for all glEndList and glDeleteLists calls to finish to ensure that 667bf215546Sopenharmony_ci * all display lists are up to date and the driver thread is not 668bf215546Sopenharmony_ci * modifiying them. We will be executing them in the application thread. 669bf215546Sopenharmony_ci */ 670bf215546Sopenharmony_ci int batch = p_atomic_read(&ctx->GLThread.LastDListChangeBatchIndex); 671bf215546Sopenharmony_ci if (batch != -1) { 672bf215546Sopenharmony_ci util_queue_fence_wait(&ctx->GLThread.batches[batch].fence); 673bf215546Sopenharmony_ci p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, -1); 674bf215546Sopenharmony_ci } 675bf215546Sopenharmony_ci 676bf215546Sopenharmony_ci if (!ctx->Shared->DisplayListsAffectGLThread) 677bf215546Sopenharmony_ci return; 678bf215546Sopenharmony_ci 679bf215546Sopenharmony_ci /* Clear GL_COMPILE_AND_EXECUTE if needed. We only execute here. */ 680bf215546Sopenharmony_ci unsigned saved_mode = ctx->GLThread.ListMode; 681bf215546Sopenharmony_ci ctx->GLThread.ListMode = 0; 682bf215546Sopenharmony_ci 683bf215546Sopenharmony_ci _mesa_glthread_execute_list(ctx, list); 684bf215546Sopenharmony_ci 685bf215546Sopenharmony_ci ctx->GLThread.ListMode = saved_mode; 686bf215546Sopenharmony_ci} 687bf215546Sopenharmony_ci 688bf215546Sopenharmony_cistatic inline void 689bf215546Sopenharmony_ci_mesa_glthread_CallLists(struct gl_context *ctx, GLsizei n, GLenum type, 690bf215546Sopenharmony_ci const GLvoid *lists) 691bf215546Sopenharmony_ci{ 692bf215546Sopenharmony_ci if (ctx->GLThread.ListMode == GL_COMPILE) 693bf215546Sopenharmony_ci return; 694bf215546Sopenharmony_ci 695bf215546Sopenharmony_ci if (n <= 0 || !lists) 696bf215546Sopenharmony_ci return; 697bf215546Sopenharmony_ci 698bf215546Sopenharmony_ci /* Wait for all glEndList and glDeleteLists calls to finish to ensure that 699bf215546Sopenharmony_ci * all display lists are up to date and the driver thread is not 700bf215546Sopenharmony_ci * modifiying them. We will be executing them in the application thread. 701bf215546Sopenharmony_ci */ 702bf215546Sopenharmony_ci int batch = p_atomic_read(&ctx->GLThread.LastDListChangeBatchIndex); 703bf215546Sopenharmony_ci if (batch != -1) { 704bf215546Sopenharmony_ci util_queue_fence_wait(&ctx->GLThread.batches[batch].fence); 705bf215546Sopenharmony_ci p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, -1); 706bf215546Sopenharmony_ci } 707bf215546Sopenharmony_ci 708bf215546Sopenharmony_ci /* Clear GL_COMPILE_AND_EXECUTE if needed. We only execute here. */ 709bf215546Sopenharmony_ci unsigned saved_mode = ctx->GLThread.ListMode; 710bf215546Sopenharmony_ci ctx->GLThread.ListMode = 0; 711bf215546Sopenharmony_ci 712bf215546Sopenharmony_ci unsigned base = ctx->GLThread.ListBase; 713bf215546Sopenharmony_ci 714bf215546Sopenharmony_ci GLbyte *bptr; 715bf215546Sopenharmony_ci GLubyte *ubptr; 716bf215546Sopenharmony_ci GLshort *sptr; 717bf215546Sopenharmony_ci GLushort *usptr; 718bf215546Sopenharmony_ci GLint *iptr; 719bf215546Sopenharmony_ci GLuint *uiptr; 720bf215546Sopenharmony_ci GLfloat *fptr; 721bf215546Sopenharmony_ci 722bf215546Sopenharmony_ci switch (type) { 723bf215546Sopenharmony_ci case GL_BYTE: 724bf215546Sopenharmony_ci bptr = (GLbyte *) lists; 725bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 726bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + bptr[i]); 727bf215546Sopenharmony_ci break; 728bf215546Sopenharmony_ci case GL_UNSIGNED_BYTE: 729bf215546Sopenharmony_ci ubptr = (GLubyte *) lists; 730bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 731bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + ubptr[i]); 732bf215546Sopenharmony_ci break; 733bf215546Sopenharmony_ci case GL_SHORT: 734bf215546Sopenharmony_ci sptr = (GLshort *) lists; 735bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 736bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + sptr[i]); 737bf215546Sopenharmony_ci break; 738bf215546Sopenharmony_ci case GL_UNSIGNED_SHORT: 739bf215546Sopenharmony_ci usptr = (GLushort *) lists; 740bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 741bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + usptr[i]); 742bf215546Sopenharmony_ci break; 743bf215546Sopenharmony_ci case GL_INT: 744bf215546Sopenharmony_ci iptr = (GLint *) lists; 745bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 746bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + iptr[i]); 747bf215546Sopenharmony_ci break; 748bf215546Sopenharmony_ci case GL_UNSIGNED_INT: 749bf215546Sopenharmony_ci uiptr = (GLuint *) lists; 750bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 751bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + uiptr[i]); 752bf215546Sopenharmony_ci break; 753bf215546Sopenharmony_ci case GL_FLOAT: 754bf215546Sopenharmony_ci fptr = (GLfloat *) lists; 755bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) 756bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + fptr[i]); 757bf215546Sopenharmony_ci break; 758bf215546Sopenharmony_ci case GL_2_BYTES: 759bf215546Sopenharmony_ci ubptr = (GLubyte *) lists; 760bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) { 761bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + 762bf215546Sopenharmony_ci (GLint)ubptr[2 * i] * 256 + 763bf215546Sopenharmony_ci (GLint)ubptr[2 * i + 1]); 764bf215546Sopenharmony_ci } 765bf215546Sopenharmony_ci break; 766bf215546Sopenharmony_ci case GL_3_BYTES: 767bf215546Sopenharmony_ci ubptr = (GLubyte *) lists; 768bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) { 769bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + 770bf215546Sopenharmony_ci (GLint)ubptr[3 * i] * 65536 + 771bf215546Sopenharmony_ci (GLint)ubptr[3 * i + 1] * 256 + 772bf215546Sopenharmony_ci (GLint)ubptr[3 * i + 2]); 773bf215546Sopenharmony_ci } 774bf215546Sopenharmony_ci break; 775bf215546Sopenharmony_ci case GL_4_BYTES: 776bf215546Sopenharmony_ci ubptr = (GLubyte *) lists; 777bf215546Sopenharmony_ci for (unsigned i = 0; i < n; i++) { 778bf215546Sopenharmony_ci _mesa_glthread_CallList(ctx, base + 779bf215546Sopenharmony_ci (GLint)ubptr[4 * i] * 16777216 + 780bf215546Sopenharmony_ci (GLint)ubptr[4 * i + 1] * 65536 + 781bf215546Sopenharmony_ci (GLint)ubptr[4 * i + 2] * 256 + 782bf215546Sopenharmony_ci (GLint)ubptr[4 * i + 3]); 783bf215546Sopenharmony_ci } 784bf215546Sopenharmony_ci break; 785bf215546Sopenharmony_ci } 786bf215546Sopenharmony_ci 787bf215546Sopenharmony_ci ctx->GLThread.ListMode = saved_mode; 788bf215546Sopenharmony_ci} 789bf215546Sopenharmony_ci 790bf215546Sopenharmony_cistatic inline void 791bf215546Sopenharmony_ci_mesa_glthread_NewList(struct gl_context *ctx, GLuint list, GLuint mode) 792bf215546Sopenharmony_ci{ 793bf215546Sopenharmony_ci if (!ctx->GLThread.ListMode) 794bf215546Sopenharmony_ci ctx->GLThread.ListMode = mode; 795bf215546Sopenharmony_ci} 796bf215546Sopenharmony_ci 797bf215546Sopenharmony_cistatic inline void 798bf215546Sopenharmony_ci_mesa_glthread_EndList(struct gl_context *ctx) 799bf215546Sopenharmony_ci{ 800bf215546Sopenharmony_ci if (!ctx->GLThread.ListMode) 801bf215546Sopenharmony_ci return; 802bf215546Sopenharmony_ci 803bf215546Sopenharmony_ci ctx->GLThread.ListMode = 0; 804bf215546Sopenharmony_ci 805bf215546Sopenharmony_ci /* Track the last display list change. */ 806bf215546Sopenharmony_ci p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, ctx->GLThread.next); 807bf215546Sopenharmony_ci _mesa_glthread_flush_batch(ctx); 808bf215546Sopenharmony_ci} 809bf215546Sopenharmony_ci 810bf215546Sopenharmony_cistatic inline void 811bf215546Sopenharmony_ci_mesa_glthread_DeleteLists(struct gl_context *ctx, GLsizei range) 812bf215546Sopenharmony_ci{ 813bf215546Sopenharmony_ci if (range < 0) 814bf215546Sopenharmony_ci return; 815bf215546Sopenharmony_ci 816bf215546Sopenharmony_ci /* Track the last display list change. */ 817bf215546Sopenharmony_ci p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, ctx->GLThread.next); 818bf215546Sopenharmony_ci _mesa_glthread_flush_batch(ctx); 819bf215546Sopenharmony_ci} 820bf215546Sopenharmony_ci 821bf215546Sopenharmony_cistatic inline void 822bf215546Sopenharmony_ci_mesa_glthread_DeleteFramebuffers(struct gl_context *ctx, GLsizei n, 823bf215546Sopenharmony_ci const GLuint *ids) 824bf215546Sopenharmony_ci{ 825bf215546Sopenharmony_ci if (ctx->GLThread.CurrentDrawFramebuffer) { 826bf215546Sopenharmony_ci for (int i = 0; i < n; i++) { 827bf215546Sopenharmony_ci if (ctx->GLThread.CurrentDrawFramebuffer == ids[i]) { 828bf215546Sopenharmony_ci ctx->GLThread.CurrentDrawFramebuffer = 0; 829bf215546Sopenharmony_ci break; 830bf215546Sopenharmony_ci } 831bf215546Sopenharmony_ci } 832bf215546Sopenharmony_ci } 833bf215546Sopenharmony_ci} 834bf215546Sopenharmony_ci 835bf215546Sopenharmony_cistruct marshal_cmd_CallList 836bf215546Sopenharmony_ci{ 837bf215546Sopenharmony_ci struct marshal_cmd_base cmd_base; 838bf215546Sopenharmony_ci GLuint list; 839bf215546Sopenharmony_ci}; 840bf215546Sopenharmony_ci 841bf215546Sopenharmony_ci#endif /* MARSHAL_H */ 842