i965: Remove check for hiz on earlier gens than SNB
[mesa.git] / src / mesa / drivers / dri / i965 / brw_misc_state.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
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:
13
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.
17
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.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32
33
34 #include "intel_batchbuffer.h"
35 #include "intel_fbo.h"
36 #include "intel_mipmap_tree.h"
37
38 #include "brw_context.h"
39 #include "brw_state.h"
40 #include "brw_defines.h"
41
42 #include "main/framebuffer.h"
43 #include "main/fbobject.h"
44 #include "main/glformats.h"
45
46 /* Constant single cliprect for framebuffer object or DRI2 drawing */
47 static void
48 upload_drawing_rect(struct brw_context *brw)
49 {
50 struct gl_context *ctx = &brw->ctx;
51 const struct gl_framebuffer *fb = ctx->DrawBuffer;
52 const unsigned int fb_width = _mesa_geometric_width(fb);
53 const unsigned int fb_height = _mesa_geometric_height(fb);
54
55 BEGIN_BATCH(4);
56 OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE << 16 | (4 - 2));
57 OUT_BATCH(0); /* xmin, ymin */
58 OUT_BATCH(((fb_width - 1) & 0xffff) | ((fb_height - 1) << 16));
59 OUT_BATCH(0);
60 ADVANCE_BATCH();
61 }
62
63 const struct brw_tracked_state brw_drawing_rect = {
64 .dirty = {
65 .mesa = _NEW_BUFFERS,
66 .brw = BRW_NEW_BLORP |
67 BRW_NEW_CONTEXT,
68 },
69 .emit = upload_drawing_rect
70 };
71
72 /**
73 * Upload pointers to the per-stage state.
74 *
75 * The state pointers in this packet are all relative to the general state
76 * base address set by CMD_STATE_BASE_ADDRESS, which is 0.
77 */
78 static void
79 upload_pipelined_state_pointers(struct brw_context *brw)
80 {
81 if (brw->gen == 5) {
82 /* Need to flush before changing clip max threads for errata. */
83 BEGIN_BATCH(1);
84 OUT_BATCH(MI_FLUSH);
85 ADVANCE_BATCH();
86 }
87
88 BEGIN_BATCH(7);
89 OUT_BATCH(_3DSTATE_PIPELINED_POINTERS << 16 | (7 - 2));
90 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
91 brw->vs.base.state_offset);
92 if (brw->ff_gs.prog_active)
93 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
94 brw->ff_gs.state_offset | 1);
95 else
96 OUT_BATCH(0);
97 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
98 brw->clip.state_offset | 1);
99 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
100 brw->sf.state_offset);
101 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
102 brw->wm.base.state_offset);
103 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
104 brw->cc.state_offset);
105 ADVANCE_BATCH();
106
107 brw->ctx.NewDriverState |= BRW_NEW_PSP;
108 }
109
110 static void
111 upload_psp_urb_cbs(struct brw_context *brw)
112 {
113 upload_pipelined_state_pointers(brw);
114 brw_upload_urb_fence(brw);
115 brw_upload_cs_urb_state(brw);
116 }
117
118 const struct brw_tracked_state brw_psp_urb_cbs = {
119 .dirty = {
120 .mesa = 0,
121 .brw = BRW_NEW_BATCH |
122 BRW_NEW_BLORP |
123 BRW_NEW_FF_GS_PROG_DATA |
124 BRW_NEW_GEN4_UNIT_STATE |
125 BRW_NEW_STATE_BASE_ADDRESS |
126 BRW_NEW_URB_FENCE,
127 },
128 .emit = upload_psp_urb_cbs,
129 };
130
131 uint32_t
132 brw_depthbuffer_format(struct brw_context *brw)
133 {
134 struct gl_context *ctx = &brw->ctx;
135 struct gl_framebuffer *fb = ctx->DrawBuffer;
136 struct intel_renderbuffer *drb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
137 struct intel_renderbuffer *srb;
138
139 if (!drb &&
140 (srb = intel_get_renderbuffer(fb, BUFFER_STENCIL)) &&
141 !srb->mt->stencil_mt &&
142 (intel_rb_format(srb) == MESA_FORMAT_Z24_UNORM_S8_UINT ||
143 intel_rb_format(srb) == MESA_FORMAT_Z32_FLOAT_S8X24_UINT)) {
144 drb = srb;
145 }
146
147 if (!drb)
148 return BRW_DEPTHFORMAT_D32_FLOAT;
149
150 return brw_depth_format(brw, drb->mt->format);
151 }
152
153 /**
154 * Returns the mask of how many bits of x and y must be handled through the
155 * depthbuffer's draw offset x and y fields.
156 *
157 * The draw offset x/y field of the depthbuffer packet is unfortunately shared
158 * between the depth, hiz, and stencil buffers. Because it can be hard to get
159 * all 3 to agree on this value, we want to do as much drawing offset
160 * adjustment as possible by moving the base offset of the 3 buffers, which is
161 * restricted to tile boundaries.
162 *
163 * For each buffer, the remainder must be applied through the x/y draw offset.
164 * This returns the worst-case mask of the low bits that have to go into the
165 * packet. If the 3 buffers don't agree on the drawing offset ANDed with this
166 * mask, then we're in trouble.
167 */
168 static void
169 brw_get_depthstencil_tile_masks(struct intel_mipmap_tree *depth_mt,
170 uint32_t depth_level,
171 uint32_t depth_layer,
172 struct intel_mipmap_tree *stencil_mt,
173 uint32_t *out_tile_mask_x,
174 uint32_t *out_tile_mask_y)
175 {
176 uint32_t tile_mask_x = 0, tile_mask_y = 0;
177
178 if (depth_mt) {
179 intel_get_tile_masks(depth_mt->tiling, depth_mt->tr_mode,
180 depth_mt->cpp,
181 &tile_mask_x, &tile_mask_y);
182 assert(!intel_miptree_level_has_hiz(depth_mt, depth_level));
183 }
184
185 if (stencil_mt) {
186 if (stencil_mt->stencil_mt)
187 stencil_mt = stencil_mt->stencil_mt;
188
189 if (stencil_mt->format == MESA_FORMAT_S_UINT8) {
190 /* Separate stencil buffer uses 64x64 tiles. */
191 tile_mask_x |= 63;
192 tile_mask_y |= 63;
193 } else {
194 uint32_t stencil_tile_mask_x, stencil_tile_mask_y;
195 intel_get_tile_masks(stencil_mt->tiling,
196 stencil_mt->tr_mode,
197 stencil_mt->cpp,
198 &stencil_tile_mask_x,
199 &stencil_tile_mask_y);
200
201 tile_mask_x |= stencil_tile_mask_x;
202 tile_mask_y |= stencil_tile_mask_y;
203 }
204 }
205
206 *out_tile_mask_x = tile_mask_x;
207 *out_tile_mask_y = tile_mask_y;
208 }
209
210 static struct intel_mipmap_tree *
211 get_stencil_miptree(struct intel_renderbuffer *irb)
212 {
213 if (!irb)
214 return NULL;
215 if (irb->mt->stencil_mt)
216 return irb->mt->stencil_mt;
217 return irb->mt;
218 }
219
220 void
221 brw_workaround_depthstencil_alignment(struct brw_context *brw,
222 GLbitfield clear_mask)
223 {
224 struct gl_context *ctx = &brw->ctx;
225 struct gl_framebuffer *fb = ctx->DrawBuffer;
226 bool rebase_depth = false;
227 bool rebase_stencil = false;
228 struct intel_renderbuffer *depth_irb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
229 struct intel_renderbuffer *stencil_irb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
230 struct intel_mipmap_tree *depth_mt = NULL;
231 struct intel_mipmap_tree *stencil_mt = get_stencil_miptree(stencil_irb);
232 uint32_t tile_x = 0, tile_y = 0, stencil_tile_x = 0, stencil_tile_y = 0;
233 uint32_t stencil_draw_x = 0, stencil_draw_y = 0;
234 bool invalidate_depth = clear_mask & BUFFER_BIT_DEPTH;
235 bool invalidate_stencil = clear_mask & BUFFER_BIT_STENCIL;
236
237 if (depth_irb)
238 depth_mt = depth_irb->mt;
239
240 /* Initialize brw->depthstencil to 'nop' workaround state.
241 */
242 brw->depthstencil.tile_x = 0;
243 brw->depthstencil.tile_y = 0;
244 brw->depthstencil.depth_offset = 0;
245 brw->depthstencil.stencil_offset = 0;
246 brw->depthstencil.hiz_offset = 0;
247 brw->depthstencil.depth_mt = NULL;
248 brw->depthstencil.stencil_mt = NULL;
249 if (depth_irb)
250 brw->depthstencil.depth_mt = depth_mt;
251 if (stencil_irb)
252 brw->depthstencil.stencil_mt = get_stencil_miptree(stencil_irb);
253
254 /* Gen6+ doesn't require the workarounds, since we always program the
255 * surface state at the start of the whole surface.
256 */
257 if (brw->gen >= 6)
258 return;
259
260 /* Check if depth buffer is in depth/stencil format. If so, then it's only
261 * safe to invalidate it if we're also clearing stencil, and both depth_irb
262 * and stencil_irb point to the same miptree.
263 *
264 * Note: it's not sufficient to check for the case where
265 * _mesa_get_format_base_format(depth_mt->format) == GL_DEPTH_STENCIL,
266 * because this fails to catch depth/stencil buffers on hardware that uses
267 * separate stencil. To catch that case, we check whether
268 * depth_mt->stencil_mt is non-NULL.
269 */
270 if (depth_irb && invalidate_depth &&
271 (_mesa_get_format_base_format(depth_mt->format) == GL_DEPTH_STENCIL ||
272 depth_mt->stencil_mt)) {
273 invalidate_depth = invalidate_stencil && depth_irb && stencil_irb
274 && depth_irb->mt == stencil_irb->mt;
275 }
276
277 uint32_t tile_mask_x, tile_mask_y;
278 brw_get_depthstencil_tile_masks(depth_mt,
279 depth_mt ? depth_irb->mt_level : 0,
280 depth_mt ? depth_irb->mt_layer : 0,
281 stencil_mt,
282 &tile_mask_x, &tile_mask_y);
283
284 if (depth_irb) {
285 tile_x = depth_irb->draw_x & tile_mask_x;
286 tile_y = depth_irb->draw_y & tile_mask_y;
287
288 /* According to the Sandy Bridge PRM, volume 2 part 1, pp326-327
289 * (3DSTATE_DEPTH_BUFFER dw5), in the documentation for "Depth
290 * Coordinate Offset X/Y":
291 *
292 * "The 3 LSBs of both offsets must be zero to ensure correct
293 * alignment"
294 */
295 if (tile_x & 7 || tile_y & 7)
296 rebase_depth = true;
297
298 /* We didn't even have intra-tile offsets before g45. */
299 if (!brw->has_surface_tile_offset) {
300 if (tile_x || tile_y)
301 rebase_depth = true;
302 }
303
304 if (rebase_depth) {
305 perf_debug("HW workaround: blitting depth level %d to a temporary "
306 "to fix alignment (depth tile offset %d,%d)\n",
307 depth_irb->mt_level, tile_x, tile_y);
308 intel_renderbuffer_move_to_temp(brw, depth_irb, invalidate_depth);
309 /* In the case of stencil_irb being the same packed depth/stencil
310 * texture but not the same rb, make it point at our rebased mt, too.
311 */
312 if (stencil_irb &&
313 stencil_irb != depth_irb &&
314 stencil_irb->mt == depth_mt) {
315 intel_miptree_reference(&stencil_irb->mt, depth_irb->mt);
316 intel_renderbuffer_set_draw_offset(stencil_irb);
317 }
318
319 stencil_mt = get_stencil_miptree(stencil_irb);
320
321 tile_x = depth_irb->draw_x & tile_mask_x;
322 tile_y = depth_irb->draw_y & tile_mask_y;
323 }
324
325 if (stencil_irb) {
326 stencil_mt = get_stencil_miptree(stencil_irb);
327 intel_miptree_get_image_offset(stencil_mt,
328 stencil_irb->mt_level,
329 stencil_irb->mt_layer,
330 &stencil_draw_x, &stencil_draw_y);
331 int stencil_tile_x = stencil_draw_x & tile_mask_x;
332 int stencil_tile_y = stencil_draw_y & tile_mask_y;
333
334 /* If stencil doesn't match depth, then we'll need to rebase stencil
335 * as well. (if we hadn't decided to rebase stencil before, the
336 * post-stencil depth test will also rebase depth to try to match it
337 * up).
338 */
339 if (tile_x != stencil_tile_x ||
340 tile_y != stencil_tile_y) {
341 rebase_stencil = true;
342 }
343 }
344 }
345
346 /* If we have (just) stencil, check it for ignored low bits as well */
347 if (stencil_irb) {
348 intel_miptree_get_image_offset(stencil_mt,
349 stencil_irb->mt_level,
350 stencil_irb->mt_layer,
351 &stencil_draw_x, &stencil_draw_y);
352 stencil_tile_x = stencil_draw_x & tile_mask_x;
353 stencil_tile_y = stencil_draw_y & tile_mask_y;
354
355 if (stencil_tile_x & 7 || stencil_tile_y & 7)
356 rebase_stencil = true;
357
358 if (!brw->has_surface_tile_offset) {
359 if (stencil_tile_x || stencil_tile_y)
360 rebase_stencil = true;
361 }
362 }
363
364 if (rebase_stencil) {
365 perf_debug("HW workaround: blitting stencil level %d to a temporary "
366 "to fix alignment (stencil tile offset %d,%d)\n",
367 stencil_irb->mt_level, stencil_tile_x, stencil_tile_y);
368
369 intel_renderbuffer_move_to_temp(brw, stencil_irb, invalidate_stencil);
370 stencil_mt = get_stencil_miptree(stencil_irb);
371
372 intel_miptree_get_image_offset(stencil_mt,
373 stencil_irb->mt_level,
374 stencil_irb->mt_layer,
375 &stencil_draw_x, &stencil_draw_y);
376 stencil_tile_x = stencil_draw_x & tile_mask_x;
377 stencil_tile_y = stencil_draw_y & tile_mask_y;
378
379 if (depth_irb && depth_irb->mt == stencil_irb->mt) {
380 intel_miptree_reference(&depth_irb->mt, stencil_irb->mt);
381 intel_renderbuffer_set_draw_offset(depth_irb);
382 } else if (depth_irb && !rebase_depth) {
383 if (tile_x != stencil_tile_x ||
384 tile_y != stencil_tile_y) {
385 perf_debug("HW workaround: blitting depth level %d to a temporary "
386 "to match stencil level %d alignment (depth tile offset "
387 "%d,%d, stencil offset %d,%d)\n",
388 depth_irb->mt_level,
389 stencil_irb->mt_level,
390 tile_x, tile_y,
391 stencil_tile_x, stencil_tile_y);
392
393 intel_renderbuffer_move_to_temp(brw, depth_irb, invalidate_depth);
394
395 tile_x = depth_irb->draw_x & tile_mask_x;
396 tile_y = depth_irb->draw_y & tile_mask_y;
397
398 if (stencil_irb && stencil_irb->mt == depth_mt) {
399 intel_miptree_reference(&stencil_irb->mt, depth_irb->mt);
400 intel_renderbuffer_set_draw_offset(stencil_irb);
401 }
402
403 WARN_ONCE(stencil_tile_x != tile_x ||
404 stencil_tile_y != tile_y,
405 "Rebased stencil tile offset (%d,%d) doesn't match depth "
406 "tile offset (%d,%d).\n",
407 stencil_tile_x, stencil_tile_y,
408 tile_x, tile_y);
409 }
410 }
411 }
412
413 if (!depth_irb) {
414 tile_x = stencil_tile_x;
415 tile_y = stencil_tile_y;
416 }
417
418 /* While we just tried to get everything aligned, we may have failed to do
419 * so in the case of rendering to array or 3D textures, where nonzero faces
420 * will still have an offset post-rebase. At least give an informative
421 * warning.
422 */
423 WARN_ONCE((tile_x & 7) || (tile_y & 7),
424 "Depth/stencil buffer needs alignment to 8-pixel boundaries.\n"
425 "Truncating offset, bad rendering may occur.\n");
426 tile_x &= ~7;
427 tile_y &= ~7;
428
429 /* Now, after rebasing, save off the new dephtstencil state so the hardware
430 * packets can just dereference that without re-calculating tile offsets.
431 */
432 brw->depthstencil.tile_x = tile_x;
433 brw->depthstencil.tile_y = tile_y;
434 if (depth_irb) {
435 depth_mt = depth_irb->mt;
436 brw->depthstencil.depth_mt = depth_mt;
437 brw->depthstencil.depth_offset =
438 intel_miptree_get_aligned_offset(depth_mt,
439 depth_irb->draw_x & ~tile_mask_x,
440 depth_irb->draw_y & ~tile_mask_y);
441 if (intel_renderbuffer_has_hiz(depth_irb)) {
442 brw->depthstencil.hiz_offset =
443 intel_miptree_get_aligned_offset(depth_mt,
444 depth_irb->draw_x & ~tile_mask_x,
445 (depth_irb->draw_y & ~tile_mask_y) / 2);
446 }
447 }
448 if (stencil_irb) {
449 stencil_mt = get_stencil_miptree(stencil_irb);
450
451 brw->depthstencil.stencil_mt = stencil_mt;
452 if (stencil_mt->format == MESA_FORMAT_S_UINT8) {
453 /* Note: we can't compute the stencil offset using
454 * intel_region_get_aligned_offset(), because stencil_region claims
455 * that the region is untiled even though it's W tiled.
456 */
457 brw->depthstencil.stencil_offset =
458 (stencil_draw_y & ~tile_mask_y) * stencil_mt->pitch +
459 (stencil_draw_x & ~tile_mask_x) * 64;
460 }
461 }
462 }
463
464 void
465 brw_emit_depthbuffer(struct brw_context *brw)
466 {
467 struct gl_context *ctx = &brw->ctx;
468 struct gl_framebuffer *fb = ctx->DrawBuffer;
469 /* _NEW_BUFFERS */
470 struct intel_renderbuffer *depth_irb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
471 struct intel_renderbuffer *stencil_irb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
472 struct intel_mipmap_tree *depth_mt = brw->depthstencil.depth_mt;
473 struct intel_mipmap_tree *stencil_mt = brw->depthstencil.stencil_mt;
474 uint32_t tile_x = brw->depthstencil.tile_x;
475 uint32_t tile_y = brw->depthstencil.tile_y;
476 bool hiz = depth_irb && intel_renderbuffer_has_hiz(depth_irb);
477 bool separate_stencil = false;
478 uint32_t depth_surface_type = BRW_SURFACE_NULL;
479 uint32_t depthbuffer_format = BRW_DEPTHFORMAT_D32_FLOAT;
480 uint32_t depth_offset = 0;
481 uint32_t width = 1, height = 1;
482
483 if (stencil_mt) {
484 separate_stencil = stencil_mt->format == MESA_FORMAT_S_UINT8;
485
486 /* Gen7 supports only separate stencil */
487 assert(separate_stencil || brw->gen < 7);
488 }
489
490 /* If there's a packed depth/stencil bound to stencil only, we need to
491 * emit the packed depth/stencil buffer packet.
492 */
493 if (!depth_irb && stencil_irb && !separate_stencil) {
494 depth_irb = stencil_irb;
495 depth_mt = stencil_mt;
496 }
497
498 if (depth_irb && depth_mt) {
499 /* When 3DSTATE_DEPTH_BUFFER.Separate_Stencil_Enable is set, then
500 * 3DSTATE_DEPTH_BUFFER.Surface_Format is not permitted to be a packed
501 * depthstencil format.
502 *
503 * Gens prior to 7 require that HiZ_Enable and Separate_Stencil_Enable be
504 * set to the same value. Gens after 7 implicitly always set
505 * Separate_Stencil_Enable; software cannot disable it.
506 */
507 if ((brw->gen < 7 && hiz) || brw->gen >= 7) {
508 assert(!_mesa_is_format_packed_depth_stencil(depth_mt->format));
509 }
510
511 /* Prior to Gen7, if using separate stencil, hiz must be enabled. */
512 assert(brw->gen >= 7 || !separate_stencil || hiz);
513
514 assert(brw->gen < 6 || depth_mt->tiling == I915_TILING_Y);
515 assert(!hiz || depth_mt->tiling == I915_TILING_Y);
516
517 depthbuffer_format = brw_depthbuffer_format(brw);
518 depth_surface_type = BRW_SURFACE_2D;
519 depth_offset = brw->depthstencil.depth_offset;
520 width = depth_irb->Base.Base.Width;
521 height = depth_irb->Base.Base.Height;
522 } else if (separate_stencil) {
523 /*
524 * There exists a separate stencil buffer but no depth buffer.
525 *
526 * The stencil buffer inherits most of its fields from
527 * 3DSTATE_DEPTH_BUFFER: namely the tile walk, surface type, width, and
528 * height.
529 *
530 * The tiled bit must be set. From the Sandybridge PRM, Volume 2, Part 1,
531 * Section 7.5.5.1.1 3DSTATE_DEPTH_BUFFER, Bit 1.27 Tiled Surface:
532 * [DevGT+]: This field must be set to TRUE.
533 */
534 assert(brw->has_separate_stencil);
535
536 depth_surface_type = BRW_SURFACE_2D;
537 width = stencil_irb->Base.Base.Width;
538 height = stencil_irb->Base.Base.Height;
539 }
540
541 if (depth_mt)
542 brw_render_cache_set_check_flush(brw, depth_mt->bo);
543 if (stencil_mt)
544 brw_render_cache_set_check_flush(brw, stencil_mt->bo);
545
546 brw->vtbl.emit_depth_stencil_hiz(brw, depth_mt, depth_offset,
547 depthbuffer_format, depth_surface_type,
548 stencil_mt, hiz, separate_stencil,
549 width, height, tile_x, tile_y);
550 }
551
552 void
553 brw_emit_depth_stencil_hiz(struct brw_context *brw,
554 struct intel_mipmap_tree *depth_mt,
555 uint32_t depth_offset, uint32_t depthbuffer_format,
556 uint32_t depth_surface_type,
557 struct intel_mipmap_tree *stencil_mt,
558 bool hiz, bool separate_stencil,
559 uint32_t width, uint32_t height,
560 uint32_t tile_x, uint32_t tile_y)
561 {
562 /* Enable the hiz bit if we're doing separate stencil, because it and the
563 * separate stencil bit must have the same value. From Section 2.11.5.6.1.1
564 * 3DSTATE_DEPTH_BUFFER, Bit 1.21 "Separate Stencil Enable":
565 * [DevIL]: If this field is enabled, Hierarchical Depth Buffer
566 * Enable must also be enabled.
567 *
568 * [DevGT]: This field must be set to the same value (enabled or
569 * disabled) as Hierarchical Depth Buffer Enable
570 */
571 bool enable_hiz_ss = hiz || separate_stencil;
572
573
574 /* 3DSTATE_DEPTH_BUFFER, 3DSTATE_STENCIL_BUFFER are both
575 * non-pipelined state that will need the PIPE_CONTROL workaround.
576 */
577 if (brw->gen == 6) {
578 brw_emit_depth_stall_flushes(brw);
579 }
580
581 unsigned int len;
582 if (brw->gen >= 6)
583 len = 7;
584 else if (brw->is_g4x || brw->gen == 5)
585 len = 6;
586 else
587 len = 5;
588
589 BEGIN_BATCH(len);
590 OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (len - 2));
591 OUT_BATCH((depth_mt ? depth_mt->pitch - 1 : 0) |
592 (depthbuffer_format << 18) |
593 ((enable_hiz_ss ? 1 : 0) << 21) | /* separate stencil enable */
594 ((enable_hiz_ss ? 1 : 0) << 22) | /* hiz enable */
595 (BRW_TILEWALK_YMAJOR << 26) |
596 ((depth_mt ? depth_mt->tiling != I915_TILING_NONE : 1)
597 << 27) |
598 (depth_surface_type << 29));
599
600 if (depth_mt) {
601 OUT_RELOC(depth_mt->bo,
602 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
603 depth_offset);
604 } else {
605 OUT_BATCH(0);
606 }
607
608 OUT_BATCH(((width + tile_x - 1) << 6) |
609 ((height + tile_y - 1) << 19));
610 OUT_BATCH(0);
611
612 if (brw->is_g4x || brw->gen >= 5)
613 OUT_BATCH(tile_x | (tile_y << 16));
614 else
615 assert(tile_x == 0 && tile_y == 0);
616
617 if (brw->gen >= 6)
618 OUT_BATCH(0);
619
620 ADVANCE_BATCH();
621
622 if (hiz || separate_stencil) {
623 /*
624 * In the 3DSTATE_DEPTH_BUFFER batch emitted above, the 'separate
625 * stencil enable' and 'hiz enable' bits were set. Therefore we must
626 * emit 3DSTATE_HIER_DEPTH_BUFFER and 3DSTATE_STENCIL_BUFFER. Even if
627 * there is no stencil buffer, 3DSTATE_STENCIL_BUFFER must be emitted;
628 * failure to do so causes hangs on gen5 and a stall on gen6.
629 */
630
631 /* Emit hiz buffer. */
632 if (hiz) {
633 assert(depth_mt);
634 struct intel_mipmap_tree *hiz_mt = depth_mt->hiz_buf->mt;
635 BEGIN_BATCH(3);
636 OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
637 OUT_BATCH(hiz_mt->pitch - 1);
638 OUT_RELOC(hiz_mt->bo,
639 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
640 brw->depthstencil.hiz_offset);
641 ADVANCE_BATCH();
642 } else {
643 BEGIN_BATCH(3);
644 OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
645 OUT_BATCH(0);
646 OUT_BATCH(0);
647 ADVANCE_BATCH();
648 }
649
650 /* Emit stencil buffer. */
651 if (separate_stencil) {
652 BEGIN_BATCH(3);
653 OUT_BATCH((_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2));
654 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
655 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
656 * The pitch must be set to 2x the value computed based on width, as
657 * the stencil buffer is stored with two rows interleaved.
658 */
659 OUT_BATCH(2 * stencil_mt->pitch - 1);
660 OUT_RELOC(stencil_mt->bo,
661 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
662 brw->depthstencil.stencil_offset);
663 ADVANCE_BATCH();
664 } else {
665 BEGIN_BATCH(3);
666 OUT_BATCH((_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2));
667 OUT_BATCH(0);
668 OUT_BATCH(0);
669 ADVANCE_BATCH();
670 }
671 }
672
673 /*
674 * On Gen >= 6, emit clear params for safety. If using hiz, then clear
675 * params must be emitted.
676 *
677 * From Section 2.11.5.6.4.1 3DSTATE_CLEAR_PARAMS:
678 * 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE packet
679 * when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
680 */
681 if (brw->gen >= 6 || hiz) {
682 BEGIN_BATCH(2);
683 OUT_BATCH(_3DSTATE_CLEAR_PARAMS << 16 |
684 GEN5_DEPTH_CLEAR_VALID |
685 (2 - 2));
686 OUT_BATCH(depth_mt ? depth_mt->depth_clear_value : 0);
687 ADVANCE_BATCH();
688 }
689 }
690
691 const struct brw_tracked_state brw_depthbuffer = {
692 .dirty = {
693 .mesa = _NEW_BUFFERS,
694 .brw = BRW_NEW_BATCH |
695 BRW_NEW_BLORP,
696 },
697 .emit = brw_emit_depthbuffer,
698 };
699
700 /**
701 * Polygon stipple packet
702 */
703 static void
704 upload_polygon_stipple(struct brw_context *brw)
705 {
706 struct gl_context *ctx = &brw->ctx;
707 GLuint i;
708
709 /* _NEW_POLYGON */
710 if (!ctx->Polygon.StippleFlag)
711 return;
712
713 BEGIN_BATCH(33);
714 OUT_BATCH(_3DSTATE_POLY_STIPPLE_PATTERN << 16 | (33 - 2));
715
716 /* Polygon stipple is provided in OpenGL order, i.e. bottom
717 * row first. If we're rendering to a window (i.e. the
718 * default frame buffer object, 0), then we need to invert
719 * it to match our pixel layout. But if we're rendering
720 * to a FBO (i.e. any named frame buffer object), we *don't*
721 * need to invert - we already match the layout.
722 */
723 if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
724 for (i = 0; i < 32; i++)
725 OUT_BATCH(ctx->PolygonStipple[31 - i]); /* invert */
726 } else {
727 for (i = 0; i < 32; i++)
728 OUT_BATCH(ctx->PolygonStipple[i]);
729 }
730 ADVANCE_BATCH();
731 }
732
733 const struct brw_tracked_state brw_polygon_stipple = {
734 .dirty = {
735 .mesa = _NEW_POLYGON |
736 _NEW_POLYGONSTIPPLE,
737 .brw = BRW_NEW_CONTEXT,
738 },
739 .emit = upload_polygon_stipple
740 };
741
742 /**
743 * Polygon stipple offset packet
744 */
745 static void
746 upload_polygon_stipple_offset(struct brw_context *brw)
747 {
748 struct gl_context *ctx = &brw->ctx;
749
750 /* _NEW_POLYGON */
751 if (!ctx->Polygon.StippleFlag)
752 return;
753
754 BEGIN_BATCH(2);
755 OUT_BATCH(_3DSTATE_POLY_STIPPLE_OFFSET << 16 | (2-2));
756
757 /* _NEW_BUFFERS
758 *
759 * If we're drawing to a system window we have to invert the Y axis
760 * in order to match the OpenGL pixel coordinate system, and our
761 * offset must be matched to the window position. If we're drawing
762 * to a user-created FBO then our native pixel coordinate system
763 * works just fine, and there's no window system to worry about.
764 */
765 if (_mesa_is_winsys_fbo(ctx->DrawBuffer))
766 OUT_BATCH((32 - (_mesa_geometric_height(ctx->DrawBuffer) & 31)) & 31);
767 else
768 OUT_BATCH(0);
769 ADVANCE_BATCH();
770 }
771
772 const struct brw_tracked_state brw_polygon_stipple_offset = {
773 .dirty = {
774 .mesa = _NEW_BUFFERS |
775 _NEW_POLYGON,
776 .brw = BRW_NEW_CONTEXT,
777 },
778 .emit = upload_polygon_stipple_offset
779 };
780
781 /**
782 * Line stipple packet
783 */
784 static void
785 upload_line_stipple(struct brw_context *brw)
786 {
787 struct gl_context *ctx = &brw->ctx;
788 GLfloat tmp;
789 GLint tmpi;
790
791 if (!ctx->Line.StippleFlag)
792 return;
793
794 BEGIN_BATCH(3);
795 OUT_BATCH(_3DSTATE_LINE_STIPPLE_PATTERN << 16 | (3 - 2));
796 OUT_BATCH(ctx->Line.StipplePattern);
797
798 if (brw->gen >= 7) {
799 /* in U1.16 */
800 tmp = 1.0f / ctx->Line.StippleFactor;
801 tmpi = tmp * (1<<16);
802 OUT_BATCH(tmpi << 15 | ctx->Line.StippleFactor);
803 } else {
804 /* in U1.13 */
805 tmp = 1.0f / ctx->Line.StippleFactor;
806 tmpi = tmp * (1<<13);
807 OUT_BATCH(tmpi << 16 | ctx->Line.StippleFactor);
808 }
809
810 ADVANCE_BATCH();
811 }
812
813 const struct brw_tracked_state brw_line_stipple = {
814 .dirty = {
815 .mesa = _NEW_LINE,
816 .brw = BRW_NEW_CONTEXT,
817 },
818 .emit = upload_line_stipple
819 };
820
821 void
822 brw_emit_select_pipeline(struct brw_context *brw, enum brw_pipeline pipeline)
823 {
824 const bool is_965 = brw->gen == 4 && !brw->is_g4x;
825 const uint32_t _3DSTATE_PIPELINE_SELECT =
826 is_965 ? CMD_PIPELINE_SELECT_965 : CMD_PIPELINE_SELECT_GM45;
827
828 if (brw->use_resource_streamer && pipeline != BRW_RENDER_PIPELINE) {
829 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
830 * PIPELINE_SELECT [DevBWR+]":
831 *
832 * Project: HSW, BDW, CHV, SKL, BXT
833 *
834 * Hardware Binding Tables are only supported for 3D
835 * workloads. Resource streamer must be enabled only for 3D
836 * workloads. Resource streamer must be disabled for Media and GPGPU
837 * workloads.
838 */
839 BEGIN_BATCH(1);
840 OUT_BATCH(MI_RS_CONTROL | 0);
841 ADVANCE_BATCH();
842
843 gen7_disable_hw_binding_tables(brw);
844
845 /* XXX - Disable gather constant pool too when we start using it. */
846 }
847
848 if (brw->gen >= 8 && brw->gen < 10) {
849 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
850 *
851 * Software must clear the COLOR_CALC_STATE Valid field in
852 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
853 * with Pipeline Select set to GPGPU.
854 *
855 * The internal hardware docs recommend the same workaround for Gen9
856 * hardware too.
857 */
858 if (pipeline == BRW_COMPUTE_PIPELINE) {
859 BEGIN_BATCH(2);
860 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (2 - 2));
861 OUT_BATCH(0);
862 ADVANCE_BATCH();
863
864 brw->ctx.NewDriverState |= BRW_NEW_CC_STATE;
865 }
866
867 } else if (brw->gen >= 6) {
868 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
869 * PIPELINE_SELECT [DevBWR+]":
870 *
871 * Project: DEVSNB+
872 *
873 * Software must ensure all the write caches are flushed through a
874 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
875 * command to invalidate read only caches prior to programming
876 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode.
877 */
878 const unsigned dc_flush =
879 brw->gen >= 7 ? PIPE_CONTROL_DATA_CACHE_FLUSH : 0;
880
881 brw_emit_pipe_control_flush(brw,
882 PIPE_CONTROL_RENDER_TARGET_FLUSH |
883 PIPE_CONTROL_DEPTH_CACHE_FLUSH |
884 dc_flush |
885 PIPE_CONTROL_NO_WRITE |
886 PIPE_CONTROL_CS_STALL);
887
888 brw_emit_pipe_control_flush(brw,
889 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
890 PIPE_CONTROL_CONST_CACHE_INVALIDATE |
891 PIPE_CONTROL_STATE_CACHE_INVALIDATE |
892 PIPE_CONTROL_INSTRUCTION_INVALIDATE |
893 PIPE_CONTROL_NO_WRITE);
894
895 } else {
896 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
897 * PIPELINE_SELECT [DevBWR+]":
898 *
899 * Project: PRE-DEVSNB
900 *
901 * Software must ensure the current pipeline is flushed via an
902 * MI_FLUSH or PIPE_CONTROL prior to the execution of PIPELINE_SELECT.
903 */
904 BEGIN_BATCH(1);
905 OUT_BATCH(MI_FLUSH);
906 ADVANCE_BATCH();
907 }
908
909 /* Select the pipeline */
910 BEGIN_BATCH(1);
911 OUT_BATCH(_3DSTATE_PIPELINE_SELECT << 16 |
912 (brw->gen >= 9 ? (3 << 8) : 0) |
913 (pipeline == BRW_COMPUTE_PIPELINE ? 2 : 0));
914 ADVANCE_BATCH();
915
916 if (brw->gen == 7 && !brw->is_haswell &&
917 pipeline == BRW_RENDER_PIPELINE) {
918 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
919 * PIPELINE_SELECT [DevBWR+]":
920 *
921 * Project: DEVIVB, DEVHSW:GT3:A0
922 *
923 * Software must send a pipe_control with a CS stall and a post sync
924 * operation and then a dummy DRAW after every MI_SET_CONTEXT and
925 * after any PIPELINE_SELECT that is enabling 3D mode.
926 */
927 gen7_emit_cs_stall_flush(brw);
928
929 BEGIN_BATCH(7);
930 OUT_BATCH(CMD_3D_PRIM << 16 | (7 - 2));
931 OUT_BATCH(_3DPRIM_POINTLIST);
932 OUT_BATCH(0);
933 OUT_BATCH(0);
934 OUT_BATCH(0);
935 OUT_BATCH(0);
936 OUT_BATCH(0);
937 ADVANCE_BATCH();
938 }
939
940 if (brw->use_resource_streamer && pipeline == BRW_RENDER_PIPELINE) {
941 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
942 * PIPELINE_SELECT [DevBWR+]":
943 *
944 * Project: HSW, BDW, CHV, SKL, BXT
945 *
946 * Hardware Binding Tables are only supported for 3D
947 * workloads. Resource streamer must be enabled only for 3D
948 * workloads. Resource streamer must be disabled for Media and GPGPU
949 * workloads.
950 */
951 BEGIN_BATCH(1);
952 OUT_BATCH(MI_RS_CONTROL | 1);
953 ADVANCE_BATCH();
954
955 gen7_enable_hw_binding_tables(brw);
956
957 /* XXX - Re-enable gather constant pool here. */
958 }
959 }
960
961 /**
962 * Misc invariant state packets
963 */
964 void
965 brw_upload_invariant_state(struct brw_context *brw)
966 {
967 const bool is_965 = brw->gen == 4 && !brw->is_g4x;
968
969 brw_emit_select_pipeline(brw, BRW_RENDER_PIPELINE);
970 brw->last_pipeline = BRW_RENDER_PIPELINE;
971
972 if (brw->gen >= 8) {
973 BEGIN_BATCH(3);
974 OUT_BATCH(CMD_STATE_SIP << 16 | (3 - 2));
975 OUT_BATCH(0);
976 OUT_BATCH(0);
977 ADVANCE_BATCH();
978 } else {
979 BEGIN_BATCH(2);
980 OUT_BATCH(CMD_STATE_SIP << 16 | (2 - 2));
981 OUT_BATCH(0);
982 ADVANCE_BATCH();
983 }
984
985 /* Original Gen4 doesn't have 3DSTATE_AA_LINE_PARAMETERS. */
986 if (!is_965) {
987 BEGIN_BATCH(3);
988 OUT_BATCH(_3DSTATE_AA_LINE_PARAMETERS << 16 | (3 - 2));
989 /* use legacy aa line coverage computation */
990 OUT_BATCH(0);
991 OUT_BATCH(0);
992 ADVANCE_BATCH();
993 }
994
995 const uint32_t _3DSTATE_VF_STATISTICS =
996 is_965 ? GEN4_3DSTATE_VF_STATISTICS : GM45_3DSTATE_VF_STATISTICS;
997 BEGIN_BATCH(1);
998 OUT_BATCH(_3DSTATE_VF_STATISTICS << 16 | 1);
999 ADVANCE_BATCH();
1000 }
1001
1002 const struct brw_tracked_state brw_invariant_state = {
1003 .dirty = {
1004 .mesa = 0,
1005 .brw = BRW_NEW_BLORP |
1006 BRW_NEW_CONTEXT,
1007 },
1008 .emit = brw_upload_invariant_state
1009 };
1010
1011 /**
1012 * Define the base addresses which some state is referenced from.
1013 *
1014 * This allows us to avoid having to emit relocations for the objects,
1015 * and is actually required for binding table pointers on gen6.
1016 *
1017 * Surface state base address covers binding table pointers and
1018 * surface state objects, but not the surfaces that the surface state
1019 * objects point to.
1020 */
1021 void
1022 brw_upload_state_base_address(struct brw_context *brw)
1023 {
1024 if (brw->batch.state_base_address_emitted)
1025 return;
1026
1027 /* FINISHME: According to section 3.6.1 "STATE_BASE_ADDRESS" of
1028 * vol1a of the G45 PRM, MI_FLUSH with the ISC invalidate should be
1029 * programmed prior to STATE_BASE_ADDRESS.
1030 *
1031 * However, given that the instruction SBA (general state base
1032 * address) on this chipset is always set to 0 across X and GL,
1033 * maybe this isn't required for us in particular.
1034 */
1035
1036 if (brw->gen >= 8) {
1037 uint32_t mocs_wb = brw->gen >= 9 ? SKL_MOCS_WB : BDW_MOCS_WB;
1038 int pkt_len = brw->gen >= 9 ? 19 : 16;
1039
1040 BEGIN_BATCH(pkt_len);
1041 OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (pkt_len - 2));
1042 /* General state base address: stateless DP read/write requests */
1043 OUT_BATCH(mocs_wb << 4 | 1);
1044 OUT_BATCH(0);
1045 OUT_BATCH(mocs_wb << 16);
1046 /* Surface state base address: */
1047 OUT_RELOC64(brw->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0,
1048 mocs_wb << 4 | 1);
1049 /* Dynamic state base address: */
1050 OUT_RELOC64(brw->batch.bo,
1051 I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION, 0,
1052 mocs_wb << 4 | 1);
1053 /* Indirect object base address: MEDIA_OBJECT data */
1054 OUT_BATCH(mocs_wb << 4 | 1);
1055 OUT_BATCH(0);
1056 /* Instruction base address: shader kernels (incl. SIP) */
1057 OUT_RELOC64(brw->cache.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
1058 mocs_wb << 4 | 1);
1059
1060 /* General state buffer size */
1061 OUT_BATCH(0xfffff001);
1062 /* Dynamic state buffer size */
1063 OUT_BATCH(ALIGN(brw->batch.bo->size, 4096) | 1);
1064 /* Indirect object upper bound */
1065 OUT_BATCH(0xfffff001);
1066 /* Instruction access upper bound */
1067 OUT_BATCH(ALIGN(brw->cache.bo->size, 4096) | 1);
1068 if (brw->gen >= 9) {
1069 OUT_BATCH(1);
1070 OUT_BATCH(0);
1071 OUT_BATCH(0);
1072 }
1073 ADVANCE_BATCH();
1074 } else if (brw->gen >= 6) {
1075 uint8_t mocs = brw->gen == 7 ? GEN7_MOCS_L3 : 0;
1076
1077 BEGIN_BATCH(10);
1078 OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (10 - 2));
1079 OUT_BATCH(mocs << 8 | /* General State Memory Object Control State */
1080 mocs << 4 | /* Stateless Data Port Access Memory Object Control State */
1081 1); /* General State Base Address Modify Enable */
1082 /* Surface state base address:
1083 * BINDING_TABLE_STATE
1084 * SURFACE_STATE
1085 */
1086 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0, 1);
1087 /* Dynamic state base address:
1088 * SAMPLER_STATE
1089 * SAMPLER_BORDER_COLOR_STATE
1090 * CLIP, SF, WM/CC viewport state
1091 * COLOR_CALC_STATE
1092 * DEPTH_STENCIL_STATE
1093 * BLEND_STATE
1094 * Push constants (when INSTPM: CONSTANT_BUFFER Address Offset
1095 * Disable is clear, which we rely on)
1096 */
1097 OUT_RELOC(brw->batch.bo, (I915_GEM_DOMAIN_RENDER |
1098 I915_GEM_DOMAIN_INSTRUCTION), 0, 1);
1099
1100 OUT_BATCH(1); /* Indirect object base address: MEDIA_OBJECT data */
1101 OUT_RELOC(brw->cache.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
1102 1); /* Instruction base address: shader kernels (incl. SIP) */
1103
1104 OUT_BATCH(1); /* General state upper bound */
1105 /* Dynamic state upper bound. Although the documentation says that
1106 * programming it to zero will cause it to be ignored, that is a lie.
1107 * If this isn't programmed to a real bound, the sampler border color
1108 * pointer is rejected, causing border color to mysteriously fail.
1109 */
1110 OUT_BATCH(0xfffff001);
1111 OUT_BATCH(1); /* Indirect object upper bound */
1112 OUT_BATCH(1); /* Instruction access upper bound */
1113 ADVANCE_BATCH();
1114 } else if (brw->gen == 5) {
1115 BEGIN_BATCH(8);
1116 OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (8 - 2));
1117 OUT_BATCH(1); /* General state base address */
1118 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0,
1119 1); /* Surface state base address */
1120 OUT_BATCH(1); /* Indirect object base address */
1121 OUT_RELOC(brw->cache.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
1122 1); /* Instruction base address */
1123 OUT_BATCH(0xfffff001); /* General state upper bound */
1124 OUT_BATCH(1); /* Indirect object upper bound */
1125 OUT_BATCH(1); /* Instruction access upper bound */
1126 ADVANCE_BATCH();
1127 } else {
1128 BEGIN_BATCH(6);
1129 OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2));
1130 OUT_BATCH(1); /* General state base address */
1131 OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0,
1132 1); /* Surface state base address */
1133 OUT_BATCH(1); /* Indirect object base address */
1134 OUT_BATCH(1); /* General state upper bound */
1135 OUT_BATCH(1); /* Indirect object upper bound */
1136 ADVANCE_BATCH();
1137 }
1138
1139 /* According to section 3.6.1 of VOL1 of the 965 PRM,
1140 * STATE_BASE_ADDRESS updates require a reissue of:
1141 *
1142 * 3DSTATE_PIPELINE_POINTERS
1143 * 3DSTATE_BINDING_TABLE_POINTERS
1144 * MEDIA_STATE_POINTERS
1145 *
1146 * and this continues through Ironlake. The Sandy Bridge PRM, vol
1147 * 1 part 1 says that the folowing packets must be reissued:
1148 *
1149 * 3DSTATE_CC_POINTERS
1150 * 3DSTATE_BINDING_TABLE_POINTERS
1151 * 3DSTATE_SAMPLER_STATE_POINTERS
1152 * 3DSTATE_VIEWPORT_STATE_POINTERS
1153 * MEDIA_STATE_POINTERS
1154 *
1155 * Those are always reissued following SBA updates anyway (new
1156 * batch time), except in the case of the program cache BO
1157 * changing. Having a separate state flag makes the sequence more
1158 * obvious.
1159 */
1160
1161 brw->ctx.NewDriverState |= BRW_NEW_STATE_BASE_ADDRESS;
1162 brw->batch.state_base_address_emitted = true;
1163 }