2 * Copyright © 2017 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 shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
26 * ============================= GENXML CODE =============================
27 * [This file is compiled once per generation.]
28 * =======================================================================
30 * This is the main state upload code.
32 * Gallium uses Constant State Objects, or CSOs, for most state. Large,
33 * complex, or highly reusable state can be created once, and bound and
34 * rebound multiple times. This is modeled with the pipe->create_*_state()
35 * and pipe->bind_*_state() hooks. Highly dynamic or inexpensive state is
36 * streamed out on the fly, via pipe->set_*_state() hooks.
38 * OpenGL involves frequently mutating context state, which is mirrored in
39 * core Mesa by highly mutable data structures. However, most applications
40 * typically draw the same things over and over - from frame to frame, most
41 * of the same objects are still visible and need to be redrawn. So, rather
42 * than inventing new state all the time, applications usually mutate to swap
43 * between known states that we've seen before.
45 * Gallium isolates us from this mutation by tracking API state, and
46 * distilling it into a set of Constant State Objects, or CSOs. Large,
47 * complex, or typically reusable state can be created once, then reused
48 * multiple times. Drivers can create and store their own associated data.
49 * This create/bind model corresponds to the pipe->create_*_state() and
50 * pipe->bind_*_state() driver hooks.
52 * Some state is cheap to create, or expected to be highly dynamic. Rather
53 * than creating and caching piles of CSOs for these, Gallium simply streams
54 * them out, via the pipe->set_*_state() driver hooks.
56 * To reduce draw time overhead, we try to compute as much state at create
57 * time as possible. Wherever possible, we translate the Gallium pipe state
58 * to 3DSTATE commands, and store those commands in the CSO. At draw time,
59 * we can simply memcpy them into a batch buffer.
61 * No hardware matches the abstraction perfectly, so some commands require
62 * information from multiple CSOs. In this case, we can store two copies
63 * of the packet (one in each CSO), and simply | together their DWords at
64 * draw time. Sometimes the second set is trivial (one or two fields), so
65 * we simply pack it at draw time.
67 * There are two main components in the file below. First, the CSO hooks
68 * create/bind/track state. The second are the draw-time upload functions,
69 * iris_upload_render_state() and iris_upload_compute_state(), which read
70 * the context state and emit the commands into the actual batch.
81 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
87 #include "pipe/p_defines.h"
88 #include "pipe/p_state.h"
89 #include "pipe/p_context.h"
90 #include "pipe/p_screen.h"
91 #include "util/u_dual_blend.h"
92 #include "util/u_inlines.h"
93 #include "util/format/u_format.h"
94 #include "util/u_framebuffer.h"
95 #include "util/u_transfer.h"
96 #include "util/u_upload_mgr.h"
97 #include "util/u_viewport.h"
98 #include "drm-uapi/i915_drm.h"
100 #include "intel/compiler/brw_compiler.h"
101 #include "intel/common/gen_aux_map.h"
102 #include "intel/common/gen_l3_config.h"
103 #include "intel/common/gen_sample_positions.h"
104 #include "iris_batch.h"
105 #include "iris_context.h"
106 #include "iris_defines.h"
107 #include "iris_pipe.h"
108 #include "iris_resource.h"
110 #include "iris_genx_macros.h"
111 #include "intel/common/gen_guardband.h"
114 mocs(const struct iris_bo
*bo
, const struct isl_device
*dev
)
116 return bo
&& bo
->external
? dev
->mocs
.external
: dev
->mocs
.internal
;
120 * Statically assert that PIPE_* enums match the hardware packets.
121 * (As long as they match, we don't need to translate them.)
123 UNUSED
static void pipe_asserts()
125 #define PIPE_ASSERT(x) STATIC_ASSERT((int)x)
127 /* pipe_logicop happens to match the hardware. */
128 PIPE_ASSERT(PIPE_LOGICOP_CLEAR
== LOGICOP_CLEAR
);
129 PIPE_ASSERT(PIPE_LOGICOP_NOR
== LOGICOP_NOR
);
130 PIPE_ASSERT(PIPE_LOGICOP_AND_INVERTED
== LOGICOP_AND_INVERTED
);
131 PIPE_ASSERT(PIPE_LOGICOP_COPY_INVERTED
== LOGICOP_COPY_INVERTED
);
132 PIPE_ASSERT(PIPE_LOGICOP_AND_REVERSE
== LOGICOP_AND_REVERSE
);
133 PIPE_ASSERT(PIPE_LOGICOP_INVERT
== LOGICOP_INVERT
);
134 PIPE_ASSERT(PIPE_LOGICOP_XOR
== LOGICOP_XOR
);
135 PIPE_ASSERT(PIPE_LOGICOP_NAND
== LOGICOP_NAND
);
136 PIPE_ASSERT(PIPE_LOGICOP_AND
== LOGICOP_AND
);
137 PIPE_ASSERT(PIPE_LOGICOP_EQUIV
== LOGICOP_EQUIV
);
138 PIPE_ASSERT(PIPE_LOGICOP_NOOP
== LOGICOP_NOOP
);
139 PIPE_ASSERT(PIPE_LOGICOP_OR_INVERTED
== LOGICOP_OR_INVERTED
);
140 PIPE_ASSERT(PIPE_LOGICOP_COPY
== LOGICOP_COPY
);
141 PIPE_ASSERT(PIPE_LOGICOP_OR_REVERSE
== LOGICOP_OR_REVERSE
);
142 PIPE_ASSERT(PIPE_LOGICOP_OR
== LOGICOP_OR
);
143 PIPE_ASSERT(PIPE_LOGICOP_SET
== LOGICOP_SET
);
145 /* pipe_blend_func happens to match the hardware. */
146 PIPE_ASSERT(PIPE_BLENDFACTOR_ONE
== BLENDFACTOR_ONE
);
147 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_COLOR
== BLENDFACTOR_SRC_COLOR
);
148 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA
== BLENDFACTOR_SRC_ALPHA
);
149 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_ALPHA
== BLENDFACTOR_DST_ALPHA
);
150 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_COLOR
== BLENDFACTOR_DST_COLOR
);
151 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
== BLENDFACTOR_SRC_ALPHA_SATURATE
);
152 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_COLOR
== BLENDFACTOR_CONST_COLOR
);
153 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_ALPHA
== BLENDFACTOR_CONST_ALPHA
);
154 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_COLOR
== BLENDFACTOR_SRC1_COLOR
);
155 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_ALPHA
== BLENDFACTOR_SRC1_ALPHA
);
156 PIPE_ASSERT(PIPE_BLENDFACTOR_ZERO
== BLENDFACTOR_ZERO
);
157 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_COLOR
== BLENDFACTOR_INV_SRC_COLOR
);
158 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_ALPHA
== BLENDFACTOR_INV_SRC_ALPHA
);
159 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_ALPHA
== BLENDFACTOR_INV_DST_ALPHA
);
160 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_COLOR
== BLENDFACTOR_INV_DST_COLOR
);
161 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_COLOR
== BLENDFACTOR_INV_CONST_COLOR
);
162 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_ALPHA
== BLENDFACTOR_INV_CONST_ALPHA
);
163 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_COLOR
== BLENDFACTOR_INV_SRC1_COLOR
);
164 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_ALPHA
== BLENDFACTOR_INV_SRC1_ALPHA
);
166 /* pipe_blend_func happens to match the hardware. */
167 PIPE_ASSERT(PIPE_BLEND_ADD
== BLENDFUNCTION_ADD
);
168 PIPE_ASSERT(PIPE_BLEND_SUBTRACT
== BLENDFUNCTION_SUBTRACT
);
169 PIPE_ASSERT(PIPE_BLEND_REVERSE_SUBTRACT
== BLENDFUNCTION_REVERSE_SUBTRACT
);
170 PIPE_ASSERT(PIPE_BLEND_MIN
== BLENDFUNCTION_MIN
);
171 PIPE_ASSERT(PIPE_BLEND_MAX
== BLENDFUNCTION_MAX
);
173 /* pipe_stencil_op happens to match the hardware. */
174 PIPE_ASSERT(PIPE_STENCIL_OP_KEEP
== STENCILOP_KEEP
);
175 PIPE_ASSERT(PIPE_STENCIL_OP_ZERO
== STENCILOP_ZERO
);
176 PIPE_ASSERT(PIPE_STENCIL_OP_REPLACE
== STENCILOP_REPLACE
);
177 PIPE_ASSERT(PIPE_STENCIL_OP_INCR
== STENCILOP_INCRSAT
);
178 PIPE_ASSERT(PIPE_STENCIL_OP_DECR
== STENCILOP_DECRSAT
);
179 PIPE_ASSERT(PIPE_STENCIL_OP_INCR_WRAP
== STENCILOP_INCR
);
180 PIPE_ASSERT(PIPE_STENCIL_OP_DECR_WRAP
== STENCILOP_DECR
);
181 PIPE_ASSERT(PIPE_STENCIL_OP_INVERT
== STENCILOP_INVERT
);
183 /* pipe_sprite_coord_mode happens to match 3DSTATE_SBE */
184 PIPE_ASSERT(PIPE_SPRITE_COORD_UPPER_LEFT
== UPPERLEFT
);
185 PIPE_ASSERT(PIPE_SPRITE_COORD_LOWER_LEFT
== LOWERLEFT
);
190 translate_prim_type(enum pipe_prim_type prim
, uint8_t verts_per_patch
)
192 static const unsigned map
[] = {
193 [PIPE_PRIM_POINTS
] = _3DPRIM_POINTLIST
,
194 [PIPE_PRIM_LINES
] = _3DPRIM_LINELIST
,
195 [PIPE_PRIM_LINE_LOOP
] = _3DPRIM_LINELOOP
,
196 [PIPE_PRIM_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
197 [PIPE_PRIM_TRIANGLES
] = _3DPRIM_TRILIST
,
198 [PIPE_PRIM_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
199 [PIPE_PRIM_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
200 [PIPE_PRIM_QUADS
] = _3DPRIM_QUADLIST
,
201 [PIPE_PRIM_QUAD_STRIP
] = _3DPRIM_QUADSTRIP
,
202 [PIPE_PRIM_POLYGON
] = _3DPRIM_POLYGON
,
203 [PIPE_PRIM_LINES_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
204 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
205 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
206 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
207 [PIPE_PRIM_PATCHES
] = _3DPRIM_PATCHLIST_1
- 1,
210 return map
[prim
] + (prim
== PIPE_PRIM_PATCHES
? verts_per_patch
: 0);
214 translate_compare_func(enum pipe_compare_func pipe_func
)
216 static const unsigned map
[] = {
217 [PIPE_FUNC_NEVER
] = COMPAREFUNCTION_NEVER
,
218 [PIPE_FUNC_LESS
] = COMPAREFUNCTION_LESS
,
219 [PIPE_FUNC_EQUAL
] = COMPAREFUNCTION_EQUAL
,
220 [PIPE_FUNC_LEQUAL
] = COMPAREFUNCTION_LEQUAL
,
221 [PIPE_FUNC_GREATER
] = COMPAREFUNCTION_GREATER
,
222 [PIPE_FUNC_NOTEQUAL
] = COMPAREFUNCTION_NOTEQUAL
,
223 [PIPE_FUNC_GEQUAL
] = COMPAREFUNCTION_GEQUAL
,
224 [PIPE_FUNC_ALWAYS
] = COMPAREFUNCTION_ALWAYS
,
226 return map
[pipe_func
];
230 translate_shadow_func(enum pipe_compare_func pipe_func
)
232 /* Gallium specifies the result of shadow comparisons as:
234 * 1 if ref <op> texel,
239 * 0 if texel <op> ref,
242 * So we need to flip the operator and also negate.
244 static const unsigned map
[] = {
245 [PIPE_FUNC_NEVER
] = PREFILTEROPALWAYS
,
246 [PIPE_FUNC_LESS
] = PREFILTEROPLEQUAL
,
247 [PIPE_FUNC_EQUAL
] = PREFILTEROPNOTEQUAL
,
248 [PIPE_FUNC_LEQUAL
] = PREFILTEROPLESS
,
249 [PIPE_FUNC_GREATER
] = PREFILTEROPGEQUAL
,
250 [PIPE_FUNC_NOTEQUAL
] = PREFILTEROPEQUAL
,
251 [PIPE_FUNC_GEQUAL
] = PREFILTEROPGREATER
,
252 [PIPE_FUNC_ALWAYS
] = PREFILTEROPNEVER
,
254 return map
[pipe_func
];
258 translate_cull_mode(unsigned pipe_face
)
260 static const unsigned map
[4] = {
261 [PIPE_FACE_NONE
] = CULLMODE_NONE
,
262 [PIPE_FACE_FRONT
] = CULLMODE_FRONT
,
263 [PIPE_FACE_BACK
] = CULLMODE_BACK
,
264 [PIPE_FACE_FRONT_AND_BACK
] = CULLMODE_BOTH
,
266 return map
[pipe_face
];
270 translate_fill_mode(unsigned pipe_polymode
)
272 static const unsigned map
[4] = {
273 [PIPE_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
274 [PIPE_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
275 [PIPE_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
276 [PIPE_POLYGON_MODE_FILL_RECTANGLE
] = FILL_MODE_SOLID
,
278 return map
[pipe_polymode
];
282 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip
)
284 static const unsigned map
[] = {
285 [PIPE_TEX_MIPFILTER_NEAREST
] = MIPFILTER_NEAREST
,
286 [PIPE_TEX_MIPFILTER_LINEAR
] = MIPFILTER_LINEAR
,
287 [PIPE_TEX_MIPFILTER_NONE
] = MIPFILTER_NONE
,
289 return map
[pipe_mip
];
293 translate_wrap(unsigned pipe_wrap
)
295 static const unsigned map
[] = {
296 [PIPE_TEX_WRAP_REPEAT
] = TCM_WRAP
,
297 [PIPE_TEX_WRAP_CLAMP
] = TCM_HALF_BORDER
,
298 [PIPE_TEX_WRAP_CLAMP_TO_EDGE
] = TCM_CLAMP
,
299 [PIPE_TEX_WRAP_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
300 [PIPE_TEX_WRAP_MIRROR_REPEAT
] = TCM_MIRROR
,
301 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
303 /* These are unsupported. */
304 [PIPE_TEX_WRAP_MIRROR_CLAMP
] = -1,
305 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
] = -1,
307 return map
[pipe_wrap
];
311 * Allocate space for some indirect state.
313 * Return a pointer to the map (to fill it out) and a state ref (for
314 * referring to the state in GPU commands).
317 upload_state(struct u_upload_mgr
*uploader
,
318 struct iris_state_ref
*ref
,
323 u_upload_alloc(uploader
, 0, size
, alignment
, &ref
->offset
, &ref
->res
, &p
);
328 * Stream out temporary/short-lived state.
330 * This allocates space, pins the BO, and includes the BO address in the
331 * returned offset (which works because all state lives in 32-bit memory
335 stream_state(struct iris_batch
*batch
,
336 struct u_upload_mgr
*uploader
,
337 struct pipe_resource
**out_res
,
340 uint32_t *out_offset
)
344 u_upload_alloc(uploader
, 0, size
, alignment
, out_offset
, out_res
, &ptr
);
346 struct iris_bo
*bo
= iris_resource_bo(*out_res
);
347 iris_use_pinned_bo(batch
, bo
, false);
349 *out_offset
+= iris_bo_offset_from_base_address(bo
);
351 iris_record_state_size(batch
->state_sizes
, *out_offset
, size
);
357 * stream_state() + memcpy.
360 emit_state(struct iris_batch
*batch
,
361 struct u_upload_mgr
*uploader
,
362 struct pipe_resource
**out_res
,
369 stream_state(batch
, uploader
, out_res
, size
, alignment
, &offset
);
372 memcpy(map
, data
, size
);
378 * Did field 'x' change between 'old_cso' and 'new_cso'?
380 * (If so, we may want to set some dirty flags.)
382 #define cso_changed(x) (!old_cso || (old_cso->x != new_cso->x))
383 #define cso_changed_memcmp(x) \
384 (!old_cso || memcmp(old_cso->x, new_cso->x, sizeof(old_cso->x)) != 0)
387 flush_before_state_base_change(struct iris_batch
*batch
)
389 /* Flush before emitting STATE_BASE_ADDRESS.
391 * This isn't documented anywhere in the PRM. However, it seems to be
392 * necessary prior to changing the surface state base adress. We've
393 * seen issues in Vulkan where we get GPU hangs when using multi-level
394 * command buffers which clear depth, reset state base address, and then
397 * Normally, in GL, we would trust the kernel to do sufficient stalls
398 * and flushes prior to executing our batch. However, it doesn't seem
399 * as if the kernel's flushing is always sufficient and we don't want to
402 * We make this an end-of-pipe sync instead of a normal flush because we
403 * do not know the current status of the GPU. On Haswell at least,
404 * having a fast-clear operation in flight at the same time as a normal
405 * rendering operation can cause hangs. Since the kernel's flushing is
406 * insufficient, we need to ensure that any rendering operations from
407 * other processes are definitely complete before we try to do our own
408 * rendering. It's a bit of a big hammer but it appears to work.
410 iris_emit_end_of_pipe_sync(batch
,
411 "change STATE_BASE_ADDRESS (flushes)",
412 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
413 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
414 PIPE_CONTROL_DATA_CACHE_FLUSH
);
418 flush_after_state_base_change(struct iris_batch
*batch
)
420 /* After re-setting the surface state base address, we have to do some
421 * cache flusing so that the sampler engine will pick up the new
422 * SURFACE_STATE objects and binding tables. From the Broadwell PRM,
423 * Shared Function > 3D Sampler > State > State Caching (page 96):
425 * Coherency with system memory in the state cache, like the texture
426 * cache is handled partially by software. It is expected that the
427 * command stream or shader will issue Cache Flush operation or
428 * Cache_Flush sampler message to ensure that the L1 cache remains
429 * coherent with system memory.
433 * Whenever the value of the Dynamic_State_Base_Addr,
434 * Surface_State_Base_Addr are altered, the L1 state cache must be
435 * invalidated to ensure the new surface or sampler state is fetched
436 * from system memory.
438 * The PIPE_CONTROL command has a "State Cache Invalidation Enable" bit
439 * which, according the PIPE_CONTROL instruction documentation in the
442 * Setting this bit is independent of any other bit in this packet.
443 * This bit controls the invalidation of the L1 and L2 state caches
444 * at the top of the pipe i.e. at the parsing time.
446 * Unfortunately, experimentation seems to indicate that state cache
447 * invalidation through a PIPE_CONTROL does nothing whatsoever in
448 * regards to surface state and binding tables. In stead, it seems that
449 * invalidating the texture cache is what is actually needed.
451 * XXX: As far as we have been able to determine through
452 * experimentation, shows that flush the texture cache appears to be
453 * sufficient. The theory here is that all of the sampling/rendering
454 * units cache the binding table in the texture cache. However, we have
455 * yet to be able to actually confirm this.
457 iris_emit_end_of_pipe_sync(batch
,
458 "change STATE_BASE_ADDRESS (invalidates)",
459 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
460 PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
461 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
465 _iris_emit_lri(struct iris_batch
*batch
, uint32_t reg
, uint32_t val
)
467 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
468 lri
.RegisterOffset
= reg
;
472 #define iris_emit_lri(b, r, v) _iris_emit_lri(b, GENX(r##_num), v)
475 _iris_emit_lrr(struct iris_batch
*batch
, uint32_t dst
, uint32_t src
)
477 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_REG
), lrr
) {
478 lrr
.SourceRegisterAddress
= src
;
479 lrr
.DestinationRegisterAddress
= dst
;
484 iris_load_register_reg32(struct iris_batch
*batch
, uint32_t dst
,
487 _iris_emit_lrr(batch
, dst
, src
);
491 iris_load_register_reg64(struct iris_batch
*batch
, uint32_t dst
,
494 _iris_emit_lrr(batch
, dst
, src
);
495 _iris_emit_lrr(batch
, dst
+ 4, src
+ 4);
499 iris_load_register_imm32(struct iris_batch
*batch
, uint32_t reg
,
502 _iris_emit_lri(batch
, reg
, val
);
506 iris_load_register_imm64(struct iris_batch
*batch
, uint32_t reg
,
509 _iris_emit_lri(batch
, reg
+ 0, val
& 0xffffffff);
510 _iris_emit_lri(batch
, reg
+ 4, val
>> 32);
514 * Emit MI_LOAD_REGISTER_MEM to load a 32-bit MMIO register from a buffer.
517 iris_load_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
518 struct iris_bo
*bo
, uint32_t offset
)
520 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
521 lrm
.RegisterAddress
= reg
;
522 lrm
.MemoryAddress
= ro_bo(bo
, offset
);
527 * Load a 64-bit value from a buffer into a MMIO register via
528 * two MI_LOAD_REGISTER_MEM commands.
531 iris_load_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
532 struct iris_bo
*bo
, uint32_t offset
)
534 iris_load_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0);
535 iris_load_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4);
539 iris_store_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
540 struct iris_bo
*bo
, uint32_t offset
,
543 iris_emit_cmd(batch
, GENX(MI_STORE_REGISTER_MEM
), srm
) {
544 srm
.RegisterAddress
= reg
;
545 srm
.MemoryAddress
= rw_bo(bo
, offset
);
546 srm
.PredicateEnable
= predicated
;
551 iris_store_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
552 struct iris_bo
*bo
, uint32_t offset
,
555 iris_store_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0, predicated
);
556 iris_store_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4, predicated
);
560 iris_store_data_imm32(struct iris_batch
*batch
,
561 struct iris_bo
*bo
, uint32_t offset
,
564 iris_emit_cmd(batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
565 sdi
.Address
= rw_bo(bo
, offset
);
566 sdi
.ImmediateData
= imm
;
571 iris_store_data_imm64(struct iris_batch
*batch
,
572 struct iris_bo
*bo
, uint32_t offset
,
575 /* Can't use iris_emit_cmd because MI_STORE_DATA_IMM has a length of
576 * 2 in genxml but it's actually variable length and we need 5 DWords.
578 void *map
= iris_get_command_space(batch
, 4 * 5);
579 _iris_pack_command(batch
, GENX(MI_STORE_DATA_IMM
), map
, sdi
) {
580 sdi
.DWordLength
= 5 - 2;
581 sdi
.Address
= rw_bo(bo
, offset
);
582 sdi
.ImmediateData
= imm
;
587 iris_copy_mem_mem(struct iris_batch
*batch
,
588 struct iris_bo
*dst_bo
, uint32_t dst_offset
,
589 struct iris_bo
*src_bo
, uint32_t src_offset
,
592 /* MI_COPY_MEM_MEM operates on DWords. */
593 assert(bytes
% 4 == 0);
594 assert(dst_offset
% 4 == 0);
595 assert(src_offset
% 4 == 0);
597 for (unsigned i
= 0; i
< bytes
; i
+= 4) {
598 iris_emit_cmd(batch
, GENX(MI_COPY_MEM_MEM
), cp
) {
599 cp
.DestinationMemoryAddress
= rw_bo(dst_bo
, dst_offset
+ i
);
600 cp
.SourceMemoryAddress
= ro_bo(src_bo
, src_offset
+ i
);
606 emit_pipeline_select(struct iris_batch
*batch
, uint32_t pipeline
)
608 #if GEN_GEN >= 8 && GEN_GEN < 10
609 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
611 * Software must clear the COLOR_CALC_STATE Valid field in
612 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
613 * with Pipeline Select set to GPGPU.
615 * The internal hardware docs recommend the same workaround for Gen9
618 if (pipeline
== GPGPU
)
619 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), t
);
623 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
624 * PIPELINE_SELECT [DevBWR+]":
628 * Software must ensure all the write caches are flushed through a
629 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
630 * command to invalidate read only caches prior to programming
631 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode."
633 iris_emit_pipe_control_flush(batch
,
634 "workaround: PIPELINE_SELECT flushes (1/2)",
635 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
636 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
637 PIPE_CONTROL_DATA_CACHE_FLUSH
|
638 PIPE_CONTROL_CS_STALL
);
640 iris_emit_pipe_control_flush(batch
,
641 "workaround: PIPELINE_SELECT flushes (2/2)",
642 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
643 PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
644 PIPE_CONTROL_STATE_CACHE_INVALIDATE
|
645 PIPE_CONTROL_INSTRUCTION_INVALIDATE
);
647 iris_emit_cmd(batch
, GENX(PIPELINE_SELECT
), sel
) {
651 sel
.PipelineSelection
= pipeline
;
656 init_glk_barrier_mode(struct iris_batch
*batch
, uint32_t value
)
661 * "This chicken bit works around a hardware issue with barrier
662 * logic encountered when switching between GPGPU and 3D pipelines.
663 * To workaround the issue, this mode bit should be set after a
664 * pipeline is selected."
667 iris_pack_state(GENX(SLICE_COMMON_ECO_CHICKEN1
), ®_val
, reg
) {
668 reg
.GLKBarrierMode
= value
;
669 reg
.GLKBarrierModeMask
= 1;
671 iris_emit_lri(batch
, SLICE_COMMON_ECO_CHICKEN1
, reg_val
);
676 init_state_base_address(struct iris_batch
*batch
)
678 uint32_t mocs
= batch
->screen
->isl_dev
.mocs
.internal
;
679 flush_before_state_base_change(batch
);
681 /* We program most base addresses once at context initialization time.
682 * Each base address points at a 4GB memory zone, and never needs to
683 * change. See iris_bufmgr.h for a description of the memory zones.
685 * The one exception is Surface State Base Address, which needs to be
686 * updated occasionally. See iris_binder.c for the details there.
688 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
689 sba
.GeneralStateMOCS
= mocs
;
690 sba
.StatelessDataPortAccessMOCS
= mocs
;
691 sba
.DynamicStateMOCS
= mocs
;
692 sba
.IndirectObjectMOCS
= mocs
;
693 sba
.InstructionMOCS
= mocs
;
694 sba
.SurfaceStateMOCS
= mocs
;
696 sba
.GeneralStateBaseAddressModifyEnable
= true;
697 sba
.DynamicStateBaseAddressModifyEnable
= true;
698 sba
.IndirectObjectBaseAddressModifyEnable
= true;
699 sba
.InstructionBaseAddressModifyEnable
= true;
700 sba
.GeneralStateBufferSizeModifyEnable
= true;
701 sba
.DynamicStateBufferSizeModifyEnable
= true;
703 sba
.BindlessSurfaceStateBaseAddressModifyEnable
= true;
704 sba
.BindlessSurfaceStateMOCS
= mocs
;
706 sba
.IndirectObjectBufferSizeModifyEnable
= true;
707 sba
.InstructionBuffersizeModifyEnable
= true;
709 sba
.InstructionBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_SHADER_START
);
710 sba
.DynamicStateBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_DYNAMIC_START
);
712 sba
.GeneralStateBufferSize
= 0xfffff;
713 sba
.IndirectObjectBufferSize
= 0xfffff;
714 sba
.InstructionBufferSize
= 0xfffff;
715 sba
.DynamicStateBufferSize
= 0xfffff;
718 flush_after_state_base_change(batch
);
722 iris_emit_l3_config(struct iris_batch
*batch
, const struct gen_l3_config
*cfg
,
723 bool has_slm
, bool wants_dc_cache
)
728 #define L3_ALLOCATION_REG GENX(L3ALLOC)
729 #define L3_ALLOCATION_REG_num GENX(L3ALLOC_num)
731 #define L3_ALLOCATION_REG GENX(L3CNTLREG)
732 #define L3_ALLOCATION_REG_num GENX(L3CNTLREG_num)
735 iris_pack_state(L3_ALLOCATION_REG
, ®_val
, reg
) {
737 reg
.SLMEnable
= has_slm
;
740 /* WA_1406697149: Bit 9 "Error Detection Behavior Control" must be set
741 * in L3CNTLREG register. The default setting of the bit is not the
742 * desirable behavior.
744 reg
.ErrorDetectionBehaviorControl
= true;
745 reg
.UseFullWays
= true;
747 reg
.URBAllocation
= cfg
->n
[GEN_L3P_URB
];
748 reg
.ROAllocation
= cfg
->n
[GEN_L3P_RO
];
749 reg
.DCAllocation
= cfg
->n
[GEN_L3P_DC
];
750 reg
.AllAllocation
= cfg
->n
[GEN_L3P_ALL
];
752 _iris_emit_lri(batch
, L3_ALLOCATION_REG_num
, reg_val
);
756 iris_emit_default_l3_config(struct iris_batch
*batch
,
757 const struct gen_device_info
*devinfo
,
760 bool wants_dc_cache
= true;
761 bool has_slm
= compute
;
762 const struct gen_l3_weights w
=
763 gen_get_default_l3_weights(devinfo
, wants_dc_cache
, has_slm
);
764 const struct gen_l3_config
*cfg
= gen_get_l3_config(devinfo
, w
);
765 iris_emit_l3_config(batch
, cfg
, has_slm
, wants_dc_cache
);
768 #if GEN_GEN == 9 || GEN_GEN == 10
770 iris_enable_obj_preemption(struct iris_batch
*batch
, bool enable
)
774 /* A fixed function pipe flush is required before modifying this field */
775 iris_emit_end_of_pipe_sync(batch
, enable
? "enable preemption"
776 : "disable preemption",
777 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
779 /* enable object level preemption */
780 iris_pack_state(GENX(CS_CHICKEN1
), ®_val
, reg
) {
781 reg
.ReplayMode
= enable
;
782 reg
.ReplayModeMask
= true;
784 iris_emit_lri(batch
, CS_CHICKEN1
, reg_val
);
790 iris_upload_slice_hashing_state(struct iris_batch
*batch
)
792 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
793 int subslices_delta
=
794 devinfo
->ppipe_subslices
[0] - devinfo
->ppipe_subslices
[1];
795 if (subslices_delta
== 0)
798 struct iris_context
*ice
= NULL
;
799 ice
= container_of(batch
, ice
, batches
[IRIS_BATCH_RENDER
]);
800 assert(&ice
->batches
[IRIS_BATCH_RENDER
] == batch
);
802 unsigned size
= GENX(SLICE_HASH_TABLE_length
) * 4;
803 uint32_t hash_address
;
804 struct pipe_resource
*tmp
= NULL
;
806 stream_state(batch
, ice
->state
.dynamic_uploader
, &tmp
,
807 size
, 64, &hash_address
);
808 pipe_resource_reference(&tmp
, NULL
);
810 struct GENX(SLICE_HASH_TABLE
) table0
= {
812 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
813 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
814 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
815 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
816 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
817 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
818 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
819 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
820 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
821 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
822 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
823 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
824 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
825 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
826 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
827 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }
831 struct GENX(SLICE_HASH_TABLE
) table1
= {
833 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
834 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
835 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
836 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
837 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
838 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
839 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
840 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
841 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
842 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
843 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
844 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
845 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
846 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
847 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
848 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 }
852 const struct GENX(SLICE_HASH_TABLE
) *table
=
853 subslices_delta
< 0 ? &table0
: &table1
;
854 GENX(SLICE_HASH_TABLE_pack
)(NULL
, map
, table
);
856 iris_emit_cmd(batch
, GENX(3DSTATE_SLICE_TABLE_STATE_POINTERS
), ptr
) {
857 ptr
.SliceHashStatePointerValid
= true;
858 ptr
.SliceHashTableStatePointer
= hash_address
;
861 iris_emit_cmd(batch
, GENX(3DSTATE_3D_MODE
), mode
) {
862 mode
.SliceHashingTableEnable
= true;
868 iris_alloc_push_constants(struct iris_batch
*batch
)
870 /* For now, we set a static partitioning of the push constant area,
871 * assuming that all stages could be in use.
873 * TODO: Try lazily allocating the HS/DS/GS sections as needed, and
874 * see if that improves performance by offering more space to
875 * the VS/FS when those aren't in use. Also, try dynamically
876 * enabling/disabling it like i965 does. This would be more
877 * stalls and may not actually help; we don't know yet.
879 for (int i
= 0; i
<= MESA_SHADER_FRAGMENT
; i
++) {
880 iris_emit_cmd(batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
), alloc
) {
881 alloc
._3DCommandSubOpcode
= 18 + i
;
882 alloc
.ConstantBufferOffset
= 6 * i
;
883 alloc
.ConstantBufferSize
= i
== MESA_SHADER_FRAGMENT
? 8 : 6;
889 * Upload the initial GPU state for a render context.
891 * This sets some invariant state that needs to be programmed a particular
892 * way, but we never actually change.
895 iris_init_render_context(struct iris_batch
*batch
)
897 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
900 emit_pipeline_select(batch
, _3D
);
902 iris_emit_default_l3_config(batch
, devinfo
, false);
904 init_state_base_address(batch
);
907 iris_pack_state(GENX(CS_DEBUG_MODE2
), ®_val
, reg
) {
908 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
909 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
911 iris_emit_lri(batch
, CS_DEBUG_MODE2
, reg_val
);
913 iris_pack_state(GENX(INSTPM
), ®_val
, reg
) {
914 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
915 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
917 iris_emit_lri(batch
, INSTPM
, reg_val
);
921 iris_pack_state(GENX(CACHE_MODE_1
), ®_val
, reg
) {
922 reg
.FloatBlendOptimizationEnable
= true;
923 reg
.FloatBlendOptimizationEnableMask
= true;
924 reg
.PartialResolveDisableInVC
= true;
925 reg
.PartialResolveDisableInVCMask
= true;
927 iris_emit_lri(batch
, CACHE_MODE_1
, reg_val
);
929 if (devinfo
->is_geminilake
)
930 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_3D_HULL
);
934 iris_pack_state(GENX(SAMPLER_MODE
), ®_val
, reg
) {
935 reg
.HeaderlessMessageforPreemptableContexts
= 1;
936 reg
.HeaderlessMessageforPreemptableContextsMask
= 1;
938 iris_emit_lri(batch
, SAMPLER_MODE
, reg_val
);
940 /* Bit 1 must be set in HALF_SLICE_CHICKEN7. */
941 iris_pack_state(GENX(HALF_SLICE_CHICKEN7
), ®_val
, reg
) {
942 reg
.EnabledTexelOffsetPrecisionFix
= 1;
943 reg
.EnabledTexelOffsetPrecisionFixMask
= 1;
945 iris_emit_lri(batch
, HALF_SLICE_CHICKEN7
, reg_val
);
947 /* Hardware specification recommends disabling repacking for the
948 * compatibility with decompression mechanism in display controller.
950 if (devinfo
->disable_ccs_repack
) {
951 iris_pack_state(GENX(CACHE_MODE_0
), ®_val
, reg
) {
952 reg
.DisableRepackingforCompression
= true;
953 reg
.DisableRepackingforCompressionMask
= true;
955 iris_emit_lri(batch
, CACHE_MODE_0
, reg_val
);
958 iris_upload_slice_hashing_state(batch
);
961 /* 3DSTATE_DRAWING_RECTANGLE is non-pipelined, so we want to avoid
962 * changing it dynamically. We set it to the maximum size here, and
963 * instead include the render target dimensions in the viewport, so
964 * viewport extents clipping takes care of pruning stray geometry.
966 iris_emit_cmd(batch
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
967 rect
.ClippedDrawingRectangleXMax
= UINT16_MAX
;
968 rect
.ClippedDrawingRectangleYMax
= UINT16_MAX
;
971 /* Set the initial MSAA sample positions. */
972 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_PATTERN
), pat
) {
973 GEN_SAMPLE_POS_1X(pat
._1xSample
);
974 GEN_SAMPLE_POS_2X(pat
._2xSample
);
975 GEN_SAMPLE_POS_4X(pat
._4xSample
);
976 GEN_SAMPLE_POS_8X(pat
._8xSample
);
978 GEN_SAMPLE_POS_16X(pat
._16xSample
);
982 /* Use the legacy AA line coverage computation. */
983 iris_emit_cmd(batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
), foo
);
985 /* Disable chromakeying (it's for media) */
986 iris_emit_cmd(batch
, GENX(3DSTATE_WM_CHROMAKEY
), foo
);
988 /* We want regular rendering, not special HiZ operations. */
989 iris_emit_cmd(batch
, GENX(3DSTATE_WM_HZ_OP
), foo
);
991 /* No polygon stippling offsets are necessary. */
992 /* TODO: may need to set an offset for origin-UL framebuffers */
993 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), foo
);
995 iris_alloc_push_constants(batch
);
998 /* Gen11+ is enabled for us by the kernel. */
999 iris_enable_obj_preemption(batch
, true);
1004 iris_init_compute_context(struct iris_batch
*batch
)
1006 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
1008 emit_pipeline_select(batch
, GPGPU
);
1010 iris_emit_default_l3_config(batch
, devinfo
, true);
1012 init_state_base_address(batch
);
1015 if (devinfo
->is_geminilake
)
1016 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_GPGPU
);
1020 struct iris_vertex_buffer_state
{
1021 /** The VERTEX_BUFFER_STATE hardware structure. */
1022 uint32_t state
[GENX(VERTEX_BUFFER_STATE_length
)];
1024 /** The resource to source vertex data from. */
1025 struct pipe_resource
*resource
;
1030 struct iris_depth_buffer_state
{
1031 /* Depth/HiZ/Stencil related hardware packets. */
1032 uint32_t packets
[GENX(3DSTATE_DEPTH_BUFFER_length
) +
1033 GENX(3DSTATE_STENCIL_BUFFER_length
) +
1034 GENX(3DSTATE_HIER_DEPTH_BUFFER_length
) +
1035 GENX(3DSTATE_CLEAR_PARAMS_length
)];
1039 * Generation-specific context state (ice->state.genx->...).
1041 * Most state can go in iris_context directly, but these encode hardware
1042 * packets which vary by generation.
1044 struct iris_genx_state
{
1045 struct iris_vertex_buffer_state vertex_buffers
[33];
1046 uint32_t last_index_buffer
[GENX(3DSTATE_INDEX_BUFFER_length
)];
1048 struct iris_depth_buffer_state depth_buffer
;
1050 uint32_t so_buffers
[4 * GENX(3DSTATE_SO_BUFFER_length
)];
1053 bool pma_fix_enabled
;
1057 /* Is object level preemption enabled? */
1058 bool object_preemption
;
1063 struct brw_image_param image_param
[PIPE_MAX_SHADER_IMAGES
];
1065 } shaders
[MESA_SHADER_STAGES
];
1069 * The pipe->set_blend_color() driver hook.
1071 * This corresponds to our COLOR_CALC_STATE.
1074 iris_set_blend_color(struct pipe_context
*ctx
,
1075 const struct pipe_blend_color
*state
)
1077 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1079 /* Our COLOR_CALC_STATE is exactly pipe_blend_color, so just memcpy */
1080 memcpy(&ice
->state
.blend_color
, state
, sizeof(struct pipe_blend_color
));
1081 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
1085 * Gallium CSO for blend state (see pipe_blend_state).
1087 struct iris_blend_state
{
1088 /** Partial 3DSTATE_PS_BLEND */
1089 uint32_t ps_blend
[GENX(3DSTATE_PS_BLEND_length
)];
1091 /** Partial BLEND_STATE */
1092 uint32_t blend_state
[GENX(BLEND_STATE_length
) +
1093 BRW_MAX_DRAW_BUFFERS
* GENX(BLEND_STATE_ENTRY_length
)];
1095 bool alpha_to_coverage
; /* for shader key */
1097 /** Bitfield of whether blending is enabled for RT[i] - for aux resolves */
1098 uint8_t blend_enables
;
1100 /** Bitfield of whether color writes are enabled for RT[i] */
1101 uint8_t color_write_enables
;
1103 /** Does RT[0] use dual color blending? */
1104 bool dual_color_blending
;
1107 static enum pipe_blendfactor
1108 fix_blendfactor(enum pipe_blendfactor f
, bool alpha_to_one
)
1111 if (f
== PIPE_BLENDFACTOR_SRC1_ALPHA
)
1112 return PIPE_BLENDFACTOR_ONE
;
1114 if (f
== PIPE_BLENDFACTOR_INV_SRC1_ALPHA
)
1115 return PIPE_BLENDFACTOR_ZERO
;
1122 * The pipe->create_blend_state() driver hook.
1124 * Translates a pipe_blend_state into iris_blend_state.
1127 iris_create_blend_state(struct pipe_context
*ctx
,
1128 const struct pipe_blend_state
*state
)
1130 struct iris_blend_state
*cso
= malloc(sizeof(struct iris_blend_state
));
1131 uint32_t *blend_entry
= cso
->blend_state
+ GENX(BLEND_STATE_length
);
1133 cso
->blend_enables
= 0;
1134 cso
->color_write_enables
= 0;
1135 STATIC_ASSERT(BRW_MAX_DRAW_BUFFERS
<= 8);
1137 cso
->alpha_to_coverage
= state
->alpha_to_coverage
;
1139 bool indep_alpha_blend
= false;
1141 for (int i
= 0; i
< BRW_MAX_DRAW_BUFFERS
; i
++) {
1142 const struct pipe_rt_blend_state
*rt
=
1143 &state
->rt
[state
->independent_blend_enable
? i
: 0];
1145 enum pipe_blendfactor src_rgb
=
1146 fix_blendfactor(rt
->rgb_src_factor
, state
->alpha_to_one
);
1147 enum pipe_blendfactor src_alpha
=
1148 fix_blendfactor(rt
->alpha_src_factor
, state
->alpha_to_one
);
1149 enum pipe_blendfactor dst_rgb
=
1150 fix_blendfactor(rt
->rgb_dst_factor
, state
->alpha_to_one
);
1151 enum pipe_blendfactor dst_alpha
=
1152 fix_blendfactor(rt
->alpha_dst_factor
, state
->alpha_to_one
);
1154 if (rt
->rgb_func
!= rt
->alpha_func
||
1155 src_rgb
!= src_alpha
|| dst_rgb
!= dst_alpha
)
1156 indep_alpha_blend
= true;
1158 if (rt
->blend_enable
)
1159 cso
->blend_enables
|= 1u << i
;
1162 cso
->color_write_enables
|= 1u << i
;
1164 iris_pack_state(GENX(BLEND_STATE_ENTRY
), blend_entry
, be
) {
1165 be
.LogicOpEnable
= state
->logicop_enable
;
1166 be
.LogicOpFunction
= state
->logicop_func
;
1168 be
.PreBlendSourceOnlyClampEnable
= false;
1169 be
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
1170 be
.PreBlendColorClampEnable
= true;
1171 be
.PostBlendColorClampEnable
= true;
1173 be
.ColorBufferBlendEnable
= rt
->blend_enable
;
1175 be
.ColorBlendFunction
= rt
->rgb_func
;
1176 be
.AlphaBlendFunction
= rt
->alpha_func
;
1177 be
.SourceBlendFactor
= src_rgb
;
1178 be
.SourceAlphaBlendFactor
= src_alpha
;
1179 be
.DestinationBlendFactor
= dst_rgb
;
1180 be
.DestinationAlphaBlendFactor
= dst_alpha
;
1182 be
.WriteDisableRed
= !(rt
->colormask
& PIPE_MASK_R
);
1183 be
.WriteDisableGreen
= !(rt
->colormask
& PIPE_MASK_G
);
1184 be
.WriteDisableBlue
= !(rt
->colormask
& PIPE_MASK_B
);
1185 be
.WriteDisableAlpha
= !(rt
->colormask
& PIPE_MASK_A
);
1187 blend_entry
+= GENX(BLEND_STATE_ENTRY_length
);
1190 iris_pack_command(GENX(3DSTATE_PS_BLEND
), cso
->ps_blend
, pb
) {
1191 /* pb.HasWriteableRT is filled in at draw time.
1192 * pb.AlphaTestEnable is filled in at draw time.
1194 * pb.ColorBufferBlendEnable is filled in at draw time so we can avoid
1195 * setting it when dual color blending without an appropriate shader.
1198 pb
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
1199 pb
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
1201 pb
.SourceBlendFactor
=
1202 fix_blendfactor(state
->rt
[0].rgb_src_factor
, state
->alpha_to_one
);
1203 pb
.SourceAlphaBlendFactor
=
1204 fix_blendfactor(state
->rt
[0].alpha_src_factor
, state
->alpha_to_one
);
1205 pb
.DestinationBlendFactor
=
1206 fix_blendfactor(state
->rt
[0].rgb_dst_factor
, state
->alpha_to_one
);
1207 pb
.DestinationAlphaBlendFactor
=
1208 fix_blendfactor(state
->rt
[0].alpha_dst_factor
, state
->alpha_to_one
);
1211 iris_pack_state(GENX(BLEND_STATE
), cso
->blend_state
, bs
) {
1212 bs
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
1213 bs
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
1214 bs
.AlphaToOneEnable
= state
->alpha_to_one
;
1215 bs
.AlphaToCoverageDitherEnable
= state
->alpha_to_coverage
;
1216 bs
.ColorDitherEnable
= state
->dither
;
1217 /* bl.AlphaTestEnable and bs.AlphaTestFunction are filled in later. */
1220 cso
->dual_color_blending
= util_blend_state_is_dual(state
, 0);
1226 * The pipe->bind_blend_state() driver hook.
1228 * Bind a blending CSO and flag related dirty bits.
1231 iris_bind_blend_state(struct pipe_context
*ctx
, void *state
)
1233 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1234 struct iris_blend_state
*cso
= state
;
1236 ice
->state
.cso_blend
= cso
;
1237 ice
->state
.blend_enables
= cso
? cso
->blend_enables
: 0;
1239 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
;
1240 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1241 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1242 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_BLEND
];
1245 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
1249 * Return true if the FS writes to any color outputs which are not disabled
1250 * via color masking.
1253 has_writeable_rt(const struct iris_blend_state
*cso_blend
,
1254 const struct shader_info
*fs_info
)
1259 unsigned rt_outputs
= fs_info
->outputs_written
>> FRAG_RESULT_DATA0
;
1261 if (fs_info
->outputs_written
& BITFIELD64_BIT(FRAG_RESULT_COLOR
))
1262 rt_outputs
= (1 << BRW_MAX_DRAW_BUFFERS
) - 1;
1264 return cso_blend
->color_write_enables
& rt_outputs
;
1268 * Gallium CSO for depth, stencil, and alpha testing state.
1270 struct iris_depth_stencil_alpha_state
{
1271 /** Partial 3DSTATE_WM_DEPTH_STENCIL. */
1272 uint32_t wmds
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
1275 uint32_t depth_bounds
[GENX(3DSTATE_DEPTH_BOUNDS_length
)];
1278 /** Outbound to BLEND_STATE, 3DSTATE_PS_BLEND, COLOR_CALC_STATE. */
1279 struct pipe_alpha_state alpha
;
1281 /** Outbound to resolve and cache set tracking. */
1282 bool depth_writes_enabled
;
1283 bool stencil_writes_enabled
;
1285 /** Outbound to Gen8-9 PMA stall equations */
1286 bool depth_test_enabled
;
1290 * The pipe->create_depth_stencil_alpha_state() driver hook.
1292 * We encode most of 3DSTATE_WM_DEPTH_STENCIL, and just save off the alpha
1293 * testing state since we need pieces of it in a variety of places.
1296 iris_create_zsa_state(struct pipe_context
*ctx
,
1297 const struct pipe_depth_stencil_alpha_state
*state
)
1299 struct iris_depth_stencil_alpha_state
*cso
=
1300 malloc(sizeof(struct iris_depth_stencil_alpha_state
));
1302 bool two_sided_stencil
= state
->stencil
[1].enabled
;
1304 cso
->alpha
= state
->alpha
;
1305 cso
->depth_writes_enabled
= state
->depth
.writemask
;
1306 cso
->depth_test_enabled
= state
->depth
.enabled
;
1307 cso
->stencil_writes_enabled
=
1308 state
->stencil
[0].writemask
!= 0 ||
1309 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1311 /* The state tracker needs to optimize away EQUAL writes for us. */
1312 assert(!(state
->depth
.func
== PIPE_FUNC_EQUAL
&& state
->depth
.writemask
));
1314 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), cso
->wmds
, wmds
) {
1315 wmds
.StencilFailOp
= state
->stencil
[0].fail_op
;
1316 wmds
.StencilPassDepthFailOp
= state
->stencil
[0].zfail_op
;
1317 wmds
.StencilPassDepthPassOp
= state
->stencil
[0].zpass_op
;
1318 wmds
.StencilTestFunction
=
1319 translate_compare_func(state
->stencil
[0].func
);
1320 wmds
.BackfaceStencilFailOp
= state
->stencil
[1].fail_op
;
1321 wmds
.BackfaceStencilPassDepthFailOp
= state
->stencil
[1].zfail_op
;
1322 wmds
.BackfaceStencilPassDepthPassOp
= state
->stencil
[1].zpass_op
;
1323 wmds
.BackfaceStencilTestFunction
=
1324 translate_compare_func(state
->stencil
[1].func
);
1325 wmds
.DepthTestFunction
= translate_compare_func(state
->depth
.func
);
1326 wmds
.DoubleSidedStencilEnable
= two_sided_stencil
;
1327 wmds
.StencilTestEnable
= state
->stencil
[0].enabled
;
1328 wmds
.StencilBufferWriteEnable
=
1329 state
->stencil
[0].writemask
!= 0 ||
1330 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1331 wmds
.DepthTestEnable
= state
->depth
.enabled
;
1332 wmds
.DepthBufferWriteEnable
= state
->depth
.writemask
;
1333 wmds
.StencilTestMask
= state
->stencil
[0].valuemask
;
1334 wmds
.StencilWriteMask
= state
->stencil
[0].writemask
;
1335 wmds
.BackfaceStencilTestMask
= state
->stencil
[1].valuemask
;
1336 wmds
.BackfaceStencilWriteMask
= state
->stencil
[1].writemask
;
1337 /* wmds.[Backface]StencilReferenceValue are merged later */
1341 iris_pack_command(GENX(3DSTATE_DEPTH_BOUNDS
), cso
->depth_bounds
, depth_bounds
) {
1342 depth_bounds
.DepthBoundsTestValueModifyDisable
= false;
1343 depth_bounds
.DepthBoundsTestEnableModifyDisable
= false;
1344 depth_bounds
.DepthBoundsTestEnable
= state
->depth
.bounds_test
;
1345 depth_bounds
.DepthBoundsTestMinValue
= state
->depth
.bounds_min
;
1346 depth_bounds
.DepthBoundsTestMaxValue
= state
->depth
.bounds_max
;
1354 * The pipe->bind_depth_stencil_alpha_state() driver hook.
1356 * Bind a depth/stencil/alpha CSO and flag related dirty bits.
1359 iris_bind_zsa_state(struct pipe_context
*ctx
, void *state
)
1361 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1362 struct iris_depth_stencil_alpha_state
*old_cso
= ice
->state
.cso_zsa
;
1363 struct iris_depth_stencil_alpha_state
*new_cso
= state
;
1366 if (cso_changed(alpha
.ref_value
))
1367 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
1369 if (cso_changed(alpha
.enabled
))
1370 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
| IRIS_DIRTY_BLEND_STATE
;
1372 if (cso_changed(alpha
.func
))
1373 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1375 if (cso_changed(depth_writes_enabled
))
1376 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1378 ice
->state
.depth_writes_enabled
= new_cso
->depth_writes_enabled
;
1379 ice
->state
.stencil_writes_enabled
= new_cso
->stencil_writes_enabled
;
1382 if (cso_changed(depth_bounds
))
1383 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BOUNDS
;
1387 ice
->state
.cso_zsa
= new_cso
;
1388 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1389 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
1390 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_DEPTH_STENCIL_ALPHA
];
1393 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
1398 want_pma_fix(struct iris_context
*ice
)
1400 UNUSED
struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
1401 UNUSED
const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1402 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
1403 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
1404 const struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
1405 const struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
1406 const struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
1408 /* In very specific combinations of state, we can instruct Gen8-9 hardware
1409 * to avoid stalling at the pixel mask array. The state equations are
1410 * documented in these places:
1412 * - Gen8 Depth PMA Fix: CACHE_MODE_1::NP_PMA_FIX_ENABLE
1413 * - Gen9 Stencil PMA Fix: CACHE_MODE_0::STC PMA Optimization Enable
1415 * Both equations share some common elements:
1418 * !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
1419 * 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
1420 * 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
1421 * 3DSTATE_WM_HZ_OP::StencilBufferClear) &&
1424 * 3DSTATE_WM::ForceKillPix != ForceOff &&
1425 * (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
1426 * 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
1427 * 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
1428 * 3DSTATE_PS_BLEND::AlphaTestEnable ||
1429 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable)
1431 * (Technically the stencil PMA treats ForceKillPix differently,
1432 * but I think this is a documentation oversight, and we don't
1433 * ever use it in this way, so it doesn't matter).
1436 * 3DSTATE_WM::ForceThreadDispatch != 1 &&
1437 * 3DSTATE_RASTER::ForceSampleCount == NUMRASTSAMPLES_0 &&
1438 * 3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL &&
1439 * 3DSTATE_DEPTH_BUFFER::HIZ Enable &&
1440 * 3DSTATE_WM::EDSC_Mode != EDSC_PREPS &&
1441 * 3DSTATE_PS_EXTRA::PixelShaderValid &&
1444 * These are always true:
1446 * 3DSTATE_RASTER::ForceSampleCount == NUMRASTSAMPLES_0
1447 * 3DSTATE_PS_EXTRA::PixelShaderValid
1449 * Also, we never use the normal drawing path for HiZ ops; these are true:
1451 * !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
1452 * 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
1453 * 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
1454 * 3DSTATE_WM_HZ_OP::StencilBufferClear)
1456 * This happens sometimes:
1458 * 3DSTATE_WM::ForceThreadDispatch != 1
1460 * However, we choose to ignore it as it either agrees with the signal
1461 * (dispatch was already enabled, so nothing out of the ordinary), or
1462 * there are no framebuffer attachments (so no depth or HiZ anyway,
1463 * meaning the PMA signal will already be disabled).
1469 struct iris_resource
*zres
, *sres
;
1470 iris_get_depth_stencil_resources(cso_fb
->zsbuf
->texture
, &zres
, &sres
);
1472 /* 3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL &&
1473 * 3DSTATE_DEPTH_BUFFER::HIZ Enable &&
1475 if (!zres
|| !iris_resource_level_has_hiz(zres
, cso_fb
->zsbuf
->u
.tex
.level
))
1478 /* 3DSTATE_WM::EDSC_Mode != EDSC_PREPS */
1479 if (wm_prog_data
->early_fragment_tests
)
1482 /* 3DSTATE_WM::ForceKillPix != ForceOff &&
1483 * (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
1484 * 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
1485 * 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
1486 * 3DSTATE_PS_BLEND::AlphaTestEnable ||
1487 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable)
1489 bool killpixels
= wm_prog_data
->uses_kill
|| wm_prog_data
->uses_omask
||
1490 cso_blend
->alpha_to_coverage
|| cso_zsa
->alpha
.enabled
;
1492 /* The Gen8 depth PMA equation becomes:
1495 * 3DSTATE_WM_DEPTH_STENCIL::DepthWriteEnable &&
1496 * 3DSTATE_DEPTH_BUFFER::DEPTH_WRITE_ENABLE
1499 * 3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
1500 * 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE &&
1501 * 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE
1505 * 3DSTATE_WM_DEPTH_STENCIL::DepthTestEnable &&
1506 * ((killpixels && (depth_writes || stencil_writes)) ||
1507 * 3DSTATE_PS_EXTRA::PixelShaderComputedDepthMode != PSCDEPTH_OFF)
1510 if (!cso_zsa
->depth_test_enabled
)
1513 return wm_prog_data
->computed_depth_mode
!= PSCDEPTH_OFF
||
1514 (killpixels
&& (cso_zsa
->depth_writes_enabled
||
1515 (sres
&& cso_zsa
->stencil_writes_enabled
)));
1520 genX(update_pma_fix
)(struct iris_context
*ice
,
1521 struct iris_batch
*batch
,
1525 struct iris_genx_state
*genx
= ice
->state
.genx
;
1527 if (genx
->pma_fix_enabled
== enable
)
1530 genx
->pma_fix_enabled
= enable
;
1532 /* According to the Broadwell PIPE_CONTROL documentation, software should
1533 * emit a PIPE_CONTROL with the CS Stall and Depth Cache Flush bits set
1534 * prior to the LRI. If stencil buffer writes are enabled, then a Render * Cache Flush is also necessary.
1536 * The Gen9 docs say to use a depth stall rather than a command streamer
1537 * stall. However, the hardware seems to violently disagree. A full
1538 * command streamer stall seems to be needed in both cases.
1540 iris_emit_pipe_control_flush(batch
, "PMA fix change (1/2)",
1541 PIPE_CONTROL_CS_STALL
|
1542 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1543 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
1546 iris_pack_state(GENX(CACHE_MODE_1
), ®_val
, reg
) {
1547 reg
.NPPMAFixEnable
= enable
;
1548 reg
.NPEarlyZFailsDisable
= enable
;
1549 reg
.NPPMAFixEnableMask
= true;
1550 reg
.NPEarlyZFailsDisableMask
= true;
1552 iris_emit_lri(batch
, CACHE_MODE_1
, reg_val
);
1554 /* After the LRI, a PIPE_CONTROL with both the Depth Stall and Depth Cache
1555 * Flush bits is often necessary. We do it regardless because it's easier.
1556 * The render cache flush is also necessary if stencil writes are enabled.
1558 * Again, the Gen9 docs give a different set of flushes but the Broadwell
1559 * flushes seem to work just as well.
1561 iris_emit_pipe_control_flush(batch
, "PMA fix change (1/2)",
1562 PIPE_CONTROL_DEPTH_STALL
|
1563 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1564 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
1569 * Gallium CSO for rasterizer state.
1571 struct iris_rasterizer_state
{
1572 uint32_t sf
[GENX(3DSTATE_SF_length
)];
1573 uint32_t clip
[GENX(3DSTATE_CLIP_length
)];
1574 uint32_t raster
[GENX(3DSTATE_RASTER_length
)];
1575 uint32_t wm
[GENX(3DSTATE_WM_length
)];
1576 uint32_t line_stipple
[GENX(3DSTATE_LINE_STIPPLE_length
)];
1578 uint8_t num_clip_plane_consts
;
1579 bool clip_halfz
; /* for CC_VIEWPORT */
1580 bool depth_clip_near
; /* for CC_VIEWPORT */
1581 bool depth_clip_far
; /* for CC_VIEWPORT */
1582 bool flatshade
; /* for shader state */
1583 bool flatshade_first
; /* for stream output */
1584 bool clamp_fragment_color
; /* for shader state */
1585 bool light_twoside
; /* for shader state */
1586 bool rasterizer_discard
; /* for 3DSTATE_STREAMOUT and 3DSTATE_CLIP */
1587 bool half_pixel_center
; /* for 3DSTATE_MULTISAMPLE */
1588 bool line_stipple_enable
;
1589 bool poly_stipple_enable
;
1591 bool force_persample_interp
;
1592 bool conservative_rasterization
;
1593 bool fill_mode_point_or_line
;
1594 enum pipe_sprite_coord_mode sprite_coord_mode
; /* PIPE_SPRITE_* */
1595 uint16_t sprite_coord_enable
;
1599 get_line_width(const struct pipe_rasterizer_state
*state
)
1601 float line_width
= state
->line_width
;
1603 /* From the OpenGL 4.4 spec:
1605 * "The actual width of non-antialiased lines is determined by rounding
1606 * the supplied width to the nearest integer, then clamping it to the
1607 * implementation-dependent maximum non-antialiased line width."
1609 if (!state
->multisample
&& !state
->line_smooth
)
1610 line_width
= roundf(state
->line_width
);
1612 if (!state
->multisample
&& state
->line_smooth
&& line_width
< 1.5f
) {
1613 /* For 1 pixel line thickness or less, the general anti-aliasing
1614 * algorithm gives up, and a garbage line is generated. Setting a
1615 * Line Width of 0.0 specifies the rasterization of the "thinnest"
1616 * (one-pixel-wide), non-antialiased lines.
1618 * Lines rendered with zero Line Width are rasterized using the
1619 * "Grid Intersection Quantization" rules as specified by the
1620 * "Zero-Width (Cosmetic) Line Rasterization" section of the docs.
1629 * The pipe->create_rasterizer_state() driver hook.
1632 iris_create_rasterizer_state(struct pipe_context
*ctx
,
1633 const struct pipe_rasterizer_state
*state
)
1635 struct iris_rasterizer_state
*cso
=
1636 malloc(sizeof(struct iris_rasterizer_state
));
1638 cso
->multisample
= state
->multisample
;
1639 cso
->force_persample_interp
= state
->force_persample_interp
;
1640 cso
->clip_halfz
= state
->clip_halfz
;
1641 cso
->depth_clip_near
= state
->depth_clip_near
;
1642 cso
->depth_clip_far
= state
->depth_clip_far
;
1643 cso
->flatshade
= state
->flatshade
;
1644 cso
->flatshade_first
= state
->flatshade_first
;
1645 cso
->clamp_fragment_color
= state
->clamp_fragment_color
;
1646 cso
->light_twoside
= state
->light_twoside
;
1647 cso
->rasterizer_discard
= state
->rasterizer_discard
;
1648 cso
->half_pixel_center
= state
->half_pixel_center
;
1649 cso
->sprite_coord_mode
= state
->sprite_coord_mode
;
1650 cso
->sprite_coord_enable
= state
->sprite_coord_enable
;
1651 cso
->line_stipple_enable
= state
->line_stipple_enable
;
1652 cso
->poly_stipple_enable
= state
->poly_stipple_enable
;
1653 cso
->conservative_rasterization
=
1654 state
->conservative_raster_mode
== PIPE_CONSERVATIVE_RASTER_POST_SNAP
;
1656 cso
->fill_mode_point_or_line
=
1657 state
->fill_front
== PIPE_POLYGON_MODE_LINE
||
1658 state
->fill_front
== PIPE_POLYGON_MODE_POINT
||
1659 state
->fill_back
== PIPE_POLYGON_MODE_LINE
||
1660 state
->fill_back
== PIPE_POLYGON_MODE_POINT
;
1662 if (state
->clip_plane_enable
!= 0)
1663 cso
->num_clip_plane_consts
= util_logbase2(state
->clip_plane_enable
) + 1;
1665 cso
->num_clip_plane_consts
= 0;
1667 float line_width
= get_line_width(state
);
1669 iris_pack_command(GENX(3DSTATE_SF
), cso
->sf
, sf
) {
1670 sf
.StatisticsEnable
= true;
1671 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
1672 sf
.LineEndCapAntialiasingRegionWidth
=
1673 state
->line_smooth
? _10pixels
: _05pixels
;
1674 sf
.LastPixelEnable
= state
->line_last_pixel
;
1675 sf
.LineWidth
= line_width
;
1676 sf
.SmoothPointEnable
= (state
->point_smooth
|| state
->multisample
) &&
1677 !state
->point_quad_rasterization
;
1678 sf
.PointWidthSource
= state
->point_size_per_vertex
? Vertex
: State
;
1679 sf
.PointWidth
= state
->point_size
;
1681 if (state
->flatshade_first
) {
1682 sf
.TriangleFanProvokingVertexSelect
= 1;
1684 sf
.TriangleStripListProvokingVertexSelect
= 2;
1685 sf
.TriangleFanProvokingVertexSelect
= 2;
1686 sf
.LineStripListProvokingVertexSelect
= 1;
1690 iris_pack_command(GENX(3DSTATE_RASTER
), cso
->raster
, rr
) {
1691 rr
.FrontWinding
= state
->front_ccw
? CounterClockwise
: Clockwise
;
1692 rr
.CullMode
= translate_cull_mode(state
->cull_face
);
1693 rr
.FrontFaceFillMode
= translate_fill_mode(state
->fill_front
);
1694 rr
.BackFaceFillMode
= translate_fill_mode(state
->fill_back
);
1695 rr
.DXMultisampleRasterizationEnable
= state
->multisample
;
1696 rr
.GlobalDepthOffsetEnableSolid
= state
->offset_tri
;
1697 rr
.GlobalDepthOffsetEnableWireframe
= state
->offset_line
;
1698 rr
.GlobalDepthOffsetEnablePoint
= state
->offset_point
;
1699 rr
.GlobalDepthOffsetConstant
= state
->offset_units
* 2;
1700 rr
.GlobalDepthOffsetScale
= state
->offset_scale
;
1701 rr
.GlobalDepthOffsetClamp
= state
->offset_clamp
;
1702 rr
.SmoothPointEnable
= state
->point_smooth
;
1703 rr
.AntialiasingEnable
= state
->line_smooth
;
1704 rr
.ScissorRectangleEnable
= state
->scissor
;
1706 rr
.ViewportZNearClipTestEnable
= state
->depth_clip_near
;
1707 rr
.ViewportZFarClipTestEnable
= state
->depth_clip_far
;
1708 rr
.ConservativeRasterizationEnable
=
1709 cso
->conservative_rasterization
;
1711 rr
.ViewportZClipTestEnable
= (state
->depth_clip_near
|| state
->depth_clip_far
);
1715 iris_pack_command(GENX(3DSTATE_CLIP
), cso
->clip
, cl
) {
1716 /* cl.NonPerspectiveBarycentricEnable is filled in at draw time from
1717 * the FS program; cl.ForceZeroRTAIndexEnable is filled in from the FB.
1719 cl
.EarlyCullEnable
= true;
1720 cl
.UserClipDistanceClipTestEnableBitmask
= state
->clip_plane_enable
;
1721 cl
.ForceUserClipDistanceClipTestEnableBitmask
= true;
1722 cl
.APIMode
= state
->clip_halfz
? APIMODE_D3D
: APIMODE_OGL
;
1723 cl
.GuardbandClipTestEnable
= true;
1724 cl
.ClipEnable
= true;
1725 cl
.MinimumPointWidth
= 0.125;
1726 cl
.MaximumPointWidth
= 255.875;
1728 if (state
->flatshade_first
) {
1729 cl
.TriangleFanProvokingVertexSelect
= 1;
1731 cl
.TriangleStripListProvokingVertexSelect
= 2;
1732 cl
.TriangleFanProvokingVertexSelect
= 2;
1733 cl
.LineStripListProvokingVertexSelect
= 1;
1737 iris_pack_command(GENX(3DSTATE_WM
), cso
->wm
, wm
) {
1738 /* wm.BarycentricInterpolationMode and wm.EarlyDepthStencilControl are
1739 * filled in at draw time from the FS program.
1741 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1742 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1743 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1744 wm
.LineStippleEnable
= state
->line_stipple_enable
;
1745 wm
.PolygonStippleEnable
= state
->poly_stipple_enable
;
1748 /* Remap from 0..255 back to 1..256 */
1749 const unsigned line_stipple_factor
= state
->line_stipple_factor
+ 1;
1751 iris_pack_command(GENX(3DSTATE_LINE_STIPPLE
), cso
->line_stipple
, line
) {
1752 if (state
->line_stipple_enable
) {
1753 line
.LineStipplePattern
= state
->line_stipple_pattern
;
1754 line
.LineStippleInverseRepeatCount
= 1.0f
/ line_stipple_factor
;
1755 line
.LineStippleRepeatCount
= line_stipple_factor
;
1763 * The pipe->bind_rasterizer_state() driver hook.
1765 * Bind a rasterizer CSO and flag related dirty bits.
1768 iris_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
1770 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1771 struct iris_rasterizer_state
*old_cso
= ice
->state
.cso_rast
;
1772 struct iris_rasterizer_state
*new_cso
= state
;
1775 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
1776 if (cso_changed_memcmp(line_stipple
))
1777 ice
->state
.dirty
|= IRIS_DIRTY_LINE_STIPPLE
;
1779 if (cso_changed(half_pixel_center
))
1780 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
1782 if (cso_changed(line_stipple_enable
) || cso_changed(poly_stipple_enable
))
1783 ice
->state
.dirty
|= IRIS_DIRTY_WM
;
1785 if (cso_changed(rasterizer_discard
))
1786 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
| IRIS_DIRTY_CLIP
;
1788 if (cso_changed(flatshade_first
))
1789 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
1791 if (cso_changed(depth_clip_near
) || cso_changed(depth_clip_far
) ||
1792 cso_changed(clip_halfz
))
1793 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1795 if (cso_changed(sprite_coord_enable
) ||
1796 cso_changed(sprite_coord_mode
) ||
1797 cso_changed(light_twoside
))
1798 ice
->state
.dirty
|= IRIS_DIRTY_SBE
;
1800 if (cso_changed(conservative_rasterization
))
1801 ice
->state
.dirty
|= IRIS_DIRTY_FS
;
1804 ice
->state
.cso_rast
= new_cso
;
1805 ice
->state
.dirty
|= IRIS_DIRTY_RASTER
;
1806 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
1807 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_RASTERIZER
];
1811 * Return true if the given wrap mode requires the border color to exist.
1813 * (We can skip uploading it if the sampler isn't going to use it.)
1816 wrap_mode_needs_border_color(unsigned wrap_mode
)
1818 return wrap_mode
== TCM_CLAMP_BORDER
|| wrap_mode
== TCM_HALF_BORDER
;
1822 * Gallium CSO for sampler state.
1824 struct iris_sampler_state
{
1825 union pipe_color_union border_color
;
1826 bool needs_border_color
;
1828 uint32_t sampler_state
[GENX(SAMPLER_STATE_length
)];
1832 * The pipe->create_sampler_state() driver hook.
1834 * We fill out SAMPLER_STATE (except for the border color pointer), and
1835 * store that on the CPU. It doesn't make sense to upload it to a GPU
1836 * buffer object yet, because 3DSTATE_SAMPLER_STATE_POINTERS requires
1837 * all bound sampler states to be in contiguous memor.
1840 iris_create_sampler_state(struct pipe_context
*ctx
,
1841 const struct pipe_sampler_state
*state
)
1843 struct iris_sampler_state
*cso
= CALLOC_STRUCT(iris_sampler_state
);
1848 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST
== MAPFILTER_NEAREST
);
1849 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR
== MAPFILTER_LINEAR
);
1851 unsigned wrap_s
= translate_wrap(state
->wrap_s
);
1852 unsigned wrap_t
= translate_wrap(state
->wrap_t
);
1853 unsigned wrap_r
= translate_wrap(state
->wrap_r
);
1855 memcpy(&cso
->border_color
, &state
->border_color
, sizeof(cso
->border_color
));
1857 cso
->needs_border_color
= wrap_mode_needs_border_color(wrap_s
) ||
1858 wrap_mode_needs_border_color(wrap_t
) ||
1859 wrap_mode_needs_border_color(wrap_r
);
1861 float min_lod
= state
->min_lod
;
1862 unsigned mag_img_filter
= state
->mag_img_filter
;
1864 // XXX: explain this code ported from ilo...I don't get it at all...
1865 if (state
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
&&
1866 state
->min_lod
> 0.0f
) {
1868 mag_img_filter
= state
->min_img_filter
;
1871 iris_pack_state(GENX(SAMPLER_STATE
), cso
->sampler_state
, samp
) {
1872 samp
.TCXAddressControlMode
= wrap_s
;
1873 samp
.TCYAddressControlMode
= wrap_t
;
1874 samp
.TCZAddressControlMode
= wrap_r
;
1875 samp
.CubeSurfaceControlMode
= state
->seamless_cube_map
;
1876 samp
.NonnormalizedCoordinateEnable
= !state
->normalized_coords
;
1877 samp
.MinModeFilter
= state
->min_img_filter
;
1878 samp
.MagModeFilter
= mag_img_filter
;
1879 samp
.MipModeFilter
= translate_mip_filter(state
->min_mip_filter
);
1880 samp
.MaximumAnisotropy
= RATIO21
;
1882 if (state
->max_anisotropy
>= 2) {
1883 if (state
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
1884 samp
.MinModeFilter
= MAPFILTER_ANISOTROPIC
;
1885 samp
.AnisotropicAlgorithm
= EWAApproximation
;
1888 if (state
->mag_img_filter
== PIPE_TEX_FILTER_LINEAR
)
1889 samp
.MagModeFilter
= MAPFILTER_ANISOTROPIC
;
1891 samp
.MaximumAnisotropy
=
1892 MIN2((state
->max_anisotropy
- 2) / 2, RATIO161
);
1895 /* Set address rounding bits if not using nearest filtering. */
1896 if (state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1897 samp
.UAddressMinFilterRoundingEnable
= true;
1898 samp
.VAddressMinFilterRoundingEnable
= true;
1899 samp
.RAddressMinFilterRoundingEnable
= true;
1902 if (state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1903 samp
.UAddressMagFilterRoundingEnable
= true;
1904 samp
.VAddressMagFilterRoundingEnable
= true;
1905 samp
.RAddressMagFilterRoundingEnable
= true;
1908 if (state
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
1909 samp
.ShadowFunction
= translate_shadow_func(state
->compare_func
);
1911 const float hw_max_lod
= GEN_GEN
>= 7 ? 14 : 13;
1913 samp
.LODPreClampMode
= CLAMP_MODE_OGL
;
1914 samp
.MinLOD
= CLAMP(min_lod
, 0, hw_max_lod
);
1915 samp
.MaxLOD
= CLAMP(state
->max_lod
, 0, hw_max_lod
);
1916 samp
.TextureLODBias
= CLAMP(state
->lod_bias
, -16, 15);
1918 /* .BorderColorPointer is filled in by iris_bind_sampler_states. */
1925 * The pipe->bind_sampler_states() driver hook.
1928 iris_bind_sampler_states(struct pipe_context
*ctx
,
1929 enum pipe_shader_type p_stage
,
1930 unsigned start
, unsigned count
,
1933 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1934 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1935 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1937 assert(start
+ count
<= IRIS_MAX_TEXTURE_SAMPLERS
);
1941 for (int i
= 0; i
< count
; i
++) {
1942 if (shs
->samplers
[start
+ i
] != states
[i
]) {
1943 shs
->samplers
[start
+ i
] = states
[i
];
1949 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
;
1953 * Upload the sampler states into a contiguous area of GPU memory, for
1954 * for 3DSTATE_SAMPLER_STATE_POINTERS_*.
1956 * Also fill out the border color state pointers.
1959 iris_upload_sampler_states(struct iris_context
*ice
, gl_shader_stage stage
)
1961 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1962 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
1964 /* We assume the state tracker will call pipe->bind_sampler_states()
1965 * if the program's number of textures changes.
1967 unsigned count
= info
? util_last_bit(info
->textures_used
) : 0;
1972 /* Assemble the SAMPLER_STATEs into a contiguous table that lives
1973 * in the dynamic state memory zone, so we can point to it via the
1974 * 3DSTATE_SAMPLER_STATE_POINTERS_* commands.
1976 unsigned size
= count
* 4 * GENX(SAMPLER_STATE_length
);
1978 upload_state(ice
->state
.dynamic_uploader
, &shs
->sampler_table
, size
, 32);
1982 struct pipe_resource
*res
= shs
->sampler_table
.res
;
1983 shs
->sampler_table
.offset
+=
1984 iris_bo_offset_from_base_address(iris_resource_bo(res
));
1986 iris_record_state_size(ice
->state
.sizes
, shs
->sampler_table
.offset
, size
);
1988 /* Make sure all land in the same BO */
1989 iris_border_color_pool_reserve(ice
, IRIS_MAX_TEXTURE_SAMPLERS
);
1991 ice
->state
.need_border_colors
&= ~(1 << stage
);
1993 for (int i
= 0; i
< count
; i
++) {
1994 struct iris_sampler_state
*state
= shs
->samplers
[i
];
1995 struct iris_sampler_view
*tex
= shs
->textures
[i
];
1998 memset(map
, 0, 4 * GENX(SAMPLER_STATE_length
));
1999 } else if (!state
->needs_border_color
) {
2000 memcpy(map
, state
->sampler_state
, 4 * GENX(SAMPLER_STATE_length
));
2002 ice
->state
.need_border_colors
|= 1 << stage
;
2004 /* We may need to swizzle the border color for format faking.
2005 * A/LA formats are faked as R/RG with 000R or R00G swizzles.
2006 * This means we need to move the border color's A channel into
2007 * the R or G channels so that those read swizzles will move it
2010 union pipe_color_union
*color
= &state
->border_color
;
2011 union pipe_color_union tmp
;
2013 enum pipe_format internal_format
= tex
->res
->internal_format
;
2015 if (util_format_is_alpha(internal_format
)) {
2016 unsigned char swz
[4] = {
2017 PIPE_SWIZZLE_W
, PIPE_SWIZZLE_0
,
2018 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
2020 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
2022 } else if (util_format_is_luminance_alpha(internal_format
) &&
2023 internal_format
!= PIPE_FORMAT_L8A8_SRGB
) {
2024 unsigned char swz
[4] = {
2025 PIPE_SWIZZLE_X
, PIPE_SWIZZLE_W
,
2026 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
2028 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
2033 /* Stream out the border color and merge the pointer. */
2034 uint32_t offset
= iris_upload_border_color(ice
, color
);
2036 uint32_t dynamic
[GENX(SAMPLER_STATE_length
)];
2037 iris_pack_state(GENX(SAMPLER_STATE
), dynamic
, dyns
) {
2038 dyns
.BorderColorPointer
= offset
;
2041 for (uint32_t j
= 0; j
< GENX(SAMPLER_STATE_length
); j
++)
2042 map
[j
] = state
->sampler_state
[j
] | dynamic
[j
];
2045 map
+= GENX(SAMPLER_STATE_length
);
2049 static enum isl_channel_select
2050 fmt_swizzle(const struct iris_format_info
*fmt
, enum pipe_swizzle swz
)
2053 case PIPE_SWIZZLE_X
: return fmt
->swizzle
.r
;
2054 case PIPE_SWIZZLE_Y
: return fmt
->swizzle
.g
;
2055 case PIPE_SWIZZLE_Z
: return fmt
->swizzle
.b
;
2056 case PIPE_SWIZZLE_W
: return fmt
->swizzle
.a
;
2057 case PIPE_SWIZZLE_1
: return SCS_ONE
;
2058 case PIPE_SWIZZLE_0
: return SCS_ZERO
;
2059 default: unreachable("invalid swizzle");
2064 fill_buffer_surface_state(struct isl_device
*isl_dev
,
2065 struct iris_resource
*res
,
2067 enum isl_format format
,
2068 struct isl_swizzle swizzle
,
2072 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
2073 const unsigned cpp
= format
== ISL_FORMAT_RAW
? 1 : fmtl
->bpb
/ 8;
2075 /* The ARB_texture_buffer_specification says:
2077 * "The number of texels in the buffer texture's texel array is given by
2079 * floor(<buffer_size> / (<components> * sizeof(<base_type>)),
2081 * where <buffer_size> is the size of the buffer object, in basic
2082 * machine units and <components> and <base_type> are the element count
2083 * and base data type for elements, as specified in Table X.1. The
2084 * number of texels in the texel array is then clamped to the
2085 * implementation-dependent limit MAX_TEXTURE_BUFFER_SIZE_ARB."
2087 * We need to clamp the size in bytes to MAX_TEXTURE_BUFFER_SIZE * stride,
2088 * so that when ISL divides by stride to obtain the number of texels, that
2089 * texel count is clamped to MAX_TEXTURE_BUFFER_SIZE.
2091 unsigned final_size
=
2092 MIN3(size
, res
->bo
->size
- res
->offset
- offset
,
2093 IRIS_MAX_TEXTURE_BUFFER_SIZE
* cpp
);
2095 isl_buffer_fill_state(isl_dev
, map
,
2096 .address
= res
->bo
->gtt_offset
+ res
->offset
+ offset
,
2097 .size_B
= final_size
,
2101 .mocs
= mocs(res
->bo
, isl_dev
));
2104 #define SURFACE_STATE_ALIGNMENT 64
2107 * Allocate several contiguous SURFACE_STATE structures, one for each
2108 * supported auxiliary surface mode.
2111 alloc_surface_states(struct u_upload_mgr
*mgr
,
2112 struct iris_state_ref
*ref
,
2113 unsigned aux_usages
)
2115 const unsigned surf_size
= 4 * GENX(RENDER_SURFACE_STATE_length
);
2117 /* If this changes, update this to explicitly align pointers */
2118 STATIC_ASSERT(surf_size
== SURFACE_STATE_ALIGNMENT
);
2120 assert(aux_usages
!= 0);
2123 upload_state(mgr
, ref
, util_bitcount(aux_usages
) * surf_size
,
2124 SURFACE_STATE_ALIGNMENT
);
2126 ref
->offset
+= iris_bo_offset_from_base_address(iris_resource_bo(ref
->res
));
2133 * Return an ISL surface for use with non-coherent render target reads.
2135 * In a few complex cases, we can't use the SURFACE_STATE for normal render
2136 * target writes. We need to make a separate one for sampling which refers
2137 * to the single slice of the texture being read.
2140 get_rt_read_isl_surf(const struct gen_device_info
*devinfo
,
2141 struct iris_resource
*res
,
2142 enum pipe_texture_target target
,
2143 struct isl_view
*view
,
2144 uint32_t *tile_x_sa
,
2145 uint32_t *tile_y_sa
,
2146 struct isl_surf
*surf
)
2151 const enum isl_dim_layout dim_layout
=
2152 iris_get_isl_dim_layout(devinfo
, res
->surf
.tiling
, target
);
2154 surf
->dim
= target_to_isl_surf_dim(target
);
2156 if (surf
->dim_layout
== dim_layout
)
2159 /* The layout of the specified texture target is not compatible with the
2160 * actual layout of the miptree structure in memory -- You're entering
2161 * dangerous territory, this can only possibly work if you only intended
2162 * to access a single level and slice of the texture, and the hardware
2163 * supports the tile offset feature in order to allow non-tile-aligned
2164 * base offsets, since we'll have to point the hardware to the first
2165 * texel of the level instead of relying on the usual base level/layer
2168 assert(view
->levels
== 1 && view
->array_len
== 1);
2169 assert(*tile_x_sa
== 0 && *tile_y_sa
== 0);
2171 res
->offset
+= iris_resource_get_tile_offsets(res
, view
->base_level
,
2172 view
->base_array_layer
,
2173 tile_x_sa
, tile_y_sa
);
2174 const unsigned l
= view
->base_level
;
2176 surf
->logical_level0_px
.width
= minify(surf
->logical_level0_px
.width
, l
);
2177 surf
->logical_level0_px
.height
= surf
->dim
<= ISL_SURF_DIM_1D
? 1 :
2178 minify(surf
->logical_level0_px
.height
, l
);
2179 surf
->logical_level0_px
.depth
= surf
->dim
<= ISL_SURF_DIM_2D
? 1 :
2180 minify(surf
->logical_level0_px
.depth
, l
);
2182 surf
->logical_level0_px
.array_len
= 1;
2184 surf
->dim_layout
= dim_layout
;
2186 view
->base_level
= 0;
2187 view
->base_array_layer
= 0;
2192 fill_surface_state(struct isl_device
*isl_dev
,
2194 struct iris_resource
*res
,
2195 struct isl_surf
*surf
,
2196 struct isl_view
*view
,
2201 struct isl_surf_fill_state_info f
= {
2204 .mocs
= mocs(res
->bo
, isl_dev
),
2205 .address
= res
->bo
->gtt_offset
+ res
->offset
,
2206 .x_offset_sa
= tile_x_sa
,
2207 .y_offset_sa
= tile_y_sa
,
2210 assert(!iris_resource_unfinished_aux_import(res
));
2212 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
2213 f
.aux_surf
= &res
->aux
.surf
;
2214 f
.aux_usage
= aux_usage
;
2215 f
.aux_address
= res
->aux
.bo
->gtt_offset
+ res
->aux
.offset
;
2217 struct iris_bo
*clear_bo
= NULL
;
2218 uint64_t clear_offset
= 0;
2220 iris_resource_get_clear_color(res
, &clear_bo
, &clear_offset
);
2222 f
.clear_address
= clear_bo
->gtt_offset
+ clear_offset
;
2223 f
.use_clear_address
= isl_dev
->info
->gen
> 9;
2227 isl_surf_fill_state_s(isl_dev
, map
, &f
);
2231 * The pipe->create_sampler_view() driver hook.
2233 static struct pipe_sampler_view
*
2234 iris_create_sampler_view(struct pipe_context
*ctx
,
2235 struct pipe_resource
*tex
,
2236 const struct pipe_sampler_view
*tmpl
)
2238 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2239 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2240 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2241 struct iris_sampler_view
*isv
= calloc(1, sizeof(struct iris_sampler_view
));
2246 /* initialize base object */
2248 isv
->base
.context
= ctx
;
2249 isv
->base
.texture
= NULL
;
2250 pipe_reference_init(&isv
->base
.reference
, 1);
2251 pipe_resource_reference(&isv
->base
.texture
, tex
);
2253 if (util_format_is_depth_or_stencil(tmpl
->format
)) {
2254 struct iris_resource
*zres
, *sres
;
2255 const struct util_format_description
*desc
=
2256 util_format_description(tmpl
->format
);
2258 iris_get_depth_stencil_resources(tex
, &zres
, &sres
);
2260 tex
= util_format_has_depth(desc
) ? &zres
->base
: &sres
->base
;
2263 isv
->res
= (struct iris_resource
*) tex
;
2265 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
2266 &isv
->surface_state
,
2267 isv
->res
->aux
.sampler_usages
);
2271 isl_surf_usage_flags_t usage
= ISL_SURF_USAGE_TEXTURE_BIT
;
2273 if (isv
->base
.target
== PIPE_TEXTURE_CUBE
||
2274 isv
->base
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
2275 usage
|= ISL_SURF_USAGE_CUBE_BIT
;
2277 const struct iris_format_info fmt
=
2278 iris_format_for_usage(devinfo
, tmpl
->format
, usage
);
2280 isv
->clear_color
= isv
->res
->aux
.clear_color
;
2282 isv
->view
= (struct isl_view
) {
2284 .swizzle
= (struct isl_swizzle
) {
2285 .r
= fmt_swizzle(&fmt
, tmpl
->swizzle_r
),
2286 .g
= fmt_swizzle(&fmt
, tmpl
->swizzle_g
),
2287 .b
= fmt_swizzle(&fmt
, tmpl
->swizzle_b
),
2288 .a
= fmt_swizzle(&fmt
, tmpl
->swizzle_a
),
2293 /* Fill out SURFACE_STATE for this view. */
2294 if (tmpl
->target
!= PIPE_BUFFER
) {
2295 isv
->view
.base_level
= tmpl
->u
.tex
.first_level
;
2296 isv
->view
.levels
= tmpl
->u
.tex
.last_level
- tmpl
->u
.tex
.first_level
+ 1;
2297 // XXX: do I need to port f9fd0cf4790cb2a530e75d1a2206dbb9d8af7cb2?
2298 isv
->view
.base_array_layer
= tmpl
->u
.tex
.first_layer
;
2299 isv
->view
.array_len
=
2300 tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
2302 if (iris_resource_unfinished_aux_import(isv
->res
))
2303 iris_resource_finish_aux_import(&screen
->base
, isv
->res
);
2305 unsigned aux_modes
= isv
->res
->aux
.sampler_usages
;
2307 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
2309 /* If we have a multisampled depth buffer, do not create a sampler
2310 * surface state with HiZ.
2312 fill_surface_state(&screen
->isl_dev
, map
, isv
->res
, &isv
->res
->surf
,
2313 &isv
->view
, aux_usage
, 0, 0);
2315 map
+= SURFACE_STATE_ALIGNMENT
;
2318 fill_buffer_surface_state(&screen
->isl_dev
, isv
->res
, map
,
2319 isv
->view
.format
, isv
->view
.swizzle
,
2320 tmpl
->u
.buf
.offset
, tmpl
->u
.buf
.size
);
2327 iris_sampler_view_destroy(struct pipe_context
*ctx
,
2328 struct pipe_sampler_view
*state
)
2330 struct iris_sampler_view
*isv
= (void *) state
;
2331 pipe_resource_reference(&state
->texture
, NULL
);
2332 pipe_resource_reference(&isv
->surface_state
.res
, NULL
);
2337 * The pipe->create_surface() driver hook.
2339 * In Gallium nomenclature, "surfaces" are a view of a resource that
2340 * can be bound as a render target or depth/stencil buffer.
2342 static struct pipe_surface
*
2343 iris_create_surface(struct pipe_context
*ctx
,
2344 struct pipe_resource
*tex
,
2345 const struct pipe_surface
*tmpl
)
2347 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2348 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2349 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2351 isl_surf_usage_flags_t usage
= 0;
2353 usage
= ISL_SURF_USAGE_STORAGE_BIT
;
2354 else if (util_format_is_depth_or_stencil(tmpl
->format
))
2355 usage
= ISL_SURF_USAGE_DEPTH_BIT
;
2357 usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
2359 const struct iris_format_info fmt
=
2360 iris_format_for_usage(devinfo
, tmpl
->format
, usage
);
2362 if ((usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) &&
2363 !isl_format_supports_rendering(devinfo
, fmt
.fmt
)) {
2364 /* Framebuffer validation will reject this invalid case, but it
2365 * hasn't had the opportunity yet. In the meantime, we need to
2366 * avoid hitting ISL asserts about unsupported formats below.
2371 struct iris_surface
*surf
= calloc(1, sizeof(struct iris_surface
));
2372 struct pipe_surface
*psurf
= &surf
->base
;
2373 struct iris_resource
*res
= (struct iris_resource
*) tex
;
2378 pipe_reference_init(&psurf
->reference
, 1);
2379 pipe_resource_reference(&psurf
->texture
, tex
);
2380 psurf
->context
= ctx
;
2381 psurf
->format
= tmpl
->format
;
2382 psurf
->width
= tex
->width0
;
2383 psurf
->height
= tex
->height0
;
2384 psurf
->texture
= tex
;
2385 psurf
->u
.tex
.first_layer
= tmpl
->u
.tex
.first_layer
;
2386 psurf
->u
.tex
.last_layer
= tmpl
->u
.tex
.last_layer
;
2387 psurf
->u
.tex
.level
= tmpl
->u
.tex
.level
;
2389 uint32_t array_len
= tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
2391 struct isl_view
*view
= &surf
->view
;
2392 *view
= (struct isl_view
) {
2394 .base_level
= tmpl
->u
.tex
.level
,
2396 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
2397 .array_len
= array_len
,
2398 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2403 enum pipe_texture_target target
= (tex
->target
== PIPE_TEXTURE_3D
&&
2404 array_len
== 1) ? PIPE_TEXTURE_2D
:
2405 tex
->target
== PIPE_TEXTURE_1D_ARRAY
?
2406 PIPE_TEXTURE_2D_ARRAY
: tex
->target
;
2408 struct isl_view
*read_view
= &surf
->read_view
;
2409 *read_view
= (struct isl_view
) {
2411 .base_level
= tmpl
->u
.tex
.level
,
2413 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
2414 .array_len
= array_len
,
2415 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2416 .usage
= ISL_SURF_USAGE_TEXTURE_BIT
,
2420 surf
->clear_color
= res
->aux
.clear_color
;
2422 /* Bail early for depth/stencil - we don't want SURFACE_STATE for them. */
2423 if (res
->surf
.usage
& (ISL_SURF_USAGE_DEPTH_BIT
|
2424 ISL_SURF_USAGE_STENCIL_BIT
))
2428 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
2429 &surf
->surface_state
,
2430 res
->aux
.possible_usages
);
2431 if (!unlikely(map
)) {
2432 pipe_resource_reference(&surf
->surface_state
.res
, NULL
);
2437 void *map_read
= alloc_surface_states(ice
->state
.surface_uploader
,
2438 &surf
->surface_state_read
,
2439 res
->aux
.possible_usages
);
2440 if (!unlikely(map_read
)) {
2441 pipe_resource_reference(&surf
->surface_state_read
.res
, NULL
);
2446 if (!isl_format_is_compressed(res
->surf
.format
)) {
2447 if (iris_resource_unfinished_aux_import(res
))
2448 iris_resource_finish_aux_import(&screen
->base
, res
);
2450 /* This is a normal surface. Fill out a SURFACE_STATE for each possible
2451 * auxiliary surface mode and return the pipe_surface.
2453 unsigned aux_modes
= res
->aux
.possible_usages
;
2456 uint32_t offset
= res
->offset
;
2458 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
2459 fill_surface_state(&screen
->isl_dev
, map
, res
, &res
->surf
,
2460 view
, aux_usage
, 0, 0);
2461 map
+= SURFACE_STATE_ALIGNMENT
;
2464 struct isl_surf surf
;
2465 uint32_t tile_x_sa
= 0, tile_y_sa
= 0;
2466 get_rt_read_isl_surf(devinfo
, res
, target
, read_view
,
2467 &tile_x_sa
, &tile_y_sa
, &surf
);
2468 fill_surface_state(&screen
->isl_dev
, map_read
, res
, &surf
, read_view
,
2469 aux_usage
, tile_x_sa
, tile_y_sa
);
2470 /* Restore offset because we change offset in case of handling
2471 * non_coherent fb fetch
2473 res
->offset
= offset
;
2474 map_read
+= SURFACE_STATE_ALIGNMENT
;
2481 /* The resource has a compressed format, which is not renderable, but we
2482 * have a renderable view format. We must be attempting to upload blocks
2483 * of compressed data via an uncompressed view.
2485 * In this case, we can assume there are no auxiliary buffers, a single
2486 * miplevel, and that the resource is single-sampled. Gallium may try
2487 * and create an uncompressed view with multiple layers, however.
2489 assert(!isl_format_is_compressed(fmt
.fmt
));
2490 assert(res
->aux
.possible_usages
== 1 << ISL_AUX_USAGE_NONE
);
2491 assert(res
->surf
.samples
== 1);
2492 assert(view
->levels
== 1);
2494 struct isl_surf isl_surf
;
2495 uint32_t offset_B
= 0, tile_x_sa
= 0, tile_y_sa
= 0;
2497 if (view
->base_level
> 0) {
2498 /* We can't rely on the hardware's miplevel selection with such
2499 * a substantial lie about the format, so we select a single image
2500 * using the Tile X/Y Offset fields. In this case, we can't handle
2501 * multiple array slices.
2503 * On Broadwell, HALIGN and VALIGN are specified in pixels and are
2504 * hard-coded to align to exactly the block size of the compressed
2505 * texture. This means that, when reinterpreted as a non-compressed
2506 * texture, the tile offsets may be anything and we can't rely on
2509 * Return NULL to force the state tracker to take fallback paths.
2511 if (view
->array_len
> 1 || GEN_GEN
== 8)
2514 const bool is_3d
= res
->surf
.dim
== ISL_SURF_DIM_3D
;
2515 isl_surf_get_image_surf(&screen
->isl_dev
, &res
->surf
,
2517 is_3d
? 0 : view
->base_array_layer
,
2518 is_3d
? view
->base_array_layer
: 0,
2520 &offset_B
, &tile_x_sa
, &tile_y_sa
);
2522 /* We use address and tile offsets to access a single level/layer
2523 * as a subimage, so reset level/layer so it doesn't offset again.
2525 view
->base_array_layer
= 0;
2526 view
->base_level
= 0;
2528 /* Level 0 doesn't require tile offsets, and the hardware can find
2529 * array slices using QPitch even with the format override, so we
2530 * can allow layers in this case. Copy the original ISL surface.
2532 memcpy(&isl_surf
, &res
->surf
, sizeof(isl_surf
));
2535 /* Scale down the image dimensions by the block size. */
2536 const struct isl_format_layout
*fmtl
=
2537 isl_format_get_layout(res
->surf
.format
);
2538 isl_surf
.format
= fmt
.fmt
;
2539 isl_surf
.logical_level0_px
= isl_surf_get_logical_level0_el(&isl_surf
);
2540 isl_surf
.phys_level0_sa
= isl_surf_get_phys_level0_el(&isl_surf
);
2541 tile_x_sa
/= fmtl
->bw
;
2542 tile_y_sa
/= fmtl
->bh
;
2544 psurf
->width
= isl_surf
.logical_level0_px
.width
;
2545 psurf
->height
= isl_surf
.logical_level0_px
.height
;
2547 struct isl_surf_fill_state_info f
= {
2550 .mocs
= mocs(res
->bo
, &screen
->isl_dev
),
2551 .address
= res
->bo
->gtt_offset
+ offset_B
,
2552 .x_offset_sa
= tile_x_sa
,
2553 .y_offset_sa
= tile_y_sa
,
2556 isl_surf_fill_state_s(&screen
->isl_dev
, map
, &f
);
2562 fill_default_image_param(struct brw_image_param
*param
)
2564 memset(param
, 0, sizeof(*param
));
2565 /* Set the swizzling shifts to all-ones to effectively disable swizzling --
2566 * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
2567 * detailed explanation of these parameters.
2569 param
->swizzling
[0] = 0xff;
2570 param
->swizzling
[1] = 0xff;
2574 fill_buffer_image_param(struct brw_image_param
*param
,
2575 enum pipe_format pfmt
,
2578 const unsigned cpp
= util_format_get_blocksize(pfmt
);
2580 fill_default_image_param(param
);
2581 param
->size
[0] = size
/ cpp
;
2582 param
->stride
[0] = cpp
;
2585 #define isl_surf_fill_image_param(x, ...)
2586 #define fill_default_image_param(x, ...)
2587 #define fill_buffer_image_param(x, ...)
2591 * The pipe->set_shader_images() driver hook.
2594 iris_set_shader_images(struct pipe_context
*ctx
,
2595 enum pipe_shader_type p_stage
,
2596 unsigned start_slot
, unsigned count
,
2597 const struct pipe_image_view
*p_images
)
2599 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2600 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2601 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2602 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2603 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2605 struct iris_genx_state
*genx
= ice
->state
.genx
;
2606 struct brw_image_param
*image_params
= genx
->shaders
[stage
].image_param
;
2609 shs
->bound_image_views
&= ~u_bit_consecutive(start_slot
, count
);
2611 for (unsigned i
= 0; i
< count
; i
++) {
2612 struct iris_image_view
*iv
= &shs
->image
[start_slot
+ i
];
2614 if (p_images
&& p_images
[i
].resource
) {
2615 const struct pipe_image_view
*img
= &p_images
[i
];
2616 struct iris_resource
*res
= (void *) img
->resource
;
2619 alloc_surface_states(ice
->state
.surface_uploader
,
2620 &iv
->surface_state
, 1 << ISL_AUX_USAGE_NONE
);
2624 util_copy_image_view(&iv
->base
, img
);
2626 shs
->bound_image_views
|= 1 << (start_slot
+ i
);
2628 res
->bind_history
|= PIPE_BIND_SHADER_IMAGE
;
2629 res
->bind_stages
|= 1 << stage
;
2631 isl_surf_usage_flags_t usage
= ISL_SURF_USAGE_STORAGE_BIT
;
2632 enum isl_format isl_fmt
=
2633 iris_format_for_usage(devinfo
, img
->format
, usage
).fmt
;
2635 bool untyped_fallback
= false;
2637 if (img
->shader_access
& PIPE_IMAGE_ACCESS_READ
) {
2638 /* On Gen8, try to use typed surfaces reads (which support a
2639 * limited number of formats), and if not possible, fall back
2642 untyped_fallback
= GEN_GEN
== 8 &&
2643 !isl_has_matching_typed_storage_image_format(devinfo
, isl_fmt
);
2645 if (untyped_fallback
)
2646 isl_fmt
= ISL_FORMAT_RAW
;
2648 isl_fmt
= isl_lower_storage_image_format(devinfo
, isl_fmt
);
2651 if (res
->base
.target
!= PIPE_BUFFER
) {
2652 struct isl_view view
= {
2654 .base_level
= img
->u
.tex
.level
,
2656 .base_array_layer
= img
->u
.tex
.first_layer
,
2657 .array_len
= img
->u
.tex
.last_layer
- img
->u
.tex
.first_layer
+ 1,
2658 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2662 if (untyped_fallback
) {
2663 fill_buffer_surface_state(&screen
->isl_dev
, res
, map
,
2664 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
2667 /* Images don't support compression */
2668 unsigned aux_modes
= 1 << ISL_AUX_USAGE_NONE
;
2670 enum isl_aux_usage usage
= u_bit_scan(&aux_modes
);
2672 fill_surface_state(&screen
->isl_dev
, map
, res
, &res
->surf
,
2673 &view
, usage
, 0, 0);
2675 map
+= SURFACE_STATE_ALIGNMENT
;
2679 isl_surf_fill_image_param(&screen
->isl_dev
,
2680 &image_params
[start_slot
+ i
],
2683 util_range_add(&res
->base
, &res
->valid_buffer_range
, img
->u
.buf
.offset
,
2684 img
->u
.buf
.offset
+ img
->u
.buf
.size
);
2686 fill_buffer_surface_state(&screen
->isl_dev
, res
, map
,
2687 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
2688 img
->u
.buf
.offset
, img
->u
.buf
.size
);
2689 fill_buffer_image_param(&image_params
[start_slot
+ i
],
2690 img
->format
, img
->u
.buf
.size
);
2693 pipe_resource_reference(&iv
->base
.resource
, NULL
);
2694 pipe_resource_reference(&iv
->surface_state
.res
, NULL
);
2695 fill_default_image_param(&image_params
[start_slot
+ i
]);
2699 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
2701 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
2702 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2704 /* Broadwell also needs brw_image_params re-uploaded */
2706 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
2707 shs
->sysvals_need_upload
= true;
2713 * The pipe->set_sampler_views() driver hook.
2716 iris_set_sampler_views(struct pipe_context
*ctx
,
2717 enum pipe_shader_type p_stage
,
2718 unsigned start
, unsigned count
,
2719 struct pipe_sampler_view
**views
)
2721 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2722 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2723 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2725 shs
->bound_sampler_views
&= ~u_bit_consecutive(start
, count
);
2727 for (unsigned i
= 0; i
< count
; i
++) {
2728 struct pipe_sampler_view
*pview
= views
? views
[i
] : NULL
;
2729 pipe_sampler_view_reference((struct pipe_sampler_view
**)
2730 &shs
->textures
[start
+ i
], pview
);
2731 struct iris_sampler_view
*view
= (void *) pview
;
2733 view
->res
->bind_history
|= PIPE_BIND_SAMPLER_VIEW
;
2734 view
->res
->bind_stages
|= 1 << stage
;
2736 shs
->bound_sampler_views
|= 1 << (start
+ i
);
2740 ice
->state
.dirty
|= (IRIS_DIRTY_BINDINGS_VS
<< stage
);
2742 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
2743 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2747 * The pipe->set_tess_state() driver hook.
2750 iris_set_tess_state(struct pipe_context
*ctx
,
2751 const float default_outer_level
[4],
2752 const float default_inner_level
[2])
2754 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2755 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_TESS_CTRL
];
2757 memcpy(&ice
->state
.default_outer_level
[0], &default_outer_level
[0], 4 * sizeof(float));
2758 memcpy(&ice
->state
.default_inner_level
[0], &default_inner_level
[0], 2 * sizeof(float));
2760 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_TCS
;
2761 shs
->sysvals_need_upload
= true;
2765 iris_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
*p_surf
)
2767 struct iris_surface
*surf
= (void *) p_surf
;
2768 pipe_resource_reference(&p_surf
->texture
, NULL
);
2769 pipe_resource_reference(&surf
->surface_state
.res
, NULL
);
2770 pipe_resource_reference(&surf
->surface_state_read
.res
, NULL
);
2775 iris_set_clip_state(struct pipe_context
*ctx
,
2776 const struct pipe_clip_state
*state
)
2778 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2779 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_VERTEX
];
2780 struct iris_shader_state
*gshs
= &ice
->state
.shaders
[MESA_SHADER_GEOMETRY
];
2781 struct iris_shader_state
*tshs
= &ice
->state
.shaders
[MESA_SHADER_TESS_EVAL
];
2783 memcpy(&ice
->state
.clip_planes
, state
, sizeof(*state
));
2785 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
| IRIS_DIRTY_CONSTANTS_GS
|
2786 IRIS_DIRTY_CONSTANTS_TES
;
2787 shs
->sysvals_need_upload
= true;
2788 gshs
->sysvals_need_upload
= true;
2789 tshs
->sysvals_need_upload
= true;
2793 * The pipe->set_polygon_stipple() driver hook.
2796 iris_set_polygon_stipple(struct pipe_context
*ctx
,
2797 const struct pipe_poly_stipple
*state
)
2799 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2800 memcpy(&ice
->state
.poly_stipple
, state
, sizeof(*state
));
2801 ice
->state
.dirty
|= IRIS_DIRTY_POLYGON_STIPPLE
;
2805 * The pipe->set_sample_mask() driver hook.
2808 iris_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
2810 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2812 /* We only support 16x MSAA, so we have 16 bits of sample maks.
2813 * st/mesa may pass us 0xffffffff though, meaning "enable all samples".
2815 ice
->state
.sample_mask
= sample_mask
& 0xffff;
2816 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLE_MASK
;
2820 * The pipe->set_scissor_states() driver hook.
2822 * This corresponds to our SCISSOR_RECT state structures. It's an
2823 * exact match, so we just store them, and memcpy them out later.
2826 iris_set_scissor_states(struct pipe_context
*ctx
,
2827 unsigned start_slot
,
2828 unsigned num_scissors
,
2829 const struct pipe_scissor_state
*rects
)
2831 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2833 for (unsigned i
= 0; i
< num_scissors
; i
++) {
2834 if (rects
[i
].minx
== rects
[i
].maxx
|| rects
[i
].miny
== rects
[i
].maxy
) {
2835 /* If the scissor was out of bounds and got clamped to 0 width/height
2836 * at the bounds, the subtraction of 1 from maximums could produce a
2837 * negative number and thus not clip anything. Instead, just provide
2838 * a min > max scissor inside the bounds, which produces the expected
2841 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2842 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,
2845 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2846 .minx
= rects
[i
].minx
, .miny
= rects
[i
].miny
,
2847 .maxx
= rects
[i
].maxx
- 1, .maxy
= rects
[i
].maxy
- 1,
2852 ice
->state
.dirty
|= IRIS_DIRTY_SCISSOR_RECT
;
2856 * The pipe->set_stencil_ref() driver hook.
2858 * This is added to 3DSTATE_WM_DEPTH_STENCIL dynamically at draw time.
2861 iris_set_stencil_ref(struct pipe_context
*ctx
,
2862 const struct pipe_stencil_ref
*state
)
2864 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2865 memcpy(&ice
->state
.stencil_ref
, state
, sizeof(*state
));
2867 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
2869 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
2873 viewport_extent(const struct pipe_viewport_state
*state
, int axis
, float sign
)
2875 return copysignf(state
->scale
[axis
], sign
) + state
->translate
[axis
];
2879 * The pipe->set_viewport_states() driver hook.
2881 * This corresponds to our SF_CLIP_VIEWPORT states. We can't calculate
2882 * the guardband yet, as we need the framebuffer dimensions, but we can
2883 * at least fill out the rest.
2886 iris_set_viewport_states(struct pipe_context
*ctx
,
2887 unsigned start_slot
,
2889 const struct pipe_viewport_state
*states
)
2891 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2893 memcpy(&ice
->state
.viewports
[start_slot
], states
, sizeof(*states
) * count
);
2895 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
2897 if (ice
->state
.cso_rast
&& (!ice
->state
.cso_rast
->depth_clip_near
||
2898 !ice
->state
.cso_rast
->depth_clip_far
))
2899 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
2903 * The pipe->set_framebuffer_state() driver hook.
2905 * Sets the current draw FBO, including color render targets, depth,
2906 * and stencil buffers.
2909 iris_set_framebuffer_state(struct pipe_context
*ctx
,
2910 const struct pipe_framebuffer_state
*state
)
2912 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2913 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2914 struct isl_device
*isl_dev
= &screen
->isl_dev
;
2915 struct pipe_framebuffer_state
*cso
= &ice
->state
.framebuffer
;
2916 struct iris_resource
*zres
;
2917 struct iris_resource
*stencil_res
;
2919 unsigned samples
= util_framebuffer_get_num_samples(state
);
2920 unsigned layers
= util_framebuffer_get_num_layers(state
);
2922 if (cso
->samples
!= samples
) {
2923 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
2925 /* We need to toggle 3DSTATE_PS::32 Pixel Dispatch Enable */
2926 if (GEN_GEN
>= 9 && (cso
->samples
== 16 || samples
== 16))
2927 ice
->state
.dirty
|= IRIS_DIRTY_FS
;
2930 if (cso
->nr_cbufs
!= state
->nr_cbufs
) {
2931 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
2934 if ((cso
->layers
== 0) != (layers
== 0)) {
2935 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
2938 if (cso
->width
!= state
->width
|| cso
->height
!= state
->height
) {
2939 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
2942 if (cso
->zsbuf
|| state
->zsbuf
) {
2943 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BUFFER
;
2946 util_copy_framebuffer_state(cso
, state
);
2947 cso
->samples
= samples
;
2948 cso
->layers
= layers
;
2950 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
2952 struct isl_view view
= {
2955 .base_array_layer
= 0,
2957 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2960 struct isl_depth_stencil_hiz_emit_info info
= { .view
= &view
};
2963 iris_get_depth_stencil_resources(cso
->zsbuf
->texture
, &zres
,
2966 view
.base_level
= cso
->zsbuf
->u
.tex
.level
;
2967 view
.base_array_layer
= cso
->zsbuf
->u
.tex
.first_layer
;
2969 cso
->zsbuf
->u
.tex
.last_layer
- cso
->zsbuf
->u
.tex
.first_layer
+ 1;
2972 view
.usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
2974 info
.depth_surf
= &zres
->surf
;
2975 info
.depth_address
= zres
->bo
->gtt_offset
+ zres
->offset
;
2976 info
.mocs
= mocs(zres
->bo
, isl_dev
);
2978 view
.format
= zres
->surf
.format
;
2980 if (iris_resource_level_has_hiz(zres
, view
.base_level
)) {
2981 info
.hiz_usage
= zres
->aux
.usage
;
2982 info
.hiz_surf
= &zres
->aux
.surf
;
2983 info
.hiz_address
= zres
->aux
.bo
->gtt_offset
+ zres
->aux
.offset
;
2988 view
.usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
2989 info
.stencil_aux_usage
= stencil_res
->aux
.usage
;
2990 info
.stencil_surf
= &stencil_res
->surf
;
2991 info
.stencil_address
= stencil_res
->bo
->gtt_offset
+ stencil_res
->offset
;
2993 view
.format
= stencil_res
->surf
.format
;
2994 info
.mocs
= mocs(stencil_res
->bo
, isl_dev
);
2999 isl_emit_depth_stencil_hiz_s(isl_dev
, cso_z
->packets
, &info
);
3001 /* Make a null surface for unbound buffers */
3002 void *null_surf_map
=
3003 upload_state(ice
->state
.surface_uploader
, &ice
->state
.null_fb
,
3004 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
3005 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
,
3006 isl_extent3d(MAX2(cso
->width
, 1),
3007 MAX2(cso
->height
, 1),
3008 cso
->layers
? cso
->layers
: 1));
3009 ice
->state
.null_fb
.offset
+=
3010 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.null_fb
.res
));
3012 /* Render target change */
3013 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_FS
;
3015 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_BUFFER
;
3017 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
3019 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_FRAMEBUFFER
];
3022 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
3026 * The pipe->set_constant_buffer() driver hook.
3028 * This uploads any constant data in user buffers, and references
3029 * any UBO resources containing constant data.
3032 iris_set_constant_buffer(struct pipe_context
*ctx
,
3033 enum pipe_shader_type p_stage
, unsigned index
,
3034 const struct pipe_constant_buffer
*input
)
3036 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3037 gl_shader_stage stage
= stage_from_pipe(p_stage
);
3038 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3039 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[index
];
3041 /* TODO: Only do this if the buffer changes? */
3042 pipe_resource_reference(&shs
->constbuf_surf_state
[index
].res
, NULL
);
3044 if (input
&& input
->buffer_size
&& (input
->buffer
|| input
->user_buffer
)) {
3045 shs
->bound_cbufs
|= 1u << index
;
3047 if (input
->user_buffer
) {
3049 pipe_resource_reference(&cbuf
->buffer
, NULL
);
3050 u_upload_alloc(ice
->ctx
.const_uploader
, 0, input
->buffer_size
, 64,
3051 &cbuf
->buffer_offset
, &cbuf
->buffer
, (void **) &map
);
3053 if (!cbuf
->buffer
) {
3054 /* Allocation was unsuccessful - just unbind */
3055 iris_set_constant_buffer(ctx
, p_stage
, index
, NULL
);
3060 memcpy(map
, input
->user_buffer
, input
->buffer_size
);
3061 } else if (input
->buffer
) {
3062 pipe_resource_reference(&cbuf
->buffer
, input
->buffer
);
3064 cbuf
->buffer_offset
= input
->buffer_offset
;
3068 MIN2(input
->buffer_size
,
3069 iris_resource_bo(cbuf
->buffer
)->size
- cbuf
->buffer_offset
);
3071 struct iris_resource
*res
= (void *) cbuf
->buffer
;
3072 res
->bind_history
|= PIPE_BIND_CONSTANT_BUFFER
;
3073 res
->bind_stages
|= 1 << stage
;
3075 shs
->bound_cbufs
&= ~(1u << index
);
3076 pipe_resource_reference(&cbuf
->buffer
, NULL
);
3079 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
3083 upload_sysvals(struct iris_context
*ice
,
3084 gl_shader_stage stage
)
3086 UNUSED
struct iris_genx_state
*genx
= ice
->state
.genx
;
3087 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3089 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
3090 if (!shader
|| shader
->num_system_values
== 0)
3093 assert(shader
->num_cbufs
> 0);
3095 unsigned sysval_cbuf_index
= shader
->num_cbufs
- 1;
3096 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[sysval_cbuf_index
];
3097 unsigned upload_size
= shader
->num_system_values
* sizeof(uint32_t);
3098 uint32_t *map
= NULL
;
3100 assert(sysval_cbuf_index
< PIPE_MAX_CONSTANT_BUFFERS
);
3101 u_upload_alloc(ice
->ctx
.const_uploader
, 0, upload_size
, 64,
3102 &cbuf
->buffer_offset
, &cbuf
->buffer
, (void **) &map
);
3104 for (int i
= 0; i
< shader
->num_system_values
; i
++) {
3105 uint32_t sysval
= shader
->system_values
[i
];
3108 if (BRW_PARAM_DOMAIN(sysval
) == BRW_PARAM_DOMAIN_IMAGE
) {
3110 unsigned img
= BRW_PARAM_IMAGE_IDX(sysval
);
3111 unsigned offset
= BRW_PARAM_IMAGE_OFFSET(sysval
);
3112 struct brw_image_param
*param
=
3113 &genx
->shaders
[stage
].image_param
[img
];
3115 assert(offset
< sizeof(struct brw_image_param
));
3116 value
= ((uint32_t *) param
)[offset
];
3118 } else if (sysval
== BRW_PARAM_BUILTIN_ZERO
) {
3120 } else if (BRW_PARAM_BUILTIN_IS_CLIP_PLANE(sysval
)) {
3121 int plane
= BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(sysval
);
3122 int comp
= BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(sysval
);
3123 value
= fui(ice
->state
.clip_planes
.ucp
[plane
][comp
]);
3124 } else if (sysval
== BRW_PARAM_BUILTIN_PATCH_VERTICES_IN
) {
3125 if (stage
== MESA_SHADER_TESS_CTRL
) {
3126 value
= ice
->state
.vertices_per_patch
;
3128 assert(stage
== MESA_SHADER_TESS_EVAL
);
3129 const struct shader_info
*tcs_info
=
3130 iris_get_shader_info(ice
, MESA_SHADER_TESS_CTRL
);
3132 value
= tcs_info
->tess
.tcs_vertices_out
;
3134 value
= ice
->state
.vertices_per_patch
;
3136 } else if (sysval
>= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
&&
3137 sysval
<= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W
) {
3138 unsigned i
= sysval
- BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
;
3139 value
= fui(ice
->state
.default_outer_level
[i
]);
3140 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X
) {
3141 value
= fui(ice
->state
.default_inner_level
[0]);
3142 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y
) {
3143 value
= fui(ice
->state
.default_inner_level
[1]);
3145 assert(!"unhandled system value");
3151 cbuf
->buffer_size
= upload_size
;
3152 iris_upload_ubo_ssbo_surf_state(ice
, cbuf
,
3153 &shs
->constbuf_surf_state
[sysval_cbuf_index
], false);
3155 shs
->sysvals_need_upload
= false;
3159 * The pipe->set_shader_buffers() driver hook.
3161 * This binds SSBOs and ABOs. Unfortunately, we need to stream out
3162 * SURFACE_STATE here, as the buffer offset may change each time.
3165 iris_set_shader_buffers(struct pipe_context
*ctx
,
3166 enum pipe_shader_type p_stage
,
3167 unsigned start_slot
, unsigned count
,
3168 const struct pipe_shader_buffer
*buffers
,
3169 unsigned writable_bitmask
)
3171 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3172 gl_shader_stage stage
= stage_from_pipe(p_stage
);
3173 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3175 unsigned modified_bits
= u_bit_consecutive(start_slot
, count
);
3177 shs
->bound_ssbos
&= ~modified_bits
;
3178 shs
->writable_ssbos
&= ~modified_bits
;
3179 shs
->writable_ssbos
|= writable_bitmask
<< start_slot
;
3181 for (unsigned i
= 0; i
< count
; i
++) {
3182 if (buffers
&& buffers
[i
].buffer
) {
3183 struct iris_resource
*res
= (void *) buffers
[i
].buffer
;
3184 struct pipe_shader_buffer
*ssbo
= &shs
->ssbo
[start_slot
+ i
];
3185 struct iris_state_ref
*surf_state
=
3186 &shs
->ssbo_surf_state
[start_slot
+ i
];
3187 pipe_resource_reference(&ssbo
->buffer
, &res
->base
);
3188 ssbo
->buffer_offset
= buffers
[i
].buffer_offset
;
3190 MIN2(buffers
[i
].buffer_size
, res
->bo
->size
- ssbo
->buffer_offset
);
3192 shs
->bound_ssbos
|= 1 << (start_slot
+ i
);
3194 iris_upload_ubo_ssbo_surf_state(ice
, ssbo
, surf_state
, true);
3196 res
->bind_history
|= PIPE_BIND_SHADER_BUFFER
;
3197 res
->bind_stages
|= 1 << stage
;
3199 util_range_add(&res
->base
, &res
->valid_buffer_range
, ssbo
->buffer_offset
,
3200 ssbo
->buffer_offset
+ ssbo
->buffer_size
);
3202 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
].buffer
, NULL
);
3203 pipe_resource_reference(&shs
->ssbo_surf_state
[start_slot
+ i
].res
,
3208 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
3212 iris_delete_state(struct pipe_context
*ctx
, void *state
)
3218 * The pipe->set_vertex_buffers() driver hook.
3220 * This translates pipe_vertex_buffer to our 3DSTATE_VERTEX_BUFFERS packet.
3223 iris_set_vertex_buffers(struct pipe_context
*ctx
,
3224 unsigned start_slot
, unsigned count
,
3225 const struct pipe_vertex_buffer
*buffers
)
3227 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3228 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3229 struct iris_genx_state
*genx
= ice
->state
.genx
;
3231 ice
->state
.bound_vertex_buffers
&= ~u_bit_consecutive64(start_slot
, count
);
3233 for (unsigned i
= 0; i
< count
; i
++) {
3234 const struct pipe_vertex_buffer
*buffer
= buffers
? &buffers
[i
] : NULL
;
3235 struct iris_vertex_buffer_state
*state
=
3236 &genx
->vertex_buffers
[start_slot
+ i
];
3239 pipe_resource_reference(&state
->resource
, NULL
);
3243 /* We may see user buffers that are NULL bindings. */
3244 assert(!(buffer
->is_user_buffer
&& buffer
->buffer
.user
!= NULL
));
3246 pipe_resource_reference(&state
->resource
, buffer
->buffer
.resource
);
3247 struct iris_resource
*res
= (void *) state
->resource
;
3249 state
->offset
= (int) buffer
->buffer_offset
;
3252 ice
->state
.bound_vertex_buffers
|= 1ull << (start_slot
+ i
);
3253 res
->bind_history
|= PIPE_BIND_VERTEX_BUFFER
;
3256 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
3257 vb
.VertexBufferIndex
= start_slot
+ i
;
3258 vb
.AddressModifyEnable
= true;
3259 vb
.BufferPitch
= buffer
->stride
;
3261 vb
.BufferSize
= res
->bo
->size
- (int) buffer
->buffer_offset
;
3262 vb
.BufferStartingAddress
=
3263 ro_bo(NULL
, res
->bo
->gtt_offset
+ (int) buffer
->buffer_offset
);
3264 vb
.MOCS
= mocs(res
->bo
, &screen
->isl_dev
);
3266 vb
.NullVertexBuffer
= true;
3271 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
3275 * Gallium CSO for vertex elements.
3277 struct iris_vertex_element_state
{
3278 uint32_t vertex_elements
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
3279 uint32_t vf_instancing
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
3280 uint32_t edgeflag_ve
[GENX(VERTEX_ELEMENT_STATE_length
)];
3281 uint32_t edgeflag_vfi
[GENX(3DSTATE_VF_INSTANCING_length
)];
3286 * The pipe->create_vertex_elements() driver hook.
3288 * This translates pipe_vertex_element to our 3DSTATE_VERTEX_ELEMENTS
3289 * and 3DSTATE_VF_INSTANCING commands. The vertex_elements and vf_instancing
3290 * arrays are ready to be emitted at draw time if no EdgeFlag or SGVs are
3291 * needed. In these cases we will need information available at draw time.
3292 * We setup edgeflag_ve and edgeflag_vfi as alternatives last
3293 * 3DSTATE_VERTEX_ELEMENT and 3DSTATE_VF_INSTANCING that can be used at
3294 * draw time if we detect that EdgeFlag is needed by the Vertex Shader.
3297 iris_create_vertex_elements(struct pipe_context
*ctx
,
3299 const struct pipe_vertex_element
*state
)
3301 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3302 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
3303 struct iris_vertex_element_state
*cso
=
3304 malloc(sizeof(struct iris_vertex_element_state
));
3308 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
), cso
->vertex_elements
, ve
) {
3310 1 + GENX(VERTEX_ELEMENT_STATE_length
) * MAX2(count
, 1) - 2;
3313 uint32_t *ve_pack_dest
= &cso
->vertex_elements
[1];
3314 uint32_t *vfi_pack_dest
= cso
->vf_instancing
;
3317 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
3319 ve
.SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
3320 ve
.Component0Control
= VFCOMP_STORE_0
;
3321 ve
.Component1Control
= VFCOMP_STORE_0
;
3322 ve
.Component2Control
= VFCOMP_STORE_0
;
3323 ve
.Component3Control
= VFCOMP_STORE_1_FP
;
3326 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
3330 for (int i
= 0; i
< count
; i
++) {
3331 const struct iris_format_info fmt
=
3332 iris_format_for_usage(devinfo
, state
[i
].src_format
, 0);
3333 unsigned comp
[4] = { VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
,
3334 VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
};
3336 switch (isl_format_get_num_channels(fmt
.fmt
)) {
3337 case 0: comp
[0] = VFCOMP_STORE_0
; /* fallthrough */
3338 case 1: comp
[1] = VFCOMP_STORE_0
; /* fallthrough */
3339 case 2: comp
[2] = VFCOMP_STORE_0
; /* fallthrough */
3341 comp
[3] = isl_format_has_int_channel(fmt
.fmt
) ? VFCOMP_STORE_1_INT
3342 : VFCOMP_STORE_1_FP
;
3345 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
3346 ve
.EdgeFlagEnable
= false;
3347 ve
.VertexBufferIndex
= state
[i
].vertex_buffer_index
;
3349 ve
.SourceElementOffset
= state
[i
].src_offset
;
3350 ve
.SourceElementFormat
= fmt
.fmt
;
3351 ve
.Component0Control
= comp
[0];
3352 ve
.Component1Control
= comp
[1];
3353 ve
.Component2Control
= comp
[2];
3354 ve
.Component3Control
= comp
[3];
3357 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
3358 vi
.VertexElementIndex
= i
;
3359 vi
.InstancingEnable
= state
[i
].instance_divisor
> 0;
3360 vi
.InstanceDataStepRate
= state
[i
].instance_divisor
;
3363 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
3364 vfi_pack_dest
+= GENX(3DSTATE_VF_INSTANCING_length
);
3367 /* An alternative version of the last VE and VFI is stored so it
3368 * can be used at draw time in case Vertex Shader uses EdgeFlag
3371 const unsigned edgeflag_index
= count
- 1;
3372 const struct iris_format_info fmt
=
3373 iris_format_for_usage(devinfo
, state
[edgeflag_index
].src_format
, 0);
3374 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), cso
->edgeflag_ve
, ve
) {
3375 ve
.EdgeFlagEnable
= true ;
3376 ve
.VertexBufferIndex
= state
[edgeflag_index
].vertex_buffer_index
;
3378 ve
.SourceElementOffset
= state
[edgeflag_index
].src_offset
;
3379 ve
.SourceElementFormat
= fmt
.fmt
;
3380 ve
.Component0Control
= VFCOMP_STORE_SRC
;
3381 ve
.Component1Control
= VFCOMP_STORE_0
;
3382 ve
.Component2Control
= VFCOMP_STORE_0
;
3383 ve
.Component3Control
= VFCOMP_STORE_0
;
3385 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), cso
->edgeflag_vfi
, vi
) {
3386 /* The vi.VertexElementIndex of the EdgeFlag Vertex Element is filled
3387 * at draw time, as it should change if SGVs are emitted.
3389 vi
.InstancingEnable
= state
[edgeflag_index
].instance_divisor
> 0;
3390 vi
.InstanceDataStepRate
= state
[edgeflag_index
].instance_divisor
;
3398 * The pipe->bind_vertex_elements_state() driver hook.
3401 iris_bind_vertex_elements_state(struct pipe_context
*ctx
, void *state
)
3403 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3404 struct iris_vertex_element_state
*old_cso
= ice
->state
.cso_vertex_elements
;
3405 struct iris_vertex_element_state
*new_cso
= state
;
3407 /* 3DSTATE_VF_SGVs overrides the last VE, so if the count is changing,
3408 * we need to re-emit it to ensure we're overriding the right one.
3410 if (new_cso
&& cso_changed(count
))
3411 ice
->state
.dirty
|= IRIS_DIRTY_VF_SGVS
;
3413 ice
->state
.cso_vertex_elements
= state
;
3414 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_ELEMENTS
;
3418 * The pipe->create_stream_output_target() driver hook.
3420 * "Target" here refers to a destination buffer. We translate this into
3421 * a 3DSTATE_SO_BUFFER packet. We can handle most fields, but don't yet
3422 * know which buffer this represents, or whether we ought to zero the
3423 * write-offsets, or append. Those are handled in the set() hook.
3425 static struct pipe_stream_output_target
*
3426 iris_create_stream_output_target(struct pipe_context
*ctx
,
3427 struct pipe_resource
*p_res
,
3428 unsigned buffer_offset
,
3429 unsigned buffer_size
)
3431 struct iris_resource
*res
= (void *) p_res
;
3432 struct iris_stream_output_target
*cso
= calloc(1, sizeof(*cso
));
3436 res
->bind_history
|= PIPE_BIND_STREAM_OUTPUT
;
3438 pipe_reference_init(&cso
->base
.reference
, 1);
3439 pipe_resource_reference(&cso
->base
.buffer
, p_res
);
3440 cso
->base
.buffer_offset
= buffer_offset
;
3441 cso
->base
.buffer_size
= buffer_size
;
3442 cso
->base
.context
= ctx
;
3444 util_range_add(&res
->base
, &res
->valid_buffer_range
, buffer_offset
,
3445 buffer_offset
+ buffer_size
);
3447 upload_state(ctx
->stream_uploader
, &cso
->offset
, sizeof(uint32_t), 4);
3453 iris_stream_output_target_destroy(struct pipe_context
*ctx
,
3454 struct pipe_stream_output_target
*state
)
3456 struct iris_stream_output_target
*cso
= (void *) state
;
3458 pipe_resource_reference(&cso
->base
.buffer
, NULL
);
3459 pipe_resource_reference(&cso
->offset
.res
, NULL
);
3465 * The pipe->set_stream_output_targets() driver hook.
3467 * At this point, we know which targets are bound to a particular index,
3468 * and also whether we want to append or start over. We can finish the
3469 * 3DSTATE_SO_BUFFER packets we started earlier.
3472 iris_set_stream_output_targets(struct pipe_context
*ctx
,
3473 unsigned num_targets
,
3474 struct pipe_stream_output_target
**targets
,
3475 const unsigned *offsets
)
3477 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3478 struct iris_genx_state
*genx
= ice
->state
.genx
;
3479 uint32_t *so_buffers
= genx
->so_buffers
;
3480 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3482 const bool active
= num_targets
> 0;
3483 if (ice
->state
.streamout_active
!= active
) {
3484 ice
->state
.streamout_active
= active
;
3485 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
3487 /* We only emit 3DSTATE_SO_DECL_LIST when streamout is active, because
3488 * it's a non-pipelined command. If we're switching streamout on, we
3489 * may have missed emitting it earlier, so do so now. (We're already
3490 * taking a stall to update 3DSTATE_SO_BUFFERS anyway...)
3493 ice
->state
.dirty
|= IRIS_DIRTY_SO_DECL_LIST
;
3496 for (int i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
3497 struct iris_stream_output_target
*tgt
=
3498 (void *) ice
->state
.so_target
[i
];
3500 struct iris_resource
*res
= (void *) tgt
->base
.buffer
;
3502 flush
|= iris_flush_bits_for_history(res
);
3503 iris_dirty_for_history(ice
, res
);
3506 iris_emit_pipe_control_flush(&ice
->batches
[IRIS_BATCH_RENDER
],
3507 "make streamout results visible", flush
);
3511 for (int i
= 0; i
< 4; i
++) {
3512 pipe_so_target_reference(&ice
->state
.so_target
[i
],
3513 i
< num_targets
? targets
[i
] : NULL
);
3516 /* No need to update 3DSTATE_SO_BUFFER unless SOL is active. */
3520 for (unsigned i
= 0; i
< 4; i
++,
3521 so_buffers
+= GENX(3DSTATE_SO_BUFFER_length
)) {
3523 struct iris_stream_output_target
*tgt
= (void *) ice
->state
.so_target
[i
];
3524 unsigned offset
= offsets
[i
];
3527 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
) {
3529 sob
.SOBufferIndex
= i
;
3531 sob
._3DCommandOpcode
= 0;
3532 sob
._3DCommandSubOpcode
= SO_BUFFER_INDEX_0_CMD
+ i
;
3538 struct iris_resource
*res
= (void *) tgt
->base
.buffer
;
3540 /* Note that offsets[i] will either be 0, causing us to zero
3541 * the value in the buffer, or 0xFFFFFFFF, which happens to mean
3542 * "continue appending at the existing offset."
3544 assert(offset
== 0 || offset
== 0xFFFFFFFF);
3546 /* We might be called by Begin (offset = 0), Pause, then Resume
3547 * (offset = 0xFFFFFFFF) before ever drawing (where these commands
3548 * will actually be sent to the GPU). In this case, we don't want
3549 * to append - we still want to do our initial zeroing.
3554 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
) {
3556 sob
.SOBufferIndex
= i
;
3558 sob
._3DCommandOpcode
= 0;
3559 sob
._3DCommandSubOpcode
= SO_BUFFER_INDEX_0_CMD
+ i
;
3561 sob
.SurfaceBaseAddress
=
3562 rw_bo(NULL
, res
->bo
->gtt_offset
+ tgt
->base
.buffer_offset
);
3563 sob
.SOBufferEnable
= true;
3564 sob
.StreamOffsetWriteEnable
= true;
3565 sob
.StreamOutputBufferOffsetAddressEnable
= true;
3566 sob
.MOCS
= mocs(res
->bo
, &screen
->isl_dev
);
3568 sob
.SurfaceSize
= MAX2(tgt
->base
.buffer_size
/ 4, 1) - 1;
3569 sob
.StreamOffset
= offset
;
3570 sob
.StreamOutputBufferOffsetAddress
=
3571 rw_bo(NULL
, iris_resource_bo(tgt
->offset
.res
)->gtt_offset
+
3572 tgt
->offset
.offset
);
3576 ice
->state
.dirty
|= IRIS_DIRTY_SO_BUFFERS
;
3580 * An iris-vtable helper for encoding the 3DSTATE_SO_DECL_LIST and
3581 * 3DSTATE_STREAMOUT packets.
3583 * 3DSTATE_SO_DECL_LIST is a list of shader outputs we want the streamout
3584 * hardware to record. We can create it entirely based on the shader, with
3585 * no dynamic state dependencies.
3587 * 3DSTATE_STREAMOUT is an annoying mix of shader-based information and
3588 * state-based settings. We capture the shader-related ones here, and merge
3589 * the rest in at draw time.
3592 iris_create_so_decl_list(const struct pipe_stream_output_info
*info
,
3593 const struct brw_vue_map
*vue_map
)
3595 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
3596 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3597 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3598 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3600 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
3602 memset(so_decl
, 0, sizeof(so_decl
));
3604 /* Construct the list of SO_DECLs to be emitted. The formatting of the
3605 * command feels strange -- each dword pair contains a SO_DECL per stream.
3607 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
3608 const struct pipe_stream_output
*output
= &info
->output
[i
];
3609 const int buffer
= output
->output_buffer
;
3610 const int varying
= output
->register_index
;
3611 const unsigned stream_id
= output
->stream
;
3612 assert(stream_id
< MAX_VERTEX_STREAMS
);
3614 buffer_mask
[stream_id
] |= 1 << buffer
;
3616 assert(vue_map
->varying_to_slot
[varying
] >= 0);
3618 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
3619 * array. Instead, it simply increments DstOffset for the following
3620 * input by the number of components that should be skipped.
3622 * Our hardware is unusual in that it requires us to program SO_DECLs
3623 * for fake "hole" components, rather than simply taking the offset
3624 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
3625 * program as many size = 4 holes as we can, then a final hole to
3626 * accommodate the final 1, 2, or 3 remaining.
3628 int skip_components
= output
->dst_offset
- next_offset
[buffer
];
3630 while (skip_components
> 0) {
3631 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3633 .OutputBufferSlot
= output
->output_buffer
,
3634 .ComponentMask
= (1 << MIN2(skip_components
, 4)) - 1,
3636 skip_components
-= 4;
3639 next_offset
[buffer
] = output
->dst_offset
+ output
->num_components
;
3641 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3642 .OutputBufferSlot
= output
->output_buffer
,
3643 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
3645 ((1 << output
->num_components
) - 1) << output
->start_component
,
3648 if (decls
[stream_id
] > max_decls
)
3649 max_decls
= decls
[stream_id
];
3652 unsigned dwords
= GENX(3DSTATE_STREAMOUT_length
) + (3 + 2 * max_decls
);
3653 uint32_t *map
= ralloc_size(NULL
, sizeof(uint32_t) * dwords
);
3654 uint32_t *so_decl_map
= map
+ GENX(3DSTATE_STREAMOUT_length
);
3656 iris_pack_command(GENX(3DSTATE_STREAMOUT
), map
, sol
) {
3657 int urb_entry_read_offset
= 0;
3658 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
3659 urb_entry_read_offset
;
3661 /* We always read the whole vertex. This could be reduced at some
3662 * point by reading less and offsetting the register index in the
3665 sol
.Stream0VertexReadOffset
= urb_entry_read_offset
;
3666 sol
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
3667 sol
.Stream1VertexReadOffset
= urb_entry_read_offset
;
3668 sol
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
3669 sol
.Stream2VertexReadOffset
= urb_entry_read_offset
;
3670 sol
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
3671 sol
.Stream3VertexReadOffset
= urb_entry_read_offset
;
3672 sol
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
3674 /* Set buffer pitches; 0 means unbound. */
3675 sol
.Buffer0SurfacePitch
= 4 * info
->stride
[0];
3676 sol
.Buffer1SurfacePitch
= 4 * info
->stride
[1];
3677 sol
.Buffer2SurfacePitch
= 4 * info
->stride
[2];
3678 sol
.Buffer3SurfacePitch
= 4 * info
->stride
[3];
3681 iris_pack_command(GENX(3DSTATE_SO_DECL_LIST
), so_decl_map
, list
) {
3682 list
.DWordLength
= 3 + 2 * max_decls
- 2;
3683 list
.StreamtoBufferSelects0
= buffer_mask
[0];
3684 list
.StreamtoBufferSelects1
= buffer_mask
[1];
3685 list
.StreamtoBufferSelects2
= buffer_mask
[2];
3686 list
.StreamtoBufferSelects3
= buffer_mask
[3];
3687 list
.NumEntries0
= decls
[0];
3688 list
.NumEntries1
= decls
[1];
3689 list
.NumEntries2
= decls
[2];
3690 list
.NumEntries3
= decls
[3];
3693 for (int i
= 0; i
< max_decls
; i
++) {
3694 iris_pack_state(GENX(SO_DECL_ENTRY
), so_decl_map
+ 3 + i
* 2, entry
) {
3695 entry
.Stream0Decl
= so_decl
[0][i
];
3696 entry
.Stream1Decl
= so_decl
[1][i
];
3697 entry
.Stream2Decl
= so_decl
[2][i
];
3698 entry
.Stream3Decl
= so_decl
[3][i
];
3706 iris_compute_sbe_urb_read_interval(uint64_t fs_input_slots
,
3707 const struct brw_vue_map
*last_vue_map
,
3708 bool two_sided_color
,
3709 unsigned *out_offset
,
3710 unsigned *out_length
)
3712 /* The compiler computes the first URB slot without considering COL/BFC
3713 * swizzling (because it doesn't know whether it's enabled), so we need
3714 * to do that here too. This may result in a smaller offset, which
3717 const unsigned first_slot
=
3718 brw_compute_first_urb_slot_required(fs_input_slots
, last_vue_map
);
3720 /* This becomes the URB read offset (counted in pairs of slots). */
3721 assert(first_slot
% 2 == 0);
3722 *out_offset
= first_slot
/ 2;
3724 /* We need to adjust the inputs read to account for front/back color
3725 * swizzling, as it can make the URB length longer.
3727 for (int c
= 0; c
<= 1; c
++) {
3728 if (fs_input_slots
& (VARYING_BIT_COL0
<< c
)) {
3729 /* If two sided color is enabled, the fragment shader's gl_Color
3730 * (COL0) input comes from either the gl_FrontColor (COL0) or
3731 * gl_BackColor (BFC0) input varyings. Mark BFC as used, too.
3733 if (two_sided_color
)
3734 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3736 /* If front color isn't written, we opt to give them back color
3737 * instead of an undefined value. Switch from COL to BFC.
3739 if (last_vue_map
->varying_to_slot
[VARYING_SLOT_COL0
+ c
] == -1) {
3740 fs_input_slots
&= ~(VARYING_BIT_COL0
<< c
);
3741 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3746 /* Compute the minimum URB Read Length necessary for the FS inputs.
3748 * From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
3749 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
3751 * "This field should be set to the minimum length required to read the
3752 * maximum source attribute. The maximum source attribute is indicated
3753 * by the maximum value of the enabled Attribute # Source Attribute if
3754 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
3755 * enable is not set.
3756 * read_length = ceiling((max_source_attr + 1) / 2)
3758 * [errata] Corruption/Hang possible if length programmed larger than
3761 * Similar text exists for Ivy Bridge.
3763 * We find the last URB slot that's actually read by the FS.
3765 unsigned last_read_slot
= last_vue_map
->num_slots
- 1;
3766 while (last_read_slot
> first_slot
&& !(fs_input_slots
&
3767 (1ull << last_vue_map
->slot_to_varying
[last_read_slot
])))
3770 /* The URB read length is the difference of the two, counted in pairs. */
3771 *out_length
= DIV_ROUND_UP(last_read_slot
- first_slot
+ 1, 2);
3775 iris_emit_sbe_swiz(struct iris_batch
*batch
,
3776 const struct iris_context
*ice
,
3777 unsigned urb_read_offset
,
3778 unsigned sprite_coord_enables
)
3780 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = {};
3781 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3782 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3783 const struct brw_vue_map
*vue_map
= ice
->shaders
.last_vue_map
;
3784 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3786 /* XXX: this should be generated when putting programs in place */
3788 for (int fs_attr
= 0; fs_attr
< VARYING_SLOT_MAX
; fs_attr
++) {
3789 const int input_index
= wm_prog_data
->urb_setup
[fs_attr
];
3790 if (input_index
< 0 || input_index
>= 16)
3793 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
=
3794 &attr_overrides
[input_index
];
3795 int slot
= vue_map
->varying_to_slot
[fs_attr
];
3797 /* Viewport and Layer are stored in the VUE header. We need to override
3798 * them to zero if earlier stages didn't write them, as GL requires that
3799 * they read back as zero when not explicitly set.
3802 case VARYING_SLOT_VIEWPORT
:
3803 case VARYING_SLOT_LAYER
:
3804 attr
->ComponentOverrideX
= true;
3805 attr
->ComponentOverrideW
= true;
3806 attr
->ConstantSource
= CONST_0000
;
3808 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
3809 attr
->ComponentOverrideY
= true;
3810 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
3811 attr
->ComponentOverrideZ
= true;
3814 case VARYING_SLOT_PRIMITIVE_ID
:
3815 /* Override if the previous shader stage didn't write gl_PrimitiveID. */
3817 attr
->ComponentOverrideX
= true;
3818 attr
->ComponentOverrideY
= true;
3819 attr
->ComponentOverrideZ
= true;
3820 attr
->ComponentOverrideW
= true;
3821 attr
->ConstantSource
= PRIM_ID
;
3829 if (sprite_coord_enables
& (1 << input_index
))
3832 /* If there was only a back color written but not front, use back
3833 * as the color instead of undefined.
3835 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
3836 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
3837 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
3838 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
3840 /* Not written by the previous stage - undefined. */
3842 attr
->ComponentOverrideX
= true;
3843 attr
->ComponentOverrideY
= true;
3844 attr
->ComponentOverrideZ
= true;
3845 attr
->ComponentOverrideW
= true;
3846 attr
->ConstantSource
= CONST_0001_FLOAT
;
3850 /* Compute the location of the attribute relative to the read offset,
3851 * which is counted in 256-bit increments (two 128-bit VUE slots).
3853 const int source_attr
= slot
- 2 * urb_read_offset
;
3854 assert(source_attr
>= 0 && source_attr
<= 32);
3855 attr
->SourceAttribute
= source_attr
;
3857 /* If we are doing two-sided color, and the VUE slot following this one
3858 * represents a back-facing color, then we need to instruct the SF unit
3859 * to do back-facing swizzling.
3861 if (cso_rast
->light_twoside
&&
3862 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
3863 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
3864 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
3865 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
)))
3866 attr
->SwizzleSelect
= INPUTATTR_FACING
;
3869 iris_emit_cmd(batch
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
3870 for (int i
= 0; i
< 16; i
++)
3871 sbes
.Attribute
[i
] = attr_overrides
[i
];
3876 iris_calculate_point_sprite_overrides(const struct brw_wm_prog_data
*prog_data
,
3877 const struct iris_rasterizer_state
*cso
)
3879 unsigned overrides
= 0;
3881 if (prog_data
->urb_setup
[VARYING_SLOT_PNTC
] != -1)
3882 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_PNTC
];
3884 for (int i
= 0; i
< 8; i
++) {
3885 if ((cso
->sprite_coord_enable
& (1 << i
)) &&
3886 prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
] != -1)
3887 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
];
3894 iris_emit_sbe(struct iris_batch
*batch
, const struct iris_context
*ice
)
3896 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3897 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3898 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3899 const struct shader_info
*fs_info
=
3900 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
3902 unsigned urb_read_offset
, urb_read_length
;
3903 iris_compute_sbe_urb_read_interval(fs_info
->inputs_read
,
3904 ice
->shaders
.last_vue_map
,
3905 cso_rast
->light_twoside
,
3906 &urb_read_offset
, &urb_read_length
);
3908 unsigned sprite_coord_overrides
=
3909 iris_calculate_point_sprite_overrides(wm_prog_data
, cso_rast
);
3911 iris_emit_cmd(batch
, GENX(3DSTATE_SBE
), sbe
) {
3912 sbe
.AttributeSwizzleEnable
= true;
3913 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
3914 sbe
.PointSpriteTextureCoordinateOrigin
= cso_rast
->sprite_coord_mode
;
3915 sbe
.VertexURBEntryReadOffset
= urb_read_offset
;
3916 sbe
.VertexURBEntryReadLength
= urb_read_length
;
3917 sbe
.ForceVertexURBEntryReadOffset
= true;
3918 sbe
.ForceVertexURBEntryReadLength
= true;
3919 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
3920 sbe
.PointSpriteTextureCoordinateEnable
= sprite_coord_overrides
;
3922 for (int i
= 0; i
< 32; i
++) {
3923 sbe
.AttributeActiveComponentFormat
[i
] = ACTIVE_COMPONENT_XYZW
;
3928 iris_emit_sbe_swiz(batch
, ice
, urb_read_offset
, sprite_coord_overrides
);
3931 /* ------------------------------------------------------------------- */
3934 * Populate VS program key fields based on the current state.
3937 iris_populate_vs_key(const struct iris_context
*ice
,
3938 const struct shader_info
*info
,
3939 gl_shader_stage last_stage
,
3940 struct brw_vs_prog_key
*key
)
3942 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3944 if (info
->clip_distance_array_size
== 0 &&
3945 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
3946 last_stage
== MESA_SHADER_VERTEX
)
3947 key
->nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
3951 * Populate TCS program key fields based on the current state.
3954 iris_populate_tcs_key(const struct iris_context
*ice
,
3955 struct brw_tcs_prog_key
*key
)
3960 * Populate TES program key fields based on the current state.
3963 iris_populate_tes_key(const struct iris_context
*ice
,
3964 const struct shader_info
*info
,
3965 gl_shader_stage last_stage
,
3966 struct brw_tes_prog_key
*key
)
3968 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3970 if (info
->clip_distance_array_size
== 0 &&
3971 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
3972 last_stage
== MESA_SHADER_TESS_EVAL
)
3973 key
->nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
3977 * Populate GS program key fields based on the current state.
3980 iris_populate_gs_key(const struct iris_context
*ice
,
3981 const struct shader_info
*info
,
3982 gl_shader_stage last_stage
,
3983 struct brw_gs_prog_key
*key
)
3985 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3987 if (info
->clip_distance_array_size
== 0 &&
3988 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
3989 last_stage
== MESA_SHADER_GEOMETRY
)
3990 key
->nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
3994 * Populate FS program key fields based on the current state.
3997 iris_populate_fs_key(const struct iris_context
*ice
,
3998 const struct shader_info
*info
,
3999 struct brw_wm_prog_key
*key
)
4001 struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
4002 const struct pipe_framebuffer_state
*fb
= &ice
->state
.framebuffer
;
4003 const struct iris_depth_stencil_alpha_state
*zsa
= ice
->state
.cso_zsa
;
4004 const struct iris_rasterizer_state
*rast
= ice
->state
.cso_rast
;
4005 const struct iris_blend_state
*blend
= ice
->state
.cso_blend
;
4007 key
->nr_color_regions
= fb
->nr_cbufs
;
4009 key
->clamp_fragment_color
= rast
->clamp_fragment_color
;
4011 key
->alpha_to_coverage
= blend
->alpha_to_coverage
;
4013 key
->alpha_test_replicate_alpha
= fb
->nr_cbufs
> 1 && zsa
->alpha
.enabled
;
4015 key
->flat_shade
= rast
->flatshade
&&
4016 (info
->inputs_read
& (VARYING_BIT_COL0
| VARYING_BIT_COL1
));
4018 key
->persample_interp
= rast
->force_persample_interp
;
4019 key
->multisample_fbo
= rast
->multisample
&& fb
->samples
> 1;
4021 key
->coherent_fb_fetch
= GEN_GEN
>= 9;
4023 key
->force_dual_color_blend
=
4024 screen
->driconf
.dual_color_blend_by_location
&&
4025 (blend
->blend_enables
& 1) && blend
->dual_color_blending
;
4027 /* TODO: Respect glHint for key->high_quality_derivatives */
4031 iris_populate_cs_key(const struct iris_context
*ice
,
4032 struct brw_cs_prog_key
*key
)
4037 KSP(const struct iris_compiled_shader
*shader
)
4039 struct iris_resource
*res
= (void *) shader
->assembly
.res
;
4040 return iris_bo_offset_from_base_address(res
->bo
) + shader
->assembly
.offset
;
4043 /* Gen11 workaround table #2056 WABTPPrefetchDisable suggests to disable
4044 * prefetching of binding tables in A0 and B0 steppings. XXX: Revisit
4045 * this WA on C0 stepping.
4047 * TODO: Fill out SamplerCount for prefetching?
4050 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix, stage) \
4051 pkt.KernelStartPointer = KSP(shader); \
4052 pkt.BindingTableEntryCount = GEN_GEN == 11 ? 0 : \
4053 shader->bt.size_bytes / 4; \
4054 pkt.FloatingPointMode = prog_data->use_alt_mode; \
4056 pkt.DispatchGRFStartRegisterForURBData = \
4057 prog_data->dispatch_grf_start_reg; \
4058 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
4059 pkt.prefix##URBEntryReadOffset = 0; \
4061 pkt.StatisticsEnable = true; \
4062 pkt.Enable = true; \
4064 if (prog_data->total_scratch) { \
4065 struct iris_bo *bo = \
4066 iris_get_scratch_space(ice, prog_data->total_scratch, stage); \
4067 uint32_t scratch_addr = bo->gtt_offset; \
4068 pkt.PerThreadScratchSpace = ffs(prog_data->total_scratch) - 11; \
4069 pkt.ScratchSpaceBasePointer = rw_bo(NULL, scratch_addr); \
4073 * Encode most of 3DSTATE_VS based on the compiled shader.
4076 iris_store_vs_state(struct iris_context
*ice
,
4077 const struct gen_device_info
*devinfo
,
4078 struct iris_compiled_shader
*shader
)
4080 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4081 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4083 iris_pack_command(GENX(3DSTATE_VS
), shader
->derived_data
, vs
) {
4084 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
, MESA_SHADER_VERTEX
);
4085 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
4086 vs
.SIMD8DispatchEnable
= true;
4087 vs
.UserClipDistanceCullTestEnableBitmask
=
4088 vue_prog_data
->cull_distance_mask
;
4093 * Encode most of 3DSTATE_HS based on the compiled shader.
4096 iris_store_tcs_state(struct iris_context
*ice
,
4097 const struct gen_device_info
*devinfo
,
4098 struct iris_compiled_shader
*shader
)
4100 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4101 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4102 struct brw_tcs_prog_data
*tcs_prog_data
= (void *) prog_data
;
4104 iris_pack_command(GENX(3DSTATE_HS
), shader
->derived_data
, hs
) {
4105 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
, MESA_SHADER_TESS_CTRL
);
4107 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
4108 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
4109 hs
.IncludeVertexHandles
= true;
4112 hs
.DispatchMode
= vue_prog_data
->dispatch_mode
;
4113 hs
.IncludePrimitiveID
= tcs_prog_data
->include_primitive_id
;
4119 * Encode 3DSTATE_TE and most of 3DSTATE_DS based on the compiled shader.
4122 iris_store_tes_state(struct iris_context
*ice
,
4123 const struct gen_device_info
*devinfo
,
4124 struct iris_compiled_shader
*shader
)
4126 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4127 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4128 struct brw_tes_prog_data
*tes_prog_data
= (void *) prog_data
;
4130 uint32_t *te_state
= (void *) shader
->derived_data
;
4131 uint32_t *ds_state
= te_state
+ GENX(3DSTATE_TE_length
);
4133 iris_pack_command(GENX(3DSTATE_TE
), te_state
, te
) {
4134 te
.Partitioning
= tes_prog_data
->partitioning
;
4135 te
.OutputTopology
= tes_prog_data
->output_topology
;
4136 te
.TEDomain
= tes_prog_data
->domain
;
4138 te
.MaximumTessellationFactorOdd
= 63.0;
4139 te
.MaximumTessellationFactorNotOdd
= 64.0;
4142 iris_pack_command(GENX(3DSTATE_DS
), ds_state
, ds
) {
4143 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
, MESA_SHADER_TESS_EVAL
);
4145 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
4146 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
4147 ds
.ComputeWCoordinateEnable
=
4148 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
4150 ds
.UserClipDistanceCullTestEnableBitmask
=
4151 vue_prog_data
->cull_distance_mask
;
4157 * Encode most of 3DSTATE_GS based on the compiled shader.
4160 iris_store_gs_state(struct iris_context
*ice
,
4161 const struct gen_device_info
*devinfo
,
4162 struct iris_compiled_shader
*shader
)
4164 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4165 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4166 struct brw_gs_prog_data
*gs_prog_data
= (void *) prog_data
;
4168 iris_pack_command(GENX(3DSTATE_GS
), shader
->derived_data
, gs
) {
4169 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
, MESA_SHADER_GEOMETRY
);
4171 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
4172 gs
.OutputTopology
= gs_prog_data
->output_topology
;
4173 gs
.ControlDataHeaderSize
=
4174 gs_prog_data
->control_data_header_size_hwords
;
4175 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
4176 gs
.DispatchMode
= DISPATCH_MODE_SIMD8
;
4177 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
4178 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
4179 gs
.ReorderMode
= TRAILING
;
4180 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
4181 gs
.MaximumNumberofThreads
=
4182 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
4183 : (devinfo
->max_gs_threads
- 1);
4185 if (gs_prog_data
->static_vertex_count
!= -1) {
4186 gs
.StaticOutput
= true;
4187 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
4189 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
4191 gs
.UserClipDistanceCullTestEnableBitmask
=
4192 vue_prog_data
->cull_distance_mask
;
4194 const int urb_entry_write_offset
= 1;
4195 const uint32_t urb_entry_output_length
=
4196 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
4197 urb_entry_write_offset
;
4199 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
4200 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
4205 * Encode most of 3DSTATE_PS and 3DSTATE_PS_EXTRA based on the shader.
4208 iris_store_fs_state(struct iris_context
*ice
,
4209 const struct gen_device_info
*devinfo
,
4210 struct iris_compiled_shader
*shader
)
4212 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4213 struct brw_wm_prog_data
*wm_prog_data
= (void *) shader
->prog_data
;
4215 uint32_t *ps_state
= (void *) shader
->derived_data
;
4216 uint32_t *psx_state
= ps_state
+ GENX(3DSTATE_PS_length
);
4218 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
4219 ps
.VectorMaskEnable
= true;
4220 // XXX: WABTPPrefetchDisable, see above, drop at C0
4221 ps
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 :
4222 shader
->bt
.size_bytes
/ 4;
4223 ps
.FloatingPointMode
= prog_data
->use_alt_mode
;
4224 ps
.MaximumNumberofThreadsPerPSD
= 64 - (GEN_GEN
== 8 ? 2 : 1);
4226 ps
.PushConstantEnable
= prog_data
->ubo_ranges
[0].length
> 0;
4228 /* From the documentation for this packet:
4229 * "If the PS kernel does not need the Position XY Offsets to
4230 * compute a Position Value, then this field should be programmed
4231 * to POSOFFSET_NONE."
4233 * "SW Recommendation: If the PS kernel needs the Position Offsets
4234 * to compute a Position XY value, this field should match Position
4235 * ZW Interpolation Mode to ensure a consistent position.xyzw
4238 * We only require XY sample offsets. So, this recommendation doesn't
4239 * look useful at the moment. We might need this in future.
4241 ps
.PositionXYOffsetSelect
=
4242 wm_prog_data
->uses_pos_offset
? POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
4244 if (prog_data
->total_scratch
) {
4245 struct iris_bo
*bo
=
4246 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
4247 MESA_SHADER_FRAGMENT
);
4248 uint32_t scratch_addr
= bo
->gtt_offset
;
4249 ps
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
4250 ps
.ScratchSpaceBasePointer
= rw_bo(NULL
, scratch_addr
);
4254 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
4255 psx
.PixelShaderValid
= true;
4256 psx
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
4257 psx
.PixelShaderKillsPixel
= wm_prog_data
->uses_kill
;
4258 psx
.AttributeEnable
= wm_prog_data
->num_varying_inputs
!= 0;
4259 psx
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
4260 psx
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
4261 psx
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
4262 psx
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
4265 psx
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
4266 psx
.PixelShaderComputesStencil
= wm_prog_data
->computed_stencil
;
4272 * Compute the size of the derived data (shader command packets).
4274 * This must match the data written by the iris_store_xs_state() functions.
4277 iris_store_cs_state(struct iris_context
*ice
,
4278 const struct gen_device_info
*devinfo
,
4279 struct iris_compiled_shader
*shader
)
4281 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4282 struct brw_cs_prog_data
*cs_prog_data
= (void *) shader
->prog_data
;
4283 void *map
= shader
->derived_data
;
4285 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), map
, desc
) {
4286 desc
.KernelStartPointer
= KSP(shader
);
4287 desc
.ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
;
4288 desc
.NumberofThreadsinGPGPUThreadGroup
= cs_prog_data
->threads
;
4289 desc
.SharedLocalMemorySize
=
4290 encode_slm_size(GEN_GEN
, prog_data
->total_shared
);
4291 desc
.BarrierEnable
= cs_prog_data
->uses_barrier
;
4292 desc
.CrossThreadConstantDataReadLength
=
4293 cs_prog_data
->push
.cross_thread
.regs
;
4298 iris_derived_program_state_size(enum iris_program_cache_id cache_id
)
4300 assert(cache_id
<= IRIS_CACHE_BLORP
);
4302 static const unsigned dwords
[] = {
4303 [IRIS_CACHE_VS
] = GENX(3DSTATE_VS_length
),
4304 [IRIS_CACHE_TCS
] = GENX(3DSTATE_HS_length
),
4305 [IRIS_CACHE_TES
] = GENX(3DSTATE_TE_length
) + GENX(3DSTATE_DS_length
),
4306 [IRIS_CACHE_GS
] = GENX(3DSTATE_GS_length
),
4308 GENX(3DSTATE_PS_length
) + GENX(3DSTATE_PS_EXTRA_length
),
4309 [IRIS_CACHE_CS
] = GENX(INTERFACE_DESCRIPTOR_DATA_length
),
4310 [IRIS_CACHE_BLORP
] = 0,
4313 return sizeof(uint32_t) * dwords
[cache_id
];
4317 * Create any state packets corresponding to the given shader stage
4318 * (i.e. 3DSTATE_VS) and save them as "derived data" in the shader variant.
4319 * This means that we can look up a program in the in-memory cache and
4320 * get most of the state packet without having to reconstruct it.
4323 iris_store_derived_program_state(struct iris_context
*ice
,
4324 enum iris_program_cache_id cache_id
,
4325 struct iris_compiled_shader
*shader
)
4327 struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
4328 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
4332 iris_store_vs_state(ice
, devinfo
, shader
);
4334 case IRIS_CACHE_TCS
:
4335 iris_store_tcs_state(ice
, devinfo
, shader
);
4337 case IRIS_CACHE_TES
:
4338 iris_store_tes_state(ice
, devinfo
, shader
);
4341 iris_store_gs_state(ice
, devinfo
, shader
);
4344 iris_store_fs_state(ice
, devinfo
, shader
);
4347 iris_store_cs_state(ice
, devinfo
, shader
);
4348 case IRIS_CACHE_BLORP
:
4355 /* ------------------------------------------------------------------- */
4357 static const uint32_t push_constant_opcodes
[] = {
4358 [MESA_SHADER_VERTEX
] = 21,
4359 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
4360 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
4361 [MESA_SHADER_GEOMETRY
] = 22,
4362 [MESA_SHADER_FRAGMENT
] = 23,
4363 [MESA_SHADER_COMPUTE
] = 0,
4367 use_null_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
4369 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.unbound_tex
.res
);
4371 iris_use_pinned_bo(batch
, state_bo
, false);
4373 return ice
->state
.unbound_tex
.offset
;
4377 use_null_fb_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
4379 /* If set_framebuffer_state() was never called, fall back to 1x1x1 */
4380 if (!ice
->state
.null_fb
.res
)
4381 return use_null_surface(batch
, ice
);
4383 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.null_fb
.res
);
4385 iris_use_pinned_bo(batch
, state_bo
, false);
4387 return ice
->state
.null_fb
.offset
;
4391 surf_state_offset_for_aux(struct iris_resource
*res
,
4393 enum isl_aux_usage aux_usage
)
4395 return SURFACE_STATE_ALIGNMENT
*
4396 util_bitcount(aux_modes
& ((1 << aux_usage
) - 1));
4401 surf_state_update_clear_value(struct iris_batch
*batch
,
4402 struct iris_resource
*res
,
4403 struct iris_state_ref
*state
,
4405 enum isl_aux_usage aux_usage
)
4407 struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
4408 struct iris_bo
*state_bo
= iris_resource_bo(state
->res
);
4409 uint64_t real_offset
= state
->offset
+ IRIS_MEMZONE_BINDER_START
;
4410 uint32_t offset_into_bo
= real_offset
- state_bo
->gtt_offset
;
4411 uint32_t clear_offset
= offset_into_bo
+
4412 isl_dev
->ss
.clear_value_offset
+
4413 surf_state_offset_for_aux(res
, aux_modes
, aux_usage
);
4414 uint32_t *color
= res
->aux
.clear_color
.u32
;
4416 assert(isl_dev
->ss
.clear_value_size
== 16);
4418 if (aux_usage
== ISL_AUX_USAGE_HIZ
) {
4419 iris_emit_pipe_control_write(batch
, "update fast clear value (Z)",
4420 PIPE_CONTROL_WRITE_IMMEDIATE
,
4421 state_bo
, clear_offset
, color
[0]);
4423 iris_emit_pipe_control_write(batch
, "update fast clear color (RG__)",
4424 PIPE_CONTROL_WRITE_IMMEDIATE
,
4425 state_bo
, clear_offset
,
4426 (uint64_t) color
[0] |
4427 (uint64_t) color
[1] << 32);
4428 iris_emit_pipe_control_write(batch
, "update fast clear color (__BA)",
4429 PIPE_CONTROL_WRITE_IMMEDIATE
,
4430 state_bo
, clear_offset
+ 8,
4431 (uint64_t) color
[2] |
4432 (uint64_t) color
[3] << 32);
4435 iris_emit_pipe_control_flush(batch
,
4436 "update fast clear: state cache invalidate",
4437 PIPE_CONTROL_FLUSH_ENABLE
|
4438 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
4443 update_clear_value(struct iris_context
*ice
,
4444 struct iris_batch
*batch
,
4445 struct iris_resource
*res
,
4446 struct iris_state_ref
*state
,
4447 unsigned all_aux_modes
,
4448 struct isl_view
*view
)
4450 UNUSED
struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
4451 UNUSED
unsigned aux_modes
= all_aux_modes
;
4453 /* We only need to update the clear color in the surface state for gen8 and
4454 * gen9. Newer gens can read it directly from the clear color state buffer.
4457 /* Skip updating the ISL_AUX_USAGE_NONE surface state */
4458 aux_modes
&= ~(1 << ISL_AUX_USAGE_NONE
);
4461 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
4463 surf_state_update_clear_value(batch
, res
, state
, all_aux_modes
,
4467 pipe_resource_reference(&state
->res
, NULL
);
4469 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
4470 state
, all_aux_modes
);
4472 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
4473 fill_surface_state(isl_dev
, map
, res
, &res
->surf
, view
, aux_usage
, 0, 0);
4474 map
+= SURFACE_STATE_ALIGNMENT
;
4480 * Add a surface to the validation list, as well as the buffer containing
4481 * the corresponding SURFACE_STATE.
4483 * Returns the binding table entry (offset to SURFACE_STATE).
4486 use_surface(struct iris_context
*ice
,
4487 struct iris_batch
*batch
,
4488 struct pipe_surface
*p_surf
,
4490 enum isl_aux_usage aux_usage
,
4491 bool is_read_surface
)
4493 struct iris_surface
*surf
= (void *) p_surf
;
4494 struct iris_resource
*res
= (void *) p_surf
->texture
;
4495 uint32_t offset
= 0;
4497 iris_use_pinned_bo(batch
, iris_resource_bo(p_surf
->texture
), writeable
);
4498 if (GEN_GEN
== 8 && is_read_surface
) {
4499 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state_read
.res
), false);
4501 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state
.res
), false);
4505 iris_use_pinned_bo(batch
, res
->aux
.bo
, writeable
);
4506 if (res
->aux
.clear_color_bo
)
4507 iris_use_pinned_bo(batch
, res
->aux
.clear_color_bo
, false);
4509 if (memcmp(&res
->aux
.clear_color
, &surf
->clear_color
,
4510 sizeof(surf
->clear_color
)) != 0) {
4511 update_clear_value(ice
, batch
, res
, &surf
->surface_state
,
4512 res
->aux
.possible_usages
, &surf
->view
);
4514 update_clear_value(ice
, batch
, res
, &surf
->surface_state_read
,
4515 res
->aux
.possible_usages
, &surf
->read_view
);
4517 surf
->clear_color
= res
->aux
.clear_color
;
4521 offset
= (GEN_GEN
== 8 && is_read_surface
) ? surf
->surface_state_read
.offset
4522 : surf
->surface_state
.offset
;
4525 surf_state_offset_for_aux(res
, res
->aux
.possible_usages
, aux_usage
);
4529 use_sampler_view(struct iris_context
*ice
,
4530 struct iris_batch
*batch
,
4531 struct iris_sampler_view
*isv
)
4534 enum isl_aux_usage aux_usage
=
4535 iris_resource_texture_aux_usage(ice
, isv
->res
, isv
->view
.format
, 0);
4537 iris_use_pinned_bo(batch
, isv
->res
->bo
, false);
4538 iris_use_pinned_bo(batch
, iris_resource_bo(isv
->surface_state
.res
), false);
4540 if (isv
->res
->aux
.bo
) {
4541 iris_use_pinned_bo(batch
, isv
->res
->aux
.bo
, false);
4542 if (isv
->res
->aux
.clear_color_bo
)
4543 iris_use_pinned_bo(batch
, isv
->res
->aux
.clear_color_bo
, false);
4544 if (memcmp(&isv
->res
->aux
.clear_color
, &isv
->clear_color
,
4545 sizeof(isv
->clear_color
)) != 0) {
4546 update_clear_value(ice
, batch
, isv
->res
, &isv
->surface_state
,
4547 isv
->res
->aux
.sampler_usages
, &isv
->view
);
4548 isv
->clear_color
= isv
->res
->aux
.clear_color
;
4552 return isv
->surface_state
.offset
+
4553 surf_state_offset_for_aux(isv
->res
, isv
->res
->aux
.sampler_usages
,
4558 use_ubo_ssbo(struct iris_batch
*batch
,
4559 struct iris_context
*ice
,
4560 struct pipe_shader_buffer
*buf
,
4561 struct iris_state_ref
*surf_state
,
4564 if (!buf
->buffer
|| !surf_state
->res
)
4565 return use_null_surface(batch
, ice
);
4567 iris_use_pinned_bo(batch
, iris_resource_bo(buf
->buffer
), writable
);
4568 iris_use_pinned_bo(batch
, iris_resource_bo(surf_state
->res
), false);
4570 return surf_state
->offset
;
4574 use_image(struct iris_batch
*batch
, struct iris_context
*ice
,
4575 struct iris_shader_state
*shs
, int i
)
4577 struct iris_image_view
*iv
= &shs
->image
[i
];
4578 struct iris_resource
*res
= (void *) iv
->base
.resource
;
4581 return use_null_surface(batch
, ice
);
4583 bool write
= iv
->base
.shader_access
& PIPE_IMAGE_ACCESS_WRITE
;
4585 iris_use_pinned_bo(batch
, res
->bo
, write
);
4586 iris_use_pinned_bo(batch
, iris_resource_bo(iv
->surface_state
.res
), false);
4589 iris_use_pinned_bo(batch
, res
->aux
.bo
, write
);
4591 return iv
->surface_state
.offset
;
4594 #define push_bt_entry(addr) \
4595 assert(addr >= binder_addr); \
4596 assert(s < shader->bt.size_bytes / sizeof(uint32_t)); \
4597 if (!pin_only) bt_map[s++] = (addr) - binder_addr;
4599 #define bt_assert(section) \
4600 if (!pin_only && shader->bt.used_mask[section] != 0) \
4601 assert(shader->bt.offsets[section] == s);
4604 * Populate the binding table for a given shader stage.
4606 * This fills out the table of pointers to surfaces required by the shader,
4607 * and also adds those buffers to the validation list so the kernel can make
4608 * resident before running our batch.
4611 iris_populate_binding_table(struct iris_context
*ice
,
4612 struct iris_batch
*batch
,
4613 gl_shader_stage stage
,
4616 const struct iris_binder
*binder
= &ice
->state
.binder
;
4617 struct iris_uncompiled_shader
*ish
= ice
->shaders
.uncompiled
[stage
];
4618 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4622 struct iris_binding_table
*bt
= &shader
->bt
;
4623 UNUSED
struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4624 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4625 uint32_t binder_addr
= binder
->bo
->gtt_offset
;
4627 uint32_t *bt_map
= binder
->map
+ binder
->bt_offset
[stage
];
4630 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
4632 /* TCS passthrough doesn't need a binding table. */
4633 assert(stage
== MESA_SHADER_TESS_CTRL
);
4637 if (stage
== MESA_SHADER_COMPUTE
&&
4638 shader
->bt
.used_mask
[IRIS_SURFACE_GROUP_CS_WORK_GROUPS
]) {
4639 /* surface for gl_NumWorkGroups */
4640 struct iris_state_ref
*grid_data
= &ice
->state
.grid_size
;
4641 struct iris_state_ref
*grid_state
= &ice
->state
.grid_surf_state
;
4642 iris_use_pinned_bo(batch
, iris_resource_bo(grid_data
->res
), false);
4643 iris_use_pinned_bo(batch
, iris_resource_bo(grid_state
->res
), false);
4644 push_bt_entry(grid_state
->offset
);
4647 if (stage
== MESA_SHADER_FRAGMENT
) {
4648 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4649 /* Note that cso_fb->nr_cbufs == fs_key->nr_color_regions. */
4650 if (cso_fb
->nr_cbufs
) {
4651 for (unsigned i
= 0; i
< cso_fb
->nr_cbufs
; i
++) {
4653 if (cso_fb
->cbufs
[i
]) {
4654 addr
= use_surface(ice
, batch
, cso_fb
->cbufs
[i
], true,
4655 ice
->state
.draw_aux_usage
[i
], false);
4657 addr
= use_null_fb_surface(batch
, ice
);
4659 push_bt_entry(addr
);
4661 } else if (GEN_GEN
< 11) {
4662 uint32_t addr
= use_null_fb_surface(batch
, ice
);
4663 push_bt_entry(addr
);
4667 #define foreach_surface_used(index, group) \
4669 for (int index = 0; index < bt->sizes[group]; index++) \
4670 if (iris_group_index_to_bti(bt, group, index) != \
4671 IRIS_SURFACE_NOT_USED)
4673 foreach_surface_used(i
, IRIS_SURFACE_GROUP_RENDER_TARGET_READ
) {
4674 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4676 if (cso_fb
->cbufs
[i
]) {
4677 addr
= use_surface(ice
, batch
, cso_fb
->cbufs
[i
],
4678 true, ice
->state
.draw_aux_usage
[i
], true);
4679 push_bt_entry(addr
);
4683 foreach_surface_used(i
, IRIS_SURFACE_GROUP_TEXTURE
) {
4684 struct iris_sampler_view
*view
= shs
->textures
[i
];
4685 uint32_t addr
= view
? use_sampler_view(ice
, batch
, view
)
4686 : use_null_surface(batch
, ice
);
4687 push_bt_entry(addr
);
4690 foreach_surface_used(i
, IRIS_SURFACE_GROUP_IMAGE
) {
4691 uint32_t addr
= use_image(batch
, ice
, shs
, i
);
4692 push_bt_entry(addr
);
4695 foreach_surface_used(i
, IRIS_SURFACE_GROUP_UBO
) {
4698 if (i
== bt
->sizes
[IRIS_SURFACE_GROUP_UBO
] - 1) {
4699 if (ish
->const_data
) {
4700 iris_use_pinned_bo(batch
, iris_resource_bo(ish
->const_data
), false);
4701 iris_use_pinned_bo(batch
, iris_resource_bo(ish
->const_data_state
.res
),
4703 addr
= ish
->const_data_state
.offset
;
4705 /* This can only happen with INTEL_DISABLE_COMPACT_BINDING_TABLE=1. */
4706 addr
= use_null_surface(batch
, ice
);
4709 addr
= use_ubo_ssbo(batch
, ice
, &shs
->constbuf
[i
],
4710 &shs
->constbuf_surf_state
[i
], false);
4713 push_bt_entry(addr
);
4716 foreach_surface_used(i
, IRIS_SURFACE_GROUP_SSBO
) {
4718 use_ubo_ssbo(batch
, ice
, &shs
->ssbo
[i
], &shs
->ssbo_surf_state
[i
],
4719 shs
->writable_ssbos
& (1u << i
));
4720 push_bt_entry(addr
);
4724 /* XXX: YUV surfaces not implemented yet */
4725 bt_assert(plane_start
[1], ...);
4726 bt_assert(plane_start
[2], ...);
4731 iris_use_optional_res(struct iris_batch
*batch
,
4732 struct pipe_resource
*res
,
4736 struct iris_bo
*bo
= iris_resource_bo(res
);
4737 iris_use_pinned_bo(batch
, bo
, writeable
);
4742 pin_depth_and_stencil_buffers(struct iris_batch
*batch
,
4743 struct pipe_surface
*zsbuf
,
4744 struct iris_depth_stencil_alpha_state
*cso_zsa
)
4749 struct iris_resource
*zres
, *sres
;
4750 iris_get_depth_stencil_resources(zsbuf
->texture
, &zres
, &sres
);
4753 iris_use_pinned_bo(batch
, zres
->bo
, cso_zsa
->depth_writes_enabled
);
4755 iris_use_pinned_bo(batch
, zres
->aux
.bo
,
4756 cso_zsa
->depth_writes_enabled
);
4761 iris_use_pinned_bo(batch
, sres
->bo
, cso_zsa
->stencil_writes_enabled
);
4765 /* ------------------------------------------------------------------- */
4768 * Pin any BOs which were installed by a previous batch, and restored
4769 * via the hardware logical context mechanism.
4771 * We don't need to re-emit all state every batch - the hardware context
4772 * mechanism will save and restore it for us. This includes pointers to
4773 * various BOs...which won't exist unless we ask the kernel to pin them
4774 * by adding them to the validation list.
4776 * We can skip buffers if we've re-emitted those packets, as we're
4777 * overwriting those stale pointers with new ones, and don't actually
4778 * refer to the old BOs.
4781 iris_restore_render_saved_bos(struct iris_context
*ice
,
4782 struct iris_batch
*batch
,
4783 const struct pipe_draw_info
*draw
)
4785 struct iris_genx_state
*genx
= ice
->state
.genx
;
4787 const uint64_t clean
= ~ice
->state
.dirty
;
4789 if (clean
& IRIS_DIRTY_CC_VIEWPORT
) {
4790 iris_use_optional_res(batch
, ice
->state
.last_res
.cc_vp
, false);
4793 if (clean
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
4794 iris_use_optional_res(batch
, ice
->state
.last_res
.sf_cl_vp
, false);
4797 if (clean
& IRIS_DIRTY_BLEND_STATE
) {
4798 iris_use_optional_res(batch
, ice
->state
.last_res
.blend
, false);
4801 if (clean
& IRIS_DIRTY_COLOR_CALC_STATE
) {
4802 iris_use_optional_res(batch
, ice
->state
.last_res
.color_calc
, false);
4805 if (clean
& IRIS_DIRTY_SCISSOR_RECT
) {
4806 iris_use_optional_res(batch
, ice
->state
.last_res
.scissor
, false);
4809 if (ice
->state
.streamout_active
&& (clean
& IRIS_DIRTY_SO_BUFFERS
)) {
4810 for (int i
= 0; i
< 4; i
++) {
4811 struct iris_stream_output_target
*tgt
=
4812 (void *) ice
->state
.so_target
[i
];
4814 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
4816 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
4822 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4823 if (!(clean
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
4826 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4827 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4832 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
4834 for (int i
= 0; i
< 4; i
++) {
4835 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
4837 if (range
->length
== 0)
4840 /* Range block is a binding table index, map back to UBO index. */
4841 unsigned block_index
= iris_bti_to_group_index(
4842 &shader
->bt
, IRIS_SURFACE_GROUP_UBO
, range
->block
);
4843 assert(block_index
!= IRIS_SURFACE_NOT_USED
);
4845 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[block_index
];
4846 struct iris_resource
*res
= (void *) cbuf
->buffer
;
4849 iris_use_pinned_bo(batch
, res
->bo
, false);
4851 iris_use_pinned_bo(batch
, batch
->screen
->workaround_bo
, false);
4855 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4856 if (clean
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
4857 /* Re-pin any buffers referred to by the binding table. */
4858 iris_populate_binding_table(ice
, batch
, stage
, true);
4862 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4863 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4864 struct pipe_resource
*res
= shs
->sampler_table
.res
;
4866 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4869 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4870 if (clean
& (IRIS_DIRTY_VS
<< stage
)) {
4871 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4874 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
4875 iris_use_pinned_bo(batch
, bo
, false);
4877 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4879 if (prog_data
->total_scratch
> 0) {
4880 struct iris_bo
*bo
=
4881 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
4882 iris_use_pinned_bo(batch
, bo
, true);
4888 if ((clean
& IRIS_DIRTY_DEPTH_BUFFER
) &&
4889 (clean
& IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
4890 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4891 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
4894 iris_use_optional_res(batch
, ice
->state
.last_res
.index_buffer
, false);
4896 if (clean
& IRIS_DIRTY_VERTEX_BUFFERS
) {
4897 uint64_t bound
= ice
->state
.bound_vertex_buffers
;
4899 const int i
= u_bit_scan64(&bound
);
4900 struct pipe_resource
*res
= genx
->vertex_buffers
[i
].resource
;
4901 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4907 iris_restore_compute_saved_bos(struct iris_context
*ice
,
4908 struct iris_batch
*batch
,
4909 const struct pipe_grid_info
*grid
)
4911 const uint64_t clean
= ~ice
->state
.dirty
;
4913 const int stage
= MESA_SHADER_COMPUTE
;
4914 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4916 if (clean
& IRIS_DIRTY_BINDINGS_CS
) {
4917 /* Re-pin any buffers referred to by the binding table. */
4918 iris_populate_binding_table(ice
, batch
, stage
, true);
4921 struct pipe_resource
*sampler_res
= shs
->sampler_table
.res
;
4923 iris_use_pinned_bo(batch
, iris_resource_bo(sampler_res
), false);
4925 if ((clean
& IRIS_DIRTY_SAMPLER_STATES_CS
) &&
4926 (clean
& IRIS_DIRTY_BINDINGS_CS
) &&
4927 (clean
& IRIS_DIRTY_CONSTANTS_CS
) &&
4928 (clean
& IRIS_DIRTY_CS
)) {
4929 iris_use_optional_res(batch
, ice
->state
.last_res
.cs_desc
, false);
4932 if (clean
& IRIS_DIRTY_CS
) {
4933 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4936 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
4937 iris_use_pinned_bo(batch
, bo
, false);
4939 struct iris_bo
*curbe_bo
=
4940 iris_resource_bo(ice
->state
.last_res
.cs_thread_ids
);
4941 iris_use_pinned_bo(batch
, curbe_bo
, false);
4943 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4945 if (prog_data
->total_scratch
> 0) {
4946 struct iris_bo
*bo
=
4947 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
4948 iris_use_pinned_bo(batch
, bo
, true);
4955 * Possibly emit STATE_BASE_ADDRESS to update Surface State Base Address.
4958 iris_update_surface_base_address(struct iris_batch
*batch
,
4959 struct iris_binder
*binder
)
4961 if (batch
->last_surface_base_address
== binder
->bo
->gtt_offset
)
4964 uint32_t mocs
= batch
->screen
->isl_dev
.mocs
.internal
;
4966 flush_before_state_base_change(batch
);
4968 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
4969 sba
.SurfaceStateBaseAddressModifyEnable
= true;
4970 sba
.SurfaceStateBaseAddress
= ro_bo(binder
->bo
, 0);
4972 /* The hardware appears to pay attention to the MOCS fields even
4973 * if you don't set the "Address Modify Enable" bit for the base.
4975 sba
.GeneralStateMOCS
= mocs
;
4976 sba
.StatelessDataPortAccessMOCS
= mocs
;
4977 sba
.DynamicStateMOCS
= mocs
;
4978 sba
.IndirectObjectMOCS
= mocs
;
4979 sba
.InstructionMOCS
= mocs
;
4980 sba
.SurfaceStateMOCS
= mocs
;
4982 sba
.BindlessSurfaceStateMOCS
= mocs
;
4986 flush_after_state_base_change(batch
);
4988 batch
->last_surface_base_address
= binder
->bo
->gtt_offset
;
4992 iris_viewport_zmin_zmax(const struct pipe_viewport_state
*vp
, bool halfz
,
4993 bool window_space_position
, float *zmin
, float *zmax
)
4995 if (window_space_position
) {
5000 util_viewport_zmin_zmax(vp
, halfz
, zmin
, zmax
);
5005 genX(emit_aux_map_state
)(struct iris_batch
*batch
)
5007 struct iris_screen
*screen
= batch
->screen
;
5008 void *aux_map_ctx
= iris_bufmgr_get_aux_map_context(screen
->bufmgr
);
5011 uint32_t aux_map_state_num
= gen_aux_map_get_state_num(aux_map_ctx
);
5012 if (batch
->last_aux_map_state
!= aux_map_state_num
) {
5013 /* If the aux-map state number increased, then we need to rewrite the
5014 * register. Rewriting the register is used to both set the aux-map
5015 * translation table address, and also to invalidate any previously
5016 * cached translations.
5018 uint64_t base_addr
= gen_aux_map_get_base(aux_map_ctx
);
5019 assert(base_addr
!= 0 && ALIGN(base_addr
, 32 * 1024) == base_addr
);
5020 iris_load_register_imm64(batch
, GENX(GFX_AUX_TABLE_BASE_ADDR_num
),
5022 batch
->last_aux_map_state
= aux_map_state_num
;
5028 iris_upload_dirty_render_state(struct iris_context
*ice
,
5029 struct iris_batch
*batch
,
5030 const struct pipe_draw_info
*draw
)
5032 const uint64_t dirty
= ice
->state
.dirty
;
5034 if (!(dirty
& IRIS_ALL_DIRTY_FOR_RENDER
))
5037 struct iris_genx_state
*genx
= ice
->state
.genx
;
5038 struct iris_binder
*binder
= &ice
->state
.binder
;
5039 struct brw_wm_prog_data
*wm_prog_data
= (void *)
5040 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
5042 if (dirty
& IRIS_DIRTY_CC_VIEWPORT
) {
5043 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5044 uint32_t cc_vp_address
;
5046 /* XXX: could avoid streaming for depth_clip [0,1] case. */
5047 uint32_t *cc_vp_map
=
5048 stream_state(batch
, ice
->state
.dynamic_uploader
,
5049 &ice
->state
.last_res
.cc_vp
,
5050 4 * ice
->state
.num_viewports
*
5051 GENX(CC_VIEWPORT_length
), 32, &cc_vp_address
);
5052 for (int i
= 0; i
< ice
->state
.num_viewports
; i
++) {
5054 iris_viewport_zmin_zmax(&ice
->state
.viewports
[i
], cso_rast
->clip_halfz
,
5055 ice
->state
.window_space_position
,
5057 if (cso_rast
->depth_clip_near
)
5059 if (cso_rast
->depth_clip_far
)
5062 iris_pack_state(GENX(CC_VIEWPORT
), cc_vp_map
, ccv
) {
5063 ccv
.MinimumDepth
= zmin
;
5064 ccv
.MaximumDepth
= zmax
;
5067 cc_vp_map
+= GENX(CC_VIEWPORT_length
);
5070 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), ptr
) {
5071 ptr
.CCViewportPointer
= cc_vp_address
;
5075 if (dirty
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
5076 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5077 uint32_t sf_cl_vp_address
;
5079 stream_state(batch
, ice
->state
.dynamic_uploader
,
5080 &ice
->state
.last_res
.sf_cl_vp
,
5081 4 * ice
->state
.num_viewports
*
5082 GENX(SF_CLIP_VIEWPORT_length
), 64, &sf_cl_vp_address
);
5084 for (unsigned i
= 0; i
< ice
->state
.num_viewports
; i
++) {
5085 const struct pipe_viewport_state
*state
= &ice
->state
.viewports
[i
];
5086 float gb_xmin
, gb_xmax
, gb_ymin
, gb_ymax
;
5088 float vp_xmin
= viewport_extent(state
, 0, -1.0f
);
5089 float vp_xmax
= viewport_extent(state
, 0, 1.0f
);
5090 float vp_ymin
= viewport_extent(state
, 1, -1.0f
);
5091 float vp_ymax
= viewport_extent(state
, 1, 1.0f
);
5093 gen_calculate_guardband_size(cso_fb
->width
, cso_fb
->height
,
5094 state
->scale
[0], state
->scale
[1],
5095 state
->translate
[0], state
->translate
[1],
5096 &gb_xmin
, &gb_xmax
, &gb_ymin
, &gb_ymax
);
5098 iris_pack_state(GENX(SF_CLIP_VIEWPORT
), vp_map
, vp
) {
5099 vp
.ViewportMatrixElementm00
= state
->scale
[0];
5100 vp
.ViewportMatrixElementm11
= state
->scale
[1];
5101 vp
.ViewportMatrixElementm22
= state
->scale
[2];
5102 vp
.ViewportMatrixElementm30
= state
->translate
[0];
5103 vp
.ViewportMatrixElementm31
= state
->translate
[1];
5104 vp
.ViewportMatrixElementm32
= state
->translate
[2];
5105 vp
.XMinClipGuardband
= gb_xmin
;
5106 vp
.XMaxClipGuardband
= gb_xmax
;
5107 vp
.YMinClipGuardband
= gb_ymin
;
5108 vp
.YMaxClipGuardband
= gb_ymax
;
5109 vp
.XMinViewPort
= MAX2(vp_xmin
, 0);
5110 vp
.XMaxViewPort
= MIN2(vp_xmax
, cso_fb
->width
) - 1;
5111 vp
.YMinViewPort
= MAX2(vp_ymin
, 0);
5112 vp
.YMaxViewPort
= MIN2(vp_ymax
, cso_fb
->height
) - 1;
5115 vp_map
+= GENX(SF_CLIP_VIEWPORT_length
);
5118 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
5119 ptr
.SFClipViewportPointer
= sf_cl_vp_address
;
5123 if (dirty
& IRIS_DIRTY_URB
) {
5126 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
5127 if (!ice
->shaders
.prog
[i
]) {
5130 struct brw_vue_prog_data
*vue_prog_data
=
5131 (void *) ice
->shaders
.prog
[i
]->prog_data
;
5132 size
[i
] = vue_prog_data
->urb_entry_size
;
5134 assert(size
[i
] != 0);
5137 genX(emit_urb_setup
)(ice
, batch
, size
,
5138 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
] != NULL
,
5139 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] != NULL
);
5142 if (dirty
& IRIS_DIRTY_BLEND_STATE
) {
5143 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
5144 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5145 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
5146 const int header_dwords
= GENX(BLEND_STATE_length
);
5148 /* Always write at least one BLEND_STATE - the final RT message will
5149 * reference BLEND_STATE[0] even if there aren't color writes. There
5150 * may still be alpha testing, computed depth, and so on.
5152 const int rt_dwords
=
5153 MAX2(cso_fb
->nr_cbufs
, 1) * GENX(BLEND_STATE_ENTRY_length
);
5155 uint32_t blend_offset
;
5156 uint32_t *blend_map
=
5157 stream_state(batch
, ice
->state
.dynamic_uploader
,
5158 &ice
->state
.last_res
.blend
,
5159 4 * (header_dwords
+ rt_dwords
), 64, &blend_offset
);
5161 uint32_t blend_state_header
;
5162 iris_pack_state(GENX(BLEND_STATE
), &blend_state_header
, bs
) {
5163 bs
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
5164 bs
.AlphaTestFunction
= translate_compare_func(cso_zsa
->alpha
.func
);
5167 blend_map
[0] = blend_state_header
| cso_blend
->blend_state
[0];
5168 memcpy(&blend_map
[1], &cso_blend
->blend_state
[1], 4 * rt_dwords
);
5170 iris_emit_cmd(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
5171 ptr
.BlendStatePointer
= blend_offset
;
5172 ptr
.BlendStatePointerValid
= true;
5176 if (dirty
& IRIS_DIRTY_COLOR_CALC_STATE
) {
5177 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
5179 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
5183 stream_state(batch
, ice
->state
.dynamic_uploader
,
5184 &ice
->state
.last_res
.color_calc
,
5185 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length
),
5187 iris_pack_state(GENX(COLOR_CALC_STATE
), cc_map
, cc
) {
5188 cc
.AlphaTestFormat
= ALPHATEST_FLOAT32
;
5189 cc
.AlphaReferenceValueAsFLOAT32
= cso
->alpha
.ref_value
;
5190 cc
.BlendConstantColorRed
= ice
->state
.blend_color
.color
[0];
5191 cc
.BlendConstantColorGreen
= ice
->state
.blend_color
.color
[1];
5192 cc
.BlendConstantColorBlue
= ice
->state
.blend_color
.color
[2];
5193 cc
.BlendConstantColorAlpha
= ice
->state
.blend_color
.color
[3];
5195 cc
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
5196 cc
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
5199 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
5200 ptr
.ColorCalcStatePointer
= cc_offset
;
5201 ptr
.ColorCalcStatePointerValid
= true;
5205 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5206 if (!(dirty
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
5209 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5210 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5215 if (shs
->sysvals_need_upload
)
5216 upload_sysvals(ice
, stage
);
5218 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
5220 iris_emit_cmd(batch
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
5221 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
5223 /* The Skylake PRM contains the following restriction:
5225 * "The driver must ensure The following case does not occur
5226 * without a flush to the 3D engine: 3DSTATE_CONSTANT_* with
5227 * buffer 3 read length equal to zero committed followed by a
5228 * 3DSTATE_CONSTANT_* with buffer 0 read length not equal to
5231 * To avoid this, we program the buffers in the highest slots.
5232 * This way, slot 0 is only used if slot 3 is also used.
5236 for (int i
= 3; i
>= 0; i
--) {
5237 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
5239 if (range
->length
== 0)
5242 /* Range block is a binding table index, map back to UBO index. */
5243 unsigned block_index
= iris_bti_to_group_index(
5244 &shader
->bt
, IRIS_SURFACE_GROUP_UBO
, range
->block
);
5245 assert(block_index
!= IRIS_SURFACE_NOT_USED
);
5247 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[block_index
];
5248 struct iris_resource
*res
= (void *) cbuf
->buffer
;
5250 assert(cbuf
->buffer_offset
% 32 == 0);
5252 pkt
.ConstantBody
.ReadLength
[n
] = range
->length
;
5253 pkt
.ConstantBody
.Buffer
[n
] =
5254 res
? ro_bo(res
->bo
, range
->start
* 32 + cbuf
->buffer_offset
)
5255 : ro_bo(batch
->screen
->workaround_bo
, 0);
5262 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5263 /* Gen9 requires 3DSTATE_BINDING_TABLE_POINTERS_XS to be re-emitted
5264 * in order to commit constants. TODO: Investigate "Disable Gather
5265 * at Set Shader" to go back to legacy mode...
5267 if (dirty
& ((IRIS_DIRTY_BINDINGS_VS
|
5268 (GEN_GEN
== 9 ? IRIS_DIRTY_CONSTANTS_VS
: 0)) << stage
)) {
5269 iris_emit_cmd(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), ptr
) {
5270 ptr
._3DCommandSubOpcode
= 38 + stage
;
5271 ptr
.PointertoVSBindingTable
= binder
->bt_offset
[stage
];
5276 if (GEN_GEN
>= 11 && (dirty
& IRIS_DIRTY_RENDER_BUFFER
)) {
5277 // XXX: we may want to flag IRIS_DIRTY_MULTISAMPLE (or SAMPLE_MASK?)
5278 // XXX: see commit 979fc1bc9bcc64027ff2cfafd285676f31b930a6
5280 /* The PIPE_CONTROL command description says:
5282 * "Whenever a Binding Table Index (BTI) used by a Render Target
5283 * Message points to a different RENDER_SURFACE_STATE, SW must issue a
5284 * Render Target Cache Flush by enabling this bit. When render target
5285 * flush is set due to new association of BTI, PS Scoreboard Stall bit
5286 * must be set in this packet."
5288 // XXX: does this need to happen at 3DSTATE_BTP_PS time?
5289 iris_emit_pipe_control_flush(batch
, "workaround: RT BTI change [draw]",
5290 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
5291 PIPE_CONTROL_STALL_AT_SCOREBOARD
);
5294 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5295 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
5296 iris_populate_binding_table(ice
, batch
, stage
, false);
5300 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5301 if (!(dirty
& (IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
)) ||
5302 !ice
->shaders
.prog
[stage
])
5305 iris_upload_sampler_states(ice
, stage
);
5307 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5308 struct pipe_resource
*res
= shs
->sampler_table
.res
;
5310 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
5312 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ptr
) {
5313 ptr
._3DCommandSubOpcode
= 43 + stage
;
5314 ptr
.PointertoVSSamplerState
= shs
->sampler_table
.offset
;
5318 if (ice
->state
.need_border_colors
)
5319 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
5321 if (dirty
& IRIS_DIRTY_MULTISAMPLE
) {
5322 iris_emit_cmd(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
5324 ice
->state
.cso_rast
->half_pixel_center
? CENTER
: UL_CORNER
;
5325 if (ice
->state
.framebuffer
.samples
> 0)
5326 ms
.NumberofMultisamples
= ffs(ice
->state
.framebuffer
.samples
) - 1;
5330 if (dirty
& IRIS_DIRTY_SAMPLE_MASK
) {
5331 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_MASK
), ms
) {
5332 ms
.SampleMask
= ice
->state
.sample_mask
;
5336 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5337 if (!(dirty
& (IRIS_DIRTY_VS
<< stage
)))
5340 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5343 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
5344 struct iris_resource
*cache
= (void *) shader
->assembly
.res
;
5345 iris_use_pinned_bo(batch
, cache
->bo
, false);
5347 if (prog_data
->total_scratch
> 0) {
5348 struct iris_bo
*bo
=
5349 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
5350 iris_use_pinned_bo(batch
, bo
, true);
5353 if (stage
== MESA_SHADER_FRAGMENT
) {
5354 UNUSED
struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5355 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5357 uint32_t ps_state
[GENX(3DSTATE_PS_length
)] = {0};
5358 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
5359 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
5360 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
5361 ps
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
5363 /* The docs for 3DSTATE_PS::32 Pixel Dispatch Enable say:
5365 * "When NUM_MULTISAMPLES = 16 or FORCE_SAMPLE_COUNT = 16,
5366 * SIMD32 Dispatch must not be enabled for PER_PIXEL dispatch
5369 * 16x MSAA only exists on Gen9+, so we can skip this on Gen8.
5371 if (GEN_GEN
>= 9 && cso_fb
->samples
== 16 &&
5372 !wm_prog_data
->persample_dispatch
) {
5373 assert(ps
._8PixelDispatchEnable
|| ps
._16PixelDispatchEnable
);
5374 ps
._32PixelDispatchEnable
= false;
5377 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
5378 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 0);
5379 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
5380 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 1);
5381 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
5382 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 2);
5384 ps
.KernelStartPointer0
= KSP(shader
) +
5385 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 0);
5386 ps
.KernelStartPointer1
= KSP(shader
) +
5387 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 1);
5388 ps
.KernelStartPointer2
= KSP(shader
) +
5389 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 2);
5392 uint32_t psx_state
[GENX(3DSTATE_PS_EXTRA_length
)] = {0};
5393 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
5395 if (!wm_prog_data
->uses_sample_mask
)
5396 psx
.InputCoverageMaskState
= ICMS_NONE
;
5397 else if (wm_prog_data
->post_depth_coverage
)
5398 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
5399 else if (wm_prog_data
->inner_coverage
&&
5400 cso
->conservative_rasterization
)
5401 psx
.InputCoverageMaskState
= ICMS_INNER_CONSERVATIVE
;
5403 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
5405 psx
.PixelShaderUsesInputCoverageMask
=
5406 wm_prog_data
->uses_sample_mask
;
5410 uint32_t *shader_ps
= (uint32_t *) shader
->derived_data
;
5411 uint32_t *shader_psx
= shader_ps
+ GENX(3DSTATE_PS_length
);
5412 iris_emit_merge(batch
, shader_ps
, ps_state
,
5413 GENX(3DSTATE_PS_length
));
5414 iris_emit_merge(batch
, shader_psx
, psx_state
,
5415 GENX(3DSTATE_PS_EXTRA_length
));
5417 iris_batch_emit(batch
, shader
->derived_data
,
5418 iris_derived_program_state_size(stage
));
5421 if (stage
== MESA_SHADER_TESS_EVAL
) {
5422 iris_emit_cmd(batch
, GENX(3DSTATE_HS
), hs
);
5423 iris_emit_cmd(batch
, GENX(3DSTATE_TE
), te
);
5424 iris_emit_cmd(batch
, GENX(3DSTATE_DS
), ds
);
5425 } else if (stage
== MESA_SHADER_GEOMETRY
) {
5426 iris_emit_cmd(batch
, GENX(3DSTATE_GS
), gs
);
5431 if (ice
->state
.streamout_active
) {
5432 if (dirty
& IRIS_DIRTY_SO_BUFFERS
) {
5433 iris_batch_emit(batch
, genx
->so_buffers
,
5434 4 * 4 * GENX(3DSTATE_SO_BUFFER_length
));
5435 for (int i
= 0; i
< 4; i
++) {
5436 struct iris_stream_output_target
*tgt
=
5437 (void *) ice
->state
.so_target
[i
];
5440 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
5442 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
5448 if ((dirty
& IRIS_DIRTY_SO_DECL_LIST
) && ice
->state
.streamout
) {
5449 uint32_t *decl_list
=
5450 ice
->state
.streamout
+ GENX(3DSTATE_STREAMOUT_length
);
5451 iris_batch_emit(batch
, decl_list
, 4 * ((decl_list
[0] & 0xff) + 2));
5454 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
5455 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5457 uint32_t dynamic_sol
[GENX(3DSTATE_STREAMOUT_length
)];
5458 iris_pack_command(GENX(3DSTATE_STREAMOUT
), dynamic_sol
, sol
) {
5459 sol
.SOFunctionEnable
= true;
5460 sol
.SOStatisticsEnable
= true;
5462 sol
.RenderingDisable
= cso_rast
->rasterizer_discard
&&
5463 !ice
->state
.prims_generated_query_active
;
5464 sol
.ReorderMode
= cso_rast
->flatshade_first
? LEADING
: TRAILING
;
5467 assert(ice
->state
.streamout
);
5469 iris_emit_merge(batch
, ice
->state
.streamout
, dynamic_sol
,
5470 GENX(3DSTATE_STREAMOUT_length
));
5473 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
5474 iris_emit_cmd(batch
, GENX(3DSTATE_STREAMOUT
), sol
);
5478 if (dirty
& IRIS_DIRTY_CLIP
) {
5479 struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5480 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5482 bool gs_or_tes
= ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] ||
5483 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
];
5484 bool points_or_lines
= cso_rast
->fill_mode_point_or_line
||
5485 (gs_or_tes
? ice
->shaders
.output_topology_is_points_or_lines
5486 : ice
->state
.prim_is_points_or_lines
);
5488 uint32_t dynamic_clip
[GENX(3DSTATE_CLIP_length
)];
5489 iris_pack_command(GENX(3DSTATE_CLIP
), &dynamic_clip
, cl
) {
5490 cl
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
5491 if (cso_rast
->rasterizer_discard
)
5492 cl
.ClipMode
= CLIPMODE_REJECT_ALL
;
5493 else if (ice
->state
.window_space_position
)
5494 cl
.ClipMode
= CLIPMODE_ACCEPT_ALL
;
5496 cl
.ClipMode
= CLIPMODE_NORMAL
;
5498 cl
.PerspectiveDivideDisable
= ice
->state
.window_space_position
;
5499 cl
.ViewportXYClipTestEnable
= !points_or_lines
;
5501 if (wm_prog_data
->barycentric_interp_modes
&
5502 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
5503 cl
.NonPerspectiveBarycentricEnable
= true;
5505 cl
.ForceZeroRTAIndexEnable
= cso_fb
->layers
<= 1;
5506 cl
.MaximumVPIndex
= ice
->state
.num_viewports
- 1;
5508 iris_emit_merge(batch
, cso_rast
->clip
, dynamic_clip
,
5509 ARRAY_SIZE(cso_rast
->clip
));
5512 if (dirty
& IRIS_DIRTY_RASTER
) {
5513 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5514 iris_batch_emit(batch
, cso
->raster
, sizeof(cso
->raster
));
5516 uint32_t dynamic_sf
[GENX(3DSTATE_SF_length
)];
5517 iris_pack_command(GENX(3DSTATE_SF
), &dynamic_sf
, sf
) {
5518 sf
.ViewportTransformEnable
= !ice
->state
.window_space_position
;
5520 iris_emit_merge(batch
, cso
->sf
, dynamic_sf
,
5521 ARRAY_SIZE(dynamic_sf
));
5524 if (dirty
& IRIS_DIRTY_WM
) {
5525 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5526 uint32_t dynamic_wm
[GENX(3DSTATE_WM_length
)];
5528 iris_pack_command(GENX(3DSTATE_WM
), &dynamic_wm
, wm
) {
5529 wm
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
5531 wm
.BarycentricInterpolationMode
=
5532 wm_prog_data
->barycentric_interp_modes
;
5534 if (wm_prog_data
->early_fragment_tests
)
5535 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
5536 else if (wm_prog_data
->has_side_effects
)
5537 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
5539 /* We could skip this bit if color writes are enabled. */
5540 if (wm_prog_data
->has_side_effects
|| wm_prog_data
->uses_kill
)
5541 wm
.ForceThreadDispatchEnable
= ForceON
;
5543 iris_emit_merge(batch
, cso
->wm
, dynamic_wm
, ARRAY_SIZE(cso
->wm
));
5546 if (dirty
& IRIS_DIRTY_SBE
) {
5547 iris_emit_sbe(batch
, ice
);
5550 if (dirty
& IRIS_DIRTY_PS_BLEND
) {
5551 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
5552 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
5553 const struct shader_info
*fs_info
=
5554 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
5556 uint32_t dynamic_pb
[GENX(3DSTATE_PS_BLEND_length
)];
5557 iris_pack_command(GENX(3DSTATE_PS_BLEND
), &dynamic_pb
, pb
) {
5558 pb
.HasWriteableRT
= has_writeable_rt(cso_blend
, fs_info
);
5559 pb
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
5561 /* The dual source blending docs caution against using SRC1 factors
5562 * when the shader doesn't use a dual source render target write.
5563 * Empirically, this can lead to GPU hangs, and the results are
5564 * undefined anyway, so simply disable blending to avoid the hang.
5566 pb
.ColorBufferBlendEnable
= (cso_blend
->blend_enables
& 1) &&
5567 (!cso_blend
->dual_color_blending
|| wm_prog_data
->dual_src_blend
);
5570 iris_emit_merge(batch
, cso_blend
->ps_blend
, dynamic_pb
,
5571 ARRAY_SIZE(cso_blend
->ps_blend
));
5574 if (dirty
& IRIS_DIRTY_WM_DEPTH_STENCIL
) {
5575 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
5577 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
5578 uint32_t stencil_refs
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
5579 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), &stencil_refs
, wmds
) {
5580 wmds
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
5581 wmds
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
5583 iris_emit_merge(batch
, cso
->wmds
, stencil_refs
, ARRAY_SIZE(cso
->wmds
));
5585 iris_batch_emit(batch
, cso
->wmds
, sizeof(cso
->wmds
));
5589 iris_batch_emit(batch
, cso
->depth_bounds
, sizeof(cso
->depth_bounds
));
5593 if (dirty
& IRIS_DIRTY_SCISSOR_RECT
) {
5594 uint32_t scissor_offset
=
5595 emit_state(batch
, ice
->state
.dynamic_uploader
,
5596 &ice
->state
.last_res
.scissor
,
5597 ice
->state
.scissors
,
5598 sizeof(struct pipe_scissor_state
) *
5599 ice
->state
.num_viewports
, 32);
5601 iris_emit_cmd(batch
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
5602 ptr
.ScissorRectPointer
= scissor_offset
;
5606 if (dirty
& IRIS_DIRTY_DEPTH_BUFFER
) {
5607 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
5609 /* Do not emit the clear params yets. We need to update the clear value
5612 uint32_t clear_length
= GENX(3DSTATE_CLEAR_PARAMS_length
) * 4;
5613 uint32_t cso_z_size
= sizeof(cso_z
->packets
) - clear_length
;
5614 iris_batch_emit(batch
, cso_z
->packets
, cso_z_size
);
5616 union isl_color_value clear_value
= { .f32
= { 0, } };
5618 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5619 if (cso_fb
->zsbuf
) {
5620 struct iris_resource
*zres
, *sres
;
5621 iris_get_depth_stencil_resources(cso_fb
->zsbuf
->texture
,
5623 if (zres
&& zres
->aux
.bo
)
5624 clear_value
= iris_resource_get_clear_color(zres
, NULL
, NULL
);
5627 uint32_t clear_params
[GENX(3DSTATE_CLEAR_PARAMS_length
)];
5628 iris_pack_command(GENX(3DSTATE_CLEAR_PARAMS
), clear_params
, clear
) {
5629 clear
.DepthClearValueValid
= true;
5630 clear
.DepthClearValue
= clear_value
.f32
[0];
5632 iris_batch_emit(batch
, clear_params
, clear_length
);
5635 if (dirty
& (IRIS_DIRTY_DEPTH_BUFFER
| IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
5636 /* Listen for buffer changes, and also write enable changes. */
5637 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5638 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
5641 if (dirty
& IRIS_DIRTY_POLYGON_STIPPLE
) {
5642 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
5643 for (int i
= 0; i
< 32; i
++) {
5644 poly
.PatternRow
[i
] = ice
->state
.poly_stipple
.stipple
[i
];
5649 if (dirty
& IRIS_DIRTY_LINE_STIPPLE
) {
5650 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5651 iris_batch_emit(batch
, cso
->line_stipple
, sizeof(cso
->line_stipple
));
5654 if (dirty
& IRIS_DIRTY_VF_TOPOLOGY
) {
5655 iris_emit_cmd(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
5656 topo
.PrimitiveTopologyType
=
5657 translate_prim_type(draw
->mode
, draw
->vertices_per_patch
);
5661 if (dirty
& IRIS_DIRTY_VERTEX_BUFFERS
) {
5662 int count
= util_bitcount64(ice
->state
.bound_vertex_buffers
);
5663 int dynamic_bound
= ice
->state
.bound_vertex_buffers
;
5665 if (ice
->state
.vs_uses_draw_params
) {
5666 assert(ice
->draw
.draw_params
.res
);
5668 struct iris_vertex_buffer_state
*state
=
5669 &(ice
->state
.genx
->vertex_buffers
[count
]);
5670 pipe_resource_reference(&state
->resource
, ice
->draw
.draw_params
.res
);
5671 struct iris_resource
*res
= (void *) state
->resource
;
5673 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
5674 vb
.VertexBufferIndex
= count
;
5675 vb
.AddressModifyEnable
= true;
5677 vb
.BufferSize
= res
->bo
->size
- ice
->draw
.draw_params
.offset
;
5678 vb
.BufferStartingAddress
=
5679 ro_bo(NULL
, res
->bo
->gtt_offset
+
5680 (int) ice
->draw
.draw_params
.offset
);
5681 vb
.MOCS
= mocs(res
->bo
, &batch
->screen
->isl_dev
);
5683 dynamic_bound
|= 1ull << count
;
5687 if (ice
->state
.vs_uses_derived_draw_params
) {
5688 struct iris_vertex_buffer_state
*state
=
5689 &(ice
->state
.genx
->vertex_buffers
[count
]);
5690 pipe_resource_reference(&state
->resource
,
5691 ice
->draw
.derived_draw_params
.res
);
5692 struct iris_resource
*res
= (void *) ice
->draw
.derived_draw_params
.res
;
5694 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
5695 vb
.VertexBufferIndex
= count
;
5696 vb
.AddressModifyEnable
= true;
5699 res
->bo
->size
- ice
->draw
.derived_draw_params
.offset
;
5700 vb
.BufferStartingAddress
=
5701 ro_bo(NULL
, res
->bo
->gtt_offset
+
5702 (int) ice
->draw
.derived_draw_params
.offset
);
5703 vb
.MOCS
= mocs(res
->bo
, &batch
->screen
->isl_dev
);
5705 dynamic_bound
|= 1ull << count
;
5710 /* The VF cache designers cut corners, and made the cache key's
5711 * <VertexBufferIndex, Memory Address> tuple only consider the bottom
5712 * 32 bits of the address. If you have two vertex buffers which get
5713 * placed exactly 4 GiB apart and use them in back-to-back draw calls,
5714 * you can get collisions (even within a single batch).
5716 * So, we need to do a VF cache invalidate if the buffer for a VB
5717 * slot slot changes [48:32] address bits from the previous time.
5719 unsigned flush_flags
= 0;
5721 uint64_t bound
= dynamic_bound
;
5723 const int i
= u_bit_scan64(&bound
);
5724 uint16_t high_bits
= 0;
5726 struct iris_resource
*res
=
5727 (void *) genx
->vertex_buffers
[i
].resource
;
5729 iris_use_pinned_bo(batch
, res
->bo
, false);
5731 high_bits
= res
->bo
->gtt_offset
>> 32ull;
5732 if (high_bits
!= ice
->state
.last_vbo_high_bits
[i
]) {
5733 flush_flags
|= PIPE_CONTROL_VF_CACHE_INVALIDATE
|
5734 PIPE_CONTROL_CS_STALL
;
5735 ice
->state
.last_vbo_high_bits
[i
] = high_bits
;
5741 iris_emit_pipe_control_flush(batch
,
5742 "workaround: VF cache 32-bit key [VB]",
5746 const unsigned vb_dwords
= GENX(VERTEX_BUFFER_STATE_length
);
5749 iris_get_command_space(batch
, 4 * (1 + vb_dwords
* count
));
5750 _iris_pack_command(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), map
, vb
) {
5751 vb
.DWordLength
= (vb_dwords
* count
+ 1) - 2;
5755 bound
= dynamic_bound
;
5757 const int i
= u_bit_scan64(&bound
);
5758 memcpy(map
, genx
->vertex_buffers
[i
].state
,
5759 sizeof(uint32_t) * vb_dwords
);
5765 if (dirty
& IRIS_DIRTY_VERTEX_ELEMENTS
) {
5766 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
5767 const unsigned entries
= MAX2(cso
->count
, 1);
5768 if (!(ice
->state
.vs_needs_sgvs_element
||
5769 ice
->state
.vs_uses_derived_draw_params
||
5770 ice
->state
.vs_needs_edge_flag
)) {
5771 iris_batch_emit(batch
, cso
->vertex_elements
, sizeof(uint32_t) *
5772 (1 + entries
* GENX(VERTEX_ELEMENT_STATE_length
)));
5774 uint32_t dynamic_ves
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
5775 const unsigned dyn_count
= cso
->count
+
5776 ice
->state
.vs_needs_sgvs_element
+
5777 ice
->state
.vs_uses_derived_draw_params
;
5779 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
),
5782 1 + GENX(VERTEX_ELEMENT_STATE_length
) * dyn_count
- 2;
5784 memcpy(&dynamic_ves
[1], &cso
->vertex_elements
[1],
5785 (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
5786 GENX(VERTEX_ELEMENT_STATE_length
) * sizeof(uint32_t));
5787 uint32_t *ve_pack_dest
=
5788 &dynamic_ves
[1 + (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
5789 GENX(VERTEX_ELEMENT_STATE_length
)];
5791 if (ice
->state
.vs_needs_sgvs_element
) {
5792 uint32_t base_ctrl
= ice
->state
.vs_uses_draw_params
?
5793 VFCOMP_STORE_SRC
: VFCOMP_STORE_0
;
5794 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
5796 ve
.VertexBufferIndex
=
5797 util_bitcount64(ice
->state
.bound_vertex_buffers
);
5798 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
5799 ve
.Component0Control
= base_ctrl
;
5800 ve
.Component1Control
= base_ctrl
;
5801 ve
.Component2Control
= VFCOMP_STORE_0
;
5802 ve
.Component3Control
= VFCOMP_STORE_0
;
5804 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
5806 if (ice
->state
.vs_uses_derived_draw_params
) {
5807 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
5809 ve
.VertexBufferIndex
=
5810 util_bitcount64(ice
->state
.bound_vertex_buffers
) +
5811 ice
->state
.vs_uses_draw_params
;
5812 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
5813 ve
.Component0Control
= VFCOMP_STORE_SRC
;
5814 ve
.Component1Control
= VFCOMP_STORE_SRC
;
5815 ve
.Component2Control
= VFCOMP_STORE_0
;
5816 ve
.Component3Control
= VFCOMP_STORE_0
;
5818 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
5820 if (ice
->state
.vs_needs_edge_flag
) {
5821 for (int i
= 0; i
< GENX(VERTEX_ELEMENT_STATE_length
); i
++)
5822 ve_pack_dest
[i
] = cso
->edgeflag_ve
[i
];
5825 iris_batch_emit(batch
, &dynamic_ves
, sizeof(uint32_t) *
5826 (1 + dyn_count
* GENX(VERTEX_ELEMENT_STATE_length
)));
5829 if (!ice
->state
.vs_needs_edge_flag
) {
5830 iris_batch_emit(batch
, cso
->vf_instancing
, sizeof(uint32_t) *
5831 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
5833 assert(cso
->count
> 0);
5834 const unsigned edgeflag_index
= cso
->count
- 1;
5835 uint32_t dynamic_vfi
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
5836 memcpy(&dynamic_vfi
[0], cso
->vf_instancing
, edgeflag_index
*
5837 GENX(3DSTATE_VF_INSTANCING_length
) * sizeof(uint32_t));
5839 uint32_t *vfi_pack_dest
= &dynamic_vfi
[0] +
5840 edgeflag_index
* GENX(3DSTATE_VF_INSTANCING_length
);
5841 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
5842 vi
.VertexElementIndex
= edgeflag_index
+
5843 ice
->state
.vs_needs_sgvs_element
+
5844 ice
->state
.vs_uses_derived_draw_params
;
5846 for (int i
= 0; i
< GENX(3DSTATE_VF_INSTANCING_length
); i
++)
5847 vfi_pack_dest
[i
] |= cso
->edgeflag_vfi
[i
];
5849 iris_batch_emit(batch
, &dynamic_vfi
[0], sizeof(uint32_t) *
5850 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
5854 if (dirty
& IRIS_DIRTY_VF_SGVS
) {
5855 const struct brw_vs_prog_data
*vs_prog_data
= (void *)
5856 ice
->shaders
.prog
[MESA_SHADER_VERTEX
]->prog_data
;
5857 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
5859 iris_emit_cmd(batch
, GENX(3DSTATE_VF_SGVS
), sgv
) {
5860 if (vs_prog_data
->uses_vertexid
) {
5861 sgv
.VertexIDEnable
= true;
5862 sgv
.VertexIDComponentNumber
= 2;
5863 sgv
.VertexIDElementOffset
=
5864 cso
->count
- ice
->state
.vs_needs_edge_flag
;
5867 if (vs_prog_data
->uses_instanceid
) {
5868 sgv
.InstanceIDEnable
= true;
5869 sgv
.InstanceIDComponentNumber
= 3;
5870 sgv
.InstanceIDElementOffset
=
5871 cso
->count
- ice
->state
.vs_needs_edge_flag
;
5876 if (dirty
& IRIS_DIRTY_VF
) {
5877 iris_emit_cmd(batch
, GENX(3DSTATE_VF
), vf
) {
5878 if (draw
->primitive_restart
) {
5879 vf
.IndexedDrawCutIndexEnable
= true;
5880 vf
.CutIndex
= draw
->restart_index
;
5885 if (dirty
& IRIS_DIRTY_VF_STATISTICS
) {
5886 iris_emit_cmd(batch
, GENX(3DSTATE_VF_STATISTICS
), vf
) {
5887 vf
.StatisticsEnable
= true;
5892 if (dirty
& IRIS_DIRTY_PMA_FIX
) {
5893 bool enable
= want_pma_fix(ice
);
5894 genX(update_pma_fix
)(ice
, batch
, enable
);
5898 if (ice
->state
.current_hash_scale
!= 1)
5899 genX(emit_hashing_mode
)(ice
, batch
, UINT_MAX
, UINT_MAX
, 1);
5902 genX(emit_aux_map_state
)(batch
);
5907 iris_upload_render_state(struct iris_context
*ice
,
5908 struct iris_batch
*batch
,
5909 const struct pipe_draw_info
*draw
)
5911 bool use_predicate
= ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
;
5913 /* Always pin the binder. If we're emitting new binding table pointers,
5914 * we need it. If not, we're probably inheriting old tables via the
5915 * context, and need it anyway. Since true zero-bindings cases are
5916 * practically non-existent, just pin it and avoid last_res tracking.
5918 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
5920 if (!batch
->contains_draw
) {
5921 iris_restore_render_saved_bos(ice
, batch
, draw
);
5922 batch
->contains_draw
= true;
5925 iris_upload_dirty_render_state(ice
, batch
, draw
);
5927 if (draw
->index_size
> 0) {
5930 if (draw
->has_user_indices
) {
5931 u_upload_data(ice
->ctx
.stream_uploader
, 0,
5932 draw
->count
* draw
->index_size
, 4, draw
->index
.user
,
5933 &offset
, &ice
->state
.last_res
.index_buffer
);
5935 struct iris_resource
*res
= (void *) draw
->index
.resource
;
5936 res
->bind_history
|= PIPE_BIND_INDEX_BUFFER
;
5938 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
,
5939 draw
->index
.resource
);
5943 struct iris_genx_state
*genx
= ice
->state
.genx
;
5944 struct iris_bo
*bo
= iris_resource_bo(ice
->state
.last_res
.index_buffer
);
5946 uint32_t ib_packet
[GENX(3DSTATE_INDEX_BUFFER_length
)];
5947 iris_pack_command(GENX(3DSTATE_INDEX_BUFFER
), ib_packet
, ib
) {
5948 ib
.IndexFormat
= draw
->index_size
>> 1;
5949 ib
.MOCS
= mocs(bo
, &batch
->screen
->isl_dev
);
5950 ib
.BufferSize
= bo
->size
- offset
;
5951 ib
.BufferStartingAddress
= ro_bo(NULL
, bo
->gtt_offset
+ offset
);
5954 if (memcmp(genx
->last_index_buffer
, ib_packet
, sizeof(ib_packet
)) != 0) {
5955 memcpy(genx
->last_index_buffer
, ib_packet
, sizeof(ib_packet
));
5956 iris_batch_emit(batch
, ib_packet
, sizeof(ib_packet
));
5957 iris_use_pinned_bo(batch
, bo
, false);
5960 /* The VF cache key only uses 32-bits, see vertex buffer comment above */
5961 uint16_t high_bits
= bo
->gtt_offset
>> 32ull;
5962 if (high_bits
!= ice
->state
.last_index_bo_high_bits
) {
5963 iris_emit_pipe_control_flush(batch
,
5964 "workaround: VF cache 32-bit key [IB]",
5965 PIPE_CONTROL_VF_CACHE_INVALIDATE
|
5966 PIPE_CONTROL_CS_STALL
);
5967 ice
->state
.last_index_bo_high_bits
= high_bits
;
5971 #define _3DPRIM_END_OFFSET 0x2420
5972 #define _3DPRIM_START_VERTEX 0x2430
5973 #define _3DPRIM_VERTEX_COUNT 0x2434
5974 #define _3DPRIM_INSTANCE_COUNT 0x2438
5975 #define _3DPRIM_START_INSTANCE 0x243C
5976 #define _3DPRIM_BASE_VERTEX 0x2440
5978 if (draw
->indirect
) {
5979 if (draw
->indirect
->indirect_draw_count
) {
5980 use_predicate
= true;
5982 struct iris_bo
*draw_count_bo
=
5983 iris_resource_bo(draw
->indirect
->indirect_draw_count
);
5984 unsigned draw_count_offset
=
5985 draw
->indirect
->indirect_draw_count_offset
;
5987 iris_emit_pipe_control_flush(batch
,
5988 "ensure indirect draw buffer is flushed",
5989 PIPE_CONTROL_FLUSH_ENABLE
);
5991 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
) {
5992 struct gen_mi_builder b
;
5993 gen_mi_builder_init(&b
, batch
);
5995 /* comparison = draw id < draw count */
5996 struct gen_mi_value comparison
=
5997 gen_mi_ult(&b
, gen_mi_imm(draw
->drawid
),
5998 gen_mi_mem32(ro_bo(draw_count_bo
,
5999 draw_count_offset
)));
6001 /* predicate = comparison & conditional rendering predicate */
6002 gen_mi_store(&b
, gen_mi_reg32(MI_PREDICATE_RESULT
),
6003 gen_mi_iand(&b
, comparison
,
6004 gen_mi_reg32(CS_GPR(15))));
6006 uint32_t mi_predicate
;
6008 /* Upload the id of the current primitive to MI_PREDICATE_SRC1. */
6009 iris_load_register_imm64(batch
, MI_PREDICATE_SRC1
, draw
->drawid
);
6010 /* Upload the current draw count from the draw parameters buffer
6011 * to MI_PREDICATE_SRC0.
6013 iris_load_register_mem32(batch
, MI_PREDICATE_SRC0
,
6014 draw_count_bo
, draw_count_offset
);
6015 /* Zero the top 32-bits of MI_PREDICATE_SRC0 */
6016 iris_load_register_imm32(batch
, MI_PREDICATE_SRC0
+ 4, 0);
6018 if (draw
->drawid
== 0) {
6019 mi_predicate
= MI_PREDICATE
| MI_PREDICATE_LOADOP_LOADINV
|
6020 MI_PREDICATE_COMBINEOP_SET
|
6021 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
;
6023 /* While draw_index < draw_count the predicate's result will be
6024 * (draw_index == draw_count) ^ TRUE = TRUE
6025 * When draw_index == draw_count the result is
6026 * (TRUE) ^ TRUE = FALSE
6027 * After this all results will be:
6028 * (FALSE) ^ FALSE = FALSE
6030 mi_predicate
= MI_PREDICATE
| MI_PREDICATE_LOADOP_LOAD
|
6031 MI_PREDICATE_COMBINEOP_XOR
|
6032 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
;
6034 iris_batch_emit(batch
, &mi_predicate
, sizeof(uint32_t));
6037 struct iris_bo
*bo
= iris_resource_bo(draw
->indirect
->buffer
);
6040 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6041 lrm
.RegisterAddress
= _3DPRIM_VERTEX_COUNT
;
6042 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 0);
6044 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6045 lrm
.RegisterAddress
= _3DPRIM_INSTANCE_COUNT
;
6046 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 4);
6048 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6049 lrm
.RegisterAddress
= _3DPRIM_START_VERTEX
;
6050 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 8);
6052 if (draw
->index_size
) {
6053 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6054 lrm
.RegisterAddress
= _3DPRIM_BASE_VERTEX
;
6055 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
6057 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6058 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
6059 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 16);
6062 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6063 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
6064 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
6066 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
6067 lri
.RegisterOffset
= _3DPRIM_BASE_VERTEX
;
6071 } else if (draw
->count_from_stream_output
) {
6072 struct iris_stream_output_target
*so
=
6073 (void *) draw
->count_from_stream_output
;
6075 /* XXX: Replace with actual cache tracking */
6076 iris_emit_pipe_control_flush(batch
,
6077 "draw count from stream output stall",
6078 PIPE_CONTROL_CS_STALL
);
6080 struct gen_mi_builder b
;
6081 gen_mi_builder_init(&b
, batch
);
6083 struct iris_address addr
=
6084 ro_bo(iris_resource_bo(so
->offset
.res
), so
->offset
.offset
);
6085 struct gen_mi_value offset
=
6086 gen_mi_iadd_imm(&b
, gen_mi_mem32(addr
), -so
->base
.buffer_offset
);
6088 gen_mi_store(&b
, gen_mi_reg32(_3DPRIM_VERTEX_COUNT
),
6089 gen_mi_udiv32_imm(&b
, offset
, so
->stride
));
6091 _iris_emit_lri(batch
, _3DPRIM_START_VERTEX
, 0);
6092 _iris_emit_lri(batch
, _3DPRIM_BASE_VERTEX
, 0);
6093 _iris_emit_lri(batch
, _3DPRIM_START_INSTANCE
, 0);
6094 _iris_emit_lri(batch
, _3DPRIM_INSTANCE_COUNT
, draw
->instance_count
);
6097 iris_emit_cmd(batch
, GENX(3DPRIMITIVE
), prim
) {
6098 prim
.VertexAccessType
= draw
->index_size
> 0 ? RANDOM
: SEQUENTIAL
;
6099 prim
.PredicateEnable
= use_predicate
;
6101 if (draw
->indirect
|| draw
->count_from_stream_output
) {
6102 prim
.IndirectParameterEnable
= true;
6104 prim
.StartInstanceLocation
= draw
->start_instance
;
6105 prim
.InstanceCount
= draw
->instance_count
;
6106 prim
.VertexCountPerInstance
= draw
->count
;
6108 prim
.StartVertexLocation
= draw
->start
;
6110 if (draw
->index_size
) {
6111 prim
.BaseVertexLocation
+= draw
->index_bias
;
6113 prim
.StartVertexLocation
+= draw
->index_bias
;
6120 iris_upload_compute_state(struct iris_context
*ice
,
6121 struct iris_batch
*batch
,
6122 const struct pipe_grid_info
*grid
)
6124 const uint64_t dirty
= ice
->state
.dirty
;
6125 struct iris_screen
*screen
= batch
->screen
;
6126 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
6127 struct iris_binder
*binder
= &ice
->state
.binder
;
6128 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_COMPUTE
];
6129 struct iris_compiled_shader
*shader
=
6130 ice
->shaders
.prog
[MESA_SHADER_COMPUTE
];
6131 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
6132 struct brw_cs_prog_data
*cs_prog_data
= (void *) prog_data
;
6134 /* Always pin the binder. If we're emitting new binding table pointers,
6135 * we need it. If not, we're probably inheriting old tables via the
6136 * context, and need it anyway. Since true zero-bindings cases are
6137 * practically non-existent, just pin it and avoid last_res tracking.
6139 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
6141 if ((dirty
& IRIS_DIRTY_CONSTANTS_CS
) && shs
->sysvals_need_upload
)
6142 upload_sysvals(ice
, MESA_SHADER_COMPUTE
);
6144 if (dirty
& IRIS_DIRTY_BINDINGS_CS
)
6145 iris_populate_binding_table(ice
, batch
, MESA_SHADER_COMPUTE
, false);
6147 if (dirty
& IRIS_DIRTY_SAMPLER_STATES_CS
)
6148 iris_upload_sampler_states(ice
, MESA_SHADER_COMPUTE
);
6150 iris_use_optional_res(batch
, shs
->sampler_table
.res
, false);
6151 iris_use_pinned_bo(batch
, iris_resource_bo(shader
->assembly
.res
), false);
6153 if (ice
->state
.need_border_colors
)
6154 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
6157 genX(emit_aux_map_state
)(batch
);
6160 if (dirty
& IRIS_DIRTY_CS
) {
6161 /* The MEDIA_VFE_STATE documentation for Gen8+ says:
6163 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
6164 * the only bits that are changed are scoreboard related: Scoreboard
6165 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard Delta. For
6166 * these scoreboard related states, a MEDIA_STATE_FLUSH is
6169 iris_emit_pipe_control_flush(batch
,
6170 "workaround: stall before MEDIA_VFE_STATE",
6171 PIPE_CONTROL_CS_STALL
);
6173 iris_emit_cmd(batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
6174 if (prog_data
->total_scratch
) {
6175 struct iris_bo
*bo
=
6176 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
6177 MESA_SHADER_COMPUTE
);
6178 vfe
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
6179 vfe
.ScratchSpaceBasePointer
= rw_bo(bo
, 0);
6182 vfe
.MaximumNumberofThreads
=
6183 devinfo
->max_cs_threads
* screen
->subslice_total
- 1;
6185 vfe
.ResetGatewayTimer
=
6186 Resettingrelativetimerandlatchingtheglobaltimestamp
;
6189 vfe
.BypassGatewayControl
= true;
6191 vfe
.NumberofURBEntries
= 2;
6192 vfe
.URBEntryAllocationSize
= 2;
6194 vfe
.CURBEAllocationSize
=
6195 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
6196 cs_prog_data
->push
.cross_thread
.regs
, 2);
6200 /* TODO: Combine subgroup-id with cbuf0 so we can push regular uniforms */
6201 if (dirty
& IRIS_DIRTY_CS
) {
6202 uint32_t curbe_data_offset
= 0;
6203 assert(cs_prog_data
->push
.cross_thread
.dwords
== 0 &&
6204 cs_prog_data
->push
.per_thread
.dwords
== 1 &&
6205 cs_prog_data
->base
.param
[0] == BRW_PARAM_BUILTIN_SUBGROUP_ID
);
6206 uint32_t *curbe_data_map
=
6207 stream_state(batch
, ice
->state
.dynamic_uploader
,
6208 &ice
->state
.last_res
.cs_thread_ids
,
6209 ALIGN(cs_prog_data
->push
.total
.size
, 64), 64,
6210 &curbe_data_offset
);
6211 assert(curbe_data_map
);
6212 memset(curbe_data_map
, 0x5a, ALIGN(cs_prog_data
->push
.total
.size
, 64));
6213 iris_fill_cs_push_const_buffer(cs_prog_data
, curbe_data_map
);
6215 iris_emit_cmd(batch
, GENX(MEDIA_CURBE_LOAD
), curbe
) {
6216 curbe
.CURBETotalDataLength
=
6217 ALIGN(cs_prog_data
->push
.total
.size
, 64);
6218 curbe
.CURBEDataStartAddress
= curbe_data_offset
;
6222 if (dirty
& (IRIS_DIRTY_SAMPLER_STATES_CS
|
6223 IRIS_DIRTY_BINDINGS_CS
|
6224 IRIS_DIRTY_CONSTANTS_CS
|
6226 uint32_t desc
[GENX(INTERFACE_DESCRIPTOR_DATA_length
)];
6228 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), desc
, idd
) {
6229 idd
.SamplerStatePointer
= shs
->sampler_table
.offset
;
6230 idd
.BindingTablePointer
= binder
->bt_offset
[MESA_SHADER_COMPUTE
];
6233 for (int i
= 0; i
< GENX(INTERFACE_DESCRIPTOR_DATA_length
); i
++)
6234 desc
[i
] |= ((uint32_t *) shader
->derived_data
)[i
];
6236 iris_emit_cmd(batch
, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD
), load
) {
6237 load
.InterfaceDescriptorTotalLength
=
6238 GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t);
6239 load
.InterfaceDescriptorDataStartAddress
=
6240 emit_state(batch
, ice
->state
.dynamic_uploader
,
6241 &ice
->state
.last_res
.cs_desc
, desc
, sizeof(desc
), 64);
6245 uint32_t group_size
= grid
->block
[0] * grid
->block
[1] * grid
->block
[2];
6246 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
6247 uint32_t right_mask
;
6250 right_mask
= ~0u >> (32 - remainder
);
6252 right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
6254 #define GPGPU_DISPATCHDIMX 0x2500
6255 #define GPGPU_DISPATCHDIMY 0x2504
6256 #define GPGPU_DISPATCHDIMZ 0x2508
6258 if (grid
->indirect
) {
6259 struct iris_state_ref
*grid_size
= &ice
->state
.grid_size
;
6260 struct iris_bo
*bo
= iris_resource_bo(grid_size
->res
);
6261 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6262 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMX
;
6263 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 0);
6265 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6266 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMY
;
6267 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 4);
6269 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6270 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMZ
;
6271 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 8);
6275 iris_emit_cmd(batch
, GENX(GPGPU_WALKER
), ggw
) {
6276 ggw
.IndirectParameterEnable
= grid
->indirect
!= NULL
;
6277 ggw
.SIMDSize
= cs_prog_data
->simd_size
/ 16;
6278 ggw
.ThreadDepthCounterMaximum
= 0;
6279 ggw
.ThreadHeightCounterMaximum
= 0;
6280 ggw
.ThreadWidthCounterMaximum
= cs_prog_data
->threads
- 1;
6281 ggw
.ThreadGroupIDXDimension
= grid
->grid
[0];
6282 ggw
.ThreadGroupIDYDimension
= grid
->grid
[1];
6283 ggw
.ThreadGroupIDZDimension
= grid
->grid
[2];
6284 ggw
.RightExecutionMask
= right_mask
;
6285 ggw
.BottomExecutionMask
= 0xffffffff;
6288 iris_emit_cmd(batch
, GENX(MEDIA_STATE_FLUSH
), msf
);
6290 if (!batch
->contains_draw
) {
6291 iris_restore_compute_saved_bos(ice
, batch
, grid
);
6292 batch
->contains_draw
= true;
6297 * State module teardown.
6300 iris_destroy_state(struct iris_context
*ice
)
6302 struct iris_genx_state
*genx
= ice
->state
.genx
;
6304 pipe_resource_reference(&ice
->draw
.draw_params
.res
, NULL
);
6305 pipe_resource_reference(&ice
->draw
.derived_draw_params
.res
, NULL
);
6307 /* Loop over all VBOs, including ones for draw parameters */
6308 for (unsigned i
= 0; i
< ARRAY_SIZE(genx
->vertex_buffers
); i
++) {
6309 pipe_resource_reference(&genx
->vertex_buffers
[i
].resource
, NULL
);
6312 free(ice
->state
.genx
);
6314 for (int i
= 0; i
< 4; i
++) {
6315 pipe_so_target_reference(&ice
->state
.so_target
[i
], NULL
);
6318 for (unsigned i
= 0; i
< ice
->state
.framebuffer
.nr_cbufs
; i
++) {
6319 pipe_surface_reference(&ice
->state
.framebuffer
.cbufs
[i
], NULL
);
6321 pipe_surface_reference(&ice
->state
.framebuffer
.zsbuf
, NULL
);
6323 for (int stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
6324 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
6325 pipe_resource_reference(&shs
->sampler_table
.res
, NULL
);
6326 for (int i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
6327 pipe_resource_reference(&shs
->constbuf
[i
].buffer
, NULL
);
6328 pipe_resource_reference(&shs
->constbuf_surf_state
[i
].res
, NULL
);
6330 for (int i
= 0; i
< PIPE_MAX_SHADER_IMAGES
; i
++) {
6331 pipe_resource_reference(&shs
->image
[i
].base
.resource
, NULL
);
6332 pipe_resource_reference(&shs
->image
[i
].surface_state
.res
, NULL
);
6334 for (int i
= 0; i
< PIPE_MAX_SHADER_BUFFERS
; i
++) {
6335 pipe_resource_reference(&shs
->ssbo
[i
].buffer
, NULL
);
6336 pipe_resource_reference(&shs
->ssbo_surf_state
[i
].res
, NULL
);
6338 for (int i
= 0; i
< IRIS_MAX_TEXTURE_SAMPLERS
; i
++) {
6339 pipe_sampler_view_reference((struct pipe_sampler_view
**)
6340 &shs
->textures
[i
], NULL
);
6344 pipe_resource_reference(&ice
->state
.grid_size
.res
, NULL
);
6345 pipe_resource_reference(&ice
->state
.grid_surf_state
.res
, NULL
);
6347 pipe_resource_reference(&ice
->state
.null_fb
.res
, NULL
);
6348 pipe_resource_reference(&ice
->state
.unbound_tex
.res
, NULL
);
6350 pipe_resource_reference(&ice
->state
.last_res
.cc_vp
, NULL
);
6351 pipe_resource_reference(&ice
->state
.last_res
.sf_cl_vp
, NULL
);
6352 pipe_resource_reference(&ice
->state
.last_res
.color_calc
, NULL
);
6353 pipe_resource_reference(&ice
->state
.last_res
.scissor
, NULL
);
6354 pipe_resource_reference(&ice
->state
.last_res
.blend
, NULL
);
6355 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
, NULL
);
6356 pipe_resource_reference(&ice
->state
.last_res
.cs_thread_ids
, NULL
);
6357 pipe_resource_reference(&ice
->state
.last_res
.cs_desc
, NULL
);
6360 /* ------------------------------------------------------------------- */
6363 iris_rebind_buffer(struct iris_context
*ice
,
6364 struct iris_resource
*res
,
6365 uint64_t old_address
)
6367 struct pipe_context
*ctx
= &ice
->ctx
;
6368 struct iris_screen
*screen
= (void *) ctx
->screen
;
6369 struct iris_genx_state
*genx
= ice
->state
.genx
;
6371 assert(res
->base
.target
== PIPE_BUFFER
);
6373 /* Buffers can't be framebuffer attachments, nor display related,
6374 * and we don't have upstream Clover support.
6376 assert(!(res
->bind_history
& (PIPE_BIND_DEPTH_STENCIL
|
6377 PIPE_BIND_RENDER_TARGET
|
6378 PIPE_BIND_BLENDABLE
|
6379 PIPE_BIND_DISPLAY_TARGET
|
6381 PIPE_BIND_COMPUTE_RESOURCE
|
6382 PIPE_BIND_GLOBAL
)));
6384 if (res
->bind_history
& PIPE_BIND_VERTEX_BUFFER
) {
6385 uint64_t bound_vbs
= ice
->state
.bound_vertex_buffers
;
6387 const int i
= u_bit_scan64(&bound_vbs
);
6388 struct iris_vertex_buffer_state
*state
= &genx
->vertex_buffers
[i
];
6390 /* Update the CPU struct */
6391 STATIC_ASSERT(GENX(VERTEX_BUFFER_STATE_BufferStartingAddress_start
) == 32);
6392 STATIC_ASSERT(GENX(VERTEX_BUFFER_STATE_BufferStartingAddress_bits
) == 64);
6393 uint64_t *addr
= (uint64_t *) &state
->state
[1];
6395 if (*addr
== old_address
+ state
->offset
) {
6396 *addr
= res
->bo
->gtt_offset
+ state
->offset
;
6397 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
6402 /* We don't need to handle PIPE_BIND_INDEX_BUFFER here: we re-emit
6403 * the 3DSTATE_INDEX_BUFFER packet whenever the address changes.
6405 * There is also no need to handle these:
6406 * - PIPE_BIND_COMMAND_ARGS_BUFFER (emitted for every indirect draw)
6407 * - PIPE_BIND_QUERY_BUFFER (no persistent state references)
6410 if (res
->bind_history
& PIPE_BIND_STREAM_OUTPUT
) {
6411 /* XXX: be careful about resetting vs appending... */
6415 for (int s
= MESA_SHADER_VERTEX
; s
< MESA_SHADER_STAGES
; s
++) {
6416 struct iris_shader_state
*shs
= &ice
->state
.shaders
[s
];
6417 enum pipe_shader_type p_stage
= stage_to_pipe(s
);
6419 if (!(res
->bind_stages
& (1 << s
)))
6422 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
6423 /* Skip constant buffer 0, it's for regular uniforms, not UBOs */
6424 uint32_t bound_cbufs
= shs
->bound_cbufs
& ~1u;
6425 while (bound_cbufs
) {
6426 const int i
= u_bit_scan(&bound_cbufs
);
6427 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[i
];
6428 struct iris_state_ref
*surf_state
= &shs
->constbuf_surf_state
[i
];
6430 if (res
->bo
== iris_resource_bo(cbuf
->buffer
)) {
6431 pipe_resource_reference(&surf_state
->res
, NULL
);
6432 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< s
;
6437 if (res
->bind_history
& PIPE_BIND_SHADER_BUFFER
) {
6438 uint32_t bound_ssbos
= shs
->bound_ssbos
;
6439 while (bound_ssbos
) {
6440 const int i
= u_bit_scan(&bound_ssbos
);
6441 struct pipe_shader_buffer
*ssbo
= &shs
->ssbo
[i
];
6443 if (res
->bo
== iris_resource_bo(ssbo
->buffer
)) {
6444 struct pipe_shader_buffer buf
= {
6445 .buffer
= &res
->base
,
6446 .buffer_offset
= ssbo
->buffer_offset
,
6447 .buffer_size
= ssbo
->buffer_size
,
6449 iris_set_shader_buffers(ctx
, p_stage
, i
, 1, &buf
,
6450 (shs
->writable_ssbos
>> i
) & 1);
6455 if (res
->bind_history
& PIPE_BIND_SAMPLER_VIEW
) {
6456 uint32_t bound_sampler_views
= shs
->bound_sampler_views
;
6457 while (bound_sampler_views
) {
6458 const int i
= u_bit_scan(&bound_sampler_views
);
6459 struct iris_sampler_view
*isv
= shs
->textures
[i
];
6461 if (res
->bo
== iris_resource_bo(isv
->base
.texture
)) {
6462 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
6463 &isv
->surface_state
,
6464 isv
->res
->aux
.sampler_usages
);
6466 fill_buffer_surface_state(&screen
->isl_dev
, isv
->res
, map
,
6467 isv
->view
.format
, isv
->view
.swizzle
,
6468 isv
->base
.u
.buf
.offset
,
6469 isv
->base
.u
.buf
.size
);
6470 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< s
;
6475 if (res
->bind_history
& PIPE_BIND_SHADER_IMAGE
) {
6476 uint32_t bound_image_views
= shs
->bound_image_views
;
6477 while (bound_image_views
) {
6478 const int i
= u_bit_scan(&bound_image_views
);
6479 struct iris_image_view
*iv
= &shs
->image
[i
];
6481 if (res
->bo
== iris_resource_bo(iv
->base
.resource
)) {
6482 iris_set_shader_images(ctx
, p_stage
, i
, 1, &iv
->base
);
6489 /* ------------------------------------------------------------------- */
6492 flags_to_post_sync_op(uint32_t flags
)
6494 if (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
)
6495 return WriteImmediateData
;
6497 if (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
)
6498 return WritePSDepthCount
;
6500 if (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
)
6501 return WriteTimestamp
;
6507 * Do the given flags have a Post Sync or LRI Post Sync operation?
6509 static enum pipe_control_flags
6510 get_post_sync_flags(enum pipe_control_flags flags
)
6512 flags
&= PIPE_CONTROL_WRITE_IMMEDIATE
|
6513 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
6514 PIPE_CONTROL_WRITE_TIMESTAMP
|
6515 PIPE_CONTROL_LRI_POST_SYNC_OP
;
6517 /* Only one "Post Sync Op" is allowed, and it's mutually exclusive with
6518 * "LRI Post Sync Operation". So more than one bit set would be illegal.
6520 assert(util_bitcount(flags
) <= 1);
6525 #define IS_COMPUTE_PIPELINE(batch) (batch->name == IRIS_BATCH_COMPUTE)
6528 * Emit a series of PIPE_CONTROL commands, taking into account any
6529 * workarounds necessary to actually accomplish the caller's request.
6531 * Unless otherwise noted, spec quotations in this function come from:
6533 * Synchronization of the 3D Pipeline > PIPE_CONTROL Command > Programming
6534 * Restrictions for PIPE_CONTROL.
6536 * You should not use this function directly. Use the helpers in
6537 * iris_pipe_control.c instead, which may split the pipe control further.
6540 iris_emit_raw_pipe_control(struct iris_batch
*batch
,
6547 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
6548 enum pipe_control_flags post_sync_flags
= get_post_sync_flags(flags
);
6549 enum pipe_control_flags non_lri_post_sync_flags
=
6550 post_sync_flags
& ~PIPE_CONTROL_LRI_POST_SYNC_OP
;
6552 /* Recursive PIPE_CONTROL workarounds --------------------------------
6553 * (http://knowyourmeme.com/memes/xzibit-yo-dawg)
6555 * We do these first because we want to look at the original operation,
6556 * rather than any workarounds we set.
6558 if (GEN_GEN
== 9 && (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
)) {
6559 /* The PIPE_CONTROL "VF Cache Invalidation Enable" bit description
6560 * lists several workarounds:
6562 * "Project: SKL, KBL, BXT
6564 * If the VF Cache Invalidation Enable is set to a 1 in a
6565 * PIPE_CONTROL, a separate Null PIPE_CONTROL, all bitfields
6566 * sets to 0, with the VF Cache Invalidation Enable set to 0
6567 * needs to be sent prior to the PIPE_CONTROL with VF Cache
6568 * Invalidation Enable set to a 1."
6570 iris_emit_raw_pipe_control(batch
,
6571 "workaround: recursive VF cache invalidate",
6575 if (GEN_GEN
== 9 && IS_COMPUTE_PIPELINE(batch
) && post_sync_flags
) {
6576 /* Project: SKL / Argument: LRI Post Sync Operation [23]
6578 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
6579 * programmed prior to programming a PIPECONTROL command with "LRI
6580 * Post Sync Operation" in GPGPU mode of operation (i.e when
6581 * PIPELINE_SELECT command is set to GPGPU mode of operation)."
6583 * The same text exists a few rows below for Post Sync Op.
6585 iris_emit_raw_pipe_control(batch
,
6586 "workaround: CS stall before gpgpu post-sync",
6587 PIPE_CONTROL_CS_STALL
, bo
, offset
, imm
);
6590 if (GEN_GEN
== 10 && (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
)) {
6592 * "Before sending a PIPE_CONTROL command with bit 12 set, SW must issue
6593 * another PIPE_CONTROL with Render Target Cache Flush Enable (bit 12)
6594 * = 0 and Pipe Control Flush Enable (bit 7) = 1"
6596 iris_emit_raw_pipe_control(batch
,
6597 "workaround: PC flush before RT flush",
6598 PIPE_CONTROL_FLUSH_ENABLE
, bo
, offset
, imm
);
6601 /* "Flush Types" workarounds ---------------------------------------------
6602 * We do these now because they may add post-sync operations or CS stalls.
6605 if (GEN_GEN
< 11 && flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) {
6606 /* Project: BDW, SKL+ (stopping at CNL) / Argument: VF Invalidate
6608 * "'Post Sync Operation' must be enabled to 'Write Immediate Data' or
6609 * 'Write PS Depth Count' or 'Write Timestamp'."
6612 flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6613 post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6614 non_lri_post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6615 bo
= batch
->screen
->workaround_bo
;
6619 /* #1130 from Gen10 workarounds page:
6621 * "Enable Depth Stall on every Post Sync Op if Render target Cache
6622 * Flush is not enabled in same PIPE CONTROL and Enable Pixel score
6623 * board stall if Render target cache flush is enabled."
6625 * Applicable to CNL B0 and C0 steppings only.
6627 * The wording here is unclear, and this workaround doesn't look anything
6628 * like the internal bug report recommendations, but leave it be for now...
6630 if (GEN_GEN
== 10) {
6631 if (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) {
6632 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
6633 } else if (flags
& non_lri_post_sync_flags
) {
6634 flags
|= PIPE_CONTROL_DEPTH_STALL
;
6638 if (flags
& PIPE_CONTROL_DEPTH_STALL
) {
6639 /* From the PIPE_CONTROL instruction table, bit 13 (Depth Stall Enable):
6641 * "This bit must be DISABLED for operations other than writing
6644 * This seems like nonsense. An Ivybridge workaround requires us to
6645 * emit a PIPE_CONTROL with a depth stall and write immediate post-sync
6646 * operation. Gen8+ requires us to emit depth stalls and depth cache
6647 * flushes together. So, it's hard to imagine this means anything other
6648 * than "we originally intended this to be used for PS_DEPTH_COUNT".
6650 * We ignore the supposed restriction and do nothing.
6654 if (flags
& (PIPE_CONTROL_RENDER_TARGET_FLUSH
|
6655 PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
6656 /* From the PIPE_CONTROL instruction table, bit 12 and bit 1:
6658 * "This bit must be DISABLED for End-of-pipe (Read) fences,
6659 * PS_DEPTH_COUNT or TIMESTAMP queries."
6661 * TODO: Implement end-of-pipe checking.
6663 assert(!(post_sync_flags
& (PIPE_CONTROL_WRITE_DEPTH_COUNT
|
6664 PIPE_CONTROL_WRITE_TIMESTAMP
)));
6667 if (GEN_GEN
< 11 && (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
6668 /* From the PIPE_CONTROL instruction table, bit 1:
6670 * "This bit is ignored if Depth Stall Enable is set.
6671 * Further, the render cache is not flushed even if Write Cache
6672 * Flush Enable bit is set."
6674 * We assert that the caller doesn't do this combination, to try and
6675 * prevent mistakes. It shouldn't hurt the GPU, though.
6677 * We skip this check on Gen11+ as the "Stall at Pixel Scoreboard"
6678 * and "Render Target Flush" combo is explicitly required for BTI
6679 * update workarounds.
6681 assert(!(flags
& (PIPE_CONTROL_DEPTH_STALL
|
6682 PIPE_CONTROL_RENDER_TARGET_FLUSH
)));
6685 /* PIPE_CONTROL page workarounds ------------------------------------- */
6687 if (GEN_GEN
<= 8 && (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
)) {
6688 /* From the PIPE_CONTROL page itself:
6691 * Restriction: Pipe_control with CS-stall bit set must be issued
6692 * before a pipe-control command that has the State Cache
6693 * Invalidate bit set."
6695 flags
|= PIPE_CONTROL_CS_STALL
;
6698 if (flags
& PIPE_CONTROL_FLUSH_LLC
) {
6699 /* From the PIPE_CONTROL instruction table, bit 26 (Flush LLC):
6702 * SW must always program Post-Sync Operation to "Write Immediate
6703 * Data" when Flush LLC is set."
6705 * For now, we just require the caller to do it.
6707 assert(flags
& PIPE_CONTROL_WRITE_IMMEDIATE
);
6710 /* "Post-Sync Operation" workarounds -------------------------------- */
6712 /* Project: All / Argument: Global Snapshot Count Reset [19]
6714 * "This bit must not be exercised on any product.
6715 * Requires stall bit ([20] of DW1) set."
6717 * We don't use this, so we just assert that it isn't used. The
6718 * PIPE_CONTROL instruction page indicates that they intended this
6719 * as a debug feature and don't think it is useful in production,
6720 * but it may actually be usable, should we ever want to.
6722 assert((flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) == 0);
6724 if (flags
& (PIPE_CONTROL_MEDIA_STATE_CLEAR
|
6725 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
)) {
6726 /* Project: All / Arguments:
6728 * - Generic Media State Clear [16]
6729 * - Indirect State Pointers Disable [16]
6731 * "Requires stall bit ([20] of DW1) set."
6733 * Also, the PIPE_CONTROL instruction table, bit 16 (Generic Media
6734 * State Clear) says:
6736 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
6737 * programmed prior to programming a PIPECONTROL command with "Media
6738 * State Clear" set in GPGPU mode of operation"
6740 * This is a subset of the earlier rule, so there's nothing to do.
6742 flags
|= PIPE_CONTROL_CS_STALL
;
6745 if (flags
& PIPE_CONTROL_STORE_DATA_INDEX
) {
6746 /* Project: All / Argument: Store Data Index
6748 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
6751 * For now, we just assert that the caller does this. We might want to
6752 * automatically add a write to the workaround BO...
6754 assert(non_lri_post_sync_flags
!= 0);
6757 if (flags
& PIPE_CONTROL_SYNC_GFDT
) {
6758 /* Project: All / Argument: Sync GFDT
6760 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
6761 * than '0' or 0x2520[13] must be set."
6763 * For now, we just assert that the caller does this.
6765 assert(non_lri_post_sync_flags
!= 0);
6768 if (flags
& PIPE_CONTROL_TLB_INVALIDATE
) {
6769 /* Project: IVB+ / Argument: TLB inv
6771 * "Requires stall bit ([20] of DW1) set."
6773 * Also, from the PIPE_CONTROL instruction table:
6776 * Post Sync Operation or CS stall must be set to ensure a TLB
6777 * invalidation occurs. Otherwise no cycle will occur to the TLB
6778 * cache to invalidate."
6780 * This is not a subset of the earlier rule, so there's nothing to do.
6782 flags
|= PIPE_CONTROL_CS_STALL
;
6785 if (GEN_GEN
>= 12 && ((flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) ||
6786 (flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
))) {
6787 /* From the PIPE_CONTROL instruction table, bit 28 (Tile Cache Flush
6790 * Unified Cache (Tile Cache Disabled):
6792 * When the Color and Depth (Z) streams are enabled to be cached in
6793 * the DC space of L2, Software must use "Render Target Cache Flush
6794 * Enable" and "Depth Cache Flush Enable" along with "Tile Cache
6795 * Flush" for getting the color and depth (Z) write data to be
6796 * globally observable. In this mode of operation it is not required
6797 * to set "CS Stall" upon setting "Tile Cache Flush" bit.
6799 flags
|= PIPE_CONTROL_TILE_CACHE_FLUSH
;
6802 if (GEN_GEN
== 9 && devinfo
->gt
== 4) {
6803 /* TODO: The big Skylake GT4 post sync op workaround */
6806 /* "GPGPU specific workarounds" (both post-sync and flush) ------------ */
6808 if (IS_COMPUTE_PIPELINE(batch
)) {
6809 if (GEN_GEN
>= 9 && (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
)) {
6810 /* Project: SKL+ / Argument: Tex Invalidate
6811 * "Requires stall bit ([20] of DW) set for all GPGPU Workloads."
6813 flags
|= PIPE_CONTROL_CS_STALL
;
6816 if (GEN_GEN
== 8 && (post_sync_flags
||
6817 (flags
& (PIPE_CONTROL_NOTIFY_ENABLE
|
6818 PIPE_CONTROL_DEPTH_STALL
|
6819 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
6820 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
6821 PIPE_CONTROL_DATA_CACHE_FLUSH
)))) {
6822 /* Project: BDW / Arguments:
6824 * - LRI Post Sync Operation [23]
6825 * - Post Sync Op [15:14]
6827 * - Depth Stall [13]
6828 * - Render Target Cache Flush [12]
6829 * - Depth Cache Flush [0]
6830 * - DC Flush Enable [5]
6832 * "Requires stall bit ([20] of DW) set for all GPGPU and Media
6835 flags
|= PIPE_CONTROL_CS_STALL
;
6837 /* Also, from the PIPE_CONTROL instruction table, bit 20:
6840 * This bit must be always set when PIPE_CONTROL command is
6841 * programmed by GPGPU and MEDIA workloads, except for the cases
6842 * when only Read Only Cache Invalidation bits are set (State
6843 * Cache Invalidation Enable, Instruction cache Invalidation
6844 * Enable, Texture Cache Invalidation Enable, Constant Cache
6845 * Invalidation Enable). This is to WA FFDOP CG issue, this WA
6846 * need not implemented when FF_DOP_CG is disable via "Fixed
6847 * Function DOP Clock Gate Disable" bit in RC_PSMI_CTRL register."
6849 * It sounds like we could avoid CS stalls in some cases, but we
6850 * don't currently bother. This list isn't exactly the list above,
6856 /* "Stall" workarounds ----------------------------------------------
6857 * These have to come after the earlier ones because we may have added
6858 * some additional CS stalls above.
6861 if (GEN_GEN
< 9 && (flags
& PIPE_CONTROL_CS_STALL
)) {
6862 /* Project: PRE-SKL, VLV, CHV
6864 * "[All Stepping][All SKUs]:
6866 * One of the following must also be set:
6868 * - Render Target Cache Flush Enable ([12] of DW1)
6869 * - Depth Cache Flush Enable ([0] of DW1)
6870 * - Stall at Pixel Scoreboard ([1] of DW1)
6871 * - Depth Stall ([13] of DW1)
6872 * - Post-Sync Operation ([13] of DW1)
6873 * - DC Flush Enable ([5] of DW1)"
6875 * If we don't already have one of those bits set, we choose to add
6876 * "Stall at Pixel Scoreboard". Some of the other bits require a
6877 * CS stall as a workaround (see above), which would send us into
6878 * an infinite recursion of PIPE_CONTROLs. "Stall at Pixel Scoreboard"
6879 * appears to be safe, so we choose that.
6881 const uint32_t wa_bits
= PIPE_CONTROL_RENDER_TARGET_FLUSH
|
6882 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
6883 PIPE_CONTROL_WRITE_IMMEDIATE
|
6884 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
6885 PIPE_CONTROL_WRITE_TIMESTAMP
|
6886 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
6887 PIPE_CONTROL_DEPTH_STALL
|
6888 PIPE_CONTROL_DATA_CACHE_FLUSH
;
6889 if (!(flags
& wa_bits
))
6890 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
6893 /* Emit --------------------------------------------------------------- */
6895 if (INTEL_DEBUG
& DEBUG_PIPE_CONTROL
) {
6897 " PC [%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%"PRIx64
"]: %s\n",
6898 (flags
& PIPE_CONTROL_FLUSH_ENABLE
) ? "PipeCon " : "",
6899 (flags
& PIPE_CONTROL_CS_STALL
) ? "CS " : "",
6900 (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
) ? "Scoreboard " : "",
6901 (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) ? "VF " : "",
6902 (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) ? "RT " : "",
6903 (flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
) ? "Const " : "",
6904 (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
) ? "TC " : "",
6905 (flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
) ? "DC " : "",
6906 (flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
) ? "ZFlush " : "",
6907 (flags
& PIPE_CONTROL_DEPTH_STALL
) ? "ZStall " : "",
6908 (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
) ? "State " : "",
6909 (flags
& PIPE_CONTROL_TLB_INVALIDATE
) ? "TLB " : "",
6910 (flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
) ? "Inst " : "",
6911 (flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
) ? "MediaClear " : "",
6912 (flags
& PIPE_CONTROL_NOTIFY_ENABLE
) ? "Notify " : "",
6913 (flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) ?
6915 (flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
) ?
6917 (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
) ? "WriteImm " : "",
6918 (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
) ? "WriteZCount " : "",
6919 (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
) ? "WriteTimestamp " : "",
6923 iris_emit_cmd(batch
, GENX(PIPE_CONTROL
), pc
) {
6925 pc
.TileCacheFlushEnable
= flags
& PIPE_CONTROL_TILE_CACHE_FLUSH
;
6927 pc
.LRIPostSyncOperation
= NoLRIOperation
;
6928 pc
.PipeControlFlushEnable
= flags
& PIPE_CONTROL_FLUSH_ENABLE
;
6929 pc
.DCFlushEnable
= flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
;
6930 pc
.StoreDataIndex
= 0;
6931 pc
.CommandStreamerStallEnable
= flags
& PIPE_CONTROL_CS_STALL
;
6932 pc
.GlobalSnapshotCountReset
=
6933 flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
;
6934 pc
.TLBInvalidate
= flags
& PIPE_CONTROL_TLB_INVALIDATE
;
6935 pc
.GenericMediaStateClear
= flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
;
6936 pc
.StallAtPixelScoreboard
= flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
;
6937 pc
.RenderTargetCacheFlushEnable
=
6938 flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
;
6939 pc
.DepthCacheFlushEnable
= flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
;
6940 pc
.StateCacheInvalidationEnable
=
6941 flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
;
6942 pc
.VFCacheInvalidationEnable
= flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
;
6943 pc
.ConstantCacheInvalidationEnable
=
6944 flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
;
6945 pc
.PostSyncOperation
= flags_to_post_sync_op(flags
);
6946 pc
.DepthStallEnable
= flags
& PIPE_CONTROL_DEPTH_STALL
;
6947 pc
.InstructionCacheInvalidateEnable
=
6948 flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
;
6949 pc
.NotifyEnable
= flags
& PIPE_CONTROL_NOTIFY_ENABLE
;
6950 pc
.IndirectStatePointersDisable
=
6951 flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
;
6952 pc
.TextureCacheInvalidationEnable
=
6953 flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
6954 pc
.Address
= rw_bo(bo
, offset
);
6955 pc
.ImmediateData
= imm
;
6960 genX(emit_urb_setup
)(struct iris_context
*ice
,
6961 struct iris_batch
*batch
,
6962 const unsigned size
[4],
6963 bool tess_present
, bool gs_present
)
6965 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
6966 const unsigned push_size_kB
= 32;
6967 unsigned entries
[4];
6970 ice
->shaders
.last_vs_entry_size
= size
[MESA_SHADER_VERTEX
];
6972 gen_get_urb_config(devinfo
, 1024 * push_size_kB
,
6973 1024 * ice
->shaders
.urb_size
,
6974 tess_present
, gs_present
,
6975 size
, entries
, start
);
6977 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
6978 iris_emit_cmd(batch
, GENX(3DSTATE_URB_VS
), urb
) {
6979 urb
._3DCommandSubOpcode
+= i
;
6980 urb
.VSURBStartingAddress
= start
[i
];
6981 urb
.VSURBEntryAllocationSize
= size
[i
] - 1;
6982 urb
.VSNumberofURBEntries
= entries
[i
];
6989 * Preemption on Gen9 has to be enabled or disabled in various cases.
6991 * See these workarounds for preemption:
6992 * - WaDisableMidObjectPreemptionForGSLineStripAdj
6993 * - WaDisableMidObjectPreemptionForTrifanOrPolygon
6994 * - WaDisableMidObjectPreemptionForLineLoop
6997 * We don't put this in the vtable because it's only used on Gen9.
7000 gen9_toggle_preemption(struct iris_context
*ice
,
7001 struct iris_batch
*batch
,
7002 const struct pipe_draw_info
*draw
)
7004 struct iris_genx_state
*genx
= ice
->state
.genx
;
7005 bool object_preemption
= true;
7007 /* WaDisableMidObjectPreemptionForGSLineStripAdj
7009 * "WA: Disable mid-draw preemption when draw-call is a linestrip_adj
7010 * and GS is enabled."
7012 if (draw
->mode
== PIPE_PRIM_LINE_STRIP_ADJACENCY
&&
7013 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
])
7014 object_preemption
= false;
7016 /* WaDisableMidObjectPreemptionForTrifanOrPolygon
7018 * "TriFan miscompare in Execlist Preemption test. Cut index that is
7019 * on a previous context. End the previous, the resume another context
7020 * with a tri-fan or polygon, and the vertex count is corrupted. If we
7021 * prempt again we will cause corruption.
7023 * WA: Disable mid-draw preemption when draw-call has a tri-fan."
7025 if (draw
->mode
== PIPE_PRIM_TRIANGLE_FAN
)
7026 object_preemption
= false;
7028 /* WaDisableMidObjectPreemptionForLineLoop
7030 * "VF Stats Counters Missing a vertex when preemption enabled.
7032 * WA: Disable mid-draw preemption when the draw uses a lineloop
7035 if (draw
->mode
== PIPE_PRIM_LINE_LOOP
)
7036 object_preemption
= false;
7040 * "VF is corrupting GAFS data when preempted on an instance boundary
7041 * and replayed with instancing enabled.
7043 * WA: Disable preemption when using instanceing."
7045 if (draw
->instance_count
> 1)
7046 object_preemption
= false;
7048 if (genx
->object_preemption
!= object_preemption
) {
7049 iris_enable_obj_preemption(batch
, object_preemption
);
7050 genx
->object_preemption
= object_preemption
;
7056 iris_lost_genx_state(struct iris_context
*ice
, struct iris_batch
*batch
)
7058 struct iris_genx_state
*genx
= ice
->state
.genx
;
7060 memset(genx
->last_index_buffer
, 0, sizeof(genx
->last_index_buffer
));
7064 iris_emit_mi_report_perf_count(struct iris_batch
*batch
,
7066 uint32_t offset_in_bytes
,
7069 iris_emit_cmd(batch
, GENX(MI_REPORT_PERF_COUNT
), mi_rpc
) {
7070 mi_rpc
.MemoryAddress
= rw_bo(bo
, offset_in_bytes
);
7071 mi_rpc
.ReportID
= report_id
;
7076 * Update the pixel hashing modes that determine the balancing of PS threads
7077 * across subslices and slices.
7079 * \param width Width bound of the rendering area (already scaled down if \p
7080 * scale is greater than 1).
7081 * \param height Height bound of the rendering area (already scaled down if \p
7082 * scale is greater than 1).
7083 * \param scale The number of framebuffer samples that could potentially be
7084 * affected by an individual channel of the PS thread. This is
7085 * typically one for single-sampled rendering, but for operations
7086 * like CCS resolves and fast clears a single PS invocation may
7087 * update a huge number of pixels, in which case a finer
7088 * balancing is desirable in order to maximally utilize the
7089 * bandwidth available. UINT_MAX can be used as shorthand for
7090 * "finest hashing mode available".
7093 genX(emit_hashing_mode
)(struct iris_context
*ice
, struct iris_batch
*batch
,
7094 unsigned width
, unsigned height
, unsigned scale
)
7097 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
7098 const unsigned slice_hashing
[] = {
7099 /* Because all Gen9 platforms with more than one slice require
7100 * three-way subslice hashing, a single "normal" 16x16 slice hashing
7101 * block is guaranteed to suffer from substantial imbalance, with one
7102 * subslice receiving twice as much work as the other two in the
7105 * The performance impact of that would be particularly severe when
7106 * three-way hashing is also in use for slice balancing (which is the
7107 * case for all Gen9 GT4 platforms), because one of the slices
7108 * receives one every three 16x16 blocks in either direction, which
7109 * is roughly the periodicity of the underlying subslice imbalance
7110 * pattern ("roughly" because in reality the hardware's
7111 * implementation of three-way hashing doesn't do exact modulo 3
7112 * arithmetic, which somewhat decreases the magnitude of this effect
7113 * in practice). This leads to a systematic subslice imbalance
7114 * within that slice regardless of the size of the primitive. The
7115 * 32x32 hashing mode guarantees that the subslice imbalance within a
7116 * single slice hashing block is minimal, largely eliminating this
7120 /* Finest slice hashing mode available. */
7123 const unsigned subslice_hashing
[] = {
7124 /* 16x16 would provide a slight cache locality benefit especially
7125 * visible in the sampler L1 cache efficiency of low-bandwidth
7126 * non-LLC platforms, but it comes at the cost of greater subslice
7127 * imbalance for primitives of dimensions approximately intermediate
7128 * between 16x4 and 16x16.
7131 /* Finest subslice hashing mode available. */
7134 /* Dimensions of the smallest hashing block of a given hashing mode. If
7135 * the rendering area is smaller than this there can't possibly be any
7136 * benefit from switching to this mode, so we optimize out the
7139 const unsigned min_size
[][2] = {
7143 const unsigned idx
= scale
> 1;
7145 if (width
> min_size
[idx
][0] || height
> min_size
[idx
][1]) {
7148 iris_pack_state(GENX(GT_MODE
), >_mode
, reg
) {
7149 reg
.SliceHashing
= (devinfo
->num_slices
> 1 ? slice_hashing
[idx
] : 0);
7150 reg
.SliceHashingMask
= (devinfo
->num_slices
> 1 ? -1 : 0);
7151 reg
.SubsliceHashing
= subslice_hashing
[idx
];
7152 reg
.SubsliceHashingMask
= -1;
7155 iris_emit_raw_pipe_control(batch
,
7156 "workaround: CS stall before GT_MODE LRI",
7157 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
7158 PIPE_CONTROL_CS_STALL
,
7161 iris_emit_lri(batch
, GT_MODE
, gt_mode
);
7163 ice
->state
.current_hash_scale
= scale
;
7169 genX(init_state
)(struct iris_context
*ice
)
7171 struct pipe_context
*ctx
= &ice
->ctx
;
7172 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
7174 ctx
->create_blend_state
= iris_create_blend_state
;
7175 ctx
->create_depth_stencil_alpha_state
= iris_create_zsa_state
;
7176 ctx
->create_rasterizer_state
= iris_create_rasterizer_state
;
7177 ctx
->create_sampler_state
= iris_create_sampler_state
;
7178 ctx
->create_sampler_view
= iris_create_sampler_view
;
7179 ctx
->create_surface
= iris_create_surface
;
7180 ctx
->create_vertex_elements_state
= iris_create_vertex_elements
;
7181 ctx
->bind_blend_state
= iris_bind_blend_state
;
7182 ctx
->bind_depth_stencil_alpha_state
= iris_bind_zsa_state
;
7183 ctx
->bind_sampler_states
= iris_bind_sampler_states
;
7184 ctx
->bind_rasterizer_state
= iris_bind_rasterizer_state
;
7185 ctx
->bind_vertex_elements_state
= iris_bind_vertex_elements_state
;
7186 ctx
->delete_blend_state
= iris_delete_state
;
7187 ctx
->delete_depth_stencil_alpha_state
= iris_delete_state
;
7188 ctx
->delete_rasterizer_state
= iris_delete_state
;
7189 ctx
->delete_sampler_state
= iris_delete_state
;
7190 ctx
->delete_vertex_elements_state
= iris_delete_state
;
7191 ctx
->set_blend_color
= iris_set_blend_color
;
7192 ctx
->set_clip_state
= iris_set_clip_state
;
7193 ctx
->set_constant_buffer
= iris_set_constant_buffer
;
7194 ctx
->set_shader_buffers
= iris_set_shader_buffers
;
7195 ctx
->set_shader_images
= iris_set_shader_images
;
7196 ctx
->set_sampler_views
= iris_set_sampler_views
;
7197 ctx
->set_tess_state
= iris_set_tess_state
;
7198 ctx
->set_framebuffer_state
= iris_set_framebuffer_state
;
7199 ctx
->set_polygon_stipple
= iris_set_polygon_stipple
;
7200 ctx
->set_sample_mask
= iris_set_sample_mask
;
7201 ctx
->set_scissor_states
= iris_set_scissor_states
;
7202 ctx
->set_stencil_ref
= iris_set_stencil_ref
;
7203 ctx
->set_vertex_buffers
= iris_set_vertex_buffers
;
7204 ctx
->set_viewport_states
= iris_set_viewport_states
;
7205 ctx
->sampler_view_destroy
= iris_sampler_view_destroy
;
7206 ctx
->surface_destroy
= iris_surface_destroy
;
7207 ctx
->draw_vbo
= iris_draw_vbo
;
7208 ctx
->launch_grid
= iris_launch_grid
;
7209 ctx
->create_stream_output_target
= iris_create_stream_output_target
;
7210 ctx
->stream_output_target_destroy
= iris_stream_output_target_destroy
;
7211 ctx
->set_stream_output_targets
= iris_set_stream_output_targets
;
7213 ice
->vtbl
.destroy_state
= iris_destroy_state
;
7214 ice
->vtbl
.init_render_context
= iris_init_render_context
;
7215 ice
->vtbl
.init_compute_context
= iris_init_compute_context
;
7216 ice
->vtbl
.upload_render_state
= iris_upload_render_state
;
7217 ice
->vtbl
.update_surface_base_address
= iris_update_surface_base_address
;
7218 ice
->vtbl
.upload_compute_state
= iris_upload_compute_state
;
7219 ice
->vtbl
.emit_raw_pipe_control
= iris_emit_raw_pipe_control
;
7220 ice
->vtbl
.emit_mi_report_perf_count
= iris_emit_mi_report_perf_count
;
7221 ice
->vtbl
.rebind_buffer
= iris_rebind_buffer
;
7222 ice
->vtbl
.load_register_reg32
= iris_load_register_reg32
;
7223 ice
->vtbl
.load_register_reg64
= iris_load_register_reg64
;
7224 ice
->vtbl
.load_register_imm32
= iris_load_register_imm32
;
7225 ice
->vtbl
.load_register_imm64
= iris_load_register_imm64
;
7226 ice
->vtbl
.load_register_mem32
= iris_load_register_mem32
;
7227 ice
->vtbl
.load_register_mem64
= iris_load_register_mem64
;
7228 ice
->vtbl
.store_register_mem32
= iris_store_register_mem32
;
7229 ice
->vtbl
.store_register_mem64
= iris_store_register_mem64
;
7230 ice
->vtbl
.store_data_imm32
= iris_store_data_imm32
;
7231 ice
->vtbl
.store_data_imm64
= iris_store_data_imm64
;
7232 ice
->vtbl
.copy_mem_mem
= iris_copy_mem_mem
;
7233 ice
->vtbl
.derived_program_state_size
= iris_derived_program_state_size
;
7234 ice
->vtbl
.store_derived_program_state
= iris_store_derived_program_state
;
7235 ice
->vtbl
.create_so_decl_list
= iris_create_so_decl_list
;
7236 ice
->vtbl
.populate_vs_key
= iris_populate_vs_key
;
7237 ice
->vtbl
.populate_tcs_key
= iris_populate_tcs_key
;
7238 ice
->vtbl
.populate_tes_key
= iris_populate_tes_key
;
7239 ice
->vtbl
.populate_gs_key
= iris_populate_gs_key
;
7240 ice
->vtbl
.populate_fs_key
= iris_populate_fs_key
;
7241 ice
->vtbl
.populate_cs_key
= iris_populate_cs_key
;
7242 ice
->vtbl
.mocs
= mocs
;
7243 ice
->vtbl
.lost_genx_state
= iris_lost_genx_state
;
7245 ice
->state
.dirty
= ~0ull;
7247 ice
->state
.statistics_counters_enabled
= true;
7249 ice
->state
.sample_mask
= 0xffff;
7250 ice
->state
.num_viewports
= 1;
7251 ice
->state
.prim_mode
= PIPE_PRIM_MAX
;
7252 ice
->state
.genx
= calloc(1, sizeof(struct iris_genx_state
));
7253 ice
->draw
.derived_params
.drawid
= -1;
7255 /* Make a 1x1x1 null surface for unbound textures */
7256 void *null_surf_map
=
7257 upload_state(ice
->state
.surface_uploader
, &ice
->state
.unbound_tex
,
7258 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
7259 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
, isl_extent3d(1, 1, 1));
7260 ice
->state
.unbound_tex
.offset
+=
7261 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.unbound_tex
.res
));
7263 /* Default all scissor rectangles to be empty regions. */
7264 for (int i
= 0; i
< IRIS_MAX_VIEWPORTS
; i
++) {
7265 ice
->state
.scissors
[i
] = (struct pipe_scissor_state
) {
7266 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,