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 "dev/gen_device_info.h"
29 #include "common/gen_sample_positions.h"
30 #include "genxml/gen_macros.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
,
60 blorp_alloc_vertex_buffer(struct blorp_batch
*batch
, uint32_t size
,
61 struct blorp_address
*addr
);
63 blorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch
*batch
,
64 const struct blorp_address
*addrs
,
68 static struct blorp_address
69 blorp_get_workaround_page(struct blorp_batch
*batch
);
73 blorp_alloc_binding_table(struct blorp_batch
*batch
, unsigned num_entries
,
74 unsigned state_size
, unsigned state_alignment
,
75 uint32_t *bt_offset
, uint32_t *surface_offsets
,
79 blorp_flush_range(struct blorp_batch
*batch
, void *start
, size_t size
);
82 blorp_surface_reloc(struct blorp_batch
*batch
, uint32_t ss_offset
,
83 struct blorp_address address
, uint32_t delta
);
85 #if GEN_GEN >= 7 && GEN_GEN < 10
86 static struct blorp_address
87 blorp_get_surface_base_address(struct blorp_batch
*batch
);
91 blorp_emit_urb_config(struct blorp_batch
*batch
,
92 unsigned vs_entry_size
, unsigned sf_entry_size
);
95 blorp_emit_pipeline(struct blorp_batch
*batch
,
96 const struct blorp_params
*params
);
98 /***** BEGIN blorp_exec implementation ******/
101 _blorp_combine_address(struct blorp_batch
*batch
, void *location
,
102 struct blorp_address address
, uint32_t delta
)
104 if (address
.buffer
== NULL
) {
105 return address
.offset
+ delta
;
107 return blorp_emit_reloc(batch
, location
, address
, delta
);
111 #define __gen_address_type struct blorp_address
112 #define __gen_user_data struct blorp_batch
113 #define __gen_combine_address _blorp_combine_address
115 #include "genxml/genX_pack.h"
117 #define _blorp_cmd_length(cmd) cmd ## _length
118 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
119 #define _blorp_cmd_header(cmd) cmd ## _header
120 #define _blorp_cmd_pack(cmd) cmd ## _pack
122 #define blorp_emit(batch, cmd, name) \
123 for (struct cmd name = { _blorp_cmd_header(cmd) }, \
124 *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
125 __builtin_expect(_dst != NULL, 1); \
126 _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name), \
129 #define blorp_emitn(batch, cmd, n) ({ \
130 uint32_t *_dw = blorp_emit_dwords(batch, n); \
132 struct cmd template = { \
133 _blorp_cmd_header(cmd), \
134 .DWordLength = n - _blorp_cmd_length_bias(cmd), \
136 _blorp_cmd_pack(cmd)(batch, _dw, &template); \
138 _dw ? _dw + 1 : NULL; /* Array starts at dw[1] */ \
141 #define STRUCT_ZERO(S) ({ struct S t; memset(&t, 0, sizeof(t)); t; })
143 #define blorp_emit_dynamic(batch, state, name, align, offset) \
144 for (struct state name = STRUCT_ZERO(state), \
145 *_dst = blorp_alloc_dynamic_state(batch, \
146 _blorp_cmd_length(state) * 4, \
148 __builtin_expect(_dst != NULL, 1); \
149 _blorp_cmd_pack(state)(batch, (void *)_dst, &name), \
150 blorp_flush_range(batch, _dst, _blorp_cmd_length(state) * 4), \
159 * Assign the entire URB to the VS. Even though the VS disabled, URB space
160 * is still needed because the clipper loads the VUE's from the URB. From
161 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
162 * Dword 1.15:0 "VS Number of URB Entries":
163 * This field is always used (even if VS Function Enable is DISABLED).
165 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
166 * safely ignore it because this batch contains only one draw call.
167 * Because of URB corruption caused by allocating a previous GS unit
168 * URB entry to the VS unit, software is required to send a “GS NULL
169 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
170 * plus a dummy DRAW call before any case where VS will be taking over
173 * If the 3DSTATE_URB_VS is emitted, than the others must be also.
174 * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
176 * 3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
177 * programmed in order for the programming of this state to be
181 emit_urb_config(struct blorp_batch
*batch
,
182 const struct blorp_params
*params
)
184 /* Once vertex fetcher has written full VUE entries with complete
185 * header the space requirement is as follows per vertex (in bytes):
187 * Header Position Program constants
188 * +--------+------------+-------------------+
189 * | 16 | 16 | n x 16 |
190 * +--------+------------+-------------------+
192 * where 'n' stands for number of varying inputs expressed as vec4s.
194 const unsigned num_varyings
=
195 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
196 const unsigned total_needed
= 16 + 16 + num_varyings
* 16;
198 /* The URB size is expressed in units of 64 bytes (512 bits) */
199 const unsigned vs_entry_size
= DIV_ROUND_UP(total_needed
, 64);
201 const unsigned sf_entry_size
=
202 params
->sf_prog_data
? params
->sf_prog_data
->urb_entry_size
: 0;
204 blorp_emit_urb_config(batch
, vs_entry_size
, sf_entry_size
);
209 blorp_emit_memcpy(struct blorp_batch
*batch
,
210 struct blorp_address dst
,
211 struct blorp_address src
,
216 blorp_emit_vertex_data(struct blorp_batch
*batch
,
217 const struct blorp_params
*params
,
218 struct blorp_address
*addr
,
221 const float vertices
[] = {
222 /* v0 */ (float)params
->x1
, (float)params
->y1
, params
->z
,
223 /* v1 */ (float)params
->x0
, (float)params
->y1
, params
->z
,
224 /* v2 */ (float)params
->x0
, (float)params
->y0
, params
->z
,
227 void *data
= blorp_alloc_vertex_buffer(batch
, sizeof(vertices
), addr
);
228 memcpy(data
, vertices
, sizeof(vertices
));
229 *size
= sizeof(vertices
);
230 blorp_flush_range(batch
, data
, *size
);
234 blorp_emit_input_varying_data(struct blorp_batch
*batch
,
235 const struct blorp_params
*params
,
236 struct blorp_address
*addr
,
239 const unsigned vec4_size_in_bytes
= 4 * sizeof(float);
240 const unsigned max_num_varyings
=
241 DIV_ROUND_UP(sizeof(params
->wm_inputs
), vec4_size_in_bytes
);
242 const unsigned num_varyings
=
243 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
245 *size
= 16 + num_varyings
* vec4_size_in_bytes
;
247 const uint32_t *const inputs_src
= (const uint32_t *)¶ms
->wm_inputs
;
248 void *data
= blorp_alloc_vertex_buffer(batch
, *size
, addr
);
249 uint32_t *inputs
= data
;
251 /* Copy in the VS inputs */
252 assert(sizeof(params
->vs_inputs
) == 16);
253 memcpy(inputs
, ¶ms
->vs_inputs
, sizeof(params
->vs_inputs
));
256 if (params
->wm_prog_data
) {
257 /* Walk over the attribute slots, determine if the attribute is used by
258 * the program and when necessary copy the values from the input storage
259 * to the vertex data buffer.
261 for (unsigned i
= 0; i
< max_num_varyings
; i
++) {
262 const gl_varying_slot attr
= VARYING_SLOT_VAR0
+ i
;
264 const int input_index
= params
->wm_prog_data
->urb_setup
[attr
];
268 memcpy(inputs
, inputs_src
+ i
* 4, vec4_size_in_bytes
);
274 blorp_flush_range(batch
, data
, *size
);
276 if (params
->dst_clear_color_as_input
) {
278 /* In this case, the clear color isn't known statically and instead
279 * comes in through an indirect which we have to copy into the vertex
280 * buffer before we execute the 3DPRIMITIVE. We already copied the
281 * value of params->wm_inputs.clear_color into the vertex buffer in the
282 * loop above. Now we emit code to stomp it from the GPU with the
283 * actual clear color value.
285 assert(num_varyings
== 1);
287 /* The clear color is the first thing after the header */
288 struct blorp_address clear_color_input_addr
= *addr
;
289 clear_color_input_addr
.offset
+= 16;
291 const unsigned clear_color_size
=
292 GEN_GEN
< 10 ? batch
->blorp
->isl_dev
->ss
.clear_value_size
: 4 * 4;
293 blorp_emit_memcpy(batch
, clear_color_input_addr
,
294 params
->dst
.clear_color_addr
,
297 unreachable("MCS partial resolve is not a thing on SNB and earlier");
303 blorp_fill_vertex_buffer_state(struct blorp_batch
*batch
,
304 struct GENX(VERTEX_BUFFER_STATE
) *vb
,
306 struct blorp_address addr
, uint32_t size
,
309 vb
[idx
].VertexBufferIndex
= idx
;
310 vb
[idx
].BufferStartingAddress
= addr
;
311 vb
[idx
].BufferPitch
= stride
;
314 vb
[idx
].VertexBufferMOCS
= addr
.mocs
;
318 vb
[idx
].AddressModifyEnable
= true;
322 vb
[idx
].BufferSize
= size
;
324 vb
[idx
].BufferAccessType
= stride
> 0 ? VERTEXDATA
: INSTANCEDATA
;
325 vb
[idx
].EndAddress
= vb
[idx
].BufferStartingAddress
;
326 vb
[idx
].EndAddress
.offset
+= size
- 1;
328 vb
[idx
].BufferAccessType
= stride
> 0 ? VERTEXDATA
: INSTANCEDATA
;
329 vb
[idx
].MaxIndex
= stride
> 0 ? size
/ stride
: 0;
334 blorp_emit_vertex_buffers(struct blorp_batch
*batch
,
335 const struct blorp_params
*params
)
337 struct GENX(VERTEX_BUFFER_STATE
) vb
[3];
338 uint32_t num_vbs
= 2;
339 memset(vb
, 0, sizeof(vb
));
341 struct blorp_address addrs
[2] = {};
343 blorp_emit_vertex_data(batch
, params
, &addrs
[0], &size
);
344 blorp_fill_vertex_buffer_state(batch
, vb
, 0, addrs
[0], size
,
347 blorp_emit_input_varying_data(batch
, params
, &addrs
[1], &size
);
348 blorp_fill_vertex_buffer_state(batch
, vb
, 1, addrs
[1], size
, 0);
350 const unsigned num_dwords
= 1 + num_vbs
* GENX(VERTEX_BUFFER_STATE_length
);
351 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), num_dwords
);
355 blorp_vf_invalidate_for_vb_48b_transitions(batch
, addrs
, num_vbs
);
357 for (unsigned i
= 0; i
< num_vbs
; i
++) {
358 GENX(VERTEX_BUFFER_STATE_pack
)(batch
, dw
, &vb
[i
]);
359 dw
+= GENX(VERTEX_BUFFER_STATE_length
);
364 blorp_emit_vertex_elements(struct blorp_batch
*batch
,
365 const struct blorp_params
*params
)
367 const unsigned num_varyings
=
368 params
->wm_prog_data
? params
->wm_prog_data
->num_varying_inputs
: 0;
369 bool need_ndc
= batch
->blorp
->compiler
->devinfo
->gen
<= 5;
370 const unsigned num_elements
= 2 + need_ndc
+ num_varyings
;
372 struct GENX(VERTEX_ELEMENT_STATE
) ve
[num_elements
];
373 memset(ve
, 0, num_elements
* sizeof(*ve
));
375 /* Setup VBO for the rectangle primitive..
377 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
378 * vertices. The vertices reside in screen space with DirectX
379 * coordinates (that is, (0, 0) is the upper left corner).
386 * Since the VS is disabled, the clipper loads each VUE directly from
387 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
388 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
389 * dw0: Reserved, MBZ.
390 * dw1: Render Target Array Index. Below vertex fetcher gets programmed
391 * to assign this with primitive instance identifier which will be
392 * used for layered clears. All other renders have only one instance
393 * and therefore the value will be effectively zero.
394 * dw2: Viewport Index. The HiZ op disables viewport mapping and
395 * scissoring, so set the dword to 0.
396 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
397 * so set the dword to 0.
398 * dw4: Vertex Position X.
399 * dw5: Vertex Position Y.
400 * dw6: Vertex Position Z.
401 * dw7: Vertex Position W.
403 * dw8: Flat vertex input 0
404 * dw9: Flat vertex input 1
406 * dwn: Flat vertex input n - 8
408 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
409 * "Vertex URB Entry (VUE) Formats".
411 * Only vertex position X and Y are going to be variable, Z is fixed to
412 * zero and W to one. Header words dw0,2,3 are zero. There is no need to
413 * include the fixed values in the vertex buffer. Vertex fetcher can be
414 * instructed to fill vertex elements with constant values of one and zero
415 * instead of reading them from the buffer.
416 * Flat inputs are program constants that are not interpolated. Moreover
417 * their values will be the same between vertices.
419 * See the vertex element setup below.
423 ve
[slot
] = (struct GENX(VERTEX_ELEMENT_STATE
)) {
424 .VertexBufferIndex
= 1,
426 .SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
,
427 .SourceElementOffset
= 0,
428 .Component0Control
= VFCOMP_STORE_SRC
,
430 /* From Gen8 onwards hardware is no more instructed to overwrite
431 * components using an element specifier. Instead one has separate
432 * 3DSTATE_VF_SGVS (System Generated Value Setup) state packet for it.
435 .Component1Control
= VFCOMP_STORE_0
,
437 .Component1Control
= VFCOMP_STORE_IID
,
439 .Component1Control
= VFCOMP_STORE_0
,
441 .Component2Control
= VFCOMP_STORE_0
,
442 .Component3Control
= VFCOMP_STORE_0
,
444 .DestinationElementOffset
= slot
* 4,
450 /* On Iron Lake and earlier, a native device coordinates version of the
451 * position goes right after the normal VUE header and before position.
452 * Since w == 1 for all of our coordinates, this is just a copy of the
455 ve
[slot
] = (struct GENX(VERTEX_ELEMENT_STATE
)) {
456 .VertexBufferIndex
= 0,
458 .SourceElementFormat
= ISL_FORMAT_R32G32B32_FLOAT
,
459 .SourceElementOffset
= 0,
460 .Component0Control
= VFCOMP_STORE_SRC
,
461 .Component1Control
= VFCOMP_STORE_SRC
,
462 .Component2Control
= VFCOMP_STORE_SRC
,
463 .Component3Control
= VFCOMP_STORE_1_FP
,
464 .DestinationElementOffset
= slot
* 4,
469 ve
[slot
] = (struct GENX(VERTEX_ELEMENT_STATE
)) {
470 .VertexBufferIndex
= 0,
472 .SourceElementFormat
= ISL_FORMAT_R32G32B32_FLOAT
,
473 .SourceElementOffset
= 0,
474 .Component0Control
= VFCOMP_STORE_SRC
,
475 .Component1Control
= VFCOMP_STORE_SRC
,
476 .Component2Control
= VFCOMP_STORE_SRC
,
477 .Component3Control
= VFCOMP_STORE_1_FP
,
479 .DestinationElementOffset
= slot
* 4,
484 for (unsigned i
= 0; i
< num_varyings
; ++i
) {
485 ve
[slot
] = (struct GENX(VERTEX_ELEMENT_STATE
)) {
486 .VertexBufferIndex
= 1,
488 .SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
,
489 .SourceElementOffset
= 16 + i
* 4 * sizeof(float),
490 .Component0Control
= VFCOMP_STORE_SRC
,
491 .Component1Control
= VFCOMP_STORE_SRC
,
492 .Component2Control
= VFCOMP_STORE_SRC
,
493 .Component3Control
= VFCOMP_STORE_SRC
,
495 .DestinationElementOffset
= slot
* 4,
501 const unsigned num_dwords
=
502 1 + GENX(VERTEX_ELEMENT_STATE_length
) * num_elements
;
503 uint32_t *dw
= blorp_emitn(batch
, GENX(3DSTATE_VERTEX_ELEMENTS
), num_dwords
);
507 for (unsigned i
= 0; i
< num_elements
; i
++) {
508 GENX(VERTEX_ELEMENT_STATE_pack
)(batch
, dw
, &ve
[i
]);
509 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
513 /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
514 * primitive instance identifier. This is used for layered clears.
516 blorp_emit(batch
, GENX(3DSTATE_VF_SGVS
), sgvs
) {
517 sgvs
.InstanceIDEnable
= true;
518 sgvs
.InstanceIDComponentNumber
= COMP_1
;
519 sgvs
.InstanceIDElementOffset
= 0;
522 for (unsigned i
= 0; i
< num_elements
; i
++) {
523 blorp_emit(batch
, GENX(3DSTATE_VF_INSTANCING
), vf
) {
524 vf
.VertexElementIndex
= i
;
525 vf
.InstancingEnable
= false;
529 blorp_emit(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
530 topo
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
535 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
537 blorp_emit_cc_viewport(struct blorp_batch
*batch
)
539 uint32_t cc_vp_offset
;
540 blorp_emit_dynamic(batch
, GENX(CC_VIEWPORT
), vp
, 32, &cc_vp_offset
) {
541 vp
.MinimumDepth
= 0.0;
542 vp
.MaximumDepth
= 1.0;
546 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), vsp
) {
547 vsp
.CCViewportPointer
= cc_vp_offset
;
550 blorp_emit(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vsp
) {
551 vsp
.CCViewportStateChange
= true;
552 vsp
.PointertoCC_VIEWPORT
= cc_vp_offset
;
560 blorp_emit_sampler_state(struct blorp_batch
*batch
)
563 blorp_emit_dynamic(batch
, GENX(SAMPLER_STATE
), sampler
, 32, &offset
) {
564 sampler
.MipModeFilter
= MIPFILTER_NONE
;
565 sampler
.MagModeFilter
= MAPFILTER_LINEAR
;
566 sampler
.MinModeFilter
= MAPFILTER_LINEAR
;
569 sampler
.TCXAddressControlMode
= TCM_CLAMP
;
570 sampler
.TCYAddressControlMode
= TCM_CLAMP
;
571 sampler
.TCZAddressControlMode
= TCM_CLAMP
;
572 sampler
.MaximumAnisotropy
= RATIO21
;
573 sampler
.RAddressMinFilterRoundingEnable
= true;
574 sampler
.RAddressMagFilterRoundingEnable
= true;
575 sampler
.VAddressMinFilterRoundingEnable
= true;
576 sampler
.VAddressMagFilterRoundingEnable
= true;
577 sampler
.UAddressMinFilterRoundingEnable
= true;
578 sampler
.UAddressMagFilterRoundingEnable
= true;
580 sampler
.NonnormalizedCoordinateEnable
= true;
585 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS
), ssp
) {
586 ssp
.PointertoPSSamplerState
= offset
;
589 blorp_emit(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS
), ssp
) {
590 ssp
.VSSamplerStateChange
= true;
591 ssp
.GSSamplerStateChange
= true;
592 ssp
.PSSamplerStateChange
= true;
593 ssp
.PointertoPSSamplerState
= offset
;
600 /* What follows is the code for setting up a "pipeline" on Sandy Bridge and
601 * later hardware. This file will be included by i965 for gen4-5 as well, so
602 * this code is guarded by GEN_GEN >= 6.
607 blorp_emit_vs_config(struct blorp_batch
*batch
,
608 const struct blorp_params
*params
)
610 struct brw_vs_prog_data
*vs_prog_data
= params
->vs_prog_data
;
611 assert(!vs_prog_data
|| GEN_GEN
< 11 ||
612 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
);
614 blorp_emit(batch
, GENX(3DSTATE_VS
), vs
) {
618 vs
.KernelStartPointer
= params
->vs_prog_kernel
;
620 vs
.DispatchGRFStartRegisterForURBData
=
621 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
622 vs
.VertexURBEntryReadLength
=
623 vs_prog_data
->base
.urb_read_length
;
624 vs
.VertexURBEntryReadOffset
= 0;
626 vs
.MaximumNumberofThreads
=
627 batch
->blorp
->isl_dev
->info
->max_vs_threads
- 1;
630 vs
.SIMD8DispatchEnable
=
631 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
638 blorp_emit_sf_config(struct blorp_batch
*batch
,
639 const struct blorp_params
*params
)
641 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
645 * Disable ViewportTransformEnable (dw2.1)
647 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
648 * Primitives Overview":
649 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
650 * use of screen- space coordinates).
652 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
653 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
655 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
656 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
657 * SOLID: Any triangle or rectangle object found to be front-facing
658 * is rendered as a solid object. This setting is required when
659 * (rendering rectangle (RECTLIST) objects.
664 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
);
666 blorp_emit(batch
, GENX(3DSTATE_RASTER
), raster
) {
667 raster
.CullMode
= CULLMODE_NONE
;
670 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
671 sbe
.VertexURBEntryReadOffset
= 1;
673 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
674 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
675 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
677 sbe
.NumberofSFOutputAttributes
= 0;
678 sbe
.VertexURBEntryReadLength
= 1;
680 sbe
.ForceVertexURBEntryReadLength
= true;
681 sbe
.ForceVertexURBEntryReadOffset
= true;
684 for (unsigned i
= 0; i
< 32; i
++)
685 sbe
.AttributeActiveComponentFormat
[i
] = ACF_XYZW
;
691 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
692 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
693 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
695 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
696 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
699 sf
.DepthBufferSurfaceFormat
= params
->depth_format
;
703 blorp_emit(batch
, GENX(3DSTATE_SBE
), sbe
) {
704 sbe
.VertexURBEntryReadOffset
= 1;
706 sbe
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
707 sbe
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
708 sbe
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
710 sbe
.NumberofSFOutputAttributes
= 0;
711 sbe
.VertexURBEntryReadLength
= 1;
715 #else /* GEN_GEN <= 6 */
717 blorp_emit(batch
, GENX(3DSTATE_SF
), sf
) {
718 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
719 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
721 sf
.MultisampleRasterizationMode
= params
->num_samples
> 1 ?
722 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
724 sf
.VertexURBEntryReadOffset
= 1;
726 sf
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
727 sf
.VertexURBEntryReadLength
= brw_blorp_get_urb_length(prog_data
);
728 sf
.ConstantInterpolationEnable
= prog_data
->flat_inputs
;
730 sf
.NumberofSFOutputAttributes
= 0;
731 sf
.VertexURBEntryReadLength
= 1;
739 blorp_emit_ps_config(struct blorp_batch
*batch
,
740 const struct blorp_params
*params
)
742 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
744 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
745 * nonzero to prevent the GPU from hanging. While the documentation doesn't
746 * mention this explicitly, it notes that the valid range for the field is
747 * [1,39] = [2,40] threads, which excludes zero.
749 * To be safe (and to minimize extraneous code) we go ahead and fully
750 * configure the WM state whether or not there is a WM program.
755 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
);
757 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
758 if (params
->src
.enabled
) {
759 ps
.SamplerCount
= 1; /* Up to 4 samplers */
760 ps
.BindingTableEntryCount
= 2;
762 ps
.BindingTableEntryCount
= 1;
766 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
767 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
769 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
770 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 0);
771 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
772 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 1);
773 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
774 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 2);
776 ps
.KernelStartPointer0
= params
->wm_prog_kernel
+
777 brw_wm_prog_data_prog_offset(prog_data
, ps
, 0);
778 ps
.KernelStartPointer1
= params
->wm_prog_kernel
+
779 brw_wm_prog_data_prog_offset(prog_data
, ps
, 1);
780 ps
.KernelStartPointer2
= params
->wm_prog_kernel
+
781 brw_wm_prog_data_prog_offset(prog_data
, ps
, 2);
784 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64
785 * for pre Gen11 and 128 for gen11+; On gen11+ If a programmed value is
786 * k, it implies 2(k+1) threads. It implicitly scales for different GT
787 * levels (which have some # of PSDs).
789 * In Gen8 the format is U8-2 whereas in Gen9+ it is U9-1.
792 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
794 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
796 switch (params
->fast_clear_op
) {
797 case ISL_AUX_OP_NONE
:
800 case ISL_AUX_OP_PARTIAL_RESOLVE
:
801 ps
.RenderTargetResolveType
= RESOLVE_PARTIAL
;
803 case ISL_AUX_OP_FULL_RESOLVE
:
804 ps
.RenderTargetResolveType
= RESOLVE_FULL
;
807 case ISL_AUX_OP_FULL_RESOLVE
:
808 ps
.RenderTargetResolveEnable
= true;
811 case ISL_AUX_OP_FAST_CLEAR
:
812 ps
.RenderTargetFastClearEnable
= true;
815 unreachable("Invalid fast clear op");
819 blorp_emit(batch
, GENX(3DSTATE_PS_EXTRA
), psx
) {
821 psx
.PixelShaderValid
= true;
822 psx
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
823 psx
.PixelShaderIsPerSample
= prog_data
->persample_dispatch
;
826 if (params
->src
.enabled
)
827 psx
.PixelShaderKillsPixel
= true;
832 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
833 switch (params
->hiz_op
) {
834 case ISL_AUX_OP_FAST_CLEAR
:
835 wm
.DepthBufferClear
= true;
837 case ISL_AUX_OP_FULL_RESOLVE
:
838 wm
.DepthBufferResolveEnable
= true;
840 case ISL_AUX_OP_AMBIGUATE
:
841 wm
.HierarchicalDepthBufferResolveEnable
= true;
843 case ISL_AUX_OP_NONE
:
846 unreachable("not reached");
850 wm
.ThreadDispatchEnable
= true;
852 if (params
->src
.enabled
)
853 wm
.PixelShaderKillsPixel
= true;
855 if (params
->num_samples
> 1) {
856 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
857 wm
.MultisampleDispatchMode
=
858 (prog_data
&& prog_data
->persample_dispatch
) ?
859 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
861 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
862 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
866 blorp_emit(batch
, GENX(3DSTATE_PS
), ps
) {
867 ps
.MaximumNumberofThreads
=
868 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
875 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
876 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
878 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
879 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 0);
880 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
881 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 1);
882 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
883 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 2);
885 ps
.KernelStartPointer0
= params
->wm_prog_kernel
+
886 brw_wm_prog_data_prog_offset(prog_data
, ps
, 0);
887 ps
.KernelStartPointer1
= params
->wm_prog_kernel
+
888 brw_wm_prog_data_prog_offset(prog_data
, ps
, 1);
889 ps
.KernelStartPointer2
= params
->wm_prog_kernel
+
890 brw_wm_prog_data_prog_offset(prog_data
, ps
, 2);
892 ps
.AttributeEnable
= prog_data
->num_varying_inputs
> 0;
894 /* Gen7 hardware gets angry if we don't enable at least one dispatch
895 * mode, so just enable 16-pixel dispatch if we don't have a program.
897 ps
._16PixelDispatchEnable
= true;
900 if (params
->src
.enabled
)
901 ps
.SamplerCount
= 1; /* Up to 4 samplers */
903 switch (params
->fast_clear_op
) {
904 case ISL_AUX_OP_NONE
:
906 case ISL_AUX_OP_FULL_RESOLVE
:
907 ps
.RenderTargetResolveEnable
= true;
909 case ISL_AUX_OP_FAST_CLEAR
:
910 ps
.RenderTargetFastClearEnable
= true;
913 unreachable("Invalid fast clear op");
917 #else /* GEN_GEN <= 6 */
919 blorp_emit(batch
, GENX(3DSTATE_WM
), wm
) {
920 wm
.MaximumNumberofThreads
=
921 batch
->blorp
->isl_dev
->info
->max_wm_threads
- 1;
923 switch (params
->hiz_op
) {
924 case ISL_AUX_OP_FAST_CLEAR
:
925 wm
.DepthBufferClear
= true;
927 case ISL_AUX_OP_FULL_RESOLVE
:
928 wm
.DepthBufferResolveEnable
= true;
930 case ISL_AUX_OP_AMBIGUATE
:
931 wm
.HierarchicalDepthBufferResolveEnable
= true;
933 case ISL_AUX_OP_NONE
:
936 unreachable("not reached");
940 wm
.ThreadDispatchEnable
= true;
942 wm
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
943 wm
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
945 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
946 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, wm
, 0);
947 wm
.DispatchGRFStartRegisterForConstantSetupData1
=
948 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, wm
, 1);
949 wm
.DispatchGRFStartRegisterForConstantSetupData2
=
950 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, wm
, 2);
952 wm
.KernelStartPointer0
= params
->wm_prog_kernel
+
953 brw_wm_prog_data_prog_offset(prog_data
, wm
, 0);
954 wm
.KernelStartPointer1
= params
->wm_prog_kernel
+
955 brw_wm_prog_data_prog_offset(prog_data
, wm
, 1);
956 wm
.KernelStartPointer2
= params
->wm_prog_kernel
+
957 brw_wm_prog_data_prog_offset(prog_data
, wm
, 2);
959 wm
.NumberofSFOutputAttributes
= prog_data
->num_varying_inputs
;
962 if (params
->src
.enabled
) {
963 wm
.SamplerCount
= 1; /* Up to 4 samplers */
964 wm
.PixelShaderKillsPixel
= true; /* TODO: temporarily smash on */
967 if (params
->num_samples
> 1) {
968 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
969 wm
.MultisampleDispatchMode
=
970 (prog_data
&& prog_data
->persample_dispatch
) ?
971 MSDISPMODE_PERSAMPLE
: MSDISPMODE_PERPIXEL
;
973 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
974 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
982 blorp_emit_blend_state(struct blorp_batch
*batch
,
983 const struct blorp_params
*params
)
985 struct GENX(BLEND_STATE
) blend
;
986 memset(&blend
, 0, sizeof(blend
));
989 int size
= GENX(BLEND_STATE_length
) * 4;
990 size
+= GENX(BLEND_STATE_ENTRY_length
) * 4 * params
->num_draw_buffers
;
991 uint32_t *state
= blorp_alloc_dynamic_state(batch
, size
, 64, &offset
);
992 uint32_t *pos
= state
;
994 GENX(BLEND_STATE_pack
)(NULL
, pos
, &blend
);
995 pos
+= GENX(BLEND_STATE_length
);
997 for (unsigned i
= 0; i
< params
->num_draw_buffers
; ++i
) {
998 struct GENX(BLEND_STATE_ENTRY
) entry
= {
999 .PreBlendColorClampEnable
= true,
1000 .PostBlendColorClampEnable
= true,
1001 .ColorClampRange
= COLORCLAMP_RTFORMAT
,
1003 .WriteDisableRed
= params
->color_write_disable
[0],
1004 .WriteDisableGreen
= params
->color_write_disable
[1],
1005 .WriteDisableBlue
= params
->color_write_disable
[2],
1006 .WriteDisableAlpha
= params
->color_write_disable
[3],
1008 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, pos
, &entry
);
1009 pos
+= GENX(BLEND_STATE_ENTRY_length
);
1012 blorp_flush_range(batch
, state
, size
);
1015 blorp_emit(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), sp
) {
1016 sp
.BlendStatePointer
= offset
;
1018 sp
.BlendStatePointerValid
= true;
1024 blorp_emit(batch
, GENX(3DSTATE_PS_BLEND
), ps_blend
) {
1025 ps_blend
.HasWriteableRT
= true;
1033 blorp_emit_color_calc_state(struct blorp_batch
*batch
,
1034 MAYBE_UNUSED
const struct blorp_params
*params
)
1037 blorp_emit_dynamic(batch
, GENX(COLOR_CALC_STATE
), cc
, 64, &offset
) {
1039 cc
.StencilReferenceValue
= params
->stencil_ref
;
1044 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), sp
) {
1045 sp
.ColorCalcStatePointer
= offset
;
1047 sp
.ColorCalcStatePointerValid
= true;
1056 blorp_emit_depth_stencil_state(struct blorp_batch
*batch
,
1057 const struct blorp_params
*params
)
1060 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) ds
= {
1061 GENX(3DSTATE_WM_DEPTH_STENCIL_header
),
1064 struct GENX(DEPTH_STENCIL_STATE
) ds
= { 0 };
1067 if (params
->depth
.enabled
) {
1068 ds
.DepthBufferWriteEnable
= true;
1070 switch (params
->hiz_op
) {
1071 case ISL_AUX_OP_NONE
:
1072 ds
.DepthTestEnable
= true;
1073 ds
.DepthTestFunction
= COMPAREFUNCTION_ALWAYS
;
1076 /* See the following sections of the Sandy Bridge PRM, Volume 2, Part1:
1077 * - 7.5.3.1 Depth Buffer Clear
1078 * - 7.5.3.2 Depth Buffer Resolve
1079 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
1081 case ISL_AUX_OP_FULL_RESOLVE
:
1082 ds
.DepthTestEnable
= true;
1083 ds
.DepthTestFunction
= COMPAREFUNCTION_NEVER
;
1086 case ISL_AUX_OP_FAST_CLEAR
:
1087 case ISL_AUX_OP_AMBIGUATE
:
1088 ds
.DepthTestEnable
= false;
1090 case ISL_AUX_OP_PARTIAL_RESOLVE
:
1091 unreachable("Invalid HIZ op");
1095 if (params
->stencil
.enabled
) {
1096 ds
.StencilBufferWriteEnable
= true;
1097 ds
.StencilTestEnable
= true;
1098 ds
.DoubleSidedStencilEnable
= false;
1100 ds
.StencilTestFunction
= COMPAREFUNCTION_ALWAYS
;
1101 ds
.StencilPassDepthPassOp
= STENCILOP_REPLACE
;
1103 ds
.StencilWriteMask
= params
->stencil_mask
;
1105 ds
.StencilReferenceValue
= params
->stencil_ref
;
1110 uint32_t offset
= 0;
1111 uint32_t *dw
= blorp_emit_dwords(batch
,
1112 GENX(3DSTATE_WM_DEPTH_STENCIL_length
));
1116 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, dw
, &ds
);
1119 void *state
= blorp_alloc_dynamic_state(batch
,
1120 GENX(DEPTH_STENCIL_STATE_length
) * 4,
1122 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, state
, &ds
);
1123 blorp_flush_range(batch
, state
, GENX(DEPTH_STENCIL_STATE_length
) * 4);
1127 blorp_emit(batch
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), sp
) {
1128 sp
.PointertoDEPTH_STENCIL_STATE
= offset
;
1136 blorp_emit_3dstate_multisample(struct blorp_batch
*batch
,
1137 const struct blorp_params
*params
)
1139 blorp_emit(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
1140 ms
.NumberofMultisamples
= __builtin_ffs(params
->num_samples
) - 1;
1143 /* The PRM says that this bit is valid only for DX9:
1145 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
1146 * should not have any effect by setting or not setting this bit.
1148 ms
.PixelPositionOffsetEnable
= false;
1151 switch (params
->num_samples
) {
1153 GEN_SAMPLE_POS_1X(ms
.Sample
);
1156 GEN_SAMPLE_POS_2X(ms
.Sample
);
1159 GEN_SAMPLE_POS_4X(ms
.Sample
);
1162 GEN_SAMPLE_POS_8X(ms
.Sample
);
1168 GEN_SAMPLE_POS_4X(ms
.Sample
);
1170 ms
.PixelLocation
= CENTER
;
1175 blorp_emit_pipeline(struct blorp_batch
*batch
,
1176 const struct blorp_params
*params
)
1178 uint32_t blend_state_offset
= 0;
1179 uint32_t color_calc_state_offset
;
1180 uint32_t depth_stencil_state_offset
;
1182 emit_urb_config(batch
, params
);
1184 if (params
->wm_prog_data
) {
1185 blend_state_offset
= blorp_emit_blend_state(batch
, params
);
1187 color_calc_state_offset
= blorp_emit_color_calc_state(batch
, params
);
1188 depth_stencil_state_offset
= blorp_emit_depth_stencil_state(batch
, params
);
1191 /* 3DSTATE_CC_STATE_POINTERS
1193 * The pointer offsets are relative to
1194 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
1196 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
1198 * The dynamic state emit helpers emit their own STATE_POINTERS packets on
1199 * gen7+. However, on gen6 and earlier, they're all lumpped together in
1200 * one CC_STATE_POINTERS packet so we have to emit that here.
1202 blorp_emit(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), cc
) {
1203 cc
.BLEND_STATEChange
= true;
1204 cc
.ColorCalcStatePointerValid
= true;
1205 cc
.DEPTH_STENCIL_STATEChange
= true;
1206 cc
.PointertoBLEND_STATE
= blend_state_offset
;
1207 cc
.ColorCalcStatePointer
= color_calc_state_offset
;
1208 cc
.PointertoDEPTH_STENCIL_STATE
= depth_stencil_state_offset
;
1211 (void)blend_state_offset
;
1212 (void)color_calc_state_offset
;
1213 (void)depth_stencil_state_offset
;
1216 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_VS
), vs
);
1218 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_HS
), hs
);
1219 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_DS
), DS
);
1221 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_GS
), gs
);
1222 blorp_emit(batch
, GENX(3DSTATE_CONSTANT_PS
), ps
);
1224 if (params
->src
.enabled
)
1225 blorp_emit_sampler_state(batch
);
1227 blorp_emit_3dstate_multisample(batch
, params
);
1229 blorp_emit(batch
, GENX(3DSTATE_SAMPLE_MASK
), mask
) {
1230 mask
.SampleMask
= (1 << params
->num_samples
) - 1;
1233 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1234 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1236 * [DevSNB] A pipeline flush must be programmed prior to a
1237 * 3DSTATE_VS command that causes the VS Function Enable to
1238 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
1239 * command with CS stall bit set and a post sync operation.
1241 * We've already done one at the start of the BLORP operation.
1243 blorp_emit_vs_config(batch
, params
);
1245 blorp_emit(batch
, GENX(3DSTATE_HS
), hs
);
1246 blorp_emit(batch
, GENX(3DSTATE_TE
), te
);
1247 blorp_emit(batch
, GENX(3DSTATE_DS
), DS
);
1248 blorp_emit(batch
, GENX(3DSTATE_STREAMOUT
), so
);
1250 blorp_emit(batch
, GENX(3DSTATE_GS
), gs
);
1252 blorp_emit(batch
, GENX(3DSTATE_CLIP
), clip
) {
1253 clip
.PerspectiveDivideDisable
= true;
1256 blorp_emit_sf_config(batch
, params
);
1257 blorp_emit_ps_config(batch
, params
);
1259 blorp_emit_cc_viewport(batch
);
1262 /******** This is the end of the pipeline setup code ********/
1264 #endif /* GEN_GEN >= 6 */
1268 blorp_emit_memcpy(struct blorp_batch
*batch
,
1269 struct blorp_address dst
,
1270 struct blorp_address src
,
1273 assert(size
% 4 == 0);
1275 for (unsigned dw
= 0; dw
< size
; dw
+= 4) {
1277 blorp_emit(batch
, GENX(MI_COPY_MEM_MEM
), cp
) {
1278 cp
.DestinationMemoryAddress
= dst
;
1279 cp
.SourceMemoryAddress
= src
;
1282 /* IVB does not have a general purpose register for command streamer
1283 * commands. Therefore, we use an alternate temporary register.
1285 #define BLORP_TEMP_REG 0x2440 /* GEN7_3DPRIM_BASE_VERTEX */
1286 blorp_emit(batch
, GENX(MI_LOAD_REGISTER_MEM
), load
) {
1287 load
.RegisterAddress
= BLORP_TEMP_REG
;
1288 load
.MemoryAddress
= src
;
1290 blorp_emit(batch
, GENX(MI_STORE_REGISTER_MEM
), store
) {
1291 store
.RegisterAddress
= BLORP_TEMP_REG
;
1292 store
.MemoryAddress
= dst
;
1294 #undef BLORP_TEMP_REG
1303 blorp_emit_surface_state(struct blorp_batch
*batch
,
1304 const struct brw_blorp_surface_info
*surface
,
1306 void *state
, uint32_t state_offset
,
1307 const bool color_write_disables
[4],
1308 bool is_render_target
)
1310 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1311 struct isl_surf surf
= surface
->surf
;
1313 if (surf
.dim
== ISL_SURF_DIM_1D
&&
1314 surf
.dim_layout
== ISL_DIM_LAYOUT_GEN4_2D
) {
1315 assert(surf
.logical_level0_px
.height
== 1);
1316 surf
.dim
= ISL_SURF_DIM_2D
;
1319 /* Blorp doesn't support HiZ in any of the blit or slow-clear paths */
1320 enum isl_aux_usage aux_usage
= surface
->aux_usage
;
1321 if (aux_usage
== ISL_AUX_USAGE_HIZ
)
1322 aux_usage
= ISL_AUX_USAGE_NONE
;
1324 isl_channel_mask_t write_disable_mask
= 0;
1325 if (is_render_target
&& GEN_GEN
<= 5) {
1326 if (color_write_disables
[0])
1327 write_disable_mask
|= ISL_CHANNEL_RED_BIT
;
1328 if (color_write_disables
[1])
1329 write_disable_mask
|= ISL_CHANNEL_GREEN_BIT
;
1330 if (color_write_disables
[2])
1331 write_disable_mask
|= ISL_CHANNEL_BLUE_BIT
;
1332 if (color_write_disables
[3])
1333 write_disable_mask
|= ISL_CHANNEL_ALPHA_BIT
;
1336 const bool use_clear_address
=
1337 GEN_GEN
>= 10 && (surface
->clear_color_addr
.buffer
!= NULL
);
1339 isl_surf_fill_state(batch
->blorp
->isl_dev
, state
,
1340 .surf
= &surf
, .view
= &surface
->view
,
1341 .aux_surf
= &surface
->aux_surf
, .aux_usage
= aux_usage
,
1342 .mocs
= surface
->addr
.mocs
,
1343 .clear_color
= surface
->clear_color
,
1344 .use_clear_address
= use_clear_address
,
1345 .write_disables
= write_disable_mask
);
1347 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.addr_offset
,
1350 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
1351 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
1352 * used to store other information. This should be ok, however, because
1353 * surface buffer addresses are always 4K page alinged.
1355 assert((surface
->aux_addr
.offset
& 0xfff) == 0);
1356 uint32_t *aux_addr
= state
+ isl_dev
->ss
.aux_addr_offset
;
1357 blorp_surface_reloc(batch
, state_offset
+ isl_dev
->ss
.aux_addr_offset
,
1358 surface
->aux_addr
, *aux_addr
);
1361 if (surface
->clear_color_addr
.buffer
) {
1363 assert((surface
->clear_color_addr
.offset
& 0x3f) == 0);
1364 uint32_t *clear_addr
= state
+ isl_dev
->ss
.clear_color_state_offset
;
1365 blorp_surface_reloc(batch
, state_offset
+
1366 isl_dev
->ss
.clear_color_state_offset
,
1367 surface
->clear_color_addr
, *clear_addr
);
1369 if (op
== ISL_AUX_OP_FULL_RESOLVE
|| op
== ISL_AUX_OP_PARTIAL_RESOLVE
) {
1370 struct blorp_address dst_addr
= blorp_get_surface_base_address(batch
);
1371 dst_addr
.offset
+= state_offset
+ isl_dev
->ss
.clear_value_offset
;
1372 blorp_emit_memcpy(batch
, dst_addr
, surface
->clear_color_addr
,
1373 isl_dev
->ss
.clear_value_size
);
1376 unreachable("Fast clears are only supported on gen7+");
1380 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1384 blorp_emit_null_surface_state(struct blorp_batch
*batch
,
1385 const struct brw_blorp_surface_info
*surface
,
1388 struct GENX(RENDER_SURFACE_STATE
) ss
= {
1389 .SurfaceType
= SURFTYPE_NULL
,
1390 .SurfaceFormat
= ISL_FORMAT_R8G8B8A8_UNORM
,
1391 .Width
= surface
->surf
.logical_level0_px
.width
- 1,
1392 .Height
= surface
->surf
.logical_level0_px
.height
- 1,
1393 .MIPCountLOD
= surface
->view
.base_level
,
1394 .MinimumArrayElement
= surface
->view
.base_array_layer
,
1395 .Depth
= surface
->view
.array_len
- 1,
1396 .RenderTargetViewExtent
= surface
->view
.array_len
- 1,
1398 .NumberofMultisamples
= ffs(surface
->surf
.samples
) - 1,
1402 .SurfaceArray
= surface
->surf
.dim
!= ISL_SURF_DIM_3D
,
1408 .TiledSurface
= true,
1412 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &ss
);
1414 blorp_flush_range(batch
, state
, GENX(RENDER_SURFACE_STATE_length
) * 4);
1418 blorp_emit_surface_states(struct blorp_batch
*batch
,
1419 const struct blorp_params
*params
)
1421 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1422 uint32_t bind_offset
= 0, surface_offsets
[2];
1423 void *surface_maps
[2];
1425 MAYBE_UNUSED
bool has_indirect_clear_color
= false;
1426 if (params
->use_pre_baked_binding_table
) {
1427 bind_offset
= params
->pre_baked_binding_table_offset
;
1429 unsigned num_surfaces
= 1 + params
->src
.enabled
;
1430 blorp_alloc_binding_table(batch
, num_surfaces
,
1431 isl_dev
->ss
.size
, isl_dev
->ss
.align
,
1432 &bind_offset
, surface_offsets
, surface_maps
);
1434 if (params
->dst
.enabled
) {
1435 blorp_emit_surface_state(batch
, ¶ms
->dst
,
1436 params
->fast_clear_op
,
1437 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
],
1438 surface_offsets
[BLORP_RENDERBUFFER_BT_INDEX
],
1439 params
->color_write_disable
, true);
1440 if (params
->dst
.clear_color_addr
.buffer
!= NULL
)
1441 has_indirect_clear_color
= true;
1443 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1444 const struct brw_blorp_surface_info
*surface
=
1445 params
->depth
.enabled
? ¶ms
->depth
: ¶ms
->stencil
;
1446 blorp_emit_null_surface_state(batch
, surface
,
1447 surface_maps
[BLORP_RENDERBUFFER_BT_INDEX
]);
1450 if (params
->src
.enabled
) {
1451 blorp_emit_surface_state(batch
, ¶ms
->src
,
1452 params
->fast_clear_op
,
1453 surface_maps
[BLORP_TEXTURE_BT_INDEX
],
1454 surface_offsets
[BLORP_TEXTURE_BT_INDEX
],
1456 if (params
->src
.clear_color_addr
.buffer
!= NULL
)
1457 has_indirect_clear_color
= true;
1462 if (has_indirect_clear_color
) {
1463 /* Updating a surface state object may require that the state cache be
1464 * invalidated. From the SKL PRM, Shared Functions -> State -> State
1467 * Whenever the RENDER_SURFACE_STATE object in memory pointed to by
1468 * the Binding Table Pointer (BTP) and Binding Table Index (BTI) is
1469 * modified [...], the L1 state cache must be invalidated to ensure
1470 * the new surface or sampler state is fetched from system memory.
1472 blorp_emit(batch
, GENX(PIPE_CONTROL
), pipe
) {
1473 pipe
.StateCacheInvalidationEnable
= true;
1479 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), bt
);
1480 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_HS
), bt
);
1481 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_DS
), bt
);
1482 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_GS
), bt
);
1484 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS
), bt
) {
1485 bt
.PointertoPSBindingTable
= bind_offset
;
1488 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS
), bt
) {
1489 bt
.PSBindingTableChange
= true;
1490 bt
.PointertoPSBindingTable
= bind_offset
;
1493 blorp_emit(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS
), bt
) {
1494 bt
.PointertoPSBindingTable
= bind_offset
;
1500 blorp_emit_depth_stencil_config(struct blorp_batch
*batch
,
1501 const struct blorp_params
*params
)
1503 const struct isl_device
*isl_dev
= batch
->blorp
->isl_dev
;
1505 uint32_t *dw
= blorp_emit_dwords(batch
, isl_dev
->ds
.size
/ 4);
1509 struct isl_depth_stencil_hiz_emit_info info
= { };
1511 if (params
->depth
.enabled
) {
1512 info
.view
= ¶ms
->depth
.view
;
1513 info
.mocs
= params
->depth
.addr
.mocs
;
1514 } else if (params
->stencil
.enabled
) {
1515 info
.view
= ¶ms
->stencil
.view
;
1516 info
.mocs
= params
->stencil
.addr
.mocs
;
1519 if (params
->depth
.enabled
) {
1520 info
.depth_surf
= ¶ms
->depth
.surf
;
1522 info
.depth_address
=
1523 blorp_emit_reloc(batch
, dw
+ isl_dev
->ds
.depth_offset
/ 4,
1524 params
->depth
.addr
, 0);
1526 info
.hiz_usage
= params
->depth
.aux_usage
;
1527 if (info
.hiz_usage
== ISL_AUX_USAGE_HIZ
) {
1528 info
.hiz_surf
= ¶ms
->depth
.aux_surf
;
1530 struct blorp_address hiz_address
= params
->depth
.aux_addr
;
1532 /* Sandy bridge hardware does not technically support mipmapped HiZ.
1533 * However, we have a special layout that allows us to make it work
1534 * anyway by manually offsetting to the specified miplevel.
1536 assert(info
.hiz_surf
->dim_layout
== ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ
);
1538 isl_surf_get_image_offset_B_tile_sa(info
.hiz_surf
,
1539 info
.view
->base_level
, 0, 0,
1540 &offset_B
, NULL
, NULL
);
1541 hiz_address
.offset
+= offset_B
;
1545 blorp_emit_reloc(batch
, dw
+ isl_dev
->ds
.hiz_offset
/ 4,
1548 info
.depth_clear_value
= params
->depth
.clear_color
.f32
[0];
1552 if (params
->stencil
.enabled
) {
1553 info
.stencil_surf
= ¶ms
->stencil
.surf
;
1555 struct blorp_address stencil_address
= params
->stencil
.addr
;
1557 /* Sandy bridge hardware does not technically support mipmapped stencil.
1558 * However, we have a special layout that allows us to make it work
1559 * anyway by manually offsetting to the specified miplevel.
1561 assert(info
.stencil_surf
->dim_layout
== ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ
);
1563 isl_surf_get_image_offset_B_tile_sa(info
.stencil_surf
,
1564 info
.view
->base_level
, 0, 0,
1565 &offset_B
, NULL
, NULL
);
1566 stencil_address
.offset
+= offset_B
;
1569 info
.stencil_address
=
1570 blorp_emit_reloc(batch
, dw
+ isl_dev
->ds
.stencil_offset
/ 4,
1571 stencil_address
, 0);
1574 isl_emit_depth_stencil_hiz_s(isl_dev
, dw
, &info
);
1578 /* Emits the Optimized HiZ sequence specified in the BDW+ PRMs. The
1579 * depth/stencil buffer extents are ignored to handle APIs which perform
1580 * clearing operations without such information.
1583 blorp_emit_gen8_hiz_op(struct blorp_batch
*batch
,
1584 const struct blorp_params
*params
)
1586 /* We should be performing an operation on a depth or stencil buffer.
1588 assert(params
->depth
.enabled
|| params
->stencil
.enabled
);
1590 /* The stencil buffer should only be enabled if a fast clear operation is
1593 if (params
->stencil
.enabled
)
1594 assert(params
->hiz_op
== ISL_AUX_OP_FAST_CLEAR
);
1596 /* From the BDW PRM Volume 2, 3DSTATE_WM_HZ_OP:
1598 * 3DSTATE_MULTISAMPLE packet must be used prior to this packet to change
1599 * the Number of Multisamples. This packet must not be used to change
1600 * Number of Multisamples in a rendering sequence.
1602 * Since HIZ may be the first thing in a batch buffer, play safe and always
1603 * emit 3DSTATE_MULTISAMPLE.
1605 blorp_emit_3dstate_multisample(batch
, params
);
1607 /* If we can't alter the depth stencil config and multiple layers are
1608 * involved, the HiZ op will fail. This is because the op requires that a
1609 * new config is emitted for each additional layer.
1611 if (batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
) {
1612 assert(params
->num_layers
<= 1);
1614 blorp_emit_depth_stencil_config(batch
, params
);
1617 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
) {
1618 switch (params
->hiz_op
) {
1619 case ISL_AUX_OP_FAST_CLEAR
:
1620 hzp
.StencilBufferClearEnable
= params
->stencil
.enabled
;
1621 hzp
.DepthBufferClearEnable
= params
->depth
.enabled
;
1622 hzp
.StencilClearValue
= params
->stencil_ref
;
1623 hzp
.FullSurfaceDepthandStencilClear
= params
->full_surface_hiz_op
;
1625 case ISL_AUX_OP_FULL_RESOLVE
:
1626 assert(params
->full_surface_hiz_op
);
1627 hzp
.DepthBufferResolveEnable
= true;
1629 case ISL_AUX_OP_AMBIGUATE
:
1630 assert(params
->full_surface_hiz_op
);
1631 hzp
.HierarchicalDepthBufferResolveEnable
= true;
1633 case ISL_AUX_OP_PARTIAL_RESOLVE
:
1634 case ISL_AUX_OP_NONE
:
1635 unreachable("Invalid HIZ op");
1638 hzp
.NumberofMultisamples
= ffs(params
->num_samples
) - 1;
1639 hzp
.SampleMask
= 0xFFFF;
1641 /* Due to a hardware issue, this bit MBZ */
1642 assert(hzp
.ScissorRectangleEnable
== false);
1644 /* Contrary to the HW docs both fields are inclusive */
1645 hzp
.ClearRectangleXMin
= params
->x0
;
1646 hzp
.ClearRectangleYMin
= params
->y0
;
1648 /* Contrary to the HW docs both fields are exclusive */
1649 hzp
.ClearRectangleXMax
= params
->x1
;
1650 hzp
.ClearRectangleYMax
= params
->y1
;
1653 /* PIPE_CONTROL w/ all bits clear except for “Post-Sync Operation” must set
1654 * to “Write Immediate Data” enabled.
1656 blorp_emit(batch
, GENX(PIPE_CONTROL
), pc
) {
1657 pc
.PostSyncOperation
= WriteImmediateData
;
1658 pc
.Address
= blorp_get_workaround_page(batch
);
1661 blorp_emit(batch
, GENX(3DSTATE_WM_HZ_OP
), hzp
);
1666 blorp_update_clear_color(struct blorp_batch
*batch
,
1667 const struct brw_blorp_surface_info
*info
,
1670 if (info
->clear_color_addr
.buffer
&& op
== ISL_AUX_OP_FAST_CLEAR
) {
1672 for (int i
= 0; i
< 4; i
++) {
1673 blorp_emit(batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
1674 sdi
.Address
= info
->clear_color_addr
;
1675 sdi
.Address
.offset
+= i
* 4;
1676 sdi
.ImmediateData
= info
->clear_color
.u32
[i
];
1680 blorp_emit(batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
1681 sdi
.Address
= info
->clear_color_addr
;
1682 sdi
.ImmediateData
= ISL_CHANNEL_SELECT_RED
<< 25 |
1683 ISL_CHANNEL_SELECT_GREEN
<< 22 |
1684 ISL_CHANNEL_SELECT_BLUE
<< 19 |
1685 ISL_CHANNEL_SELECT_ALPHA
<< 16;
1686 if (isl_format_has_int_channel(info
->view
.format
)) {
1687 for (unsigned i
= 0; i
< 4; i
++) {
1688 assert(info
->clear_color
.u32
[i
] == 0 ||
1689 info
->clear_color
.u32
[i
] == 1);
1691 sdi
.ImmediateData
|= (info
->clear_color
.u32
[0] != 0) << 31;
1692 sdi
.ImmediateData
|= (info
->clear_color
.u32
[1] != 0) << 30;
1693 sdi
.ImmediateData
|= (info
->clear_color
.u32
[2] != 0) << 29;
1694 sdi
.ImmediateData
|= (info
->clear_color
.u32
[3] != 0) << 28;
1696 for (unsigned i
= 0; i
< 4; i
++) {
1697 assert(info
->clear_color
.f32
[i
] == 0.0f
||
1698 info
->clear_color
.f32
[i
] == 1.0f
);
1700 sdi
.ImmediateData
|= (info
->clear_color
.f32
[0] != 0.0f
) << 31;
1701 sdi
.ImmediateData
|= (info
->clear_color
.f32
[1] != 0.0f
) << 30;
1702 sdi
.ImmediateData
|= (info
->clear_color
.f32
[2] != 0.0f
) << 29;
1703 sdi
.ImmediateData
|= (info
->clear_color
.f32
[3] != 0.0f
) << 28;
1711 * \brief Execute a blit or render pass operation.
1713 * To execute the operation, this function manually constructs and emits a
1714 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1715 * constructing and after emitting the batch.
1717 * This function alters no GL state.
1720 blorp_exec(struct blorp_batch
*batch
, const struct blorp_params
*params
)
1722 if (!(batch
->flags
& BLORP_BATCH_NO_UPDATE_CLEAR_COLOR
)) {
1723 blorp_update_clear_color(batch
, ¶ms
->dst
, params
->fast_clear_op
);
1724 blorp_update_clear_color(batch
, ¶ms
->depth
, params
->hiz_op
);
1728 if (params
->hiz_op
!= ISL_AUX_OP_NONE
) {
1729 blorp_emit_gen8_hiz_op(batch
, params
);
1734 blorp_emit_vertex_buffers(batch
, params
);
1735 blorp_emit_vertex_elements(batch
, params
);
1737 blorp_emit_pipeline(batch
, params
);
1739 blorp_emit_surface_states(batch
, params
);
1741 if (!(batch
->flags
& BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
))
1742 blorp_emit_depth_stencil_config(batch
, params
);
1744 blorp_emit(batch
, GENX(3DPRIMITIVE
), prim
) {
1745 prim
.VertexAccessType
= SEQUENTIAL
;
1746 prim
.PrimitiveTopologyType
= _3DPRIM_RECTLIST
;
1748 prim
.PredicateEnable
= batch
->flags
& BLORP_BATCH_PREDICATE_ENABLE
;
1750 prim
.VertexCountPerInstance
= 3;
1751 prim
.InstanceCount
= params
->num_layers
;
1755 #endif /* BLORP_GENX_EXEC_H */