2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "brw_debug.h"
35 #include "brw_batchbuffer.h"
36 #include "brw_context.h"
37 #include "brw_state.h"
38 #include "brw_defines.h"
39 #include "brw_screen.h"
40 #include "brw_pipe_rast.h"
46 /***********************************************************************
50 static int upload_blend_constant_color(struct brw_context
*brw
)
52 BRW_CACHED_BATCH_STRUCT(brw
, &brw
->curr
.bcc
);
57 const struct brw_tracked_state brw_blend_constant_color
= {
59 .mesa
= PIPE_NEW_BLEND_COLOR
,
63 .emit
= upload_blend_constant_color
66 /***********************************************************************
67 * Drawing rectangle - framebuffer dimensions
69 static int upload_drawing_rect(struct brw_context
*brw
)
71 BEGIN_BATCH(4, NO_LOOP_CLIPRECTS
);
72 OUT_BATCH(_3DSTATE_DRAWRECT_INFO_I965
);
74 OUT_BATCH(((brw
->curr
.fb
.width
- 1) & 0xffff) |
75 ((brw
->curr
.fb
.height
- 1) << 16));
81 const struct brw_tracked_state brw_drawing_rect
= {
83 .mesa
= PIPE_NEW_FRAMEBUFFER_DIMENSIONS
,
87 .emit
= upload_drawing_rect
91 /***********************************************************************
92 * Binding table pointers
95 static int prepare_binding_table_pointers(struct brw_context
*brw
)
97 brw_add_validated_bo(brw
, brw
->vs
.bind_bo
);
98 brw_add_validated_bo(brw
, brw
->wm
.bind_bo
);
103 * Upload the binding table pointers, which point each stage's array of surface
106 * The binding table pointers are relative to the surface state base address,
109 static int upload_binding_table_pointers(struct brw_context
*brw
)
111 BEGIN_BATCH(6, IGNORE_CLIPRECTS
);
112 OUT_BATCH(CMD_BINDING_TABLE_PTRS
<< 16 | (6 - 2));
113 if (brw
->vs
.bind_bo
!= NULL
)
114 OUT_RELOC(brw
->vs
.bind_bo
,
119 OUT_BATCH(0); /* gs */
120 OUT_BATCH(0); /* clip */
121 OUT_BATCH(0); /* sf */
122 OUT_RELOC(brw
->wm
.bind_bo
,
129 const struct brw_tracked_state brw_binding_table_pointers
= {
132 .brw
= BRW_NEW_BATCH
,
133 .cache
= CACHE_NEW_SURF_BIND
,
135 .prepare
= prepare_binding_table_pointers
,
136 .emit
= upload_binding_table_pointers
,
140 /**********************************************************************
141 * Upload pointers to the per-stage state.
143 * The state pointers in this packet are all relative to the general state
144 * base address set by CMD_STATE_BASE_ADDRESS, which is 0.
146 static int upload_pipelined_state_pointers(struct brw_context
*brw
)
148 BEGIN_BATCH(7, IGNORE_CLIPRECTS
);
149 OUT_BATCH(CMD_PIPELINED_STATE_POINTERS
<< 16 | (7 - 2));
150 OUT_RELOC(brw
->vs
.state_bo
,
153 if (brw
->gs
.prog_active
)
154 OUT_RELOC(brw
->gs
.state_bo
,
159 OUT_RELOC(brw
->clip
.state_bo
,
162 OUT_RELOC(brw
->sf
.state_bo
,
165 OUT_RELOC(brw
->wm
.state_bo
,
168 OUT_RELOC(brw
->cc
.state_bo
,
173 brw
->state
.dirty
.brw
|= BRW_NEW_PSP
;
178 static int prepare_psp_urb_cbs(struct brw_context
*brw
)
180 brw_add_validated_bo(brw
, brw
->vs
.state_bo
);
181 brw_add_validated_bo(brw
, brw
->gs
.state_bo
);
182 brw_add_validated_bo(brw
, brw
->clip
.state_bo
);
183 brw_add_validated_bo(brw
, brw
->sf
.state_bo
);
184 brw_add_validated_bo(brw
, brw
->wm
.state_bo
);
185 brw_add_validated_bo(brw
, brw
->cc
.state_bo
);
189 static int upload_psp_urb_cbs(struct brw_context
*brw
)
193 ret
= upload_pipelined_state_pointers(brw
);
197 ret
= brw_upload_urb_fence(brw
);
201 ret
= brw_upload_cs_urb_state(brw
);
208 const struct brw_tracked_state brw_psp_urb_cbs
= {
211 .brw
= BRW_NEW_URB_FENCE
| BRW_NEW_BATCH
,
212 .cache
= (CACHE_NEW_VS_UNIT
|
215 CACHE_NEW_CLIP_UNIT
|
220 .prepare
= prepare_psp_urb_cbs
,
221 .emit
= upload_psp_urb_cbs
,
225 /***********************************************************************
229 static int prepare_depthbuffer(struct brw_context
*brw
)
231 struct pipe_surface
*zsbuf
= brw
->curr
.fb
.zsbuf
;
234 brw_add_validated_bo(brw
, brw_surface(zsbuf
)->bo
);
239 static int emit_depthbuffer(struct brw_context
*brw
)
241 struct pipe_surface
*surface
= brw
->curr
.fb
.zsbuf
;
242 unsigned int len
= (brw
->is_g4x
|| brw
->gen
== 5) ? 6 : 5;
244 if (surface
== NULL
) {
245 BEGIN_BATCH(len
, IGNORE_CLIPRECTS
);
246 OUT_BATCH(CMD_DEPTH_BUFFER
<< 16 | (len
- 2));
247 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT
<< 18) |
248 (BRW_SURFACE_NULL
<< 29));
253 if (brw
->is_g4x
|| brw
->gen
== 5)
258 struct brw_winsys_buffer
*bo
;
263 switch (surface
->format
) {
264 case PIPE_FORMAT_Z16_UNORM
:
265 format
= BRW_DEPTHFORMAT_D16_UNORM
;
268 case PIPE_FORMAT_Z24X8_UNORM
:
269 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
270 format
= BRW_DEPTHFORMAT_D24_UNORM_S8_UINT
;
273 case PIPE_FORMAT_Z32_FLOAT
:
274 format
= BRW_DEPTHFORMAT_D32_FLOAT
;
279 return PIPE_ERROR_BAD_INPUT
;
282 bo
= brw_surface(surface
)->bo
;
283 pitch
= brw_surface(surface
)->pitch
;
285 BEGIN_BATCH(len
, IGNORE_CLIPRECTS
);
286 OUT_BATCH(CMD_DEPTH_BUFFER
<< 16 | (len
- 2));
287 OUT_BATCH(((pitch
* cpp
) - 1) |
289 (BRW_TILEWALK_YMAJOR
<< 26) |
291 ((surface->layout != PIPE_SURFACE_LAYOUT_LINEAR) << 27) |*/
292 (BRW_SURFACE_2D
<< 29));
294 BRW_USAGE_DEPTH_BUFFER
,
295 brw_surface(surface
)->offset
);
296 OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< 1) |
298 ((surface
->height
- 1) << 19));
301 if (brw
->is_g4x
|| brw
->gen
== 5)
310 const struct brw_tracked_state brw_depthbuffer
= {
312 .mesa
= PIPE_NEW_DEPTH_BUFFER
,
313 .brw
= BRW_NEW_BATCH
,
316 .prepare
= prepare_depthbuffer
,
317 .emit
= emit_depthbuffer
,
322 /***********************************************************************
323 * Polygon stipple packet
326 static int upload_polygon_stipple(struct brw_context
*brw
)
328 BRW_CACHED_BATCH_STRUCT(brw
, &brw
->curr
.bps
);
332 const struct brw_tracked_state brw_polygon_stipple
= {
334 .mesa
= PIPE_NEW_POLYGON_STIPPLE
,
338 .emit
= upload_polygon_stipple
342 /***********************************************************************
343 * Line stipple packet
346 static int upload_line_stipple(struct brw_context
*brw
)
348 const struct brw_line_stipple
*bls
= &brw
->curr
.rast
->bls
;
349 if (bls
->header
.opcode
) {
350 BRW_CACHED_BATCH_STRUCT(brw
, bls
);
355 const struct brw_tracked_state brw_line_stipple
= {
357 .mesa
= PIPE_NEW_RAST
,
361 .emit
= upload_line_stipple
365 /***********************************************************************
366 * Misc invariant state packets
369 static int upload_invariant_state( struct brw_context
*brw
)
372 /* 0x61040000 Pipeline Select */
373 /* PipelineSelect : 0 */
374 struct brw_pipeline_select ps
;
376 memset(&ps
, 0, sizeof(ps
));
377 if (brw
->is_g4x
|| brw
->gen
== 5)
378 ps
.header
.opcode
= CMD_PIPELINE_SELECT_GM45
;
380 ps
.header
.opcode
= CMD_PIPELINE_SELECT_965
;
381 ps
.header
.pipeline_select
= 0;
382 BRW_BATCH_STRUCT(brw
, &ps
);
386 struct brw_global_depth_offset_clamp gdo
;
387 memset(&gdo
, 0, sizeof(gdo
));
389 /* Disable depth offset clamping.
391 gdo
.header
.opcode
= CMD_GLOBAL_DEPTH_OFFSET_CLAMP
;
392 gdo
.header
.length
= sizeof(gdo
)/4 - 2;
393 gdo
.depth_offset_clamp
= 0.0;
395 BRW_BATCH_STRUCT(brw
, &gdo
);
399 /* 0x61020000 State Instruction Pointer */
401 struct brw_system_instruction_pointer sip
;
402 memset(&sip
, 0, sizeof(sip
));
404 sip
.header
.opcode
= CMD_STATE_INSN_POINTER
;
405 sip
.header
.length
= 0;
407 sip
.bits0
.system_instruction_pointer
= 0;
408 BRW_BATCH_STRUCT(brw
, &sip
);
413 struct brw_vf_statistics vfs
;
414 memset(&vfs
, 0, sizeof(vfs
));
416 if (brw
->is_g4x
|| brw
->gen
== 5)
417 vfs
.opcode
= CMD_VF_STATISTICS_GM45
;
419 vfs
.opcode
= CMD_VF_STATISTICS_965
;
421 if (BRW_DEBUG
& DEBUG_STATS
)
422 vfs
.statistics_enable
= 1;
424 BRW_BATCH_STRUCT(brw
, &vfs
);
427 if (!(brw
->gen
== 4))
429 struct brw_aa_line_parameters balp
;
431 /* use legacy aa line coverage computation */
432 memset(&balp
, 0, sizeof(balp
));
433 balp
.header
.opcode
= CMD_AA_LINE_PARAMETERS
;
434 balp
.header
.length
= sizeof(balp
) / 4 - 2;
436 BRW_BATCH_STRUCT(brw
, &balp
);
440 struct brw_polygon_stipple_offset bpso
;
442 /* This is invariant state in gallium:
444 memset(&bpso
, 0, sizeof(bpso
));
445 bpso
.header
.opcode
= CMD_POLY_STIPPLE_OFFSET
;
446 bpso
.header
.length
= sizeof(bpso
)/4-2;
447 bpso
.bits0
.y_offset
= 0;
448 bpso
.bits0
.x_offset
= 0;
450 BRW_BATCH_STRUCT(brw
, &bpso
);
456 const struct brw_tracked_state brw_invariant_state
= {
459 .brw
= BRW_NEW_CONTEXT
,
462 .emit
= upload_invariant_state
466 /***********************************************************************
471 * Define the base addresses which some state is referenced from.
473 * This allows us to avoid having to emit relocations in many places for
474 * cached state, and instead emit pointers inside of large, mostly-static
475 * state pools. This comes at the expense of memory, and more expensive cache
478 static int upload_state_base_address( struct brw_context
*brw
)
480 /* Output the structure (brw_state_base_address) directly to the
481 * batchbuffer, so we can emit relocations inline.
484 BEGIN_BATCH(8, IGNORE_CLIPRECTS
);
485 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (8 - 2));
486 OUT_BATCH(1); /* General state base address */
487 OUT_BATCH(1); /* Surface state base address */
488 OUT_BATCH(1); /* Indirect object base address */
489 OUT_BATCH(1); /* Instruction base address */
490 OUT_BATCH(1); /* General state upper bound */
491 OUT_BATCH(1); /* Indirect object upper bound */
492 OUT_BATCH(1); /* Instruction access upper bound */
495 BEGIN_BATCH(6, IGNORE_CLIPRECTS
);
496 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (6 - 2));
497 OUT_BATCH(1); /* General state base address */
498 OUT_BATCH(1); /* Surface state base address */
499 OUT_BATCH(1); /* Indirect object base address */
500 OUT_BATCH(1); /* General state upper bound */
501 OUT_BATCH(1); /* Indirect object upper bound */
507 const struct brw_tracked_state brw_state_base_address
= {
510 .brw
= BRW_NEW_CONTEXT
,
513 .emit
= upload_state_base_address