2 * Copyright © 2016 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
24 #ifndef BLORP_GENX_EXEC_H
25 #define BLORP_GENX_EXEC_H
27 #include "blorp_priv.h"
28 #include "common/gen_device_info.h"
29 #include "common/gen_sample_positions.h"
30 #include "intel_aub.h"
33 * This file provides the blorp pipeline setup and execution functionality.
34 * It defines the following function:
37 * blorp_exec(struct blorp_context *blorp, void *batch_data,
38 * const struct blorp_params *params);
40 * It is the job of whoever includes this header to wrap this in something
41 * to get an externally visible symbol.
43 * In order for the blorp_exec function to work, the driver must provide
44 * implementations of the following static helper functions.
48 blorp_emit_dwords(struct blorp_batch
*batch
, unsigned n
);
51 blorp_emit_reloc(struct blorp_batch
*batch
,
52 void *location
, struct blorp_address address
, uint32_t delta
);
55 blorp_alloc_dynamic_state(struct blorp_batch
*batch
,
56 enum aub_state_struct_type type
,
61 blorp_alloc_vertex_buffer(struct blorp_batch
*batch
, uint32_t size
,
62 struct blorp_address
*addr
);
65 blorp_alloc_binding_table(struct blorp_batch
*batch
, unsigned num_entries
,
66 unsigned state_size
, unsigned state_alignment
,
67 uint32_t *bt_offset
, uint32_t *surface_offsets
,
71 blorp_flush_range(struct blorp_batch
*batch
, void *start
, size_t size
);
74 blorp_surface_reloc(struct blorp_batch
*batch
, uint32_t ss_offset
,
75 struct blorp_address address
, uint32_t delta
);
78 blorp_emit_urb_config(struct blorp_batch
*batch
, unsigned vs_entry_size
);
80 /***** BEGIN blorp_exec implementation ******/
82 #include "genxml/gen_macros.h"
85 _blorp_combine_address(struct blorp_batch
*batch
, void *location
,
86 struct blorp_address address
, uint32_t delta
)
88 if (address
.buffer
== NULL
) {
89 return address
.offset
+ delta
;
91 return blorp_emit_reloc(batch
, location
, address
, delta
);
95 #define __gen_address_type struct blorp_address
96 #define __gen_user_data struct blorp_batch
97 #define __gen_combine_address _blorp_combine_address
99 #include "genxml/genX_pack.h"
101 #define _blorp_cmd_length(cmd) cmd ## _length
102 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
103 #define _blorp_cmd_header(cmd) cmd ## _header
104 #define _blorp_cmd_pack(cmd) cmd ## _pack
106 #define blorp_emit(batch, cmd, name) \
107 for (struct cmd name = { _blorp_cmd_header(cmd) }, \
108 *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
109 __builtin_expect(_dst != NULL, 1); \
110 _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name), \
113 #define blorp_emitn(batch, cmd, n) ({ \
114 uint32_t *_dw = blorp_emit_dwords(batch, n); \
116 struct cmd template = { \
117 _blorp_cmd_header(cmd), \
118 .DWordLength = n - _blorp_cmd_length_bias(cmd), \
120 _blorp_cmd_pack(cmd)(batch, _dw, &template); \
122 _dw ? _dw + 1 : NULL; /* Array starts at dw[1] */ \
131 * Assign the entire URB to the VS. Even though the VS disabled, URB space
132 * is still needed because the clipper loads the VUE's from the URB. From
133 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
134 * Dword 1.15:0 "VS Number of URB Entries":
135 * This field is always used (even if VS Function Enable is DISABLED).
137 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
138 * safely ignore it because this batch contains only one draw call.
139 * Because of URB corruption caused by allocating a previous GS unit
140 * URB entry to the VS unit, software is required to send a “GS NULL
141 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
142 * plus a dummy DRAW call before any case where VS will be taking over
145 * If the 3DSTATE_URB_VS is emitted, than the others must be also.
146 * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
148 * 3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
149 * programmed in order for the programming of this state to be
153 emit_urb_config(struct blorp_batch
*batch
,
154 const struct blorp_params
*params
)
156 /* Once vertex fetcher has written full VUE entries with complete
157 * header the space requirement is as follows per vertex (in bytes):
159 * Header Position Program constants
160 * +--------+------------+-------------------+
161 * | 16 | 16 | n x 16 |
162 * +--------+------------+-------------------+
164 * where 'n' stands for number of varying inputs expressed as vec4s.
166 const unsigned num_varyings
=
167 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
168 const unsigned total_needed
= 16 + 16 + num_varyings
* 16;
170 /* The URB size is expressed in units of 64 bytes (512 bits) */
171 const unsigned vs_entry_size
= DIV_ROUND_UP(total_needed
, 64);
173 blorp_emit_urb_config(batch
, vs_entry_size
);
177 blorp_emit_vertex_data(struct blorp_batch
*batch
,
178 const struct blorp_params
*params
,
179 struct blorp_address
*addr
,
182 const float vertices
[] = {
183 /* v0 */ (float)params
->x1
, (float)params
->y1
, params
->z
,
184 /* v1 */ (float)params
->x0
, (float)params
->y1
, params
->z
,
185 /* v2 */ (float)params
->x0
, (float)params
->y0
, params
->z
,
188 void *data
= blorp_alloc_vertex_buffer(batch
, sizeof(vertices
), addr
);
189 memcpy(data
, vertices
, sizeof(vertices
));
190 *size
= sizeof(vertices
);
191 blorp_flush_range(batch
, data
, *size
);
195 blorp_emit_input_varying_data(struct blorp_batch
*batch
,
196 const struct blorp_params
*params
,
197 struct blorp_address
*addr
,
200 const unsigned vec4_size_in_bytes
= 4 * sizeof(float);
201 const unsigned max_num_varyings
=
202 DIV_ROUND_UP(sizeof(params
->wm_inputs
), vec4_size_in_bytes
);
203 const unsigned num_varyings
=
204 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
206 *size
= 16 + num_varyings
* vec4_size_in_bytes
;
208 const uint32_t *const inputs_src
= (const uint32_t *)¶ms
->wm_inputs
;
209 void *data
= blorp_alloc_vertex_buffer(batch
, *size
, addr
);
210 uint32_t *inputs
= data
;
212 /* Copy in the VS inputs */
213 assert(sizeof(params
->vs_inputs
) == 16);
214 memcpy(inputs
, ¶ms
->vs_inputs
, sizeof(params
->vs_inputs
));
217 if (params
->wm_prog_data
) {
218 /* Walk over the attribute slots, determine if the attribute is used by
219 * the program and when necessary copy the values from the input storage
220 * to the vertex data buffer.
222 for (unsigned i
= 0; i
< max_num_varyings
; i
++) {
223 const gl_varying_slot attr
= VARYING_SLOT_VAR0
+ i
;
225 const int input_index
= params
->wm_prog_data
->urb_setup
[attr
];
229 memcpy(inputs
, inputs_src
+ i
* 4, vec4_size_in_bytes
);
235 blorp_flush_range(batch
, data
, *size
);
239 blorp_emit_vertex_buffers(struct blorp_batch
*batch
,
240 const struct blorp_params
*params
)
242 struct GENX(VERTEX_BUFFER_STATE
) vb
[2];
243 memset(vb
, 0, sizeof(vb
));
246 blorp_emit_vertex_data(batch
, params
, &vb
[0].BufferStartingAddress
, &size
);
247 vb
[0].VertexBufferIndex
= 0;
248 vb
[0].BufferPitch
= 3 * sizeof(float);
249 vb
[0].VertexBufferMOCS
= batch
->blorp
->mocs
.vb
;
251 vb
[0].AddressModifyEnable
= true;
254 vb
[0].BufferSize
= size
;
256 vb
[0].BufferAccessType
= VERTEXDATA
;
257 vb
[0].EndAddress
= vb
[0].BufferStartingAddress
;
258 vb
[0].EndAddress
.offset
+= size
- 1;
261 blorp_emit_input_varying_data(batch
, params
,
262 &vb
[1].BufferStartingAddress
, &size
);
263 vb
[1].VertexBufferIndex
= 1;
264 vb
[1].BufferPitch
= 0;
265 vb
[1].VertexBufferMOCS
= batch
->blorp
->mocs
.vb
;
267 vb
[1].AddressModifyEnable
= true;
270 vb
[1].BufferSize
= size
;
272 vb
[1].BufferAccessType
= INSTANCEDATA
;
273 vb
[1].EndAddress
= vb
[1].BufferStartingAddress
;
274 vb
[1].EndAddress
.offset
+= size
- 1;
277 const unsigned num_dwords
= 1 + GENX(VERTEX_BUFFER_STATE_length
) * 2;
278 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), num_dwords
);
282 for (unsigned i
= 0; i
< 2; i
++) {
283 GENX(VERTEX_BUFFER_STATE_pack
)(batch
, dw
, &vb
[i
]);
284 dw
+= GENX(VERTEX_BUFFER_STATE_length
);
289 blorp_emit_vertex_elements(struct blorp_batch
*batch
,
290 const struct blorp_params
*params
)
292 const unsigned num_varyings
=
293 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
294 const unsigned num_elements
= 2 + num_varyings
;
296 struct GENX(VERTEX_ELEMENT_STATE
) ve
[num_elements
];
297 memset(ve
, 0, num_elements
* sizeof(*ve
));
299 /* Setup VBO for the rectangle primitive..
301 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
302 * vertices. The vertices reside in screen space with DirectX
303 * coordinates (that is, (0, 0) is the upper left corner).
310 * Since the VS is disabled, the clipper loads each VUE directly from
311 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
312 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
313 * dw0: Reserved, MBZ.
314 * dw1: Render Target Array Index. Below vertex fetcher gets programmed
315 * to assign this with primitive instance identifier which will be
316 * used for layered clears. All other renders have only one instance
317 * and therefore the value will be effectively zero.
318 * dw2: Viewport Index. The HiZ op disables viewport mapping and
319 * scissoring, so set the dword to 0.
320 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
321 * so set the dword to 0.
322 * dw4: Vertex Position X.
323 * dw5: Vertex Position Y.
324 * dw6: Vertex Position Z.
325 * dw7: Vertex Position W.
327 * dw8: Flat vertex input 0
328 * dw9: Flat vertex input 1
330 * dwn: Flat vertex input n - 8
332 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
333 * "Vertex URB Entry (VUE) Formats".
335 * Only vertex position X and Y are going to be variable, Z is fixed to
336 * zero and W to one. Header words dw0,2,3 are zero. There is no need to
337 * include the fixed values in the vertex buffer. Vertex fetcher can be
338 * instructed to fill vertex elements with constant values of one and zero
339 * instead of reading them from the buffer.
340 * Flat inputs are program constants that are not interpolated. Moreover
341 * their values will be the same between vertices.
343 * See the vertex element setup below.
345 ve
[0].VertexBufferIndex
= 1;
347 ve
[0].SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
348 ve
[0].SourceElementOffset
= 0;
349 ve
[0].Component0Control
= VFCOMP_STORE_SRC
;
351 /* From Gen8 onwards hardware is no more instructed to overwrite components
352 * using an element specifier. Instead one has separate 3DSTATE_VF_SGVS
353 * (System Generated Value Setup) state packet for it.
356 ve
[0].Component1Control
= VFCOMP_STORE_0
;
358 ve
[0].Component1Control
= VFCOMP_STORE_IID
;
360 ve
[0].Component2Control
= VFCOMP_STORE_SRC
;
361 ve
[0].Component3Control
= VFCOMP_STORE_SRC
;
363 ve
[1].VertexBufferIndex
= 0;
365 ve
[1].SourceElementFormat
= ISL_FORMAT_R32G32B32_FLOAT
;
366 ve
[1].SourceElementOffset
= 0;
367 ve
[1].Component0Control
= VFCOMP_STORE_SRC
;
368 ve
[1].Component1Control
= VFCOMP_STORE_SRC
;
369 ve
[1].Component2Control
= VFCOMP_STORE_SRC
;
370 ve
[1].Component3Control
= VFCOMP_STORE_1_FP
;
372 for (unsigned i
= 0; i
< num_varyings
; ++i
) {
373 ve
[i
+ 2].VertexBufferIndex
= 1;
374 ve
[i
+ 2].Valid
= true;
375 ve
[i
+ 2].SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
376 ve
[i
+ 2].SourceElementOffset
= 16 + i
* 4 * sizeof(float);
377 ve
[i
+ 2].Component0Control
= VFCOMP_STORE_SRC
;
378 ve
[i
+ 2].Component1Control
= VFCOMP_STORE_SRC
;
379 ve
[i
+ 2].Component2Control
= VFCOMP_STORE_SRC
;
380 ve
[i
+ 2].Component3Control
= VFCOMP_STORE_SRC
;
383 const unsigned num_dwords
=
384 1 + GENX(VERTEX_ELEMENT_STATE_length
) * num_elements
;
385 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_ELEMENTS
), num_dwords
);
389 for (unsigned i
= 0; i
< num_elements
; i
++) {
390 GENX(VERTEX_ELEMENT_STATE_pack
)(batch
, dw
, &ve
[i
]);
391 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
395 /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
396 * primitive instance identifier. This is used for layered clears.
398 blorp_emit(batch
, GENX(3DSTATE_VF_SGVS
), sgvs
) {
399 sgvs
.InstanceIDEnable
= true;
400 sgvs
.InstanceIDComponentNumber
= COMP_1
;
401 sgvs
.InstanceIDElementOffset
= 0;
404 for (unsigned i
= 0; i
< num_elements
; i
++) {
405 blorp_emit(batch
, GENX(3DSTATE_VF_INSTANCING
), vf
) {
406 vf
.VertexElementIndex
= i
;
407 vf
.InstancingEnable
= false;
411 blorp_emit(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
412 topo
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
418 blorp_emit_vs_config(struct blorp_batch
*batch
,
419 const struct blorp_params
*params
)
421 struct brw_vs_prog_data
*vs_prog_data
= params
->vs_prog_data
;
423 blorp_emit(batch
, GENX(3DSTATE_VS
), vs
) {
425 vs
.FunctionEnable
= true;
427 vs
.KernelStartPointer
= params
->vs_prog_kernel
;
429 vs
.DispatchGRFStartRegisterForURBData
=
430 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
431 vs
.VertexURBEntryReadLength
=
432 vs_prog_data
->base
.urb_read_length
;
433 vs
.VertexURBEntryReadOffset
= 0;
435 vs
.MaximumNumberofThreads
=
436 batch
->blorp
->isl_dev
->info
->max_vs_threads
- 1;
439 vs
.SIMD8DispatchEnable
=
440 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
447 blorp_emit_sf_config(struct blorp_batch
*batch
,
448 const struct blorp_params
*params
)
450 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
454 * Disable ViewportTransformEnable (dw2.1)
456 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
457 * Primitives Overview":
458 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
459 * use of screen- space coordinates).
461 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
462 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
464 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
465 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
466 * SOLID: Any triangle or rectangle object found to be front-facing
467 * is rendered as a solid object. This setting is required when
468 * (rendering rectangle (RECTLIST) objects.
473 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
);
475 blorp_emit(batch
, GENX(3DSTATE_RASTER
), raster
) {
476 raster
.CullMode
= CULLMODE_NONE
;
479 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
480 sbe
.VertexURBEntryReadOffset
= 1;
482 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
483 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
484 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
486 sbe
.NumberofSFOutputAttributes
= 0;
487 sbe
.VertexURBEntryReadLength
= 1;
489 sbe
.ForceVertexURBEntryReadLength
= true;
490 sbe
.ForceVertexURBEntryReadOffset
= true;
493 for (unsigned i
= 0; i
< 32; i
++)
494 sbe
.AttributeActiveComponentFormat
[i
] = ACF_XYZW
;
500 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
501 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
502 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
504 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
505 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
508 sf
.DepthBufferSurfaceFormat
= params
->depth_format
;
512 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
513 sbe
.VertexURBEntryReadOffset
= 1;
515 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
516 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
517 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
519 sbe
.NumberofSFOutputAttributes
= 0;
520 sbe
.VertexURBEntryReadLength
= 1;
524 #else /* GEN_GEN <= 6 */
526 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
527 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
528 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
530 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
531 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
533 sf
.VertexURBEntryReadOffset
= 1;
535 sf
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
536 sf
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
537 sf
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
539 sf
.NumberofSFOutputAttributes
= 0;
540 sf
.VertexURBEntryReadLength
= 1;
548 blorp_emit_ps_config(struct blorp_batch
*batch
,
549 const struct blorp_params
*params
)
551 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
553 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
554 * nonzero to prevent the GPU from hanging. While the documentation doesn't
555 * mention this explicitly, it notes that the valid range for the field is
556 * [1,39] = [2,40] threads, which excludes zero.
558 * To be safe (and to minimize extraneous code) we go ahead and fully
559 * configure the WM state whether or not there is a WM program.
564 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
);
566 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
567 if (params
->src
.enabled
) {
568 ps
.SamplerCount
= 1; /* Up to 4 samplers */
569 ps
.BindingTableEntryCount
= 2;
571 ps
.BindingTableEntryCount
= 1;
575 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
576 prog_data
->base
.dispatch_grf_start_reg
;
577 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
578 prog_data
->dispatch_grf_start_reg_2
;
580 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
581 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
583 ps
.KernelStartPointer0
= params
->wm_prog_kernel
;
584 ps
.KernelStartPointer2
=
585 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
588 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64;
589 * it implicitly scales for different GT levels (which have some # of
592 * In Gen8 the format is U8-2 whereas in Gen9 it is U8-1.
595 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
597 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
599 switch (params
->fast_clear_op
) {
600 case BLORP_FAST_CLEAR_OP_NONE
:
603 case BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL
:
604 ps
.RenderTargetResolveType
= RESOLVE_PARTIAL
;
606 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
607 ps
.RenderTargetResolveType
= RESOLVE_FULL
;
610 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
611 ps
.RenderTargetResolveEnable
= true;
614 case BLORP_FAST_CLEAR_OP_CLEAR
:
615 ps
.RenderTargetFastClearEnable
= true;
618 unreachable("Invalid fast clear op");
622 blorp_emit(batch
, GENX(3DSTATE_PS_EXTRA
), psx
) {
624 psx
.PixelShaderValid
= true;
625 psx
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
626 psx
.PixelShaderIsPerSample
= prog_data
->persample_dispatch
;
629 if (params
->src
.enabled
)
630 psx
.PixelShaderKillsPixel
= true;
635 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
636 switch (params
->hiz_op
) {
637 case BLORP_HIZ_OP_DEPTH_CLEAR
:
638 wm
.DepthBufferClear
= true;
640 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
641 wm
.DepthBufferResolveEnable
= true;
643 case BLORP_HIZ_OP_HIZ_RESOLVE
:
644 wm
.HierarchicalDepthBufferResolveEnable
= true;
646 case BLORP_HIZ_OP_NONE
:
649 unreachable("not reached");
653 wm
.ThreadDispatchEnable
= true;
655 if (params
->src
.enabled
)
656 wm
.PixelShaderKillsPixel
= true;
658 if (params
->num_samples
> 1) {
659 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
660 wm
.MultisampleDispatchMode
=
661 (prog_data
&& prog_data
->persample_dispatch
) ?
662 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
664 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
665 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
669 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
670 ps
.MaximumNumberofThreads
=
671 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
678 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
679 prog_data
->base
.dispatch_grf_start_reg
;
680 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
681 prog_data
->dispatch_grf_start_reg_2
;
683 ps
.KernelStartPointer0
= params
->wm_prog_kernel
;
684 ps
.KernelStartPointer2
=
685 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
687 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
688 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
690 ps
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
692 /* Gen7 hardware gets angry if we don't enable at least one dispatch
693 * mode, so just enable 16-pixel dispatch if we don't have a program.
695 ps
._16PixelDispatchEnable
= true;
698 if (params
->src
.enabled
)
699 ps
.SamplerCount
= 1; /* Up to 4 samplers */
701 switch (params
->fast_clear_op
) {
702 case BLORP_FAST_CLEAR_OP_NONE
:
704 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
705 ps
.RenderTargetResolveEnable
= true;
707 case BLORP_FAST_CLEAR_OP_CLEAR
:
708 ps
.RenderTargetFastClearEnable
= true;
711 unreachable("Invalid fast clear op");
715 #else /* GEN_GEN <= 6 */
717 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
718 wm
.MaximumNumberofThreads
=
719 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
721 switch (params
->hiz_op
) {
722 case BLORP_HIZ_OP_DEPTH_CLEAR
:
723 wm
.DepthBufferClear
= true;
725 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
726 wm
.DepthBufferResolveEnable
= true;
728 case BLORP_HIZ_OP_HIZ_RESOLVE
:
729 wm
.HierarchicalDepthBufferResolveEnable
= true;
731 case BLORP_HIZ_OP_NONE
:
734 unreachable("not reached");
738 wm
.ThreadDispatchEnable
= true;
740 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
741 prog_data
->base
.dispatch_grf_start_reg
;
742 wm
.DispatchGRFStartRegisterForConstantSetupData2
=
743 prog_data
->dispatch_grf_start_reg_2
;
745 wm
.KernelStartPointer0
= params
->wm_prog_kernel
;
746 wm
.KernelStartPointer2
=
747 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
749 wm
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
750 wm
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
752 wm
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
755 if (params
->src
.enabled
) {
756 wm
.SamplerCount
= 1; /* Up to 4 samplers */
757 wm
.PixelShaderKillsPixel
= true; /* TODO: temporarily smash on */
760 if (params
->num_samples
> 1) {
761 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
762 wm
.MultisampleDispatchMode
=
763 (prog_data
&& prog_data
->persample_dispatch
) ?
764 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
766 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
767 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
774 static const uint32_t isl_to_gen_ds_surftype
[] = {
776 /* From the SKL PRM, "3DSTATE_DEPTH_STENCIL::SurfaceType":
778 * "If depth/stencil is enabled with 1D render target, depth/stencil
779 * surface type needs to be set to 2D surface type and height set to 1.
780 * Depth will use (legacy) TileY and stencil will use TileW. For this
781 * case only, the Surface Type of the depth buffer can be 2D while the
782 * Surface Type of the render target(s) are 1D, representing an
783 * exception to a programming note above.
785 [ISL_SURF_DIM_1D
] = SURFTYPE_2D
,
787 [ISL_SURF_DIM_1D
] = SURFTYPE_1D
,
789 [ISL_SURF_DIM_2D
] = SURFTYPE_2D
,
790 [ISL_SURF_DIM_3D
] = SURFTYPE_3D
,
794 blorp_emit_depth_stencil_config(struct blorp_batch
*batch
,
795 const struct blorp_params
*params
)
798 const uint32_t mocs
= 1; /* GEN7_MOCS_L3 */
800 const uint32_t mocs
= 0;
803 blorp_emit(batch
, GENX(3DSTATE_DEPTH_BUFFER
), db
) {
805 db
.DepthWriteEnable
= params
->depth
.enabled
;
806 db
.StencilWriteEnable
= params
->stencil
.enabled
;
810 db
.SeparateStencilBufferEnable
= true;
813 if (params
->depth
.enabled
) {
814 db
.SurfaceFormat
= params
->depth_format
;
815 db
.SurfaceType
= isl_to_gen_ds_surftype
[params
->depth
.surf
.dim
];
818 db
.TiledSurface
= true;
819 db
.TileWalk
= TILEWALK_YMAJOR
;
820 db
.MIPMapLayoutMode
= MIPLAYOUT_BELOW
;
823 db
.HierarchicalDepthBufferEnable
=
824 params
->depth
.aux_usage
== ISL_AUX_USAGE_HIZ
;
826 db
.Width
= params
->depth
.surf
.logical_level0_px
.width
- 1;
827 db
.Height
= params
->depth
.surf
.logical_level0_px
.height
- 1;
828 db
.RenderTargetViewExtent
= db
.Depth
=
829 params
->depth
.view
.array_len
- 1;
831 db
.LOD
= params
->depth
.view
.base_level
;
832 db
.MinimumArrayElement
= params
->depth
.view
.base_array_layer
;
834 db
.SurfacePitch
= params
->depth
.surf
.row_pitch
- 1;
837 isl_surf_get_array_pitch_el_rows(¶ms
->depth
.surf
) >> 2,
840 db
.SurfaceBaseAddress
= params
->depth
.addr
;
841 db
.DepthBufferMOCS
= mocs
;
842 } else if (params
->stencil
.enabled
) {
843 db
.SurfaceFormat
= D32_FLOAT
;
844 db
.SurfaceType
= isl_to_gen_ds_surftype
[params
->stencil
.surf
.dim
];
846 db
.Width
= params
->stencil
.surf
.logical_level0_px
.width
- 1;
847 db
.Height
= params
->stencil
.surf
.logical_level0_px
.height
- 1;
848 db
.RenderTargetViewExtent
= db
.Depth
=
849 params
->stencil
.view
.array_len
- 1;
851 db
.LOD
= params
->stencil
.view
.base_level
;
852 db
.MinimumArrayElement
= params
->stencil
.view
.base_array_layer
;
854 db
.SurfaceType
= SURFTYPE_NULL
;
855 db
.SurfaceFormat
= D32_FLOAT
;
859 blorp_emit(batch
, GENX(3DSTATE_HIER_DEPTH_BUFFER
), hiz
) {
860 if (params
->depth
.aux_usage
== ISL_AUX_USAGE_HIZ
) {
861 hiz
.SurfacePitch
= params
->depth
.aux_surf
.row_pitch
- 1;
862 hiz
.SurfaceBaseAddress
= params
->depth
.aux_addr
;
863 hiz
.HierarchicalDepthBufferMOCS
= mocs
;
866 isl_surf_get_array_pitch_sa_rows(¶ms
->depth
.aux_surf
) >> 2;
871 blorp_emit(batch
, GENX(3DSTATE_STENCIL_BUFFER
), sb
) {
872 if (params
->stencil
.enabled
) {
873 #if GEN_GEN >= 8 || GEN_IS_HASWELL
874 sb
.StencilBufferEnable
= true;
877 sb
.SurfacePitch
= params
->stencil
.surf
.row_pitch
- 1,
880 isl_surf_get_array_pitch_el_rows(¶ms
->stencil
.surf
) >> 2,
883 sb
.SurfaceBaseAddress
= params
->stencil
.addr
;
884 sb
.StencilBufferMOCS
= batch
->blorp
->mocs
.tex
;
888 /* 3DSTATE_CLEAR_PARAMS
890 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
891 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
892 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
894 blorp_emit(batch
, GENX(3DSTATE_CLEAR_PARAMS
), clear
) {
895 clear
.DepthClearValueValid
= true;
896 clear
.DepthClearValue
= params
->depth
.clear_color
.u32
[0];
901 blorp_emit_blend_state(struct blorp_batch
*batch
,
902 const struct blorp_params
*params
)
904 struct GENX(BLEND_STATE
) blend
;
905 memset(&blend
, 0, sizeof(blend
));
907 for (unsigned i
= 0; i
< params
->num_draw_buffers
; ++i
) {
908 blend
.Entry
[i
].PreBlendColorClampEnable
= true;
909 blend
.Entry
[i
].PostBlendColorClampEnable
= true;
910 blend
.Entry
[i
].ColorClampRange
= COLORCLAMP_RTFORMAT
;
912 blend
.Entry
[i
].WriteDisableRed
= params
->color_write_disable
[0];
913 blend
.Entry
[i
].WriteDisableGreen
= params
->color_write_disable
[1];
914 blend
.Entry
[i
].WriteDisableBlue
= params
->color_write_disable
[2];
915 blend
.Entry
[i
].WriteDisableAlpha
= params
->color_write_disable
[3];
919 void *state
= blorp_alloc_dynamic_state(batch
, AUB_TRACE_BLEND_STATE
,
920 GENX(BLEND_STATE_length
) * 4,
922 GENX(BLEND_STATE_pack
)(NULL
, state
, &blend
);
923 blorp_flush_range(batch
, state
, GENX(BLEND_STATE_length
) * 4);
926 blorp_emit(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), sp
) {
927 sp
.BlendStatePointer
= offset
;
929 sp
.BlendStatePointerValid
= true;
935 blorp_emit(batch
, GENX(3DSTATE_PS_BLEND
), ps_blend
) {
936 ps_blend
.HasWriteableRT
= true;
944 blorp_emit_color_calc_state(struct blorp_batch
*batch
,
945 const struct blorp_params
*params
)
947 struct GENX(COLOR_CALC_STATE
) cc
= { 0 };
950 cc
.StencilReferenceValue
= params
->stencil_ref
;
954 void *state
= blorp_alloc_dynamic_state(batch
, AUB_TRACE_CC_STATE
,
955 GENX(COLOR_CALC_STATE_length
) * 4,
957 GENX(COLOR_CALC_STATE_pack
)(NULL
, state
, &cc
);
958 blorp_flush_range(batch
, state
, GENX(COLOR_CALC_STATE_length
) * 4);
961 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), sp
) {
962 sp
.ColorCalcStatePointer
= offset
;
964 sp
.ColorCalcStatePointerValid
= true;
973 blorp_emit_depth_stencil_state(struct blorp_batch
*batch
,
974 const struct blorp_params
*params
)
977 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) ds
= {
978 GENX(3DSTATE_WM_DEPTH_STENCIL_header
),
981 struct GENX(DEPTH_STENCIL_STATE
) ds
= { 0 };
984 if (params
->depth
.enabled
) {
985 ds
.DepthBufferWriteEnable
= true;
987 switch (params
->hiz_op
) {
988 case BLORP_HIZ_OP_NONE
:
989 ds
.DepthTestEnable
= true;
990 ds
.DepthTestFunction
= COMPAREFUNCTION_ALWAYS
;
993 /* See the following sections of the Sandy Bridge PRM, Volume 2, Part1:
994 * - 7.5.3.1 Depth Buffer Clear
995 * - 7.5.3.2 Depth Buffer Resolve
996 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
998 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
999 ds
.DepthTestEnable
= true;
1000 ds
.DepthTestFunction
= COMPAREFUNCTION_NEVER
;
1003 case BLORP_HIZ_OP_DEPTH_CLEAR
:
1004 case BLORP_HIZ_OP_HIZ_RESOLVE
:
1005 ds
.DepthTestEnable
= false;
1010 if (params
->stencil
.enabled
) {
1011 ds
.StencilBufferWriteEnable
= true;
1012 ds
.StencilTestEnable
= true;
1013 ds
.DoubleSidedStencilEnable
= false;
1015 ds
.StencilTestFunction
= COMPAREFUNCTION_ALWAYS
;
1016 ds
.StencilPassDepthPassOp
= STENCILOP_REPLACE
;
1018 ds
.StencilWriteMask
= params
->stencil_mask
;
1020 ds
.StencilReferenceValue
= params
->stencil_ref
;
1025 uint32_t offset
= 0;
1026 uint32_t *dw
= blorp_emit_dwords(batch
,
1027 GENX(3DSTATE_WM_DEPTH_STENCIL_length
));
1031 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, dw
, &ds
);
1034 void *state
= blorp_alloc_dynamic_state(batch
, AUB_TRACE_DEPTH_STENCIL_STATE
,
1035 GENX(DEPTH_STENCIL_STATE_length
) * 4,
1037 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, state
, &ds
);
1038 blorp_flush_range(batch
, state
, GENX(DEPTH_STENCIL_STATE_length
) * 4);
1042 blorp_emit(batch
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), sp
) {
1043 sp
.PointertoDEPTH_STENCIL_STATE
= offset
;
1051 blorp_emit_surface_state(struct blorp_batch
*batch
,
1052 const struct brw_blorp_surface_info
*surface
,
1053 void *state
, uint32_t state_offset
,
1054 bool is_render_target
)
1056 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1057 struct isl_surf surf
= surface
->surf
;
1059 if (surf
.dim
== ISL_SURF_DIM_1D
&&
1060 surf
.dim_layout
== ISL_DIM_LAYOUT_GEN4_2D
) {
1061 assert(surf
.logical_level0_px
.height
== 1);
1062 surf
.dim
= ISL_SURF_DIM_2D
;
1065 /* Blorp doesn't support HiZ in any of the blit or slow-clear paths */
1066 enum isl_aux_usage aux_usage
= surface
->aux_usage
;
1067 if (aux_usage
== ISL_AUX_USAGE_HIZ
)
1068 aux_usage
= ISL_AUX_USAGE_NONE
;
1070 const uint32_t mocs
=
1071 is_render_target
? batch
->blorp
->mocs
.rb
: batch
->blorp
->mocs
.tex
;
1073 isl_surf_fill_state(batch
->blorp
->isl_dev
, state
,
1074 .surf
= &surf
, .view
= &surface
->view
,
1075 .aux_surf
= &surface
->aux_surf
, .aux_usage
= aux_usage
,
1076 .mocs
= mocs
, .clear_color
= surface
->clear_color
);
1078 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.addr_offset
,
1081 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
1082 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
1083 * used to store other information. This should be ok, however, because
1084 * surface buffer addresses are always 4K page alinged.
1086 assert((surface
->aux_addr
.offset
& 0xfff) == 0);
1087 uint32_t *aux_addr
= state
+ isl_dev
->ss
.aux_addr_offset
;
1088 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.aux_addr_offset
,
1089 surface
->aux_addr
, *aux_addr
);
1092 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1096 blorp_emit_null_surface_state(struct blorp_batch
*batch
,
1097 const struct brw_blorp_surface_info
*surface
,
1100 struct GENX(RENDER_SURFACE_STATE
) ss
= {
1101 .SurfaceType
= SURFTYPE_NULL
,
1102 .SurfaceFormat
= ISL_FORMAT_R8G8B8A8_UNORM
,
1103 .Width
= surface
->surf
.logical_level0_px
.width
- 1,
1104 .Height
= surface
->surf
.logical_level0_px
.height
- 1,
1105 .MIPCountLOD
= surface
->view
.base_level
,
1106 .MinimumArrayElement
= surface
->view
.base_array_layer
,
1107 .Depth
= surface
->view
.array_len
- 1,
1108 .RenderTargetViewExtent
= surface
->view
.array_len
- 1,
1109 .NumberofMultisamples
= ffs(surface
->surf
.samples
) - 1,
1112 .SurfaceArray
= surface
->surf
.dim
!= ISL_SURF_DIM_3D
,
1118 .TiledSurface
= true,
1122 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &ss
);
1124 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1128 blorp_emit_surface_states(struct blorp_batch
*batch
,
1129 const struct blorp_params
*params
)
1131 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1132 uint32_t bind_offset
, surface_offsets
[2];
1133 void *surface_maps
[2];
1135 if (params
->use_pre_baked_binding_table
) {
1136 bind_offset
= params
->pre_baked_binding_table_offset
;
1138 unsigned num_surfaces
= 1 + params
->src
.enabled
;
1139 blorp_alloc_binding_table(batch
, num_surfaces
,
1140 isl_dev
->ss
.size
, isl_dev
->ss
.align
,
1141 &bind_offset
, surface_offsets
, surface_maps
);
1143 if (params
->dst
.enabled
) {
1144 blorp_emit_surface_state(batch
, ¶ms
->dst
,
1145 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
],
1146 surface_offsets
[BLORP_RENDERBUFFER_BT_INDEX
],
1149 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1150 const struct brw_blorp_surface_info
*surface
=
1151 params
->depth
.enabled
? ¶ms
->depth
: ¶ms
->stencil
;
1152 blorp_emit_null_surface_state(batch
, surface
,
1153 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
]);
1156 if (params
->src
.enabled
) {
1157 blorp_emit_surface_state(batch
, ¶ms
->src
,
1158 surface_maps
[BLORP_TEXTURE_BT_INDEX
],
1159 surface_offsets
[BLORP_TEXTURE_BT_INDEX
], false);
1164 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), bt
);
1165 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_HS
), bt
);
1166 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_DS
), bt
);
1167 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_GS
), bt
);
1169 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS
), bt
) {
1170 bt
.PointertoPSBindingTable
= bind_offset
;
1173 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS
), bt
) {
1174 bt
.PSBindingTableChange
= true;
1175 bt
.PointertoPSBindingTable
= bind_offset
;
1181 blorp_emit_sampler_state(struct blorp_batch
*batch
,
1182 const struct blorp_params
*params
)
1184 struct GENX(SAMPLER_STATE
) sampler
= {
1185 .MipModeFilter
= MIPFILTER_NONE
,
1186 .MagModeFilter
= MAPFILTER_LINEAR
,
1187 .MinModeFilter
= MAPFILTER_LINEAR
,
1190 .TCXAddressControlMode
= TCM_CLAMP
,
1191 .TCYAddressControlMode
= TCM_CLAMP
,
1192 .TCZAddressControlMode
= TCM_CLAMP
,
1193 .MaximumAnisotropy
= RATIO21
,
1194 .RAddressMinFilterRoundingEnable
= true,
1195 .RAddressMagFilterRoundingEnable
= true,
1196 .VAddressMinFilterRoundingEnable
= true,
1197 .VAddressMagFilterRoundingEnable
= true,
1198 .UAddressMinFilterRoundingEnable
= true,
1199 .UAddressMagFilterRoundingEnable
= true,
1200 .NonnormalizedCoordinateEnable
= true,
1204 void *state
= blorp_alloc_dynamic_state(batch
, AUB_TRACE_SAMPLER_STATE
,
1205 GENX(SAMPLER_STATE_length
) * 4,
1207 GENX(SAMPLER_STATE_pack
)(NULL
, state
, &sampler
);
1208 blorp_flush_range(batch
, state
, GENX(SAMPLER_STATE_length
) * 4);
1211 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS
), ssp
) {
1212 ssp
.PointertoPSSamplerState
= offset
;
1215 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS
), ssp
) {
1216 ssp
.VSSamplerStateChange
= true;
1217 ssp
.GSSamplerStateChange
= true;
1218 ssp
.PSSamplerStateChange
= true;
1219 ssp
.PointertoPSSamplerState
= offset
;
1225 blorp_emit_3dstate_multisample(struct blorp_batch
*batch
,
1226 const struct blorp_params
*params
)
1228 blorp_emit(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
1229 ms
.NumberofMultisamples
= __builtin_ffs(params
->num_samples
) - 1;
1232 /* The PRM says that this bit is valid only for DX9:
1234 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
1235 * should not have any effect by setting or not setting this bit.
1237 ms
.PixelPositionOffsetEnable
= false;
1238 ms
.PixelLocation
= CENTER
;
1240 ms
.PixelLocation
= PIXLOC_CENTER
;
1242 switch (params
->num_samples
) {
1244 GEN_SAMPLE_POS_1X(ms
.Sample
);
1247 GEN_SAMPLE_POS_2X(ms
.Sample
);
1250 GEN_SAMPLE_POS_4X(ms
.Sample
);
1253 GEN_SAMPLE_POS_8X(ms
.Sample
);
1259 ms
.PixelLocation
= PIXLOC_CENTER
;
1260 GEN_SAMPLE_POS_4X(ms
.Sample
);
1266 /* Emits the Optimized HiZ sequence specified in the BDW+ PRMs. The
1267 * depth/stencil buffer extents are ignored to handle APIs which perform
1268 * clearing operations without such information.
1271 blorp_emit_gen8_hiz_op(struct blorp_batch
*batch
,
1272 const struct blorp_params
*params
)
1274 /* We should be performing an operation on a depth or stencil buffer.
1276 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1278 /* The stencil buffer should only be enabled if a fast clear operation is
1281 if (params
->stencil
.enabled
)
1282 assert(params
->hiz_op
== BLORP_HIZ_OP_DEPTH_CLEAR
);
1284 /* If we can't alter the depth stencil config and multiple layers are
1285 * involved, the HiZ op will fail. This is because the op requires that a
1286 * new config is emitted for each additional layer.
1288 if (batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
) {
1289 assert(params
->num_layers
<= 1);
1291 blorp_emit_depth_stencil_config(batch
, params
);
1294 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
) {
1295 switch (params
->hiz_op
) {
1296 case BLORP_HIZ_OP_DEPTH_CLEAR
:
1297 hzp
.StencilBufferClearEnable
= params
->stencil
.enabled
;
1298 hzp
.DepthBufferClearEnable
= params
->depth
.enabled
;
1299 hzp
.StencilClearValue
= params
->stencil_ref
;
1301 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
1302 hzp
.DepthBufferResolveEnable
= true;
1304 case BLORP_HIZ_OP_HIZ_RESOLVE
:
1305 hzp
.HierarchicalDepthBufferResolveEnable
= true;
1307 case BLORP_HIZ_OP_NONE
:
1308 unreachable("Invalid HIZ op");
1311 hzp
.NumberofMultisamples
= ffs(params
->num_samples
) - 1;
1312 hzp
.SampleMask
= 0xFFFF;
1314 /* Due to a hardware issue, this bit MBZ */
1315 assert(hzp
.ScissorRectangleEnable
== false);
1317 /* Contrary to the HW docs both fields are inclusive */
1318 hzp
.ClearRectangleXMin
= params
->x0
;
1319 hzp
.ClearRectangleYMin
= params
->y0
;
1321 /* Contrary to the HW docs both fields are exclusive */
1322 hzp
.ClearRectangleXMax
= params
->x1
;
1323 hzp
.ClearRectangleYMax
= params
->y1
;
1326 /* PIPE_CONTROL w/ all bits clear except for “Post-Sync Operation” must set
1327 * to “Write Immediate Data” enabled.
1329 blorp_emit(batch
, GENX(PIPE_CONTROL
), pc
) {
1330 pc
.PostSyncOperation
= WriteImmediateData
;
1333 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
);
1335 /* Perform depth clear specific flushing */
1336 if (params
->hiz_op
== BLORP_HIZ_OP_DEPTH_CLEAR
&& params
->depth
.enabled
) {
1337 blorp_emit(batch
, GENX(PIPE_CONTROL
), pc
) {
1338 pc
.DepthStallEnable
= true;
1339 pc
.DepthCacheFlushEnable
= true;
1345 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
1347 blorp_emit_viewport_state(struct blorp_batch
*batch
,
1348 const struct blorp_params
*params
)
1350 uint32_t cc_vp_offset
;
1352 void *state
= blorp_alloc_dynamic_state(batch
, AUB_TRACE_CC_VP_STATE
,
1353 GENX(CC_VIEWPORT_length
) * 4, 32,
1356 GENX(CC_VIEWPORT_pack
)(batch
, state
,
1357 &(struct GENX(CC_VIEWPORT
)) {
1358 .MinimumDepth
= 0.0,
1359 .MaximumDepth
= 1.0,
1361 blorp_flush_range(batch
, state
, GENX(CC_VIEWPORT_length
) * 4);
1364 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), vsp
) {
1365 vsp
.CCViewportPointer
= cc_vp_offset
;
1368 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vsp
) {
1369 vsp
.CCViewportStateChange
= true;
1370 vsp
.PointertoCC_VIEWPORT
= cc_vp_offset
;
1377 * \brief Execute a blit or render pass operation.
1379 * To execute the operation, this function manually constructs and emits a
1380 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1381 * constructing and after emitting the batch.
1383 * This function alters no GL state.
1386 blorp_exec(struct blorp_batch
*batch
, const struct blorp_params
*params
)
1388 uint32_t blend_state_offset
= 0;
1389 uint32_t color_calc_state_offset
= 0;
1390 uint32_t depth_stencil_state_offset
;
1393 if (params
->hiz_op
!= BLORP_HIZ_OP_NONE
) {
1394 blorp_emit_gen8_hiz_op(batch
, params
);
1399 blorp_emit_vertex_buffers(batch
, params
);
1400 blorp_emit_vertex_elements(batch
, params
);
1402 emit_urb_config(batch
, params
);
1404 if (params
->wm_prog_data
) {
1405 blend_state_offset
= blorp_emit_blend_state(batch
, params
);
1407 color_calc_state_offset
= blorp_emit_color_calc_state(batch
, params
);
1408 depth_stencil_state_offset
= blorp_emit_depth_stencil_state(batch
, params
);
1411 /* 3DSTATE_CC_STATE_POINTERS
1413 * The pointer offsets are relative to
1414 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
1416 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
1418 * The dynamic state emit helpers emit their own STATE_POINTERS packets on
1419 * gen7+. However, on gen6 and earlier, they're all lumpped together in
1420 * one CC_STATE_POINTERS packet so we have to emit that here.
1422 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), cc
) {
1423 cc
.BLEND_STATEChange
= true;
1424 cc
.COLOR_CALC_STATEChange
= true;
1425 cc
.DEPTH_STENCIL_STATEChange
= true;
1426 cc
.PointertoBLEND_STATE
= blend_state_offset
;
1427 cc
.PointertoCOLOR_CALC_STATE
= color_calc_state_offset
;
1428 cc
.PointertoDEPTH_STENCIL_STATE
= depth_stencil_state_offset
;
1431 (void)blend_state_offset
;
1432 (void)color_calc_state_offset
;
1433 (void)depth_stencil_state_offset
;
1436 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_VS
), vs
);
1438 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_HS
), hs
);
1439 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_DS
), DS
);
1441 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_GS
), gs
);
1442 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_PS
), ps
);
1444 blorp_emit_surface_states(batch
, params
);
1446 if (params
->src
.enabled
)
1447 blorp_emit_sampler_state(batch
, params
);
1449 blorp_emit_3dstate_multisample(batch
, params
);
1451 blorp_emit(batch
, GENX(3DSTATE_SAMPLE_MASK
), mask
) {
1452 mask
.SampleMask
= (1 << params
->num_samples
) - 1;
1455 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1456 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1458 * [DevSNB] A pipeline flush must be programmed prior to a
1459 * 3DSTATE_VS command that causes the VS Function Enable to
1460 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
1461 * command with CS stall bit set and a post sync operation.
1463 * We've already done one at the start of the BLORP operation.
1465 blorp_emit_vs_config(batch
, params
);
1467 blorp_emit(batch
, GENX(3DSTATE_HS
), hs
);
1468 blorp_emit(batch
, GENX(3DSTATE_TE
), te
);
1469 blorp_emit(batch
, GENX(3DSTATE_DS
), DS
);
1470 blorp_emit(batch
, GENX(3DSTATE_STREAMOUT
), so
);
1472 blorp_emit(batch
, GENX(3DSTATE_GS
), gs
);
1474 blorp_emit(batch
, GENX(3DSTATE_CLIP
), clip
) {
1475 clip
.PerspectiveDivideDisable
= true;
1478 blorp_emit_sf_config(batch
, params
);
1479 blorp_emit_ps_config(batch
, params
);
1481 blorp_emit_viewport_state(batch
, params
);
1483 if (!(batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
))
1484 blorp_emit_depth_stencil_config(batch
, params
);
1486 blorp_emit(batch
, GENX(3DPRIMITIVE
), prim
) {
1487 prim
.VertexAccessType
= SEQUENTIAL
;
1488 prim
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
1489 prim
.VertexCountPerInstance
= 3;
1490 prim
.InstanceCount
= params
->num_layers
;
1494 #endif /* BLORP_GENX_EXEC_H */