2
* Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3
* Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sub license,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice (including the
13
* next paragraph) shall be included in all copies or substantial portions
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19
* VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
* DEALINGS IN THE SOFTWARE.
27
#ifndef SAVAGECONTEXT_INC
28
#define SAVAGECONTEXT_INC
30
typedef struct savage_context_t savageContext;
31
typedef struct savage_context_t *savageContextPtr;
32
typedef struct savage_texture_object_t *savageTextureObjectPtr;
35
#include "main/mtypes.h"
38
#include "savage_drm.h"
39
#include "savage_init.h"
40
#include "savage_3d_reg.h"
42
#include "tnl/t_vertex.h"
46
#include "xmlconfig.h"
48
/* Reasons to fallback on all primitives.
50
#define SAVAGE_FALLBACK_TEXTURE 0x1
51
#define SAVAGE_FALLBACK_DRAW_BUFFER 0x2
52
#define SAVAGE_FALLBACK_READ_BUFFER 0x4
53
#define SAVAGE_FALLBACK_COLORMASK 0x8
54
#define SAVAGE_FALLBACK_SPECULAR 0x10
55
#define SAVAGE_FALLBACK_LOGICOP 0x20
56
/*frank 2001/11/12 add the stencil fallbak*/
57
#define SAVAGE_FALLBACK_STENCIL 0x40
58
#define SAVAGE_FALLBACK_RENDERMODE 0x80
59
#define SAVAGE_FALLBACK_BLEND_EQ 0x100
60
#define SAVAGE_FALLBACK_NORAST 0x200
61
#define SAVAGE_FALLBACK_PROJ_TEXTURE 0x400
66
/* for savagectx.new_state - manage GL->driver state changes
68
#define SAVAGE_NEW_TEXTURE 0x1
69
#define SAVAGE_NEW_CULL 0x2
71
/* What needs to be changed for the current vertex dma buffer?
74
#define SAVAGE_UPLOAD_LOCAL 0x1 /* DrawLocalCtrl (S4) or
75
DrawCtrl and ZBufCtrl (S3D) */
76
#define SAVAGE_UPLOAD_TEX0 0x2 /* texture unit 0 */
77
#define SAVAGE_UPLOAD_TEX1 0x4 /* texture unit 1 (S4 only) */
78
#define SAVAGE_UPLOAD_FOGTBL 0x8 /* fog table */
79
#define SAVAGE_UPLOAD_GLOBAL 0x10 /* most global regs */
80
#define SAVAGE_UPLOAD_TEXGLOBAL 0x20 /* TexBlendColor (S4 only) */
82
/*define the max numer of vertex in vertex buf*/
83
#define SAVAGE_MAX_VERTEXS 0x10000
85
/* Don't make it too big. We don't want to buffer up a whole frame
86
* that would force the application to wait later. */
87
#define SAVAGE_CMDBUF_SIZE 1024
89
/* Use the templated vertex formats:
91
#define TAG(x) savage##x
92
#include "tnl_dd/t_dd_vertex.h"
95
typedef void (*savage_tri_func)( savageContextPtr, savageVertex *,
96
savageVertex *, savageVertex * );
97
typedef void (*savage_line_func)( savageContextPtr,
98
savageVertex *, savageVertex * );
99
typedef void (*savage_point_func)( savageContextPtr, savageVertex * );
102
/**************************************************************
103
**************** enums for chip IDs ************************
104
**************************************************************/
106
#define CHIP_S3GX3MS1NB 0x8A25
107
#define CHIP_S3GX3MS1NBK 0x8A26
108
#define CHIP_S3TWISTER 0x8D01
109
#define CHIP_S3TWISTERK 0x8D02
110
#define CHIP_S3TWISTER_P4M 0x8D04
111
#define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
112
#define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
113
#define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
114
#define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
115
#define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
117
#define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
118
imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
119
imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
120
imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
121
imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
122
imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
123
imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
124
imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
125
imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
126
imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
129
struct savage_vtxbuf_t {
130
GLuint total, used, flushed; /* in 32 bit units */
131
GLuint idx; /* for DMA buffers */
135
struct savage_cmdbuf_t {
136
GLuint size; /* size in qwords */
137
drm_savage_cmd_header_t *base; /* initial state starts here */
138
drm_savage_cmd_header_t *start; /* drawing/state commands start here */
139
drm_savage_cmd_header_t *write; /* append stuff here */
142
struct savage_elt_t {
143
GLuint n; /* number of elts currently allocated */
144
drm_savage_cmd_header_t *cmd; /* the indexed drawing command */
148
struct savage_context_t {
151
struct gl_context *glCtx;
154
driTexHeap *textureHeaps[SAVAGE_NR_TEX_HEAPS];
155
driTextureObject swapped;
157
driTextureObject *CurrentTexObj[2];
162
savageRegisters regs, oldRegs, globalRegMask;
164
/* Manage our own state */
170
struct savage_cmdbuf_t cmdBuf;
172
/* Elt book-keeping */
173
struct savage_elt_t elts;
177
struct savage_vtxbuf_t dmaVtxBuf, clientVtxBuf;
178
struct savage_vtxbuf_t *vtxBuf;
181
GLubyte *apertureBase[5];
182
GLuint aperturePitch;
183
/* Manage hardware state */
185
GLboolean lostContext;
187
/* One of the few bits of hardware state that can't be calculated
188
* completely on the fly:
196
struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
197
GLuint vertex_attr_count;
198
char *verts; /* points to tnl->clipspace.vertex_buf */
200
/* Rasterization state
202
GLuint SetupNewInputs;
207
GLenum raster_primitive;
208
GLenum render_primitive;
214
/* Fallback rasterization functions
216
savage_point_func draw_point;
217
savage_line_func draw_line;
218
savage_tri_func draw_tri;
220
/* Funny mesa mirrors
225
GLfloat hw_viewport[16];
229
struct gl_framebuffer *glBuffer;
231
/* Two flags to keep track of fallbacks. */
236
/* These refer to the current draw (front vs. back) buffer:
238
int drawX; /* origin of drawable in draw buffer */
240
GLuint numClipRects; /* cliprects for that buffer */
242
drm_clip_rect_t *pClipRects;
244
/* use this bit to support single/double buffer */
246
/* use this to indicate Fullscreen mode */
247
GLuint IsFullScreen; /* FIXME - open/close fullscreen is gone, is this needed? */
248
GLuint backup_frontOffset;
249
GLuint backup_backOffset;
250
GLuint backup_frontBitmapDesc;
252
GLuint backup_streamFIFO;
253
GLuint NotFirstFrame;
259
GLuint any_contend; /* throttle me harder */
261
/* Scissor state needs to be mirrored so buffered commands can be
262
* emitted with the old scissor state when scissor state changes.
270
drm_context_t hHWContext;
271
drm_hw_lock_t *driHwLock;
274
__DRIdrawable *driDrawable;
275
__DRIdrawable *driReadable;
277
__DRIscreen *driScreen;
278
savageScreenPrivate *savageScreen;
279
drm_savage_sarea_t *sarea;
281
GLboolean hw_stencil;
283
/* Performance counters
285
GLuint c_textureSwaps;
287
/* Configuration cache
289
driOptionCache optionCache;
292
GLboolean float_depth;
293
GLboolean enable_fastpath;
294
GLboolean enable_vdma;
295
GLboolean sync_frames;
298
#define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
300
/* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
301
* preprocessor symbol, and equal to zero.
304
extern int SAVAGE_DEBUG;
307
#define DEBUG_FALLBACKS 0x001
308
#define DEBUG_VERBOSE_API 0x002
309
#define DEBUG_VERBOSE_TEX 0x004
310
#define DEBUG_VERBOSE_MSG 0x008
311
#define DEBUG_DMA 0x010
312
#define DEBUG_STATE 0x020
314
#define TARGET_FRONT 0x0
315
#define TARGET_BACK 0x1
316
#define TARGET_DEPTH 0x2
318
#define SUBPIXEL_X -0.5
319
#define SUBPIXEL_Y -0.375