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"
32 * This file provides the blorp pipeline setup and execution functionality.
33 * It defines the following function:
36 * blorp_exec(struct blorp_context *blorp, void *batch_data,
37 * const struct blorp_params *params);
39 * It is the job of whoever includes this header to wrap this in something
40 * to get an externally visible symbol.
42 * In order for the blorp_exec function to work, the driver must provide
43 * implementations of the following static helper functions.
47 blorp_emit_dwords(struct blorp_batch
*batch
, unsigned n
);
50 blorp_emit_reloc(struct blorp_batch
*batch
,
51 void *location
, struct blorp_address address
, uint32_t delta
);
54 blorp_alloc_dynamic_state(struct blorp_batch
*batch
,
59 blorp_alloc_vertex_buffer(struct blorp_batch
*batch
, uint32_t size
,
60 struct blorp_address
*addr
);
63 blorp_alloc_binding_table(struct blorp_batch
*batch
, unsigned num_entries
,
64 unsigned state_size
, unsigned state_alignment
,
65 uint32_t *bt_offset
, uint32_t *surface_offsets
,
69 blorp_flush_range(struct blorp_batch
*batch
, void *start
, size_t size
);
72 blorp_surface_reloc(struct blorp_batch
*batch
, uint32_t ss_offset
,
73 struct blorp_address address
, uint32_t delta
);
76 blorp_emit_urb_config(struct blorp_batch
*batch
, unsigned vs_entry_size
);
78 /***** BEGIN blorp_exec implementation ******/
80 #include "genxml/gen_macros.h"
83 _blorp_combine_address(struct blorp_batch
*batch
, void *location
,
84 struct blorp_address address
, uint32_t delta
)
86 if (address
.buffer
== NULL
) {
87 return address
.offset
+ delta
;
89 return blorp_emit_reloc(batch
, location
, address
, delta
);
93 #define __gen_address_type struct blorp_address
94 #define __gen_user_data struct blorp_batch
95 #define __gen_combine_address _blorp_combine_address
97 #include "genxml/genX_pack.h"
99 #define _blorp_cmd_length(cmd) cmd ## _length
100 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
101 #define _blorp_cmd_header(cmd) cmd ## _header
102 #define _blorp_cmd_pack(cmd) cmd ## _pack
104 #define blorp_emit(batch, cmd, name) \
105 for (struct cmd name = { _blorp_cmd_header(cmd) }, \
106 *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
107 __builtin_expect(_dst != NULL, 1); \
108 _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name), \
111 #define blorp_emitn(batch, cmd, n) ({ \
112 uint32_t *_dw = blorp_emit_dwords(batch, n); \
114 struct cmd template = { \
115 _blorp_cmd_header(cmd), \
116 .DWordLength = n - _blorp_cmd_length_bias(cmd), \
118 _blorp_cmd_pack(cmd)(batch, _dw, &template); \
120 _dw ? _dw + 1 : NULL; /* Array starts at dw[1] */ \
129 * Assign the entire URB to the VS. Even though the VS disabled, URB space
130 * is still needed because the clipper loads the VUE's from the URB. From
131 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
132 * Dword 1.15:0 "VS Number of URB Entries":
133 * This field is always used (even if VS Function Enable is DISABLED).
135 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
136 * safely ignore it because this batch contains only one draw call.
137 * Because of URB corruption caused by allocating a previous GS unit
138 * URB entry to the VS unit, software is required to send a “GS NULL
139 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
140 * plus a dummy DRAW call before any case where VS will be taking over
143 * If the 3DSTATE_URB_VS is emitted, than the others must be also.
144 * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
146 * 3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
147 * programmed in order for the programming of this state to be
151 emit_urb_config(struct blorp_batch
*batch
,
152 const struct blorp_params
*params
)
154 /* Once vertex fetcher has written full VUE entries with complete
155 * header the space requirement is as follows per vertex (in bytes):
157 * Header Position Program constants
158 * +--------+------------+-------------------+
159 * | 16 | 16 | n x 16 |
160 * +--------+------------+-------------------+
162 * where 'n' stands for number of varying inputs expressed as vec4s.
164 const unsigned num_varyings
=
165 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
166 const unsigned total_needed
= 16 + 16 + num_varyings
* 16;
168 /* The URB size is expressed in units of 64 bytes (512 bits) */
169 const unsigned vs_entry_size
= DIV_ROUND_UP(total_needed
, 64);
171 blorp_emit_urb_config(batch
, vs_entry_size
);
175 blorp_emit_vertex_data(struct blorp_batch
*batch
,
176 const struct blorp_params
*params
,
177 struct blorp_address
*addr
,
180 const float vertices
[] = {
181 /* v0 */ (float)params
->x1
, (float)params
->y1
, params
->z
,
182 /* v1 */ (float)params
->x0
, (float)params
->y1
, params
->z
,
183 /* v2 */ (float)params
->x0
, (float)params
->y0
, params
->z
,
186 void *data
= blorp_alloc_vertex_buffer(batch
, sizeof(vertices
), addr
);
187 memcpy(data
, vertices
, sizeof(vertices
));
188 *size
= sizeof(vertices
);
189 blorp_flush_range(batch
, data
, *size
);
193 blorp_emit_input_varying_data(struct blorp_batch
*batch
,
194 const struct blorp_params
*params
,
195 struct blorp_address
*addr
,
198 const unsigned vec4_size_in_bytes
= 4 * sizeof(float);
199 const unsigned max_num_varyings
=
200 DIV_ROUND_UP(sizeof(params
->wm_inputs
), vec4_size_in_bytes
);
201 const unsigned num_varyings
=
202 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
204 *size
= 16 + num_varyings
* vec4_size_in_bytes
;
206 const uint32_t *const inputs_src
= (const uint32_t *)¶ms
->wm_inputs
;
207 void *data
= blorp_alloc_vertex_buffer(batch
, *size
, addr
);
208 uint32_t *inputs
= data
;
210 /* Copy in the VS inputs */
211 assert(sizeof(params
->vs_inputs
) == 16);
212 memcpy(inputs
, ¶ms
->vs_inputs
, sizeof(params
->vs_inputs
));
215 if (params
->wm_prog_data
) {
216 /* Walk over the attribute slots, determine if the attribute is used by
217 * the program and when necessary copy the values from the input storage
218 * to the vertex data buffer.
220 for (unsigned i
= 0; i
< max_num_varyings
; i
++) {
221 const gl_varying_slot attr
= VARYING_SLOT_VAR0
+ i
;
223 const int input_index
= params
->wm_prog_data
->urb_setup
[attr
];
227 memcpy(inputs
, inputs_src
+ i
* 4, vec4_size_in_bytes
);
233 blorp_flush_range(batch
, data
, *size
);
237 blorp_emit_vertex_buffers(struct blorp_batch
*batch
,
238 const struct blorp_params
*params
)
240 struct GENX(VERTEX_BUFFER_STATE
) vb
[2];
241 memset(vb
, 0, sizeof(vb
));
244 blorp_emit_vertex_data(batch
, params
, &vb
[0].BufferStartingAddress
, &size
);
245 vb
[0].VertexBufferIndex
= 0;
246 vb
[0].BufferPitch
= 3 * sizeof(float);
247 vb
[0].VertexBufferMOCS
= batch
->blorp
->mocs
.vb
;
249 vb
[0].AddressModifyEnable
= true;
252 vb
[0].BufferSize
= size
;
254 vb
[0].BufferAccessType
= VERTEXDATA
;
255 vb
[0].EndAddress
= vb
[0].BufferStartingAddress
;
256 vb
[0].EndAddress
.offset
+= size
- 1;
259 blorp_emit_input_varying_data(batch
, params
,
260 &vb
[1].BufferStartingAddress
, &size
);
261 vb
[1].VertexBufferIndex
= 1;
262 vb
[1].BufferPitch
= 0;
263 vb
[1].VertexBufferMOCS
= batch
->blorp
->mocs
.vb
;
265 vb
[1].AddressModifyEnable
= true;
268 vb
[1].BufferSize
= size
;
270 vb
[1].BufferAccessType
= INSTANCEDATA
;
271 vb
[1].EndAddress
= vb
[1].BufferStartingAddress
;
272 vb
[1].EndAddress
.offset
+= size
- 1;
275 const unsigned num_dwords
= 1 + GENX(VERTEX_BUFFER_STATE_length
) * 2;
276 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), num_dwords
);
280 for (unsigned i
= 0; i
< 2; i
++) {
281 GENX(VERTEX_BUFFER_STATE_pack
)(batch
, dw
, &vb
[i
]);
282 dw
+= GENX(VERTEX_BUFFER_STATE_length
);
287 blorp_emit_vertex_elements(struct blorp_batch
*batch
,
288 const struct blorp_params
*params
)
290 const unsigned num_varyings
=
291 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
292 const unsigned num_elements
= 2 + num_varyings
;
294 struct GENX(VERTEX_ELEMENT_STATE
) ve
[num_elements
];
295 memset(ve
, 0, num_elements
* sizeof(*ve
));
297 /* Setup VBO for the rectangle primitive..
299 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
300 * vertices. The vertices reside in screen space with DirectX
301 * coordinates (that is, (0, 0) is the upper left corner).
308 * Since the VS is disabled, the clipper loads each VUE directly from
309 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
310 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
311 * dw0: Reserved, MBZ.
312 * dw1: Render Target Array Index. Below vertex fetcher gets programmed
313 * to assign this with primitive instance identifier which will be
314 * used for layered clears. All other renders have only one instance
315 * and therefore the value will be effectively zero.
316 * dw2: Viewport Index. The HiZ op disables viewport mapping and
317 * scissoring, so set the dword to 0.
318 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
319 * so set the dword to 0.
320 * dw4: Vertex Position X.
321 * dw5: Vertex Position Y.
322 * dw6: Vertex Position Z.
323 * dw7: Vertex Position W.
325 * dw8: Flat vertex input 0
326 * dw9: Flat vertex input 1
328 * dwn: Flat vertex input n - 8
330 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
331 * "Vertex URB Entry (VUE) Formats".
333 * Only vertex position X and Y are going to be variable, Z is fixed to
334 * zero and W to one. Header words dw0,2,3 are zero. There is no need to
335 * include the fixed values in the vertex buffer. Vertex fetcher can be
336 * instructed to fill vertex elements with constant values of one and zero
337 * instead of reading them from the buffer.
338 * Flat inputs are program constants that are not interpolated. Moreover
339 * their values will be the same between vertices.
341 * See the vertex element setup below.
343 ve
[0].VertexBufferIndex
= 1;
345 ve
[0].SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
346 ve
[0].SourceElementOffset
= 0;
347 ve
[0].Component0Control
= VFCOMP_STORE_SRC
;
349 /* From Gen8 onwards hardware is no more instructed to overwrite components
350 * using an element specifier. Instead one has separate 3DSTATE_VF_SGVS
351 * (System Generated Value Setup) state packet for it.
354 ve
[0].Component1Control
= VFCOMP_STORE_0
;
356 ve
[0].Component1Control
= VFCOMP_STORE_IID
;
358 ve
[0].Component2Control
= VFCOMP_STORE_SRC
;
359 ve
[0].Component3Control
= VFCOMP_STORE_SRC
;
361 ve
[1].VertexBufferIndex
= 0;
363 ve
[1].SourceElementFormat
= ISL_FORMAT_R32G32B32_FLOAT
;
364 ve
[1].SourceElementOffset
= 0;
365 ve
[1].Component0Control
= VFCOMP_STORE_SRC
;
366 ve
[1].Component1Control
= VFCOMP_STORE_SRC
;
367 ve
[1].Component2Control
= VFCOMP_STORE_SRC
;
368 ve
[1].Component3Control
= VFCOMP_STORE_1_FP
;
370 for (unsigned i
= 0; i
< num_varyings
; ++i
) {
371 ve
[i
+ 2].VertexBufferIndex
= 1;
372 ve
[i
+ 2].Valid
= true;
373 ve
[i
+ 2].SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
374 ve
[i
+ 2].SourceElementOffset
= 16 + i
* 4 * sizeof(float);
375 ve
[i
+ 2].Component0Control
= VFCOMP_STORE_SRC
;
376 ve
[i
+ 2].Component1Control
= VFCOMP_STORE_SRC
;
377 ve
[i
+ 2].Component2Control
= VFCOMP_STORE_SRC
;
378 ve
[i
+ 2].Component3Control
= VFCOMP_STORE_SRC
;
381 const unsigned num_dwords
=
382 1 + GENX(VERTEX_ELEMENT_STATE_length
) * num_elements
;
383 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_ELEMENTS
), num_dwords
);
387 for (unsigned i
= 0; i
< num_elements
; i
++) {
388 GENX(VERTEX_ELEMENT_STATE_pack
)(batch
, dw
, &ve
[i
]);
389 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
393 /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
394 * primitive instance identifier. This is used for layered clears.
396 blorp_emit(batch
, GENX(3DSTATE_VF_SGVS
), sgvs
) {
397 sgvs
.InstanceIDEnable
= true;
398 sgvs
.InstanceIDComponentNumber
= COMP_1
;
399 sgvs
.InstanceIDElementOffset
= 0;
402 for (unsigned i
= 0; i
< num_elements
; i
++) {
403 blorp_emit(batch
, GENX(3DSTATE_VF_INSTANCING
), vf
) {
404 vf
.VertexElementIndex
= i
;
405 vf
.InstancingEnable
= false;
409 blorp_emit(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
410 topo
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
416 blorp_emit_vs_config(struct blorp_batch
*batch
,
417 const struct blorp_params
*params
)
419 struct brw_vs_prog_data
*vs_prog_data
= params
->vs_prog_data
;
421 blorp_emit(batch
, GENX(3DSTATE_VS
), vs
) {
423 vs
.FunctionEnable
= true;
425 vs
.KernelStartPointer
= params
->vs_prog_kernel
;
427 vs
.DispatchGRFStartRegisterForURBData
=
428 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
429 vs
.VertexURBEntryReadLength
=
430 vs_prog_data
->base
.urb_read_length
;
431 vs
.VertexURBEntryReadOffset
= 0;
433 vs
.MaximumNumberofThreads
=
434 batch
->blorp
->isl_dev
->info
->max_vs_threads
- 1;
437 vs
.SIMD8DispatchEnable
=
438 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
445 blorp_emit_sf_config(struct blorp_batch
*batch
,
446 const struct blorp_params
*params
)
448 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
452 * Disable ViewportTransformEnable (dw2.1)
454 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
455 * Primitives Overview":
456 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
457 * use of screen- space coordinates).
459 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
460 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
462 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
463 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
464 * SOLID: Any triangle or rectangle object found to be front-facing
465 * is rendered as a solid object. This setting is required when
466 * (rendering rectangle (RECTLIST) objects.
471 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
);
473 blorp_emit(batch
, GENX(3DSTATE_RASTER
), raster
) {
474 raster
.CullMode
= CULLMODE_NONE
;
477 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
478 sbe
.VertexURBEntryReadOffset
= 1;
480 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
481 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
482 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
484 sbe
.NumberofSFOutputAttributes
= 0;
485 sbe
.VertexURBEntryReadLength
= 1;
487 sbe
.ForceVertexURBEntryReadLength
= true;
488 sbe
.ForceVertexURBEntryReadOffset
= true;
491 for (unsigned i
= 0; i
< 32; i
++)
492 sbe
.AttributeActiveComponentFormat
[i
] = ACF_XYZW
;
498 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
499 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
500 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
502 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
503 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
506 sf
.DepthBufferSurfaceFormat
= params
->depth_format
;
510 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
511 sbe
.VertexURBEntryReadOffset
= 1;
513 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
514 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
515 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
517 sbe
.NumberofSFOutputAttributes
= 0;
518 sbe
.VertexURBEntryReadLength
= 1;
522 #else /* GEN_GEN <= 6 */
524 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
525 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
526 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
528 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
529 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
531 sf
.VertexURBEntryReadOffset
= 1;
533 sf
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
534 sf
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
535 sf
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
537 sf
.NumberofSFOutputAttributes
= 0;
538 sf
.VertexURBEntryReadLength
= 1;
546 blorp_emit_ps_config(struct blorp_batch
*batch
,
547 const struct blorp_params
*params
)
549 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
551 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
552 * nonzero to prevent the GPU from hanging. While the documentation doesn't
553 * mention this explicitly, it notes that the valid range for the field is
554 * [1,39] = [2,40] threads, which excludes zero.
556 * To be safe (and to minimize extraneous code) we go ahead and fully
557 * configure the WM state whether or not there is a WM program.
562 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
);
564 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
565 if (params
->src
.enabled
) {
566 ps
.SamplerCount
= 1; /* Up to 4 samplers */
567 ps
.BindingTableEntryCount
= 2;
569 ps
.BindingTableEntryCount
= 1;
573 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
574 prog_data
->base
.dispatch_grf_start_reg
;
575 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
576 prog_data
->dispatch_grf_start_reg_2
;
578 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
579 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
581 ps
.KernelStartPointer0
= params
->wm_prog_kernel
;
582 ps
.KernelStartPointer2
=
583 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
586 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64;
587 * it implicitly scales for different GT levels (which have some # of
590 * In Gen8 the format is U8-2 whereas in Gen9 it is U8-1.
593 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
595 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
597 switch (params
->fast_clear_op
) {
598 case BLORP_FAST_CLEAR_OP_NONE
:
601 case BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL
:
602 ps
.RenderTargetResolveType
= RESOLVE_PARTIAL
;
604 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
605 ps
.RenderTargetResolveType
= RESOLVE_FULL
;
608 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
609 ps
.RenderTargetResolveEnable
= true;
612 case BLORP_FAST_CLEAR_OP_CLEAR
:
613 ps
.RenderTargetFastClearEnable
= true;
616 unreachable("Invalid fast clear op");
620 blorp_emit(batch
, GENX(3DSTATE_PS_EXTRA
), psx
) {
622 psx
.PixelShaderValid
= true;
623 psx
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
624 psx
.PixelShaderIsPerSample
= prog_data
->persample_dispatch
;
627 if (params
->src
.enabled
)
628 psx
.PixelShaderKillsPixel
= true;
633 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
634 switch (params
->hiz_op
) {
635 case BLORP_HIZ_OP_DEPTH_CLEAR
:
636 wm
.DepthBufferClear
= true;
638 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
639 wm
.DepthBufferResolveEnable
= true;
641 case BLORP_HIZ_OP_HIZ_RESOLVE
:
642 wm
.HierarchicalDepthBufferResolveEnable
= true;
644 case BLORP_HIZ_OP_NONE
:
647 unreachable("not reached");
651 wm
.ThreadDispatchEnable
= true;
653 if (params
->src
.enabled
)
654 wm
.PixelShaderKillsPixel
= true;
656 if (params
->num_samples
> 1) {
657 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
658 wm
.MultisampleDispatchMode
=
659 (prog_data
&& prog_data
->persample_dispatch
) ?
660 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
662 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
663 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
667 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
668 ps
.MaximumNumberofThreads
=
669 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
676 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
677 prog_data
->base
.dispatch_grf_start_reg
;
678 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
679 prog_data
->dispatch_grf_start_reg_2
;
681 ps
.KernelStartPointer0
= params
->wm_prog_kernel
;
682 ps
.KernelStartPointer2
=
683 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
685 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
686 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
688 ps
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
690 /* Gen7 hardware gets angry if we don't enable at least one dispatch
691 * mode, so just enable 16-pixel dispatch if we don't have a program.
693 ps
._16PixelDispatchEnable
= true;
696 if (params
->src
.enabled
)
697 ps
.SamplerCount
= 1; /* Up to 4 samplers */
699 switch (params
->fast_clear_op
) {
700 case BLORP_FAST_CLEAR_OP_NONE
:
702 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL
:
703 ps
.RenderTargetResolveEnable
= true;
705 case BLORP_FAST_CLEAR_OP_CLEAR
:
706 ps
.RenderTargetFastClearEnable
= true;
709 unreachable("Invalid fast clear op");
713 #else /* GEN_GEN <= 6 */
715 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
716 wm
.MaximumNumberofThreads
=
717 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
719 switch (params
->hiz_op
) {
720 case BLORP_HIZ_OP_DEPTH_CLEAR
:
721 wm
.DepthBufferClear
= true;
723 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
724 wm
.DepthBufferResolveEnable
= true;
726 case BLORP_HIZ_OP_HIZ_RESOLVE
:
727 wm
.HierarchicalDepthBufferResolveEnable
= true;
729 case BLORP_HIZ_OP_NONE
:
732 unreachable("not reached");
736 wm
.ThreadDispatchEnable
= true;
738 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
739 prog_data
->base
.dispatch_grf_start_reg
;
740 wm
.DispatchGRFStartRegisterForConstantSetupData2
=
741 prog_data
->dispatch_grf_start_reg_2
;
743 wm
.KernelStartPointer0
= params
->wm_prog_kernel
;
744 wm
.KernelStartPointer2
=
745 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
747 wm
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
748 wm
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
750 wm
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
753 if (params
->src
.enabled
) {
754 wm
.SamplerCount
= 1; /* Up to 4 samplers */
755 wm
.PixelShaderKillsPixel
= true; /* TODO: temporarily smash on */
758 if (params
->num_samples
> 1) {
759 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
760 wm
.MultisampleDispatchMode
=
761 (prog_data
&& prog_data
->persample_dispatch
) ?
762 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
764 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
765 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
772 static const uint32_t isl_to_gen_ds_surftype
[] = {
774 /* From the SKL PRM, "3DSTATE_DEPTH_STENCIL::SurfaceType":
776 * "If depth/stencil is enabled with 1D render target, depth/stencil
777 * surface type needs to be set to 2D surface type and height set to 1.
778 * Depth will use (legacy) TileY and stencil will use TileW. For this
779 * case only, the Surface Type of the depth buffer can be 2D while the
780 * Surface Type of the render target(s) are 1D, representing an
781 * exception to a programming note above.
783 [ISL_SURF_DIM_1D
] = SURFTYPE_2D
,
785 [ISL_SURF_DIM_1D
] = SURFTYPE_1D
,
787 [ISL_SURF_DIM_2D
] = SURFTYPE_2D
,
788 [ISL_SURF_DIM_3D
] = SURFTYPE_3D
,
792 blorp_emit_depth_stencil_config(struct blorp_batch
*batch
,
793 const struct blorp_params
*params
)
796 const uint32_t mocs
= 1; /* GEN7_MOCS_L3 */
798 const uint32_t mocs
= 0;
801 blorp_emit(batch
, GENX(3DSTATE_DEPTH_BUFFER
), db
) {
803 db
.DepthWriteEnable
= params
->depth
.enabled
;
804 db
.StencilWriteEnable
= params
->stencil
.enabled
;
808 db
.SeparateStencilBufferEnable
= true;
811 if (params
->depth
.enabled
) {
812 db
.SurfaceFormat
= params
->depth_format
;
813 db
.SurfaceType
= isl_to_gen_ds_surftype
[params
->depth
.surf
.dim
];
816 db
.TiledSurface
= true;
817 db
.TileWalk
= TILEWALK_YMAJOR
;
818 db
.MIPMapLayoutMode
= MIPLAYOUT_BELOW
;
821 db
.HierarchicalDepthBufferEnable
=
822 params
->depth
.aux_usage
== ISL_AUX_USAGE_HIZ
;
824 db
.Width
= params
->depth
.surf
.logical_level0_px
.width
- 1;
825 db
.Height
= params
->depth
.surf
.logical_level0_px
.height
- 1;
826 db
.RenderTargetViewExtent
= db
.Depth
=
827 params
->depth
.view
.array_len
- 1;
829 db
.LOD
= params
->depth
.view
.base_level
;
830 db
.MinimumArrayElement
= params
->depth
.view
.base_array_layer
;
832 db
.SurfacePitch
= params
->depth
.surf
.row_pitch
- 1;
835 isl_surf_get_array_pitch_el_rows(¶ms
->depth
.surf
) >> 2,
838 db
.SurfaceBaseAddress
= params
->depth
.addr
;
839 db
.DepthBufferMOCS
= mocs
;
840 } else if (params
->stencil
.enabled
) {
841 db
.SurfaceFormat
= D32_FLOAT
;
842 db
.SurfaceType
= isl_to_gen_ds_surftype
[params
->stencil
.surf
.dim
];
844 db
.Width
= params
->stencil
.surf
.logical_level0_px
.width
- 1;
845 db
.Height
= params
->stencil
.surf
.logical_level0_px
.height
- 1;
846 db
.RenderTargetViewExtent
= db
.Depth
=
847 params
->stencil
.view
.array_len
- 1;
849 db
.LOD
= params
->stencil
.view
.base_level
;
850 db
.MinimumArrayElement
= params
->stencil
.view
.base_array_layer
;
852 db
.SurfaceType
= SURFTYPE_NULL
;
853 db
.SurfaceFormat
= D32_FLOAT
;
857 blorp_emit(batch
, GENX(3DSTATE_HIER_DEPTH_BUFFER
), hiz
) {
858 if (params
->depth
.aux_usage
== ISL_AUX_USAGE_HIZ
) {
859 hiz
.SurfacePitch
= params
->depth
.aux_surf
.row_pitch
- 1;
860 hiz
.SurfaceBaseAddress
= params
->depth
.aux_addr
;
861 hiz
.HierarchicalDepthBufferMOCS
= mocs
;
864 isl_surf_get_array_pitch_sa_rows(¶ms
->depth
.aux_surf
) >> 2;
869 blorp_emit(batch
, GENX(3DSTATE_STENCIL_BUFFER
), sb
) {
870 if (params
->stencil
.enabled
) {
871 #if GEN_GEN >= 8 || GEN_IS_HASWELL
872 sb
.StencilBufferEnable
= true;
875 sb
.SurfacePitch
= params
->stencil
.surf
.row_pitch
- 1,
878 isl_surf_get_array_pitch_el_rows(¶ms
->stencil
.surf
) >> 2,
881 sb
.SurfaceBaseAddress
= params
->stencil
.addr
;
882 sb
.StencilBufferMOCS
= batch
->blorp
->mocs
.tex
;
886 /* 3DSTATE_CLEAR_PARAMS
888 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
889 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
890 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
892 blorp_emit(batch
, GENX(3DSTATE_CLEAR_PARAMS
), clear
) {
893 clear
.DepthClearValueValid
= true;
894 clear
.DepthClearValue
= params
->depth
.clear_color
.u32
[0];
899 blorp_emit_blend_state(struct blorp_batch
*batch
,
900 const struct blorp_params
*params
)
902 struct GENX(BLEND_STATE
) blend
;
903 memset(&blend
, 0, sizeof(blend
));
905 for (unsigned i
= 0; i
< params
->num_draw_buffers
; ++i
) {
906 blend
.Entry
[i
].PreBlendColorClampEnable
= true;
907 blend
.Entry
[i
].PostBlendColorClampEnable
= true;
908 blend
.Entry
[i
].ColorClampRange
= COLORCLAMP_RTFORMAT
;
910 blend
.Entry
[i
].WriteDisableRed
= params
->color_write_disable
[0];
911 blend
.Entry
[i
].WriteDisableGreen
= params
->color_write_disable
[1];
912 blend
.Entry
[i
].WriteDisableBlue
= params
->color_write_disable
[2];
913 blend
.Entry
[i
].WriteDisableAlpha
= params
->color_write_disable
[3];
917 void *state
= blorp_alloc_dynamic_state(batch
,
918 GENX(BLEND_STATE_length
) * 4,
920 GENX(BLEND_STATE_pack
)(NULL
, state
, &blend
);
921 blorp_flush_range(batch
, state
, GENX(BLEND_STATE_length
) * 4);
924 blorp_emit(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), sp
) {
925 sp
.BlendStatePointer
= offset
;
927 sp
.BlendStatePointerValid
= true;
933 blorp_emit(batch
, GENX(3DSTATE_PS_BLEND
), ps_blend
) {
934 ps_blend
.HasWriteableRT
= true;
942 blorp_emit_color_calc_state(struct blorp_batch
*batch
,
943 const struct blorp_params
*params
)
945 struct GENX(COLOR_CALC_STATE
) cc
= { 0 };
948 cc
.StencilReferenceValue
= params
->stencil_ref
;
952 void *state
= blorp_alloc_dynamic_state(batch
,
953 GENX(COLOR_CALC_STATE_length
) * 4,
955 GENX(COLOR_CALC_STATE_pack
)(NULL
, state
, &cc
);
956 blorp_flush_range(batch
, state
, GENX(COLOR_CALC_STATE_length
) * 4);
959 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), sp
) {
960 sp
.ColorCalcStatePointer
= offset
;
962 sp
.ColorCalcStatePointerValid
= true;
971 blorp_emit_depth_stencil_state(struct blorp_batch
*batch
,
972 const struct blorp_params
*params
)
975 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) ds
= {
976 GENX(3DSTATE_WM_DEPTH_STENCIL_header
),
979 struct GENX(DEPTH_STENCIL_STATE
) ds
= { 0 };
982 if (params
->depth
.enabled
) {
983 ds
.DepthBufferWriteEnable
= true;
985 switch (params
->hiz_op
) {
986 case BLORP_HIZ_OP_NONE
:
987 ds
.DepthTestEnable
= true;
988 ds
.DepthTestFunction
= COMPAREFUNCTION_ALWAYS
;
991 /* See the following sections of the Sandy Bridge PRM, Volume 2, Part1:
992 * - 7.5.3.1 Depth Buffer Clear
993 * - 7.5.3.2 Depth Buffer Resolve
994 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
996 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
997 ds
.DepthTestEnable
= true;
998 ds
.DepthTestFunction
= COMPAREFUNCTION_NEVER
;
1001 case BLORP_HIZ_OP_DEPTH_CLEAR
:
1002 case BLORP_HIZ_OP_HIZ_RESOLVE
:
1003 ds
.DepthTestEnable
= false;
1008 if (params
->stencil
.enabled
) {
1009 ds
.StencilBufferWriteEnable
= true;
1010 ds
.StencilTestEnable
= true;
1011 ds
.DoubleSidedStencilEnable
= false;
1013 ds
.StencilTestFunction
= COMPAREFUNCTION_ALWAYS
;
1014 ds
.StencilPassDepthPassOp
= STENCILOP_REPLACE
;
1016 ds
.StencilWriteMask
= params
->stencil_mask
;
1018 ds
.StencilReferenceValue
= params
->stencil_ref
;
1023 uint32_t offset
= 0;
1024 uint32_t *dw
= blorp_emit_dwords(batch
,
1025 GENX(3DSTATE_WM_DEPTH_STENCIL_length
));
1029 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, dw
, &ds
);
1032 void *state
= blorp_alloc_dynamic_state(batch
,
1033 GENX(DEPTH_STENCIL_STATE_length
) * 4,
1035 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, state
, &ds
);
1036 blorp_flush_range(batch
, state
, GENX(DEPTH_STENCIL_STATE_length
) * 4);
1040 blorp_emit(batch
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), sp
) {
1041 sp
.PointertoDEPTH_STENCIL_STATE
= offset
;
1049 blorp_emit_surface_state(struct blorp_batch
*batch
,
1050 const struct brw_blorp_surface_info
*surface
,
1051 void *state
, uint32_t state_offset
,
1052 bool is_render_target
)
1054 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1055 struct isl_surf surf
= surface
->surf
;
1057 if (surf
.dim
== ISL_SURF_DIM_1D
&&
1058 surf
.dim_layout
== ISL_DIM_LAYOUT_GEN4_2D
) {
1059 assert(surf
.logical_level0_px
.height
== 1);
1060 surf
.dim
= ISL_SURF_DIM_2D
;
1063 /* Blorp doesn't support HiZ in any of the blit or slow-clear paths */
1064 enum isl_aux_usage aux_usage
= surface
->aux_usage
;
1065 if (aux_usage
== ISL_AUX_USAGE_HIZ
)
1066 aux_usage
= ISL_AUX_USAGE_NONE
;
1068 const uint32_t mocs
=
1069 is_render_target
? batch
->blorp
->mocs
.rb
: batch
->blorp
->mocs
.tex
;
1071 isl_surf_fill_state(batch
->blorp
->isl_dev
, state
,
1072 .surf
= &surf
, .view
= &surface
->view
,
1073 .aux_surf
= &surface
->aux_surf
, .aux_usage
= aux_usage
,
1074 .mocs
= mocs
, .clear_color
= surface
->clear_color
);
1076 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.addr_offset
,
1079 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
1080 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
1081 * used to store other information. This should be ok, however, because
1082 * surface buffer addresses are always 4K page alinged.
1084 assert((surface
->aux_addr
.offset
& 0xfff) == 0);
1085 uint32_t *aux_addr
= state
+ isl_dev
->ss
.aux_addr_offset
;
1086 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.aux_addr_offset
,
1087 surface
->aux_addr
, *aux_addr
);
1090 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1094 blorp_emit_null_surface_state(struct blorp_batch
*batch
,
1095 const struct brw_blorp_surface_info
*surface
,
1098 struct GENX(RENDER_SURFACE_STATE
) ss
= {
1099 .SurfaceType
= SURFTYPE_NULL
,
1100 .SurfaceFormat
= ISL_FORMAT_R8G8B8A8_UNORM
,
1101 .Width
= surface
->surf
.logical_level0_px
.width
- 1,
1102 .Height
= surface
->surf
.logical_level0_px
.height
- 1,
1103 .MIPCountLOD
= surface
->view
.base_level
,
1104 .MinimumArrayElement
= surface
->view
.base_array_layer
,
1105 .Depth
= surface
->view
.array_len
- 1,
1106 .RenderTargetViewExtent
= surface
->view
.array_len
- 1,
1107 .NumberofMultisamples
= ffs(surface
->surf
.samples
) - 1,
1110 .SurfaceArray
= surface
->surf
.dim
!= ISL_SURF_DIM_3D
,
1116 .TiledSurface
= true,
1120 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &ss
);
1122 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1126 blorp_emit_surface_states(struct blorp_batch
*batch
,
1127 const struct blorp_params
*params
)
1129 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1130 uint32_t bind_offset
, surface_offsets
[2];
1131 void *surface_maps
[2];
1133 if (params
->use_pre_baked_binding_table
) {
1134 bind_offset
= params
->pre_baked_binding_table_offset
;
1136 unsigned num_surfaces
= 1 + params
->src
.enabled
;
1137 blorp_alloc_binding_table(batch
, num_surfaces
,
1138 isl_dev
->ss
.size
, isl_dev
->ss
.align
,
1139 &bind_offset
, surface_offsets
, surface_maps
);
1141 if (params
->dst
.enabled
) {
1142 blorp_emit_surface_state(batch
, ¶ms
->dst
,
1143 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
],
1144 surface_offsets
[BLORP_RENDERBUFFER_BT_INDEX
],
1147 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1148 const struct brw_blorp_surface_info
*surface
=
1149 params
->depth
.enabled
? ¶ms
->depth
: ¶ms
->stencil
;
1150 blorp_emit_null_surface_state(batch
, surface
,
1151 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
]);
1154 if (params
->src
.enabled
) {
1155 blorp_emit_surface_state(batch
, ¶ms
->src
,
1156 surface_maps
[BLORP_TEXTURE_BT_INDEX
],
1157 surface_offsets
[BLORP_TEXTURE_BT_INDEX
], false);
1162 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), bt
);
1163 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_HS
), bt
);
1164 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_DS
), bt
);
1165 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_GS
), bt
);
1167 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS
), bt
) {
1168 bt
.PointertoPSBindingTable
= bind_offset
;
1171 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS
), bt
) {
1172 bt
.PSBindingTableChange
= true;
1173 bt
.PointertoPSBindingTable
= bind_offset
;
1179 blorp_emit_sampler_state(struct blorp_batch
*batch
,
1180 const struct blorp_params
*params
)
1182 struct GENX(SAMPLER_STATE
) sampler
= {
1183 .MipModeFilter
= MIPFILTER_NONE
,
1184 .MagModeFilter
= MAPFILTER_LINEAR
,
1185 .MinModeFilter
= MAPFILTER_LINEAR
,
1188 .TCXAddressControlMode
= TCM_CLAMP
,
1189 .TCYAddressControlMode
= TCM_CLAMP
,
1190 .TCZAddressControlMode
= TCM_CLAMP
,
1191 .MaximumAnisotropy
= RATIO21
,
1192 .RAddressMinFilterRoundingEnable
= true,
1193 .RAddressMagFilterRoundingEnable
= true,
1194 .VAddressMinFilterRoundingEnable
= true,
1195 .VAddressMagFilterRoundingEnable
= true,
1196 .UAddressMinFilterRoundingEnable
= true,
1197 .UAddressMagFilterRoundingEnable
= true,
1198 .NonnormalizedCoordinateEnable
= true,
1202 void *state
= blorp_alloc_dynamic_state(batch
,
1203 GENX(SAMPLER_STATE_length
) * 4,
1205 GENX(SAMPLER_STATE_pack
)(NULL
, state
, &sampler
);
1206 blorp_flush_range(batch
, state
, GENX(SAMPLER_STATE_length
) * 4);
1209 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS
), ssp
) {
1210 ssp
.PointertoPSSamplerState
= offset
;
1213 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS
), ssp
) {
1214 ssp
.VSSamplerStateChange
= true;
1215 ssp
.GSSamplerStateChange
= true;
1216 ssp
.PSSamplerStateChange
= true;
1217 ssp
.PointertoPSSamplerState
= offset
;
1223 blorp_emit_3dstate_multisample(struct blorp_batch
*batch
,
1224 const struct blorp_params
*params
)
1226 blorp_emit(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
1227 ms
.NumberofMultisamples
= __builtin_ffs(params
->num_samples
) - 1;
1230 /* The PRM says that this bit is valid only for DX9:
1232 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
1233 * should not have any effect by setting or not setting this bit.
1235 ms
.PixelPositionOffsetEnable
= false;
1236 ms
.PixelLocation
= CENTER
;
1238 ms
.PixelLocation
= PIXLOC_CENTER
;
1240 switch (params
->num_samples
) {
1242 GEN_SAMPLE_POS_1X(ms
.Sample
);
1245 GEN_SAMPLE_POS_2X(ms
.Sample
);
1248 GEN_SAMPLE_POS_4X(ms
.Sample
);
1251 GEN_SAMPLE_POS_8X(ms
.Sample
);
1257 ms
.PixelLocation
= PIXLOC_CENTER
;
1258 GEN_SAMPLE_POS_4X(ms
.Sample
);
1264 /* Emits the Optimized HiZ sequence specified in the BDW+ PRMs. The
1265 * depth/stencil buffer extents are ignored to handle APIs which perform
1266 * clearing operations without such information.
1269 blorp_emit_gen8_hiz_op(struct blorp_batch
*batch
,
1270 const struct blorp_params
*params
)
1272 /* We should be performing an operation on a depth or stencil buffer.
1274 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1276 /* The stencil buffer should only be enabled if a fast clear operation is
1279 if (params
->stencil
.enabled
)
1280 assert(params
->hiz_op
== BLORP_HIZ_OP_DEPTH_CLEAR
);
1282 /* If we can't alter the depth stencil config and multiple layers are
1283 * involved, the HiZ op will fail. This is because the op requires that a
1284 * new config is emitted for each additional layer.
1286 if (batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
) {
1287 assert(params
->num_layers
<= 1);
1289 blorp_emit_depth_stencil_config(batch
, params
);
1292 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
) {
1293 switch (params
->hiz_op
) {
1294 case BLORP_HIZ_OP_DEPTH_CLEAR
:
1295 hzp
.StencilBufferClearEnable
= params
->stencil
.enabled
;
1296 hzp
.DepthBufferClearEnable
= params
->depth
.enabled
;
1297 hzp
.StencilClearValue
= params
->stencil_ref
;
1299 case BLORP_HIZ_OP_DEPTH_RESOLVE
:
1300 hzp
.DepthBufferResolveEnable
= true;
1302 case BLORP_HIZ_OP_HIZ_RESOLVE
:
1303 hzp
.HierarchicalDepthBufferResolveEnable
= true;
1305 case BLORP_HIZ_OP_NONE
:
1306 unreachable("Invalid HIZ op");
1309 hzp
.NumberofMultisamples
= ffs(params
->num_samples
) - 1;
1310 hzp
.SampleMask
= 0xFFFF;
1312 /* Due to a hardware issue, this bit MBZ */
1313 assert(hzp
.ScissorRectangleEnable
== false);
1315 /* Contrary to the HW docs both fields are inclusive */
1316 hzp
.ClearRectangleXMin
= params
->x0
;
1317 hzp
.ClearRectangleYMin
= params
->y0
;
1319 /* Contrary to the HW docs both fields are exclusive */
1320 hzp
.ClearRectangleXMax
= params
->x1
;
1321 hzp
.ClearRectangleYMax
= params
->y1
;
1324 /* PIPE_CONTROL w/ all bits clear except for “Post-Sync Operation” must set
1325 * to “Write Immediate Data” enabled.
1327 blorp_emit(batch
, GENX(PIPE_CONTROL
), pc
) {
1328 pc
.PostSyncOperation
= WriteImmediateData
;
1331 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
);
1333 /* Perform depth clear specific flushing */
1334 if (params
->hiz_op
== BLORP_HIZ_OP_DEPTH_CLEAR
&& params
->depth
.enabled
) {
1335 blorp_emit(batch
, GENX(PIPE_CONTROL
), pc
) {
1336 pc
.DepthStallEnable
= true;
1337 pc
.DepthCacheFlushEnable
= true;
1343 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
1345 blorp_emit_viewport_state(struct blorp_batch
*batch
,
1346 const struct blorp_params
*params
)
1348 uint32_t cc_vp_offset
;
1350 void *state
= blorp_alloc_dynamic_state(batch
,
1351 GENX(CC_VIEWPORT_length
) * 4, 32,
1354 GENX(CC_VIEWPORT_pack
)(batch
, state
,
1355 &(struct GENX(CC_VIEWPORT
)) {
1356 .MinimumDepth
= 0.0,
1357 .MaximumDepth
= 1.0,
1359 blorp_flush_range(batch
, state
, GENX(CC_VIEWPORT_length
) * 4);
1362 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), vsp
) {
1363 vsp
.CCViewportPointer
= cc_vp_offset
;
1366 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vsp
) {
1367 vsp
.CCViewportStateChange
= true;
1368 vsp
.PointertoCC_VIEWPORT
= cc_vp_offset
;
1375 * \brief Execute a blit or render pass operation.
1377 * To execute the operation, this function manually constructs and emits a
1378 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1379 * constructing and after emitting the batch.
1381 * This function alters no GL state.
1384 blorp_exec(struct blorp_batch
*batch
, const struct blorp_params
*params
)
1386 uint32_t blend_state_offset
= 0;
1387 uint32_t color_calc_state_offset
= 0;
1388 uint32_t depth_stencil_state_offset
;
1391 if (params
->hiz_op
!= BLORP_HIZ_OP_NONE
) {
1392 blorp_emit_gen8_hiz_op(batch
, params
);
1397 blorp_emit_vertex_buffers(batch
, params
);
1398 blorp_emit_vertex_elements(batch
, params
);
1400 emit_urb_config(batch
, params
);
1402 if (params
->wm_prog_data
) {
1403 blend_state_offset
= blorp_emit_blend_state(batch
, params
);
1405 color_calc_state_offset
= blorp_emit_color_calc_state(batch
, params
);
1406 depth_stencil_state_offset
= blorp_emit_depth_stencil_state(batch
, params
);
1409 /* 3DSTATE_CC_STATE_POINTERS
1411 * The pointer offsets are relative to
1412 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
1414 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
1416 * The dynamic state emit helpers emit their own STATE_POINTERS packets on
1417 * gen7+. However, on gen6 and earlier, they're all lumpped together in
1418 * one CC_STATE_POINTERS packet so we have to emit that here.
1420 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), cc
) {
1421 cc
.BLEND_STATEChange
= true;
1422 cc
.COLOR_CALC_STATEChange
= true;
1423 cc
.DEPTH_STENCIL_STATEChange
= true;
1424 cc
.PointertoBLEND_STATE
= blend_state_offset
;
1425 cc
.PointertoCOLOR_CALC_STATE
= color_calc_state_offset
;
1426 cc
.PointertoDEPTH_STENCIL_STATE
= depth_stencil_state_offset
;
1429 (void)blend_state_offset
;
1430 (void)color_calc_state_offset
;
1431 (void)depth_stencil_state_offset
;
1434 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_VS
), vs
);
1436 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_HS
), hs
);
1437 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_DS
), DS
);
1439 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_GS
), gs
);
1440 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_PS
), ps
);
1442 blorp_emit_surface_states(batch
, params
);
1444 if (params
->src
.enabled
)
1445 blorp_emit_sampler_state(batch
, params
);
1447 blorp_emit_3dstate_multisample(batch
, params
);
1449 blorp_emit(batch
, GENX(3DSTATE_SAMPLE_MASK
), mask
) {
1450 mask
.SampleMask
= (1 << params
->num_samples
) - 1;
1453 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1454 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1456 * [DevSNB] A pipeline flush must be programmed prior to a
1457 * 3DSTATE_VS command that causes the VS Function Enable to
1458 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
1459 * command with CS stall bit set and a post sync operation.
1461 * We've already done one at the start of the BLORP operation.
1463 blorp_emit_vs_config(batch
, params
);
1465 blorp_emit(batch
, GENX(3DSTATE_HS
), hs
);
1466 blorp_emit(batch
, GENX(3DSTATE_TE
), te
);
1467 blorp_emit(batch
, GENX(3DSTATE_DS
), DS
);
1468 blorp_emit(batch
, GENX(3DSTATE_STREAMOUT
), so
);
1470 blorp_emit(batch
, GENX(3DSTATE_GS
), gs
);
1472 blorp_emit(batch
, GENX(3DSTATE_CLIP
), clip
) {
1473 clip
.PerspectiveDivideDisable
= true;
1476 blorp_emit_sf_config(batch
, params
);
1477 blorp_emit_ps_config(batch
, params
);
1479 blorp_emit_viewport_state(batch
, params
);
1481 if (!(batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
))
1482 blorp_emit_depth_stencil_config(batch
, params
);
1484 blorp_emit(batch
, GENX(3DPRIMITIVE
), prim
) {
1485 prim
.VertexAccessType
= SEQUENTIAL
;
1486 prim
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
1487 prim
.VertexCountPerInstance
= 3;
1488 prim
.InstanceCount
= params
->num_layers
;
1492 #endif /* BLORP_GENX_EXEC_H */