2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "intel_batchbuffer.h"
27 #include "intel_mipmap_tree.h"
29 #include "brw_context.h"
30 #include "brw_state.h"
32 #include "brw_blorp.h"
35 gen6_blorp_emit_vertex_buffer_state(struct brw_context
*brw
,
38 uint32_t vertex_offset
)
40 /* 3DSTATE_VERTEX_BUFFERS */
41 const int num_buffers
= 1;
42 const int batch_length
= 1 + 4 * num_buffers
;
44 uint32_t dw0
= GEN6_VB0_ACCESS_VERTEXDATA
|
45 (num_elems
* sizeof(float)) << BRW_VB0_PITCH_SHIFT
;
48 dw0
|= GEN7_VB0_ADDRESS_MODIFYENABLE
;
52 dw0
|= GEN7_MOCS_L3
<< 16;
55 dw0
|= BDW_MOCS_WB
<< 16;
58 dw0
|= SKL_MOCS_WB
<< 16;
62 BEGIN_BATCH(batch_length
);
63 OUT_BATCH((_3DSTATE_VERTEX_BUFFERS
<< 16) | (batch_length
- 2));
66 OUT_RELOC64(brw
->batch
.bo
, I915_GEM_DOMAIN_VERTEX
, 0, vertex_offset
);
70 OUT_RELOC(brw
->batch
.bo
, I915_GEM_DOMAIN_VERTEX
, 0,
73 OUT_RELOC(brw
->batch
.bo
, I915_GEM_DOMAIN_VERTEX
, 0,
74 vertex_offset
+ vbo_size
- 1);
81 gen6_blorp_emit_vertices(struct brw_context
*brw
,
82 const struct brw_blorp_params
*params
)
84 uint32_t vertex_offset
;
86 /* Setup VBO for the rectangle primitive..
88 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
89 * vertices. The vertices reside in screen space with DirectX coordinates
90 * (that is, (0, 0) is the upper left corner).
97 * Since the VS is disabled, the clipper loads each VUE directly from
98 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
99 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
100 * dw0: Reserved, MBZ.
101 * dw1: Render Target Array Index. The HiZ op does not use indexed
102 * vertices, so set the dword to 0.
103 * dw2: Viewport Index. The HiZ op disables viewport mapping and
104 * scissoring, so set the dword to 0.
105 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive, so
106 * set the dword to 0.
107 * dw4: Vertex Position X.
108 * dw5: Vertex Position Y.
109 * dw6: Vertex Position Z.
110 * dw7: Vertex Position W.
112 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
113 * "Vertex URB Entry (VUE) Formats".
115 * Only vertex position X and Y are going to be variable, Z is fixed to
116 * zero and W to one. Header words dw0-3 are all zero. There is no need to
117 * include the fixed values in the vertex buffer. Vertex fetcher can be
118 * instructed to fill vertex elements with constant values of one and zero
119 * instead of reading them from the buffer. See the vertex element setup
125 const float vertices
[] = {
126 /* v0 */ (float)params
->x0
, (float)params
->y1
,
127 /* v1 */ (float)params
->x1
, (float)params
->y1
,
128 /* v2 */ (float)params
->x0
, (float)params
->y0
,
131 vertex_data
= (float *) brw_state_batch(brw
, AUB_TRACE_VERTEX_BUFFER
,
132 sizeof(vertices
), 32,
134 memcpy(vertex_data
, vertices
, sizeof(vertices
));
136 const unsigned blorp_num_vue_elems
= 2;
137 gen6_blorp_emit_vertex_buffer_state(brw
, blorp_num_vue_elems
,
138 sizeof(vertices
), vertex_offset
);
141 /* 3DSTATE_VERTEX_ELEMENTS
143 * Fetch dwords 0 - 7 from each VUE. See the comments above where
144 * the vertex_bo is filled with data.
147 const int num_elements
= 2;
148 const int batch_length
= 1 + 2 * num_elements
;
150 BEGIN_BATCH(batch_length
);
151 OUT_BATCH((_3DSTATE_VERTEX_ELEMENTS
<< 16) | (batch_length
- 2));
153 OUT_BATCH(GEN6_VE0_VALID
|
154 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
<< BRW_VE0_FORMAT_SHIFT
|
155 0 << BRW_VE0_SRC_OFFSET_SHIFT
);
156 OUT_BATCH(BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_0_SHIFT
|
157 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_1_SHIFT
|
158 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_2_SHIFT
|
159 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_3_SHIFT
);
161 OUT_BATCH(GEN6_VE0_VALID
|
162 BRW_SURFACEFORMAT_R32G32_FLOAT
<< BRW_VE0_FORMAT_SHIFT
|
163 0 << BRW_VE0_SRC_OFFSET_SHIFT
);
164 OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_0_SHIFT
|
165 BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_1_SHIFT
|
166 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_2_SHIFT
|
167 BRW_VE1_COMPONENT_STORE_1_FLT
<< BRW_VE1_COMPONENT_3_SHIFT
);
175 * Assign the entire URB to the VS. Even though the VS disabled, URB space
176 * is still needed because the clipper loads the VUE's from the URB. From
177 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
178 * Dword 1.15:0 "VS Number of URB Entries":
179 * This field is always used (even if VS Function Enable is DISABLED).
181 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
182 * safely ignore it because this batch contains only one draw call.
183 * Because of URB corruption caused by allocating a previous GS unit
184 * URB entry to the VS unit, software is required to send a “GS NULL
185 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
186 * plus a dummy DRAW call before any case where VS will be taking over
190 gen6_blorp_emit_urb_config(struct brw_context
*brw
,
191 const struct brw_blorp_params
*params
)
194 OUT_BATCH(_3DSTATE_URB
<< 16 | (3 - 2));
195 OUT_BATCH(brw
->urb
.max_vs_entries
<< GEN6_URB_VS_ENTRIES_SHIFT
);
203 gen6_blorp_emit_blend_state(struct brw_context
*brw
,
204 const struct brw_blorp_params
*params
)
206 uint32_t cc_blend_state_offset
;
208 assume(params
->num_draw_buffers
);
210 const unsigned size
= params
->num_draw_buffers
*
211 sizeof(struct gen6_blend_state
);
212 struct gen6_blend_state
*blend
= (struct gen6_blend_state
*)
213 brw_state_batch(brw
, AUB_TRACE_BLEND_STATE
, size
, 64,
214 &cc_blend_state_offset
);
216 memset(blend
, 0, size
);
218 for (unsigned i
= 0; i
< params
->num_draw_buffers
; ++i
) {
219 blend
[i
].blend1
.pre_blend_clamp_enable
= 1;
220 blend
[i
].blend1
.post_blend_clamp_enable
= 1;
221 blend
[i
].blend1
.clamp_range
= BRW_RENDERTARGET_CLAMPRANGE_FORMAT
;
223 blend
[i
].blend1
.write_disable_r
= params
->color_write_disable
[0];
224 blend
[i
].blend1
.write_disable_g
= params
->color_write_disable
[1];
225 blend
[i
].blend1
.write_disable_b
= params
->color_write_disable
[2];
226 blend
[i
].blend1
.write_disable_a
= params
->color_write_disable
[3];
229 return cc_blend_state_offset
;
235 gen6_blorp_emit_cc_state(struct brw_context
*brw
)
237 uint32_t cc_state_offset
;
239 struct gen6_color_calc_state
*cc
= (struct gen6_color_calc_state
*)
240 brw_state_batch(brw
, AUB_TRACE_CC_STATE
,
241 sizeof(gen6_color_calc_state
), 64,
243 memset(cc
, 0, sizeof(*cc
));
245 return cc_state_offset
;
250 * \param out_offset is relative to
251 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
254 gen6_blorp_emit_depth_stencil_state(struct brw_context
*brw
,
255 const struct brw_blorp_params
*params
)
257 uint32_t depthstencil_offset
;
259 struct gen6_depth_stencil_state
*state
;
260 state
= (struct gen6_depth_stencil_state
*)
261 brw_state_batch(brw
, AUB_TRACE_DEPTH_STENCIL_STATE
,
263 &depthstencil_offset
);
264 memset(state
, 0, sizeof(*state
));
266 /* See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
267 * - 7.5.3.1 Depth Buffer Clear
268 * - 7.5.3.2 Depth Buffer Resolve
269 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
271 state
->ds2
.depth_write_enable
= 1;
272 if (params
->hiz_op
== GEN6_HIZ_OP_DEPTH_RESOLVE
) {
273 state
->ds2
.depth_test_enable
= 1;
274 state
->ds2
.depth_test_func
= BRW_COMPAREFUNCTION_NEVER
;
277 return depthstencil_offset
;
281 /* 3DSTATE_CC_STATE_POINTERS
283 * The pointer offsets are relative to
284 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
286 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
289 gen6_blorp_emit_cc_state_pointers(struct brw_context
*brw
,
290 const struct brw_blorp_params
*params
,
291 uint32_t cc_blend_state_offset
,
292 uint32_t depthstencil_offset
,
293 uint32_t cc_state_offset
)
296 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS
<< 16 | (4 - 2));
297 OUT_BATCH(cc_blend_state_offset
| 1); /* BLEND_STATE offset */
298 OUT_BATCH(depthstencil_offset
| 1); /* DEPTH_STENCIL_STATE offset */
299 OUT_BATCH(cc_state_offset
| 1); /* COLOR_CALC_STATE offset */
304 /* WM push constants */
306 gen6_blorp_emit_wm_constants(struct brw_context
*brw
,
307 const struct brw_blorp_params
*params
)
309 uint32_t wm_push_const_offset
;
311 uint32_t *constants
= brw_state_batch(brw
, AUB_TRACE_WM_CONSTANTS
,
312 sizeof(params
->wm_push_consts
),
313 32, &wm_push_const_offset
);
315 const uint32_t *push_consts
= (const uint32_t *)¶ms
->wm_push_consts
;
316 for (unsigned i
= 0; i
< params
->wm_prog_data
->nr_params
; i
++)
317 constants
[i
] = push_consts
[params
->wm_prog_data
->param
[i
]];
319 return wm_push_const_offset
;
323 /* SURFACE_STATE for renderbuffer or texture surface (see
324 * brw_update_renderbuffer_surface and brw_update_texture_surface)
327 gen6_blorp_emit_surface_state(struct brw_context
*brw
,
328 const struct brw_blorp_params
*params
,
329 const struct brw_blorp_surface_info
*surface
,
330 uint32_t read_domains
, uint32_t write_domain
)
332 uint32_t wm_surf_offset
;
333 uint32_t width
= surface
->width
;
334 uint32_t height
= surface
->height
;
335 if (surface
->num_samples
> 1) {
336 /* Since gen6 uses INTEL_MSAA_LAYOUT_IMS, width and height are measured
337 * in samples. But SURFACE_STATE wants them in pixels, so we need to
338 * divide them each by 2.
343 struct intel_mipmap_tree
*mt
= surface
->mt
;
344 uint32_t tile_x
, tile_y
;
346 uint32_t *surf
= (uint32_t *)
347 brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
, 6 * 4, 32,
350 surf
[0] = (BRW_SURFACE_2D
<< BRW_SURFACE_TYPE_SHIFT
|
351 BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< BRW_SURFACE_MIPLAYOUT_SHIFT
|
352 BRW_SURFACE_CUBEFACE_ENABLES
|
353 surface
->brw_surfaceformat
<< BRW_SURFACE_FORMAT_SHIFT
);
356 surf
[1] = (brw_blorp_compute_tile_offsets(surface
, &tile_x
, &tile_y
) +
359 surf
[2] = (0 << BRW_SURFACE_LOD_SHIFT
|
360 (width
- 1) << BRW_SURFACE_WIDTH_SHIFT
|
361 (height
- 1) << BRW_SURFACE_HEIGHT_SHIFT
);
363 uint32_t tiling
= surface
->map_stencil_as_y_tiled
364 ? BRW_SURFACE_TILED
| BRW_SURFACE_TILED_Y
365 : brw_get_surface_tiling_bits(mt
->tiling
);
366 uint32_t pitch_bytes
= mt
->pitch
;
367 if (surface
->map_stencil_as_y_tiled
)
370 0 << BRW_SURFACE_DEPTH_SHIFT
|
371 (pitch_bytes
- 1) << BRW_SURFACE_PITCH_SHIFT
);
373 surf
[4] = brw_get_surface_num_multisamples(surface
->num_samples
);
375 /* Note that the low bits of these fields are missing, so
376 * there's the possibility of getting in trouble.
378 assert(tile_x
% 4 == 0);
379 assert(tile_y
% 2 == 0);
380 surf
[5] = ((tile_x
/ 4) << BRW_SURFACE_X_OFFSET_SHIFT
|
381 (tile_y
/ 2) << BRW_SURFACE_Y_OFFSET_SHIFT
|
382 (surface
->mt
->valign
== 4 ?
383 BRW_SURFACE_VERTICAL_ALIGN_ENABLE
: 0));
385 /* Emit relocation to surface contents */
386 drm_intel_bo_emit_reloc(brw
->batch
.bo
,
389 surf
[1] - mt
->bo
->offset64
,
390 read_domains
, write_domain
);
392 return wm_surf_offset
;
396 /* BINDING_TABLE. See brw_wm_binding_table(). */
398 gen6_blorp_emit_binding_table(struct brw_context
*brw
,
399 uint32_t wm_surf_offset_renderbuffer
,
400 uint32_t wm_surf_offset_texture
)
402 uint32_t wm_bind_bo_offset
;
403 uint32_t *bind
= (uint32_t *)
404 brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
406 BRW_BLORP_NUM_BINDING_TABLE_ENTRIES
,
409 bind
[BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX
] =
410 wm_surf_offset_renderbuffer
;
411 bind
[BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX
] = wm_surf_offset_texture
;
413 return wm_bind_bo_offset
;
418 * SAMPLER_STATE. See brw_update_sampler_state().
421 gen6_blorp_emit_sampler_state(struct brw_context
*brw
,
422 unsigned tex_filter
, unsigned max_lod
,
423 bool non_normalized_coords
)
425 uint32_t sampler_offset
;
426 uint32_t *sampler_state
= (uint32_t *)
427 brw_state_batch(brw
, AUB_TRACE_SAMPLER_STATE
, 16, 32, &sampler_offset
);
429 unsigned address_rounding
= BRW_ADDRESS_ROUNDING_ENABLE_U_MIN
|
430 BRW_ADDRESS_ROUNDING_ENABLE_V_MIN
|
431 BRW_ADDRESS_ROUNDING_ENABLE_R_MIN
|
432 BRW_ADDRESS_ROUNDING_ENABLE_U_MAG
|
433 BRW_ADDRESS_ROUNDING_ENABLE_V_MAG
|
434 BRW_ADDRESS_ROUNDING_ENABLE_R_MAG
;
436 /* XXX: I don't think that using firstLevel, lastLevel works,
437 * because we always setup the surface state as if firstLevel ==
438 * level zero. Probably have to subtract firstLevel from each of
441 brw_emit_sampler_state(brw
,
444 tex_filter
, /* min filter */
445 tex_filter
, /* mag filter */
449 BRW_TEXCOORDMODE_CLAMP
,
450 BRW_TEXCOORDMODE_CLAMP
,
451 BRW_TEXCOORDMODE_CLAMP
,
455 0, /* shadow function */
456 non_normalized_coords
,
457 0); /* border color offset - unused */
459 return sampler_offset
;
464 * 3DSTATE_SAMPLER_STATE_POINTERS. See upload_sampler_state_pointers().
467 gen6_blorp_emit_sampler_state_pointers(struct brw_context
*brw
,
468 uint32_t sampler_offset
)
471 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS
<< 16 |
472 VS_SAMPLER_STATE_CHANGE
|
473 GS_SAMPLER_STATE_CHANGE
|
474 PS_SAMPLER_STATE_CHANGE
|
476 OUT_BATCH(0); /* VS */
477 OUT_BATCH(0); /* GS */
478 OUT_BATCH(sampler_offset
);
485 * Disable vertex shader.
488 gen6_blorp_emit_vs_disable(struct brw_context
*brw
,
489 const struct brw_blorp_params
*params
)
491 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
492 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
494 * [DevSNB] A pipeline flush must be programmed prior to a
495 * 3DSTATE_VS command that causes the VS Function Enable to
496 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
497 * command with CS stall bit set and a post sync operation.
499 * We've already done one at the start of the BLORP operation.
502 /* Disable the push constant buffers. */
504 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 | (5 - 2));
512 OUT_BATCH(_3DSTATE_VS
<< 16 | (6 - 2));
524 * Disable the geometry shader.
527 gen6_blorp_emit_gs_disable(struct brw_context
*brw
,
528 const struct brw_blorp_params
*params
)
530 /* Disable all the constant buffers. */
532 OUT_BATCH(_3DSTATE_CONSTANT_GS
<< 16 | (5 - 2));
540 OUT_BATCH(_3DSTATE_GS
<< 16 | (7 - 2));
548 brw
->gs
.enabled
= false;
554 * Disable the clipper.
556 * The BLORP op emits a rectangle primitive, which requires clipping to
557 * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
558 * Section 1.3 "3D Primitives Overview":
560 * Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
561 * Mode should be set to a value other than CLIPMODE_NORMAL.
563 * Also disable perspective divide. This doesn't change the clipper's
564 * output, but does spare a few electrons.
567 gen6_blorp_emit_clip_disable(struct brw_context
*brw
)
570 OUT_BATCH(_3DSTATE_CLIP
<< 16 | (4 - 2));
572 OUT_BATCH(GEN6_CLIP_PERSPECTIVE_DIVIDE_DISABLE
);
580 * Disable ViewportTransformEnable (dw2.1)
582 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
583 * Primitives Overview":
584 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
585 * use of screen- space coordinates).
587 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
588 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
590 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
591 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
592 * SOLID: Any triangle or rectangle object found to be front-facing
593 * is rendered as a solid object. This setting is required when
594 * (rendering rectangle (RECTLIST) objects.
597 gen6_blorp_emit_sf_config(struct brw_context
*brw
,
598 const struct brw_blorp_params
*params
)
601 OUT_BATCH(_3DSTATE_SF
<< 16 | (20 - 2));
602 OUT_BATCH(params
->num_varyings
<< GEN6_SF_NUM_OUTPUTS_SHIFT
|
603 1 << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT
|
604 BRW_SF_URB_ENTRY_READ_OFFSET
<<
605 GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT
);
606 OUT_BATCH(0); /* dw2 */
607 OUT_BATCH(params
->dst
.num_samples
> 1 ? GEN6_SF_MSRAST_ON_PATTERN
: 0);
608 for (int i
= 0; i
< 16; ++i
)
615 * Enable or disable thread dispatch and set the HiZ op appropriately.
618 gen6_blorp_emit_wm_config(struct brw_context
*brw
,
619 const struct brw_blorp_params
*params
)
621 const struct brw_blorp_prog_data
*prog_data
= params
->wm_prog_data
;
622 uint32_t dw2
, dw4
, dw5
, dw6
, ksp0
, ksp2
;
624 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
625 * nonzero to prevent the GPU from hanging. While the documentation doesn't
626 * mention this explicitly, it notes that the valid range for the field is
627 * [1,39] = [2,40] threads, which excludes zero.
629 * To be safe (and to minimize extraneous code) we go ahead and fully
630 * configure the WM state whether or not there is a WM program.
633 dw2
= dw4
= dw5
= dw6
= ksp0
= ksp2
= 0;
634 switch (params
->hiz_op
) {
635 case GEN6_HIZ_OP_DEPTH_CLEAR
:
636 dw4
|= GEN6_WM_DEPTH_CLEAR
;
638 case GEN6_HIZ_OP_DEPTH_RESOLVE
:
639 dw4
|= GEN6_WM_DEPTH_RESOLVE
;
641 case GEN6_HIZ_OP_HIZ_RESOLVE
:
642 dw4
|= GEN6_WM_HIERARCHICAL_DEPTH_RESOLVE
;
644 case GEN6_HIZ_OP_NONE
:
647 unreachable("not reached");
649 dw5
|= GEN6_WM_LINE_AA_WIDTH_1_0
;
650 dw5
|= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5
;
651 dw5
|= (brw
->max_wm_threads
- 1) << GEN6_WM_MAX_THREADS_SHIFT
;
652 dw6
|= 0 << GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT
; /* No interp */
653 dw6
|= 0 << GEN6_WM_NUM_SF_OUTPUTS_SHIFT
; /* No inputs from SF */
654 if (params
->wm_prog_data
) {
655 dw5
|= GEN6_WM_DISPATCH_ENABLE
; /* We are rendering */
657 dw4
|= prog_data
->first_curbe_grf_0
<< GEN6_WM_DISPATCH_START_GRF_SHIFT_0
;
658 dw4
|= prog_data
->first_curbe_grf_2
<< GEN6_WM_DISPATCH_START_GRF_SHIFT_2
;
660 ksp0
= params
->wm_prog_kernel
;
661 ksp2
= params
->wm_prog_kernel
+ params
->wm_prog_data
->ksp_offset_2
;
663 if (params
->wm_prog_data
->dispatch_8
)
664 dw5
|= GEN6_WM_8_DISPATCH_ENABLE
;
665 if (params
->wm_prog_data
->dispatch_16
)
666 dw5
|= GEN6_WM_16_DISPATCH_ENABLE
;
669 if (params
->src
.mt
) {
670 dw5
|= GEN6_WM_KILL_ENABLE
; /* TODO: temporarily smash on */
671 dw2
|= 1 << GEN6_WM_SAMPLER_COUNT_SHIFT
; /* Up to 4 samplers */
674 if (params
->dst
.num_samples
> 1) {
675 dw6
|= GEN6_WM_MSRAST_ON_PATTERN
;
676 if (prog_data
&& prog_data
->persample_msaa_dispatch
)
677 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
679 dw6
|= GEN6_WM_MSDISPMODE_PERPIXEL
;
681 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
682 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
686 OUT_BATCH(_3DSTATE_WM
<< 16 | (9 - 2));
689 OUT_BATCH(0); /* No scratch needed */
693 OUT_BATCH(0); /* kernel 1 pointer */
700 gen6_blorp_emit_constant_ps(struct brw_context
*brw
,
701 const struct brw_blorp_params
*params
,
702 uint32_t wm_push_const_offset
)
704 /* Make sure the push constants fill an exact integer number of
707 assert(sizeof(struct brw_blorp_wm_push_constants
) % 32 == 0);
709 /* There must be at least one register worth of push constant data. */
710 assert(BRW_BLORP_NUM_PUSH_CONST_REGS
> 0);
712 /* Enable push constant buffer 0. */
714 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 |
715 GEN6_CONSTANT_BUFFER_0_ENABLE
|
717 OUT_BATCH(wm_push_const_offset
+ (BRW_BLORP_NUM_PUSH_CONST_REGS
- 1));
725 gen6_blorp_emit_constant_ps_disable(struct brw_context
*brw
,
726 const struct brw_blorp_params
*params
)
728 /* Disable the push constant buffers. */
730 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (5 - 2));
739 * 3DSTATE_BINDING_TABLE_POINTERS
742 gen6_blorp_emit_binding_table_pointers(struct brw_context
*brw
,
743 uint32_t wm_bind_bo_offset
)
746 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 |
747 GEN6_BINDING_TABLE_MODIFY_PS
|
749 OUT_BATCH(0); /* vs -- ignored */
750 OUT_BATCH(0); /* gs -- ignored */
751 OUT_BATCH(wm_bind_bo_offset
); /* wm/ps */
757 gen6_blorp_emit_depth_stencil_config(struct brw_context
*brw
,
758 const struct brw_blorp_params
*params
)
760 uint32_t surfwidth
, surfheight
;
762 unsigned int depth
= MAX2(params
->depth
.mt
->logical_depth0
, 1);
763 GLenum gl_target
= params
->depth
.mt
->target
;
767 case GL_TEXTURE_CUBE_MAP_ARRAY
:
768 case GL_TEXTURE_CUBE_MAP
:
769 /* The PRM claims that we should use BRW_SURFACE_CUBE for this
770 * situation, but experiments show that gl_Layer doesn't work when we do
771 * this. So we use BRW_SURFACE_2D, since for rendering purposes this is
774 surftype
= BRW_SURFACE_2D
;
778 surftype
= translate_tex_target(gl_target
);
782 const unsigned min_array_element
= params
->depth
.layer
;
784 lod
= params
->depth
.level
- params
->depth
.mt
->first_level
;
786 if (params
->hiz_op
!= GEN6_HIZ_OP_NONE
&& lod
== 0) {
787 /* HIZ ops for lod 0 may set the width & height a little
788 * larger to allow the fast depth clear to fit the hardware
789 * alignment requirements. (8x4)
791 surfwidth
= params
->depth
.width
;
792 surfheight
= params
->depth
.height
;
794 surfwidth
= params
->depth
.mt
->logical_width0
;
795 surfheight
= params
->depth
.mt
->logical_height0
;
798 /* 3DSTATE_DEPTH_BUFFER */
800 brw_emit_depth_stall_flushes(brw
);
803 /* 3DSTATE_DEPTH_BUFFER dw0 */
804 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
806 /* 3DSTATE_DEPTH_BUFFER dw1 */
807 OUT_BATCH((params
->depth
.mt
->pitch
- 1) |
808 params
->depth_format
<< 18 |
809 1 << 21 | /* separate stencil enable */
810 1 << 22 | /* hiz enable */
811 BRW_TILEWALK_YMAJOR
<< 26 |
812 1 << 27 | /* y-tiled */
815 /* 3DSTATE_DEPTH_BUFFER dw2 */
816 OUT_RELOC(params
->depth
.mt
->bo
,
817 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
820 /* 3DSTATE_DEPTH_BUFFER dw3 */
821 OUT_BATCH(BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< 1 |
822 (surfwidth
- 1) << 6 |
823 (surfheight
- 1) << 19 |
826 /* 3DSTATE_DEPTH_BUFFER dw4 */
827 OUT_BATCH((depth
- 1) << 21 |
828 min_array_element
<< 10 |
831 /* 3DSTATE_DEPTH_BUFFER dw5 */
834 /* 3DSTATE_DEPTH_BUFFER dw6 */
839 /* 3DSTATE_HIER_DEPTH_BUFFER */
841 struct intel_mipmap_tree
*hiz_mt
= params
->depth
.mt
->hiz_buf
->mt
;
844 if (hiz_mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
845 offset
= intel_miptree_get_aligned_offset(hiz_mt
,
846 hiz_mt
->level
[lod
].level_x
,
847 hiz_mt
->level
[lod
].level_y
,
852 OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER
<< 16) | (3 - 2));
853 OUT_BATCH(hiz_mt
->pitch
- 1);
854 OUT_RELOC(hiz_mt
->bo
,
855 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
860 /* 3DSTATE_STENCIL_BUFFER */
863 OUT_BATCH((_3DSTATE_STENCIL_BUFFER
<< 16) | (3 - 2));
872 gen6_blorp_emit_depth_disable(struct brw_context
*brw
,
873 const struct brw_blorp_params
*params
)
875 brw_emit_depth_stall_flushes(brw
);
878 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
879 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT
<< 18) |
880 (BRW_SURFACE_NULL
<< 29));
889 OUT_BATCH(_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
895 OUT_BATCH(_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
902 /* 3DSTATE_CLEAR_PARAMS
904 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
905 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
906 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
909 gen6_blorp_emit_clear_params(struct brw_context
*brw
,
910 const struct brw_blorp_params
*params
)
913 OUT_BATCH(_3DSTATE_CLEAR_PARAMS
<< 16 |
914 GEN5_DEPTH_CLEAR_VALID
|
916 OUT_BATCH(params
->depth
.mt
? params
->depth
.mt
->depth_clear_value
: 0);
921 /* 3DSTATE_DRAWING_RECTANGLE */
923 gen6_blorp_emit_drawing_rectangle(struct brw_context
*brw
,
924 const struct brw_blorp_params
*params
)
927 OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE
<< 16 | (4 - 2));
929 OUT_BATCH(((MAX2(params
->x1
, params
->x0
) - 1) & 0xffff) |
930 ((MAX2(params
->y1
, params
->y0
) - 1) << 16));
935 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
937 gen6_blorp_emit_viewport_state(struct brw_context
*brw
,
938 const struct brw_blorp_params
*params
)
940 struct brw_cc_viewport
*ccv
;
941 uint32_t cc_vp_offset
;
943 ccv
= (struct brw_cc_viewport
*)brw_state_batch(brw
, AUB_TRACE_CC_VP_STATE
,
947 ccv
->min_depth
= 0.0;
948 ccv
->max_depth
= 1.0;
951 OUT_BATCH(_3DSTATE_VIEWPORT_STATE_POINTERS
<< 16 | (4 - 2) |
952 GEN6_CC_VIEWPORT_MODIFY
);
953 OUT_BATCH(0); /* clip VP */
954 OUT_BATCH(0); /* SF VP */
955 OUT_BATCH(cc_vp_offset
);
962 gen6_blorp_emit_primitive(struct brw_context
*brw
,
963 const struct brw_blorp_params
*params
)
966 OUT_BATCH(CMD_3D_PRIM
<< 16 | (6 - 2) |
967 _3DPRIM_RECTLIST
<< GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT
|
968 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
);
969 OUT_BATCH(3); /* vertex count per instance */
971 OUT_BATCH(params
->num_layers
); /* instance count */
978 * \brief Execute a blit or render pass operation.
980 * To execute the operation, this function manually constructs and emits a
981 * batch to draw a rectangle primitive. The batchbuffer is flushed before
982 * constructing and after emitting the batch.
984 * This function alters no GL state.
987 gen6_blorp_exec(struct brw_context
*brw
,
988 const struct brw_blorp_params
*params
)
990 uint32_t cc_blend_state_offset
= 0;
991 uint32_t cc_state_offset
= 0;
992 uint32_t depthstencil_offset
;
993 uint32_t wm_push_const_offset
= 0;
994 uint32_t wm_bind_bo_offset
= 0;
996 /* Emit workaround flushes when we switch from drawing to blorping. */
997 brw_emit_post_sync_nonzero_flush(brw
);
999 brw_upload_state_base_address(brw
);
1001 gen6_emit_3dstate_multisample(brw
, params
->dst
.num_samples
);
1002 gen6_emit_3dstate_sample_mask(brw
,
1003 params
->dst
.num_samples
> 1 ?
1004 (1 << params
->dst
.num_samples
) - 1 : 1);
1005 gen6_blorp_emit_vertices(brw
, params
);
1006 gen6_blorp_emit_urb_config(brw
, params
);
1007 if (params
->wm_prog_data
) {
1008 cc_blend_state_offset
= gen6_blorp_emit_blend_state(brw
, params
);
1009 cc_state_offset
= gen6_blorp_emit_cc_state(brw
);
1011 depthstencil_offset
= gen6_blorp_emit_depth_stencil_state(brw
, params
);
1012 gen6_blorp_emit_cc_state_pointers(brw
, params
, cc_blend_state_offset
,
1013 depthstencil_offset
, cc_state_offset
);
1014 if (params
->wm_prog_data
) {
1015 uint32_t wm_surf_offset_renderbuffer
;
1016 uint32_t wm_surf_offset_texture
= 0;
1017 wm_push_const_offset
= gen6_blorp_emit_wm_constants(brw
, params
);
1018 intel_miptree_used_for_rendering(params
->dst
.mt
);
1019 wm_surf_offset_renderbuffer
=
1020 gen6_blorp_emit_surface_state(brw
, params
, ¶ms
->dst
,
1021 I915_GEM_DOMAIN_RENDER
,
1022 I915_GEM_DOMAIN_RENDER
);
1023 if (params
->src
.mt
) {
1024 wm_surf_offset_texture
=
1025 gen6_blorp_emit_surface_state(brw
, params
, ¶ms
->src
,
1026 I915_GEM_DOMAIN_SAMPLER
, 0);
1029 gen6_blorp_emit_binding_table(brw
,
1030 wm_surf_offset_renderbuffer
,
1031 wm_surf_offset_texture
);
1034 if (params
->src
.mt
) {
1035 const uint32_t sampler_offset
=
1036 gen6_blorp_emit_sampler_state(brw
, BRW_MAPFILTER_LINEAR
, 0, true);
1037 gen6_blorp_emit_sampler_state_pointers(brw
, sampler_offset
);
1039 gen6_blorp_emit_vs_disable(brw
, params
);
1040 gen6_blorp_emit_gs_disable(brw
, params
);
1041 gen6_blorp_emit_clip_disable(brw
);
1042 gen6_blorp_emit_sf_config(brw
, params
);
1043 if (params
->wm_prog_data
)
1044 gen6_blorp_emit_constant_ps(brw
, params
, wm_push_const_offset
);
1046 gen6_blorp_emit_constant_ps_disable(brw
, params
);
1047 gen6_blorp_emit_wm_config(brw
, params
);
1048 if (params
->wm_prog_data
)
1049 gen6_blorp_emit_binding_table_pointers(brw
, wm_bind_bo_offset
);
1050 gen6_blorp_emit_viewport_state(brw
, params
);
1052 if (params
->depth
.mt
)
1053 gen6_blorp_emit_depth_stencil_config(brw
, params
);
1055 gen6_blorp_emit_depth_disable(brw
, params
);
1056 gen6_blorp_emit_clear_params(brw
, params
);
1057 gen6_blorp_emit_drawing_rectangle(brw
, params
);
1058 gen6_blorp_emit_primitive(brw
, params
);