r200_context.h revision fbe5296d1463e1052590b744f3d62ebb9e5d5dd4
1/* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */ 2/* 3Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 4 5The Weather Channel (TM) funded Tungsten Graphics to develop the 6initial release of the Radeon 8500 driver under the XFree86 license. 7This notice must be preserved. 8 9Permission is hereby granted, free of charge, to any person obtaining 10a copy of this software and associated documentation files (the 11"Software"), to deal in the Software without restriction, including 12without limitation the rights to use, copy, modify, merge, publish, 13distribute, sublicense, and/or sell copies of the Software, and to 14permit persons to whom the Software is furnished to do so, subject to 15the following conditions: 16 17The above copyright notice and this permission notice (including the 18next paragraph) shall be included in all copies or substantial 19portions of the Software. 20 21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 25LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 29**************************************************************************/ 30 31/* 32 * Authors: 33 * Keith Whitwell <keith@tungstengraphics.com> 34 */ 35 36#ifndef __R200_CONTEXT_H__ 37#define __R200_CONTEXT_H__ 38 39#include "tnl/t_vertex.h" 40#include "drm.h" 41#include "radeon_drm.h" 42#include "dri_util.h" 43#include "texmem.h" 44 45#include "macros.h" 46#include "mtypes.h" 47#include "colormac.h" 48#include "r200_reg.h" 49 50#define ENABLE_HW_3D_TEXTURE 1 /* XXX this is temporary! */ 51 52struct r200_context; 53typedef struct r200_context r200ContextRec; 54typedef struct r200_context *r200ContextPtr; 55 56#include "r200_lock.h" 57#include "r200_screen.h" 58#include "mm.h" 59 60/* Flags for software fallback cases */ 61/* See correponding strings in r200_swtcl.c */ 62#define R200_FALLBACK_TEXTURE 0x1 63#define R200_FALLBACK_DRAW_BUFFER 0x2 64#define R200_FALLBACK_STENCIL 0x4 65#define R200_FALLBACK_RENDER_MODE 0x8 66#define R200_FALLBACK_BLEND_EQ 0x10 67#define R200_FALLBACK_BLEND_FUNC 0x20 68#define R200_FALLBACK_DISABLE 0x40 69#define R200_FALLBACK_BORDER_MODE 0x80 70 71/* The blit width for texture uploads 72 */ 73#define BLIT_WIDTH_BYTES 1024 74 75/* Use the templated vertex format: 76 */ 77#define COLOR_IS_RGBA 78#define TAG(x) r200##x 79#include "tnl_dd/t_dd_vertex.h" 80#undef TAG 81 82typedef void (*r200_tri_func)( r200ContextPtr, 83 r200Vertex *, 84 r200Vertex *, 85 r200Vertex * ); 86 87typedef void (*r200_line_func)( r200ContextPtr, 88 r200Vertex *, 89 r200Vertex * ); 90 91typedef void (*r200_point_func)( r200ContextPtr, 92 r200Vertex * ); 93 94 95struct r200_colorbuffer_state { 96 GLuint clear; 97 GLint drawOffset, drawPitch; 98 int roundEnable; 99}; 100 101 102struct r200_depthbuffer_state { 103 GLuint clear; 104 GLfloat scale; 105}; 106 107struct r200_pixel_state { 108 GLint readOffset, readPitch; 109}; 110 111struct r200_scissor_state { 112 drm_clip_rect_t rect; 113 GLboolean enabled; 114 115 GLuint numClipRects; /* Cliprects active */ 116 GLuint numAllocedClipRects; /* Cliprects available */ 117 drm_clip_rect_t *pClipRects; 118}; 119 120struct r200_stencilbuffer_state { 121 GLboolean hwBuffer; 122 GLuint clear; /* rb3d_stencilrefmask value */ 123}; 124 125struct r200_stipple_state { 126 GLuint mask[32]; 127}; 128 129 130 131#define TEX_0 0x1 132#define TEX_1 0x2 133#define TEX_2 0x4 134#define TEX_3 0x8 135#define TEX_4 0x10 136#define TEX_5 0x20 137#define TEX_ALL 0x3f 138 139typedef struct r200_tex_obj r200TexObj, *r200TexObjPtr; 140 141/* Texture object in locally shared texture space. 142 */ 143struct r200_tex_obj { 144 driTextureObject base; 145 146 GLuint bufAddr; /* Offset to start of locally 147 shared texture block */ 148 149 GLuint dirty_state; /* Flags (1 per texunit) for 150 whether or not this texobj 151 has dirty hardware state 152 (pp_*) that needs to be 153 brought into the 154 texunit. */ 155 156 drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS]; 157 /* Six, for the cube faces */ 158 159 GLuint pp_txfilter; /* hardware register values */ 160 GLuint pp_txformat; 161 GLuint pp_txformat_x; 162 GLuint pp_txoffset; /* Image location in texmem. 163 All cube faces follow. */ 164 GLuint pp_txsize; /* npot only */ 165 GLuint pp_txpitch; /* npot only */ 166 GLuint pp_border_color; 167 GLuint pp_cubic_faces; /* cube face 1,2,3,4 log2 sizes */ 168 169 GLboolean border_fallback; 170 171 GLuint tile_bits; /* hw texture tile bits used on this texture */ 172}; 173 174 175struct r200_texture_env_state { 176 r200TexObjPtr texobj; 177 GLenum format; 178 GLenum envMode; 179}; 180 181#define R200_MAX_TEXTURE_UNITS 6 182 183struct r200_texture_state { 184 struct r200_texture_env_state unit[R200_MAX_TEXTURE_UNITS]; 185}; 186 187 188struct r200_state_atom { 189 struct r200_state_atom *next, *prev; 190 const char *name; /* for debug */ 191 int cmd_size; /* size in bytes */ 192 GLuint idx; 193 int *cmd; /* one or more cmd's */ 194 int *lastcmd; /* one or more cmd's */ 195 GLboolean dirty; 196 GLboolean (*check)( GLcontext *, int ); /* is this state active? */ 197}; 198 199 200 201/* Trying to keep these relatively short as the variables are becoming 202 * extravagently long. Drop the driver name prefix off the front of 203 * everything - I think we know which driver we're in by now, and keep the 204 * prefix to 3 letters unless absolutely impossible. 205 */ 206 207#define CTX_CMD_0 0 208#define CTX_PP_MISC 1 209#define CTX_PP_FOG_COLOR 2 210#define CTX_RE_SOLID_COLOR 3 211#define CTX_RB3D_BLENDCNTL 4 212#define CTX_RB3D_DEPTHOFFSET 5 213#define CTX_RB3D_DEPTHPITCH 6 214#define CTX_RB3D_ZSTENCILCNTL 7 215#define CTX_CMD_1 8 216#define CTX_PP_CNTL 9 217#define CTX_RB3D_CNTL 10 218#define CTX_RB3D_COLOROFFSET 11 219#define CTX_CMD_2 12 /* why */ 220#define CTX_RB3D_COLORPITCH 13 /* why */ 221#define CTX_STATE_SIZE_OLDDRM 14 222#define CTX_CMD_3 14 223#define CTX_RB3D_BLENDCOLOR 15 224#define CTX_RB3D_ABLENDCNTL 16 225#define CTX_RB3D_CBLENDCNTL 17 226#define CTX_STATE_SIZE_NEWDRM 18 227 228#define SET_CMD_0 0 229#define SET_SE_CNTL 1 230#define SET_RE_CNTL 2 /* replace se_coord_fmt */ 231#define SET_STATE_SIZE 3 232 233#define VTE_CMD_0 0 234#define VTE_SE_VTE_CNTL 1 235#define VTE_STATE_SIZE 2 236 237#define LIN_CMD_0 0 238#define LIN_RE_LINE_PATTERN 1 239#define LIN_RE_LINE_STATE 2 240#define LIN_CMD_1 3 241#define LIN_SE_LINE_WIDTH 4 242#define LIN_STATE_SIZE 5 243 244#define MSK_CMD_0 0 245#define MSK_RB3D_STENCILREFMASK 1 246#define MSK_RB3D_ROPCNTL 2 247#define MSK_RB3D_PLANEMASK 3 248#define MSK_STATE_SIZE 4 249 250#define VPT_CMD_0 0 251#define VPT_SE_VPORT_XSCALE 1 252#define VPT_SE_VPORT_XOFFSET 2 253#define VPT_SE_VPORT_YSCALE 3 254#define VPT_SE_VPORT_YOFFSET 4 255#define VPT_SE_VPORT_ZSCALE 5 256#define VPT_SE_VPORT_ZOFFSET 6 257#define VPT_STATE_SIZE 7 258 259#define ZBS_CMD_0 0 260#define ZBS_SE_ZBIAS_FACTOR 1 261#define ZBS_SE_ZBIAS_CONSTANT 2 262#define ZBS_STATE_SIZE 3 263 264#define MSC_CMD_0 0 265#define MSC_RE_MISC 1 266#define MSC_STATE_SIZE 2 267 268#define TAM_CMD_0 0 269#define TAM_DEBUG3 1 270#define TAM_STATE_SIZE 2 271 272#define TEX_CMD_0 0 273#define TEX_PP_TXFILTER 1 /*2c00*/ 274#define TEX_PP_TXFORMAT 2 /*2c04*/ 275#define TEX_PP_TXFORMAT_X 3 /*2c08*/ 276#define TEX_PP_TXSIZE 4 /*2c0c*/ 277#define TEX_PP_TXPITCH 5 /*2c10*/ 278#define TEX_PP_BORDER_COLOR 6 /*2c14*/ 279#define TEX_CMD_1 7 280#define TEX_PP_TXOFFSET 8 /*2d00 */ 281#define TEX_STATE_SIZE 9 282 283#define CUBE_CMD_0 0 /* 1 register follows */ 284#define CUBE_PP_CUBIC_FACES 1 /* 0x2c18 */ 285#define CUBE_CMD_1 2 /* 5 registers follow */ 286#define CUBE_PP_CUBIC_OFFSET_F1 3 /* 0x2d04 */ 287#define CUBE_PP_CUBIC_OFFSET_F2 4 /* 0x2d08 */ 288#define CUBE_PP_CUBIC_OFFSET_F3 5 /* 0x2d0c */ 289#define CUBE_PP_CUBIC_OFFSET_F4 6 /* 0x2d10 */ 290#define CUBE_PP_CUBIC_OFFSET_F5 7 /* 0x2d14 */ 291#define CUBE_STATE_SIZE 8 292 293#define PIX_CMD_0 0 294#define PIX_PP_TXCBLEND 1 295#define PIX_PP_TXCBLEND2 2 296#define PIX_PP_TXABLEND 3 297#define PIX_PP_TXABLEND2 4 298#define PIX_STATE_SIZE 5 299 300#define TF_CMD_0 0 301#define TF_TFACTOR_0 1 302#define TF_TFACTOR_1 2 303#define TF_TFACTOR_2 3 304#define TF_TFACTOR_3 4 305#define TF_TFACTOR_4 5 306#define TF_TFACTOR_5 6 307#define TF_STATE_SIZE 7 308 309#define TCL_CMD_0 0 310#define TCL_LIGHT_MODEL_CTL_0 1 311#define TCL_LIGHT_MODEL_CTL_1 2 312#define TCL_PER_LIGHT_CTL_0 3 313#define TCL_PER_LIGHT_CTL_1 4 314#define TCL_PER_LIGHT_CTL_2 5 315#define TCL_PER_LIGHT_CTL_3 6 316#define TCL_CMD_1 7 317#define TCL_UCP_VERT_BLEND_CTL 8 318#define TCL_STATE_SIZE 9 319 320#define MSL_CMD_0 0 321#define MSL_MATRIX_SELECT_0 1 322#define MSL_MATRIX_SELECT_1 2 323#define MSL_MATRIX_SELECT_2 3 324#define MSL_MATRIX_SELECT_3 4 325#define MSL_MATRIX_SELECT_4 5 326#define MSL_STATE_SIZE 6 327 328#define TCG_CMD_0 0 329#define TCG_TEX_PROC_CTL_2 1 330#define TCG_TEX_PROC_CTL_3 2 331#define TCG_TEX_PROC_CTL_0 3 332#define TCG_TEX_PROC_CTL_1 4 333#define TCG_TEX_CYL_WRAP_CTL 5 334#define TCG_STATE_SIZE 6 335 336#define MTL_CMD_0 0 337#define MTL_EMMISSIVE_RED 1 338#define MTL_EMMISSIVE_GREEN 2 339#define MTL_EMMISSIVE_BLUE 3 340#define MTL_EMMISSIVE_ALPHA 4 341#define MTL_AMBIENT_RED 5 342#define MTL_AMBIENT_GREEN 6 343#define MTL_AMBIENT_BLUE 7 344#define MTL_AMBIENT_ALPHA 8 345#define MTL_DIFFUSE_RED 9 346#define MTL_DIFFUSE_GREEN 10 347#define MTL_DIFFUSE_BLUE 11 348#define MTL_DIFFUSE_ALPHA 12 349#define MTL_SPECULAR_RED 13 350#define MTL_SPECULAR_GREEN 14 351#define MTL_SPECULAR_BLUE 15 352#define MTL_SPECULAR_ALPHA 16 353#define MTL_CMD_1 17 354#define MTL_SHININESS 18 355#define MTL_STATE_SIZE 19 356 357#define VAP_CMD_0 0 358#define VAP_SE_VAP_CNTL 1 359#define VAP_STATE_SIZE 2 360 361/* Replaces a lot of packet info from radeon 362 */ 363#define VTX_CMD_0 0 364#define VTX_VTXFMT_0 1 365#define VTX_VTXFMT_1 2 366#define VTX_TCL_OUTPUT_VTXFMT_0 3 367#define VTX_TCL_OUTPUT_VTXFMT_1 4 368#define VTX_CMD_1 5 369#define VTX_TCL_OUTPUT_COMPSEL 6 370#define VTX_CMD_2 7 371#define VTX_STATE_CNTL 8 372#define VTX_STATE_SIZE 9 373 374 375#define VTX_COLOR(v,n) (((v)>>(R200_VTX_COLOR_0_SHIFT+(n)*2))&\ 376 R200_VTX_COLOR_MASK) 377 378/** 379 * Given the \c R200_SE_VTX_FMT_1 for the current vertex state, determine 380 * how many components are in texture coordinate \c n. 381 */ 382#define VTX_TEXn_COUNT(v,n) (((v) >> (3 * n)) & 0x07) 383 384#define MAT_CMD_0 0 385#define MAT_ELT_0 1 386#define MAT_STATE_SIZE 17 387 388#define GRD_CMD_0 0 389#define GRD_VERT_GUARD_CLIP_ADJ 1 390#define GRD_VERT_GUARD_DISCARD_ADJ 2 391#define GRD_HORZ_GUARD_CLIP_ADJ 3 392#define GRD_HORZ_GUARD_DISCARD_ADJ 4 393#define GRD_STATE_SIZE 5 394 395/* position changes frequently when lighting in modelpos - separate 396 * out to new state item? 397 */ 398#define LIT_CMD_0 0 399#define LIT_AMBIENT_RED 1 400#define LIT_AMBIENT_GREEN 2 401#define LIT_AMBIENT_BLUE 3 402#define LIT_AMBIENT_ALPHA 4 403#define LIT_DIFFUSE_RED 5 404#define LIT_DIFFUSE_GREEN 6 405#define LIT_DIFFUSE_BLUE 7 406#define LIT_DIFFUSE_ALPHA 8 407#define LIT_SPECULAR_RED 9 408#define LIT_SPECULAR_GREEN 10 409#define LIT_SPECULAR_BLUE 11 410#define LIT_SPECULAR_ALPHA 12 411#define LIT_POSITION_X 13 412#define LIT_POSITION_Y 14 413#define LIT_POSITION_Z 15 414#define LIT_POSITION_W 16 415#define LIT_DIRECTION_X 17 416#define LIT_DIRECTION_Y 18 417#define LIT_DIRECTION_Z 19 418#define LIT_DIRECTION_W 20 419#define LIT_ATTEN_QUADRATIC 21 420#define LIT_ATTEN_LINEAR 22 421#define LIT_ATTEN_CONST 23 422#define LIT_ATTEN_XXX 24 423#define LIT_CMD_1 25 424#define LIT_SPOT_DCD 26 425#define LIT_SPOT_DCM 27 426#define LIT_SPOT_EXPONENT 28 427#define LIT_SPOT_CUTOFF 29 428#define LIT_SPECULAR_THRESH 30 429#define LIT_RANGE_CUTOFF 31 /* ? */ 430#define LIT_ATTEN_CONST_INV 32 431#define LIT_STATE_SIZE 33 432 433/* Fog 434 */ 435#define FOG_CMD_0 0 436#define FOG_R 1 437#define FOG_C 2 438#define FOG_D 3 439#define FOG_PAD 4 440#define FOG_STATE_SIZE 5 441 442/* UCP 443 */ 444#define UCP_CMD_0 0 445#define UCP_X 1 446#define UCP_Y 2 447#define UCP_Z 3 448#define UCP_W 4 449#define UCP_STATE_SIZE 5 450 451/* GLT - Global ambient 452 */ 453#define GLT_CMD_0 0 454#define GLT_RED 1 455#define GLT_GREEN 2 456#define GLT_BLUE 3 457#define GLT_ALPHA 4 458#define GLT_STATE_SIZE 5 459 460/* EYE 461 */ 462#define EYE_CMD_0 0 463#define EYE_X 1 464#define EYE_Y 2 465#define EYE_Z 3 466#define EYE_RESCALE_FACTOR 4 467#define EYE_STATE_SIZE 5 468 469/* CST - constant state 470 */ 471#define CST_CMD_0 0 472#define CST_PP_CNTL_X 1 473#define CST_CMD_1 2 474#define CST_RB3D_DEPTHXY_OFFSET 3 475#define CST_CMD_2 4 476#define CST_RE_AUX_SCISSOR_CNTL 5 477#define CST_CMD_3 6 478#define CST_RE_SCISSOR_TL_0 7 479#define CST_RE_SCISSOR_BR_0 8 480#define CST_CMD_4 9 481#define CST_SE_VAP_CNTL_STATUS 10 482#define CST_CMD_5 11 483#define CST_RE_POINTSIZE 12 484#define CST_CMD_6 13 485#define CST_SE_TCL_INPUT_VTX_0 14 486#define CST_SE_TCL_INPUT_VTX_1 15 487#define CST_SE_TCL_INPUT_VTX_2 16 488#define CST_SE_TCL_INPUT_VTX_3 17 489#define CST_STATE_SIZE 18 490 491#define PRF_CMD_0 0 492#define PRF_PP_TRI_PERF 1 493#define PRF_PP_PERF_CNTL 2 494#define PRF_STATE_SIZE 3 495 496 497struct r200_hw_state { 498 /* Head of the linked list of state atoms. */ 499 struct r200_state_atom atomlist; 500 501 /* Hardware state, stored as cmdbuf commands: 502 * -- Need to doublebuffer for 503 * - reviving state after loss of context 504 * - eliding noop statechange loops? (except line stipple count) 505 */ 506 struct r200_state_atom ctx; 507 struct r200_state_atom set; 508 struct r200_state_atom vte; 509 struct r200_state_atom lin; 510 struct r200_state_atom msk; 511 struct r200_state_atom vpt; 512 struct r200_state_atom vap; 513 struct r200_state_atom vtx; 514 struct r200_state_atom tcl; 515 struct r200_state_atom msl; 516 struct r200_state_atom tcg; 517 struct r200_state_atom msc; 518 struct r200_state_atom cst; 519 struct r200_state_atom tam; 520 struct r200_state_atom tf; 521 struct r200_state_atom tex[6]; 522 struct r200_state_atom cube[6]; 523 struct r200_state_atom zbs; 524 struct r200_state_atom mtl[2]; 525 struct r200_state_atom mat[9]; 526 struct r200_state_atom lit[8]; /* includes vec, scl commands */ 527 struct r200_state_atom ucp[6]; 528 struct r200_state_atom pix[6]; /* pixshader stages */ 529 struct r200_state_atom eye; /* eye pos */ 530 struct r200_state_atom grd; /* guard band clipping */ 531 struct r200_state_atom fog; 532 struct r200_state_atom glt; 533 struct r200_state_atom prf; 534 535 int max_state_size; /* Number of bytes necessary for a full state emit. */ 536 GLboolean is_dirty, all_dirty; 537}; 538 539struct r200_state { 540 /* Derived state for internal purposes: 541 */ 542 struct r200_colorbuffer_state color; 543 struct r200_depthbuffer_state depth; 544 struct r200_pixel_state pixel; 545 struct r200_scissor_state scissor; 546 struct r200_stencilbuffer_state stencil; 547 struct r200_stipple_state stipple; 548 struct r200_texture_state texture; 549}; 550 551/* Need refcounting on dma buffers: 552 */ 553struct r200_dma_buffer { 554 int refcount; /* the number of retained regions in buf */ 555 drmBufPtr buf; 556}; 557 558#define GET_START(rvb) (rmesa->r200Screen->gart_buffer_offset + \ 559 (rvb)->address - rmesa->dma.buf0_address + \ 560 (rvb)->start) 561 562/* A retained region, eg vertices for indexed vertices. 563 */ 564struct r200_dma_region { 565 struct r200_dma_buffer *buf; 566 char *address; /* == buf->address */ 567 int start, end, ptr; /* offsets from start of buf */ 568 int aos_start; 569 int aos_stride; 570 int aos_size; 571}; 572 573 574struct r200_dma { 575 /* Active dma region. Allocations for vertices and retained 576 * regions come from here. Also used for emitting random vertices, 577 * these may be flushed by calling flush_current(); 578 */ 579 struct r200_dma_region current; 580 581 void (*flush)( r200ContextPtr ); 582 583 char *buf0_address; /* start of buf[0], for index calcs */ 584 GLuint nr_released_bufs; /* flush after so many buffers released */ 585}; 586 587struct r200_dri_mirror { 588 __DRIcontextPrivate *context; /* DRI context */ 589 __DRIscreenPrivate *screen; /* DRI screen */ 590 __DRIdrawablePrivate *drawable; /* DRI drawable bound to this ctx */ 591 592 drm_context_t hwContext; 593 drm_hw_lock_t *hwLock; 594 int fd; 595 int drmMinor; 596}; 597 598 599#define R200_CMD_BUF_SZ (8*1024) 600 601struct r200_store { 602 GLuint statenr; 603 GLuint primnr; 604 char cmd_buf[R200_CMD_BUF_SZ]; 605 int cmd_used; 606 int elts_start; 607}; 608 609 610/* r200_tcl.c 611 */ 612struct r200_tcl_info { 613 GLuint vertex_format; 614 GLint last_offset; 615 GLuint hw_primitive; 616 617 struct r200_dma_region *aos_components[8]; 618 GLuint nr_aos_components; 619 620 GLuint *Elts; 621 622 struct r200_dma_region indexed_verts; 623 struct r200_dma_region obj; 624 struct r200_dma_region rgba; 625 struct r200_dma_region spec; 626 struct r200_dma_region fog; 627 struct r200_dma_region tex[R200_MAX_TEXTURE_UNITS]; 628 struct r200_dma_region norm; 629}; 630 631 632/* r200_swtcl.c 633 */ 634struct r200_swtcl_info { 635 GLuint RenderIndex; 636 637 /** 638 * Size of a hardware vertex. This is calculated when \c ::vertex_attrs is 639 * installed in the Mesa state vector. 640 */ 641 GLuint vertex_size; 642 643 /** 644 * Attributes instructing the Mesa TCL pipeline where / how to put vertex 645 * data in the hardware buffer. 646 */ 647 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; 648 649 /** 650 * Number of elements of \c ::vertex_attrs that are actually used. 651 */ 652 GLuint vertex_attr_count; 653 654 /** 655 * Cached pointer to the buffer where Mesa will store vertex data. 656 */ 657 GLubyte *verts; 658 659 /* Fallback rasterization functions 660 */ 661 r200_point_func draw_point; 662 r200_line_func draw_line; 663 r200_tri_func draw_tri; 664 665 GLuint hw_primitive; 666 GLenum render_primitive; 667 GLuint numverts; 668 669 /** 670 * Offset of the 4UB color data within a hardware (swtcl) vertex. 671 */ 672 GLuint coloroffset; 673 674 /** 675 * Offset of the 3UB specular color data within a hardware (swtcl) vertex. 676 */ 677 GLuint specoffset; 678 679 /** 680 * Should Mesa project vertex data or will the hardware do it? 681 */ 682 GLboolean needproj; 683 684 struct r200_dma_region indexed_verts; 685}; 686 687 688struct r200_ioctl { 689 GLuint vertex_offset; 690 GLuint vertex_size; 691}; 692 693 694 695#define R200_MAX_PRIMS 64 696 697 698/* Want to keep a cache of these around. Each is parameterized by 699 * only a single value which has only a small range. Only expect a 700 * few, so just rescan the list each time? 701 */ 702struct dynfn { 703 struct dynfn *next, *prev; 704 int key[2]; 705 char *code; 706}; 707 708struct dfn_lists { 709 struct dynfn Vertex2f; 710 struct dynfn Vertex2fv; 711 struct dynfn Vertex3f; 712 struct dynfn Vertex3fv; 713 struct dynfn Color4ub; 714 struct dynfn Color4ubv; 715 struct dynfn Color3ub; 716 struct dynfn Color3ubv; 717 struct dynfn Color4f; 718 struct dynfn Color4fv; 719 struct dynfn Color3f; 720 struct dynfn Color3fv; 721 struct dynfn SecondaryColor3ubEXT; 722 struct dynfn SecondaryColor3ubvEXT; 723 struct dynfn SecondaryColor3fEXT; 724 struct dynfn SecondaryColor3fvEXT; 725 struct dynfn Normal3f; 726 struct dynfn Normal3fv; 727 struct dynfn TexCoord3f; 728 struct dynfn TexCoord3fv; 729 struct dynfn TexCoord2f; 730 struct dynfn TexCoord2fv; 731 struct dynfn TexCoord1f; 732 struct dynfn TexCoord1fv; 733 struct dynfn MultiTexCoord3fARB; 734 struct dynfn MultiTexCoord3fvARB; 735 struct dynfn MultiTexCoord2fARB; 736 struct dynfn MultiTexCoord2fvARB; 737 struct dynfn MultiTexCoord1fARB; 738 struct dynfn MultiTexCoord1fvARB; 739 struct dynfn FogCoordfEXT; 740 struct dynfn FogCoordfvEXT; 741}; 742 743struct dfn_generators { 744 struct dynfn *(*Vertex2f)( GLcontext *, const int * ); 745 struct dynfn *(*Vertex2fv)( GLcontext *, const int * ); 746 struct dynfn *(*Vertex3f)( GLcontext *, const int * ); 747 struct dynfn *(*Vertex3fv)( GLcontext *, const int * ); 748 struct dynfn *(*Color4ub)( GLcontext *, const int * ); 749 struct dynfn *(*Color4ubv)( GLcontext *, const int * ); 750 struct dynfn *(*Color3ub)( GLcontext *, const int * ); 751 struct dynfn *(*Color3ubv)( GLcontext *, const int * ); 752 struct dynfn *(*Color4f)( GLcontext *, const int * ); 753 struct dynfn *(*Color4fv)( GLcontext *, const int * ); 754 struct dynfn *(*Color3f)( GLcontext *, const int * ); 755 struct dynfn *(*Color3fv)( GLcontext *, const int * ); 756 struct dynfn *(*SecondaryColor3ubEXT)( GLcontext *, const int * ); 757 struct dynfn *(*SecondaryColor3ubvEXT)( GLcontext *, const int * ); 758 struct dynfn *(*SecondaryColor3fEXT)( GLcontext *, const int * ); 759 struct dynfn *(*SecondaryColor3fvEXT)( GLcontext *, const int * ); 760 struct dynfn *(*Normal3f)( GLcontext *, const int * ); 761 struct dynfn *(*Normal3fv)( GLcontext *, const int * ); 762 struct dynfn *(*TexCoord3f)( GLcontext *, const int * ); 763 struct dynfn *(*TexCoord3fv)( GLcontext *, const int * ); 764 struct dynfn *(*TexCoord2f)( GLcontext *, const int * ); 765 struct dynfn *(*TexCoord2fv)( GLcontext *, const int * ); 766 struct dynfn *(*TexCoord1f)( GLcontext *, const int * ); 767 struct dynfn *(*TexCoord1fv)( GLcontext *, const int * ); 768 struct dynfn *(*MultiTexCoord3fARB)( GLcontext *, const int * ); 769 struct dynfn *(*MultiTexCoord3fvARB)( GLcontext *, const int * ); 770 struct dynfn *(*MultiTexCoord2fARB)( GLcontext *, const int * ); 771 struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * ); 772 struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * ); 773 struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * ); 774 struct dynfn *(*FogCoordfEXT)( GLcontext *, const int * ); 775 struct dynfn *(*FogCoordfvEXT)( GLcontext *, const int * ); 776}; 777 778 779 780struct r200_prim { 781 GLuint start; 782 GLuint end; 783 GLuint prim; 784}; 785 786 /* A maximum total of 29 elements per vertex: 3 floats for position, 3 787 * floats for normal, 4 floats for color, 4 bytes for secondary color, 788 * 3 floats for each texture unit (18 floats total). 789 * 790 * we maybe need add. 4 to prevent segfault if someone specifies 791 * GL_TEXTURE6/GL_TEXTURE7 (esp. for the codegen-path) (FIXME: ) 792 * 793 * The position data is never actually stored here, so 3 elements could be 794 * trimmed out of the buffer. 795 */ 796 797#define R200_MAX_VERTEX_SIZE ((3*6)+11) 798 799struct r200_vbinfo { 800 GLint counter, initial_counter; 801 GLint *dmaptr; 802 void (*notify)( void ); 803 GLint vertex_size; 804 805 union { float f; int i; r200_color_t color; } vertex[R200_MAX_VERTEX_SIZE]; 806 807 GLfloat *normalptr; 808 GLfloat *floatcolorptr; 809 GLfloat *fogptr; 810 r200_color_t *colorptr; 811 GLfloat *floatspecptr; 812 r200_color_t *specptr; 813 GLfloat *texcoordptr[8]; /* 6 (TMU) + 2 for r200_vtxfmt_c.c when GL_TEXTURE6/7 */ 814 815 816 GLenum *prim; /* &ctx->Driver.CurrentExecPrimitive */ 817 GLuint primflags; 818 GLboolean enabled; /* *_NO_VTXFMT / *_NO_TCL env vars */ 819 GLboolean installed; 820 GLboolean fell_back; 821 GLboolean recheck; 822 GLint nrverts; 823 GLuint vtxfmt_0, vtxfmt_1; 824 825 GLuint installed_vertex_format; 826 GLuint installed_color_3f_sz; 827 828 struct r200_prim primlist[R200_MAX_PRIMS]; 829 int nrprims; 830 831 struct dfn_lists dfn_cache; 832 struct dfn_generators codegen; 833 GLvertexformat vtxfmt; 834}; 835 836 837struct r200_context { 838 GLcontext *glCtx; /* Mesa context */ 839 840 /* Driver and hardware state management 841 */ 842 struct r200_hw_state hw; 843 struct r200_state state; 844 845 /* Texture object bookkeeping 846 */ 847 unsigned nr_heaps; 848 driTexHeap * texture_heaps[ R200_NR_TEX_HEAPS ]; 849 driTextureObject swapped; 850 int texture_depth; 851 float initialMaxAnisotropy; 852 853 /* Rasterization and vertex state: 854 */ 855 GLuint TclFallback; 856 GLuint Fallback; 857 GLuint NewGLState; 858 GLuint tnl_index; /* index of bits for last tnl_install_attrs */ 859 860 /* Vertex buffers 861 */ 862 struct r200_ioctl ioctl; 863 struct r200_dma dma; 864 struct r200_store store; 865 /* A full state emit as of the first state emit in the main store, in case 866 * the context is lost. 867 */ 868 struct r200_store backup_store; 869 870 /* Page flipping 871 */ 872 GLuint doPageFlip; 873 874 /* Busy waiting 875 */ 876 GLuint do_usleeps; 877 GLuint do_irqs; 878 GLuint irqsEmitted; 879 drm_radeon_irq_wait_t iw; 880 881 /* Clientdata textures; 882 */ 883 GLuint prefer_gart_client_texturing; 884 885 /* Drawable, cliprect and scissor information 886 */ 887 GLuint numClipRects; /* Cliprects for the draw buffer */ 888 drm_clip_rect_t *pClipRects; 889 unsigned int lastStamp; 890 GLboolean lost_context; 891 GLboolean save_on_next_emit; 892 r200ScreenPtr r200Screen; /* Screen private DRI data */ 893 drm_radeon_sarea_t *sarea; /* Private SAREA data */ 894 895 /* TCL stuff 896 */ 897 GLmatrix TexGenMatrix[R200_MAX_TEXTURE_UNITS]; 898 GLboolean recheck_texgen[R200_MAX_TEXTURE_UNITS]; 899 GLboolean TexGenNeedNormals[R200_MAX_TEXTURE_UNITS]; 900 GLuint TexMatEnabled; 901 GLuint TexMatCompSel; 902 GLuint TexGenEnabled; 903 GLuint TexGenCompSel; 904 GLmatrix tmpmat; 905 906 /* VBI / buffer swap 907 */ 908 GLuint vbl_seq; 909 GLuint vblank_flags; 910 911 int64_t swap_ust; 912 int64_t swap_missed_ust; 913 914 GLuint swap_count; 915 GLuint swap_missed_count; 916 917 PFNGLXGETUSTPROC get_ust; 918 919 /* r200_tcl.c 920 */ 921 struct r200_tcl_info tcl; 922 923 /* r200_swtcl.c 924 */ 925 struct r200_swtcl_info swtcl; 926 927 /* r200_vtxfmt.c 928 */ 929 struct r200_vbinfo vb; 930 931 /* Mirrors of some DRI state 932 */ 933 struct r200_dri_mirror dri; 934 935 /* Configuration cache 936 */ 937 driOptionCache optionCache; 938 939 GLboolean using_hyperz; 940 GLboolean texmicrotile; 941}; 942 943#define R200_CONTEXT(ctx) ((r200ContextPtr)(ctx->DriverCtx)) 944 945 946static __inline GLuint r200PackColor( GLuint cpp, 947 GLubyte r, GLubyte g, 948 GLubyte b, GLubyte a ) 949{ 950 switch ( cpp ) { 951 case 2: 952 return PACK_COLOR_565( r, g, b ); 953 case 4: 954 return PACK_COLOR_8888( a, r, g, b ); 955 default: 956 return 0; 957 } 958} 959 960 961extern void r200DestroyContext( __DRIcontextPrivate *driContextPriv ); 962extern GLboolean r200CreateContext( const __GLcontextModes *glVisual, 963 __DRIcontextPrivate *driContextPriv, 964 void *sharedContextPrivate); 965extern void r200SwapBuffers( __DRIdrawablePrivate *dPriv ); 966extern GLboolean r200MakeCurrent( __DRIcontextPrivate *driContextPriv, 967 __DRIdrawablePrivate *driDrawPriv, 968 __DRIdrawablePrivate *driReadPriv ); 969extern GLboolean r200UnbindContext( __DRIcontextPrivate *driContextPriv ); 970 971/* ================================================================ 972 * Debugging: 973 */ 974#define DO_DEBUG 1 975 976#if DO_DEBUG 977extern int R200_DEBUG; 978#else 979#define R200_DEBUG 0 980#endif 981 982#define DEBUG_TEXTURE 0x001 983#define DEBUG_STATE 0x002 984#define DEBUG_IOCTL 0x004 985#define DEBUG_PRIMS 0x008 986#define DEBUG_VERTS 0x010 987#define DEBUG_FALLBACKS 0x020 988#define DEBUG_VFMT 0x040 989#define DEBUG_CODEGEN 0x080 990#define DEBUG_VERBOSE 0x100 991#define DEBUG_DRI 0x200 992#define DEBUG_DMA 0x400 993#define DEBUG_SANITY 0x800 994#define DEBUG_SYNC 0x1000 995#define DEBUG_PIXEL 0x2000 996#define DEBUG_MEMORY 0x4000 997 998#endif /* __R200_CONTEXT_H__ */ 999