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>
32 #include "brw_batch.h"
33 #include "brw_context.h"
34 #include "brw_state.h"
35 #include "brw_defines.h"
41 /***********************************************************************
45 static void upload_blend_constant_color(struct brw_context
*brw
)
47 struct brw_blend_constant_color bcc
;
49 memset(&bcc
, 0, sizeof(bcc
));
50 bcc
.header
.opcode
= CMD_BLEND_CONSTANT_COLOR
;
51 bcc
.header
.length
= sizeof(bcc
)/4-2;
52 bcc
.blend_constant_color
[0] = brw
->attribs
.BlendColor
.color
[0];
53 bcc
.blend_constant_color
[1] = brw
->attribs
.BlendColor
.color
[1];
54 bcc
.blend_constant_color
[2] = brw
->attribs
.BlendColor
.color
[2];
55 bcc
.blend_constant_color
[3] = brw
->attribs
.BlendColor
.color
[3];
57 BRW_CACHED_BATCH_STRUCT(brw
, &bcc
);
61 const struct brw_tracked_state brw_blend_constant_color
= {
66 .update
= upload_blend_constant_color
70 /***********************************************************************
73 static void upload_drawing_rect(struct brw_context
*brw
)
75 struct brw_drawrect bdr
;
77 memset(&bdr
, 0, sizeof(bdr
));
78 bdr
.header
.opcode
= CMD_DRAW_RECT
;
79 bdr
.header
.length
= sizeof(bdr
)/4 - 2;
82 bdr
.xmax
= brw
->attribs
.FrameBuffer
.cbufs
[0]->width
;
83 bdr
.ymax
= brw
->attribs
.FrameBuffer
.cbufs
[0]->height
;
87 /* Can't use BRW_CACHED_BATCH_STRUCT because this is also emitted
88 * uncached in brw_draw.c:
90 BRW_BATCH_STRUCT(brw
, &bdr
);
93 const struct brw_tracked_state brw_drawing_rect
= {
98 .update
= upload_drawing_rect
102 * Upload the binding table pointers, which point each stage's array of surface
105 * The binding table pointers are relative to the surface state base address,
106 * which is the BRW_SS_POOL cache buffer.
108 static void upload_binding_table_pointers(struct brw_context
*brw
)
110 struct brw_binding_table_pointers btp
;
111 memset(&btp
, 0, sizeof(btp
));
113 btp
.header
.opcode
= CMD_BINDING_TABLE_PTRS
;
114 btp
.header
.length
= sizeof(btp
)/4 - 2;
119 btp
.wm
= brw
->wm
.bind_ss_offset
;
121 BRW_CACHED_BATCH_STRUCT(brw
, &btp
);
124 const struct brw_tracked_state brw_binding_table_pointers
= {
127 .cache
= CACHE_NEW_SURF_BIND
129 .update
= upload_binding_table_pointers
,
134 * Upload pointers to the per-stage state.
136 * The state pointers in this packet are all relative to the general state
137 * base address set by CMD_STATE_BASE_ADDRESS, which is the BRW_GS_POOL buffer.
139 static void upload_pipelined_state_pointers(struct brw_context
*brw
)
141 struct brw_pipelined_state_pointers psp
;
142 memset(&psp
, 0, sizeof(psp
));
144 psp
.header
.opcode
= CMD_PIPELINED_STATE_POINTERS
;
145 psp
.header
.length
= sizeof(psp
)/4 - 2;
147 psp
.vs
.offset
= brw
->vs
.state_gs_offset
>> 5;
148 psp
.sf
.offset
= brw
->sf
.state_gs_offset
>> 5;
149 psp
.wm
.offset
= brw
->wm
.state_gs_offset
>> 5;
150 psp
.cc
.offset
= brw
->cc
.state_gs_offset
>> 5;
152 /* GS gets turned on and off regularly. Need to re-emit URB fence
155 if (brw
->gs
.prog_active
) {
156 psp
.gs
.offset
= brw
->gs
.state_gs_offset
>> 5;
161 psp
.clp
.offset
= brw
->clip
.state_gs_offset
>> 5;
166 if (BRW_CACHED_BATCH_STRUCT(brw
, &psp
))
167 brw
->state
.dirty
.brw
|= BRW_NEW_PSP
;
170 const struct brw_tracked_state brw_pipelined_state_pointers
= {
173 .cache
= (CACHE_NEW_VS_UNIT
|
176 CACHE_NEW_CLIP_UNIT
|
181 .update
= upload_pipelined_state_pointers
184 static void upload_psp_urb_cbs(struct brw_context
*brw
)
186 upload_pipelined_state_pointers(brw
);
187 brw_upload_urb_fence(brw
);
188 brw_upload_constant_buffer_state(brw
);
192 const struct brw_tracked_state brw_psp_urb_cbs
= {
194 .brw
= BRW_NEW_URB_FENCE
,
195 .cache
= (CACHE_NEW_VS_UNIT
|
198 CACHE_NEW_CLIP_UNIT
|
203 .update
= upload_psp_urb_cbs
207 * Upload the depthbuffer offset and format.
209 * We have to do this per state validation as we need to emit the relocation
210 * in the batch buffer.
212 static void upload_depthbuffer(struct brw_context
*brw
)
214 struct pipe_surface
*depth_surface
= brw
->attribs
.FrameBuffer
.zsbuf
;
216 BEGIN_BATCH(5, INTEL_BATCH_NO_CLIPRECTS
);
217 OUT_BATCH(CMD_DEPTH_BUFFER
<< 16 | (5 - 2));
218 if (depth_surface
== NULL
) {
219 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT
<< 18) |
220 (BRW_SURFACE_NULL
<< 29));
226 struct brw_texture
*tex
= (struct brw_texture
*)depth_surface
->texture
;
227 assert(depth_surface
->block
.width
== 1);
228 assert(depth_surface
->block
.height
== 1);
229 switch (depth_surface
->block
.size
) {
231 format
= BRW_DEPTHFORMAT_D16_UNORM
;
234 if (depth_surface
->format
== PIPE_FORMAT_Z32_FLOAT
)
235 format
= BRW_DEPTHFORMAT_D32_FLOAT
;
237 format
= BRW_DEPTHFORMAT_D24_UNORM_S8_UINT
;
244 OUT_BATCH((depth_surface
->stride
- 1) |
246 (BRW_TILEWALK_YMAJOR
<< 26) |
247 // (depth_surface->region->tiled << 27) |
248 (BRW_SURFACE_2D
<< 29));
249 OUT_RELOC(tex
->buffer
,
250 PIPE_BUFFER_USAGE_GPU_READ
| PIPE_BUFFER_USAGE_GPU_WRITE
, 0);
251 OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< 1) |
252 ((depth_surface
->stride
/depth_surface
->block
.size
- 1) << 6) |
253 ((depth_surface
->height
- 1) << 19));
259 const struct brw_tracked_state brw_depthbuffer
= {
261 .brw
= BRW_NEW_SCENE
,
264 .update
= upload_depthbuffer
,
270 /***********************************************************************
271 * Polygon stipple packet
274 static void upload_polygon_stipple(struct brw_context
*brw
)
276 struct brw_polygon_stipple bps
;
279 memset(&bps
, 0, sizeof(bps
));
280 bps
.header
.opcode
= CMD_POLY_STIPPLE_PATTERN
;
281 bps
.header
.length
= sizeof(bps
)/4-2;
283 /* XXX: state tracker should send *all* state down initially!
285 if (brw
->attribs
.PolygonStipple
)
286 for (i
= 0; i
< 32; i
++)
287 bps
.stipple
[i
] = brw
->attribs
.PolygonStipple
->stipple
[31 - i
]; /* invert */
289 BRW_CACHED_BATCH_STRUCT(brw
, &bps
);
292 const struct brw_tracked_state brw_polygon_stipple
= {
294 .brw
= BRW_NEW_STIPPLE
,
297 .update
= upload_polygon_stipple
301 /***********************************************************************
302 * Line stipple packet
305 static void upload_line_stipple(struct brw_context
*brw
)
307 struct brw_line_stipple bls
;
311 memset(&bls
, 0, sizeof(bls
));
312 bls
.header
.opcode
= CMD_LINE_STIPPLE_PATTERN
;
313 bls
.header
.length
= sizeof(bls
)/4 - 2;
315 bls
.bits0
.pattern
= brw
->attribs
.Raster
->line_stipple_pattern
;
316 bls
.bits1
.repeat_count
= brw
->attribs
.Raster
->line_stipple_factor
;
318 tmp
= 1.0 / (float) brw
->attribs
.Raster
->line_stipple_factor
;
319 tmpi
= tmp
* (1<<13);
322 bls
.bits1
.inverse_repeat_count
= tmpi
;
324 BRW_CACHED_BATCH_STRUCT(brw
, &bls
);
327 const struct brw_tracked_state brw_line_stipple
= {
329 .brw
= BRW_NEW_STIPPLE
,
332 .update
= upload_line_stipple
336 /***********************************************************************
337 * Misc constant state packets
340 static void upload_pipe_control(struct brw_context
*brw
)
342 struct brw_pipe_control pc
;
346 memset(&pc
, 0, sizeof(pc
));
348 pc
.header
.opcode
= CMD_PIPE_CONTROL
;
349 pc
.header
.length
= sizeof(pc
)/4 - 2;
350 pc
.header
.post_sync_operation
= PIPE_CONTROL_NOWRITE
;
352 pc
.header
.instruction_state_cache_flush_enable
= 1;
354 pc
.bits1
.dest_addr_type
= PIPE_CONTROL_GTTWRITE_GLOBAL
;
356 BRW_BATCH_STRUCT(brw
, &pc
);
359 const struct brw_tracked_state brw_pipe_control
= {
361 .brw
= BRW_NEW_SCENE
,
364 .update
= upload_pipe_control
368 /***********************************************************************
369 * Misc invarient state packets
372 static void upload_invarient_state( struct brw_context
*brw
)
375 struct brw_mi_flush flush
;
377 memset(&flush
, 0, sizeof(flush
));
378 flush
.opcode
= CMD_MI_FLUSH
;
379 flush
.flags
= BRW_FLUSH_STATE_CACHE
| BRW_FLUSH_READ_CACHE
;
380 BRW_BATCH_STRUCT(brw
, &flush
);
384 /* 0x61040000 Pipeline Select */
385 /* PipelineSelect : 0 */
386 struct brw_pipeline_select ps
;
388 memset(&ps
, 0, sizeof(ps
));
389 ps
.header
.opcode
= CMD_PIPELINE_SELECT
;
390 ps
.header
.pipeline_select
= 0;
391 BRW_BATCH_STRUCT(brw
, &ps
);
395 struct brw_global_depth_offset_clamp gdo
;
396 memset(&gdo
, 0, sizeof(gdo
));
398 /* Disable depth offset clamping.
400 gdo
.header
.opcode
= CMD_GLOBAL_DEPTH_OFFSET_CLAMP
;
401 gdo
.header
.length
= sizeof(gdo
)/4 - 2;
402 gdo
.depth_offset_clamp
= 0.0;
404 BRW_BATCH_STRUCT(brw
, &gdo
);
408 /* 0x61020000 State Instruction Pointer */
410 struct brw_system_instruction_pointer sip
;
411 memset(&sip
, 0, sizeof(sip
));
413 sip
.header
.opcode
= CMD_STATE_INSN_POINTER
;
414 sip
.header
.length
= 0;
416 sip
.bits0
.system_instruction_pointer
= 0;
417 BRW_BATCH_STRUCT(brw
, &sip
);
422 struct brw_vf_statistics vfs
;
423 memset(&vfs
, 0, sizeof(vfs
));
425 vfs
.opcode
= CMD_VF_STATISTICS
;
426 if (BRW_DEBUG
& DEBUG_STATS
)
427 vfs
.statistics_enable
= 1;
429 BRW_BATCH_STRUCT(brw
, &vfs
);
434 struct brw_polygon_stipple_offset bpso
;
436 memset(&bpso
, 0, sizeof(bpso
));
437 bpso
.header
.opcode
= CMD_POLY_STIPPLE_OFFSET
;
438 bpso
.header
.length
= sizeof(bpso
)/4-2;
439 bpso
.bits0
.x_offset
= 0;
440 bpso
.bits0
.y_offset
= 0;
442 BRW_BATCH_STRUCT(brw
, &bpso
);
446 const struct brw_tracked_state brw_invarient_state
= {
448 .brw
= BRW_NEW_SCENE
,
451 .update
= upload_invarient_state
455 * Define the base addresses which some state is referenced from.
457 * This allows us to avoid having to emit relocations in many places for
458 * cached state, and instead emit pointers inside of large, mostly-static
459 * state pools. This comes at the expense of memory, and more expensive cache
462 static void upload_state_base_address( struct brw_context
*brw
)
464 /* Output the structure (brw_state_base_address) directly to the
465 * batchbuffer, so we can emit relocations inline.
467 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
468 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (6 - 2));
469 OUT_RELOC(brw
->pool
[BRW_GS_POOL
].buffer
,
470 PIPE_BUFFER_USAGE_GPU_READ
,
471 1); /* General state base address */
472 OUT_RELOC(brw
->pool
[BRW_SS_POOL
].buffer
,
473 PIPE_BUFFER_USAGE_GPU_READ
,
474 1); /* Surface state base address */
475 OUT_BATCH(1); /* Indirect object base address */
476 OUT_BATCH(1); /* General state upper bound */
477 OUT_BATCH(1); /* Indirect object upper bound */
482 const struct brw_tracked_state brw_state_base_address
= {
484 .brw
= BRW_NEW_SCENE
,
487 .update
= upload_state_base_address