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 **************************************************************************/
30 #include "i915_context.h"
31 #include "i915_winsys.h"
32 #include "i915_batch.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_defines.h"
38 static unsigned translate_format( unsigned format
)
41 case PIPE_FORMAT_U_A8_R8_G8_B8
:
42 return COLOR_BUF_ARGB8888
;
43 case PIPE_FORMAT_U_R5_G6_B5
:
44 return COLOR_BUF_RGB565
;
51 static unsigned translate_depth_format( unsigned zformat
)
53 assert(zformat
== PIPE_FORMAT_S8_Z24
);
54 return DEPTH_FRMT_24_FIXED_8_OTHER
;
58 /* Push the state into the sarea and/or texture memory.
61 i915_emit_hardware_state(struct i915_context
*i915
)
65 if (i915
->hardware_dirty
& I915_HW_INVARIENT
)
67 OUT_BATCH(_3DSTATE_AA_CMD
|
68 AA_LINE_ECAAR_WIDTH_ENABLE
|
69 AA_LINE_ECAAR_WIDTH_1_0
|
70 AA_LINE_REGION_WIDTH_ENABLE
| AA_LINE_REGION_WIDTH_1_0
);
72 OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD
);
75 OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD
);
78 OUT_BATCH(_3DSTATE_DFLT_Z_CMD
);
81 OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS
|
91 OUT_BATCH(_3DSTATE_RASTER_RULES_CMD
|
92 ENABLE_POINT_RASTER_RULE
|
93 OGL_POINT_RASTER_RULE
|
94 ENABLE_LINE_STRIP_PROVOKE_VRTX
|
95 ENABLE_TRI_FAN_PROVOKE_VRTX
|
96 LINE_STRIP_PROVOKE_VRTX(1) |
97 TRI_FAN_PROVOKE_VRTX(2) |
98 ENABLE_TEXKILL_3D_4D
|
101 /* Need to initialize this to zero.
103 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
| I1_LOAD_S(3) | (0));
106 OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE
);
108 /* disable indirect state for now
110 OUT_BATCH(_3DSTATE_LOAD_INDIRECT
| 0);
115 if (i915
->hardware_dirty
& I915_HW_IMMEDIATE
)
117 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
124 OUT_BATCH(i915
->current
.immediate
[I915_IMMEDIATE_S2
]);
125 OUT_BATCH(i915
->current
.immediate
[I915_IMMEDIATE_S4
]);
126 OUT_BATCH(i915
->current
.immediate
[I915_IMMEDIATE_S5
]);
127 OUT_BATCH(i915
->current
.immediate
[I915_IMMEDIATE_S6
]);
131 if (i915
->hardware_dirty
& I915_HW_DYNAMIC
)
134 for (i
= 0; i
< I915_MAX_DYNAMIC
; i
++) {
135 OUT_BATCH(i915
->current
.dynamic
[i
]);
139 if (i915
->hardware_dirty
& I915_HW_STATIC
)
141 if (i915
->framebuffer
.cbufs
[0]) {
142 struct pipe_region
*cbuf_region
= i915
->framebuffer
.cbufs
[0]->region
;
143 unsigned pitch
= (cbuf_region
->pitch
*
146 OUT_BATCH(_3DSTATE_BUF_INFO_CMD
);
148 OUT_BATCH(BUF_3D_ID_COLOR_BACK
|
149 BUF_3D_PITCH(pitch
) | /* pitch in bytes */
152 OUT_RELOC(cbuf_region
->buffer
,
153 I915_BUFFER_ACCESS_WRITE
,
157 /* What happens if no zbuf??
159 if (i915
->framebuffer
.zbuf
) {
160 struct pipe_region
*depth_region
= i915
->framebuffer
.zbuf
->region
;
161 unsigned zpitch
= (depth_region
->pitch
*
164 OUT_BATCH(_3DSTATE_BUF_INFO_CMD
);
166 OUT_BATCH(BUF_3D_ID_DEPTH
|
167 BUF_3D_PITCH(zpitch
) | /* pitch in bytes */
170 OUT_RELOC(depth_region
->buffer
,
171 I915_BUFFER_ACCESS_WRITE
,
176 unsigned cformat
= translate_format( i915
->framebuffer
.cbufs
[0]->format
);
177 unsigned zformat
= 0;
179 if (i915
->framebuffer
.zbuf
)
180 zformat
= translate_depth_format( i915
->framebuffer
.zbuf
->format
);
182 OUT_BATCH(_3DSTATE_DST_BUF_VARS_CMD
);
183 OUT_BATCH(DSTORG_HORT_BIAS(0x8) | /* .5 */
184 DSTORG_VERT_BIAS(0x8) | /* .5 */
186 TEX_DEFAULT_COLOR_OGL
|
195 if (i915
->hardware_dirty
& (I915_HW_MAP
| I915_HW_SAMPLER
))
197 /* XXX: we were refering to sampler state
198 * (current.sampler_enable_nr) below, but only checking
199 * I915_HW_MAP above. Should probably calculate the enabled
200 * flags separately - but there will be further rework of
201 * state so perhaps not necessary yet.
203 const uint nr
= i915
->current
.sampler_enable_nr
;
205 const uint enabled
= i915
->current
.sampler_enable_flags
;
208 OUT_BATCH(_3DSTATE_MAP_STATE
| (3 * nr
));
210 for (unit
= 0; unit
< I915_TEX_UNITS
; unit
++) {
211 if (enabled
& (1 << unit
)) {
212 struct pipe_buffer_handle
*buf
=
213 i915
->texture
[unit
]->region
->buffer
;
220 I915_BUFFER_ACCESS_READ
,
222 OUT_BATCH(i915
->current
.texbuffer
[unit
][0]); /* MS3 */
223 OUT_BATCH(i915
->current
.texbuffer
[unit
][1]); /* MS4 */
233 if (i915
->hardware_dirty
& I915_HW_SAMPLER
)
235 if (i915
->current
.sampler_enable_nr
) {
238 OUT_BATCH( _3DSTATE_SAMPLER_STATE
|
239 (3 * i915
->current
.sampler_enable_nr
) );
241 OUT_BATCH( i915
->current
.sampler_enable_flags
);
243 for (i
= 0; i
< I915_TEX_UNITS
; i
++) {
244 if (i915
->current
.sampler_enable_flags
& (1<<i
)) {
245 OUT_BATCH( i915
->current
.sampler
[i
][0] );
246 OUT_BATCH( i915
->current
.sampler
[i
][1] );
247 OUT_BATCH( i915
->current
.sampler
[i
][2] );
255 if (i915
->hardware_dirty
& I915_HW_PROGRAM
)
257 const uint nr
= i915
->current
.num_constants
[PIPE_SHADER_FRAGMENT
];
258 assert(nr
<= I915_MAX_CONSTANT
);
261 = (const uint
*) i915
->current
.constants
[PIPE_SHADER_FRAGMENT
];
263 OUT_BATCH( _3DSTATE_PIXEL_SHADER_CONSTANTS
| (nr
* 4) );
264 OUT_BATCH( (1 << (nr
- 1)) | ((1 << (nr
- 1)) - 1) );
265 for (i
= 0; i
< nr
; i
++) {
274 /* Fragment program */
275 if (i915
->hardware_dirty
& I915_HW_PROGRAM
)
278 /* we should always have, at least, a pass-through program */
279 assert(i915
->current
.program_len
> 0);
280 for (i
= 0; i
< i915
->current
.program_len
; i
++) {
281 OUT_BATCH(i915
->current
.program
[i
]);
285 /* drawing surface size */
287 int w
= i915
->framebuffer
.cbufs
[0]->width
;
288 int h
= i915
->framebuffer
.cbufs
[0]->height
;
290 OUT_BATCH(_3DSTATE_DRAW_RECT_CMD
);
293 OUT_BATCH(((w
- 1) & 0xffff) | ((h
- 1) << 16));
299 i915
->hardware_dirty
= 0;