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"
37 gen6_blorp_emit_input_varying_data(struct brw_context
*brw
,
38 const struct brw_blorp_params
*params
,
42 const unsigned vec4_size_in_bytes
= 4 * sizeof(float);
43 const unsigned max_num_varyings
=
44 DIV_ROUND_UP(sizeof(params
->wm_inputs
), vec4_size_in_bytes
);
45 const unsigned num_varyings
= params
->wm_prog_data
->num_varying_inputs
;
47 *size
= num_varyings
* vec4_size_in_bytes
;
49 const float *const inputs_src
= (const float *)¶ms
->wm_inputs
;
50 float *inputs
= (float *)brw_state_batch(brw
, AUB_TRACE_VERTEX_BUFFER
,
53 /* Walk over the attribute slots, determine if the attribute is used by
54 * the program and when necessary copy the values from the input storage to
55 * the vertex data buffer.
57 for (unsigned i
= 0; i
< max_num_varyings
; i
++) {
58 const gl_varying_slot attr
= VARYING_SLOT_VAR0
+ i
;
60 if (!(params
->wm_prog_data
->inputs_read
& BITFIELD64_BIT(attr
)))
63 memcpy(inputs
, inputs_src
+ i
* 4, vec4_size_in_bytes
);
70 gen6_blorp_emit_vertex_data(struct brw_context
*brw
,
71 const struct brw_blorp_params
*params
)
73 uint32_t vertex_offset
;
74 uint32_t const_data_offset
= 0;
75 unsigned const_data_size
= 0;
77 /* Setup VBO for the rectangle primitive..
79 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
80 * vertices. The vertices reside in screen space with DirectX coordinates
81 * (that is, (0, 0) is the upper left corner).
88 * Since the VS is disabled, the clipper loads each VUE directly from
89 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
90 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
92 * dw1: Render Target Array Index. The HiZ op does not use indexed
93 * vertices, so set the dword to 0.
94 * dw2: Viewport Index. The HiZ op disables viewport mapping and
95 * scissoring, so set the dword to 0.
96 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive, so
98 * dw4: Vertex Position X.
99 * dw5: Vertex Position Y.
100 * dw6: Vertex Position Z.
101 * dw7: Vertex Position W.
103 * dw8: Flat vertex input 0
104 * dw9: Flat vertex input 1
106 * dwn: Flat vertex input n - 8
108 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
109 * "Vertex URB Entry (VUE) Formats".
111 * Only vertex position X and Y are going to be variable, Z is fixed to
112 * zero and W to one. Header words dw0-3 are all zero. There is no need to
113 * include the fixed values in the vertex buffer. Vertex fetcher can be
114 * instructed to fill vertex elements with constant values of one and zero
115 * instead of reading them from the buffer.
116 * Flat inputs are program constants that are not interpolated. Moreover
117 * their values will be the same between vertices.
119 * See the vertex element setup below.
121 const float vertices
[] = {
122 /* v0 */ (float)params
->x0
, (float)params
->y1
,
123 /* v1 */ (float)params
->x1
, (float)params
->y1
,
124 /* v2 */ (float)params
->x0
, (float)params
->y0
,
127 float *const vertex_data
= (float *)brw_state_batch(
128 brw
, AUB_TRACE_VERTEX_BUFFER
,
129 sizeof(vertices
), 32,
131 memcpy(vertex_data
, vertices
, sizeof(vertices
));
133 if (params
->wm_prog_data
&& params
->wm_prog_data
->num_varying_inputs
)
134 gen6_blorp_emit_input_varying_data(brw
, params
,
138 /* 3DSTATE_VERTEX_BUFFERS */
139 const int num_buffers
= 1 + (const_data_size
> 0);
140 const int batch_length
= 1 + 4 * num_buffers
;
142 BEGIN_BATCH(batch_length
);
143 OUT_BATCH((_3DSTATE_VERTEX_BUFFERS
<< 16) | (batch_length
- 2));
145 const unsigned blorp_num_vue_elems
= 2;
146 const unsigned stride
= blorp_num_vue_elems
* sizeof(float);
147 EMIT_VERTEX_BUFFER_STATE(brw
, 0 /* buffer_nr */, brw
->batch
.bo
,
148 vertex_offset
, vertex_offset
+ sizeof(vertices
),
149 stride
, 0 /* steprate */);
151 if (const_data_size
) {
152 /* Tell vertex fetcher not to advance the pointer in the buffer when
153 * moving to the next vertex. This will effectively provide the same
154 * data for all the vertices. For flat inputs only the data provided
155 * for the first provoking vertex actually matters.
157 const unsigned stride_zero
= 0;
158 EMIT_VERTEX_BUFFER_STATE(brw
, 1 /* buffer_nr */, brw
->batch
.bo
,
160 const_data_offset
+ const_data_size
,
161 stride_zero
, 0 /* step_rate */);
168 gen6_blorp_emit_vertices(struct brw_context
*brw
,
169 const struct brw_blorp_params
*params
)
171 gen6_blorp_emit_vertex_data(brw
, params
);
173 const unsigned num_varyings
=
174 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
175 const unsigned num_elements
= 2 + num_varyings
;
176 const int batch_length
= 1 + 2 * num_elements
;
178 BEGIN_BATCH(batch_length
);
180 /* 3DSTATE_VERTEX_ELEMENTS
182 * Fetch dwords 0 - 7 from each VUE. See the comments above where
183 * the vertex_bo is filled with data. First element contains dwords
184 * for the VUE header, second the actual position values and the
185 * remaining contain the flat inputs.
188 OUT_BATCH((_3DSTATE_VERTEX_ELEMENTS
<< 16) | (batch_length
- 2));
190 OUT_BATCH(GEN6_VE0_VALID
|
191 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
<< BRW_VE0_FORMAT_SHIFT
|
192 0 << BRW_VE0_SRC_OFFSET_SHIFT
);
193 OUT_BATCH(BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_0_SHIFT
|
194 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_1_SHIFT
|
195 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_2_SHIFT
|
196 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_3_SHIFT
);
198 OUT_BATCH(GEN6_VE0_VALID
|
199 BRW_SURFACEFORMAT_R32G32_FLOAT
<< BRW_VE0_FORMAT_SHIFT
|
200 0 << BRW_VE0_SRC_OFFSET_SHIFT
);
201 OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_0_SHIFT
|
202 BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_1_SHIFT
|
203 BRW_VE1_COMPONENT_STORE_0
<< BRW_VE1_COMPONENT_2_SHIFT
|
204 BRW_VE1_COMPONENT_STORE_1_FLT
<< BRW_VE1_COMPONENT_3_SHIFT
);
207 for (unsigned i
= 0; i
< num_varyings
; ++i
) {
209 OUT_BATCH(1 << GEN6_VE0_INDEX_SHIFT
|
211 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
<< BRW_VE0_FORMAT_SHIFT
|
212 (i
* 4 * sizeof(float)) << BRW_VE0_SRC_OFFSET_SHIFT
);
213 OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_0_SHIFT
|
214 BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_1_SHIFT
|
215 BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_2_SHIFT
|
216 BRW_VE1_COMPONENT_STORE_SRC
<< BRW_VE1_COMPONENT_3_SHIFT
);
225 * Assign the entire URB to the VS. Even though the VS disabled, URB space
226 * is still needed because the clipper loads the VUE's from the URB. From
227 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
228 * Dword 1.15:0 "VS Number of URB Entries":
229 * This field is always used (even if VS Function Enable is DISABLED).
231 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
232 * safely ignore it because this batch contains only one draw call.
233 * Because of URB corruption caused by allocating a previous GS unit
234 * URB entry to the VS unit, software is required to send a “GS NULL
235 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
236 * plus a dummy DRAW call before any case where VS will be taking over
240 gen6_blorp_emit_urb_config(struct brw_context
*brw
,
241 const struct brw_blorp_params
*params
)
244 OUT_BATCH(_3DSTATE_URB
<< 16 | (3 - 2));
245 OUT_BATCH(brw
->urb
.max_vs_entries
<< GEN6_URB_VS_ENTRIES_SHIFT
);
253 gen6_blorp_emit_blend_state(struct brw_context
*brw
,
254 const struct brw_blorp_params
*params
)
256 uint32_t cc_blend_state_offset
;
258 assume(params
->num_draw_buffers
);
260 const unsigned size
= params
->num_draw_buffers
*
261 sizeof(struct gen6_blend_state
);
262 struct gen6_blend_state
*blend
= (struct gen6_blend_state
*)
263 brw_state_batch(brw
, AUB_TRACE_BLEND_STATE
, size
, 64,
264 &cc_blend_state_offset
);
266 memset(blend
, 0, size
);
268 for (unsigned i
= 0; i
< params
->num_draw_buffers
; ++i
) {
269 blend
[i
].blend1
.pre_blend_clamp_enable
= 1;
270 blend
[i
].blend1
.post_blend_clamp_enable
= 1;
271 blend
[i
].blend1
.clamp_range
= BRW_RENDERTARGET_CLAMPRANGE_FORMAT
;
273 blend
[i
].blend1
.write_disable_r
= params
->color_write_disable
[0];
274 blend
[i
].blend1
.write_disable_g
= params
->color_write_disable
[1];
275 blend
[i
].blend1
.write_disable_b
= params
->color_write_disable
[2];
276 blend
[i
].blend1
.write_disable_a
= params
->color_write_disable
[3];
279 return cc_blend_state_offset
;
285 gen6_blorp_emit_cc_state(struct brw_context
*brw
)
287 uint32_t cc_state_offset
;
289 struct gen6_color_calc_state
*cc
= (struct gen6_color_calc_state
*)
290 brw_state_batch(brw
, AUB_TRACE_CC_STATE
,
291 sizeof(gen6_color_calc_state
), 64,
293 memset(cc
, 0, sizeof(*cc
));
295 return cc_state_offset
;
300 * \param out_offset is relative to
301 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
304 gen6_blorp_emit_depth_stencil_state(struct brw_context
*brw
,
305 const struct brw_blorp_params
*params
)
307 uint32_t depthstencil_offset
;
309 struct gen6_depth_stencil_state
*state
;
310 state
= (struct gen6_depth_stencil_state
*)
311 brw_state_batch(brw
, AUB_TRACE_DEPTH_STENCIL_STATE
,
313 &depthstencil_offset
);
314 memset(state
, 0, sizeof(*state
));
316 /* See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
317 * - 7.5.3.1 Depth Buffer Clear
318 * - 7.5.3.2 Depth Buffer Resolve
319 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
321 state
->ds2
.depth_write_enable
= 1;
322 if (params
->hiz_op
== GEN6_HIZ_OP_DEPTH_RESOLVE
) {
323 state
->ds2
.depth_test_enable
= 1;
324 state
->ds2
.depth_test_func
= BRW_COMPAREFUNCTION_NEVER
;
327 return depthstencil_offset
;
331 /* 3DSTATE_CC_STATE_POINTERS
333 * The pointer offsets are relative to
334 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
336 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
339 gen6_blorp_emit_cc_state_pointers(struct brw_context
*brw
,
340 const struct brw_blorp_params
*params
,
341 uint32_t cc_blend_state_offset
,
342 uint32_t depthstencil_offset
,
343 uint32_t cc_state_offset
)
346 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS
<< 16 | (4 - 2));
347 OUT_BATCH(cc_blend_state_offset
| 1); /* BLEND_STATE offset */
348 OUT_BATCH(depthstencil_offset
| 1); /* DEPTH_STENCIL_STATE offset */
349 OUT_BATCH(cc_state_offset
| 1); /* COLOR_CALC_STATE offset */
354 /* BINDING_TABLE. See brw_wm_binding_table(). */
356 gen6_blorp_emit_binding_table(struct brw_context
*brw
,
357 uint32_t wm_surf_offset_renderbuffer
,
358 uint32_t wm_surf_offset_texture
)
360 uint32_t wm_bind_bo_offset
;
361 uint32_t *bind
= (uint32_t *)
362 brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
364 BRW_BLORP_NUM_BINDING_TABLE_ENTRIES
,
367 bind
[BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX
] =
368 wm_surf_offset_renderbuffer
;
369 bind
[BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX
] = wm_surf_offset_texture
;
371 return wm_bind_bo_offset
;
376 * SAMPLER_STATE. See brw_update_sampler_state().
379 gen6_blorp_emit_sampler_state(struct brw_context
*brw
,
380 unsigned tex_filter
, unsigned max_lod
,
381 bool non_normalized_coords
)
383 uint32_t sampler_offset
;
384 uint32_t *sampler_state
= (uint32_t *)
385 brw_state_batch(brw
, AUB_TRACE_SAMPLER_STATE
, 16, 32, &sampler_offset
);
387 unsigned address_rounding
= BRW_ADDRESS_ROUNDING_ENABLE_U_MIN
|
388 BRW_ADDRESS_ROUNDING_ENABLE_V_MIN
|
389 BRW_ADDRESS_ROUNDING_ENABLE_R_MIN
|
390 BRW_ADDRESS_ROUNDING_ENABLE_U_MAG
|
391 BRW_ADDRESS_ROUNDING_ENABLE_V_MAG
|
392 BRW_ADDRESS_ROUNDING_ENABLE_R_MAG
;
394 /* XXX: I don't think that using firstLevel, lastLevel works,
395 * because we always setup the surface state as if firstLevel ==
396 * level zero. Probably have to subtract firstLevel from each of
399 brw_emit_sampler_state(brw
,
402 tex_filter
, /* min filter */
403 tex_filter
, /* mag filter */
407 BRW_TEXCOORDMODE_CLAMP
,
408 BRW_TEXCOORDMODE_CLAMP
,
409 BRW_TEXCOORDMODE_CLAMP
,
413 0, /* shadow function */
414 non_normalized_coords
,
415 0); /* border color offset - unused */
417 return sampler_offset
;
422 * 3DSTATE_SAMPLER_STATE_POINTERS. See upload_sampler_state_pointers().
425 gen6_blorp_emit_sampler_state_pointers(struct brw_context
*brw
,
426 uint32_t sampler_offset
)
429 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS
<< 16 |
430 VS_SAMPLER_STATE_CHANGE
|
431 GS_SAMPLER_STATE_CHANGE
|
432 PS_SAMPLER_STATE_CHANGE
|
434 OUT_BATCH(0); /* VS */
435 OUT_BATCH(0); /* GS */
436 OUT_BATCH(sampler_offset
);
443 * Disable vertex shader.
446 gen6_blorp_emit_vs_disable(struct brw_context
*brw
,
447 const struct brw_blorp_params
*params
)
449 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
450 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
452 * [DevSNB] A pipeline flush must be programmed prior to a
453 * 3DSTATE_VS command that causes the VS Function Enable to
454 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
455 * command with CS stall bit set and a post sync operation.
457 * We've already done one at the start of the BLORP operation.
460 /* Disable the push constant buffers. */
462 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 | (5 - 2));
470 OUT_BATCH(_3DSTATE_VS
<< 16 | (6 - 2));
482 * Disable the geometry shader.
485 gen6_blorp_emit_gs_disable(struct brw_context
*brw
,
486 const struct brw_blorp_params
*params
)
488 /* Disable all the constant buffers. */
490 OUT_BATCH(_3DSTATE_CONSTANT_GS
<< 16 | (5 - 2));
498 OUT_BATCH(_3DSTATE_GS
<< 16 | (7 - 2));
506 brw
->gs
.enabled
= false;
512 * Disable the clipper.
514 * The BLORP op emits a rectangle primitive, which requires clipping to
515 * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
516 * Section 1.3 "3D Primitives Overview":
518 * Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
519 * Mode should be set to a value other than CLIPMODE_NORMAL.
521 * Also disable perspective divide. This doesn't change the clipper's
522 * output, but does spare a few electrons.
525 gen6_blorp_emit_clip_disable(struct brw_context
*brw
)
528 OUT_BATCH(_3DSTATE_CLIP
<< 16 | (4 - 2));
530 OUT_BATCH(GEN6_CLIP_PERSPECTIVE_DIVIDE_DISABLE
);
538 * Disable ViewportTransformEnable (dw2.1)
540 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
541 * Primitives Overview":
542 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
543 * use of screen- space coordinates).
545 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
546 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
548 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
549 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
550 * SOLID: Any triangle or rectangle object found to be front-facing
551 * is rendered as a solid object. This setting is required when
552 * (rendering rectangle (RECTLIST) objects.
555 gen6_blorp_emit_sf_config(struct brw_context
*brw
,
556 const struct brw_blorp_params
*params
)
558 const unsigned num_varyings
=
559 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
560 const unsigned urb_read_length
=
561 brw_blorp_get_urb_length(params
->wm_prog_data
);
564 OUT_BATCH(_3DSTATE_SF
<< 16 | (20 - 2));
565 OUT_BATCH(num_varyings
<< GEN6_SF_NUM_OUTPUTS_SHIFT
|
566 urb_read_length
<< GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT
|
567 BRW_SF_URB_ENTRY_READ_OFFSET
<<
568 GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT
);
569 OUT_BATCH(0); /* dw2 */
570 OUT_BATCH(params
->dst
.surf
.samples
> 1 ? GEN6_SF_MSRAST_ON_PATTERN
: 0);
571 for (int i
= 0; i
< 13; ++i
)
573 OUT_BATCH(params
->wm_prog_data
? params
->wm_prog_data
->flat_inputs
: 0);
581 * Enable or disable thread dispatch and set the HiZ op appropriately.
584 gen6_blorp_emit_wm_config(struct brw_context
*brw
,
585 const struct brw_blorp_params
*params
)
587 const struct brw_blorp_prog_data
*prog_data
= params
->wm_prog_data
;
588 uint32_t dw2
, dw4
, dw5
, dw6
, ksp0
, ksp2
;
590 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
591 * nonzero to prevent the GPU from hanging. While the documentation doesn't
592 * mention this explicitly, it notes that the valid range for the field is
593 * [1,39] = [2,40] threads, which excludes zero.
595 * To be safe (and to minimize extraneous code) we go ahead and fully
596 * configure the WM state whether or not there is a WM program.
599 dw2
= dw4
= dw5
= dw6
= ksp0
= ksp2
= 0;
600 switch (params
->hiz_op
) {
601 case GEN6_HIZ_OP_DEPTH_CLEAR
:
602 dw4
|= GEN6_WM_DEPTH_CLEAR
;
604 case GEN6_HIZ_OP_DEPTH_RESOLVE
:
605 dw4
|= GEN6_WM_DEPTH_RESOLVE
;
607 case GEN6_HIZ_OP_HIZ_RESOLVE
:
608 dw4
|= GEN6_WM_HIERARCHICAL_DEPTH_RESOLVE
;
610 case GEN6_HIZ_OP_NONE
:
613 unreachable("not reached");
615 dw5
|= GEN6_WM_LINE_AA_WIDTH_1_0
;
616 dw5
|= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5
;
617 dw5
|= (brw
->max_wm_threads
- 1) << GEN6_WM_MAX_THREADS_SHIFT
;
618 dw6
|= 0 << GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT
; /* No interp */
619 dw6
|= (params
->wm_prog_data
? prog_data
->num_varying_inputs
: 0) <<
620 GEN6_WM_NUM_SF_OUTPUTS_SHIFT
;
622 if (params
->wm_prog_data
) {
623 dw5
|= GEN6_WM_DISPATCH_ENABLE
; /* We are rendering */
625 dw4
|= prog_data
->first_curbe_grf_0
<< GEN6_WM_DISPATCH_START_GRF_SHIFT_0
;
626 dw4
|= prog_data
->first_curbe_grf_2
<< GEN6_WM_DISPATCH_START_GRF_SHIFT_2
;
628 ksp0
= params
->wm_prog_kernel
;
629 ksp2
= params
->wm_prog_kernel
+ params
->wm_prog_data
->ksp_offset_2
;
631 if (params
->wm_prog_data
->dispatch_8
)
632 dw5
|= GEN6_WM_8_DISPATCH_ENABLE
;
633 if (params
->wm_prog_data
->dispatch_16
)
634 dw5
|= GEN6_WM_16_DISPATCH_ENABLE
;
637 if (params
->src
.mt
) {
638 dw5
|= GEN6_WM_KILL_ENABLE
; /* TODO: temporarily smash on */
639 dw2
|= 1 << GEN6_WM_SAMPLER_COUNT_SHIFT
; /* Up to 4 samplers */
642 if (params
->dst
.surf
.samples
> 1) {
643 dw6
|= GEN6_WM_MSRAST_ON_PATTERN
;
644 if (prog_data
&& prog_data
->persample_msaa_dispatch
)
645 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
647 dw6
|= GEN6_WM_MSDISPMODE_PERPIXEL
;
649 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
650 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
654 OUT_BATCH(_3DSTATE_WM
<< 16 | (9 - 2));
657 OUT_BATCH(0); /* No scratch needed */
661 OUT_BATCH(0); /* kernel 1 pointer */
667 gen6_blorp_emit_constant_ps_disable(struct brw_context
*brw
,
668 const struct brw_blorp_params
*params
)
670 /* Disable the push constant buffers. */
672 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (5 - 2));
681 * 3DSTATE_BINDING_TABLE_POINTERS
684 gen6_blorp_emit_binding_table_pointers(struct brw_context
*brw
,
685 uint32_t wm_bind_bo_offset
)
688 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 |
689 GEN6_BINDING_TABLE_MODIFY_PS
|
691 OUT_BATCH(0); /* vs -- ignored */
692 OUT_BATCH(0); /* gs -- ignored */
693 OUT_BATCH(wm_bind_bo_offset
); /* wm/ps */
699 gen6_blorp_emit_depth_stencil_config(struct brw_context
*brw
,
700 const struct brw_blorp_params
*params
)
703 GLenum gl_target
= params
->depth
.mt
->target
;
706 case GL_TEXTURE_CUBE_MAP_ARRAY
:
707 case GL_TEXTURE_CUBE_MAP
:
708 /* The PRM claims that we should use BRW_SURFACE_CUBE for this
709 * situation, but experiments show that gl_Layer doesn't work when we do
710 * this. So we use BRW_SURFACE_2D, since for rendering purposes this is
713 surftype
= BRW_SURFACE_2D
;
716 surftype
= translate_tex_target(gl_target
);
720 /* 3DSTATE_DEPTH_BUFFER */
722 brw_emit_depth_stall_flushes(brw
);
724 unsigned depth
= MAX2(params
->depth
.surf
.logical_level0_px
.depth
,
725 params
->depth
.surf
.logical_level0_px
.array_len
);
728 /* 3DSTATE_DEPTH_BUFFER dw0 */
729 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
731 /* 3DSTATE_DEPTH_BUFFER dw1 */
732 OUT_BATCH((params
->depth
.surf
.row_pitch
- 1) |
733 params
->depth_format
<< 18 |
734 1 << 21 | /* separate stencil enable */
735 1 << 22 | /* hiz enable */
736 BRW_TILEWALK_YMAJOR
<< 26 |
737 1 << 27 | /* y-tiled */
740 /* 3DSTATE_DEPTH_BUFFER dw2 */
741 OUT_RELOC(params
->depth
.mt
->bo
,
742 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
745 /* 3DSTATE_DEPTH_BUFFER dw3 */
746 OUT_BATCH(BRW_SURFACE_MIPMAPLAYOUT_BELOW
<< 1 |
747 (params
->depth
.surf
.logical_level0_px
.width
- 1) << 6 |
748 (params
->depth
.surf
.logical_level0_px
.height
- 1) << 19 |
749 params
->depth
.view
.base_level
<< 2);
751 /* 3DSTATE_DEPTH_BUFFER dw4 */
752 OUT_BATCH((depth
- 1) << 21 |
753 params
->depth
.view
.base_array_layer
<< 10 |
756 /* 3DSTATE_DEPTH_BUFFER dw5 */
759 /* 3DSTATE_DEPTH_BUFFER dw6 */
764 /* 3DSTATE_HIER_DEPTH_BUFFER */
766 struct intel_mipmap_tree
*hiz_mt
= params
->depth
.mt
->hiz_buf
->mt
;
769 if (hiz_mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
770 const unsigned lod
= params
->depth
.view
.base_level
;
771 offset
= intel_miptree_get_aligned_offset(hiz_mt
,
772 hiz_mt
->level
[lod
].level_x
,
773 hiz_mt
->level
[lod
].level_y
,
778 OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER
<< 16) | (3 - 2));
779 OUT_BATCH(hiz_mt
->pitch
- 1);
780 OUT_RELOC(hiz_mt
->bo
,
781 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
786 /* 3DSTATE_STENCIL_BUFFER */
789 OUT_BATCH((_3DSTATE_STENCIL_BUFFER
<< 16) | (3 - 2));
798 gen6_blorp_emit_depth_disable(struct brw_context
*brw
,
799 const struct brw_blorp_params
*params
)
801 brw_emit_depth_stall_flushes(brw
);
804 OUT_BATCH(_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
805 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT
<< 18) |
806 (BRW_SURFACE_NULL
<< 29));
815 OUT_BATCH(_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
821 OUT_BATCH(_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
828 /* 3DSTATE_CLEAR_PARAMS
830 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
831 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
832 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
835 gen6_blorp_emit_clear_params(struct brw_context
*brw
,
836 const struct brw_blorp_params
*params
)
839 OUT_BATCH(_3DSTATE_CLEAR_PARAMS
<< 16 |
840 GEN5_DEPTH_CLEAR_VALID
|
842 OUT_BATCH(params
->depth
.mt
? params
->depth
.mt
->depth_clear_value
: 0);
847 /* 3DSTATE_DRAWING_RECTANGLE */
849 gen6_blorp_emit_drawing_rectangle(struct brw_context
*brw
,
850 const struct brw_blorp_params
*params
)
853 OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE
<< 16 | (4 - 2));
855 OUT_BATCH(((MAX2(params
->x1
, params
->x0
) - 1) & 0xffff) |
856 ((MAX2(params
->y1
, params
->y0
) - 1) << 16));
861 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
863 gen6_blorp_emit_viewport_state(struct brw_context
*brw
,
864 const struct brw_blorp_params
*params
)
866 struct brw_cc_viewport
*ccv
;
867 uint32_t cc_vp_offset
;
869 ccv
= (struct brw_cc_viewport
*)brw_state_batch(brw
, AUB_TRACE_CC_VP_STATE
,
873 ccv
->min_depth
= 0.0;
874 ccv
->max_depth
= 1.0;
877 OUT_BATCH(_3DSTATE_VIEWPORT_STATE_POINTERS
<< 16 | (4 - 2) |
878 GEN6_CC_VIEWPORT_MODIFY
);
879 OUT_BATCH(0); /* clip VP */
880 OUT_BATCH(0); /* SF VP */
881 OUT_BATCH(cc_vp_offset
);
888 gen6_blorp_emit_primitive(struct brw_context
*brw
,
889 const struct brw_blorp_params
*params
)
892 OUT_BATCH(CMD_3D_PRIM
<< 16 | (6 - 2) |
893 _3DPRIM_RECTLIST
<< GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT
|
894 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
);
895 OUT_BATCH(3); /* vertex count per instance */
897 OUT_BATCH(params
->num_layers
); /* instance count */
904 * \brief Execute a blit or render pass operation.
906 * To execute the operation, this function manually constructs and emits a
907 * batch to draw a rectangle primitive. The batchbuffer is flushed before
908 * constructing and after emitting the batch.
910 * This function alters no GL state.
913 gen6_blorp_exec(struct brw_context
*brw
,
914 const struct brw_blorp_params
*params
)
916 uint32_t cc_blend_state_offset
= 0;
917 uint32_t cc_state_offset
= 0;
918 uint32_t depthstencil_offset
;
919 uint32_t wm_bind_bo_offset
= 0;
921 /* Emit workaround flushes when we switch from drawing to blorping. */
922 brw_emit_post_sync_nonzero_flush(brw
);
924 brw_upload_state_base_address(brw
);
926 gen6_emit_3dstate_multisample(brw
, params
->dst
.surf
.samples
);
927 gen6_emit_3dstate_sample_mask(brw
,
928 params
->dst
.surf
.samples
> 1 ?
929 (1 << params
->dst
.surf
.samples
) - 1 : 1);
930 gen6_blorp_emit_vertices(brw
, params
);
931 gen6_blorp_emit_urb_config(brw
, params
);
932 if (params
->wm_prog_data
) {
933 cc_blend_state_offset
= gen6_blorp_emit_blend_state(brw
, params
);
934 cc_state_offset
= gen6_blorp_emit_cc_state(brw
);
936 depthstencil_offset
= gen6_blorp_emit_depth_stencil_state(brw
, params
);
937 gen6_blorp_emit_cc_state_pointers(brw
, params
, cc_blend_state_offset
,
938 depthstencil_offset
, cc_state_offset
);
939 if (params
->wm_prog_data
) {
940 uint32_t wm_surf_offset_renderbuffer
;
941 uint32_t wm_surf_offset_texture
= 0;
943 intel_miptree_used_for_rendering(params
->dst
.mt
);
944 wm_surf_offset_renderbuffer
=
945 brw_blorp_emit_surface_state(brw
, ¶ms
->dst
,
946 I915_GEM_DOMAIN_RENDER
,
947 I915_GEM_DOMAIN_RENDER
, true);
948 if (params
->src
.mt
) {
949 wm_surf_offset_texture
=
950 brw_blorp_emit_surface_state(brw
, ¶ms
->src
,
951 I915_GEM_DOMAIN_SAMPLER
, 0, false);
954 gen6_blorp_emit_binding_table(brw
,
955 wm_surf_offset_renderbuffer
,
956 wm_surf_offset_texture
);
959 if (params
->src
.mt
) {
960 const uint32_t sampler_offset
=
961 gen6_blorp_emit_sampler_state(brw
, BRW_MAPFILTER_LINEAR
, 0, true);
962 gen6_blorp_emit_sampler_state_pointers(brw
, sampler_offset
);
964 gen6_blorp_emit_vs_disable(brw
, params
);
965 gen6_blorp_emit_gs_disable(brw
, params
);
966 gen6_blorp_emit_clip_disable(brw
);
967 gen6_blorp_emit_sf_config(brw
, params
);
968 gen6_blorp_emit_constant_ps_disable(brw
, params
);
969 gen6_blorp_emit_wm_config(brw
, params
);
970 if (params
->wm_prog_data
)
971 gen6_blorp_emit_binding_table_pointers(brw
, wm_bind_bo_offset
);
972 gen6_blorp_emit_viewport_state(brw
, params
);
974 if (params
->depth
.mt
)
975 gen6_blorp_emit_depth_stencil_config(brw
, params
);
977 gen6_blorp_emit_depth_disable(brw
, params
);
978 gen6_blorp_emit_clear_params(brw
, params
);
979 gen6_blorp_emit_drawing_rectangle(brw
, params
);
980 gen6_blorp_emit_primitive(brw
, params
);