1 /**************************************************************************
2  *
3  * Copyright 2003 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #ifndef I830CONTEXT_INC
29 #define I830CONTEXT_INC
30 
31 #include "intel_context.h"
32 
33 #define I830_FALLBACK_TEXTURE		 0x1000
34 #define I830_FALLBACK_COLORMASK		 0x2000
35 #define I830_FALLBACK_STENCIL		 0x4000
36 #define I830_FALLBACK_STIPPLE		 0x8000
37 #define I830_FALLBACK_LOGICOP		 0x20000
38 #define I830_FALLBACK_DRAW_OFFSET	 0x200000
39 
40 #define I830_UPLOAD_CTX              0x1
41 #define I830_UPLOAD_BUFFERS          0x2
42 #define I830_UPLOAD_STIPPLE          0x4
43 #define I830_UPLOAD_INVARIENT        0x8
44 #define I830_UPLOAD_RASTER_RULES     0x10
45 #define I830_UPLOAD_TEX(i)           (0x0100<<(i))
46 #define I830_UPLOAD_TEXBLEND(i)      (0x1000<<(i))
47 #define I830_UPLOAD_TEX_ALL          (0x0f00)
48 #define I830_UPLOAD_TEXBLEND_ALL     (0xf000)
49 
50 /* State structure offsets - these will probably disappear.
51  */
52 #define I830_DESTREG_CBUFADDR0 0
53 #define I830_DESTREG_CBUFADDR1 1
54 #define I830_DESTREG_DBUFADDR0 2
55 #define I830_DESTREG_DBUFADDR1 3
56 #define I830_DESTREG_DV0 4
57 #define I830_DESTREG_DV1 5
58 #define I830_DESTREG_SR0 6
59 #define I830_DESTREG_SR1 7
60 #define I830_DESTREG_SR2 8
61 #define I830_DESTREG_SENABLE 9
62 #define I830_DESTREG_DRAWRECT0 10
63 #define I830_DESTREG_DRAWRECT1 11
64 #define I830_DESTREG_DRAWRECT2 12
65 #define I830_DESTREG_DRAWRECT3 13
66 #define I830_DESTREG_DRAWRECT4 14
67 #define I830_DESTREG_DRAWRECT5 15
68 #define I830_DEST_SETUP_SIZE 16
69 
70 #define I830_CTXREG_STATE1		0
71 #define I830_CTXREG_STATE2		1
72 #define I830_CTXREG_STATE3		2
73 #define I830_CTXREG_STATE4		3
74 #define I830_CTXREG_STATE5		4
75 #define I830_CTXREG_IALPHAB		5
76 #define I830_CTXREG_STENCILTST		6
77 #define I830_CTXREG_ENABLES_1		7
78 #define I830_CTXREG_ENABLES_2		8
79 #define I830_CTXREG_AA			9
80 #define I830_CTXREG_FOGCOLOR		10
81 #define I830_CTXREG_BLENDCOLOR0		11
82 #define I830_CTXREG_BLENDCOLOR1		12
83 #define I830_CTXREG_VF			13
84 #define I830_CTXREG_VF2			14
85 #define I830_CTXREG_MCSB0		15
86 #define I830_CTXREG_MCSB1		16
87 #define I830_CTX_SETUP_SIZE		17
88 
89 #define I830_STPREG_ST0        0
90 #define I830_STPREG_ST1        1
91 #define I830_STP_SETUP_SIZE    2
92 
93 #define I830_TEXREG_TM0LI      0        /* load immediate 2 texture map n */
94 #define I830_TEXREG_TM0S1      1
95 #define I830_TEXREG_TM0S2      2
96 #define I830_TEXREG_TM0S3      3
97 #define I830_TEXREG_TM0S4      4
98 #define I830_TEXREG_MCS	       5        /* _3DSTATE_MAP_COORD_SETS */
99 #define I830_TEXREG_CUBE       6        /* _3DSTATE_MAP_SUBE */
100 #define I830_TEX_SETUP_SIZE    7
101 
102 #define I830_TEXBLEND_SIZE	12      /* (4 args + op) * 2 + COLOR_FACTOR */
103 
104 enum {
105    I830_RASTER_RULES,
106    I830_RASTER_RULES_SIZE
107 };
108 
109 struct i830_texture_object
110 {
111    struct intel_texture_object intel;
112    GLuint Setup[I830_TEX_SETUP_SIZE];
113 };
114 
115 #define I830_TEX_UNITS 4
116 
117 struct i830_hw_state
118 {
119    GLuint Ctx[I830_CTX_SETUP_SIZE];
120    GLuint Buffer[I830_DEST_SETUP_SIZE];
121    GLuint Stipple[I830_STP_SETUP_SIZE];
122    GLuint RasterRules[I830_RASTER_RULES_SIZE];
123    GLuint Tex[I830_TEX_UNITS][I830_TEX_SETUP_SIZE];
124    GLuint TexBlend[I830_TEX_UNITS][I830_TEXBLEND_SIZE];
125    GLuint TexBlendWordsUsed[I830_TEX_UNITS];
126 
127    struct intel_region *draw_region;
128    struct intel_region *depth_region;
129 
130    /* Regions aren't actually that appropriate here as the memory may
131     * be from a PBO or FBO.  Will have to do this for draw and depth for
132     * FBO's...
133     */
134    drm_intel_bo *tex_buffer[I830_TEX_UNITS];
135    GLuint tex_offset[I830_TEX_UNITS];
136 
137    GLuint emitted;              /* I810_UPLOAD_* */
138    GLuint active;
139 };
140 
141 struct i830_context
142 {
143    struct intel_context intel;
144 
145    GLuint lodbias_tm0s3[MAX_TEXTURE_UNITS];
146    GLbitfield64 last_index_bitset;
147 
148    struct i830_hw_state state;
149 };
150 
151 
152 
153 
154 #define I830_STATECHANGE(i830, flag)				\
155 do {								\
156    INTEL_FIREVERTICES( &i830->intel );				\
157    i830->state.emitted &= ~flag;					\
158 } while (0)
159 
160 #define I830_ACTIVESTATE(i830, flag, mode)	\
161 do {						\
162    INTEL_FIREVERTICES( &i830->intel );		\
163    if (mode)					\
164       i830->state.active |= flag;		\
165    else						\
166       i830->state.active &= ~flag;		\
167 } while (0)
168 
169 /* i830_vtbl.c
170  */
171 extern void i830InitVtbl(struct i830_context *i830);
172 
173 extern void
174 i830_state_draw_region(struct intel_context *intel,
175                        struct i830_hw_state *state,
176                        struct intel_region *color_region,
177                        struct intel_region *depth_region);
178 /* i830_context.c
179  */
180 extern bool
181 i830CreateContext(int api,
182                   const struct gl_config * mesaVis,
183                   __DRIcontext * driContextPriv,
184                   unsigned major_version,
185                   unsigned minor_version,
186                   uint32_t flags,
187                   unsigned *error,
188                   void *sharedContextPrivate);
189 
190 /* i830_tex.c, i830_texstate.c
191  */
192 extern void i830UpdateTextureState(struct intel_context *intel);
193 
194 extern void i830InitTextureFuncs(struct dd_function_table *functions);
195 
196 /* i830_texblend.c
197  */
198 extern GLuint i830SetTexEnvCombine(struct i830_context *i830,
199                                    const struct gl_tex_env_combine_state
200                                    *combine, GLint blendUnit, GLuint texel_op,
201                                    GLuint * state, const GLfloat * factor);
202 
203 extern void i830EmitTextureBlend(struct i830_context *i830);
204 
205 
206 /* i830_state.c
207  */
208 extern void i830InitStateFuncs(struct dd_function_table *functions);
209 
210 extern void i830EmitState(struct i830_context *i830);
211 
212 extern void i830InitState(struct i830_context *i830);
213 extern void i830_update_provoking_vertex(struct gl_context *ctx);
214 
215 /*======================================================================
216  * Inline conversion functions.  These are better-typed than the
217  * macros used previously:
218  */
219 static inline struct i830_context *
i830_context(struct gl_context * ctx)220 i830_context(struct gl_context * ctx)
221 {
222    return (struct i830_context *) ctx;
223 }
224 
225 #endif
226