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 "intel_batchbuffer.h"
35 #include "intel_regions.h"
37 #include "brw_context.h"
38 #include "brw_state.h"
39 #include "brw_defines.h"
41 /* Constant single cliprect for framebuffer object or DRI2 drawing */
42 static void upload_drawing_rect(struct brw_context
*brw
)
44 struct intel_context
*intel
= &brw
->intel
;
45 struct gl_context
*ctx
= &intel
->ctx
;
48 OUT_BATCH(_3DSTATE_DRAWRECT_INFO_I965
);
49 OUT_BATCH(0); /* xmin, ymin */
50 OUT_BATCH(((ctx
->DrawBuffer
->Width
- 1) & 0xffff) |
51 ((ctx
->DrawBuffer
->Height
- 1) << 16));
56 const struct brw_tracked_state brw_drawing_rect
= {
59 .brw
= BRW_NEW_CONTEXT
,
62 .emit
= upload_drawing_rect
66 * Upload the binding table pointers, which point each stage's array of surface
69 * The binding table pointers are relative to the surface state base address,
70 * which points at the batchbuffer containing the streamed batch state.
72 static void upload_binding_table_pointers(struct brw_context
*brw
)
74 struct intel_context
*intel
= &brw
->intel
;
77 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 | (6 - 2));
78 OUT_BATCH(brw
->vs
.bind_bo_offset
);
79 OUT_BATCH(0); /* gs */
80 OUT_BATCH(0); /* clip */
81 OUT_BATCH(0); /* sf */
82 OUT_BATCH(brw
->wm
.bind_bo_offset
);
86 const struct brw_tracked_state brw_binding_table_pointers
= {
89 .brw
= BRW_NEW_BATCH
| BRW_NEW_BINDING_TABLE
,
92 .emit
= upload_binding_table_pointers
,
96 * Upload the binding table pointers, which point each stage's array of surface
99 * The binding table pointers are relative to the surface state base address,
100 * which points at the batchbuffer containing the streamed batch state.
102 static void upload_gen6_binding_table_pointers(struct brw_context
*brw
)
104 struct intel_context
*intel
= &brw
->intel
;
107 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 |
108 GEN6_BINDING_TABLE_MODIFY_VS
|
109 GEN6_BINDING_TABLE_MODIFY_GS
|
110 GEN6_BINDING_TABLE_MODIFY_PS
|
112 OUT_BATCH(brw
->vs
.bind_bo_offset
); /* vs */
113 OUT_BATCH(0); /* gs */
114 OUT_BATCH(brw
->wm
.bind_bo_offset
); /* wm/ps */
118 const struct brw_tracked_state gen6_binding_table_pointers
= {
121 .brw
= BRW_NEW_BATCH
| BRW_NEW_BINDING_TABLE
,
124 .emit
= upload_gen6_binding_table_pointers
,
128 * Upload pointers to the per-stage state.
130 * The state pointers in this packet are all relative to the general state
131 * base address set by CMD_STATE_BASE_ADDRESS, which is 0.
133 static void upload_pipelined_state_pointers(struct brw_context
*brw
)
135 struct intel_context
*intel
= &brw
->intel
;
137 if (intel
->gen
== 5) {
138 /* Need to flush before changing clip max threads for errata. */
145 OUT_BATCH(_3DSTATE_PIPELINED_POINTERS
<< 16 | (7 - 2));
146 OUT_RELOC(intel
->batch
.bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0,
147 brw
->vs
.state_offset
);
148 if (brw
->gs
.prog_active
)
149 OUT_RELOC(brw
->gs
.state_bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0, 1);
152 OUT_RELOC(brw
->clip
.state_bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0, 1);
153 OUT_RELOC(brw
->intel
.batch
.bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0,
154 brw
->sf
.state_offset
);
155 OUT_RELOC(brw
->intel
.batch
.bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0,
156 brw
->wm
.state_offset
);
157 OUT_RELOC(brw
->intel
.batch
.bo
, I915_GEM_DOMAIN_INSTRUCTION
, 0,
158 brw
->cc
.state_offset
);
161 brw
->state
.dirty
.brw
|= BRW_NEW_PSP
;
165 static void prepare_psp_urb_cbs(struct brw_context
*brw
)
167 brw_add_validated_bo(brw
, brw
->gs
.state_bo
);
168 brw_add_validated_bo(brw
, brw
->clip
.state_bo
);
171 static void upload_psp_urb_cbs(struct brw_context
*brw
)
173 upload_pipelined_state_pointers(brw
);
174 brw_upload_urb_fence(brw
);
175 brw_upload_cs_urb_state(brw
);
178 const struct brw_tracked_state brw_psp_urb_cbs
= {
181 .brw
= BRW_NEW_URB_FENCE
| BRW_NEW_BATCH
,
182 .cache
= (CACHE_NEW_VS_UNIT
|
185 CACHE_NEW_CLIP_UNIT
|
190 .prepare
= prepare_psp_urb_cbs
,
191 .emit
= upload_psp_urb_cbs
,
194 static void prepare_depthbuffer(struct brw_context
*brw
)
196 struct intel_region
*region
= brw
->state
.depth_region
;
199 brw_add_validated_bo(brw
, region
->buffer
);
202 static void emit_depthbuffer(struct brw_context
*brw
)
204 struct intel_context
*intel
= &brw
->intel
;
205 struct intel_region
*region
= brw
->state
.depth_region
;
210 else if (intel
->is_g4x
|| intel
->gen
== 5)
215 if (region
== NULL
) {
217 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (len
- 2));
218 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT
<< 18) |
219 (BRW_SURFACE_NULL
<< 29));
224 if (intel
->is_g4x
|| intel
->gen
>= 5)
234 switch (region
->cpp
) {
236 format
= BRW_DEPTHFORMAT_D16_UNORM
;
239 if (intel
->depth_buffer_is_float
)
240 format
= BRW_DEPTHFORMAT_D32_FLOAT
;
242 format
= BRW_DEPTHFORMAT_D24_UNORM_S8_UINT
;
249 assert(region
->tiling
!= I915_TILING_X
);
250 assert(intel
->gen
< 6 || region
->tiling
== I915_TILING_Y
);
253 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (len
- 2));
254 OUT_BATCH(((region
->pitch
* region
->cpp
) - 1) |
256 (BRW_TILEWALK_YMAJOR
<< 26) |
257 ((region
->tiling
!= I915_TILING_NONE
) << 27) |
258 (BRW_SURFACE_2D
<< 29));
259 OUT_RELOC(region
->buffer
,
260 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
262 OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< 1) |
263 ((region
->width
- 1) << 6) |
264 ((region
->height
- 1) << 19));
267 if (intel
->is_g4x
|| intel
->gen
>= 5)
276 /* Initialize it for safety. */
277 if (intel
->gen
>= 6) {
279 OUT_BATCH(_3DSTATE_CLEAR_PARAMS
<< 16 | (2 - 2));
286 * \see brw_context.state.depth_region
288 const struct brw_tracked_state brw_depthbuffer
= {
291 .brw
= BRW_NEW_DEPTH_BUFFER
| BRW_NEW_BATCH
,
294 .prepare
= prepare_depthbuffer
,
295 .emit
= emit_depthbuffer
,
300 /***********************************************************************
301 * Polygon stipple packet
304 static void upload_polygon_stipple(struct brw_context
*brw
)
306 struct intel_context
*intel
= &brw
->intel
;
307 struct gl_context
*ctx
= &brw
->intel
.ctx
;
310 if (!ctx
->Polygon
.StippleFlag
)
314 OUT_BATCH(_3DSTATE_POLY_STIPPLE_PATTERN
<< 16 | (33 - 2));
316 /* Polygon stipple is provided in OpenGL order, i.e. bottom
317 * row first. If we're rendering to a window (i.e. the
318 * default frame buffer object, 0), then we need to invert
319 * it to match our pixel layout. But if we're rendering
320 * to a FBO (i.e. any named frame buffer object), we *don't*
321 * need to invert - we already match the layout.
323 if (ctx
->DrawBuffer
->Name
== 0) {
324 for (i
= 0; i
< 32; i
++)
325 OUT_BATCH(ctx
->PolygonStipple
[31 - i
]); /* invert */
328 for (i
= 0; i
< 32; i
++)
329 OUT_BATCH(ctx
->PolygonStipple
[i
]);
334 const struct brw_tracked_state brw_polygon_stipple
= {
336 .mesa
= _NEW_POLYGONSTIPPLE
,
337 .brw
= BRW_NEW_CONTEXT
,
340 .emit
= upload_polygon_stipple
344 /***********************************************************************
345 * Polygon stipple offset packet
348 static void upload_polygon_stipple_offset(struct brw_context
*brw
)
350 struct intel_context
*intel
= &brw
->intel
;
351 struct gl_context
*ctx
= &brw
->intel
.ctx
;
353 if (!ctx
->Polygon
.StippleFlag
)
357 OUT_BATCH(_3DSTATE_POLY_STIPPLE_OFFSET
<< 16 | (2-2));
359 /* If we're drawing to a system window (ctx->DrawBuffer->Name == 0),
360 * we have to invert the Y axis in order to match the OpenGL
361 * pixel coordinate system, and our offset must be matched
362 * to the window position. If we're drawing to a FBO
363 * (ctx->DrawBuffer->Name != 0), then our native pixel coordinate
364 * system works just fine, and there's no window system to
367 if (brw
->intel
.ctx
.DrawBuffer
->Name
== 0)
368 OUT_BATCH((32 - (ctx
->DrawBuffer
->Height
& 31)) & 31);
374 #define _NEW_WINDOW_POS 0x40000000
376 const struct brw_tracked_state brw_polygon_stipple_offset
= {
378 .mesa
= _NEW_WINDOW_POS
| _NEW_POLYGONSTIPPLE
,
379 .brw
= BRW_NEW_CONTEXT
,
382 .emit
= upload_polygon_stipple_offset
385 /**********************************************************************
388 static void upload_aa_line_parameters(struct brw_context
*brw
)
390 struct intel_context
*intel
= &brw
->intel
;
391 struct gl_context
*ctx
= &brw
->intel
.ctx
;
393 if (!ctx
->Line
.SmoothFlag
|| !brw
->has_aa_line_parameters
)
396 OUT_BATCH(_3DSTATE_AA_LINE_PARAMETERS
<< 16 | (3 - 2));
397 /* use legacy aa line coverage computation */
403 const struct brw_tracked_state brw_aa_line_parameters
= {
406 .brw
= BRW_NEW_CONTEXT
,
409 .emit
= upload_aa_line_parameters
412 /***********************************************************************
413 * Line stipple packet
416 static void upload_line_stipple(struct brw_context
*brw
)
418 struct intel_context
*intel
= &brw
->intel
;
419 struct gl_context
*ctx
= &brw
->intel
.ctx
;
423 if (!ctx
->Line
.StippleFlag
)
427 OUT_BATCH(_3DSTATE_LINE_STIPPLE_PATTERN
<< 16 | (3 - 2));
428 OUT_BATCH(ctx
->Line
.StipplePattern
);
429 tmp
= 1.0 / (GLfloat
) ctx
->Line
.StippleFactor
;
430 tmpi
= tmp
* (1<<13);
431 OUT_BATCH(tmpi
<< 16 | ctx
->Line
.StippleFactor
);
435 const struct brw_tracked_state brw_line_stipple
= {
438 .brw
= BRW_NEW_CONTEXT
,
441 .emit
= upload_line_stipple
445 /***********************************************************************
446 * Misc invarient state packets
449 static void upload_invarient_state( struct brw_context
*brw
)
451 struct intel_context
*intel
= &brw
->intel
;
454 /* 0x61040000 Pipeline Select */
455 /* PipelineSelect : 0 */
456 struct brw_pipeline_select ps
;
458 memset(&ps
, 0, sizeof(ps
));
459 ps
.header
.opcode
= brw
->CMD_PIPELINE_SELECT
;
460 ps
.header
.pipeline_select
= 0;
461 BRW_BATCH_STRUCT(brw
, &ps
);
464 if (intel
->gen
< 6) {
465 struct brw_global_depth_offset_clamp gdo
;
466 memset(&gdo
, 0, sizeof(gdo
));
468 /* Disable depth offset clamping.
470 gdo
.header
.opcode
= _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP
;
471 gdo
.header
.length
= sizeof(gdo
)/4 - 2;
472 gdo
.depth_offset_clamp
= 0.0;
474 BRW_BATCH_STRUCT(brw
, &gdo
);
477 if (intel
->gen
>= 6) {
481 OUT_BATCH(_3DSTATE_MULTISAMPLE
<< 16 | (3 - 2));
482 OUT_BATCH(MS_PIXEL_LOCATION_CENTER
|
484 OUT_BATCH(0); /* positions for 4/8-sample */
488 OUT_BATCH(_3DSTATE_SAMPLE_MASK
<< 16 | (2 - 2));
492 for (i
= 0; i
< 4; i
++) {
494 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
495 OUT_BATCH(i
<< SVB_INDEX_SHIFT
);
497 OUT_BATCH(0xffffffff);
502 /* 0x61020000 State Instruction Pointer */
504 struct brw_system_instruction_pointer sip
;
505 memset(&sip
, 0, sizeof(sip
));
507 sip
.header
.opcode
= CMD_STATE_INSN_POINTER
;
508 sip
.header
.length
= 0;
510 sip
.bits0
.system_instruction_pointer
= 0;
511 BRW_BATCH_STRUCT(brw
, &sip
);
516 struct brw_vf_statistics vfs
;
517 memset(&vfs
, 0, sizeof(vfs
));
519 vfs
.opcode
= brw
->CMD_VF_STATISTICS
;
520 if (unlikely(INTEL_DEBUG
& DEBUG_STATS
))
521 vfs
.statistics_enable
= 1;
523 BRW_BATCH_STRUCT(brw
, &vfs
);
527 const struct brw_tracked_state brw_invarient_state
= {
530 .brw
= BRW_NEW_CONTEXT
,
533 .emit
= upload_invarient_state
537 * Define the base addresses which some state is referenced from.
539 * This allows us to avoid having to emit relocations for the objects,
540 * and is actually required for binding table pointers on gen6.
542 * Surface state base address covers binding table pointers and
543 * surface state objects, but not the surfaces that the surface state
546 static void upload_state_base_address( struct brw_context
*brw
)
548 struct intel_context
*intel
= &brw
->intel
;
550 if (intel
->gen
>= 6) {
552 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (10 - 2));
553 /* General state base address: stateless DP read/write requests */
555 /* Surface state base address:
556 * BINDING_TABLE_STATE
559 OUT_RELOC(intel
->batch
.bo
, I915_GEM_DOMAIN_SAMPLER
, 0, 1);
560 /* Dynamic state base address:
562 * SAMPLER_BORDER_COLOR_STATE
563 * CLIP, SF, WM/CC viewport state
565 * DEPTH_STENCIL_STATE
567 * Push constants (when INSTPM: CONSTANT_BUFFER Address Offset
568 * Disable is clear, which we rely on)
570 OUT_RELOC(intel
->batch
.bo
, (I915_GEM_DOMAIN_RENDER
|
571 I915_GEM_DOMAIN_INSTRUCTION
), 0, 1);
573 OUT_BATCH(1); /* Indirect object base address: MEDIA_OBJECT data */
574 OUT_BATCH(1); /* Instruction base address: shader kernels (incl. SIP) */
575 OUT_BATCH(1); /* General state upper bound */
576 OUT_BATCH(1); /* Dynamic state upper bound */
577 OUT_BATCH(1); /* Indirect object upper bound */
578 OUT_BATCH(1); /* Instruction access upper bound */
580 } else if (intel
->gen
== 5) {
582 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (8 - 2));
583 OUT_BATCH(1); /* General state base address */
584 OUT_RELOC(intel
->batch
.bo
, I915_GEM_DOMAIN_SAMPLER
, 0,
585 1); /* Surface state base address */
586 OUT_BATCH(1); /* Indirect object base address */
587 OUT_BATCH(1); /* Instruction base address */
588 OUT_BATCH(1); /* General state upper bound */
589 OUT_BATCH(1); /* Indirect object upper bound */
590 OUT_BATCH(1); /* Instruction access upper bound */
594 OUT_BATCH(CMD_STATE_BASE_ADDRESS
<< 16 | (6 - 2));
595 OUT_BATCH(1); /* General state base address */
596 OUT_RELOC(intel
->batch
.bo
, I915_GEM_DOMAIN_SAMPLER
, 0,
597 1); /* Surface state base address */
598 OUT_BATCH(1); /* Indirect object base address */
599 OUT_BATCH(1); /* General state upper bound */
600 OUT_BATCH(1); /* Indirect object upper bound */
605 const struct brw_tracked_state brw_state_base_address
= {
608 .brw
= BRW_NEW_BATCH
,
611 .emit
= upload_state_base_address