1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 TUNGSTEN GRAPHICS 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.
26 **************************************************************************/
34 #include "intel_screen.h"
35 #include "intel_batchbuffer.h"
36 #include "intel_ioctl.h"
37 #include "intel_regions.h"
39 #include "i830_context.h"
42 /* A large amount of state doesn't need to be uploaded.
44 #define ACTIVE (I830_UPLOAD_INVARIENT | \
46 I830_UPLOAD_BUFFERS | \
47 I830_UPLOAD_STIPPLE | \
48 I830_UPLOAD_TEXBLEND(0) | \
52 #define SET_STATE( i830, STATE ) \
54 i830->current->emitted &= ~ACTIVE; \
55 i830->current = &i830->STATE; \
56 i830->current->emitted &= ~ACTIVE; \
61 set_no_stencil_write(struct intel_context
*intel
)
63 struct i830_context
*i830
= i830_context(&intel
->ctx
);
65 /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_FALSE )
67 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_STENCIL_TEST
;
68 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_STENCIL_WRITE
;
69 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_STENCIL_TEST
;
70 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_STENCIL_WRITE
;
72 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
76 set_no_depth_write(struct intel_context
*intel
)
78 struct i830_context
*i830
= i830_context(&intel
->ctx
);
80 /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_FALSE )
82 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_DEPTH_TEST_MASK
;
83 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DIS_DEPTH_WRITE_MASK
;
84 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_DEPTH_TEST
;
85 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_DEPTH_WRITE
;
87 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
90 /* Set depth unit to replace.
93 set_depth_replace(struct intel_context
*intel
)
95 struct i830_context
*i830
= i830_context(&intel
->ctx
);
97 /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_FALSE )
98 * ctx->Driver.DepthMask( ctx, GL_TRUE )
100 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_DEPTH_TEST_MASK
;
101 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DIS_DEPTH_WRITE_MASK
;
102 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_DEPTH_TEST
;
103 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_DEPTH_WRITE
;
105 /* ctx->Driver.DepthFunc( ctx, GL_ALWAYS )
107 i830
->meta
.Ctx
[I830_CTXREG_STATE3
] &= ~DEPTH_TEST_FUNC_MASK
;
108 i830
->meta
.Ctx
[I830_CTXREG_STATE3
] |= (ENABLE_DEPTH_TEST_FUNC
|
110 (COMPAREFUNC_ALWAYS
));
112 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
116 /* Set stencil unit to replace always with the reference value.
119 set_stencil_replace(struct intel_context
*intel
,
120 GLuint s_mask
, GLuint s_clear
)
122 struct i830_context
*i830
= i830_context(&intel
->ctx
);
124 /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_TRUE )
126 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_STENCIL_TEST
;
127 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_STENCIL_WRITE
;
129 /* ctx->Driver.StencilMask( ctx, s_mask )
131 i830
->meta
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK
;
132 i830
->meta
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_WRITE_MASK
|
133 STENCIL_WRITE_MASK((s_mask
&
136 /* ctx->Driver.StencilOp( ctx, GL_REPLACE, GL_REPLACE, GL_REPLACE )
138 i830
->meta
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_OPS_MASK
);
139 i830
->meta
.Ctx
[I830_CTXREG_STENCILTST
] |=
140 (ENABLE_STENCIL_PARMS
|
141 STENCIL_FAIL_OP(STENCILOP_REPLACE
) |
142 STENCIL_PASS_DEPTH_FAIL_OP(STENCILOP_REPLACE
) |
143 STENCIL_PASS_DEPTH_PASS_OP(STENCILOP_REPLACE
));
145 /* ctx->Driver.StencilFunc( ctx, GL_ALWAYS, s_clear, ~0 )
147 i830
->meta
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_TEST_MASK
;
148 i830
->meta
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_TEST_MASK
|
149 STENCIL_TEST_MASK(0xff));
151 i830
->meta
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_REF_VALUE_MASK
|
152 ENABLE_STENCIL_TEST_FUNC_MASK
);
153 i830
->meta
.Ctx
[I830_CTXREG_STENCILTST
] |=
154 (ENABLE_STENCIL_REF_VALUE
|
155 ENABLE_STENCIL_TEST_FUNC
|
156 STENCIL_REF_VALUE((s_clear
& 0xff)) |
157 STENCIL_TEST_FUNC(COMPAREFUNC_ALWAYS
));
161 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
166 set_color_mask(struct intel_context
*intel
, GLboolean state
)
168 struct i830_context
*i830
= i830_context(&intel
->ctx
);
170 const GLuint mask
= ((1 << WRITEMASK_RED_SHIFT
) |
171 (1 << WRITEMASK_GREEN_SHIFT
) |
172 (1 << WRITEMASK_BLUE_SHIFT
) |
173 (1 << WRITEMASK_ALPHA_SHIFT
));
175 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~mask
;
178 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] |=
179 (i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] & mask
);
182 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
185 /* Installs a one-stage passthrough texture blend pipeline. Is there
186 * more that can be done to turn off texturing?
189 set_no_texture(struct intel_context
*intel
)
191 struct i830_context
*i830
= i830_context(&intel
->ctx
);
192 static const struct gl_tex_env_combine_state comb
= {
194 {GL_TEXTURE
, 0, 0,}, {GL_TEXTURE
, 0, 0,},
195 {GL_SRC_COLOR
, 0, 0}, {GL_SRC_ALPHA
, 0, 0},
199 i830
->meta
.TexBlendWordsUsed
[0] =
200 i830SetTexEnvCombine(i830
, &comb
, 0, TEXBLENDARG_TEXEL0
,
201 i830
->meta
.TexBlend
[0], NULL
);
203 i830
->meta
.TexBlend
[0][0] |= TEXOP_LAST_STAGE
;
204 i830
->meta
.emitted
&= ~I830_UPLOAD_TEXBLEND(0);
207 /* Set up a single element blend stage for 'replace' texturing with no
211 set_texture_blend_replace(struct intel_context
*intel
)
213 struct i830_context
*i830
= i830_context(&intel
->ctx
);
214 static const struct gl_tex_env_combine_state comb
= {
215 GL_REPLACE
, GL_REPLACE
,
216 {GL_TEXTURE
, GL_TEXTURE
, GL_TEXTURE
,}, {GL_TEXTURE
, GL_TEXTURE
,
218 {GL_SRC_COLOR
, GL_SRC_COLOR
, GL_SRC_COLOR
}, {GL_SRC_ALPHA
, GL_SRC_ALPHA
,
223 i830
->meta
.TexBlendWordsUsed
[0] =
224 i830SetTexEnvCombine(i830
, &comb
, 0, TEXBLENDARG_TEXEL0
,
225 i830
->meta
.TexBlend
[0], NULL
);
227 i830
->meta
.TexBlend
[0][0] |= TEXOP_LAST_STAGE
;
228 i830
->meta
.emitted
&= ~I830_UPLOAD_TEXBLEND(0);
230 /* fprintf(stderr, "%s: TexBlendWordsUsed[0]: %d\n", */
231 /* __FUNCTION__, i830->meta.TexBlendWordsUsed[0]); */
236 /* Set up an arbitary piece of memory as a rectangular texture
237 * (including the front or back buffer).
240 set_tex_rect_source(struct intel_context
*intel
,
243 GLuint pitch
, GLuint height
, GLenum format
, GLenum type
)
245 struct i830_context
*i830
= i830_context(&intel
->ctx
);
246 GLuint
*setup
= i830
->meta
.Tex
[0];
248 GLuint textureFormat
;
251 /* A full implementation of this would do the upload through
252 * glTexImage2d, and get all the conversion operations at that
253 * point. We are restricted, but still at least have access to the
254 * fragment program swizzle.
259 case GL_UNSIGNED_INT_8_8_8_8_REV
:
260 case GL_UNSIGNED_BYTE
:
261 textureFormat
= (MAPSURF_32BIT
| MT_32BIT_ARGB8888
);
270 case GL_UNSIGNED_INT_8_8_8_8_REV
:
271 case GL_UNSIGNED_BYTE
:
272 textureFormat
= (MAPSURF_32BIT
| MT_32BIT_ABGR8888
);
281 case GL_UNSIGNED_SHORT_5_6_5_REV
:
282 textureFormat
= (MAPSURF_16BIT
| MT_16BIT_RGB565
);
291 case GL_UNSIGNED_SHORT_5_6_5
:
292 textureFormat
= (MAPSURF_16BIT
| MT_16BIT_RGB565
);
304 i830
->meta
.tex_buffer
[0] = buffer
;
305 i830
->meta
.tex_offset
[0] = offset
;
307 setup
[I830_TEXREG_TM0LI
] = (_3DSTATE_LOAD_STATE_IMMEDIATE_2
|
308 (LOAD_TEXTURE_MAP0
<< 0) | 4);
309 setup
[I830_TEXREG_TM0S1
] = (((height
- 1) << TM0S1_HEIGHT_SHIFT
) |
310 ((pitch
- 1) << TM0S1_WIDTH_SHIFT
) |
312 setup
[I830_TEXREG_TM0S2
] =
313 (((((pitch
* cpp
) / 4) -
314 1) << TM0S2_PITCH_SHIFT
) | TM0S2_CUBE_FACE_ENA_MASK
);
316 setup
[I830_TEXREG_TM0S3
] =
319 4) << TM0S3_MIN_MIP_SHIFT
) | (FILTER_NEAREST
<<
320 TM0S3_MIN_FILTER_SHIFT
) |
321 (MIPFILTER_NONE
<< TM0S3_MIP_FILTER_SHIFT
) | (FILTER_NEAREST
<<
322 TM0S3_MAG_FILTER_SHIFT
));
324 setup
[I830_TEXREG_CUBE
] = (_3DSTATE_MAP_CUBE
| MAP_UNIT(0));
326 setup
[I830_TEXREG_MCS
] = (_3DSTATE_MAP_COORD_SET_CMD
|
328 ENABLE_TEXCOORD_PARAMS
|
329 TEXCOORDS_ARE_IN_TEXELUNITS
|
330 TEXCOORDTYPE_CARTESIAN
|
332 TEXCOORD_ADDR_V_MODE(TEXCOORDMODE_WRAP
) |
334 TEXCOORD_ADDR_U_MODE(TEXCOORDMODE_WRAP
));
336 i830
->meta
.emitted
&= ~I830_UPLOAD_TEX(0);
342 set_vertex_format(struct intel_context
*intel
)
344 struct i830_context
*i830
= i830_context(&intel
->ctx
);
345 i830
->meta
.Ctx
[I830_CTXREG_VF
] = (_3DSTATE_VFT0_CMD
|
347 VFT0_DIFFUSE
| VFT0_XYZ
);
348 i830
->meta
.Ctx
[I830_CTXREG_VF2
] = (_3DSTATE_VFT1_CMD
|
349 VFT1_TEX0_FMT(TEXCOORDFMT_2D
) |
350 VFT1_TEX1_FMT(TEXCOORDFMT_2D
) |
351 VFT1_TEX2_FMT(TEXCOORDFMT_2D
) |
352 VFT1_TEX3_FMT(TEXCOORDFMT_2D
));
353 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
358 meta_import_pixel_state(struct intel_context
*intel
)
360 struct i830_context
*i830
= i830_context(&intel
->ctx
);
362 i830
->meta
.Ctx
[I830_CTXREG_STATE1
] = i830
->state
.Ctx
[I830_CTXREG_STATE1
];
363 i830
->meta
.Ctx
[I830_CTXREG_STATE2
] = i830
->state
.Ctx
[I830_CTXREG_STATE2
];
364 i830
->meta
.Ctx
[I830_CTXREG_STATE3
] = i830
->state
.Ctx
[I830_CTXREG_STATE3
];
365 i830
->meta
.Ctx
[I830_CTXREG_STATE4
] = i830
->state
.Ctx
[I830_CTXREG_STATE4
];
366 i830
->meta
.Ctx
[I830_CTXREG_STATE5
] = i830
->state
.Ctx
[I830_CTXREG_STATE5
];
367 i830
->meta
.Ctx
[I830_CTXREG_IALPHAB
] = i830
->state
.Ctx
[I830_CTXREG_IALPHAB
];
368 i830
->meta
.Ctx
[I830_CTXREG_STENCILTST
] =
369 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
];
370 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_1
] =
371 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
];
372 i830
->meta
.Ctx
[I830_CTXREG_ENABLES_2
] =
373 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
];
374 i830
->meta
.Ctx
[I830_CTXREG_AA
] = i830
->state
.Ctx
[I830_CTXREG_AA
];
375 i830
->meta
.Ctx
[I830_CTXREG_FOGCOLOR
] =
376 i830
->state
.Ctx
[I830_CTXREG_FOGCOLOR
];
377 i830
->meta
.Ctx
[I830_CTXREG_BLENDCOLOR0
] =
378 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR0
];
379 i830
->meta
.Ctx
[I830_CTXREG_BLENDCOLOR1
] =
380 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR1
];
381 i830
->meta
.Ctx
[I830_CTXREG_MCSB0
] = i830
->state
.Ctx
[I830_CTXREG_MCSB0
];
382 i830
->meta
.Ctx
[I830_CTXREG_MCSB1
] = i830
->state
.Ctx
[I830_CTXREG_MCSB1
];
385 i830
->meta
.Ctx
[I830_CTXREG_STATE3
] &= ~CULLMODE_MASK
;
386 i830
->meta
.Stipple
[I830_STPREG_ST1
] &= ~ST1_ENABLE
;
387 i830
->meta
.emitted
&= ~I830_UPLOAD_CTX
;
390 i830
->meta
.Buffer
[I830_DESTREG_SENABLE
] =
391 i830
->state
.Buffer
[I830_DESTREG_SENABLE
];
392 i830
->meta
.Buffer
[I830_DESTREG_SR1
] = i830
->state
.Buffer
[I830_DESTREG_SR1
];
393 i830
->meta
.Buffer
[I830_DESTREG_SR2
] = i830
->state
.Buffer
[I830_DESTREG_SR2
];
394 i830
->meta
.emitted
&= ~I830_UPLOAD_BUFFERS
;
399 /* Select between front and back draw buffers.
402 meta_draw_region(struct intel_context
*intel
,
403 struct intel_region
*color_region
,
404 struct intel_region
*depth_region
)
406 struct i830_context
*i830
= i830_context(&intel
->ctx
);
408 i830_state_draw_region(intel
, &i830
->meta
, color_region
, depth_region
);
412 /* Operations where the 3D engine is decoupled temporarily from the
413 * current GL state and used for other purposes than simply rendering
414 * incoming triangles.
417 install_meta_state(struct intel_context
*intel
)
419 struct i830_context
*i830
= i830_context(&intel
->ctx
);
420 memcpy(&i830
->meta
, &i830
->initial
, sizeof(i830
->meta
));
422 i830
->meta
.active
= ACTIVE
;
423 i830
->meta
.emitted
= 0;
425 SET_STATE(i830
, meta
);
426 set_vertex_format(intel
);
427 set_no_texture(intel
);
431 leave_meta_state(struct intel_context
*intel
)
433 struct i830_context
*i830
= i830_context(&intel
->ctx
);
434 intel_region_release(&i830
->meta
.draw_region
);
435 intel_region_release(&i830
->meta
.depth_region
);
436 /* intel_region_release(intel, &i830->meta.tex_region[0]); */
437 SET_STATE(i830
, state
);
443 i830InitMetaFuncs(struct i830_context
*i830
)
445 i830
->intel
.vtbl
.install_meta_state
= install_meta_state
;
446 i830
->intel
.vtbl
.leave_meta_state
= leave_meta_state
;
447 i830
->intel
.vtbl
.meta_no_depth_write
= set_no_depth_write
;
448 i830
->intel
.vtbl
.meta_no_stencil_write
= set_no_stencil_write
;
449 i830
->intel
.vtbl
.meta_stencil_replace
= set_stencil_replace
;
450 i830
->intel
.vtbl
.meta_depth_replace
= set_depth_replace
;
451 i830
->intel
.vtbl
.meta_color_mask
= set_color_mask
;
452 i830
->intel
.vtbl
.meta_no_texture
= set_no_texture
;
453 i830
->intel
.vtbl
.meta_texture_blend_replace
= set_texture_blend_replace
;
454 i830
->intel
.vtbl
.meta_tex_rect_source
= set_tex_rect_source
;
455 i830
->intel
.vtbl
.meta_draw_region
= meta_draw_region
;
456 i830
->intel
.vtbl
.meta_import_pixel_state
= meta_import_pixel_state
;