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 "util/u_memory.h"
99 #include "drm-uapi/i915_drm.h"
101 #include "intel/compiler/brw_compiler.h"
102 #include "intel/common/gen_aux_map.h"
103 #include "intel/common/gen_l3_config.h"
104 #include "intel/common/gen_sample_positions.h"
105 #include "iris_batch.h"
106 #include "iris_context.h"
107 #include "iris_defines.h"
108 #include "iris_pipe.h"
109 #include "iris_resource.h"
111 #include "iris_genx_macros.h"
112 #include "intel/common/gen_guardband.h"
115 * Statically assert that PIPE_* enums match the hardware packets.
116 * (As long as they match, we don't need to translate them.)
118 UNUSED
static void pipe_asserts()
120 #define PIPE_ASSERT(x) STATIC_ASSERT((int)x)
122 /* pipe_logicop happens to match the hardware. */
123 PIPE_ASSERT(PIPE_LOGICOP_CLEAR
== LOGICOP_CLEAR
);
124 PIPE_ASSERT(PIPE_LOGICOP_NOR
== LOGICOP_NOR
);
125 PIPE_ASSERT(PIPE_LOGICOP_AND_INVERTED
== LOGICOP_AND_INVERTED
);
126 PIPE_ASSERT(PIPE_LOGICOP_COPY_INVERTED
== LOGICOP_COPY_INVERTED
);
127 PIPE_ASSERT(PIPE_LOGICOP_AND_REVERSE
== LOGICOP_AND_REVERSE
);
128 PIPE_ASSERT(PIPE_LOGICOP_INVERT
== LOGICOP_INVERT
);
129 PIPE_ASSERT(PIPE_LOGICOP_XOR
== LOGICOP_XOR
);
130 PIPE_ASSERT(PIPE_LOGICOP_NAND
== LOGICOP_NAND
);
131 PIPE_ASSERT(PIPE_LOGICOP_AND
== LOGICOP_AND
);
132 PIPE_ASSERT(PIPE_LOGICOP_EQUIV
== LOGICOP_EQUIV
);
133 PIPE_ASSERT(PIPE_LOGICOP_NOOP
== LOGICOP_NOOP
);
134 PIPE_ASSERT(PIPE_LOGICOP_OR_INVERTED
== LOGICOP_OR_INVERTED
);
135 PIPE_ASSERT(PIPE_LOGICOP_COPY
== LOGICOP_COPY
);
136 PIPE_ASSERT(PIPE_LOGICOP_OR_REVERSE
== LOGICOP_OR_REVERSE
);
137 PIPE_ASSERT(PIPE_LOGICOP_OR
== LOGICOP_OR
);
138 PIPE_ASSERT(PIPE_LOGICOP_SET
== LOGICOP_SET
);
140 /* pipe_blend_func happens to match the hardware. */
141 PIPE_ASSERT(PIPE_BLENDFACTOR_ONE
== BLENDFACTOR_ONE
);
142 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_COLOR
== BLENDFACTOR_SRC_COLOR
);
143 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA
== BLENDFACTOR_SRC_ALPHA
);
144 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_ALPHA
== BLENDFACTOR_DST_ALPHA
);
145 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_COLOR
== BLENDFACTOR_DST_COLOR
);
146 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
== BLENDFACTOR_SRC_ALPHA_SATURATE
);
147 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_COLOR
== BLENDFACTOR_CONST_COLOR
);
148 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_ALPHA
== BLENDFACTOR_CONST_ALPHA
);
149 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_COLOR
== BLENDFACTOR_SRC1_COLOR
);
150 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_ALPHA
== BLENDFACTOR_SRC1_ALPHA
);
151 PIPE_ASSERT(PIPE_BLENDFACTOR_ZERO
== BLENDFACTOR_ZERO
);
152 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_COLOR
== BLENDFACTOR_INV_SRC_COLOR
);
153 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_ALPHA
== BLENDFACTOR_INV_SRC_ALPHA
);
154 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_ALPHA
== BLENDFACTOR_INV_DST_ALPHA
);
155 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_COLOR
== BLENDFACTOR_INV_DST_COLOR
);
156 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_COLOR
== BLENDFACTOR_INV_CONST_COLOR
);
157 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_ALPHA
== BLENDFACTOR_INV_CONST_ALPHA
);
158 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_COLOR
== BLENDFACTOR_INV_SRC1_COLOR
);
159 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_ALPHA
== BLENDFACTOR_INV_SRC1_ALPHA
);
161 /* pipe_blend_func happens to match the hardware. */
162 PIPE_ASSERT(PIPE_BLEND_ADD
== BLENDFUNCTION_ADD
);
163 PIPE_ASSERT(PIPE_BLEND_SUBTRACT
== BLENDFUNCTION_SUBTRACT
);
164 PIPE_ASSERT(PIPE_BLEND_REVERSE_SUBTRACT
== BLENDFUNCTION_REVERSE_SUBTRACT
);
165 PIPE_ASSERT(PIPE_BLEND_MIN
== BLENDFUNCTION_MIN
);
166 PIPE_ASSERT(PIPE_BLEND_MAX
== BLENDFUNCTION_MAX
);
168 /* pipe_stencil_op happens to match the hardware. */
169 PIPE_ASSERT(PIPE_STENCIL_OP_KEEP
== STENCILOP_KEEP
);
170 PIPE_ASSERT(PIPE_STENCIL_OP_ZERO
== STENCILOP_ZERO
);
171 PIPE_ASSERT(PIPE_STENCIL_OP_REPLACE
== STENCILOP_REPLACE
);
172 PIPE_ASSERT(PIPE_STENCIL_OP_INCR
== STENCILOP_INCRSAT
);
173 PIPE_ASSERT(PIPE_STENCIL_OP_DECR
== STENCILOP_DECRSAT
);
174 PIPE_ASSERT(PIPE_STENCIL_OP_INCR_WRAP
== STENCILOP_INCR
);
175 PIPE_ASSERT(PIPE_STENCIL_OP_DECR_WRAP
== STENCILOP_DECR
);
176 PIPE_ASSERT(PIPE_STENCIL_OP_INVERT
== STENCILOP_INVERT
);
178 /* pipe_sprite_coord_mode happens to match 3DSTATE_SBE */
179 PIPE_ASSERT(PIPE_SPRITE_COORD_UPPER_LEFT
== UPPERLEFT
);
180 PIPE_ASSERT(PIPE_SPRITE_COORD_LOWER_LEFT
== LOWERLEFT
);
185 translate_prim_type(enum pipe_prim_type prim
, uint8_t verts_per_patch
)
187 static const unsigned map
[] = {
188 [PIPE_PRIM_POINTS
] = _3DPRIM_POINTLIST
,
189 [PIPE_PRIM_LINES
] = _3DPRIM_LINELIST
,
190 [PIPE_PRIM_LINE_LOOP
] = _3DPRIM_LINELOOP
,
191 [PIPE_PRIM_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
192 [PIPE_PRIM_TRIANGLES
] = _3DPRIM_TRILIST
,
193 [PIPE_PRIM_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
194 [PIPE_PRIM_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
195 [PIPE_PRIM_QUADS
] = _3DPRIM_QUADLIST
,
196 [PIPE_PRIM_QUAD_STRIP
] = _3DPRIM_QUADSTRIP
,
197 [PIPE_PRIM_POLYGON
] = _3DPRIM_POLYGON
,
198 [PIPE_PRIM_LINES_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
199 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
200 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
201 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
202 [PIPE_PRIM_PATCHES
] = _3DPRIM_PATCHLIST_1
- 1,
205 return map
[prim
] + (prim
== PIPE_PRIM_PATCHES
? verts_per_patch
: 0);
209 translate_compare_func(enum pipe_compare_func pipe_func
)
211 static const unsigned map
[] = {
212 [PIPE_FUNC_NEVER
] = COMPAREFUNCTION_NEVER
,
213 [PIPE_FUNC_LESS
] = COMPAREFUNCTION_LESS
,
214 [PIPE_FUNC_EQUAL
] = COMPAREFUNCTION_EQUAL
,
215 [PIPE_FUNC_LEQUAL
] = COMPAREFUNCTION_LEQUAL
,
216 [PIPE_FUNC_GREATER
] = COMPAREFUNCTION_GREATER
,
217 [PIPE_FUNC_NOTEQUAL
] = COMPAREFUNCTION_NOTEQUAL
,
218 [PIPE_FUNC_GEQUAL
] = COMPAREFUNCTION_GEQUAL
,
219 [PIPE_FUNC_ALWAYS
] = COMPAREFUNCTION_ALWAYS
,
221 return map
[pipe_func
];
225 translate_shadow_func(enum pipe_compare_func pipe_func
)
227 /* Gallium specifies the result of shadow comparisons as:
229 * 1 if ref <op> texel,
234 * 0 if texel <op> ref,
237 * So we need to flip the operator and also negate.
239 static const unsigned map
[] = {
240 [PIPE_FUNC_NEVER
] = PREFILTEROPALWAYS
,
241 [PIPE_FUNC_LESS
] = PREFILTEROPLEQUAL
,
242 [PIPE_FUNC_EQUAL
] = PREFILTEROPNOTEQUAL
,
243 [PIPE_FUNC_LEQUAL
] = PREFILTEROPLESS
,
244 [PIPE_FUNC_GREATER
] = PREFILTEROPGEQUAL
,
245 [PIPE_FUNC_NOTEQUAL
] = PREFILTEROPEQUAL
,
246 [PIPE_FUNC_GEQUAL
] = PREFILTEROPGREATER
,
247 [PIPE_FUNC_ALWAYS
] = PREFILTEROPNEVER
,
249 return map
[pipe_func
];
253 translate_cull_mode(unsigned pipe_face
)
255 static const unsigned map
[4] = {
256 [PIPE_FACE_NONE
] = CULLMODE_NONE
,
257 [PIPE_FACE_FRONT
] = CULLMODE_FRONT
,
258 [PIPE_FACE_BACK
] = CULLMODE_BACK
,
259 [PIPE_FACE_FRONT_AND_BACK
] = CULLMODE_BOTH
,
261 return map
[pipe_face
];
265 translate_fill_mode(unsigned pipe_polymode
)
267 static const unsigned map
[4] = {
268 [PIPE_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
269 [PIPE_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
270 [PIPE_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
271 [PIPE_POLYGON_MODE_FILL_RECTANGLE
] = FILL_MODE_SOLID
,
273 return map
[pipe_polymode
];
277 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip
)
279 static const unsigned map
[] = {
280 [PIPE_TEX_MIPFILTER_NEAREST
] = MIPFILTER_NEAREST
,
281 [PIPE_TEX_MIPFILTER_LINEAR
] = MIPFILTER_LINEAR
,
282 [PIPE_TEX_MIPFILTER_NONE
] = MIPFILTER_NONE
,
284 return map
[pipe_mip
];
288 translate_wrap(unsigned pipe_wrap
)
290 static const unsigned map
[] = {
291 [PIPE_TEX_WRAP_REPEAT
] = TCM_WRAP
,
292 [PIPE_TEX_WRAP_CLAMP
] = TCM_HALF_BORDER
,
293 [PIPE_TEX_WRAP_CLAMP_TO_EDGE
] = TCM_CLAMP
,
294 [PIPE_TEX_WRAP_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
295 [PIPE_TEX_WRAP_MIRROR_REPEAT
] = TCM_MIRROR
,
296 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
298 /* These are unsupported. */
299 [PIPE_TEX_WRAP_MIRROR_CLAMP
] = -1,
300 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
] = -1,
302 return map
[pipe_wrap
];
306 * Allocate space for some indirect state.
308 * Return a pointer to the map (to fill it out) and a state ref (for
309 * referring to the state in GPU commands).
312 upload_state(struct u_upload_mgr
*uploader
,
313 struct iris_state_ref
*ref
,
318 u_upload_alloc(uploader
, 0, size
, alignment
, &ref
->offset
, &ref
->res
, &p
);
323 * Stream out temporary/short-lived state.
325 * This allocates space, pins the BO, and includes the BO address in the
326 * returned offset (which works because all state lives in 32-bit memory
330 stream_state(struct iris_batch
*batch
,
331 struct u_upload_mgr
*uploader
,
332 struct pipe_resource
**out_res
,
335 uint32_t *out_offset
)
339 u_upload_alloc(uploader
, 0, size
, alignment
, out_offset
, out_res
, &ptr
);
341 struct iris_bo
*bo
= iris_resource_bo(*out_res
);
342 iris_use_pinned_bo(batch
, bo
, false);
344 iris_record_state_size(batch
->state_sizes
,
345 bo
->gtt_offset
+ *out_offset
, size
);
347 *out_offset
+= iris_bo_offset_from_base_address(bo
);
353 * stream_state() + memcpy.
356 emit_state(struct iris_batch
*batch
,
357 struct u_upload_mgr
*uploader
,
358 struct pipe_resource
**out_res
,
365 stream_state(batch
, uploader
, out_res
, size
, alignment
, &offset
);
368 memcpy(map
, data
, size
);
374 * Did field 'x' change between 'old_cso' and 'new_cso'?
376 * (If so, we may want to set some dirty flags.)
378 #define cso_changed(x) (!old_cso || (old_cso->x != new_cso->x))
379 #define cso_changed_memcmp(x) \
380 (!old_cso || memcmp(old_cso->x, new_cso->x, sizeof(old_cso->x)) != 0)
383 flush_before_state_base_change(struct iris_batch
*batch
)
385 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
387 /* Flush before emitting STATE_BASE_ADDRESS.
389 * This isn't documented anywhere in the PRM. However, it seems to be
390 * necessary prior to changing the surface state base adress. We've
391 * seen issues in Vulkan where we get GPU hangs when using multi-level
392 * command buffers which clear depth, reset state base address, and then
395 * Normally, in GL, we would trust the kernel to do sufficient stalls
396 * and flushes prior to executing our batch. However, it doesn't seem
397 * as if the kernel's flushing is always sufficient and we don't want to
400 * We make this an end-of-pipe sync instead of a normal flush because we
401 * do not know the current status of the GPU. On Haswell at least,
402 * having a fast-clear operation in flight at the same time as a normal
403 * rendering operation can cause hangs. Since the kernel's flushing is
404 * insufficient, we need to ensure that any rendering operations from
405 * other processes are definitely complete before we try to do our own
406 * rendering. It's a bit of a big hammer but it appears to work.
408 iris_emit_end_of_pipe_sync(batch
,
409 "change STATE_BASE_ADDRESS (flushes)",
410 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
411 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
412 PIPE_CONTROL_DATA_CACHE_FLUSH
|
413 /* GEN:BUG:1606662791:
415 * Software must program PIPE_CONTROL command
416 * with "HDC Pipeline Flush" prior to
417 * programming of the below two non-pipeline
419 * * STATE_BASE_ADDRESS
420 * * 3DSTATE_BINDING_TABLE_POOL_ALLOC
422 ((GEN_GEN
== 12 && devinfo
->revision
== 0 /* A0 */ ?
423 PIPE_CONTROL_FLUSH_HDC
: 0)));
427 flush_after_state_base_change(struct iris_batch
*batch
)
429 /* After re-setting the surface state base address, we have to do some
430 * cache flusing so that the sampler engine will pick up the new
431 * SURFACE_STATE objects and binding tables. From the Broadwell PRM,
432 * Shared Function > 3D Sampler > State > State Caching (page 96):
434 * Coherency with system memory in the state cache, like the texture
435 * cache is handled partially by software. It is expected that the
436 * command stream or shader will issue Cache Flush operation or
437 * Cache_Flush sampler message to ensure that the L1 cache remains
438 * coherent with system memory.
442 * Whenever the value of the Dynamic_State_Base_Addr,
443 * Surface_State_Base_Addr are altered, the L1 state cache must be
444 * invalidated to ensure the new surface or sampler state is fetched
445 * from system memory.
447 * The PIPE_CONTROL command has a "State Cache Invalidation Enable" bit
448 * which, according the PIPE_CONTROL instruction documentation in the
451 * Setting this bit is independent of any other bit in this packet.
452 * This bit controls the invalidation of the L1 and L2 state caches
453 * at the top of the pipe i.e. at the parsing time.
455 * Unfortunately, experimentation seems to indicate that state cache
456 * invalidation through a PIPE_CONTROL does nothing whatsoever in
457 * regards to surface state and binding tables. In stead, it seems that
458 * invalidating the texture cache is what is actually needed.
460 * XXX: As far as we have been able to determine through
461 * experimentation, shows that flush the texture cache appears to be
462 * sufficient. The theory here is that all of the sampling/rendering
463 * units cache the binding table in the texture cache. However, we have
464 * yet to be able to actually confirm this.
466 iris_emit_end_of_pipe_sync(batch
,
467 "change STATE_BASE_ADDRESS (invalidates)",
468 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
469 PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
470 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
474 _iris_emit_lri(struct iris_batch
*batch
, uint32_t reg
, uint32_t val
)
476 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
477 lri
.RegisterOffset
= reg
;
481 #define iris_emit_lri(b, r, v) _iris_emit_lri(b, GENX(r##_num), v)
484 _iris_emit_lrr(struct iris_batch
*batch
, uint32_t dst
, uint32_t src
)
486 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_REG
), lrr
) {
487 lrr
.SourceRegisterAddress
= src
;
488 lrr
.DestinationRegisterAddress
= dst
;
493 iris_load_register_reg32(struct iris_batch
*batch
, uint32_t dst
,
496 _iris_emit_lrr(batch
, dst
, src
);
500 iris_load_register_reg64(struct iris_batch
*batch
, uint32_t dst
,
503 _iris_emit_lrr(batch
, dst
, src
);
504 _iris_emit_lrr(batch
, dst
+ 4, src
+ 4);
508 iris_load_register_imm32(struct iris_batch
*batch
, uint32_t reg
,
511 _iris_emit_lri(batch
, reg
, val
);
515 iris_load_register_imm64(struct iris_batch
*batch
, uint32_t reg
,
518 _iris_emit_lri(batch
, reg
+ 0, val
& 0xffffffff);
519 _iris_emit_lri(batch
, reg
+ 4, val
>> 32);
523 * Emit MI_LOAD_REGISTER_MEM to load a 32-bit MMIO register from a buffer.
526 iris_load_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
527 struct iris_bo
*bo
, uint32_t offset
)
529 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
530 lrm
.RegisterAddress
= reg
;
531 lrm
.MemoryAddress
= ro_bo(bo
, offset
);
536 * Load a 64-bit value from a buffer into a MMIO register via
537 * two MI_LOAD_REGISTER_MEM commands.
540 iris_load_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
541 struct iris_bo
*bo
, uint32_t offset
)
543 iris_load_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0);
544 iris_load_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4);
548 iris_store_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
549 struct iris_bo
*bo
, uint32_t offset
,
552 iris_emit_cmd(batch
, GENX(MI_STORE_REGISTER_MEM
), srm
) {
553 srm
.RegisterAddress
= reg
;
554 srm
.MemoryAddress
= rw_bo(bo
, offset
);
555 srm
.PredicateEnable
= predicated
;
560 iris_store_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
561 struct iris_bo
*bo
, uint32_t offset
,
564 iris_store_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0, predicated
);
565 iris_store_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4, predicated
);
569 iris_store_data_imm32(struct iris_batch
*batch
,
570 struct iris_bo
*bo
, uint32_t offset
,
573 iris_emit_cmd(batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
574 sdi
.Address
= rw_bo(bo
, offset
);
575 sdi
.ImmediateData
= imm
;
580 iris_store_data_imm64(struct iris_batch
*batch
,
581 struct iris_bo
*bo
, uint32_t offset
,
584 /* Can't use iris_emit_cmd because MI_STORE_DATA_IMM has a length of
585 * 2 in genxml but it's actually variable length and we need 5 DWords.
587 void *map
= iris_get_command_space(batch
, 4 * 5);
588 _iris_pack_command(batch
, GENX(MI_STORE_DATA_IMM
), map
, sdi
) {
589 sdi
.DWordLength
= 5 - 2;
590 sdi
.Address
= rw_bo(bo
, offset
);
591 sdi
.ImmediateData
= imm
;
596 iris_copy_mem_mem(struct iris_batch
*batch
,
597 struct iris_bo
*dst_bo
, uint32_t dst_offset
,
598 struct iris_bo
*src_bo
, uint32_t src_offset
,
601 /* MI_COPY_MEM_MEM operates on DWords. */
602 assert(bytes
% 4 == 0);
603 assert(dst_offset
% 4 == 0);
604 assert(src_offset
% 4 == 0);
606 for (unsigned i
= 0; i
< bytes
; i
+= 4) {
607 iris_emit_cmd(batch
, GENX(MI_COPY_MEM_MEM
), cp
) {
608 cp
.DestinationMemoryAddress
= rw_bo(dst_bo
, dst_offset
+ i
);
609 cp
.SourceMemoryAddress
= ro_bo(src_bo
, src_offset
+ i
);
615 emit_pipeline_select(struct iris_batch
*batch
, uint32_t pipeline
)
617 #if GEN_GEN >= 8 && GEN_GEN < 10
618 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
620 * Software must clear the COLOR_CALC_STATE Valid field in
621 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
622 * with Pipeline Select set to GPGPU.
624 * The internal hardware docs recommend the same workaround for Gen9
627 if (pipeline
== GPGPU
)
628 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), t
);
632 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
633 * PIPELINE_SELECT [DevBWR+]":
637 * Software must ensure all the write caches are flushed through a
638 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
639 * command to invalidate read only caches prior to programming
640 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode."
642 iris_emit_pipe_control_flush(batch
,
643 "workaround: PIPELINE_SELECT flushes (1/2)",
644 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
645 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
646 PIPE_CONTROL_DATA_CACHE_FLUSH
|
647 PIPE_CONTROL_CS_STALL
);
649 iris_emit_pipe_control_flush(batch
,
650 "workaround: PIPELINE_SELECT flushes (2/2)",
651 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
652 PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
653 PIPE_CONTROL_STATE_CACHE_INVALIDATE
|
654 PIPE_CONTROL_INSTRUCTION_INVALIDATE
);
656 iris_emit_cmd(batch
, GENX(PIPELINE_SELECT
), sel
) {
660 sel
.PipelineSelection
= pipeline
;
665 init_glk_barrier_mode(struct iris_batch
*batch
, uint32_t value
)
670 * "This chicken bit works around a hardware issue with barrier
671 * logic encountered when switching between GPGPU and 3D pipelines.
672 * To workaround the issue, this mode bit should be set after a
673 * pipeline is selected."
676 iris_pack_state(GENX(SLICE_COMMON_ECO_CHICKEN1
), ®_val
, reg
) {
677 reg
.GLKBarrierMode
= value
;
678 reg
.GLKBarrierModeMask
= 1;
680 iris_emit_lri(batch
, SLICE_COMMON_ECO_CHICKEN1
, reg_val
);
685 init_state_base_address(struct iris_batch
*batch
)
687 uint32_t mocs
= batch
->screen
->isl_dev
.mocs
.internal
;
688 flush_before_state_base_change(batch
);
690 /* We program most base addresses once at context initialization time.
691 * Each base address points at a 4GB memory zone, and never needs to
692 * change. See iris_bufmgr.h for a description of the memory zones.
694 * The one exception is Surface State Base Address, which needs to be
695 * updated occasionally. See iris_binder.c for the details there.
697 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
698 sba
.GeneralStateMOCS
= mocs
;
699 sba
.StatelessDataPortAccessMOCS
= mocs
;
700 sba
.DynamicStateMOCS
= mocs
;
701 sba
.IndirectObjectMOCS
= mocs
;
702 sba
.InstructionMOCS
= mocs
;
703 sba
.SurfaceStateMOCS
= mocs
;
705 sba
.GeneralStateBaseAddressModifyEnable
= true;
706 sba
.DynamicStateBaseAddressModifyEnable
= true;
707 sba
.IndirectObjectBaseAddressModifyEnable
= true;
708 sba
.InstructionBaseAddressModifyEnable
= true;
709 sba
.GeneralStateBufferSizeModifyEnable
= true;
710 sba
.DynamicStateBufferSizeModifyEnable
= true;
712 sba
.BindlessSurfaceStateBaseAddressModifyEnable
= true;
713 sba
.BindlessSurfaceStateMOCS
= mocs
;
715 sba
.IndirectObjectBufferSizeModifyEnable
= true;
716 sba
.InstructionBuffersizeModifyEnable
= true;
718 sba
.InstructionBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_SHADER_START
);
719 sba
.DynamicStateBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_DYNAMIC_START
);
721 sba
.GeneralStateBufferSize
= 0xfffff;
722 sba
.IndirectObjectBufferSize
= 0xfffff;
723 sba
.InstructionBufferSize
= 0xfffff;
724 sba
.DynamicStateBufferSize
= 0xfffff;
727 flush_after_state_base_change(batch
);
731 iris_emit_l3_config(struct iris_batch
*batch
,
732 const struct gen_l3_config
*cfg
)
737 #define L3_ALLOCATION_REG GENX(L3ALLOC)
738 #define L3_ALLOCATION_REG_num GENX(L3ALLOC_num)
740 #define L3_ALLOCATION_REG GENX(L3CNTLREG)
741 #define L3_ALLOCATION_REG_num GENX(L3CNTLREG_num)
744 iris_pack_state(L3_ALLOCATION_REG
, ®_val
, reg
) {
746 reg
.SLMEnable
= cfg
->n
[GEN_L3P_SLM
] > 0;
749 /* WA_1406697149: Bit 9 "Error Detection Behavior Control" must be set
750 * in L3CNTLREG register. The default setting of the bit is not the
751 * desirable behavior.
753 reg
.ErrorDetectionBehaviorControl
= true;
754 reg
.UseFullWays
= true;
756 reg
.URBAllocation
= cfg
->n
[GEN_L3P_URB
];
757 reg
.ROAllocation
= cfg
->n
[GEN_L3P_RO
];
758 reg
.DCAllocation
= cfg
->n
[GEN_L3P_DC
];
759 reg
.AllAllocation
= cfg
->n
[GEN_L3P_ALL
];
761 _iris_emit_lri(batch
, L3_ALLOCATION_REG_num
, reg_val
);
766 iris_enable_obj_preemption(struct iris_batch
*batch
, bool enable
)
770 /* A fixed function pipe flush is required before modifying this field */
771 iris_emit_end_of_pipe_sync(batch
, enable
? "enable preemption"
772 : "disable preemption",
773 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
775 /* enable object level preemption */
776 iris_pack_state(GENX(CS_CHICKEN1
), ®_val
, reg
) {
777 reg
.ReplayMode
= enable
;
778 reg
.ReplayModeMask
= true;
780 iris_emit_lri(batch
, CS_CHICKEN1
, reg_val
);
786 iris_upload_slice_hashing_state(struct iris_batch
*batch
)
788 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
789 int subslices_delta
=
790 devinfo
->ppipe_subslices
[0] - devinfo
->ppipe_subslices
[1];
791 if (subslices_delta
== 0)
794 struct iris_context
*ice
= NULL
;
795 ice
= container_of(batch
, ice
, batches
[IRIS_BATCH_RENDER
]);
796 assert(&ice
->batches
[IRIS_BATCH_RENDER
] == batch
);
798 unsigned size
= GENX(SLICE_HASH_TABLE_length
) * 4;
799 uint32_t hash_address
;
800 struct pipe_resource
*tmp
= NULL
;
802 stream_state(batch
, ice
->state
.dynamic_uploader
, &tmp
,
803 size
, 64, &hash_address
);
804 pipe_resource_reference(&tmp
, NULL
);
806 struct GENX(SLICE_HASH_TABLE
) table0
= {
808 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
809 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
810 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
811 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
812 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
813 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
814 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
815 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
816 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
817 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
818 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
819 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
820 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
821 { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
822 { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
823 { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }
827 struct GENX(SLICE_HASH_TABLE
) table1
= {
829 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
830 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
831 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
832 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
833 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
834 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
835 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
836 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
837 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
838 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
839 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
840 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
841 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
842 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
843 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
844 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 }
848 const struct GENX(SLICE_HASH_TABLE
) *table
=
849 subslices_delta
< 0 ? &table0
: &table1
;
850 GENX(SLICE_HASH_TABLE_pack
)(NULL
, map
, table
);
852 iris_emit_cmd(batch
, GENX(3DSTATE_SLICE_TABLE_STATE_POINTERS
), ptr
) {
853 ptr
.SliceHashStatePointerValid
= true;
854 ptr
.SliceHashTableStatePointer
= hash_address
;
857 iris_emit_cmd(batch
, GENX(3DSTATE_3D_MODE
), mode
) {
858 mode
.SliceHashingTableEnable
= true;
864 iris_alloc_push_constants(struct iris_batch
*batch
)
866 /* For now, we set a static partitioning of the push constant area,
867 * assuming that all stages could be in use.
869 * TODO: Try lazily allocating the HS/DS/GS sections as needed, and
870 * see if that improves performance by offering more space to
871 * the VS/FS when those aren't in use. Also, try dynamically
872 * enabling/disabling it like i965 does. This would be more
873 * stalls and may not actually help; we don't know yet.
875 for (int i
= 0; i
<= MESA_SHADER_FRAGMENT
; i
++) {
876 iris_emit_cmd(batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
), alloc
) {
877 alloc
._3DCommandSubOpcode
= 18 + i
;
878 alloc
.ConstantBufferOffset
= 6 * i
;
879 alloc
.ConstantBufferSize
= i
== MESA_SHADER_FRAGMENT
? 8 : 6;
886 init_aux_map_state(struct iris_batch
*batch
);
890 * Upload the initial GPU state for a render context.
892 * This sets some invariant state that needs to be programmed a particular
893 * way, but we never actually change.
896 iris_init_render_context(struct iris_batch
*batch
)
898 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
901 emit_pipeline_select(batch
, _3D
);
903 iris_emit_l3_config(batch
, batch
->screen
->l3_config_3d
);
905 init_state_base_address(batch
);
908 iris_pack_state(GENX(CS_DEBUG_MODE2
), ®_val
, reg
) {
909 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
910 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
912 iris_emit_lri(batch
, CS_DEBUG_MODE2
, reg_val
);
914 iris_pack_state(GENX(INSTPM
), ®_val
, reg
) {
915 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
916 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
918 iris_emit_lri(batch
, INSTPM
, reg_val
);
922 iris_pack_state(GENX(CACHE_MODE_1
), ®_val
, reg
) {
923 reg
.FloatBlendOptimizationEnable
= true;
924 reg
.FloatBlendOptimizationEnableMask
= true;
925 reg
.PartialResolveDisableInVC
= true;
926 reg
.PartialResolveDisableInVCMask
= true;
928 iris_emit_lri(batch
, CACHE_MODE_1
, reg_val
);
930 if (devinfo
->is_geminilake
)
931 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_3D_HULL
);
935 iris_pack_state(GENX(TCCNTLREG
), ®_val
, reg
) {
936 reg
.L3DataPartialWriteMergingEnable
= true;
937 reg
.ColorZPartialWriteMergingEnable
= true;
938 reg
.URBPartialWriteMergingEnable
= true;
939 reg
.TCDisable
= true;
941 iris_emit_lri(batch
, TCCNTLREG
, reg_val
);
943 iris_pack_state(GENX(SAMPLER_MODE
), ®_val
, reg
) {
944 reg
.HeaderlessMessageforPreemptableContexts
= 1;
945 reg
.HeaderlessMessageforPreemptableContextsMask
= 1;
947 iris_emit_lri(batch
, SAMPLER_MODE
, reg_val
);
949 /* Bit 1 must be set in HALF_SLICE_CHICKEN7. */
950 iris_pack_state(GENX(HALF_SLICE_CHICKEN7
), ®_val
, reg
) {
951 reg
.EnabledTexelOffsetPrecisionFix
= 1;
952 reg
.EnabledTexelOffsetPrecisionFixMask
= 1;
954 iris_emit_lri(batch
, HALF_SLICE_CHICKEN7
, reg_val
);
956 /* Hardware specification recommends disabling repacking for the
957 * compatibility with decompression mechanism in display controller.
959 if (devinfo
->disable_ccs_repack
) {
960 iris_pack_state(GENX(CACHE_MODE_0
), ®_val
, reg
) {
961 reg
.DisableRepackingforCompression
= true;
962 reg
.DisableRepackingforCompressionMask
= true;
964 iris_emit_lri(batch
, CACHE_MODE_0
, reg_val
);
967 iris_upload_slice_hashing_state(batch
);
970 /* 3DSTATE_DRAWING_RECTANGLE is non-pipelined, so we want to avoid
971 * changing it dynamically. We set it to the maximum size here, and
972 * instead include the render target dimensions in the viewport, so
973 * viewport extents clipping takes care of pruning stray geometry.
975 iris_emit_cmd(batch
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
976 rect
.ClippedDrawingRectangleXMax
= UINT16_MAX
;
977 rect
.ClippedDrawingRectangleYMax
= UINT16_MAX
;
980 /* Set the initial MSAA sample positions. */
981 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_PATTERN
), pat
) {
982 GEN_SAMPLE_POS_1X(pat
._1xSample
);
983 GEN_SAMPLE_POS_2X(pat
._2xSample
);
984 GEN_SAMPLE_POS_4X(pat
._4xSample
);
985 GEN_SAMPLE_POS_8X(pat
._8xSample
);
987 GEN_SAMPLE_POS_16X(pat
._16xSample
);
991 /* Use the legacy AA line coverage computation. */
992 iris_emit_cmd(batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
), foo
);
994 /* Disable chromakeying (it's for media) */
995 iris_emit_cmd(batch
, GENX(3DSTATE_WM_CHROMAKEY
), foo
);
997 /* We want regular rendering, not special HiZ operations. */
998 iris_emit_cmd(batch
, GENX(3DSTATE_WM_HZ_OP
), foo
);
1000 /* No polygon stippling offsets are necessary. */
1001 /* TODO: may need to set an offset for origin-UL framebuffers */
1002 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), foo
);
1004 iris_alloc_push_constants(batch
);
1007 init_aux_map_state(batch
);
1012 iris_init_compute_context(struct iris_batch
*batch
)
1014 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
1016 /* GEN:BUG:1607854226:
1018 * Start with pipeline in 3D mode to set the STATE_BASE_ADDRESS.
1021 emit_pipeline_select(batch
, _3D
);
1023 emit_pipeline_select(batch
, GPGPU
);
1026 iris_emit_l3_config(batch
, batch
->screen
->l3_config_cs
);
1028 init_state_base_address(batch
);
1031 emit_pipeline_select(batch
, GPGPU
);
1035 if (devinfo
->is_geminilake
)
1036 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_GPGPU
);
1040 init_aux_map_state(batch
);
1045 struct iris_vertex_buffer_state
{
1046 /** The VERTEX_BUFFER_STATE hardware structure. */
1047 uint32_t state
[GENX(VERTEX_BUFFER_STATE_length
)];
1049 /** The resource to source vertex data from. */
1050 struct pipe_resource
*resource
;
1055 struct iris_depth_buffer_state
{
1056 /* Depth/HiZ/Stencil related hardware packets. */
1057 uint32_t packets
[GENX(3DSTATE_DEPTH_BUFFER_length
) +
1058 GENX(3DSTATE_STENCIL_BUFFER_length
) +
1059 GENX(3DSTATE_HIER_DEPTH_BUFFER_length
) +
1060 GENX(3DSTATE_CLEAR_PARAMS_length
) +
1061 GENX(MI_LOAD_REGISTER_IMM_length
) * 2];
1065 * Generation-specific context state (ice->state.genx->...).
1067 * Most state can go in iris_context directly, but these encode hardware
1068 * packets which vary by generation.
1070 struct iris_genx_state
{
1071 struct iris_vertex_buffer_state vertex_buffers
[33];
1072 uint32_t last_index_buffer
[GENX(3DSTATE_INDEX_BUFFER_length
)];
1074 struct iris_depth_buffer_state depth_buffer
;
1076 uint32_t so_buffers
[4 * GENX(3DSTATE_SO_BUFFER_length
)];
1079 bool pma_fix_enabled
;
1083 /* Is object level preemption enabled? */
1084 bool object_preemption
;
1089 struct brw_image_param image_param
[PIPE_MAX_SHADER_IMAGES
];
1091 } shaders
[MESA_SHADER_STAGES
];
1095 * The pipe->set_blend_color() driver hook.
1097 * This corresponds to our COLOR_CALC_STATE.
1100 iris_set_blend_color(struct pipe_context
*ctx
,
1101 const struct pipe_blend_color
*state
)
1103 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1105 /* Our COLOR_CALC_STATE is exactly pipe_blend_color, so just memcpy */
1106 memcpy(&ice
->state
.blend_color
, state
, sizeof(struct pipe_blend_color
));
1107 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
1111 * Gallium CSO for blend state (see pipe_blend_state).
1113 struct iris_blend_state
{
1114 /** Partial 3DSTATE_PS_BLEND */
1115 uint32_t ps_blend
[GENX(3DSTATE_PS_BLEND_length
)];
1117 /** Partial BLEND_STATE */
1118 uint32_t blend_state
[GENX(BLEND_STATE_length
) +
1119 BRW_MAX_DRAW_BUFFERS
* GENX(BLEND_STATE_ENTRY_length
)];
1121 bool alpha_to_coverage
; /* for shader key */
1123 /** Bitfield of whether blending is enabled for RT[i] - for aux resolves */
1124 uint8_t blend_enables
;
1126 /** Bitfield of whether color writes are enabled for RT[i] */
1127 uint8_t color_write_enables
;
1129 /** Does RT[0] use dual color blending? */
1130 bool dual_color_blending
;
1133 static enum pipe_blendfactor
1134 fix_blendfactor(enum pipe_blendfactor f
, bool alpha_to_one
)
1137 if (f
== PIPE_BLENDFACTOR_SRC1_ALPHA
)
1138 return PIPE_BLENDFACTOR_ONE
;
1140 if (f
== PIPE_BLENDFACTOR_INV_SRC1_ALPHA
)
1141 return PIPE_BLENDFACTOR_ZERO
;
1148 * The pipe->create_blend_state() driver hook.
1150 * Translates a pipe_blend_state into iris_blend_state.
1153 iris_create_blend_state(struct pipe_context
*ctx
,
1154 const struct pipe_blend_state
*state
)
1156 struct iris_blend_state
*cso
= malloc(sizeof(struct iris_blend_state
));
1157 uint32_t *blend_entry
= cso
->blend_state
+ GENX(BLEND_STATE_length
);
1159 cso
->blend_enables
= 0;
1160 cso
->color_write_enables
= 0;
1161 STATIC_ASSERT(BRW_MAX_DRAW_BUFFERS
<= 8);
1163 cso
->alpha_to_coverage
= state
->alpha_to_coverage
;
1165 bool indep_alpha_blend
= false;
1167 for (int i
= 0; i
< BRW_MAX_DRAW_BUFFERS
; i
++) {
1168 const struct pipe_rt_blend_state
*rt
=
1169 &state
->rt
[state
->independent_blend_enable
? i
: 0];
1171 enum pipe_blendfactor src_rgb
=
1172 fix_blendfactor(rt
->rgb_src_factor
, state
->alpha_to_one
);
1173 enum pipe_blendfactor src_alpha
=
1174 fix_blendfactor(rt
->alpha_src_factor
, state
->alpha_to_one
);
1175 enum pipe_blendfactor dst_rgb
=
1176 fix_blendfactor(rt
->rgb_dst_factor
, state
->alpha_to_one
);
1177 enum pipe_blendfactor dst_alpha
=
1178 fix_blendfactor(rt
->alpha_dst_factor
, state
->alpha_to_one
);
1180 if (rt
->rgb_func
!= rt
->alpha_func
||
1181 src_rgb
!= src_alpha
|| dst_rgb
!= dst_alpha
)
1182 indep_alpha_blend
= true;
1184 if (rt
->blend_enable
)
1185 cso
->blend_enables
|= 1u << i
;
1188 cso
->color_write_enables
|= 1u << i
;
1190 iris_pack_state(GENX(BLEND_STATE_ENTRY
), blend_entry
, be
) {
1191 be
.LogicOpEnable
= state
->logicop_enable
;
1192 be
.LogicOpFunction
= state
->logicop_func
;
1194 be
.PreBlendSourceOnlyClampEnable
= false;
1195 be
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
1196 be
.PreBlendColorClampEnable
= true;
1197 be
.PostBlendColorClampEnable
= true;
1199 be
.ColorBufferBlendEnable
= rt
->blend_enable
;
1201 be
.ColorBlendFunction
= rt
->rgb_func
;
1202 be
.AlphaBlendFunction
= rt
->alpha_func
;
1203 be
.SourceBlendFactor
= src_rgb
;
1204 be
.SourceAlphaBlendFactor
= src_alpha
;
1205 be
.DestinationBlendFactor
= dst_rgb
;
1206 be
.DestinationAlphaBlendFactor
= dst_alpha
;
1208 be
.WriteDisableRed
= !(rt
->colormask
& PIPE_MASK_R
);
1209 be
.WriteDisableGreen
= !(rt
->colormask
& PIPE_MASK_G
);
1210 be
.WriteDisableBlue
= !(rt
->colormask
& PIPE_MASK_B
);
1211 be
.WriteDisableAlpha
= !(rt
->colormask
& PIPE_MASK_A
);
1213 blend_entry
+= GENX(BLEND_STATE_ENTRY_length
);
1216 iris_pack_command(GENX(3DSTATE_PS_BLEND
), cso
->ps_blend
, pb
) {
1217 /* pb.HasWriteableRT is filled in at draw time.
1218 * pb.AlphaTestEnable is filled in at draw time.
1220 * pb.ColorBufferBlendEnable is filled in at draw time so we can avoid
1221 * setting it when dual color blending without an appropriate shader.
1224 pb
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
1225 pb
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
1227 pb
.SourceBlendFactor
=
1228 fix_blendfactor(state
->rt
[0].rgb_src_factor
, state
->alpha_to_one
);
1229 pb
.SourceAlphaBlendFactor
=
1230 fix_blendfactor(state
->rt
[0].alpha_src_factor
, state
->alpha_to_one
);
1231 pb
.DestinationBlendFactor
=
1232 fix_blendfactor(state
->rt
[0].rgb_dst_factor
, state
->alpha_to_one
);
1233 pb
.DestinationAlphaBlendFactor
=
1234 fix_blendfactor(state
->rt
[0].alpha_dst_factor
, state
->alpha_to_one
);
1237 iris_pack_state(GENX(BLEND_STATE
), cso
->blend_state
, bs
) {
1238 bs
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
1239 bs
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
1240 bs
.AlphaToOneEnable
= state
->alpha_to_one
;
1241 bs
.AlphaToCoverageDitherEnable
= state
->alpha_to_coverage
;
1242 bs
.ColorDitherEnable
= state
->dither
;
1243 /* bl.AlphaTestEnable and bs.AlphaTestFunction are filled in later. */
1246 cso
->dual_color_blending
= util_blend_state_is_dual(state
, 0);
1252 * The pipe->bind_blend_state() driver hook.
1254 * Bind a blending CSO and flag related dirty bits.
1257 iris_bind_blend_state(struct pipe_context
*ctx
, void *state
)
1259 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1260 struct iris_blend_state
*cso
= state
;
1262 ice
->state
.cso_blend
= cso
;
1263 ice
->state
.blend_enables
= cso
? cso
->blend_enables
: 0;
1265 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
;
1266 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1267 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1268 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_BLEND
];
1271 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
1275 * Return true if the FS writes to any color outputs which are not disabled
1276 * via color masking.
1279 has_writeable_rt(const struct iris_blend_state
*cso_blend
,
1280 const struct shader_info
*fs_info
)
1285 unsigned rt_outputs
= fs_info
->outputs_written
>> FRAG_RESULT_DATA0
;
1287 if (fs_info
->outputs_written
& BITFIELD64_BIT(FRAG_RESULT_COLOR
))
1288 rt_outputs
= (1 << BRW_MAX_DRAW_BUFFERS
) - 1;
1290 return cso_blend
->color_write_enables
& rt_outputs
;
1294 * Gallium CSO for depth, stencil, and alpha testing state.
1296 struct iris_depth_stencil_alpha_state
{
1297 /** Partial 3DSTATE_WM_DEPTH_STENCIL. */
1298 uint32_t wmds
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
1301 uint32_t depth_bounds
[GENX(3DSTATE_DEPTH_BOUNDS_length
)];
1304 /** Outbound to BLEND_STATE, 3DSTATE_PS_BLEND, COLOR_CALC_STATE. */
1305 struct pipe_alpha_state alpha
;
1307 /** Outbound to resolve and cache set tracking. */
1308 bool depth_writes_enabled
;
1309 bool stencil_writes_enabled
;
1311 /** Outbound to Gen8-9 PMA stall equations */
1312 bool depth_test_enabled
;
1316 * The pipe->create_depth_stencil_alpha_state() driver hook.
1318 * We encode most of 3DSTATE_WM_DEPTH_STENCIL, and just save off the alpha
1319 * testing state since we need pieces of it in a variety of places.
1322 iris_create_zsa_state(struct pipe_context
*ctx
,
1323 const struct pipe_depth_stencil_alpha_state
*state
)
1325 struct iris_depth_stencil_alpha_state
*cso
=
1326 malloc(sizeof(struct iris_depth_stencil_alpha_state
));
1328 bool two_sided_stencil
= state
->stencil
[1].enabled
;
1330 cso
->alpha
= state
->alpha
;
1331 cso
->depth_writes_enabled
= state
->depth
.writemask
;
1332 cso
->depth_test_enabled
= state
->depth
.enabled
;
1333 cso
->stencil_writes_enabled
=
1334 state
->stencil
[0].writemask
!= 0 ||
1335 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1337 /* gallium frontends need to optimize away EQUAL writes for us. */
1338 assert(!(state
->depth
.func
== PIPE_FUNC_EQUAL
&& state
->depth
.writemask
));
1340 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), cso
->wmds
, wmds
) {
1341 wmds
.StencilFailOp
= state
->stencil
[0].fail_op
;
1342 wmds
.StencilPassDepthFailOp
= state
->stencil
[0].zfail_op
;
1343 wmds
.StencilPassDepthPassOp
= state
->stencil
[0].zpass_op
;
1344 wmds
.StencilTestFunction
=
1345 translate_compare_func(state
->stencil
[0].func
);
1346 wmds
.BackfaceStencilFailOp
= state
->stencil
[1].fail_op
;
1347 wmds
.BackfaceStencilPassDepthFailOp
= state
->stencil
[1].zfail_op
;
1348 wmds
.BackfaceStencilPassDepthPassOp
= state
->stencil
[1].zpass_op
;
1349 wmds
.BackfaceStencilTestFunction
=
1350 translate_compare_func(state
->stencil
[1].func
);
1351 wmds
.DepthTestFunction
= translate_compare_func(state
->depth
.func
);
1352 wmds
.DoubleSidedStencilEnable
= two_sided_stencil
;
1353 wmds
.StencilTestEnable
= state
->stencil
[0].enabled
;
1354 wmds
.StencilBufferWriteEnable
=
1355 state
->stencil
[0].writemask
!= 0 ||
1356 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1357 wmds
.DepthTestEnable
= state
->depth
.enabled
;
1358 wmds
.DepthBufferWriteEnable
= state
->depth
.writemask
;
1359 wmds
.StencilTestMask
= state
->stencil
[0].valuemask
;
1360 wmds
.StencilWriteMask
= state
->stencil
[0].writemask
;
1361 wmds
.BackfaceStencilTestMask
= state
->stencil
[1].valuemask
;
1362 wmds
.BackfaceStencilWriteMask
= state
->stencil
[1].writemask
;
1363 /* wmds.[Backface]StencilReferenceValue are merged later */
1367 iris_pack_command(GENX(3DSTATE_DEPTH_BOUNDS
), cso
->depth_bounds
, depth_bounds
) {
1368 depth_bounds
.DepthBoundsTestValueModifyDisable
= false;
1369 depth_bounds
.DepthBoundsTestEnableModifyDisable
= false;
1370 depth_bounds
.DepthBoundsTestEnable
= state
->depth
.bounds_test
;
1371 depth_bounds
.DepthBoundsTestMinValue
= state
->depth
.bounds_min
;
1372 depth_bounds
.DepthBoundsTestMaxValue
= state
->depth
.bounds_max
;
1380 * The pipe->bind_depth_stencil_alpha_state() driver hook.
1382 * Bind a depth/stencil/alpha CSO and flag related dirty bits.
1385 iris_bind_zsa_state(struct pipe_context
*ctx
, void *state
)
1387 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1388 struct iris_depth_stencil_alpha_state
*old_cso
= ice
->state
.cso_zsa
;
1389 struct iris_depth_stencil_alpha_state
*new_cso
= state
;
1392 if (cso_changed(alpha
.ref_value
))
1393 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
1395 if (cso_changed(alpha
.enabled
))
1396 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
| IRIS_DIRTY_BLEND_STATE
;
1398 if (cso_changed(alpha
.func
))
1399 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1401 if (cso_changed(depth_writes_enabled
))
1402 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1404 ice
->state
.depth_writes_enabled
= new_cso
->depth_writes_enabled
;
1405 ice
->state
.stencil_writes_enabled
= new_cso
->stencil_writes_enabled
;
1408 if (cso_changed(depth_bounds
))
1409 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BOUNDS
;
1413 ice
->state
.cso_zsa
= new_cso
;
1414 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1415 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
1416 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_DEPTH_STENCIL_ALPHA
];
1419 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
1424 want_pma_fix(struct iris_context
*ice
)
1426 UNUSED
struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
1427 UNUSED
const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1428 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
1429 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
1430 const struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
1431 const struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
1432 const struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
1434 /* In very specific combinations of state, we can instruct Gen8-9 hardware
1435 * to avoid stalling at the pixel mask array. The state equations are
1436 * documented in these places:
1438 * - Gen8 Depth PMA Fix: CACHE_MODE_1::NP_PMA_FIX_ENABLE
1439 * - Gen9 Stencil PMA Fix: CACHE_MODE_0::STC PMA Optimization Enable
1441 * Both equations share some common elements:
1444 * !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
1445 * 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
1446 * 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
1447 * 3DSTATE_WM_HZ_OP::StencilBufferClear) &&
1450 * 3DSTATE_WM::ForceKillPix != ForceOff &&
1451 * (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
1452 * 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
1453 * 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
1454 * 3DSTATE_PS_BLEND::AlphaTestEnable ||
1455 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable)
1457 * (Technically the stencil PMA treats ForceKillPix differently,
1458 * but I think this is a documentation oversight, and we don't
1459 * ever use it in this way, so it doesn't matter).
1462 * 3DSTATE_WM::ForceThreadDispatch != 1 &&
1463 * 3DSTATE_RASTER::ForceSampleCount == NUMRASTSAMPLES_0 &&
1464 * 3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL &&
1465 * 3DSTATE_DEPTH_BUFFER::HIZ Enable &&
1466 * 3DSTATE_WM::EDSC_Mode != EDSC_PREPS &&
1467 * 3DSTATE_PS_EXTRA::PixelShaderValid &&
1470 * These are always true:
1472 * 3DSTATE_RASTER::ForceSampleCount == NUMRASTSAMPLES_0
1473 * 3DSTATE_PS_EXTRA::PixelShaderValid
1475 * Also, we never use the normal drawing path for HiZ ops; these are true:
1477 * !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
1478 * 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
1479 * 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
1480 * 3DSTATE_WM_HZ_OP::StencilBufferClear)
1482 * This happens sometimes:
1484 * 3DSTATE_WM::ForceThreadDispatch != 1
1486 * However, we choose to ignore it as it either agrees with the signal
1487 * (dispatch was already enabled, so nothing out of the ordinary), or
1488 * there are no framebuffer attachments (so no depth or HiZ anyway,
1489 * meaning the PMA signal will already be disabled).
1495 struct iris_resource
*zres
, *sres
;
1496 iris_get_depth_stencil_resources(cso_fb
->zsbuf
->texture
, &zres
, &sres
);
1498 /* 3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL &&
1499 * 3DSTATE_DEPTH_BUFFER::HIZ Enable &&
1501 if (!zres
|| !iris_resource_level_has_hiz(zres
, cso_fb
->zsbuf
->u
.tex
.level
))
1504 /* 3DSTATE_WM::EDSC_Mode != EDSC_PREPS */
1505 if (wm_prog_data
->early_fragment_tests
)
1508 /* 3DSTATE_WM::ForceKillPix != ForceOff &&
1509 * (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
1510 * 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
1511 * 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
1512 * 3DSTATE_PS_BLEND::AlphaTestEnable ||
1513 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable)
1515 bool killpixels
= wm_prog_data
->uses_kill
|| wm_prog_data
->uses_omask
||
1516 cso_blend
->alpha_to_coverage
|| cso_zsa
->alpha
.enabled
;
1518 /* The Gen8 depth PMA equation becomes:
1521 * 3DSTATE_WM_DEPTH_STENCIL::DepthWriteEnable &&
1522 * 3DSTATE_DEPTH_BUFFER::DEPTH_WRITE_ENABLE
1525 * 3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
1526 * 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE &&
1527 * 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE
1531 * 3DSTATE_WM_DEPTH_STENCIL::DepthTestEnable &&
1532 * ((killpixels && (depth_writes || stencil_writes)) ||
1533 * 3DSTATE_PS_EXTRA::PixelShaderComputedDepthMode != PSCDEPTH_OFF)
1536 if (!cso_zsa
->depth_test_enabled
)
1539 return wm_prog_data
->computed_depth_mode
!= PSCDEPTH_OFF
||
1540 (killpixels
&& (cso_zsa
->depth_writes_enabled
||
1541 (sres
&& cso_zsa
->stencil_writes_enabled
)));
1546 genX(update_pma_fix
)(struct iris_context
*ice
,
1547 struct iris_batch
*batch
,
1551 struct iris_genx_state
*genx
= ice
->state
.genx
;
1553 if (genx
->pma_fix_enabled
== enable
)
1556 genx
->pma_fix_enabled
= enable
;
1558 /* According to the Broadwell PIPE_CONTROL documentation, software should
1559 * emit a PIPE_CONTROL with the CS Stall and Depth Cache Flush bits set
1560 * prior to the LRI. If stencil buffer writes are enabled, then a Render * Cache Flush is also necessary.
1562 * The Gen9 docs say to use a depth stall rather than a command streamer
1563 * stall. However, the hardware seems to violently disagree. A full
1564 * command streamer stall seems to be needed in both cases.
1566 iris_emit_pipe_control_flush(batch
, "PMA fix change (1/2)",
1567 PIPE_CONTROL_CS_STALL
|
1568 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1569 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
1572 iris_pack_state(GENX(CACHE_MODE_1
), ®_val
, reg
) {
1573 reg
.NPPMAFixEnable
= enable
;
1574 reg
.NPEarlyZFailsDisable
= enable
;
1575 reg
.NPPMAFixEnableMask
= true;
1576 reg
.NPEarlyZFailsDisableMask
= true;
1578 iris_emit_lri(batch
, CACHE_MODE_1
, reg_val
);
1580 /* After the LRI, a PIPE_CONTROL with both the Depth Stall and Depth Cache
1581 * Flush bits is often necessary. We do it regardless because it's easier.
1582 * The render cache flush is also necessary if stencil writes are enabled.
1584 * Again, the Gen9 docs give a different set of flushes but the Broadwell
1585 * flushes seem to work just as well.
1587 iris_emit_pipe_control_flush(batch
, "PMA fix change (1/2)",
1588 PIPE_CONTROL_DEPTH_STALL
|
1589 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1590 PIPE_CONTROL_RENDER_TARGET_FLUSH
);
1595 * Gallium CSO for rasterizer state.
1597 struct iris_rasterizer_state
{
1598 uint32_t sf
[GENX(3DSTATE_SF_length
)];
1599 uint32_t clip
[GENX(3DSTATE_CLIP_length
)];
1600 uint32_t raster
[GENX(3DSTATE_RASTER_length
)];
1601 uint32_t wm
[GENX(3DSTATE_WM_length
)];
1602 uint32_t line_stipple
[GENX(3DSTATE_LINE_STIPPLE_length
)];
1604 uint8_t num_clip_plane_consts
;
1605 bool clip_halfz
; /* for CC_VIEWPORT */
1606 bool depth_clip_near
; /* for CC_VIEWPORT */
1607 bool depth_clip_far
; /* for CC_VIEWPORT */
1608 bool flatshade
; /* for shader state */
1609 bool flatshade_first
; /* for stream output */
1610 bool clamp_fragment_color
; /* for shader state */
1611 bool light_twoside
; /* for shader state */
1612 bool rasterizer_discard
; /* for 3DSTATE_STREAMOUT and 3DSTATE_CLIP */
1613 bool half_pixel_center
; /* for 3DSTATE_MULTISAMPLE */
1614 bool line_stipple_enable
;
1615 bool poly_stipple_enable
;
1617 bool force_persample_interp
;
1618 bool conservative_rasterization
;
1619 bool fill_mode_point_or_line
;
1620 enum pipe_sprite_coord_mode sprite_coord_mode
; /* PIPE_SPRITE_* */
1621 uint16_t sprite_coord_enable
;
1625 get_line_width(const struct pipe_rasterizer_state
*state
)
1627 float line_width
= state
->line_width
;
1629 /* From the OpenGL 4.4 spec:
1631 * "The actual width of non-antialiased lines is determined by rounding
1632 * the supplied width to the nearest integer, then clamping it to the
1633 * implementation-dependent maximum non-antialiased line width."
1635 if (!state
->multisample
&& !state
->line_smooth
)
1636 line_width
= roundf(state
->line_width
);
1638 if (!state
->multisample
&& state
->line_smooth
&& line_width
< 1.5f
) {
1639 /* For 1 pixel line thickness or less, the general anti-aliasing
1640 * algorithm gives up, and a garbage line is generated. Setting a
1641 * Line Width of 0.0 specifies the rasterization of the "thinnest"
1642 * (one-pixel-wide), non-antialiased lines.
1644 * Lines rendered with zero Line Width are rasterized using the
1645 * "Grid Intersection Quantization" rules as specified by the
1646 * "Zero-Width (Cosmetic) Line Rasterization" section of the docs.
1655 * The pipe->create_rasterizer_state() driver hook.
1658 iris_create_rasterizer_state(struct pipe_context
*ctx
,
1659 const struct pipe_rasterizer_state
*state
)
1661 struct iris_rasterizer_state
*cso
=
1662 malloc(sizeof(struct iris_rasterizer_state
));
1664 cso
->multisample
= state
->multisample
;
1665 cso
->force_persample_interp
= state
->force_persample_interp
;
1666 cso
->clip_halfz
= state
->clip_halfz
;
1667 cso
->depth_clip_near
= state
->depth_clip_near
;
1668 cso
->depth_clip_far
= state
->depth_clip_far
;
1669 cso
->flatshade
= state
->flatshade
;
1670 cso
->flatshade_first
= state
->flatshade_first
;
1671 cso
->clamp_fragment_color
= state
->clamp_fragment_color
;
1672 cso
->light_twoside
= state
->light_twoside
;
1673 cso
->rasterizer_discard
= state
->rasterizer_discard
;
1674 cso
->half_pixel_center
= state
->half_pixel_center
;
1675 cso
->sprite_coord_mode
= state
->sprite_coord_mode
;
1676 cso
->sprite_coord_enable
= state
->sprite_coord_enable
;
1677 cso
->line_stipple_enable
= state
->line_stipple_enable
;
1678 cso
->poly_stipple_enable
= state
->poly_stipple_enable
;
1679 cso
->conservative_rasterization
=
1680 state
->conservative_raster_mode
== PIPE_CONSERVATIVE_RASTER_POST_SNAP
;
1682 cso
->fill_mode_point_or_line
=
1683 state
->fill_front
== PIPE_POLYGON_MODE_LINE
||
1684 state
->fill_front
== PIPE_POLYGON_MODE_POINT
||
1685 state
->fill_back
== PIPE_POLYGON_MODE_LINE
||
1686 state
->fill_back
== PIPE_POLYGON_MODE_POINT
;
1688 if (state
->clip_plane_enable
!= 0)
1689 cso
->num_clip_plane_consts
= util_logbase2(state
->clip_plane_enable
) + 1;
1691 cso
->num_clip_plane_consts
= 0;
1693 float line_width
= get_line_width(state
);
1695 iris_pack_command(GENX(3DSTATE_SF
), cso
->sf
, sf
) {
1696 sf
.StatisticsEnable
= true;
1697 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
1698 sf
.LineEndCapAntialiasingRegionWidth
=
1699 state
->line_smooth
? _10pixels
: _05pixels
;
1700 sf
.LastPixelEnable
= state
->line_last_pixel
;
1701 sf
.LineWidth
= line_width
;
1702 sf
.SmoothPointEnable
= (state
->point_smooth
|| state
->multisample
) &&
1703 !state
->point_quad_rasterization
;
1704 sf
.PointWidthSource
= state
->point_size_per_vertex
? Vertex
: State
;
1705 sf
.PointWidth
= state
->point_size
;
1707 if (state
->flatshade_first
) {
1708 sf
.TriangleFanProvokingVertexSelect
= 1;
1710 sf
.TriangleStripListProvokingVertexSelect
= 2;
1711 sf
.TriangleFanProvokingVertexSelect
= 2;
1712 sf
.LineStripListProvokingVertexSelect
= 1;
1716 iris_pack_command(GENX(3DSTATE_RASTER
), cso
->raster
, rr
) {
1717 rr
.FrontWinding
= state
->front_ccw
? CounterClockwise
: Clockwise
;
1718 rr
.CullMode
= translate_cull_mode(state
->cull_face
);
1719 rr
.FrontFaceFillMode
= translate_fill_mode(state
->fill_front
);
1720 rr
.BackFaceFillMode
= translate_fill_mode(state
->fill_back
);
1721 rr
.DXMultisampleRasterizationEnable
= state
->multisample
;
1722 rr
.GlobalDepthOffsetEnableSolid
= state
->offset_tri
;
1723 rr
.GlobalDepthOffsetEnableWireframe
= state
->offset_line
;
1724 rr
.GlobalDepthOffsetEnablePoint
= state
->offset_point
;
1725 rr
.GlobalDepthOffsetConstant
= state
->offset_units
* 2;
1726 rr
.GlobalDepthOffsetScale
= state
->offset_scale
;
1727 rr
.GlobalDepthOffsetClamp
= state
->offset_clamp
;
1728 rr
.SmoothPointEnable
= state
->point_smooth
;
1729 rr
.AntialiasingEnable
= state
->line_smooth
;
1730 rr
.ScissorRectangleEnable
= state
->scissor
;
1732 rr
.ViewportZNearClipTestEnable
= state
->depth_clip_near
;
1733 rr
.ViewportZFarClipTestEnable
= state
->depth_clip_far
;
1734 rr
.ConservativeRasterizationEnable
=
1735 cso
->conservative_rasterization
;
1737 rr
.ViewportZClipTestEnable
= (state
->depth_clip_near
|| state
->depth_clip_far
);
1741 iris_pack_command(GENX(3DSTATE_CLIP
), cso
->clip
, cl
) {
1742 /* cl.NonPerspectiveBarycentricEnable is filled in at draw time from
1743 * the FS program; cl.ForceZeroRTAIndexEnable is filled in from the FB.
1745 cl
.EarlyCullEnable
= true;
1746 cl
.UserClipDistanceClipTestEnableBitmask
= state
->clip_plane_enable
;
1747 cl
.ForceUserClipDistanceClipTestEnableBitmask
= true;
1748 cl
.APIMode
= state
->clip_halfz
? APIMODE_D3D
: APIMODE_OGL
;
1749 cl
.GuardbandClipTestEnable
= true;
1750 cl
.ClipEnable
= true;
1751 cl
.MinimumPointWidth
= 0.125;
1752 cl
.MaximumPointWidth
= 255.875;
1754 if (state
->flatshade_first
) {
1755 cl
.TriangleFanProvokingVertexSelect
= 1;
1757 cl
.TriangleStripListProvokingVertexSelect
= 2;
1758 cl
.TriangleFanProvokingVertexSelect
= 2;
1759 cl
.LineStripListProvokingVertexSelect
= 1;
1763 iris_pack_command(GENX(3DSTATE_WM
), cso
->wm
, wm
) {
1764 /* wm.BarycentricInterpolationMode and wm.EarlyDepthStencilControl are
1765 * filled in at draw time from the FS program.
1767 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1768 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1769 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1770 wm
.LineStippleEnable
= state
->line_stipple_enable
;
1771 wm
.PolygonStippleEnable
= state
->poly_stipple_enable
;
1774 /* Remap from 0..255 back to 1..256 */
1775 const unsigned line_stipple_factor
= state
->line_stipple_factor
+ 1;
1777 iris_pack_command(GENX(3DSTATE_LINE_STIPPLE
), cso
->line_stipple
, line
) {
1778 if (state
->line_stipple_enable
) {
1779 line
.LineStipplePattern
= state
->line_stipple_pattern
;
1780 line
.LineStippleInverseRepeatCount
= 1.0f
/ line_stipple_factor
;
1781 line
.LineStippleRepeatCount
= line_stipple_factor
;
1789 * The pipe->bind_rasterizer_state() driver hook.
1791 * Bind a rasterizer CSO and flag related dirty bits.
1794 iris_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
1796 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1797 struct iris_rasterizer_state
*old_cso
= ice
->state
.cso_rast
;
1798 struct iris_rasterizer_state
*new_cso
= state
;
1801 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
1802 if (cso_changed_memcmp(line_stipple
))
1803 ice
->state
.dirty
|= IRIS_DIRTY_LINE_STIPPLE
;
1805 if (cso_changed(half_pixel_center
))
1806 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
1808 if (cso_changed(line_stipple_enable
) || cso_changed(poly_stipple_enable
))
1809 ice
->state
.dirty
|= IRIS_DIRTY_WM
;
1811 if (cso_changed(rasterizer_discard
))
1812 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
| IRIS_DIRTY_CLIP
;
1814 if (cso_changed(flatshade_first
))
1815 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
1817 if (cso_changed(depth_clip_near
) || cso_changed(depth_clip_far
) ||
1818 cso_changed(clip_halfz
))
1819 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1821 if (cso_changed(sprite_coord_enable
) ||
1822 cso_changed(sprite_coord_mode
) ||
1823 cso_changed(light_twoside
))
1824 ice
->state
.dirty
|= IRIS_DIRTY_SBE
;
1826 if (cso_changed(conservative_rasterization
))
1827 ice
->state
.dirty
|= IRIS_DIRTY_FS
;
1830 ice
->state
.cso_rast
= new_cso
;
1831 ice
->state
.dirty
|= IRIS_DIRTY_RASTER
;
1832 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
1833 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_RASTERIZER
];
1837 * Return true if the given wrap mode requires the border color to exist.
1839 * (We can skip uploading it if the sampler isn't going to use it.)
1842 wrap_mode_needs_border_color(unsigned wrap_mode
)
1844 return wrap_mode
== TCM_CLAMP_BORDER
|| wrap_mode
== TCM_HALF_BORDER
;
1848 * Gallium CSO for sampler state.
1850 struct iris_sampler_state
{
1851 union pipe_color_union border_color
;
1852 bool needs_border_color
;
1854 uint32_t sampler_state
[GENX(SAMPLER_STATE_length
)];
1858 * The pipe->create_sampler_state() driver hook.
1860 * We fill out SAMPLER_STATE (except for the border color pointer), and
1861 * store that on the CPU. It doesn't make sense to upload it to a GPU
1862 * buffer object yet, because 3DSTATE_SAMPLER_STATE_POINTERS requires
1863 * all bound sampler states to be in contiguous memor.
1866 iris_create_sampler_state(struct pipe_context
*ctx
,
1867 const struct pipe_sampler_state
*state
)
1869 struct iris_sampler_state
*cso
= CALLOC_STRUCT(iris_sampler_state
);
1874 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST
== MAPFILTER_NEAREST
);
1875 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR
== MAPFILTER_LINEAR
);
1877 unsigned wrap_s
= translate_wrap(state
->wrap_s
);
1878 unsigned wrap_t
= translate_wrap(state
->wrap_t
);
1879 unsigned wrap_r
= translate_wrap(state
->wrap_r
);
1881 memcpy(&cso
->border_color
, &state
->border_color
, sizeof(cso
->border_color
));
1883 cso
->needs_border_color
= wrap_mode_needs_border_color(wrap_s
) ||
1884 wrap_mode_needs_border_color(wrap_t
) ||
1885 wrap_mode_needs_border_color(wrap_r
);
1887 float min_lod
= state
->min_lod
;
1888 unsigned mag_img_filter
= state
->mag_img_filter
;
1890 // XXX: explain this code ported from ilo...I don't get it at all...
1891 if (state
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
&&
1892 state
->min_lod
> 0.0f
) {
1894 mag_img_filter
= state
->min_img_filter
;
1897 iris_pack_state(GENX(SAMPLER_STATE
), cso
->sampler_state
, samp
) {
1898 samp
.TCXAddressControlMode
= wrap_s
;
1899 samp
.TCYAddressControlMode
= wrap_t
;
1900 samp
.TCZAddressControlMode
= wrap_r
;
1901 samp
.CubeSurfaceControlMode
= state
->seamless_cube_map
;
1902 samp
.NonnormalizedCoordinateEnable
= !state
->normalized_coords
;
1903 samp
.MinModeFilter
= state
->min_img_filter
;
1904 samp
.MagModeFilter
= mag_img_filter
;
1905 samp
.MipModeFilter
= translate_mip_filter(state
->min_mip_filter
);
1906 samp
.MaximumAnisotropy
= RATIO21
;
1908 if (state
->max_anisotropy
>= 2) {
1909 if (state
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
1910 samp
.MinModeFilter
= MAPFILTER_ANISOTROPIC
;
1911 samp
.AnisotropicAlgorithm
= EWAApproximation
;
1914 if (state
->mag_img_filter
== PIPE_TEX_FILTER_LINEAR
)
1915 samp
.MagModeFilter
= MAPFILTER_ANISOTROPIC
;
1917 samp
.MaximumAnisotropy
=
1918 MIN2((state
->max_anisotropy
- 2) / 2, RATIO161
);
1921 /* Set address rounding bits if not using nearest filtering. */
1922 if (state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1923 samp
.UAddressMinFilterRoundingEnable
= true;
1924 samp
.VAddressMinFilterRoundingEnable
= true;
1925 samp
.RAddressMinFilterRoundingEnable
= true;
1928 if (state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1929 samp
.UAddressMagFilterRoundingEnable
= true;
1930 samp
.VAddressMagFilterRoundingEnable
= true;
1931 samp
.RAddressMagFilterRoundingEnable
= true;
1934 if (state
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
1935 samp
.ShadowFunction
= translate_shadow_func(state
->compare_func
);
1937 const float hw_max_lod
= GEN_GEN
>= 7 ? 14 : 13;
1939 samp
.LODPreClampMode
= CLAMP_MODE_OGL
;
1940 samp
.MinLOD
= CLAMP(min_lod
, 0, hw_max_lod
);
1941 samp
.MaxLOD
= CLAMP(state
->max_lod
, 0, hw_max_lod
);
1942 samp
.TextureLODBias
= CLAMP(state
->lod_bias
, -16, 15);
1944 /* .BorderColorPointer is filled in by iris_bind_sampler_states. */
1951 * The pipe->bind_sampler_states() driver hook.
1954 iris_bind_sampler_states(struct pipe_context
*ctx
,
1955 enum pipe_shader_type p_stage
,
1956 unsigned start
, unsigned count
,
1959 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1960 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1961 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1963 assert(start
+ count
<= IRIS_MAX_TEXTURE_SAMPLERS
);
1967 for (int i
= 0; i
< count
; i
++) {
1968 if (shs
->samplers
[start
+ i
] != states
[i
]) {
1969 shs
->samplers
[start
+ i
] = states
[i
];
1975 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
;
1979 * Upload the sampler states into a contiguous area of GPU memory, for
1980 * for 3DSTATE_SAMPLER_STATE_POINTERS_*.
1982 * Also fill out the border color state pointers.
1985 iris_upload_sampler_states(struct iris_context
*ice
, gl_shader_stage stage
)
1987 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1988 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
1990 /* We assume gallium frontends will call pipe->bind_sampler_states()
1991 * if the program's number of textures changes.
1993 unsigned count
= info
? util_last_bit(info
->textures_used
) : 0;
1998 /* Assemble the SAMPLER_STATEs into a contiguous table that lives
1999 * in the dynamic state memory zone, so we can point to it via the
2000 * 3DSTATE_SAMPLER_STATE_POINTERS_* commands.
2002 unsigned size
= count
* 4 * GENX(SAMPLER_STATE_length
);
2004 upload_state(ice
->state
.dynamic_uploader
, &shs
->sampler_table
, size
, 32);
2008 struct pipe_resource
*res
= shs
->sampler_table
.res
;
2009 struct iris_bo
*bo
= iris_resource_bo(res
);
2011 iris_record_state_size(ice
->state
.sizes
,
2012 bo
->gtt_offset
+ shs
->sampler_table
.offset
, size
);
2014 shs
->sampler_table
.offset
+= iris_bo_offset_from_base_address(bo
);
2016 /* Make sure all land in the same BO */
2017 iris_border_color_pool_reserve(ice
, IRIS_MAX_TEXTURE_SAMPLERS
);
2019 ice
->state
.need_border_colors
&= ~(1 << stage
);
2021 for (int i
= 0; i
< count
; i
++) {
2022 struct iris_sampler_state
*state
= shs
->samplers
[i
];
2023 struct iris_sampler_view
*tex
= shs
->textures
[i
];
2026 memset(map
, 0, 4 * GENX(SAMPLER_STATE_length
));
2027 } else if (!state
->needs_border_color
) {
2028 memcpy(map
, state
->sampler_state
, 4 * GENX(SAMPLER_STATE_length
));
2030 ice
->state
.need_border_colors
|= 1 << stage
;
2032 /* We may need to swizzle the border color for format faking.
2033 * A/LA formats are faked as R/RG with 000R or R00G swizzles.
2034 * This means we need to move the border color's A channel into
2035 * the R or G channels so that those read swizzles will move it
2038 union pipe_color_union
*color
= &state
->border_color
;
2039 union pipe_color_union tmp
;
2041 enum pipe_format internal_format
= tex
->res
->internal_format
;
2043 if (util_format_is_alpha(internal_format
)) {
2044 unsigned char swz
[4] = {
2045 PIPE_SWIZZLE_W
, PIPE_SWIZZLE_0
,
2046 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
2048 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
2050 } else if (util_format_is_luminance_alpha(internal_format
) &&
2051 internal_format
!= PIPE_FORMAT_L8A8_SRGB
) {
2052 unsigned char swz
[4] = {
2053 PIPE_SWIZZLE_X
, PIPE_SWIZZLE_W
,
2054 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
2056 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
2061 /* Stream out the border color and merge the pointer. */
2062 uint32_t offset
= iris_upload_border_color(ice
, color
);
2064 uint32_t dynamic
[GENX(SAMPLER_STATE_length
)];
2065 iris_pack_state(GENX(SAMPLER_STATE
), dynamic
, dyns
) {
2066 dyns
.BorderColorPointer
= offset
;
2069 for (uint32_t j
= 0; j
< GENX(SAMPLER_STATE_length
); j
++)
2070 map
[j
] = state
->sampler_state
[j
] | dynamic
[j
];
2073 map
+= GENX(SAMPLER_STATE_length
);
2077 static enum isl_channel_select
2078 fmt_swizzle(const struct iris_format_info
*fmt
, enum pipe_swizzle swz
)
2081 case PIPE_SWIZZLE_X
: return fmt
->swizzle
.r
;
2082 case PIPE_SWIZZLE_Y
: return fmt
->swizzle
.g
;
2083 case PIPE_SWIZZLE_Z
: return fmt
->swizzle
.b
;
2084 case PIPE_SWIZZLE_W
: return fmt
->swizzle
.a
;
2085 case PIPE_SWIZZLE_1
: return SCS_ONE
;
2086 case PIPE_SWIZZLE_0
: return SCS_ZERO
;
2087 default: unreachable("invalid swizzle");
2092 fill_buffer_surface_state(struct isl_device
*isl_dev
,
2093 struct iris_resource
*res
,
2095 enum isl_format format
,
2096 struct isl_swizzle swizzle
,
2100 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
2101 const unsigned cpp
= format
== ISL_FORMAT_RAW
? 1 : fmtl
->bpb
/ 8;
2103 /* The ARB_texture_buffer_specification says:
2105 * "The number of texels in the buffer texture's texel array is given by
2107 * floor(<buffer_size> / (<components> * sizeof(<base_type>)),
2109 * where <buffer_size> is the size of the buffer object, in basic
2110 * machine units and <components> and <base_type> are the element count
2111 * and base data type for elements, as specified in Table X.1. The
2112 * number of texels in the texel array is then clamped to the
2113 * implementation-dependent limit MAX_TEXTURE_BUFFER_SIZE_ARB."
2115 * We need to clamp the size in bytes to MAX_TEXTURE_BUFFER_SIZE * stride,
2116 * so that when ISL divides by stride to obtain the number of texels, that
2117 * texel count is clamped to MAX_TEXTURE_BUFFER_SIZE.
2119 unsigned final_size
=
2120 MIN3(size
, res
->bo
->size
- res
->offset
- offset
,
2121 IRIS_MAX_TEXTURE_BUFFER_SIZE
* cpp
);
2123 isl_buffer_fill_state(isl_dev
, map
,
2124 .address
= res
->bo
->gtt_offset
+ res
->offset
+ offset
,
2125 .size_B
= final_size
,
2129 .mocs
= iris_mocs(res
->bo
, isl_dev
));
2132 #define SURFACE_STATE_ALIGNMENT 64
2135 * Allocate several contiguous SURFACE_STATE structures, one for each
2136 * supported auxiliary surface mode. This only allocates the CPU-side
2137 * copy, they will need to be uploaded later after they're filled in.
2140 alloc_surface_states(struct iris_surface_state
*surf_state
,
2141 unsigned aux_usages
)
2143 const unsigned surf_size
= 4 * GENX(RENDER_SURFACE_STATE_length
);
2145 /* If this changes, update this to explicitly align pointers */
2146 STATIC_ASSERT(surf_size
== SURFACE_STATE_ALIGNMENT
);
2148 assert(aux_usages
!= 0);
2150 /* In case we're re-allocating them... */
2151 free(surf_state
->cpu
);
2153 surf_state
->num_states
= util_bitcount(aux_usages
);
2154 surf_state
->cpu
= calloc(surf_state
->num_states
, surf_size
);
2155 surf_state
->ref
.offset
= 0;
2156 pipe_resource_reference(&surf_state
->ref
.res
, NULL
);
2158 assert(surf_state
->cpu
);
2162 * Upload the CPU side SURFACE_STATEs into a GPU buffer.
2165 upload_surface_states(struct u_upload_mgr
*mgr
,
2166 struct iris_surface_state
*surf_state
)
2168 const unsigned surf_size
= 4 * GENX(RENDER_SURFACE_STATE_length
);
2169 const unsigned bytes
= surf_state
->num_states
* surf_size
;
2172 upload_state(mgr
, &surf_state
->ref
, bytes
, SURFACE_STATE_ALIGNMENT
);
2174 surf_state
->ref
.offset
+=
2175 iris_bo_offset_from_base_address(iris_resource_bo(surf_state
->ref
.res
));
2178 memcpy(map
, surf_state
->cpu
, bytes
);
2182 * Update resource addresses in a set of SURFACE_STATE descriptors,
2183 * and re-upload them if necessary.
2186 update_surface_state_addrs(struct u_upload_mgr
*mgr
,
2187 struct iris_surface_state
*surf_state
,
2190 if (surf_state
->bo_address
== bo
->gtt_offset
)
2193 STATIC_ASSERT(GENX(RENDER_SURFACE_STATE_SurfaceBaseAddress_start
) % 64 == 0);
2194 STATIC_ASSERT(GENX(RENDER_SURFACE_STATE_SurfaceBaseAddress_bits
) == 64);
2196 uint64_t *ss_addr
= (uint64_t *) &surf_state
->cpu
[GENX(RENDER_SURFACE_STATE_SurfaceBaseAddress_start
) / 32];
2198 /* First, update the CPU copies. We assume no other fields exist in
2199 * the QWord containing Surface Base Address.
2201 for (unsigned i
= 0; i
< surf_state
->num_states
; i
++) {
2202 *ss_addr
= *ss_addr
- surf_state
->bo_address
+ bo
->gtt_offset
;
2203 ss_addr
= ((void *) ss_addr
) + SURFACE_STATE_ALIGNMENT
;
2206 /* Next, upload the updated copies to a GPU buffer. */
2207 upload_surface_states(mgr
, surf_state
);
2209 surf_state
->bo_address
= bo
->gtt_offset
;
2216 * Return an ISL surface for use with non-coherent render target reads.
2218 * In a few complex cases, we can't use the SURFACE_STATE for normal render
2219 * target writes. We need to make a separate one for sampling which refers
2220 * to the single slice of the texture being read.
2223 get_rt_read_isl_surf(const struct gen_device_info
*devinfo
,
2224 struct iris_resource
*res
,
2225 enum pipe_texture_target target
,
2226 struct isl_view
*view
,
2227 uint32_t *offset_to_tile
,
2228 uint32_t *tile_x_sa
,
2229 uint32_t *tile_y_sa
,
2230 struct isl_surf
*surf
)
2234 const enum isl_dim_layout dim_layout
=
2235 iris_get_isl_dim_layout(devinfo
, res
->surf
.tiling
, target
);
2237 surf
->dim
= target_to_isl_surf_dim(target
);
2239 if (surf
->dim_layout
== dim_layout
)
2242 /* The layout of the specified texture target is not compatible with the
2243 * actual layout of the miptree structure in memory -- You're entering
2244 * dangerous territory, this can only possibly work if you only intended
2245 * to access a single level and slice of the texture, and the hardware
2246 * supports the tile offset feature in order to allow non-tile-aligned
2247 * base offsets, since we'll have to point the hardware to the first
2248 * texel of the level instead of relying on the usual base level/layer
2251 assert(view
->levels
== 1 && view
->array_len
== 1);
2252 assert(*tile_x_sa
== 0 && *tile_y_sa
== 0);
2254 *offset_to_tile
= iris_resource_get_tile_offsets(res
, view
->base_level
,
2255 view
->base_array_layer
,
2256 tile_x_sa
, tile_y_sa
);
2257 const unsigned l
= view
->base_level
;
2259 surf
->logical_level0_px
.width
= minify(surf
->logical_level0_px
.width
, l
);
2260 surf
->logical_level0_px
.height
= surf
->dim
<= ISL_SURF_DIM_1D
? 1 :
2261 minify(surf
->logical_level0_px
.height
, l
);
2262 surf
->logical_level0_px
.depth
= surf
->dim
<= ISL_SURF_DIM_2D
? 1 :
2263 minify(surf
->logical_level0_px
.depth
, l
);
2265 surf
->logical_level0_px
.array_len
= 1;
2267 surf
->dim_layout
= dim_layout
;
2269 view
->base_level
= 0;
2270 view
->base_array_layer
= 0;
2275 fill_surface_state(struct isl_device
*isl_dev
,
2277 struct iris_resource
*res
,
2278 struct isl_surf
*surf
,
2279 struct isl_view
*view
,
2281 uint32_t extra_main_offset
,
2285 struct isl_surf_fill_state_info f
= {
2288 .mocs
= iris_mocs(res
->bo
, isl_dev
),
2289 .address
= res
->bo
->gtt_offset
+ res
->offset
+ extra_main_offset
,
2290 .x_offset_sa
= tile_x_sa
,
2291 .y_offset_sa
= tile_y_sa
,
2294 assert(!iris_resource_unfinished_aux_import(res
));
2296 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
2297 f
.aux_surf
= &res
->aux
.surf
;
2298 f
.aux_usage
= aux_usage
;
2299 f
.aux_address
= res
->aux
.bo
->gtt_offset
+ res
->aux
.offset
;
2301 struct iris_bo
*clear_bo
= NULL
;
2302 uint64_t clear_offset
= 0;
2304 iris_resource_get_clear_color(res
, &clear_bo
, &clear_offset
);
2306 f
.clear_address
= clear_bo
->gtt_offset
+ clear_offset
;
2307 f
.use_clear_address
= isl_dev
->info
->gen
> 9;
2311 isl_surf_fill_state_s(isl_dev
, map
, &f
);
2315 * The pipe->create_sampler_view() driver hook.
2317 static struct pipe_sampler_view
*
2318 iris_create_sampler_view(struct pipe_context
*ctx
,
2319 struct pipe_resource
*tex
,
2320 const struct pipe_sampler_view
*tmpl
)
2322 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2323 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2324 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2325 struct iris_sampler_view
*isv
= calloc(1, sizeof(struct iris_sampler_view
));
2330 /* initialize base object */
2332 isv
->base
.context
= ctx
;
2333 isv
->base
.texture
= NULL
;
2334 pipe_reference_init(&isv
->base
.reference
, 1);
2335 pipe_resource_reference(&isv
->base
.texture
, tex
);
2337 if (util_format_is_depth_or_stencil(tmpl
->format
)) {
2338 struct iris_resource
*zres
, *sres
;
2339 const struct util_format_description
*desc
=
2340 util_format_description(tmpl
->format
);
2342 iris_get_depth_stencil_resources(tex
, &zres
, &sres
);
2344 tex
= util_format_has_depth(desc
) ? &zres
->base
: &sres
->base
;
2347 isv
->res
= (struct iris_resource
*) tex
;
2349 alloc_surface_states(&isv
->surface_state
, isv
->res
->aux
.sampler_usages
);
2351 isv
->surface_state
.bo_address
= isv
->res
->bo
->gtt_offset
;
2353 isl_surf_usage_flags_t usage
= ISL_SURF_USAGE_TEXTURE_BIT
;
2355 if (isv
->base
.target
== PIPE_TEXTURE_CUBE
||
2356 isv
->base
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
2357 usage
|= ISL_SURF_USAGE_CUBE_BIT
;
2359 const struct iris_format_info fmt
=
2360 iris_format_for_usage(devinfo
, tmpl
->format
, usage
);
2362 isv
->clear_color
= isv
->res
->aux
.clear_color
;
2364 isv
->view
= (struct isl_view
) {
2366 .swizzle
= (struct isl_swizzle
) {
2367 .r
= fmt_swizzle(&fmt
, tmpl
->swizzle_r
),
2368 .g
= fmt_swizzle(&fmt
, tmpl
->swizzle_g
),
2369 .b
= fmt_swizzle(&fmt
, tmpl
->swizzle_b
),
2370 .a
= fmt_swizzle(&fmt
, tmpl
->swizzle_a
),
2375 void *map
= isv
->surface_state
.cpu
;
2377 /* Fill out SURFACE_STATE for this view. */
2378 if (tmpl
->target
!= PIPE_BUFFER
) {
2379 isv
->view
.base_level
= tmpl
->u
.tex
.first_level
;
2380 isv
->view
.levels
= tmpl
->u
.tex
.last_level
- tmpl
->u
.tex
.first_level
+ 1;
2381 // XXX: do I need to port f9fd0cf4790cb2a530e75d1a2206dbb9d8af7cb2?
2382 isv
->view
.base_array_layer
= tmpl
->u
.tex
.first_layer
;
2383 isv
->view
.array_len
=
2384 tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
2386 if (iris_resource_unfinished_aux_import(isv
->res
))
2387 iris_resource_finish_aux_import(&screen
->base
, isv
->res
);
2389 unsigned aux_modes
= isv
->res
->aux
.sampler_usages
;
2391 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
2393 /* If we have a multisampled depth buffer, do not create a sampler
2394 * surface state with HiZ.
2396 fill_surface_state(&screen
->isl_dev
, map
, isv
->res
, &isv
->res
->surf
,
2397 &isv
->view
, aux_usage
, 0, 0, 0);
2399 map
+= SURFACE_STATE_ALIGNMENT
;
2402 fill_buffer_surface_state(&screen
->isl_dev
, isv
->res
, map
,
2403 isv
->view
.format
, isv
->view
.swizzle
,
2404 tmpl
->u
.buf
.offset
, tmpl
->u
.buf
.size
);
2407 upload_surface_states(ice
->state
.surface_uploader
, &isv
->surface_state
);
2413 iris_sampler_view_destroy(struct pipe_context
*ctx
,
2414 struct pipe_sampler_view
*state
)
2416 struct iris_sampler_view
*isv
= (void *) state
;
2417 pipe_resource_reference(&state
->texture
, NULL
);
2418 pipe_resource_reference(&isv
->surface_state
.ref
.res
, NULL
);
2419 free(isv
->surface_state
.cpu
);
2424 * The pipe->create_surface() driver hook.
2426 * In Gallium nomenclature, "surfaces" are a view of a resource that
2427 * can be bound as a render target or depth/stencil buffer.
2429 static struct pipe_surface
*
2430 iris_create_surface(struct pipe_context
*ctx
,
2431 struct pipe_resource
*tex
,
2432 const struct pipe_surface
*tmpl
)
2434 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2435 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2436 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2438 isl_surf_usage_flags_t usage
= 0;
2440 usage
= ISL_SURF_USAGE_STORAGE_BIT
;
2441 else if (util_format_is_depth_or_stencil(tmpl
->format
))
2442 usage
= ISL_SURF_USAGE_DEPTH_BIT
;
2444 usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
2446 const struct iris_format_info fmt
=
2447 iris_format_for_usage(devinfo
, tmpl
->format
, usage
);
2449 if ((usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) &&
2450 !isl_format_supports_rendering(devinfo
, fmt
.fmt
)) {
2451 /* Framebuffer validation will reject this invalid case, but it
2452 * hasn't had the opportunity yet. In the meantime, we need to
2453 * avoid hitting ISL asserts about unsupported formats below.
2458 struct iris_surface
*surf
= calloc(1, sizeof(struct iris_surface
));
2459 struct pipe_surface
*psurf
= &surf
->base
;
2460 struct iris_resource
*res
= (struct iris_resource
*) tex
;
2465 pipe_reference_init(&psurf
->reference
, 1);
2466 pipe_resource_reference(&psurf
->texture
, tex
);
2467 psurf
->context
= ctx
;
2468 psurf
->format
= tmpl
->format
;
2469 psurf
->width
= tex
->width0
;
2470 psurf
->height
= tex
->height0
;
2471 psurf
->texture
= tex
;
2472 psurf
->u
.tex
.first_layer
= tmpl
->u
.tex
.first_layer
;
2473 psurf
->u
.tex
.last_layer
= tmpl
->u
.tex
.last_layer
;
2474 psurf
->u
.tex
.level
= tmpl
->u
.tex
.level
;
2476 uint32_t array_len
= tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
2478 struct isl_view
*view
= &surf
->view
;
2479 *view
= (struct isl_view
) {
2481 .base_level
= tmpl
->u
.tex
.level
,
2483 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
2484 .array_len
= array_len
,
2485 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2490 enum pipe_texture_target target
= (tex
->target
== PIPE_TEXTURE_3D
&&
2491 array_len
== 1) ? PIPE_TEXTURE_2D
:
2492 tex
->target
== PIPE_TEXTURE_1D_ARRAY
?
2493 PIPE_TEXTURE_2D_ARRAY
: tex
->target
;
2495 struct isl_view
*read_view
= &surf
->read_view
;
2496 *read_view
= (struct isl_view
) {
2498 .base_level
= tmpl
->u
.tex
.level
,
2500 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
2501 .array_len
= array_len
,
2502 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2503 .usage
= ISL_SURF_USAGE_TEXTURE_BIT
,
2507 surf
->clear_color
= res
->aux
.clear_color
;
2509 /* Bail early for depth/stencil - we don't want SURFACE_STATE for them. */
2510 if (res
->surf
.usage
& (ISL_SURF_USAGE_DEPTH_BIT
|
2511 ISL_SURF_USAGE_STENCIL_BIT
))
2515 alloc_surface_states(&surf
->surface_state
, res
->aux
.possible_usages
);
2516 surf
->surface_state
.bo_address
= res
->bo
->gtt_offset
;
2519 alloc_surface_states(&surf
->surface_state_read
, res
->aux
.possible_usages
);
2520 surf
->surface_state_read
.bo_address
= res
->bo
->gtt_offset
;
2523 if (!isl_format_is_compressed(res
->surf
.format
)) {
2524 if (iris_resource_unfinished_aux_import(res
))
2525 iris_resource_finish_aux_import(&screen
->base
, res
);
2527 void *map
= surf
->surface_state
.cpu
;
2528 UNUSED
void *map_read
= surf
->surface_state_read
.cpu
;
2530 /* This is a normal surface. Fill out a SURFACE_STATE for each possible
2531 * auxiliary surface mode and return the pipe_surface.
2533 unsigned aux_modes
= res
->aux
.possible_usages
;
2535 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
2536 fill_surface_state(&screen
->isl_dev
, map
, res
, &res
->surf
,
2537 view
, aux_usage
, 0, 0, 0);
2538 map
+= SURFACE_STATE_ALIGNMENT
;
2541 struct isl_surf surf
;
2542 uint32_t offset_to_tile
= 0, tile_x_sa
= 0, tile_y_sa
= 0;
2543 get_rt_read_isl_surf(devinfo
, res
, target
, read_view
,
2544 &offset_to_tile
, &tile_x_sa
, &tile_y_sa
, &surf
);
2545 fill_surface_state(&screen
->isl_dev
, map_read
, res
, &surf
, read_view
,
2546 aux_usage
, offset_to_tile
, tile_x_sa
, tile_y_sa
);
2547 map_read
+= SURFACE_STATE_ALIGNMENT
;
2551 upload_surface_states(ice
->state
.surface_uploader
, &surf
->surface_state
);
2554 upload_surface_states(ice
->state
.surface_uploader
,
2555 &surf
->surface_state_read
);
2561 /* The resource has a compressed format, which is not renderable, but we
2562 * have a renderable view format. We must be attempting to upload blocks
2563 * of compressed data via an uncompressed view.
2565 * In this case, we can assume there are no auxiliary buffers, a single
2566 * miplevel, and that the resource is single-sampled. Gallium may try
2567 * and create an uncompressed view with multiple layers, however.
2569 assert(!isl_format_is_compressed(fmt
.fmt
));
2570 assert(res
->aux
.possible_usages
== 1 << ISL_AUX_USAGE_NONE
);
2571 assert(res
->surf
.samples
== 1);
2572 assert(view
->levels
== 1);
2574 struct isl_surf isl_surf
;
2575 uint32_t offset_B
= 0, tile_x_sa
= 0, tile_y_sa
= 0;
2577 if (view
->base_level
> 0) {
2578 /* We can't rely on the hardware's miplevel selection with such
2579 * a substantial lie about the format, so we select a single image
2580 * using the Tile X/Y Offset fields. In this case, we can't handle
2581 * multiple array slices.
2583 * On Broadwell, HALIGN and VALIGN are specified in pixels and are
2584 * hard-coded to align to exactly the block size of the compressed
2585 * texture. This means that, when reinterpreted as a non-compressed
2586 * texture, the tile offsets may be anything and we can't rely on
2589 * Return NULL to force gallium frontends to take fallback paths.
2591 if (view
->array_len
> 1 || GEN_GEN
== 8)
2594 const bool is_3d
= res
->surf
.dim
== ISL_SURF_DIM_3D
;
2595 isl_surf_get_image_surf(&screen
->isl_dev
, &res
->surf
,
2597 is_3d
? 0 : view
->base_array_layer
,
2598 is_3d
? view
->base_array_layer
: 0,
2600 &offset_B
, &tile_x_sa
, &tile_y_sa
);
2602 /* We use address and tile offsets to access a single level/layer
2603 * as a subimage, so reset level/layer so it doesn't offset again.
2605 view
->base_array_layer
= 0;
2606 view
->base_level
= 0;
2608 /* Level 0 doesn't require tile offsets, and the hardware can find
2609 * array slices using QPitch even with the format override, so we
2610 * can allow layers in this case. Copy the original ISL surface.
2612 memcpy(&isl_surf
, &res
->surf
, sizeof(isl_surf
));
2615 /* Scale down the image dimensions by the block size. */
2616 const struct isl_format_layout
*fmtl
=
2617 isl_format_get_layout(res
->surf
.format
);
2618 isl_surf
.format
= fmt
.fmt
;
2619 isl_surf
.logical_level0_px
= isl_surf_get_logical_level0_el(&isl_surf
);
2620 isl_surf
.phys_level0_sa
= isl_surf_get_phys_level0_el(&isl_surf
);
2621 tile_x_sa
/= fmtl
->bw
;
2622 tile_y_sa
/= fmtl
->bh
;
2624 psurf
->width
= isl_surf
.logical_level0_px
.width
;
2625 psurf
->height
= isl_surf
.logical_level0_px
.height
;
2627 struct isl_surf_fill_state_info f
= {
2630 .mocs
= iris_mocs(res
->bo
, &screen
->isl_dev
),
2631 .address
= res
->bo
->gtt_offset
+ offset_B
,
2632 .x_offset_sa
= tile_x_sa
,
2633 .y_offset_sa
= tile_y_sa
,
2636 isl_surf_fill_state_s(&screen
->isl_dev
, surf
->surface_state
.cpu
, &f
);
2638 upload_surface_states(ice
->state
.surface_uploader
, &surf
->surface_state
);
2645 fill_default_image_param(struct brw_image_param
*param
)
2647 memset(param
, 0, sizeof(*param
));
2648 /* Set the swizzling shifts to all-ones to effectively disable swizzling --
2649 * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
2650 * detailed explanation of these parameters.
2652 param
->swizzling
[0] = 0xff;
2653 param
->swizzling
[1] = 0xff;
2657 fill_buffer_image_param(struct brw_image_param
*param
,
2658 enum pipe_format pfmt
,
2661 const unsigned cpp
= util_format_get_blocksize(pfmt
);
2663 fill_default_image_param(param
);
2664 param
->size
[0] = size
/ cpp
;
2665 param
->stride
[0] = cpp
;
2668 #define isl_surf_fill_image_param(x, ...)
2669 #define fill_default_image_param(x, ...)
2670 #define fill_buffer_image_param(x, ...)
2674 * The pipe->set_shader_images() driver hook.
2677 iris_set_shader_images(struct pipe_context
*ctx
,
2678 enum pipe_shader_type p_stage
,
2679 unsigned start_slot
, unsigned count
,
2680 const struct pipe_image_view
*p_images
)
2682 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2683 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2684 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2685 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2687 struct iris_genx_state
*genx
= ice
->state
.genx
;
2688 struct brw_image_param
*image_params
= genx
->shaders
[stage
].image_param
;
2691 shs
->bound_image_views
&= ~u_bit_consecutive(start_slot
, count
);
2693 for (unsigned i
= 0; i
< count
; i
++) {
2694 struct iris_image_view
*iv
= &shs
->image
[start_slot
+ i
];
2696 if (p_images
&& p_images
[i
].resource
) {
2697 const struct pipe_image_view
*img
= &p_images
[i
];
2698 struct iris_resource
*res
= (void *) img
->resource
;
2700 util_copy_image_view(&iv
->base
, img
);
2702 shs
->bound_image_views
|= 1 << (start_slot
+ i
);
2704 res
->bind_history
|= PIPE_BIND_SHADER_IMAGE
;
2705 res
->bind_stages
|= 1 << stage
;
2707 enum isl_format isl_fmt
= iris_image_view_get_format(ice
, img
);
2709 /* Render compression with images supported on gen12+ only. */
2710 unsigned aux_usages
= GEN_GEN
>= 12 ? res
->aux
.possible_usages
:
2711 1 << ISL_AUX_USAGE_NONE
;
2713 alloc_surface_states(&iv
->surface_state
, aux_usages
);
2714 iv
->surface_state
.bo_address
= res
->bo
->gtt_offset
;
2716 void *map
= iv
->surface_state
.cpu
;
2718 if (res
->base
.target
!= PIPE_BUFFER
) {
2719 struct isl_view view
= {
2721 .base_level
= img
->u
.tex
.level
,
2723 .base_array_layer
= img
->u
.tex
.first_layer
,
2724 .array_len
= img
->u
.tex
.last_layer
- img
->u
.tex
.first_layer
+ 1,
2725 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2726 .usage
= ISL_SURF_USAGE_STORAGE_BIT
,
2729 /* If using untyped fallback. */
2730 if (isl_fmt
== ISL_FORMAT_RAW
) {
2731 fill_buffer_surface_state(&screen
->isl_dev
, res
, map
,
2732 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
2735 unsigned aux_modes
= aux_usages
;
2737 enum isl_aux_usage usage
= u_bit_scan(&aux_modes
);
2739 fill_surface_state(&screen
->isl_dev
, map
, res
, &res
->surf
,
2740 &view
, usage
, 0, 0, 0);
2742 map
+= SURFACE_STATE_ALIGNMENT
;
2746 isl_surf_fill_image_param(&screen
->isl_dev
,
2747 &image_params
[start_slot
+ i
],
2750 util_range_add(&res
->base
, &res
->valid_buffer_range
, img
->u
.buf
.offset
,
2751 img
->u
.buf
.offset
+ img
->u
.buf
.size
);
2753 fill_buffer_surface_state(&screen
->isl_dev
, res
, map
,
2754 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
2755 img
->u
.buf
.offset
, img
->u
.buf
.size
);
2756 fill_buffer_image_param(&image_params
[start_slot
+ i
],
2757 img
->format
, img
->u
.buf
.size
);
2760 upload_surface_states(ice
->state
.surface_uploader
, &iv
->surface_state
);
2762 pipe_resource_reference(&iv
->base
.resource
, NULL
);
2763 pipe_resource_reference(&iv
->surface_state
.ref
.res
, NULL
);
2764 fill_default_image_param(&image_params
[start_slot
+ i
]);
2768 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
2770 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
2771 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2773 /* Broadwell also needs brw_image_params re-uploaded */
2775 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
2776 shs
->sysvals_need_upload
= true;
2782 * The pipe->set_sampler_views() driver hook.
2785 iris_set_sampler_views(struct pipe_context
*ctx
,
2786 enum pipe_shader_type p_stage
,
2787 unsigned start
, unsigned count
,
2788 struct pipe_sampler_view
**views
)
2790 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2791 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2792 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2794 shs
->bound_sampler_views
&= ~u_bit_consecutive(start
, count
);
2796 for (unsigned i
= 0; i
< count
; i
++) {
2797 struct pipe_sampler_view
*pview
= views
? views
[i
] : NULL
;
2798 pipe_sampler_view_reference((struct pipe_sampler_view
**)
2799 &shs
->textures
[start
+ i
], pview
);
2800 struct iris_sampler_view
*view
= (void *) pview
;
2802 view
->res
->bind_history
|= PIPE_BIND_SAMPLER_VIEW
;
2803 view
->res
->bind_stages
|= 1 << stage
;
2805 shs
->bound_sampler_views
|= 1 << (start
+ i
);
2807 update_surface_state_addrs(ice
->state
.surface_uploader
,
2808 &view
->surface_state
, view
->res
->bo
);
2812 ice
->state
.dirty
|= (IRIS_DIRTY_BINDINGS_VS
<< stage
);
2814 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
2815 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2819 * The pipe->set_tess_state() driver hook.
2822 iris_set_tess_state(struct pipe_context
*ctx
,
2823 const float default_outer_level
[4],
2824 const float default_inner_level
[2])
2826 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2827 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_TESS_CTRL
];
2829 memcpy(&ice
->state
.default_outer_level
[0], &default_outer_level
[0], 4 * sizeof(float));
2830 memcpy(&ice
->state
.default_inner_level
[0], &default_inner_level
[0], 2 * sizeof(float));
2832 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_TCS
;
2833 shs
->sysvals_need_upload
= true;
2837 iris_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
*p_surf
)
2839 struct iris_surface
*surf
= (void *) p_surf
;
2840 pipe_resource_reference(&p_surf
->texture
, NULL
);
2841 pipe_resource_reference(&surf
->surface_state
.ref
.res
, NULL
);
2842 pipe_resource_reference(&surf
->surface_state_read
.ref
.res
, NULL
);
2843 free(surf
->surface_state
.cpu
);
2848 iris_set_clip_state(struct pipe_context
*ctx
,
2849 const struct pipe_clip_state
*state
)
2851 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2852 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_VERTEX
];
2853 struct iris_shader_state
*gshs
= &ice
->state
.shaders
[MESA_SHADER_GEOMETRY
];
2854 struct iris_shader_state
*tshs
= &ice
->state
.shaders
[MESA_SHADER_TESS_EVAL
];
2856 memcpy(&ice
->state
.clip_planes
, state
, sizeof(*state
));
2858 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
| IRIS_DIRTY_CONSTANTS_GS
|
2859 IRIS_DIRTY_CONSTANTS_TES
;
2860 shs
->sysvals_need_upload
= true;
2861 gshs
->sysvals_need_upload
= true;
2862 tshs
->sysvals_need_upload
= true;
2866 * The pipe->set_polygon_stipple() driver hook.
2869 iris_set_polygon_stipple(struct pipe_context
*ctx
,
2870 const struct pipe_poly_stipple
*state
)
2872 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2873 memcpy(&ice
->state
.poly_stipple
, state
, sizeof(*state
));
2874 ice
->state
.dirty
|= IRIS_DIRTY_POLYGON_STIPPLE
;
2878 * The pipe->set_sample_mask() driver hook.
2881 iris_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
2883 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2885 /* We only support 16x MSAA, so we have 16 bits of sample maks.
2886 * st/mesa may pass us 0xffffffff though, meaning "enable all samples".
2888 ice
->state
.sample_mask
= sample_mask
& 0xffff;
2889 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLE_MASK
;
2893 * The pipe->set_scissor_states() driver hook.
2895 * This corresponds to our SCISSOR_RECT state structures. It's an
2896 * exact match, so we just store them, and memcpy them out later.
2899 iris_set_scissor_states(struct pipe_context
*ctx
,
2900 unsigned start_slot
,
2901 unsigned num_scissors
,
2902 const struct pipe_scissor_state
*rects
)
2904 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2906 for (unsigned i
= 0; i
< num_scissors
; i
++) {
2907 if (rects
[i
].minx
== rects
[i
].maxx
|| rects
[i
].miny
== rects
[i
].maxy
) {
2908 /* If the scissor was out of bounds and got clamped to 0 width/height
2909 * at the bounds, the subtraction of 1 from maximums could produce a
2910 * negative number and thus not clip anything. Instead, just provide
2911 * a min > max scissor inside the bounds, which produces the expected
2914 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2915 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,
2918 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2919 .minx
= rects
[i
].minx
, .miny
= rects
[i
].miny
,
2920 .maxx
= rects
[i
].maxx
- 1, .maxy
= rects
[i
].maxy
- 1,
2925 ice
->state
.dirty
|= IRIS_DIRTY_SCISSOR_RECT
;
2929 * The pipe->set_stencil_ref() driver hook.
2931 * This is added to 3DSTATE_WM_DEPTH_STENCIL dynamically at draw time.
2934 iris_set_stencil_ref(struct pipe_context
*ctx
,
2935 const struct pipe_stencil_ref
*state
)
2937 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2938 memcpy(&ice
->state
.stencil_ref
, state
, sizeof(*state
));
2940 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
2942 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
2946 viewport_extent(const struct pipe_viewport_state
*state
, int axis
, float sign
)
2948 return copysignf(state
->scale
[axis
], sign
) + state
->translate
[axis
];
2952 * The pipe->set_viewport_states() driver hook.
2954 * This corresponds to our SF_CLIP_VIEWPORT states. We can't calculate
2955 * the guardband yet, as we need the framebuffer dimensions, but we can
2956 * at least fill out the rest.
2959 iris_set_viewport_states(struct pipe_context
*ctx
,
2960 unsigned start_slot
,
2962 const struct pipe_viewport_state
*states
)
2964 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2966 memcpy(&ice
->state
.viewports
[start_slot
], states
, sizeof(*states
) * count
);
2968 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
2970 if (ice
->state
.cso_rast
&& (!ice
->state
.cso_rast
->depth_clip_near
||
2971 !ice
->state
.cso_rast
->depth_clip_far
))
2972 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
2976 * The pipe->set_framebuffer_state() driver hook.
2978 * Sets the current draw FBO, including color render targets, depth,
2979 * and stencil buffers.
2982 iris_set_framebuffer_state(struct pipe_context
*ctx
,
2983 const struct pipe_framebuffer_state
*state
)
2985 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2986 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2987 struct isl_device
*isl_dev
= &screen
->isl_dev
;
2988 struct pipe_framebuffer_state
*cso
= &ice
->state
.framebuffer
;
2989 struct iris_resource
*zres
;
2990 struct iris_resource
*stencil_res
;
2992 unsigned samples
= util_framebuffer_get_num_samples(state
);
2993 unsigned layers
= util_framebuffer_get_num_layers(state
);
2995 if (cso
->samples
!= samples
) {
2996 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
2998 /* We need to toggle 3DSTATE_PS::32 Pixel Dispatch Enable */
2999 if (GEN_GEN
>= 9 && (cso
->samples
== 16 || samples
== 16))
3000 ice
->state
.dirty
|= IRIS_DIRTY_FS
;
3003 if (cso
->nr_cbufs
!= state
->nr_cbufs
) {
3004 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
3007 if ((cso
->layers
== 0) != (layers
== 0)) {
3008 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
3011 if (cso
->width
!= state
->width
|| cso
->height
!= state
->height
) {
3012 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
3015 if (cso
->zsbuf
|| state
->zsbuf
) {
3016 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BUFFER
;
3019 util_copy_framebuffer_state(cso
, state
);
3020 cso
->samples
= samples
;
3021 cso
->layers
= layers
;
3023 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
3025 struct isl_view view
= {
3028 .base_array_layer
= 0,
3030 .swizzle
= ISL_SWIZZLE_IDENTITY
,
3033 struct isl_depth_stencil_hiz_emit_info info
= { .view
= &view
};
3036 iris_get_depth_stencil_resources(cso
->zsbuf
->texture
, &zres
,
3039 view
.base_level
= cso
->zsbuf
->u
.tex
.level
;
3040 view
.base_array_layer
= cso
->zsbuf
->u
.tex
.first_layer
;
3042 cso
->zsbuf
->u
.tex
.last_layer
- cso
->zsbuf
->u
.tex
.first_layer
+ 1;
3045 view
.usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
3047 info
.depth_surf
= &zres
->surf
;
3048 info
.depth_address
= zres
->bo
->gtt_offset
+ zres
->offset
;
3049 info
.mocs
= iris_mocs(zres
->bo
, isl_dev
);
3051 view
.format
= zres
->surf
.format
;
3053 if (iris_resource_level_has_hiz(zres
, view
.base_level
)) {
3054 info
.hiz_usage
= zres
->aux
.usage
;
3055 info
.hiz_surf
= &zres
->aux
.surf
;
3056 info
.hiz_address
= zres
->aux
.bo
->gtt_offset
+ zres
->aux
.offset
;
3061 view
.usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
3062 info
.stencil_aux_usage
= stencil_res
->aux
.usage
;
3063 info
.stencil_surf
= &stencil_res
->surf
;
3064 info
.stencil_address
= stencil_res
->bo
->gtt_offset
+ stencil_res
->offset
;
3066 view
.format
= stencil_res
->surf
.format
;
3067 info
.mocs
= iris_mocs(stencil_res
->bo
, isl_dev
);
3072 isl_emit_depth_stencil_hiz_s(isl_dev
, cso_z
->packets
, &info
);
3074 /* Make a null surface for unbound buffers */
3075 void *null_surf_map
=
3076 upload_state(ice
->state
.surface_uploader
, &ice
->state
.null_fb
,
3077 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
3078 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
,
3079 isl_extent3d(MAX2(cso
->width
, 1),
3080 MAX2(cso
->height
, 1),
3081 cso
->layers
? cso
->layers
: 1));
3082 ice
->state
.null_fb
.offset
+=
3083 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.null_fb
.res
));
3085 /* Render target change */
3086 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_FS
;
3088 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_BUFFER
;
3090 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
3092 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_FRAMEBUFFER
];
3095 ice
->state
.dirty
|= IRIS_DIRTY_PMA_FIX
;
3099 * The pipe->set_constant_buffer() driver hook.
3101 * This uploads any constant data in user buffers, and references
3102 * any UBO resources containing constant data.
3105 iris_set_constant_buffer(struct pipe_context
*ctx
,
3106 enum pipe_shader_type p_stage
, unsigned index
,
3107 const struct pipe_constant_buffer
*input
)
3109 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3110 gl_shader_stage stage
= stage_from_pipe(p_stage
);
3111 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3112 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[index
];
3114 /* TODO: Only do this if the buffer changes? */
3115 pipe_resource_reference(&shs
->constbuf_surf_state
[index
].res
, NULL
);
3117 if (input
&& input
->buffer_size
&& (input
->buffer
|| input
->user_buffer
)) {
3118 shs
->bound_cbufs
|= 1u << index
;
3120 if (input
->user_buffer
) {
3122 pipe_resource_reference(&cbuf
->buffer
, NULL
);
3123 u_upload_alloc(ice
->ctx
.const_uploader
, 0, input
->buffer_size
, 64,
3124 &cbuf
->buffer_offset
, &cbuf
->buffer
, (void **) &map
);
3126 if (!cbuf
->buffer
) {
3127 /* Allocation was unsuccessful - just unbind */
3128 iris_set_constant_buffer(ctx
, p_stage
, index
, NULL
);
3133 memcpy(map
, input
->user_buffer
, input
->buffer_size
);
3134 } else if (input
->buffer
) {
3135 pipe_resource_reference(&cbuf
->buffer
, input
->buffer
);
3137 cbuf
->buffer_offset
= input
->buffer_offset
;
3141 MIN2(input
->buffer_size
,
3142 iris_resource_bo(cbuf
->buffer
)->size
- cbuf
->buffer_offset
);
3144 struct iris_resource
*res
= (void *) cbuf
->buffer
;
3145 res
->bind_history
|= PIPE_BIND_CONSTANT_BUFFER
;
3146 res
->bind_stages
|= 1 << stage
;
3148 shs
->bound_cbufs
&= ~(1u << index
);
3149 pipe_resource_reference(&cbuf
->buffer
, NULL
);
3152 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
3156 upload_sysvals(struct iris_context
*ice
,
3157 gl_shader_stage stage
)
3159 UNUSED
struct iris_genx_state
*genx
= ice
->state
.genx
;
3160 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3162 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
3163 if (!shader
|| shader
->num_system_values
== 0)
3166 assert(shader
->num_cbufs
> 0);
3168 unsigned sysval_cbuf_index
= shader
->num_cbufs
- 1;
3169 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[sysval_cbuf_index
];
3170 unsigned upload_size
= shader
->num_system_values
* sizeof(uint32_t);
3171 uint32_t *map
= NULL
;
3173 assert(sysval_cbuf_index
< PIPE_MAX_CONSTANT_BUFFERS
);
3174 u_upload_alloc(ice
->ctx
.const_uploader
, 0, upload_size
, 64,
3175 &cbuf
->buffer_offset
, &cbuf
->buffer
, (void **) &map
);
3177 for (int i
= 0; i
< shader
->num_system_values
; i
++) {
3178 uint32_t sysval
= shader
->system_values
[i
];
3181 if (BRW_PARAM_DOMAIN(sysval
) == BRW_PARAM_DOMAIN_IMAGE
) {
3183 unsigned img
= BRW_PARAM_IMAGE_IDX(sysval
);
3184 unsigned offset
= BRW_PARAM_IMAGE_OFFSET(sysval
);
3185 struct brw_image_param
*param
=
3186 &genx
->shaders
[stage
].image_param
[img
];
3188 assert(offset
< sizeof(struct brw_image_param
));
3189 value
= ((uint32_t *) param
)[offset
];
3191 } else if (sysval
== BRW_PARAM_BUILTIN_ZERO
) {
3193 } else if (BRW_PARAM_BUILTIN_IS_CLIP_PLANE(sysval
)) {
3194 int plane
= BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(sysval
);
3195 int comp
= BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(sysval
);
3196 value
= fui(ice
->state
.clip_planes
.ucp
[plane
][comp
]);
3197 } else if (sysval
== BRW_PARAM_BUILTIN_PATCH_VERTICES_IN
) {
3198 if (stage
== MESA_SHADER_TESS_CTRL
) {
3199 value
= ice
->state
.vertices_per_patch
;
3201 assert(stage
== MESA_SHADER_TESS_EVAL
);
3202 const struct shader_info
*tcs_info
=
3203 iris_get_shader_info(ice
, MESA_SHADER_TESS_CTRL
);
3205 value
= tcs_info
->tess
.tcs_vertices_out
;
3207 value
= ice
->state
.vertices_per_patch
;
3209 } else if (sysval
>= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
&&
3210 sysval
<= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W
) {
3211 unsigned i
= sysval
- BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
;
3212 value
= fui(ice
->state
.default_outer_level
[i
]);
3213 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X
) {
3214 value
= fui(ice
->state
.default_inner_level
[0]);
3215 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y
) {
3216 value
= fui(ice
->state
.default_inner_level
[1]);
3217 } else if (sysval
>= BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_X
&&
3218 sysval
<= BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Z
) {
3219 unsigned i
= sysval
- BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_X
;
3220 value
= ice
->state
.last_block
[i
];
3222 assert(!"unhandled system value");
3228 cbuf
->buffer_size
= upload_size
;
3229 iris_upload_ubo_ssbo_surf_state(ice
, cbuf
,
3230 &shs
->constbuf_surf_state
[sysval_cbuf_index
], false);
3232 shs
->sysvals_need_upload
= false;
3236 * The pipe->set_shader_buffers() driver hook.
3238 * This binds SSBOs and ABOs. Unfortunately, we need to stream out
3239 * SURFACE_STATE here, as the buffer offset may change each time.
3242 iris_set_shader_buffers(struct pipe_context
*ctx
,
3243 enum pipe_shader_type p_stage
,
3244 unsigned start_slot
, unsigned count
,
3245 const struct pipe_shader_buffer
*buffers
,
3246 unsigned writable_bitmask
)
3248 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3249 gl_shader_stage stage
= stage_from_pipe(p_stage
);
3250 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3252 unsigned modified_bits
= u_bit_consecutive(start_slot
, count
);
3254 shs
->bound_ssbos
&= ~modified_bits
;
3255 shs
->writable_ssbos
&= ~modified_bits
;
3256 shs
->writable_ssbos
|= writable_bitmask
<< start_slot
;
3258 for (unsigned i
= 0; i
< count
; i
++) {
3259 if (buffers
&& buffers
[i
].buffer
) {
3260 struct iris_resource
*res
= (void *) buffers
[i
].buffer
;
3261 struct pipe_shader_buffer
*ssbo
= &shs
->ssbo
[start_slot
+ i
];
3262 struct iris_state_ref
*surf_state
=
3263 &shs
->ssbo_surf_state
[start_slot
+ i
];
3264 pipe_resource_reference(&ssbo
->buffer
, &res
->base
);
3265 ssbo
->buffer_offset
= buffers
[i
].buffer_offset
;
3267 MIN2(buffers
[i
].buffer_size
, res
->bo
->size
- ssbo
->buffer_offset
);
3269 shs
->bound_ssbos
|= 1 << (start_slot
+ i
);
3271 iris_upload_ubo_ssbo_surf_state(ice
, ssbo
, surf_state
, true);
3273 res
->bind_history
|= PIPE_BIND_SHADER_BUFFER
;
3274 res
->bind_stages
|= 1 << stage
;
3276 util_range_add(&res
->base
, &res
->valid_buffer_range
, ssbo
->buffer_offset
,
3277 ssbo
->buffer_offset
+ ssbo
->buffer_size
);
3279 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
].buffer
, NULL
);
3280 pipe_resource_reference(&shs
->ssbo_surf_state
[start_slot
+ i
].res
,
3285 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
3289 iris_delete_state(struct pipe_context
*ctx
, void *state
)
3295 * The pipe->set_vertex_buffers() driver hook.
3297 * This translates pipe_vertex_buffer to our 3DSTATE_VERTEX_BUFFERS packet.
3300 iris_set_vertex_buffers(struct pipe_context
*ctx
,
3301 unsigned start_slot
, unsigned count
,
3302 const struct pipe_vertex_buffer
*buffers
)
3304 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3305 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3306 struct iris_genx_state
*genx
= ice
->state
.genx
;
3308 ice
->state
.bound_vertex_buffers
&= ~u_bit_consecutive64(start_slot
, count
);
3310 for (unsigned i
= 0; i
< count
; i
++) {
3311 const struct pipe_vertex_buffer
*buffer
= buffers
? &buffers
[i
] : NULL
;
3312 struct iris_vertex_buffer_state
*state
=
3313 &genx
->vertex_buffers
[start_slot
+ i
];
3316 pipe_resource_reference(&state
->resource
, NULL
);
3320 /* We may see user buffers that are NULL bindings. */
3321 assert(!(buffer
->is_user_buffer
&& buffer
->buffer
.user
!= NULL
));
3323 pipe_resource_reference(&state
->resource
, buffer
->buffer
.resource
);
3324 struct iris_resource
*res
= (void *) state
->resource
;
3326 state
->offset
= (int) buffer
->buffer_offset
;
3329 ice
->state
.bound_vertex_buffers
|= 1ull << (start_slot
+ i
);
3330 res
->bind_history
|= PIPE_BIND_VERTEX_BUFFER
;
3333 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
3334 vb
.VertexBufferIndex
= start_slot
+ i
;
3335 vb
.AddressModifyEnable
= true;
3336 vb
.BufferPitch
= buffer
->stride
;
3338 vb
.BufferSize
= res
->base
.width0
- (int) buffer
->buffer_offset
;
3339 vb
.BufferStartingAddress
=
3340 ro_bo(NULL
, res
->bo
->gtt_offset
+ (int) buffer
->buffer_offset
);
3341 vb
.MOCS
= iris_mocs(res
->bo
, &screen
->isl_dev
);
3343 vb
.NullVertexBuffer
= true;
3348 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
3352 * Gallium CSO for vertex elements.
3354 struct iris_vertex_element_state
{
3355 uint32_t vertex_elements
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
3356 uint32_t vf_instancing
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
3357 uint32_t edgeflag_ve
[GENX(VERTEX_ELEMENT_STATE_length
)];
3358 uint32_t edgeflag_vfi
[GENX(3DSTATE_VF_INSTANCING_length
)];
3363 * The pipe->create_vertex_elements() driver hook.
3365 * This translates pipe_vertex_element to our 3DSTATE_VERTEX_ELEMENTS
3366 * and 3DSTATE_VF_INSTANCING commands. The vertex_elements and vf_instancing
3367 * arrays are ready to be emitted at draw time if no EdgeFlag or SGVs are
3368 * needed. In these cases we will need information available at draw time.
3369 * We setup edgeflag_ve and edgeflag_vfi as alternatives last
3370 * 3DSTATE_VERTEX_ELEMENT and 3DSTATE_VF_INSTANCING that can be used at
3371 * draw time if we detect that EdgeFlag is needed by the Vertex Shader.
3374 iris_create_vertex_elements(struct pipe_context
*ctx
,
3376 const struct pipe_vertex_element
*state
)
3378 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3379 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
3380 struct iris_vertex_element_state
*cso
=
3381 malloc(sizeof(struct iris_vertex_element_state
));
3385 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
), cso
->vertex_elements
, ve
) {
3387 1 + GENX(VERTEX_ELEMENT_STATE_length
) * MAX2(count
, 1) - 2;
3390 uint32_t *ve_pack_dest
= &cso
->vertex_elements
[1];
3391 uint32_t *vfi_pack_dest
= cso
->vf_instancing
;
3394 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
3396 ve
.SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
3397 ve
.Component0Control
= VFCOMP_STORE_0
;
3398 ve
.Component1Control
= VFCOMP_STORE_0
;
3399 ve
.Component2Control
= VFCOMP_STORE_0
;
3400 ve
.Component3Control
= VFCOMP_STORE_1_FP
;
3403 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
3407 for (int i
= 0; i
< count
; i
++) {
3408 const struct iris_format_info fmt
=
3409 iris_format_for_usage(devinfo
, state
[i
].src_format
, 0);
3410 unsigned comp
[4] = { VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
,
3411 VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
};
3413 switch (isl_format_get_num_channels(fmt
.fmt
)) {
3414 case 0: comp
[0] = VFCOMP_STORE_0
; /* fallthrough */
3415 case 1: comp
[1] = VFCOMP_STORE_0
; /* fallthrough */
3416 case 2: comp
[2] = VFCOMP_STORE_0
; /* fallthrough */
3418 comp
[3] = isl_format_has_int_channel(fmt
.fmt
) ? VFCOMP_STORE_1_INT
3419 : VFCOMP_STORE_1_FP
;
3422 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
3423 ve
.EdgeFlagEnable
= false;
3424 ve
.VertexBufferIndex
= state
[i
].vertex_buffer_index
;
3426 ve
.SourceElementOffset
= state
[i
].src_offset
;
3427 ve
.SourceElementFormat
= fmt
.fmt
;
3428 ve
.Component0Control
= comp
[0];
3429 ve
.Component1Control
= comp
[1];
3430 ve
.Component2Control
= comp
[2];
3431 ve
.Component3Control
= comp
[3];
3434 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
3435 vi
.VertexElementIndex
= i
;
3436 vi
.InstancingEnable
= state
[i
].instance_divisor
> 0;
3437 vi
.InstanceDataStepRate
= state
[i
].instance_divisor
;
3440 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
3441 vfi_pack_dest
+= GENX(3DSTATE_VF_INSTANCING_length
);
3444 /* An alternative version of the last VE and VFI is stored so it
3445 * can be used at draw time in case Vertex Shader uses EdgeFlag
3448 const unsigned edgeflag_index
= count
- 1;
3449 const struct iris_format_info fmt
=
3450 iris_format_for_usage(devinfo
, state
[edgeflag_index
].src_format
, 0);
3451 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), cso
->edgeflag_ve
, ve
) {
3452 ve
.EdgeFlagEnable
= true ;
3453 ve
.VertexBufferIndex
= state
[edgeflag_index
].vertex_buffer_index
;
3455 ve
.SourceElementOffset
= state
[edgeflag_index
].src_offset
;
3456 ve
.SourceElementFormat
= fmt
.fmt
;
3457 ve
.Component0Control
= VFCOMP_STORE_SRC
;
3458 ve
.Component1Control
= VFCOMP_STORE_0
;
3459 ve
.Component2Control
= VFCOMP_STORE_0
;
3460 ve
.Component3Control
= VFCOMP_STORE_0
;
3462 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), cso
->edgeflag_vfi
, vi
) {
3463 /* The vi.VertexElementIndex of the EdgeFlag Vertex Element is filled
3464 * at draw time, as it should change if SGVs are emitted.
3466 vi
.InstancingEnable
= state
[edgeflag_index
].instance_divisor
> 0;
3467 vi
.InstanceDataStepRate
= state
[edgeflag_index
].instance_divisor
;
3475 * The pipe->bind_vertex_elements_state() driver hook.
3478 iris_bind_vertex_elements_state(struct pipe_context
*ctx
, void *state
)
3480 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3481 struct iris_vertex_element_state
*old_cso
= ice
->state
.cso_vertex_elements
;
3482 struct iris_vertex_element_state
*new_cso
= state
;
3484 /* 3DSTATE_VF_SGVs overrides the last VE, so if the count is changing,
3485 * we need to re-emit it to ensure we're overriding the right one.
3487 if (new_cso
&& cso_changed(count
))
3488 ice
->state
.dirty
|= IRIS_DIRTY_VF_SGVS
;
3490 ice
->state
.cso_vertex_elements
= state
;
3491 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_ELEMENTS
;
3495 * The pipe->create_stream_output_target() driver hook.
3497 * "Target" here refers to a destination buffer. We translate this into
3498 * a 3DSTATE_SO_BUFFER packet. We can handle most fields, but don't yet
3499 * know which buffer this represents, or whether we ought to zero the
3500 * write-offsets, or append. Those are handled in the set() hook.
3502 static struct pipe_stream_output_target
*
3503 iris_create_stream_output_target(struct pipe_context
*ctx
,
3504 struct pipe_resource
*p_res
,
3505 unsigned buffer_offset
,
3506 unsigned buffer_size
)
3508 struct iris_resource
*res
= (void *) p_res
;
3509 struct iris_stream_output_target
*cso
= calloc(1, sizeof(*cso
));
3513 res
->bind_history
|= PIPE_BIND_STREAM_OUTPUT
;
3515 pipe_reference_init(&cso
->base
.reference
, 1);
3516 pipe_resource_reference(&cso
->base
.buffer
, p_res
);
3517 cso
->base
.buffer_offset
= buffer_offset
;
3518 cso
->base
.buffer_size
= buffer_size
;
3519 cso
->base
.context
= ctx
;
3521 util_range_add(&res
->base
, &res
->valid_buffer_range
, buffer_offset
,
3522 buffer_offset
+ buffer_size
);
3524 upload_state(ctx
->stream_uploader
, &cso
->offset
, sizeof(uint32_t), 4);
3530 iris_stream_output_target_destroy(struct pipe_context
*ctx
,
3531 struct pipe_stream_output_target
*state
)
3533 struct iris_stream_output_target
*cso
= (void *) state
;
3535 pipe_resource_reference(&cso
->base
.buffer
, NULL
);
3536 pipe_resource_reference(&cso
->offset
.res
, NULL
);
3542 * The pipe->set_stream_output_targets() driver hook.
3544 * At this point, we know which targets are bound to a particular index,
3545 * and also whether we want to append or start over. We can finish the
3546 * 3DSTATE_SO_BUFFER packets we started earlier.
3549 iris_set_stream_output_targets(struct pipe_context
*ctx
,
3550 unsigned num_targets
,
3551 struct pipe_stream_output_target
**targets
,
3552 const unsigned *offsets
)
3554 struct iris_context
*ice
= (struct iris_context
*) ctx
;
3555 struct iris_genx_state
*genx
= ice
->state
.genx
;
3556 uint32_t *so_buffers
= genx
->so_buffers
;
3557 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3559 const bool active
= num_targets
> 0;
3560 if (ice
->state
.streamout_active
!= active
) {
3561 ice
->state
.streamout_active
= active
;
3562 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
3564 /* We only emit 3DSTATE_SO_DECL_LIST when streamout is active, because
3565 * it's a non-pipelined command. If we're switching streamout on, we
3566 * may have missed emitting it earlier, so do so now. (We're already
3567 * taking a stall to update 3DSTATE_SO_BUFFERS anyway...)
3570 ice
->state
.dirty
|= IRIS_DIRTY_SO_DECL_LIST
;
3573 for (int i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
3574 struct iris_stream_output_target
*tgt
=
3575 (void *) ice
->state
.so_target
[i
];
3577 struct iris_resource
*res
= (void *) tgt
->base
.buffer
;
3579 flush
|= iris_flush_bits_for_history(res
);
3580 iris_dirty_for_history(ice
, res
);
3583 iris_emit_pipe_control_flush(&ice
->batches
[IRIS_BATCH_RENDER
],
3584 "make streamout results visible", flush
);
3588 for (int i
= 0; i
< 4; i
++) {
3589 pipe_so_target_reference(&ice
->state
.so_target
[i
],
3590 i
< num_targets
? targets
[i
] : NULL
);
3593 /* No need to update 3DSTATE_SO_BUFFER unless SOL is active. */
3597 for (unsigned i
= 0; i
< 4; i
++,
3598 so_buffers
+= GENX(3DSTATE_SO_BUFFER_length
)) {
3600 struct iris_stream_output_target
*tgt
= (void *) ice
->state
.so_target
[i
];
3601 unsigned offset
= offsets
[i
];
3604 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
) {
3606 sob
.SOBufferIndex
= i
;
3608 sob
._3DCommandOpcode
= 0;
3609 sob
._3DCommandSubOpcode
= SO_BUFFER_INDEX_0_CMD
+ i
;
3615 struct iris_resource
*res
= (void *) tgt
->base
.buffer
;
3617 /* Note that offsets[i] will either be 0, causing us to zero
3618 * the value in the buffer, or 0xFFFFFFFF, which happens to mean
3619 * "continue appending at the existing offset."
3621 assert(offset
== 0 || offset
== 0xFFFFFFFF);
3623 /* We might be called by Begin (offset = 0), Pause, then Resume
3624 * (offset = 0xFFFFFFFF) before ever drawing (where these commands
3625 * will actually be sent to the GPU). In this case, we don't want
3626 * to append - we still want to do our initial zeroing.
3631 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
) {
3633 sob
.SOBufferIndex
= i
;
3635 sob
._3DCommandOpcode
= 0;
3636 sob
._3DCommandSubOpcode
= SO_BUFFER_INDEX_0_CMD
+ i
;
3638 sob
.SurfaceBaseAddress
=
3639 rw_bo(NULL
, res
->bo
->gtt_offset
+ tgt
->base
.buffer_offset
);
3640 sob
.SOBufferEnable
= true;
3641 sob
.StreamOffsetWriteEnable
= true;
3642 sob
.StreamOutputBufferOffsetAddressEnable
= true;
3643 sob
.MOCS
= iris_mocs(res
->bo
, &screen
->isl_dev
);
3645 sob
.SurfaceSize
= MAX2(tgt
->base
.buffer_size
/ 4, 1) - 1;
3646 sob
.StreamOffset
= offset
;
3647 sob
.StreamOutputBufferOffsetAddress
=
3648 rw_bo(NULL
, iris_resource_bo(tgt
->offset
.res
)->gtt_offset
+
3649 tgt
->offset
.offset
);
3653 ice
->state
.dirty
|= IRIS_DIRTY_SO_BUFFERS
;
3657 * An iris-vtable helper for encoding the 3DSTATE_SO_DECL_LIST and
3658 * 3DSTATE_STREAMOUT packets.
3660 * 3DSTATE_SO_DECL_LIST is a list of shader outputs we want the streamout
3661 * hardware to record. We can create it entirely based on the shader, with
3662 * no dynamic state dependencies.
3664 * 3DSTATE_STREAMOUT is an annoying mix of shader-based information and
3665 * state-based settings. We capture the shader-related ones here, and merge
3666 * the rest in at draw time.
3669 iris_create_so_decl_list(const struct pipe_stream_output_info
*info
,
3670 const struct brw_vue_map
*vue_map
)
3672 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
3673 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3674 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3675 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3677 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
3679 memset(so_decl
, 0, sizeof(so_decl
));
3681 /* Construct the list of SO_DECLs to be emitted. The formatting of the
3682 * command feels strange -- each dword pair contains a SO_DECL per stream.
3684 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
3685 const struct pipe_stream_output
*output
= &info
->output
[i
];
3686 const int buffer
= output
->output_buffer
;
3687 const int varying
= output
->register_index
;
3688 const unsigned stream_id
= output
->stream
;
3689 assert(stream_id
< MAX_VERTEX_STREAMS
);
3691 buffer_mask
[stream_id
] |= 1 << buffer
;
3693 assert(vue_map
->varying_to_slot
[varying
] >= 0);
3695 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
3696 * array. Instead, it simply increments DstOffset for the following
3697 * input by the number of components that should be skipped.
3699 * Our hardware is unusual in that it requires us to program SO_DECLs
3700 * for fake "hole" components, rather than simply taking the offset
3701 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
3702 * program as many size = 4 holes as we can, then a final hole to
3703 * accommodate the final 1, 2, or 3 remaining.
3705 int skip_components
= output
->dst_offset
- next_offset
[buffer
];
3707 while (skip_components
> 0) {
3708 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3710 .OutputBufferSlot
= output
->output_buffer
,
3711 .ComponentMask
= (1 << MIN2(skip_components
, 4)) - 1,
3713 skip_components
-= 4;
3716 next_offset
[buffer
] = output
->dst_offset
+ output
->num_components
;
3718 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3719 .OutputBufferSlot
= output
->output_buffer
,
3720 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
3722 ((1 << output
->num_components
) - 1) << output
->start_component
,
3725 if (decls
[stream_id
] > max_decls
)
3726 max_decls
= decls
[stream_id
];
3729 unsigned dwords
= GENX(3DSTATE_STREAMOUT_length
) + (3 + 2 * max_decls
);
3730 uint32_t *map
= ralloc_size(NULL
, sizeof(uint32_t) * dwords
);
3731 uint32_t *so_decl_map
= map
+ GENX(3DSTATE_STREAMOUT_length
);
3733 iris_pack_command(GENX(3DSTATE_STREAMOUT
), map
, sol
) {
3734 int urb_entry_read_offset
= 0;
3735 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
3736 urb_entry_read_offset
;
3738 /* We always read the whole vertex. This could be reduced at some
3739 * point by reading less and offsetting the register index in the
3742 sol
.Stream0VertexReadOffset
= urb_entry_read_offset
;
3743 sol
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
3744 sol
.Stream1VertexReadOffset
= urb_entry_read_offset
;
3745 sol
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
3746 sol
.Stream2VertexReadOffset
= urb_entry_read_offset
;
3747 sol
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
3748 sol
.Stream3VertexReadOffset
= urb_entry_read_offset
;
3749 sol
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
3751 /* Set buffer pitches; 0 means unbound. */
3752 sol
.Buffer0SurfacePitch
= 4 * info
->stride
[0];
3753 sol
.Buffer1SurfacePitch
= 4 * info
->stride
[1];
3754 sol
.Buffer2SurfacePitch
= 4 * info
->stride
[2];
3755 sol
.Buffer3SurfacePitch
= 4 * info
->stride
[3];
3758 iris_pack_command(GENX(3DSTATE_SO_DECL_LIST
), so_decl_map
, list
) {
3759 list
.DWordLength
= 3 + 2 * max_decls
- 2;
3760 list
.StreamtoBufferSelects0
= buffer_mask
[0];
3761 list
.StreamtoBufferSelects1
= buffer_mask
[1];
3762 list
.StreamtoBufferSelects2
= buffer_mask
[2];
3763 list
.StreamtoBufferSelects3
= buffer_mask
[3];
3764 list
.NumEntries0
= decls
[0];
3765 list
.NumEntries1
= decls
[1];
3766 list
.NumEntries2
= decls
[2];
3767 list
.NumEntries3
= decls
[3];
3770 for (int i
= 0; i
< max_decls
; i
++) {
3771 iris_pack_state(GENX(SO_DECL_ENTRY
), so_decl_map
+ 3 + i
* 2, entry
) {
3772 entry
.Stream0Decl
= so_decl
[0][i
];
3773 entry
.Stream1Decl
= so_decl
[1][i
];
3774 entry
.Stream2Decl
= so_decl
[2][i
];
3775 entry
.Stream3Decl
= so_decl
[3][i
];
3783 iris_compute_sbe_urb_read_interval(uint64_t fs_input_slots
,
3784 const struct brw_vue_map
*last_vue_map
,
3785 bool two_sided_color
,
3786 unsigned *out_offset
,
3787 unsigned *out_length
)
3789 /* The compiler computes the first URB slot without considering COL/BFC
3790 * swizzling (because it doesn't know whether it's enabled), so we need
3791 * to do that here too. This may result in a smaller offset, which
3794 const unsigned first_slot
=
3795 brw_compute_first_urb_slot_required(fs_input_slots
, last_vue_map
);
3797 /* This becomes the URB read offset (counted in pairs of slots). */
3798 assert(first_slot
% 2 == 0);
3799 *out_offset
= first_slot
/ 2;
3801 /* We need to adjust the inputs read to account for front/back color
3802 * swizzling, as it can make the URB length longer.
3804 for (int c
= 0; c
<= 1; c
++) {
3805 if (fs_input_slots
& (VARYING_BIT_COL0
<< c
)) {
3806 /* If two sided color is enabled, the fragment shader's gl_Color
3807 * (COL0) input comes from either the gl_FrontColor (COL0) or
3808 * gl_BackColor (BFC0) input varyings. Mark BFC as used, too.
3810 if (two_sided_color
)
3811 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3813 /* If front color isn't written, we opt to give them back color
3814 * instead of an undefined value. Switch from COL to BFC.
3816 if (last_vue_map
->varying_to_slot
[VARYING_SLOT_COL0
+ c
] == -1) {
3817 fs_input_slots
&= ~(VARYING_BIT_COL0
<< c
);
3818 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3823 /* Compute the minimum URB Read Length necessary for the FS inputs.
3825 * From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
3826 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
3828 * "This field should be set to the minimum length required to read the
3829 * maximum source attribute. The maximum source attribute is indicated
3830 * by the maximum value of the enabled Attribute # Source Attribute if
3831 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
3832 * enable is not set.
3833 * read_length = ceiling((max_source_attr + 1) / 2)
3835 * [errata] Corruption/Hang possible if length programmed larger than
3838 * Similar text exists for Ivy Bridge.
3840 * We find the last URB slot that's actually read by the FS.
3842 unsigned last_read_slot
= last_vue_map
->num_slots
- 1;
3843 while (last_read_slot
> first_slot
&& !(fs_input_slots
&
3844 (1ull << last_vue_map
->slot_to_varying
[last_read_slot
])))
3847 /* The URB read length is the difference of the two, counted in pairs. */
3848 *out_length
= DIV_ROUND_UP(last_read_slot
- first_slot
+ 1, 2);
3852 iris_emit_sbe_swiz(struct iris_batch
*batch
,
3853 const struct iris_context
*ice
,
3854 unsigned urb_read_offset
,
3855 unsigned sprite_coord_enables
)
3857 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = {};
3858 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3859 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3860 const struct brw_vue_map
*vue_map
= ice
->shaders
.last_vue_map
;
3861 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3863 /* XXX: this should be generated when putting programs in place */
3865 for (uint8_t idx
= 0; idx
< wm_prog_data
->urb_setup_attribs_count
; idx
++) {
3866 const uint8_t fs_attr
= wm_prog_data
->urb_setup_attribs
[idx
];
3867 const int input_index
= wm_prog_data
->urb_setup
[fs_attr
];
3868 if (input_index
< 0 || input_index
>= 16)
3871 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
=
3872 &attr_overrides
[input_index
];
3873 int slot
= vue_map
->varying_to_slot
[fs_attr
];
3875 /* Viewport and Layer are stored in the VUE header. We need to override
3876 * them to zero if earlier stages didn't write them, as GL requires that
3877 * they read back as zero when not explicitly set.
3880 case VARYING_SLOT_VIEWPORT
:
3881 case VARYING_SLOT_LAYER
:
3882 attr
->ComponentOverrideX
= true;
3883 attr
->ComponentOverrideW
= true;
3884 attr
->ConstantSource
= CONST_0000
;
3886 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
3887 attr
->ComponentOverrideY
= true;
3888 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
3889 attr
->ComponentOverrideZ
= true;
3892 case VARYING_SLOT_PRIMITIVE_ID
:
3893 /* Override if the previous shader stage didn't write gl_PrimitiveID. */
3895 attr
->ComponentOverrideX
= true;
3896 attr
->ComponentOverrideY
= true;
3897 attr
->ComponentOverrideZ
= true;
3898 attr
->ComponentOverrideW
= true;
3899 attr
->ConstantSource
= PRIM_ID
;
3907 if (sprite_coord_enables
& (1 << input_index
))
3910 /* If there was only a back color written but not front, use back
3911 * as the color instead of undefined.
3913 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
3914 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
3915 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
3916 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
3918 /* Not written by the previous stage - undefined. */
3920 attr
->ComponentOverrideX
= true;
3921 attr
->ComponentOverrideY
= true;
3922 attr
->ComponentOverrideZ
= true;
3923 attr
->ComponentOverrideW
= true;
3924 attr
->ConstantSource
= CONST_0001_FLOAT
;
3928 /* Compute the location of the attribute relative to the read offset,
3929 * which is counted in 256-bit increments (two 128-bit VUE slots).
3931 const int source_attr
= slot
- 2 * urb_read_offset
;
3932 assert(source_attr
>= 0 && source_attr
<= 32);
3933 attr
->SourceAttribute
= source_attr
;
3935 /* If we are doing two-sided color, and the VUE slot following this one
3936 * represents a back-facing color, then we need to instruct the SF unit
3937 * to do back-facing swizzling.
3939 if (cso_rast
->light_twoside
&&
3940 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
3941 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
3942 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
3943 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
)))
3944 attr
->SwizzleSelect
= INPUTATTR_FACING
;
3947 iris_emit_cmd(batch
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
3948 for (int i
= 0; i
< 16; i
++)
3949 sbes
.Attribute
[i
] = attr_overrides
[i
];
3954 iris_calculate_point_sprite_overrides(const struct brw_wm_prog_data
*prog_data
,
3955 const struct iris_rasterizer_state
*cso
)
3957 unsigned overrides
= 0;
3959 if (prog_data
->urb_setup
[VARYING_SLOT_PNTC
] != -1)
3960 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_PNTC
];
3962 for (int i
= 0; i
< 8; i
++) {
3963 if ((cso
->sprite_coord_enable
& (1 << i
)) &&
3964 prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
] != -1)
3965 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
];
3972 iris_emit_sbe(struct iris_batch
*batch
, const struct iris_context
*ice
)
3974 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3975 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3976 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3977 const struct shader_info
*fs_info
=
3978 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
3980 unsigned urb_read_offset
, urb_read_length
;
3981 iris_compute_sbe_urb_read_interval(fs_info
->inputs_read
,
3982 ice
->shaders
.last_vue_map
,
3983 cso_rast
->light_twoside
,
3984 &urb_read_offset
, &urb_read_length
);
3986 unsigned sprite_coord_overrides
=
3987 iris_calculate_point_sprite_overrides(wm_prog_data
, cso_rast
);
3989 iris_emit_cmd(batch
, GENX(3DSTATE_SBE
), sbe
) {
3990 sbe
.AttributeSwizzleEnable
= true;
3991 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
3992 sbe
.PointSpriteTextureCoordinateOrigin
= cso_rast
->sprite_coord_mode
;
3993 sbe
.VertexURBEntryReadOffset
= urb_read_offset
;
3994 sbe
.VertexURBEntryReadLength
= urb_read_length
;
3995 sbe
.ForceVertexURBEntryReadOffset
= true;
3996 sbe
.ForceVertexURBEntryReadLength
= true;
3997 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
3998 sbe
.PointSpriteTextureCoordinateEnable
= sprite_coord_overrides
;
4000 for (int i
= 0; i
< 32; i
++) {
4001 sbe
.AttributeActiveComponentFormat
[i
] = ACTIVE_COMPONENT_XYZW
;
4006 iris_emit_sbe_swiz(batch
, ice
, urb_read_offset
, sprite_coord_overrides
);
4009 /* ------------------------------------------------------------------- */
4012 * Populate VS program key fields based on the current state.
4015 iris_populate_vs_key(const struct iris_context
*ice
,
4016 const struct shader_info
*info
,
4017 gl_shader_stage last_stage
,
4018 struct iris_vs_prog_key
*key
)
4020 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4022 if (info
->clip_distance_array_size
== 0 &&
4023 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
4024 last_stage
== MESA_SHADER_VERTEX
)
4025 key
->vue
.nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
4029 * Populate TCS program key fields based on the current state.
4032 iris_populate_tcs_key(const struct iris_context
*ice
,
4033 struct iris_tcs_prog_key
*key
)
4038 * Populate TES program key fields based on the current state.
4041 iris_populate_tes_key(const struct iris_context
*ice
,
4042 const struct shader_info
*info
,
4043 gl_shader_stage last_stage
,
4044 struct iris_tes_prog_key
*key
)
4046 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4048 if (info
->clip_distance_array_size
== 0 &&
4049 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
4050 last_stage
== MESA_SHADER_TESS_EVAL
)
4051 key
->vue
.nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
4055 * Populate GS program key fields based on the current state.
4058 iris_populate_gs_key(const struct iris_context
*ice
,
4059 const struct shader_info
*info
,
4060 gl_shader_stage last_stage
,
4061 struct iris_gs_prog_key
*key
)
4063 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4065 if (info
->clip_distance_array_size
== 0 &&
4066 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)) &&
4067 last_stage
== MESA_SHADER_GEOMETRY
)
4068 key
->vue
.nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
4072 * Populate FS program key fields based on the current state.
4075 iris_populate_fs_key(const struct iris_context
*ice
,
4076 const struct shader_info
*info
,
4077 struct iris_fs_prog_key
*key
)
4079 struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
4080 const struct pipe_framebuffer_state
*fb
= &ice
->state
.framebuffer
;
4081 const struct iris_depth_stencil_alpha_state
*zsa
= ice
->state
.cso_zsa
;
4082 const struct iris_rasterizer_state
*rast
= ice
->state
.cso_rast
;
4083 const struct iris_blend_state
*blend
= ice
->state
.cso_blend
;
4085 key
->nr_color_regions
= fb
->nr_cbufs
;
4087 key
->clamp_fragment_color
= rast
->clamp_fragment_color
;
4089 key
->alpha_to_coverage
= blend
->alpha_to_coverage
;
4091 key
->alpha_test_replicate_alpha
= fb
->nr_cbufs
> 1 && zsa
->alpha
.enabled
;
4093 key
->flat_shade
= rast
->flatshade
&&
4094 (info
->inputs_read
& (VARYING_BIT_COL0
| VARYING_BIT_COL1
));
4096 key
->persample_interp
= rast
->force_persample_interp
;
4097 key
->multisample_fbo
= rast
->multisample
&& fb
->samples
> 1;
4099 key
->coherent_fb_fetch
= GEN_GEN
>= 9;
4101 key
->force_dual_color_blend
=
4102 screen
->driconf
.dual_color_blend_by_location
&&
4103 (blend
->blend_enables
& 1) && blend
->dual_color_blending
;
4105 /* TODO: Respect glHint for key->high_quality_derivatives */
4109 iris_populate_cs_key(const struct iris_context
*ice
,
4110 struct iris_cs_prog_key
*key
)
4115 KSP(const struct iris_compiled_shader
*shader
)
4117 struct iris_resource
*res
= (void *) shader
->assembly
.res
;
4118 return iris_bo_offset_from_base_address(res
->bo
) + shader
->assembly
.offset
;
4121 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix, stage) \
4122 pkt.KernelStartPointer = KSP(shader); \
4123 pkt.BindingTableEntryCount = shader->bt.size_bytes / 4; \
4124 pkt.FloatingPointMode = prog_data->use_alt_mode; \
4126 pkt.DispatchGRFStartRegisterForURBData = \
4127 prog_data->dispatch_grf_start_reg; \
4128 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
4129 pkt.prefix##URBEntryReadOffset = 0; \
4131 pkt.StatisticsEnable = true; \
4132 pkt.Enable = true; \
4134 if (prog_data->total_scratch) { \
4135 struct iris_bo *bo = \
4136 iris_get_scratch_space(ice, prog_data->total_scratch, stage); \
4137 uint32_t scratch_addr = bo->gtt_offset; \
4138 pkt.PerThreadScratchSpace = ffs(prog_data->total_scratch) - 11; \
4139 pkt.ScratchSpaceBasePointer = rw_bo(NULL, scratch_addr); \
4143 * Encode most of 3DSTATE_VS based on the compiled shader.
4146 iris_store_vs_state(struct iris_context
*ice
,
4147 const struct gen_device_info
*devinfo
,
4148 struct iris_compiled_shader
*shader
)
4150 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4151 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4153 iris_pack_command(GENX(3DSTATE_VS
), shader
->derived_data
, vs
) {
4154 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
, MESA_SHADER_VERTEX
);
4155 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
4156 vs
.SIMD8DispatchEnable
= true;
4157 vs
.UserClipDistanceCullTestEnableBitmask
=
4158 vue_prog_data
->cull_distance_mask
;
4163 * Encode most of 3DSTATE_HS based on the compiled shader.
4166 iris_store_tcs_state(struct iris_context
*ice
,
4167 const struct gen_device_info
*devinfo
,
4168 struct iris_compiled_shader
*shader
)
4170 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4171 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4172 struct brw_tcs_prog_data
*tcs_prog_data
= (void *) prog_data
;
4174 iris_pack_command(GENX(3DSTATE_HS
), shader
->derived_data
, hs
) {
4175 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
, MESA_SHADER_TESS_CTRL
);
4178 /* GEN:BUG:1604578095:
4180 * Hang occurs when the number of max threads is less than 2 times
4181 * the number of instance count. The number of max threads must be
4182 * more than 2 times the number of instance count.
4184 assert((devinfo
->max_tcs_threads
/ 2) > tcs_prog_data
->instances
);
4185 hs
.DispatchGRFStartRegisterForURBData
= prog_data
->dispatch_grf_start_reg
& 0x1f;
4186 hs
.DispatchGRFStartRegisterForURBData5
= prog_data
->dispatch_grf_start_reg
>> 5;
4189 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
4190 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
4191 hs
.IncludeVertexHandles
= true;
4194 /* Patch Count threshold specifies the maximum number of patches that
4195 * will be accumulated before a thread dispatch is forced.
4197 hs
.PatchCountThreshold
= tcs_prog_data
->patch_count_threshold
;
4201 hs
.DispatchMode
= vue_prog_data
->dispatch_mode
;
4202 hs
.IncludePrimitiveID
= tcs_prog_data
->include_primitive_id
;
4208 * Encode 3DSTATE_TE and most of 3DSTATE_DS based on the compiled shader.
4211 iris_store_tes_state(struct iris_context
*ice
,
4212 const struct gen_device_info
*devinfo
,
4213 struct iris_compiled_shader
*shader
)
4215 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4216 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4217 struct brw_tes_prog_data
*tes_prog_data
= (void *) prog_data
;
4219 uint32_t *te_state
= (void *) shader
->derived_data
;
4220 uint32_t *ds_state
= te_state
+ GENX(3DSTATE_TE_length
);
4222 iris_pack_command(GENX(3DSTATE_TE
), te_state
, te
) {
4223 te
.Partitioning
= tes_prog_data
->partitioning
;
4224 te
.OutputTopology
= tes_prog_data
->output_topology
;
4225 te
.TEDomain
= tes_prog_data
->domain
;
4227 te
.MaximumTessellationFactorOdd
= 63.0;
4228 te
.MaximumTessellationFactorNotOdd
= 64.0;
4231 iris_pack_command(GENX(3DSTATE_DS
), ds_state
, ds
) {
4232 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
, MESA_SHADER_TESS_EVAL
);
4234 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
4235 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
4236 ds
.ComputeWCoordinateEnable
=
4237 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
4239 ds
.UserClipDistanceCullTestEnableBitmask
=
4240 vue_prog_data
->cull_distance_mask
;
4246 * Encode most of 3DSTATE_GS based on the compiled shader.
4249 iris_store_gs_state(struct iris_context
*ice
,
4250 const struct gen_device_info
*devinfo
,
4251 struct iris_compiled_shader
*shader
)
4253 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4254 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
4255 struct brw_gs_prog_data
*gs_prog_data
= (void *) prog_data
;
4257 iris_pack_command(GENX(3DSTATE_GS
), shader
->derived_data
, gs
) {
4258 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
, MESA_SHADER_GEOMETRY
);
4260 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
4261 gs
.OutputTopology
= gs_prog_data
->output_topology
;
4262 gs
.ControlDataHeaderSize
=
4263 gs_prog_data
->control_data_header_size_hwords
;
4264 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
4265 gs
.DispatchMode
= DISPATCH_MODE_SIMD8
;
4266 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
4267 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
4268 gs
.ReorderMode
= TRAILING
;
4269 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
4270 gs
.MaximumNumberofThreads
=
4271 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
4272 : (devinfo
->max_gs_threads
- 1);
4274 if (gs_prog_data
->static_vertex_count
!= -1) {
4275 gs
.StaticOutput
= true;
4276 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
4278 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
4280 gs
.UserClipDistanceCullTestEnableBitmask
=
4281 vue_prog_data
->cull_distance_mask
;
4283 const int urb_entry_write_offset
= 1;
4284 const uint32_t urb_entry_output_length
=
4285 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
4286 urb_entry_write_offset
;
4288 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
4289 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
4294 * Encode most of 3DSTATE_PS and 3DSTATE_PS_EXTRA based on the shader.
4297 iris_store_fs_state(struct iris_context
*ice
,
4298 const struct gen_device_info
*devinfo
,
4299 struct iris_compiled_shader
*shader
)
4301 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4302 struct brw_wm_prog_data
*wm_prog_data
= (void *) shader
->prog_data
;
4304 uint32_t *ps_state
= (void *) shader
->derived_data
;
4305 uint32_t *psx_state
= ps_state
+ GENX(3DSTATE_PS_length
);
4307 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
4308 ps
.VectorMaskEnable
= true;
4309 ps
.BindingTableEntryCount
= shader
->bt
.size_bytes
/ 4;
4310 ps
.FloatingPointMode
= prog_data
->use_alt_mode
;
4311 ps
.MaximumNumberofThreadsPerPSD
= 64 - (GEN_GEN
== 8 ? 2 : 1);
4313 ps
.PushConstantEnable
= prog_data
->ubo_ranges
[0].length
> 0;
4315 /* From the documentation for this packet:
4316 * "If the PS kernel does not need the Position XY Offsets to
4317 * compute a Position Value, then this field should be programmed
4318 * to POSOFFSET_NONE."
4320 * "SW Recommendation: If the PS kernel needs the Position Offsets
4321 * to compute a Position XY value, this field should match Position
4322 * ZW Interpolation Mode to ensure a consistent position.xyzw
4325 * We only require XY sample offsets. So, this recommendation doesn't
4326 * look useful at the moment. We might need this in future.
4328 ps
.PositionXYOffsetSelect
=
4329 wm_prog_data
->uses_pos_offset
? POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
4331 if (prog_data
->total_scratch
) {
4332 struct iris_bo
*bo
=
4333 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
4334 MESA_SHADER_FRAGMENT
);
4335 uint32_t scratch_addr
= bo
->gtt_offset
;
4336 ps
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
4337 ps
.ScratchSpaceBasePointer
= rw_bo(NULL
, scratch_addr
);
4341 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
4342 psx
.PixelShaderValid
= true;
4343 psx
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
4344 psx
.PixelShaderKillsPixel
= wm_prog_data
->uses_kill
;
4345 psx
.AttributeEnable
= wm_prog_data
->num_varying_inputs
!= 0;
4346 psx
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
4347 psx
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
4348 psx
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
4349 psx
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
4352 psx
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
4353 psx
.PixelShaderComputesStencil
= wm_prog_data
->computed_stencil
;
4359 * Compute the size of the derived data (shader command packets).
4361 * This must match the data written by the iris_store_xs_state() functions.
4364 iris_store_cs_state(struct iris_context
*ice
,
4365 const struct gen_device_info
*devinfo
,
4366 struct iris_compiled_shader
*shader
)
4368 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4369 struct brw_cs_prog_data
*cs_prog_data
= (void *) shader
->prog_data
;
4370 void *map
= shader
->derived_data
;
4372 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), map
, desc
) {
4373 desc
.KernelStartPointer
= KSP(shader
);
4374 desc
.ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
;
4375 desc
.SharedLocalMemorySize
=
4376 encode_slm_size(GEN_GEN
, prog_data
->total_shared
);
4377 desc
.BarrierEnable
= cs_prog_data
->uses_barrier
;
4378 desc
.CrossThreadConstantDataReadLength
=
4379 cs_prog_data
->push
.cross_thread
.regs
;
4381 /* TODO: Check if we are missing workarounds and enable mid-thread
4384 * We still have issues with mid-thread preemption (it was already
4385 * disabled by the kernel on gen11, due to missing workarounds). It's
4386 * possible that we are just missing some workarounds, and could enable
4387 * it later, but for now let's disable it to fix a GPU in compute in Car
4388 * Chase (and possibly more).
4390 desc
.ThreadPreemptionDisable
= true;
4396 iris_derived_program_state_size(enum iris_program_cache_id cache_id
)
4398 assert(cache_id
<= IRIS_CACHE_BLORP
);
4400 static const unsigned dwords
[] = {
4401 [IRIS_CACHE_VS
] = GENX(3DSTATE_VS_length
),
4402 [IRIS_CACHE_TCS
] = GENX(3DSTATE_HS_length
),
4403 [IRIS_CACHE_TES
] = GENX(3DSTATE_TE_length
) + GENX(3DSTATE_DS_length
),
4404 [IRIS_CACHE_GS
] = GENX(3DSTATE_GS_length
),
4406 GENX(3DSTATE_PS_length
) + GENX(3DSTATE_PS_EXTRA_length
),
4407 [IRIS_CACHE_CS
] = GENX(INTERFACE_DESCRIPTOR_DATA_length
),
4408 [IRIS_CACHE_BLORP
] = 0,
4411 return sizeof(uint32_t) * dwords
[cache_id
];
4415 * Create any state packets corresponding to the given shader stage
4416 * (i.e. 3DSTATE_VS) and save them as "derived data" in the shader variant.
4417 * This means that we can look up a program in the in-memory cache and
4418 * get most of the state packet without having to reconstruct it.
4421 iris_store_derived_program_state(struct iris_context
*ice
,
4422 enum iris_program_cache_id cache_id
,
4423 struct iris_compiled_shader
*shader
)
4425 struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
4426 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
4430 iris_store_vs_state(ice
, devinfo
, shader
);
4432 case IRIS_CACHE_TCS
:
4433 iris_store_tcs_state(ice
, devinfo
, shader
);
4435 case IRIS_CACHE_TES
:
4436 iris_store_tes_state(ice
, devinfo
, shader
);
4439 iris_store_gs_state(ice
, devinfo
, shader
);
4442 iris_store_fs_state(ice
, devinfo
, shader
);
4445 iris_store_cs_state(ice
, devinfo
, shader
);
4446 case IRIS_CACHE_BLORP
:
4453 /* ------------------------------------------------------------------- */
4455 static const uint32_t push_constant_opcodes
[] = {
4456 [MESA_SHADER_VERTEX
] = 21,
4457 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
4458 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
4459 [MESA_SHADER_GEOMETRY
] = 22,
4460 [MESA_SHADER_FRAGMENT
] = 23,
4461 [MESA_SHADER_COMPUTE
] = 0,
4465 use_null_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
4467 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.unbound_tex
.res
);
4469 iris_use_pinned_bo(batch
, state_bo
, false);
4471 return ice
->state
.unbound_tex
.offset
;
4475 use_null_fb_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
4477 /* If set_framebuffer_state() was never called, fall back to 1x1x1 */
4478 if (!ice
->state
.null_fb
.res
)
4479 return use_null_surface(batch
, ice
);
4481 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.null_fb
.res
);
4483 iris_use_pinned_bo(batch
, state_bo
, false);
4485 return ice
->state
.null_fb
.offset
;
4489 surf_state_offset_for_aux(struct iris_resource
*res
,
4491 enum isl_aux_usage aux_usage
)
4493 return SURFACE_STATE_ALIGNMENT
*
4494 util_bitcount(aux_modes
& ((1 << aux_usage
) - 1));
4499 surf_state_update_clear_value(struct iris_batch
*batch
,
4500 struct iris_resource
*res
,
4501 struct iris_state_ref
*state
,
4503 enum isl_aux_usage aux_usage
)
4505 struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
4506 struct iris_bo
*state_bo
= iris_resource_bo(state
->res
);
4507 uint64_t real_offset
= state
->offset
+ IRIS_MEMZONE_BINDER_START
;
4508 uint32_t offset_into_bo
= real_offset
- state_bo
->gtt_offset
;
4509 uint32_t clear_offset
= offset_into_bo
+
4510 isl_dev
->ss
.clear_value_offset
+
4511 surf_state_offset_for_aux(res
, aux_modes
, aux_usage
);
4512 uint32_t *color
= res
->aux
.clear_color
.u32
;
4514 assert(isl_dev
->ss
.clear_value_size
== 16);
4516 if (aux_usage
== ISL_AUX_USAGE_HIZ
) {
4517 iris_emit_pipe_control_write(batch
, "update fast clear value (Z)",
4518 PIPE_CONTROL_WRITE_IMMEDIATE
,
4519 state_bo
, clear_offset
, color
[0]);
4521 iris_emit_pipe_control_write(batch
, "update fast clear color (RG__)",
4522 PIPE_CONTROL_WRITE_IMMEDIATE
,
4523 state_bo
, clear_offset
,
4524 (uint64_t) color
[0] |
4525 (uint64_t) color
[1] << 32);
4526 iris_emit_pipe_control_write(batch
, "update fast clear color (__BA)",
4527 PIPE_CONTROL_WRITE_IMMEDIATE
,
4528 state_bo
, clear_offset
+ 8,
4529 (uint64_t) color
[2] |
4530 (uint64_t) color
[3] << 32);
4533 iris_emit_pipe_control_flush(batch
,
4534 "update fast clear: state cache invalidate",
4535 PIPE_CONTROL_FLUSH_ENABLE
|
4536 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
4541 update_clear_value(struct iris_context
*ice
,
4542 struct iris_batch
*batch
,
4543 struct iris_resource
*res
,
4544 struct iris_surface_state
*surf_state
,
4545 unsigned all_aux_modes
,
4546 struct isl_view
*view
)
4548 UNUSED
struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
4549 UNUSED
unsigned aux_modes
= all_aux_modes
;
4551 /* We only need to update the clear color in the surface state for gen8 and
4552 * gen9. Newer gens can read it directly from the clear color state buffer.
4555 /* Skip updating the ISL_AUX_USAGE_NONE surface state */
4556 aux_modes
&= ~(1 << ISL_AUX_USAGE_NONE
);
4559 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
4561 surf_state_update_clear_value(batch
, res
, &surf_state
->ref
,
4562 all_aux_modes
, aux_usage
);
4565 /* TODO: Could update rather than re-filling */
4566 alloc_surface_states(surf_state
, all_aux_modes
);
4568 void *map
= surf_state
->cpu
;
4571 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
4572 fill_surface_state(isl_dev
, map
, res
, &res
->surf
, view
, aux_usage
,
4574 map
+= SURFACE_STATE_ALIGNMENT
;
4577 upload_surface_states(ice
->state
.surface_uploader
, surf_state
);
4582 * Add a surface to the validation list, as well as the buffer containing
4583 * the corresponding SURFACE_STATE.
4585 * Returns the binding table entry (offset to SURFACE_STATE).
4588 use_surface(struct iris_context
*ice
,
4589 struct iris_batch
*batch
,
4590 struct pipe_surface
*p_surf
,
4592 enum isl_aux_usage aux_usage
,
4593 bool is_read_surface
)
4595 struct iris_surface
*surf
= (void *) p_surf
;
4596 struct iris_resource
*res
= (void *) p_surf
->texture
;
4597 uint32_t offset
= 0;
4599 iris_use_pinned_bo(batch
, iris_resource_bo(p_surf
->texture
), writeable
);
4600 if (GEN_GEN
== 8 && is_read_surface
) {
4601 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state_read
.ref
.res
), false);
4603 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state
.ref
.res
), false);
4607 iris_use_pinned_bo(batch
, res
->aux
.bo
, writeable
);
4608 if (res
->aux
.clear_color_bo
)
4609 iris_use_pinned_bo(batch
, res
->aux
.clear_color_bo
, false);
4611 if (memcmp(&res
->aux
.clear_color
, &surf
->clear_color
,
4612 sizeof(surf
->clear_color
)) != 0) {
4613 update_clear_value(ice
, batch
, res
, &surf
->surface_state
,
4614 res
->aux
.possible_usages
, &surf
->view
);
4616 update_clear_value(ice
, batch
, res
, &surf
->surface_state_read
,
4617 res
->aux
.possible_usages
, &surf
->read_view
);
4619 surf
->clear_color
= res
->aux
.clear_color
;
4623 offset
= (GEN_GEN
== 8 && is_read_surface
)
4624 ? surf
->surface_state_read
.ref
.offset
4625 : surf
->surface_state
.ref
.offset
;
4628 surf_state_offset_for_aux(res
, res
->aux
.possible_usages
, aux_usage
);
4632 use_sampler_view(struct iris_context
*ice
,
4633 struct iris_batch
*batch
,
4634 struct iris_sampler_view
*isv
)
4636 enum isl_aux_usage aux_usage
=
4637 iris_resource_texture_aux_usage(ice
, isv
->res
, isv
->view
.format
);
4639 iris_use_pinned_bo(batch
, isv
->res
->bo
, false);
4640 iris_use_pinned_bo(batch
, iris_resource_bo(isv
->surface_state
.ref
.res
), false);
4642 if (isv
->res
->aux
.bo
) {
4643 iris_use_pinned_bo(batch
, isv
->res
->aux
.bo
, false);
4644 if (isv
->res
->aux
.clear_color_bo
)
4645 iris_use_pinned_bo(batch
, isv
->res
->aux
.clear_color_bo
, false);
4646 if (memcmp(&isv
->res
->aux
.clear_color
, &isv
->clear_color
,
4647 sizeof(isv
->clear_color
)) != 0) {
4648 update_clear_value(ice
, batch
, isv
->res
, &isv
->surface_state
,
4649 isv
->res
->aux
.sampler_usages
, &isv
->view
);
4650 isv
->clear_color
= isv
->res
->aux
.clear_color
;
4654 return isv
->surface_state
.ref
.offset
+
4655 surf_state_offset_for_aux(isv
->res
, isv
->res
->aux
.sampler_usages
,
4660 use_ubo_ssbo(struct iris_batch
*batch
,
4661 struct iris_context
*ice
,
4662 struct pipe_shader_buffer
*buf
,
4663 struct iris_state_ref
*surf_state
,
4666 if (!buf
->buffer
|| !surf_state
->res
)
4667 return use_null_surface(batch
, ice
);
4669 iris_use_pinned_bo(batch
, iris_resource_bo(buf
->buffer
), writable
);
4670 iris_use_pinned_bo(batch
, iris_resource_bo(surf_state
->res
), false);
4672 return surf_state
->offset
;
4676 use_image(struct iris_batch
*batch
, struct iris_context
*ice
,
4677 struct iris_shader_state
*shs
, const struct shader_info
*info
,
4680 struct iris_image_view
*iv
= &shs
->image
[i
];
4681 struct iris_resource
*res
= (void *) iv
->base
.resource
;
4684 return use_null_surface(batch
, ice
);
4686 bool write
= iv
->base
.shader_access
& PIPE_IMAGE_ACCESS_WRITE
;
4688 iris_use_pinned_bo(batch
, res
->bo
, write
);
4689 iris_use_pinned_bo(batch
, iris_resource_bo(iv
->surface_state
.ref
.res
), false);
4692 iris_use_pinned_bo(batch
, res
->aux
.bo
, write
);
4694 enum isl_aux_usage aux_usage
=
4695 iris_image_view_aux_usage(ice
, &iv
->base
, info
);
4697 return iv
->surface_state
.ref
.offset
+
4698 surf_state_offset_for_aux(res
, res
->aux
.possible_usages
, aux_usage
);
4701 #define push_bt_entry(addr) \
4702 assert(addr >= binder_addr); \
4703 assert(s < shader->bt.size_bytes / sizeof(uint32_t)); \
4704 if (!pin_only) bt_map[s++] = (addr) - binder_addr;
4706 #define bt_assert(section) \
4707 if (!pin_only && shader->bt.used_mask[section] != 0) \
4708 assert(shader->bt.offsets[section] == s);
4711 * Populate the binding table for a given shader stage.
4713 * This fills out the table of pointers to surfaces required by the shader,
4714 * and also adds those buffers to the validation list so the kernel can make
4715 * resident before running our batch.
4718 iris_populate_binding_table(struct iris_context
*ice
,
4719 struct iris_batch
*batch
,
4720 gl_shader_stage stage
,
4723 const struct iris_binder
*binder
= &ice
->state
.binder
;
4724 struct iris_uncompiled_shader
*ish
= ice
->shaders
.uncompiled
[stage
];
4725 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4729 struct iris_binding_table
*bt
= &shader
->bt
;
4730 UNUSED
struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4731 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4732 uint32_t binder_addr
= binder
->bo
->gtt_offset
;
4734 uint32_t *bt_map
= binder
->map
+ binder
->bt_offset
[stage
];
4737 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
4739 /* TCS passthrough doesn't need a binding table. */
4740 assert(stage
== MESA_SHADER_TESS_CTRL
);
4744 if (stage
== MESA_SHADER_COMPUTE
&&
4745 shader
->bt
.used_mask
[IRIS_SURFACE_GROUP_CS_WORK_GROUPS
]) {
4746 /* surface for gl_NumWorkGroups */
4747 struct iris_state_ref
*grid_data
= &ice
->state
.grid_size
;
4748 struct iris_state_ref
*grid_state
= &ice
->state
.grid_surf_state
;
4749 iris_use_pinned_bo(batch
, iris_resource_bo(grid_data
->res
), false);
4750 iris_use_pinned_bo(batch
, iris_resource_bo(grid_state
->res
), false);
4751 push_bt_entry(grid_state
->offset
);
4754 if (stage
== MESA_SHADER_FRAGMENT
) {
4755 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4756 /* Note that cso_fb->nr_cbufs == fs_key->nr_color_regions. */
4757 if (cso_fb
->nr_cbufs
) {
4758 for (unsigned i
= 0; i
< cso_fb
->nr_cbufs
; i
++) {
4760 if (cso_fb
->cbufs
[i
]) {
4761 addr
= use_surface(ice
, batch
, cso_fb
->cbufs
[i
], true,
4762 ice
->state
.draw_aux_usage
[i
], false);
4764 addr
= use_null_fb_surface(batch
, ice
);
4766 push_bt_entry(addr
);
4768 } else if (GEN_GEN
< 11) {
4769 uint32_t addr
= use_null_fb_surface(batch
, ice
);
4770 push_bt_entry(addr
);
4774 #define foreach_surface_used(index, group) \
4776 for (int index = 0; index < bt->sizes[group]; index++) \
4777 if (iris_group_index_to_bti(bt, group, index) != \
4778 IRIS_SURFACE_NOT_USED)
4780 foreach_surface_used(i
, IRIS_SURFACE_GROUP_RENDER_TARGET_READ
) {
4781 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4783 if (cso_fb
->cbufs
[i
]) {
4784 addr
= use_surface(ice
, batch
, cso_fb
->cbufs
[i
],
4785 true, ice
->state
.draw_aux_usage
[i
], true);
4786 push_bt_entry(addr
);
4790 foreach_surface_used(i
, IRIS_SURFACE_GROUP_TEXTURE
) {
4791 struct iris_sampler_view
*view
= shs
->textures
[i
];
4792 uint32_t addr
= view
? use_sampler_view(ice
, batch
, view
)
4793 : use_null_surface(batch
, ice
);
4794 push_bt_entry(addr
);
4797 foreach_surface_used(i
, IRIS_SURFACE_GROUP_IMAGE
) {
4798 uint32_t addr
= use_image(batch
, ice
, shs
, info
, i
);
4799 push_bt_entry(addr
);
4802 foreach_surface_used(i
, IRIS_SURFACE_GROUP_UBO
) {
4805 if (i
== bt
->sizes
[IRIS_SURFACE_GROUP_UBO
] - 1) {
4806 if (ish
->const_data
) {
4807 iris_use_pinned_bo(batch
, iris_resource_bo(ish
->const_data
), false);
4808 iris_use_pinned_bo(batch
, iris_resource_bo(ish
->const_data_state
.res
),
4810 addr
= ish
->const_data_state
.offset
;
4812 /* This can only happen with INTEL_DISABLE_COMPACT_BINDING_TABLE=1. */
4813 addr
= use_null_surface(batch
, ice
);
4816 addr
= use_ubo_ssbo(batch
, ice
, &shs
->constbuf
[i
],
4817 &shs
->constbuf_surf_state
[i
], false);
4820 push_bt_entry(addr
);
4823 foreach_surface_used(i
, IRIS_SURFACE_GROUP_SSBO
) {
4825 use_ubo_ssbo(batch
, ice
, &shs
->ssbo
[i
], &shs
->ssbo_surf_state
[i
],
4826 shs
->writable_ssbos
& (1u << i
));
4827 push_bt_entry(addr
);
4831 /* XXX: YUV surfaces not implemented yet */
4832 bt_assert(plane_start
[1], ...);
4833 bt_assert(plane_start
[2], ...);
4838 iris_use_optional_res(struct iris_batch
*batch
,
4839 struct pipe_resource
*res
,
4843 struct iris_bo
*bo
= iris_resource_bo(res
);
4844 iris_use_pinned_bo(batch
, bo
, writeable
);
4849 pin_depth_and_stencil_buffers(struct iris_batch
*batch
,
4850 struct pipe_surface
*zsbuf
,
4851 struct iris_depth_stencil_alpha_state
*cso_zsa
)
4856 struct iris_resource
*zres
, *sres
;
4857 iris_get_depth_stencil_resources(zsbuf
->texture
, &zres
, &sres
);
4860 iris_use_pinned_bo(batch
, zres
->bo
, cso_zsa
->depth_writes_enabled
);
4862 iris_use_pinned_bo(batch
, zres
->aux
.bo
,
4863 cso_zsa
->depth_writes_enabled
);
4868 iris_use_pinned_bo(batch
, sres
->bo
, cso_zsa
->stencil_writes_enabled
);
4872 /* ------------------------------------------------------------------- */
4875 * Pin any BOs which were installed by a previous batch, and restored
4876 * via the hardware logical context mechanism.
4878 * We don't need to re-emit all state every batch - the hardware context
4879 * mechanism will save and restore it for us. This includes pointers to
4880 * various BOs...which won't exist unless we ask the kernel to pin them
4881 * by adding them to the validation list.
4883 * We can skip buffers if we've re-emitted those packets, as we're
4884 * overwriting those stale pointers with new ones, and don't actually
4885 * refer to the old BOs.
4888 iris_restore_render_saved_bos(struct iris_context
*ice
,
4889 struct iris_batch
*batch
,
4890 const struct pipe_draw_info
*draw
)
4892 struct iris_genx_state
*genx
= ice
->state
.genx
;
4894 const uint64_t clean
= ~ice
->state
.dirty
;
4896 if (clean
& IRIS_DIRTY_CC_VIEWPORT
) {
4897 iris_use_optional_res(batch
, ice
->state
.last_res
.cc_vp
, false);
4900 if (clean
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
4901 iris_use_optional_res(batch
, ice
->state
.last_res
.sf_cl_vp
, false);
4904 if (clean
& IRIS_DIRTY_BLEND_STATE
) {
4905 iris_use_optional_res(batch
, ice
->state
.last_res
.blend
, false);
4908 if (clean
& IRIS_DIRTY_COLOR_CALC_STATE
) {
4909 iris_use_optional_res(batch
, ice
->state
.last_res
.color_calc
, false);
4912 if (clean
& IRIS_DIRTY_SCISSOR_RECT
) {
4913 iris_use_optional_res(batch
, ice
->state
.last_res
.scissor
, false);
4916 if (ice
->state
.streamout_active
&& (clean
& IRIS_DIRTY_SO_BUFFERS
)) {
4917 for (int i
= 0; i
< 4; i
++) {
4918 struct iris_stream_output_target
*tgt
=
4919 (void *) ice
->state
.so_target
[i
];
4921 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
4923 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
4929 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4930 if (!(clean
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
4933 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4934 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4939 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
4941 for (int i
= 0; i
< 4; i
++) {
4942 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
4944 if (range
->length
== 0)
4947 /* Range block is a binding table index, map back to UBO index. */
4948 unsigned block_index
= iris_bti_to_group_index(
4949 &shader
->bt
, IRIS_SURFACE_GROUP_UBO
, range
->block
);
4950 assert(block_index
!= IRIS_SURFACE_NOT_USED
);
4952 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[block_index
];
4953 struct iris_resource
*res
= (void *) cbuf
->buffer
;
4956 iris_use_pinned_bo(batch
, res
->bo
, false);
4958 iris_use_pinned_bo(batch
, batch
->screen
->workaround_bo
, false);
4962 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4963 if (clean
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
4964 /* Re-pin any buffers referred to by the binding table. */
4965 iris_populate_binding_table(ice
, batch
, stage
, true);
4969 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4970 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4971 struct pipe_resource
*res
= shs
->sampler_table
.res
;
4973 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4976 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4977 if (clean
& (IRIS_DIRTY_VS
<< stage
)) {
4978 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4981 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
4982 iris_use_pinned_bo(batch
, bo
, false);
4984 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4986 if (prog_data
->total_scratch
> 0) {
4987 struct iris_bo
*bo
=
4988 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
4989 iris_use_pinned_bo(batch
, bo
, true);
4995 if ((clean
& IRIS_DIRTY_DEPTH_BUFFER
) &&
4996 (clean
& IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
4997 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4998 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
5001 iris_use_optional_res(batch
, ice
->state
.last_res
.index_buffer
, false);
5003 if (clean
& IRIS_DIRTY_VERTEX_BUFFERS
) {
5004 uint64_t bound
= ice
->state
.bound_vertex_buffers
;
5006 const int i
= u_bit_scan64(&bound
);
5007 struct pipe_resource
*res
= genx
->vertex_buffers
[i
].resource
;
5008 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
5014 iris_restore_compute_saved_bos(struct iris_context
*ice
,
5015 struct iris_batch
*batch
,
5016 const struct pipe_grid_info
*grid
)
5018 const uint64_t clean
= ~ice
->state
.dirty
;
5020 const int stage
= MESA_SHADER_COMPUTE
;
5021 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5023 if (clean
& IRIS_DIRTY_BINDINGS_CS
) {
5024 /* Re-pin any buffers referred to by the binding table. */
5025 iris_populate_binding_table(ice
, batch
, stage
, true);
5028 struct pipe_resource
*sampler_res
= shs
->sampler_table
.res
;
5030 iris_use_pinned_bo(batch
, iris_resource_bo(sampler_res
), false);
5032 if ((clean
& IRIS_DIRTY_SAMPLER_STATES_CS
) &&
5033 (clean
& IRIS_DIRTY_BINDINGS_CS
) &&
5034 (clean
& IRIS_DIRTY_CONSTANTS_CS
) &&
5035 (clean
& IRIS_DIRTY_CS
)) {
5036 iris_use_optional_res(batch
, ice
->state
.last_res
.cs_desc
, false);
5039 if (clean
& IRIS_DIRTY_CS
) {
5040 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5043 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
5044 iris_use_pinned_bo(batch
, bo
, false);
5046 struct iris_bo
*curbe_bo
=
5047 iris_resource_bo(ice
->state
.last_res
.cs_thread_ids
);
5048 iris_use_pinned_bo(batch
, curbe_bo
, false);
5050 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
5052 if (prog_data
->total_scratch
> 0) {
5053 struct iris_bo
*bo
=
5054 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
5055 iris_use_pinned_bo(batch
, bo
, true);
5062 * Possibly emit STATE_BASE_ADDRESS to update Surface State Base Address.
5065 iris_update_surface_base_address(struct iris_batch
*batch
,
5066 struct iris_binder
*binder
)
5068 if (batch
->last_surface_base_address
== binder
->bo
->gtt_offset
)
5071 uint32_t mocs
= batch
->screen
->isl_dev
.mocs
.internal
;
5073 flush_before_state_base_change(batch
);
5076 /* GEN:BUG:1607854226:
5078 * Workaround the non pipelined state not applying in MEDIA/GPGPU pipeline
5079 * mode by putting the pipeline temporarily in 3D mode..
5081 if (batch
->name
== IRIS_BATCH_COMPUTE
)
5082 emit_pipeline_select(batch
, _3D
);
5085 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
5086 sba
.SurfaceStateBaseAddressModifyEnable
= true;
5087 sba
.SurfaceStateBaseAddress
= ro_bo(binder
->bo
, 0);
5089 /* The hardware appears to pay attention to the MOCS fields even
5090 * if you don't set the "Address Modify Enable" bit for the base.
5092 sba
.GeneralStateMOCS
= mocs
;
5093 sba
.StatelessDataPortAccessMOCS
= mocs
;
5094 sba
.DynamicStateMOCS
= mocs
;
5095 sba
.IndirectObjectMOCS
= mocs
;
5096 sba
.InstructionMOCS
= mocs
;
5097 sba
.SurfaceStateMOCS
= mocs
;
5099 sba
.BindlessSurfaceStateMOCS
= mocs
;
5104 /* GEN:BUG:1607854226:
5106 * Put the pipeline back into compute mode.
5108 if (batch
->name
== IRIS_BATCH_COMPUTE
)
5109 emit_pipeline_select(batch
, GPGPU
);
5112 flush_after_state_base_change(batch
);
5114 batch
->last_surface_base_address
= binder
->bo
->gtt_offset
;
5118 iris_viewport_zmin_zmax(const struct pipe_viewport_state
*vp
, bool halfz
,
5119 bool window_space_position
, float *zmin
, float *zmax
)
5121 if (window_space_position
) {
5126 util_viewport_zmin_zmax(vp
, halfz
, zmin
, zmax
);
5131 genX(invalidate_aux_map_state
)(struct iris_batch
*batch
)
5133 struct iris_screen
*screen
= batch
->screen
;
5134 void *aux_map_ctx
= iris_bufmgr_get_aux_map_context(screen
->bufmgr
);
5137 uint32_t aux_map_state_num
= gen_aux_map_get_state_num(aux_map_ctx
);
5138 if (batch
->last_aux_map_state
!= aux_map_state_num
) {
5139 /* HSD 1209978178: docs say that before programming the aux table:
5141 * "Driver must ensure that the engine is IDLE but ensure it doesn't
5142 * add extra flushes in the case it knows that the engine is already
5145 * An end of pipe sync is needed here, otherwise we see GPU hangs in
5146 * dEQP-GLES31.functional.copy_image.* tests.
5148 iris_emit_end_of_pipe_sync(batch
, "Invalidate aux map table",
5149 PIPE_CONTROL_CS_STALL
);
5151 /* If the aux-map state number increased, then we need to rewrite the
5152 * register. Rewriting the register is used to both set the aux-map
5153 * translation table address, and also to invalidate any previously
5154 * cached translations.
5156 iris_load_register_imm32(batch
, GENX(GFX_CCS_AUX_INV_num
), 1);
5157 batch
->last_aux_map_state
= aux_map_state_num
;
5162 init_aux_map_state(struct iris_batch
*batch
)
5164 struct iris_screen
*screen
= batch
->screen
;
5165 void *aux_map_ctx
= iris_bufmgr_get_aux_map_context(screen
->bufmgr
);
5169 uint64_t base_addr
= gen_aux_map_get_base(aux_map_ctx
);
5170 assert(base_addr
!= 0 && align64(base_addr
, 32 * 1024) == base_addr
);
5171 iris_load_register_imm64(batch
, GENX(GFX_AUX_TABLE_BASE_ADDR_num
),
5178 struct iris_address addr
;
5182 uint32_t max_length
;
5186 setup_constant_buffers(struct iris_context
*ice
,
5187 struct iris_batch
*batch
,
5189 struct push_bos
*push_bos
)
5191 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5192 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5193 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
5195 uint32_t push_range_sum
= 0;
5198 for (int i
= 0; i
< 4; i
++) {
5199 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
5201 if (range
->length
== 0)
5204 push_range_sum
+= range
->length
;
5206 if (range
->length
> push_bos
->max_length
)
5207 push_bos
->max_length
= range
->length
;
5209 /* Range block is a binding table index, map back to UBO index. */
5210 unsigned block_index
= iris_bti_to_group_index(
5211 &shader
->bt
, IRIS_SURFACE_GROUP_UBO
, range
->block
);
5212 assert(block_index
!= IRIS_SURFACE_NOT_USED
);
5214 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[block_index
];
5215 struct iris_resource
*res
= (void *) cbuf
->buffer
;
5217 assert(cbuf
->buffer_offset
% 32 == 0);
5219 push_bos
->buffers
[n
].length
= range
->length
;
5220 push_bos
->buffers
[n
].addr
=
5221 res
? ro_bo(res
->bo
, range
->start
* 32 + cbuf
->buffer_offset
)
5222 : ro_bo(batch
->screen
->workaround_bo
, 0);
5226 /* From the 3DSTATE_CONSTANT_XS and 3DSTATE_CONSTANT_ALL programming notes:
5228 * "The sum of all four read length fields must be less than or
5229 * equal to the size of 64."
5231 assert(push_range_sum
<= 64);
5233 push_bos
->buffer_count
= n
;
5237 emit_push_constant_packets(struct iris_context
*ice
,
5238 struct iris_batch
*batch
,
5240 const struct push_bos
*push_bos
)
5242 UNUSED
struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
5243 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5244 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
5246 iris_emit_cmd(batch
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
5247 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
5249 pkt
.MOCS
= isl_dev
->mocs
.internal
;
5252 /* The Skylake PRM contains the following restriction:
5254 * "The driver must ensure The following case does not occur
5255 * without a flush to the 3D engine: 3DSTATE_CONSTANT_* with
5256 * buffer 3 read length equal to zero committed followed by a
5257 * 3DSTATE_CONSTANT_* with buffer 0 read length not equal to
5260 * To avoid this, we program the buffers in the highest slots.
5261 * This way, slot 0 is only used if slot 3 is also used.
5263 int n
= push_bos
->buffer_count
;
5265 const unsigned shift
= 4 - n
;
5266 for (int i
= 0; i
< n
; i
++) {
5267 pkt
.ConstantBody
.ReadLength
[i
+ shift
] =
5268 push_bos
->buffers
[i
].length
;
5269 pkt
.ConstantBody
.Buffer
[i
+ shift
] = push_bos
->buffers
[i
].addr
;
5277 emit_push_constant_packet_all(struct iris_context
*ice
,
5278 struct iris_batch
*batch
,
5279 uint32_t shader_mask
,
5280 const struct push_bos
*push_bos
)
5282 struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
5285 iris_emit_cmd(batch
, GENX(3DSTATE_CONSTANT_ALL
), pc
) {
5286 pc
.ShaderUpdateEnable
= shader_mask
;
5291 const uint32_t n
= push_bos
->buffer_count
;
5292 const uint32_t max_pointers
= 4;
5293 const uint32_t num_dwords
= 2 + 2 * n
;
5294 uint32_t const_all
[2 + 2 * max_pointers
];
5295 uint32_t *dw
= &const_all
[0];
5297 assert(n
<= max_pointers
);
5298 iris_pack_command(GENX(3DSTATE_CONSTANT_ALL
), dw
, all
) {
5299 all
.DWordLength
= num_dwords
- 2;
5300 all
.MOCS
= isl_dev
->mocs
.internal
;
5301 all
.ShaderUpdateEnable
= shader_mask
;
5302 all
.PointerBufferMask
= (1 << n
) - 1;
5306 for (int i
= 0; i
< n
; i
++) {
5307 _iris_pack_state(batch
, GENX(3DSTATE_CONSTANT_ALL_DATA
),
5309 data
.PointerToConstantBuffer
= push_bos
->buffers
[i
].addr
;
5310 data
.ConstantBufferReadLength
= push_bos
->buffers
[i
].length
;
5313 iris_batch_emit(batch
, const_all
, sizeof(uint32_t) * num_dwords
);
5318 iris_upload_dirty_render_state(struct iris_context
*ice
,
5319 struct iris_batch
*batch
,
5320 const struct pipe_draw_info
*draw
)
5322 const uint64_t dirty
= ice
->state
.dirty
;
5324 if (!(dirty
& IRIS_ALL_DIRTY_FOR_RENDER
))
5327 struct iris_genx_state
*genx
= ice
->state
.genx
;
5328 struct iris_binder
*binder
= &ice
->state
.binder
;
5329 struct brw_wm_prog_data
*wm_prog_data
= (void *)
5330 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
5332 if (dirty
& IRIS_DIRTY_CC_VIEWPORT
) {
5333 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5334 uint32_t cc_vp_address
;
5336 /* XXX: could avoid streaming for depth_clip [0,1] case. */
5337 uint32_t *cc_vp_map
=
5338 stream_state(batch
, ice
->state
.dynamic_uploader
,
5339 &ice
->state
.last_res
.cc_vp
,
5340 4 * ice
->state
.num_viewports
*
5341 GENX(CC_VIEWPORT_length
), 32, &cc_vp_address
);
5342 for (int i
= 0; i
< ice
->state
.num_viewports
; i
++) {
5344 iris_viewport_zmin_zmax(&ice
->state
.viewports
[i
], cso_rast
->clip_halfz
,
5345 ice
->state
.window_space_position
,
5347 if (cso_rast
->depth_clip_near
)
5349 if (cso_rast
->depth_clip_far
)
5352 iris_pack_state(GENX(CC_VIEWPORT
), cc_vp_map
, ccv
) {
5353 ccv
.MinimumDepth
= zmin
;
5354 ccv
.MaximumDepth
= zmax
;
5357 cc_vp_map
+= GENX(CC_VIEWPORT_length
);
5360 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), ptr
) {
5361 ptr
.CCViewportPointer
= cc_vp_address
;
5365 if (dirty
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
5366 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5367 uint32_t sf_cl_vp_address
;
5369 stream_state(batch
, ice
->state
.dynamic_uploader
,
5370 &ice
->state
.last_res
.sf_cl_vp
,
5371 4 * ice
->state
.num_viewports
*
5372 GENX(SF_CLIP_VIEWPORT_length
), 64, &sf_cl_vp_address
);
5374 for (unsigned i
= 0; i
< ice
->state
.num_viewports
; i
++) {
5375 const struct pipe_viewport_state
*state
= &ice
->state
.viewports
[i
];
5376 float gb_xmin
, gb_xmax
, gb_ymin
, gb_ymax
;
5378 float vp_xmin
= viewport_extent(state
, 0, -1.0f
);
5379 float vp_xmax
= viewport_extent(state
, 0, 1.0f
);
5380 float vp_ymin
= viewport_extent(state
, 1, -1.0f
);
5381 float vp_ymax
= viewport_extent(state
, 1, 1.0f
);
5383 gen_calculate_guardband_size(cso_fb
->width
, cso_fb
->height
,
5384 state
->scale
[0], state
->scale
[1],
5385 state
->translate
[0], state
->translate
[1],
5386 &gb_xmin
, &gb_xmax
, &gb_ymin
, &gb_ymax
);
5388 iris_pack_state(GENX(SF_CLIP_VIEWPORT
), vp_map
, vp
) {
5389 vp
.ViewportMatrixElementm00
= state
->scale
[0];
5390 vp
.ViewportMatrixElementm11
= state
->scale
[1];
5391 vp
.ViewportMatrixElementm22
= state
->scale
[2];
5392 vp
.ViewportMatrixElementm30
= state
->translate
[0];
5393 vp
.ViewportMatrixElementm31
= state
->translate
[1];
5394 vp
.ViewportMatrixElementm32
= state
->translate
[2];
5395 vp
.XMinClipGuardband
= gb_xmin
;
5396 vp
.XMaxClipGuardband
= gb_xmax
;
5397 vp
.YMinClipGuardband
= gb_ymin
;
5398 vp
.YMaxClipGuardband
= gb_ymax
;
5399 vp
.XMinViewPort
= MAX2(vp_xmin
, 0);
5400 vp
.XMaxViewPort
= MIN2(vp_xmax
, cso_fb
->width
) - 1;
5401 vp
.YMinViewPort
= MAX2(vp_ymin
, 0);
5402 vp
.YMaxViewPort
= MIN2(vp_ymax
, cso_fb
->height
) - 1;
5405 vp_map
+= GENX(SF_CLIP_VIEWPORT_length
);
5408 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
5409 ptr
.SFClipViewportPointer
= sf_cl_vp_address
;
5413 if (dirty
& IRIS_DIRTY_URB
) {
5416 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
5417 if (!ice
->shaders
.prog
[i
]) {
5420 struct brw_vue_prog_data
*vue_prog_data
=
5421 (void *) ice
->shaders
.prog
[i
]->prog_data
;
5422 size
[i
] = vue_prog_data
->urb_entry_size
;
5424 assert(size
[i
] != 0);
5427 unsigned entries
[4], start
[4];
5428 gen_get_urb_config(&batch
->screen
->devinfo
,
5429 batch
->screen
->l3_config_3d
,
5430 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
] != NULL
,
5431 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] != NULL
,
5432 size
, entries
, start
,
5433 &ice
->state
.urb_deref_block_size
);
5435 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
5436 iris_emit_cmd(batch
, GENX(3DSTATE_URB_VS
), urb
) {
5437 urb
._3DCommandSubOpcode
+= i
;
5438 urb
.VSURBStartingAddress
= start
[i
];
5439 urb
.VSURBEntryAllocationSize
= size
[i
] - 1;
5440 urb
.VSNumberofURBEntries
= entries
[i
];
5445 if (dirty
& IRIS_DIRTY_BLEND_STATE
) {
5446 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
5447 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5448 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
5449 const int header_dwords
= GENX(BLEND_STATE_length
);
5451 /* Always write at least one BLEND_STATE - the final RT message will
5452 * reference BLEND_STATE[0] even if there aren't color writes. There
5453 * may still be alpha testing, computed depth, and so on.
5455 const int rt_dwords
=
5456 MAX2(cso_fb
->nr_cbufs
, 1) * GENX(BLEND_STATE_ENTRY_length
);
5458 uint32_t blend_offset
;
5459 uint32_t *blend_map
=
5460 stream_state(batch
, ice
->state
.dynamic_uploader
,
5461 &ice
->state
.last_res
.blend
,
5462 4 * (header_dwords
+ rt_dwords
), 64, &blend_offset
);
5464 uint32_t blend_state_header
;
5465 iris_pack_state(GENX(BLEND_STATE
), &blend_state_header
, bs
) {
5466 bs
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
5467 bs
.AlphaTestFunction
= translate_compare_func(cso_zsa
->alpha
.func
);
5470 blend_map
[0] = blend_state_header
| cso_blend
->blend_state
[0];
5471 memcpy(&blend_map
[1], &cso_blend
->blend_state
[1], 4 * rt_dwords
);
5473 iris_emit_cmd(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
5474 ptr
.BlendStatePointer
= blend_offset
;
5475 ptr
.BlendStatePointerValid
= true;
5479 if (dirty
& IRIS_DIRTY_COLOR_CALC_STATE
) {
5480 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
5482 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
5486 stream_state(batch
, ice
->state
.dynamic_uploader
,
5487 &ice
->state
.last_res
.color_calc
,
5488 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length
),
5490 iris_pack_state(GENX(COLOR_CALC_STATE
), cc_map
, cc
) {
5491 cc
.AlphaTestFormat
= ALPHATEST_FLOAT32
;
5492 cc
.AlphaReferenceValueAsFLOAT32
= cso
->alpha
.ref_value
;
5493 cc
.BlendConstantColorRed
= ice
->state
.blend_color
.color
[0];
5494 cc
.BlendConstantColorGreen
= ice
->state
.blend_color
.color
[1];
5495 cc
.BlendConstantColorBlue
= ice
->state
.blend_color
.color
[2];
5496 cc
.BlendConstantColorAlpha
= ice
->state
.blend_color
.color
[3];
5498 cc
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
5499 cc
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
5502 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
5503 ptr
.ColorCalcStatePointer
= cc_offset
;
5504 ptr
.ColorCalcStatePointerValid
= true;
5508 /* GEN:BUG:1604061319
5510 * 3DSTATE_CONSTANT_* needs to be programmed before BTP_*
5512 * Testing shows that all the 3DSTATE_CONSTANT_XS need to be emitted if
5513 * any stage has a dirty binding table.
5515 const bool emit_const_wa
= GEN_GEN
>= 11 &&
5516 (dirty
& IRIS_ALL_DIRTY_BINDINGS
) != 0;
5519 uint32_t nobuffer_stages
= 0;
5522 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5523 if (!(dirty
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)) &&
5527 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5528 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5533 if (shs
->sysvals_need_upload
)
5534 upload_sysvals(ice
, stage
);
5536 struct push_bos push_bos
= {};
5537 setup_constant_buffers(ice
, batch
, stage
, &push_bos
);
5540 /* If this stage doesn't have any push constants, emit it later in a
5541 * single CONSTANT_ALL packet with all the other stages.
5543 if (push_bos
.buffer_count
== 0) {
5544 nobuffer_stages
|= 1 << stage
;
5548 /* The Constant Buffer Read Length field from 3DSTATE_CONSTANT_ALL
5549 * contains only 5 bits, so we can only use it for buffers smaller than
5552 if (push_bos
.max_length
< 32) {
5553 emit_push_constant_packet_all(ice
, batch
, 1 << stage
, &push_bos
);
5557 emit_push_constant_packets(ice
, batch
, stage
, &push_bos
);
5561 if (nobuffer_stages
)
5562 emit_push_constant_packet_all(ice
, batch
, nobuffer_stages
, NULL
);
5565 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5566 /* Gen9 requires 3DSTATE_BINDING_TABLE_POINTERS_XS to be re-emitted
5567 * in order to commit constants. TODO: Investigate "Disable Gather
5568 * at Set Shader" to go back to legacy mode...
5570 if (dirty
& ((IRIS_DIRTY_BINDINGS_VS
|
5571 (GEN_GEN
== 9 ? IRIS_DIRTY_CONSTANTS_VS
: 0)) << stage
)) {
5572 iris_emit_cmd(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), ptr
) {
5573 ptr
._3DCommandSubOpcode
= 38 + stage
;
5574 ptr
.PointertoVSBindingTable
= binder
->bt_offset
[stage
];
5579 if (GEN_GEN
>= 11 && (dirty
& IRIS_DIRTY_RENDER_BUFFER
)) {
5580 // XXX: we may want to flag IRIS_DIRTY_MULTISAMPLE (or SAMPLE_MASK?)
5581 // XXX: see commit 979fc1bc9bcc64027ff2cfafd285676f31b930a6
5583 /* The PIPE_CONTROL command description says:
5585 * "Whenever a Binding Table Index (BTI) used by a Render Target
5586 * Message points to a different RENDER_SURFACE_STATE, SW must issue a
5587 * Render Target Cache Flush by enabling this bit. When render target
5588 * flush is set due to new association of BTI, PS Scoreboard Stall bit
5589 * must be set in this packet."
5591 // XXX: does this need to happen at 3DSTATE_BTP_PS time?
5592 iris_emit_pipe_control_flush(batch
, "workaround: RT BTI change [draw]",
5593 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
5594 PIPE_CONTROL_STALL_AT_SCOREBOARD
);
5597 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5598 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
5599 iris_populate_binding_table(ice
, batch
, stage
, false);
5603 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5604 if (!(dirty
& (IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
)) ||
5605 !ice
->shaders
.prog
[stage
])
5608 iris_upload_sampler_states(ice
, stage
);
5610 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5611 struct pipe_resource
*res
= shs
->sampler_table
.res
;
5613 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
5615 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ptr
) {
5616 ptr
._3DCommandSubOpcode
= 43 + stage
;
5617 ptr
.PointertoVSSamplerState
= shs
->sampler_table
.offset
;
5621 if (ice
->state
.need_border_colors
)
5622 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
5624 if (dirty
& IRIS_DIRTY_MULTISAMPLE
) {
5625 iris_emit_cmd(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
5627 ice
->state
.cso_rast
->half_pixel_center
? CENTER
: UL_CORNER
;
5628 if (ice
->state
.framebuffer
.samples
> 0)
5629 ms
.NumberofMultisamples
= ffs(ice
->state
.framebuffer
.samples
) - 1;
5633 if (dirty
& IRIS_DIRTY_SAMPLE_MASK
) {
5634 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_MASK
), ms
) {
5635 ms
.SampleMask
= ice
->state
.sample_mask
;
5639 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
5640 if (!(dirty
& (IRIS_DIRTY_VS
<< stage
)))
5643 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
5646 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
5647 struct iris_resource
*cache
= (void *) shader
->assembly
.res
;
5648 iris_use_pinned_bo(batch
, cache
->bo
, false);
5650 if (prog_data
->total_scratch
> 0) {
5651 struct iris_bo
*bo
=
5652 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
5653 iris_use_pinned_bo(batch
, bo
, true);
5656 if (stage
== MESA_SHADER_FRAGMENT
) {
5657 UNUSED
struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5658 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5660 uint32_t ps_state
[GENX(3DSTATE_PS_length
)] = {0};
5661 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
5662 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
5663 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
5664 ps
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
5666 /* The docs for 3DSTATE_PS::32 Pixel Dispatch Enable say:
5668 * "When NUM_MULTISAMPLES = 16 or FORCE_SAMPLE_COUNT = 16,
5669 * SIMD32 Dispatch must not be enabled for PER_PIXEL dispatch
5672 * 16x MSAA only exists on Gen9+, so we can skip this on Gen8.
5674 if (GEN_GEN
>= 9 && cso_fb
->samples
== 16 &&
5675 !wm_prog_data
->persample_dispatch
) {
5676 assert(ps
._8PixelDispatchEnable
|| ps
._16PixelDispatchEnable
);
5677 ps
._32PixelDispatchEnable
= false;
5680 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
5681 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 0);
5682 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
5683 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 1);
5684 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
5685 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 2);
5687 ps
.KernelStartPointer0
= KSP(shader
) +
5688 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 0);
5689 ps
.KernelStartPointer1
= KSP(shader
) +
5690 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 1);
5691 ps
.KernelStartPointer2
= KSP(shader
) +
5692 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 2);
5695 uint32_t psx_state
[GENX(3DSTATE_PS_EXTRA_length
)] = {0};
5696 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
5698 if (!wm_prog_data
->uses_sample_mask
)
5699 psx
.InputCoverageMaskState
= ICMS_NONE
;
5700 else if (wm_prog_data
->post_depth_coverage
)
5701 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
5702 else if (wm_prog_data
->inner_coverage
&&
5703 cso
->conservative_rasterization
)
5704 psx
.InputCoverageMaskState
= ICMS_INNER_CONSERVATIVE
;
5706 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
5708 psx
.PixelShaderUsesInputCoverageMask
=
5709 wm_prog_data
->uses_sample_mask
;
5713 uint32_t *shader_ps
= (uint32_t *) shader
->derived_data
;
5714 uint32_t *shader_psx
= shader_ps
+ GENX(3DSTATE_PS_length
);
5715 iris_emit_merge(batch
, shader_ps
, ps_state
,
5716 GENX(3DSTATE_PS_length
));
5717 iris_emit_merge(batch
, shader_psx
, psx_state
,
5718 GENX(3DSTATE_PS_EXTRA_length
));
5720 iris_batch_emit(batch
, shader
->derived_data
,
5721 iris_derived_program_state_size(stage
));
5724 if (stage
== MESA_SHADER_TESS_EVAL
) {
5725 iris_emit_cmd(batch
, GENX(3DSTATE_HS
), hs
);
5726 iris_emit_cmd(batch
, GENX(3DSTATE_TE
), te
);
5727 iris_emit_cmd(batch
, GENX(3DSTATE_DS
), ds
);
5728 } else if (stage
== MESA_SHADER_GEOMETRY
) {
5729 iris_emit_cmd(batch
, GENX(3DSTATE_GS
), gs
);
5734 if (ice
->state
.streamout_active
) {
5735 if (dirty
& IRIS_DIRTY_SO_BUFFERS
) {
5736 iris_batch_emit(batch
, genx
->so_buffers
,
5737 4 * 4 * GENX(3DSTATE_SO_BUFFER_length
));
5738 for (int i
= 0; i
< 4; i
++) {
5739 struct iris_stream_output_target
*tgt
=
5740 (void *) ice
->state
.so_target
[i
];
5743 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
5745 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
5751 if ((dirty
& IRIS_DIRTY_SO_DECL_LIST
) && ice
->state
.streamout
) {
5752 uint32_t *decl_list
=
5753 ice
->state
.streamout
+ GENX(3DSTATE_STREAMOUT_length
);
5754 iris_batch_emit(batch
, decl_list
, 4 * ((decl_list
[0] & 0xff) + 2));
5757 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
5758 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5760 uint32_t dynamic_sol
[GENX(3DSTATE_STREAMOUT_length
)];
5761 iris_pack_command(GENX(3DSTATE_STREAMOUT
), dynamic_sol
, sol
) {
5762 sol
.SOFunctionEnable
= true;
5763 sol
.SOStatisticsEnable
= true;
5765 sol
.RenderingDisable
= cso_rast
->rasterizer_discard
&&
5766 !ice
->state
.prims_generated_query_active
;
5767 sol
.ReorderMode
= cso_rast
->flatshade_first
? LEADING
: TRAILING
;
5770 assert(ice
->state
.streamout
);
5772 iris_emit_merge(batch
, ice
->state
.streamout
, dynamic_sol
,
5773 GENX(3DSTATE_STREAMOUT_length
));
5776 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
5777 iris_emit_cmd(batch
, GENX(3DSTATE_STREAMOUT
), sol
);
5781 if (dirty
& IRIS_DIRTY_CLIP
) {
5782 struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
5783 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5785 bool gs_or_tes
= ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] ||
5786 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
];
5787 bool points_or_lines
= cso_rast
->fill_mode_point_or_line
||
5788 (gs_or_tes
? ice
->shaders
.output_topology_is_points_or_lines
5789 : ice
->state
.prim_is_points_or_lines
);
5791 uint32_t dynamic_clip
[GENX(3DSTATE_CLIP_length
)];
5792 iris_pack_command(GENX(3DSTATE_CLIP
), &dynamic_clip
, cl
) {
5793 cl
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
5794 if (cso_rast
->rasterizer_discard
)
5795 cl
.ClipMode
= CLIPMODE_REJECT_ALL
;
5796 else if (ice
->state
.window_space_position
)
5797 cl
.ClipMode
= CLIPMODE_ACCEPT_ALL
;
5799 cl
.ClipMode
= CLIPMODE_NORMAL
;
5801 cl
.PerspectiveDivideDisable
= ice
->state
.window_space_position
;
5802 cl
.ViewportXYClipTestEnable
= !points_or_lines
;
5804 if (wm_prog_data
->barycentric_interp_modes
&
5805 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
5806 cl
.NonPerspectiveBarycentricEnable
= true;
5808 cl
.ForceZeroRTAIndexEnable
= cso_fb
->layers
<= 1;
5809 cl
.MaximumVPIndex
= ice
->state
.num_viewports
- 1;
5811 iris_emit_merge(batch
, cso_rast
->clip
, dynamic_clip
,
5812 ARRAY_SIZE(cso_rast
->clip
));
5815 if (dirty
& (IRIS_DIRTY_RASTER
| IRIS_DIRTY_URB
)) {
5816 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5817 iris_batch_emit(batch
, cso
->raster
, sizeof(cso
->raster
));
5819 uint32_t dynamic_sf
[GENX(3DSTATE_SF_length
)];
5820 iris_pack_command(GENX(3DSTATE_SF
), &dynamic_sf
, sf
) {
5821 sf
.ViewportTransformEnable
= !ice
->state
.window_space_position
;
5824 sf
.DerefBlockSize
= ice
->state
.urb_deref_block_size
;
5827 iris_emit_merge(batch
, cso
->sf
, dynamic_sf
,
5828 ARRAY_SIZE(dynamic_sf
));
5831 if (dirty
& IRIS_DIRTY_WM
) {
5832 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5833 uint32_t dynamic_wm
[GENX(3DSTATE_WM_length
)];
5835 iris_pack_command(GENX(3DSTATE_WM
), &dynamic_wm
, wm
) {
5836 wm
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
5838 wm
.BarycentricInterpolationMode
=
5839 wm_prog_data
->barycentric_interp_modes
;
5841 if (wm_prog_data
->early_fragment_tests
)
5842 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
5843 else if (wm_prog_data
->has_side_effects
)
5844 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
5846 /* We could skip this bit if color writes are enabled. */
5847 if (wm_prog_data
->has_side_effects
|| wm_prog_data
->uses_kill
)
5848 wm
.ForceThreadDispatchEnable
= ForceON
;
5850 iris_emit_merge(batch
, cso
->wm
, dynamic_wm
, ARRAY_SIZE(cso
->wm
));
5853 if (dirty
& IRIS_DIRTY_SBE
) {
5854 iris_emit_sbe(batch
, ice
);
5857 if (dirty
& IRIS_DIRTY_PS_BLEND
) {
5858 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
5859 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
5860 const struct shader_info
*fs_info
=
5861 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
5863 uint32_t dynamic_pb
[GENX(3DSTATE_PS_BLEND_length
)];
5864 iris_pack_command(GENX(3DSTATE_PS_BLEND
), &dynamic_pb
, pb
) {
5865 pb
.HasWriteableRT
= has_writeable_rt(cso_blend
, fs_info
);
5866 pb
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
5868 /* The dual source blending docs caution against using SRC1 factors
5869 * when the shader doesn't use a dual source render target write.
5870 * Empirically, this can lead to GPU hangs, and the results are
5871 * undefined anyway, so simply disable blending to avoid the hang.
5873 pb
.ColorBufferBlendEnable
= (cso_blend
->blend_enables
& 1) &&
5874 (!cso_blend
->dual_color_blending
|| wm_prog_data
->dual_src_blend
);
5877 iris_emit_merge(batch
, cso_blend
->ps_blend
, dynamic_pb
,
5878 ARRAY_SIZE(cso_blend
->ps_blend
));
5881 if (dirty
& IRIS_DIRTY_WM_DEPTH_STENCIL
) {
5882 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
5884 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
5885 uint32_t stencil_refs
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
5886 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), &stencil_refs
, wmds
) {
5887 wmds
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
5888 wmds
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
5890 iris_emit_merge(batch
, cso
->wmds
, stencil_refs
, ARRAY_SIZE(cso
->wmds
));
5892 iris_batch_emit(batch
, cso
->wmds
, sizeof(cso
->wmds
));
5896 iris_batch_emit(batch
, cso
->depth_bounds
, sizeof(cso
->depth_bounds
));
5900 if (dirty
& IRIS_DIRTY_SCISSOR_RECT
) {
5901 uint32_t scissor_offset
=
5902 emit_state(batch
, ice
->state
.dynamic_uploader
,
5903 &ice
->state
.last_res
.scissor
,
5904 ice
->state
.scissors
,
5905 sizeof(struct pipe_scissor_state
) *
5906 ice
->state
.num_viewports
, 32);
5908 iris_emit_cmd(batch
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
5909 ptr
.ScissorRectPointer
= scissor_offset
;
5913 if (dirty
& IRIS_DIRTY_DEPTH_BUFFER
) {
5914 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
5916 /* Do not emit the clear params yets. We need to update the clear value
5919 uint32_t clear_length
= GENX(3DSTATE_CLEAR_PARAMS_length
) * 4;
5920 uint32_t cso_z_size
= batch
->screen
->isl_dev
.ds
.size
- clear_length
;;
5923 /* GEN:BUG:14010455700
5925 * ISL will change some CHICKEN registers depending on the depth surface
5926 * format, along with emitting the depth and stencil packets. In that
5927 * case, we want to do a depth flush and stall, so the pipeline is not
5928 * using these settings while we change the registers.
5930 iris_emit_end_of_pipe_sync(batch
,
5931 "Workaround: Stop pipeline for 14010455700",
5932 PIPE_CONTROL_DEPTH_STALL
|
5933 PIPE_CONTROL_DEPTH_CACHE_FLUSH
);
5936 iris_batch_emit(batch
, cso_z
->packets
, cso_z_size
);
5937 if (GEN_GEN
>= 12) {
5938 /* GEN:BUG:1408224581
5940 * Workaround: Gen12LP Astep only An additional pipe control with
5941 * post-sync = store dword operation would be required.( w/a is to
5942 * have an additional pipe control after the stencil state whenever
5943 * the surface state bits of this state is changing).
5945 iris_emit_pipe_control_write(batch
, "WA for stencil state",
5946 PIPE_CONTROL_WRITE_IMMEDIATE
,
5947 batch
->screen
->workaround_bo
, 0, 0);
5950 union isl_color_value clear_value
= { .f32
= { 0, } };
5952 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5953 if (cso_fb
->zsbuf
) {
5954 struct iris_resource
*zres
, *sres
;
5955 iris_get_depth_stencil_resources(cso_fb
->zsbuf
->texture
,
5957 if (zres
&& zres
->aux
.bo
)
5958 clear_value
= iris_resource_get_clear_color(zres
, NULL
, NULL
);
5961 uint32_t clear_params
[GENX(3DSTATE_CLEAR_PARAMS_length
)];
5962 iris_pack_command(GENX(3DSTATE_CLEAR_PARAMS
), clear_params
, clear
) {
5963 clear
.DepthClearValueValid
= true;
5964 clear
.DepthClearValue
= clear_value
.f32
[0];
5966 iris_batch_emit(batch
, clear_params
, clear_length
);
5969 if (dirty
& (IRIS_DIRTY_DEPTH_BUFFER
| IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
5970 /* Listen for buffer changes, and also write enable changes. */
5971 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
5972 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
5975 if (dirty
& IRIS_DIRTY_POLYGON_STIPPLE
) {
5976 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
5977 for (int i
= 0; i
< 32; i
++) {
5978 poly
.PatternRow
[i
] = ice
->state
.poly_stipple
.stipple
[i
];
5983 if (dirty
& IRIS_DIRTY_LINE_STIPPLE
) {
5984 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
5985 iris_batch_emit(batch
, cso
->line_stipple
, sizeof(cso
->line_stipple
));
5988 if (dirty
& IRIS_DIRTY_VF_TOPOLOGY
) {
5989 iris_emit_cmd(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
5990 topo
.PrimitiveTopologyType
=
5991 translate_prim_type(draw
->mode
, draw
->vertices_per_patch
);
5995 if (dirty
& IRIS_DIRTY_VERTEX_BUFFERS
) {
5996 int count
= util_bitcount64(ice
->state
.bound_vertex_buffers
);
5997 uint64_t dynamic_bound
= ice
->state
.bound_vertex_buffers
;
5999 if (ice
->state
.vs_uses_draw_params
) {
6000 assert(ice
->draw
.draw_params
.res
);
6002 struct iris_vertex_buffer_state
*state
=
6003 &(ice
->state
.genx
->vertex_buffers
[count
]);
6004 pipe_resource_reference(&state
->resource
, ice
->draw
.draw_params
.res
);
6005 struct iris_resource
*res
= (void *) state
->resource
;
6007 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
6008 vb
.VertexBufferIndex
= count
;
6009 vb
.AddressModifyEnable
= true;
6011 vb
.BufferSize
= res
->bo
->size
- ice
->draw
.draw_params
.offset
;
6012 vb
.BufferStartingAddress
=
6013 ro_bo(NULL
, res
->bo
->gtt_offset
+
6014 (int) ice
->draw
.draw_params
.offset
);
6015 vb
.MOCS
= iris_mocs(res
->bo
, &batch
->screen
->isl_dev
);
6017 dynamic_bound
|= 1ull << count
;
6021 if (ice
->state
.vs_uses_derived_draw_params
) {
6022 struct iris_vertex_buffer_state
*state
=
6023 &(ice
->state
.genx
->vertex_buffers
[count
]);
6024 pipe_resource_reference(&state
->resource
,
6025 ice
->draw
.derived_draw_params
.res
);
6026 struct iris_resource
*res
= (void *) ice
->draw
.derived_draw_params
.res
;
6028 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
6029 vb
.VertexBufferIndex
= count
;
6030 vb
.AddressModifyEnable
= true;
6033 res
->bo
->size
- ice
->draw
.derived_draw_params
.offset
;
6034 vb
.BufferStartingAddress
=
6035 ro_bo(NULL
, res
->bo
->gtt_offset
+
6036 (int) ice
->draw
.derived_draw_params
.offset
);
6037 vb
.MOCS
= iris_mocs(res
->bo
, &batch
->screen
->isl_dev
);
6039 dynamic_bound
|= 1ull << count
;
6045 /* Gen11+ doesn't need the cache workaround below */
6046 uint64_t bound
= dynamic_bound
;
6048 const int i
= u_bit_scan64(&bound
);
6049 iris_use_optional_res(batch
, genx
->vertex_buffers
[i
].resource
,
6053 /* The VF cache designers cut corners, and made the cache key's
6054 * <VertexBufferIndex, Memory Address> tuple only consider the bottom
6055 * 32 bits of the address. If you have two vertex buffers which get
6056 * placed exactly 4 GiB apart and use them in back-to-back draw calls,
6057 * you can get collisions (even within a single batch).
6059 * So, we need to do a VF cache invalidate if the buffer for a VB
6060 * slot slot changes [48:32] address bits from the previous time.
6062 unsigned flush_flags
= 0;
6064 uint64_t bound
= dynamic_bound
;
6066 const int i
= u_bit_scan64(&bound
);
6067 uint16_t high_bits
= 0;
6069 struct iris_resource
*res
=
6070 (void *) genx
->vertex_buffers
[i
].resource
;
6072 iris_use_pinned_bo(batch
, res
->bo
, false);
6074 high_bits
= res
->bo
->gtt_offset
>> 32ull;
6075 if (high_bits
!= ice
->state
.last_vbo_high_bits
[i
]) {
6076 flush_flags
|= PIPE_CONTROL_VF_CACHE_INVALIDATE
|
6077 PIPE_CONTROL_CS_STALL
;
6078 ice
->state
.last_vbo_high_bits
[i
] = high_bits
;
6084 iris_emit_pipe_control_flush(batch
,
6085 "workaround: VF cache 32-bit key [VB]",
6090 const unsigned vb_dwords
= GENX(VERTEX_BUFFER_STATE_length
);
6093 iris_get_command_space(batch
, 4 * (1 + vb_dwords
* count
));
6094 _iris_pack_command(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), map
, vb
) {
6095 vb
.DWordLength
= (vb_dwords
* count
+ 1) - 2;
6099 bound
= dynamic_bound
;
6101 const int i
= u_bit_scan64(&bound
);
6102 memcpy(map
, genx
->vertex_buffers
[i
].state
,
6103 sizeof(uint32_t) * vb_dwords
);
6109 if (dirty
& IRIS_DIRTY_VERTEX_ELEMENTS
) {
6110 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
6111 const unsigned entries
= MAX2(cso
->count
, 1);
6112 if (!(ice
->state
.vs_needs_sgvs_element
||
6113 ice
->state
.vs_uses_derived_draw_params
||
6114 ice
->state
.vs_needs_edge_flag
)) {
6115 iris_batch_emit(batch
, cso
->vertex_elements
, sizeof(uint32_t) *
6116 (1 + entries
* GENX(VERTEX_ELEMENT_STATE_length
)));
6118 uint32_t dynamic_ves
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
6119 const unsigned dyn_count
= cso
->count
+
6120 ice
->state
.vs_needs_sgvs_element
+
6121 ice
->state
.vs_uses_derived_draw_params
;
6123 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
),
6126 1 + GENX(VERTEX_ELEMENT_STATE_length
) * dyn_count
- 2;
6128 memcpy(&dynamic_ves
[1], &cso
->vertex_elements
[1],
6129 (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
6130 GENX(VERTEX_ELEMENT_STATE_length
) * sizeof(uint32_t));
6131 uint32_t *ve_pack_dest
=
6132 &dynamic_ves
[1 + (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
6133 GENX(VERTEX_ELEMENT_STATE_length
)];
6135 if (ice
->state
.vs_needs_sgvs_element
) {
6136 uint32_t base_ctrl
= ice
->state
.vs_uses_draw_params
?
6137 VFCOMP_STORE_SRC
: VFCOMP_STORE_0
;
6138 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
6140 ve
.VertexBufferIndex
=
6141 util_bitcount64(ice
->state
.bound_vertex_buffers
);
6142 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
6143 ve
.Component0Control
= base_ctrl
;
6144 ve
.Component1Control
= base_ctrl
;
6145 ve
.Component2Control
= VFCOMP_STORE_0
;
6146 ve
.Component3Control
= VFCOMP_STORE_0
;
6148 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
6150 if (ice
->state
.vs_uses_derived_draw_params
) {
6151 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
6153 ve
.VertexBufferIndex
=
6154 util_bitcount64(ice
->state
.bound_vertex_buffers
) +
6155 ice
->state
.vs_uses_draw_params
;
6156 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
6157 ve
.Component0Control
= VFCOMP_STORE_SRC
;
6158 ve
.Component1Control
= VFCOMP_STORE_SRC
;
6159 ve
.Component2Control
= VFCOMP_STORE_0
;
6160 ve
.Component3Control
= VFCOMP_STORE_0
;
6162 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
6164 if (ice
->state
.vs_needs_edge_flag
) {
6165 for (int i
= 0; i
< GENX(VERTEX_ELEMENT_STATE_length
); i
++)
6166 ve_pack_dest
[i
] = cso
->edgeflag_ve
[i
];
6169 iris_batch_emit(batch
, &dynamic_ves
, sizeof(uint32_t) *
6170 (1 + dyn_count
* GENX(VERTEX_ELEMENT_STATE_length
)));
6173 if (!ice
->state
.vs_needs_edge_flag
) {
6174 iris_batch_emit(batch
, cso
->vf_instancing
, sizeof(uint32_t) *
6175 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
6177 assert(cso
->count
> 0);
6178 const unsigned edgeflag_index
= cso
->count
- 1;
6179 uint32_t dynamic_vfi
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
6180 memcpy(&dynamic_vfi
[0], cso
->vf_instancing
, edgeflag_index
*
6181 GENX(3DSTATE_VF_INSTANCING_length
) * sizeof(uint32_t));
6183 uint32_t *vfi_pack_dest
= &dynamic_vfi
[0] +
6184 edgeflag_index
* GENX(3DSTATE_VF_INSTANCING_length
);
6185 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
6186 vi
.VertexElementIndex
= edgeflag_index
+
6187 ice
->state
.vs_needs_sgvs_element
+
6188 ice
->state
.vs_uses_derived_draw_params
;
6190 for (int i
= 0; i
< GENX(3DSTATE_VF_INSTANCING_length
); i
++)
6191 vfi_pack_dest
[i
] |= cso
->edgeflag_vfi
[i
];
6193 iris_batch_emit(batch
, &dynamic_vfi
[0], sizeof(uint32_t) *
6194 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
6198 if (dirty
& IRIS_DIRTY_VF_SGVS
) {
6199 const struct brw_vs_prog_data
*vs_prog_data
= (void *)
6200 ice
->shaders
.prog
[MESA_SHADER_VERTEX
]->prog_data
;
6201 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
6203 iris_emit_cmd(batch
, GENX(3DSTATE_VF_SGVS
), sgv
) {
6204 if (vs_prog_data
->uses_vertexid
) {
6205 sgv
.VertexIDEnable
= true;
6206 sgv
.VertexIDComponentNumber
= 2;
6207 sgv
.VertexIDElementOffset
=
6208 cso
->count
- ice
->state
.vs_needs_edge_flag
;
6211 if (vs_prog_data
->uses_instanceid
) {
6212 sgv
.InstanceIDEnable
= true;
6213 sgv
.InstanceIDComponentNumber
= 3;
6214 sgv
.InstanceIDElementOffset
=
6215 cso
->count
- ice
->state
.vs_needs_edge_flag
;
6220 if (dirty
& IRIS_DIRTY_VF
) {
6221 iris_emit_cmd(batch
, GENX(3DSTATE_VF
), vf
) {
6222 if (draw
->primitive_restart
) {
6223 vf
.IndexedDrawCutIndexEnable
= true;
6224 vf
.CutIndex
= draw
->restart_index
;
6229 if (dirty
& IRIS_DIRTY_VF_STATISTICS
) {
6230 iris_emit_cmd(batch
, GENX(3DSTATE_VF_STATISTICS
), vf
) {
6231 vf
.StatisticsEnable
= true;
6236 if (dirty
& IRIS_DIRTY_PMA_FIX
) {
6237 bool enable
= want_pma_fix(ice
);
6238 genX(update_pma_fix
)(ice
, batch
, enable
);
6242 if (ice
->state
.current_hash_scale
!= 1)
6243 genX(emit_hashing_mode
)(ice
, batch
, UINT_MAX
, UINT_MAX
, 1);
6246 genX(invalidate_aux_map_state
)(batch
);
6251 iris_upload_render_state(struct iris_context
*ice
,
6252 struct iris_batch
*batch
,
6253 const struct pipe_draw_info
*draw
)
6255 bool use_predicate
= ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
;
6257 /* Always pin the binder. If we're emitting new binding table pointers,
6258 * we need it. If not, we're probably inheriting old tables via the
6259 * context, and need it anyway. Since true zero-bindings cases are
6260 * practically non-existent, just pin it and avoid last_res tracking.
6262 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
6264 if (!batch
->contains_draw
) {
6265 iris_restore_render_saved_bos(ice
, batch
, draw
);
6266 batch
->contains_draw
= true;
6269 iris_upload_dirty_render_state(ice
, batch
, draw
);
6271 if (draw
->index_size
> 0) {
6274 if (draw
->has_user_indices
) {
6275 u_upload_data(ice
->ctx
.stream_uploader
, 0,
6276 draw
->count
* draw
->index_size
, 4, draw
->index
.user
,
6277 &offset
, &ice
->state
.last_res
.index_buffer
);
6279 struct iris_resource
*res
= (void *) draw
->index
.resource
;
6280 res
->bind_history
|= PIPE_BIND_INDEX_BUFFER
;
6282 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
,
6283 draw
->index
.resource
);
6287 struct iris_genx_state
*genx
= ice
->state
.genx
;
6288 struct iris_bo
*bo
= iris_resource_bo(ice
->state
.last_res
.index_buffer
);
6290 uint32_t ib_packet
[GENX(3DSTATE_INDEX_BUFFER_length
)];
6291 iris_pack_command(GENX(3DSTATE_INDEX_BUFFER
), ib_packet
, ib
) {
6292 ib
.IndexFormat
= draw
->index_size
>> 1;
6293 ib
.MOCS
= iris_mocs(bo
, &batch
->screen
->isl_dev
);
6294 ib
.BufferSize
= bo
->size
- offset
;
6295 ib
.BufferStartingAddress
= ro_bo(NULL
, bo
->gtt_offset
+ offset
);
6298 if (memcmp(genx
->last_index_buffer
, ib_packet
, sizeof(ib_packet
)) != 0) {
6299 memcpy(genx
->last_index_buffer
, ib_packet
, sizeof(ib_packet
));
6300 iris_batch_emit(batch
, ib_packet
, sizeof(ib_packet
));
6301 iris_use_pinned_bo(batch
, bo
, false);
6305 /* The VF cache key only uses 32-bits, see vertex buffer comment above */
6306 uint16_t high_bits
= bo
->gtt_offset
>> 32ull;
6307 if (high_bits
!= ice
->state
.last_index_bo_high_bits
) {
6308 iris_emit_pipe_control_flush(batch
,
6309 "workaround: VF cache 32-bit key [IB]",
6310 PIPE_CONTROL_VF_CACHE_INVALIDATE
|
6311 PIPE_CONTROL_CS_STALL
);
6312 ice
->state
.last_index_bo_high_bits
= high_bits
;
6317 #define _3DPRIM_END_OFFSET 0x2420
6318 #define _3DPRIM_START_VERTEX 0x2430
6319 #define _3DPRIM_VERTEX_COUNT 0x2434
6320 #define _3DPRIM_INSTANCE_COUNT 0x2438
6321 #define _3DPRIM_START_INSTANCE 0x243C
6322 #define _3DPRIM_BASE_VERTEX 0x2440
6324 if (draw
->indirect
) {
6325 if (draw
->indirect
->indirect_draw_count
) {
6326 use_predicate
= true;
6328 struct iris_bo
*draw_count_bo
=
6329 iris_resource_bo(draw
->indirect
->indirect_draw_count
);
6330 unsigned draw_count_offset
=
6331 draw
->indirect
->indirect_draw_count_offset
;
6333 iris_emit_pipe_control_flush(batch
,
6334 "ensure indirect draw buffer is flushed",
6335 PIPE_CONTROL_FLUSH_ENABLE
);
6337 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
) {
6338 struct gen_mi_builder b
;
6339 gen_mi_builder_init(&b
, batch
);
6341 /* comparison = draw id < draw count */
6342 struct gen_mi_value comparison
=
6343 gen_mi_ult(&b
, gen_mi_imm(draw
->drawid
),
6344 gen_mi_mem32(ro_bo(draw_count_bo
,
6345 draw_count_offset
)));
6347 /* predicate = comparison & conditional rendering predicate */
6348 gen_mi_store(&b
, gen_mi_reg32(MI_PREDICATE_RESULT
),
6349 gen_mi_iand(&b
, comparison
,
6350 gen_mi_reg32(CS_GPR(15))));
6352 uint32_t mi_predicate
;
6354 /* Upload the id of the current primitive to MI_PREDICATE_SRC1. */
6355 iris_load_register_imm64(batch
, MI_PREDICATE_SRC1
, draw
->drawid
);
6356 /* Upload the current draw count from the draw parameters buffer
6357 * to MI_PREDICATE_SRC0.
6359 iris_load_register_mem32(batch
, MI_PREDICATE_SRC0
,
6360 draw_count_bo
, draw_count_offset
);
6361 /* Zero the top 32-bits of MI_PREDICATE_SRC0 */
6362 iris_load_register_imm32(batch
, MI_PREDICATE_SRC0
+ 4, 0);
6364 if (draw
->drawid
== 0) {
6365 mi_predicate
= MI_PREDICATE
| MI_PREDICATE_LOADOP_LOADINV
|
6366 MI_PREDICATE_COMBINEOP_SET
|
6367 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
;
6369 /* While draw_index < draw_count the predicate's result will be
6370 * (draw_index == draw_count) ^ TRUE = TRUE
6371 * When draw_index == draw_count the result is
6372 * (TRUE) ^ TRUE = FALSE
6373 * After this all results will be:
6374 * (FALSE) ^ FALSE = FALSE
6376 mi_predicate
= MI_PREDICATE
| MI_PREDICATE_LOADOP_LOAD
|
6377 MI_PREDICATE_COMBINEOP_XOR
|
6378 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
;
6380 iris_batch_emit(batch
, &mi_predicate
, sizeof(uint32_t));
6383 struct iris_bo
*bo
= iris_resource_bo(draw
->indirect
->buffer
);
6386 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6387 lrm
.RegisterAddress
= _3DPRIM_VERTEX_COUNT
;
6388 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 0);
6390 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6391 lrm
.RegisterAddress
= _3DPRIM_INSTANCE_COUNT
;
6392 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 4);
6394 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6395 lrm
.RegisterAddress
= _3DPRIM_START_VERTEX
;
6396 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 8);
6398 if (draw
->index_size
) {
6399 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6400 lrm
.RegisterAddress
= _3DPRIM_BASE_VERTEX
;
6401 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
6403 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6404 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
6405 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 16);
6408 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6409 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
6410 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
6412 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
6413 lri
.RegisterOffset
= _3DPRIM_BASE_VERTEX
;
6417 } else if (draw
->count_from_stream_output
) {
6418 struct iris_stream_output_target
*so
=
6419 (void *) draw
->count_from_stream_output
;
6421 /* XXX: Replace with actual cache tracking */
6422 iris_emit_pipe_control_flush(batch
,
6423 "draw count from stream output stall",
6424 PIPE_CONTROL_CS_STALL
);
6426 struct gen_mi_builder b
;
6427 gen_mi_builder_init(&b
, batch
);
6429 struct iris_address addr
=
6430 ro_bo(iris_resource_bo(so
->offset
.res
), so
->offset
.offset
);
6431 struct gen_mi_value offset
=
6432 gen_mi_iadd_imm(&b
, gen_mi_mem32(addr
), -so
->base
.buffer_offset
);
6434 gen_mi_store(&b
, gen_mi_reg32(_3DPRIM_VERTEX_COUNT
),
6435 gen_mi_udiv32_imm(&b
, offset
, so
->stride
));
6437 _iris_emit_lri(batch
, _3DPRIM_START_VERTEX
, 0);
6438 _iris_emit_lri(batch
, _3DPRIM_BASE_VERTEX
, 0);
6439 _iris_emit_lri(batch
, _3DPRIM_START_INSTANCE
, 0);
6440 _iris_emit_lri(batch
, _3DPRIM_INSTANCE_COUNT
, draw
->instance_count
);
6443 iris_emit_cmd(batch
, GENX(3DPRIMITIVE
), prim
) {
6444 prim
.VertexAccessType
= draw
->index_size
> 0 ? RANDOM
: SEQUENTIAL
;
6445 prim
.PredicateEnable
= use_predicate
;
6447 if (draw
->indirect
|| draw
->count_from_stream_output
) {
6448 prim
.IndirectParameterEnable
= true;
6450 prim
.StartInstanceLocation
= draw
->start_instance
;
6451 prim
.InstanceCount
= draw
->instance_count
;
6452 prim
.VertexCountPerInstance
= draw
->count
;
6454 prim
.StartVertexLocation
= draw
->start
;
6456 if (draw
->index_size
) {
6457 prim
.BaseVertexLocation
+= draw
->index_bias
;
6459 prim
.StartVertexLocation
+= draw
->index_bias
;
6466 iris_upload_compute_state(struct iris_context
*ice
,
6467 struct iris_batch
*batch
,
6468 const struct pipe_grid_info
*grid
)
6470 const uint64_t dirty
= ice
->state
.dirty
;
6471 struct iris_screen
*screen
= batch
->screen
;
6472 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
6473 struct iris_binder
*binder
= &ice
->state
.binder
;
6474 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_COMPUTE
];
6475 struct iris_compiled_shader
*shader
=
6476 ice
->shaders
.prog
[MESA_SHADER_COMPUTE
];
6477 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
6478 struct brw_cs_prog_data
*cs_prog_data
= (void *) prog_data
;
6480 const uint32_t group_size
= grid
->block
[0] * grid
->block
[1] * grid
->block
[2];
6481 const unsigned threads
= DIV_ROUND_UP(group_size
, cs_prog_data
->simd_size
);
6483 /* Always pin the binder. If we're emitting new binding table pointers,
6484 * we need it. If not, we're probably inheriting old tables via the
6485 * context, and need it anyway. Since true zero-bindings cases are
6486 * practically non-existent, just pin it and avoid last_res tracking.
6488 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
6490 if ((dirty
& IRIS_DIRTY_CONSTANTS_CS
) && shs
->sysvals_need_upload
)
6491 upload_sysvals(ice
, MESA_SHADER_COMPUTE
);
6493 if (dirty
& IRIS_DIRTY_BINDINGS_CS
)
6494 iris_populate_binding_table(ice
, batch
, MESA_SHADER_COMPUTE
, false);
6496 if (dirty
& IRIS_DIRTY_SAMPLER_STATES_CS
)
6497 iris_upload_sampler_states(ice
, MESA_SHADER_COMPUTE
);
6499 iris_use_optional_res(batch
, shs
->sampler_table
.res
, false);
6500 iris_use_pinned_bo(batch
, iris_resource_bo(shader
->assembly
.res
), false);
6502 if (ice
->state
.need_border_colors
)
6503 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
6506 genX(invalidate_aux_map_state
)(batch
);
6509 if (dirty
& IRIS_DIRTY_CS
) {
6510 /* The MEDIA_VFE_STATE documentation for Gen8+ says:
6512 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
6513 * the only bits that are changed are scoreboard related: Scoreboard
6514 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard Delta. For
6515 * these scoreboard related states, a MEDIA_STATE_FLUSH is
6518 iris_emit_pipe_control_flush(batch
,
6519 "workaround: stall before MEDIA_VFE_STATE",
6520 PIPE_CONTROL_CS_STALL
);
6522 iris_emit_cmd(batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
6523 if (prog_data
->total_scratch
) {
6524 struct iris_bo
*bo
=
6525 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
6526 MESA_SHADER_COMPUTE
);
6527 vfe
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
6528 vfe
.ScratchSpaceBasePointer
= rw_bo(bo
, 0);
6531 vfe
.MaximumNumberofThreads
=
6532 devinfo
->max_cs_threads
* screen
->subslice_total
- 1;
6534 vfe
.ResetGatewayTimer
=
6535 Resettingrelativetimerandlatchingtheglobaltimestamp
;
6538 vfe
.BypassGatewayControl
= true;
6540 vfe
.NumberofURBEntries
= 2;
6541 vfe
.URBEntryAllocationSize
= 2;
6543 vfe
.CURBEAllocationSize
=
6544 ALIGN(cs_prog_data
->push
.per_thread
.regs
* threads
+
6545 cs_prog_data
->push
.cross_thread
.regs
, 2);
6549 /* TODO: Combine subgroup-id with cbuf0 so we can push regular uniforms */
6550 if (dirty
& IRIS_DIRTY_CS
) {
6551 uint32_t curbe_data_offset
= 0;
6552 assert(cs_prog_data
->push
.cross_thread
.dwords
== 0 &&
6553 cs_prog_data
->push
.per_thread
.dwords
== 1 &&
6554 cs_prog_data
->base
.param
[0] == BRW_PARAM_BUILTIN_SUBGROUP_ID
);
6555 const unsigned push_const_size
=
6556 brw_cs_push_const_total_size(cs_prog_data
, threads
);
6557 uint32_t *curbe_data_map
=
6558 stream_state(batch
, ice
->state
.dynamic_uploader
,
6559 &ice
->state
.last_res
.cs_thread_ids
,
6560 ALIGN(push_const_size
, 64), 64,
6561 &curbe_data_offset
);
6562 assert(curbe_data_map
);
6563 memset(curbe_data_map
, 0x5a, ALIGN(push_const_size
, 64));
6564 iris_fill_cs_push_const_buffer(cs_prog_data
, threads
, curbe_data_map
);
6566 iris_emit_cmd(batch
, GENX(MEDIA_CURBE_LOAD
), curbe
) {
6567 curbe
.CURBETotalDataLength
= ALIGN(push_const_size
, 64);
6568 curbe
.CURBEDataStartAddress
= curbe_data_offset
;
6572 if (dirty
& (IRIS_DIRTY_SAMPLER_STATES_CS
|
6573 IRIS_DIRTY_BINDINGS_CS
|
6574 IRIS_DIRTY_CONSTANTS_CS
|
6576 uint32_t desc
[GENX(INTERFACE_DESCRIPTOR_DATA_length
)];
6578 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), desc
, idd
) {
6579 idd
.SamplerStatePointer
= shs
->sampler_table
.offset
;
6580 idd
.BindingTablePointer
= binder
->bt_offset
[MESA_SHADER_COMPUTE
];
6581 idd
.NumberofThreadsinGPGPUThreadGroup
= threads
;
6584 for (int i
= 0; i
< GENX(INTERFACE_DESCRIPTOR_DATA_length
); i
++)
6585 desc
[i
] |= ((uint32_t *) shader
->derived_data
)[i
];
6587 iris_emit_cmd(batch
, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD
), load
) {
6588 load
.InterfaceDescriptorTotalLength
=
6589 GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t);
6590 load
.InterfaceDescriptorDataStartAddress
=
6591 emit_state(batch
, ice
->state
.dynamic_uploader
,
6592 &ice
->state
.last_res
.cs_desc
, desc
, sizeof(desc
), 64);
6596 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
6597 uint32_t right_mask
;
6600 right_mask
= ~0u >> (32 - remainder
);
6602 right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
6604 #define GPGPU_DISPATCHDIMX 0x2500
6605 #define GPGPU_DISPATCHDIMY 0x2504
6606 #define GPGPU_DISPATCHDIMZ 0x2508
6608 if (grid
->indirect
) {
6609 struct iris_state_ref
*grid_size
= &ice
->state
.grid_size
;
6610 struct iris_bo
*bo
= iris_resource_bo(grid_size
->res
);
6611 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6612 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMX
;
6613 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 0);
6615 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6616 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMY
;
6617 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 4);
6619 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
6620 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMZ
;
6621 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 8);
6625 iris_emit_cmd(batch
, GENX(GPGPU_WALKER
), ggw
) {
6626 ggw
.IndirectParameterEnable
= grid
->indirect
!= NULL
;
6627 ggw
.SIMDSize
= cs_prog_data
->simd_size
/ 16;
6628 ggw
.ThreadDepthCounterMaximum
= 0;
6629 ggw
.ThreadHeightCounterMaximum
= 0;
6630 ggw
.ThreadWidthCounterMaximum
= threads
- 1;
6631 ggw
.ThreadGroupIDXDimension
= grid
->grid
[0];
6632 ggw
.ThreadGroupIDYDimension
= grid
->grid
[1];
6633 ggw
.ThreadGroupIDZDimension
= grid
->grid
[2];
6634 ggw
.RightExecutionMask
= right_mask
;
6635 ggw
.BottomExecutionMask
= 0xffffffff;
6638 iris_emit_cmd(batch
, GENX(MEDIA_STATE_FLUSH
), msf
);
6640 if (!batch
->contains_draw
) {
6641 iris_restore_compute_saved_bos(ice
, batch
, grid
);
6642 batch
->contains_draw
= true;
6647 * State module teardown.
6650 iris_destroy_state(struct iris_context
*ice
)
6652 struct iris_genx_state
*genx
= ice
->state
.genx
;
6654 pipe_resource_reference(&ice
->draw
.draw_params
.res
, NULL
);
6655 pipe_resource_reference(&ice
->draw
.derived_draw_params
.res
, NULL
);
6657 /* Loop over all VBOs, including ones for draw parameters */
6658 for (unsigned i
= 0; i
< ARRAY_SIZE(genx
->vertex_buffers
); i
++) {
6659 pipe_resource_reference(&genx
->vertex_buffers
[i
].resource
, NULL
);
6662 free(ice
->state
.genx
);
6664 for (int i
= 0; i
< 4; i
++) {
6665 pipe_so_target_reference(&ice
->state
.so_target
[i
], NULL
);
6668 for (unsigned i
= 0; i
< ice
->state
.framebuffer
.nr_cbufs
; i
++) {
6669 pipe_surface_reference(&ice
->state
.framebuffer
.cbufs
[i
], NULL
);
6671 pipe_surface_reference(&ice
->state
.framebuffer
.zsbuf
, NULL
);
6673 for (int stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
6674 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
6675 pipe_resource_reference(&shs
->sampler_table
.res
, NULL
);
6676 for (int i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
6677 pipe_resource_reference(&shs
->constbuf
[i
].buffer
, NULL
);
6678 pipe_resource_reference(&shs
->constbuf_surf_state
[i
].res
, NULL
);
6680 for (int i
= 0; i
< PIPE_MAX_SHADER_IMAGES
; i
++) {
6681 pipe_resource_reference(&shs
->image
[i
].base
.resource
, NULL
);
6682 pipe_resource_reference(&shs
->image
[i
].surface_state
.ref
.res
, NULL
);
6683 free(shs
->image
[i
].surface_state
.cpu
);
6685 for (int i
= 0; i
< PIPE_MAX_SHADER_BUFFERS
; i
++) {
6686 pipe_resource_reference(&shs
->ssbo
[i
].buffer
, NULL
);
6687 pipe_resource_reference(&shs
->ssbo_surf_state
[i
].res
, NULL
);
6689 for (int i
= 0; i
< IRIS_MAX_TEXTURE_SAMPLERS
; i
++) {
6690 pipe_sampler_view_reference((struct pipe_sampler_view
**)
6691 &shs
->textures
[i
], NULL
);
6695 pipe_resource_reference(&ice
->state
.grid_size
.res
, NULL
);
6696 pipe_resource_reference(&ice
->state
.grid_surf_state
.res
, NULL
);
6698 pipe_resource_reference(&ice
->state
.null_fb
.res
, NULL
);
6699 pipe_resource_reference(&ice
->state
.unbound_tex
.res
, NULL
);
6701 pipe_resource_reference(&ice
->state
.last_res
.cc_vp
, NULL
);
6702 pipe_resource_reference(&ice
->state
.last_res
.sf_cl_vp
, NULL
);
6703 pipe_resource_reference(&ice
->state
.last_res
.color_calc
, NULL
);
6704 pipe_resource_reference(&ice
->state
.last_res
.scissor
, NULL
);
6705 pipe_resource_reference(&ice
->state
.last_res
.blend
, NULL
);
6706 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
, NULL
);
6707 pipe_resource_reference(&ice
->state
.last_res
.cs_thread_ids
, NULL
);
6708 pipe_resource_reference(&ice
->state
.last_res
.cs_desc
, NULL
);
6711 /* ------------------------------------------------------------------- */
6714 iris_rebind_buffer(struct iris_context
*ice
,
6715 struct iris_resource
*res
)
6717 struct pipe_context
*ctx
= &ice
->ctx
;
6718 struct iris_genx_state
*genx
= ice
->state
.genx
;
6720 assert(res
->base
.target
== PIPE_BUFFER
);
6722 /* Buffers can't be framebuffer attachments, nor display related,
6723 * and we don't have upstream Clover support.
6725 assert(!(res
->bind_history
& (PIPE_BIND_DEPTH_STENCIL
|
6726 PIPE_BIND_RENDER_TARGET
|
6727 PIPE_BIND_BLENDABLE
|
6728 PIPE_BIND_DISPLAY_TARGET
|
6730 PIPE_BIND_COMPUTE_RESOURCE
|
6731 PIPE_BIND_GLOBAL
)));
6733 if (res
->bind_history
& PIPE_BIND_VERTEX_BUFFER
) {
6734 uint64_t bound_vbs
= ice
->state
.bound_vertex_buffers
;
6736 const int i
= u_bit_scan64(&bound_vbs
);
6737 struct iris_vertex_buffer_state
*state
= &genx
->vertex_buffers
[i
];
6739 /* Update the CPU struct */
6740 STATIC_ASSERT(GENX(VERTEX_BUFFER_STATE_BufferStartingAddress_start
) == 32);
6741 STATIC_ASSERT(GENX(VERTEX_BUFFER_STATE_BufferStartingAddress_bits
) == 64);
6742 uint64_t *addr
= (uint64_t *) &state
->state
[1];
6743 struct iris_bo
*bo
= iris_resource_bo(state
->resource
);
6745 if (*addr
!= bo
->gtt_offset
+ state
->offset
) {
6746 *addr
= bo
->gtt_offset
+ state
->offset
;
6747 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
6752 /* We don't need to handle PIPE_BIND_INDEX_BUFFER here: we re-emit
6753 * the 3DSTATE_INDEX_BUFFER packet whenever the address changes.
6755 * There is also no need to handle these:
6756 * - PIPE_BIND_COMMAND_ARGS_BUFFER (emitted for every indirect draw)
6757 * - PIPE_BIND_QUERY_BUFFER (no persistent state references)
6760 if (res
->bind_history
& PIPE_BIND_STREAM_OUTPUT
) {
6761 /* XXX: be careful about resetting vs appending... */
6765 for (int s
= MESA_SHADER_VERTEX
; s
< MESA_SHADER_STAGES
; s
++) {
6766 struct iris_shader_state
*shs
= &ice
->state
.shaders
[s
];
6767 enum pipe_shader_type p_stage
= stage_to_pipe(s
);
6769 if (!(res
->bind_stages
& (1 << s
)))
6772 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
6773 /* Skip constant buffer 0, it's for regular uniforms, not UBOs */
6774 uint32_t bound_cbufs
= shs
->bound_cbufs
& ~1u;
6775 while (bound_cbufs
) {
6776 const int i
= u_bit_scan(&bound_cbufs
);
6777 struct pipe_shader_buffer
*cbuf
= &shs
->constbuf
[i
];
6778 struct iris_state_ref
*surf_state
= &shs
->constbuf_surf_state
[i
];
6780 if (res
->bo
== iris_resource_bo(cbuf
->buffer
)) {
6781 pipe_resource_reference(&surf_state
->res
, NULL
);
6782 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< s
;
6787 if (res
->bind_history
& PIPE_BIND_SHADER_BUFFER
) {
6788 uint32_t bound_ssbos
= shs
->bound_ssbos
;
6789 while (bound_ssbos
) {
6790 const int i
= u_bit_scan(&bound_ssbos
);
6791 struct pipe_shader_buffer
*ssbo
= &shs
->ssbo
[i
];
6793 if (res
->bo
== iris_resource_bo(ssbo
->buffer
)) {
6794 struct pipe_shader_buffer buf
= {
6795 .buffer
= &res
->base
,
6796 .buffer_offset
= ssbo
->buffer_offset
,
6797 .buffer_size
= ssbo
->buffer_size
,
6799 iris_set_shader_buffers(ctx
, p_stage
, i
, 1, &buf
,
6800 (shs
->writable_ssbos
>> i
) & 1);
6805 if (res
->bind_history
& PIPE_BIND_SAMPLER_VIEW
) {
6806 uint32_t bound_sampler_views
= shs
->bound_sampler_views
;
6807 while (bound_sampler_views
) {
6808 const int i
= u_bit_scan(&bound_sampler_views
);
6809 struct iris_sampler_view
*isv
= shs
->textures
[i
];
6810 struct iris_bo
*bo
= isv
->res
->bo
;
6812 if (update_surface_state_addrs(ice
->state
.surface_uploader
,
6813 &isv
->surface_state
, bo
)) {
6814 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< s
;
6819 if (res
->bind_history
& PIPE_BIND_SHADER_IMAGE
) {
6820 uint32_t bound_image_views
= shs
->bound_image_views
;
6821 while (bound_image_views
) {
6822 const int i
= u_bit_scan(&bound_image_views
);
6823 struct iris_image_view
*iv
= &shs
->image
[i
];
6824 struct iris_bo
*bo
= iris_resource_bo(iv
->base
.resource
);
6826 if (update_surface_state_addrs(ice
->state
.surface_uploader
,
6827 &iv
->surface_state
, bo
)) {
6828 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< s
;
6835 /* ------------------------------------------------------------------- */
6838 flags_to_post_sync_op(uint32_t flags
)
6840 if (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
)
6841 return WriteImmediateData
;
6843 if (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
)
6844 return WritePSDepthCount
;
6846 if (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
)
6847 return WriteTimestamp
;
6853 * Do the given flags have a Post Sync or LRI Post Sync operation?
6855 static enum pipe_control_flags
6856 get_post_sync_flags(enum pipe_control_flags flags
)
6858 flags
&= PIPE_CONTROL_WRITE_IMMEDIATE
|
6859 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
6860 PIPE_CONTROL_WRITE_TIMESTAMP
|
6861 PIPE_CONTROL_LRI_POST_SYNC_OP
;
6863 /* Only one "Post Sync Op" is allowed, and it's mutually exclusive with
6864 * "LRI Post Sync Operation". So more than one bit set would be illegal.
6866 assert(util_bitcount(flags
) <= 1);
6871 #define IS_COMPUTE_PIPELINE(batch) (batch->name == IRIS_BATCH_COMPUTE)
6874 * Emit a series of PIPE_CONTROL commands, taking into account any
6875 * workarounds necessary to actually accomplish the caller's request.
6877 * Unless otherwise noted, spec quotations in this function come from:
6879 * Synchronization of the 3D Pipeline > PIPE_CONTROL Command > Programming
6880 * Restrictions for PIPE_CONTROL.
6882 * You should not use this function directly. Use the helpers in
6883 * iris_pipe_control.c instead, which may split the pipe control further.
6886 iris_emit_raw_pipe_control(struct iris_batch
*batch
,
6893 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
6894 enum pipe_control_flags post_sync_flags
= get_post_sync_flags(flags
);
6895 enum pipe_control_flags non_lri_post_sync_flags
=
6896 post_sync_flags
& ~PIPE_CONTROL_LRI_POST_SYNC_OP
;
6898 /* Recursive PIPE_CONTROL workarounds --------------------------------
6899 * (http://knowyourmeme.com/memes/xzibit-yo-dawg)
6901 * We do these first because we want to look at the original operation,
6902 * rather than any workarounds we set.
6904 if (GEN_GEN
== 9 && (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
)) {
6905 /* The PIPE_CONTROL "VF Cache Invalidation Enable" bit description
6906 * lists several workarounds:
6908 * "Project: SKL, KBL, BXT
6910 * If the VF Cache Invalidation Enable is set to a 1 in a
6911 * PIPE_CONTROL, a separate Null PIPE_CONTROL, all bitfields
6912 * sets to 0, with the VF Cache Invalidation Enable set to 0
6913 * needs to be sent prior to the PIPE_CONTROL with VF Cache
6914 * Invalidation Enable set to a 1."
6916 iris_emit_raw_pipe_control(batch
,
6917 "workaround: recursive VF cache invalidate",
6921 /* GEN:BUG:1409226450, Wait for EU to be idle before pipe control which
6922 * invalidates the instruction cache
6924 if (GEN_GEN
== 12 && (flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
)) {
6925 iris_emit_raw_pipe_control(batch
,
6926 "workaround: CS stall before instruction "
6928 PIPE_CONTROL_CS_STALL
|
6929 PIPE_CONTROL_STALL_AT_SCOREBOARD
, bo
, offset
,
6933 if ((GEN_GEN
== 9 || (GEN_GEN
== 12 && devinfo
->revision
== 0 /* A0*/)) &&
6934 IS_COMPUTE_PIPELINE(batch
) && post_sync_flags
) {
6935 /* Project: SKL / Argument: LRI Post Sync Operation [23]
6937 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
6938 * programmed prior to programming a PIPECONTROL command with "LRI
6939 * Post Sync Operation" in GPGPU mode of operation (i.e when
6940 * PIPELINE_SELECT command is set to GPGPU mode of operation)."
6942 * The same text exists a few rows below for Post Sync Op.
6944 * On Gen12 this is GEN:BUG:1607156449.
6946 iris_emit_raw_pipe_control(batch
,
6947 "workaround: CS stall before gpgpu post-sync",
6948 PIPE_CONTROL_CS_STALL
, bo
, offset
, imm
);
6951 /* "Flush Types" workarounds ---------------------------------------------
6952 * We do these now because they may add post-sync operations or CS stalls.
6955 if (GEN_GEN
< 11 && flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) {
6956 /* Project: BDW, SKL+ (stopping at CNL) / Argument: VF Invalidate
6958 * "'Post Sync Operation' must be enabled to 'Write Immediate Data' or
6959 * 'Write PS Depth Count' or 'Write Timestamp'."
6962 flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6963 post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6964 non_lri_post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
6965 bo
= batch
->screen
->workaround_bo
;
6969 if (flags
& PIPE_CONTROL_DEPTH_STALL
) {
6970 /* From the PIPE_CONTROL instruction table, bit 13 (Depth Stall Enable):
6972 * "This bit must be DISABLED for operations other than writing
6975 * This seems like nonsense. An Ivybridge workaround requires us to
6976 * emit a PIPE_CONTROL with a depth stall and write immediate post-sync
6977 * operation. Gen8+ requires us to emit depth stalls and depth cache
6978 * flushes together. So, it's hard to imagine this means anything other
6979 * than "we originally intended this to be used for PS_DEPTH_COUNT".
6981 * We ignore the supposed restriction and do nothing.
6985 if (flags
& (PIPE_CONTROL_RENDER_TARGET_FLUSH
|
6986 PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
6987 /* From the PIPE_CONTROL instruction table, bit 12 and bit 1:
6989 * "This bit must be DISABLED for End-of-pipe (Read) fences,
6990 * PS_DEPTH_COUNT or TIMESTAMP queries."
6992 * TODO: Implement end-of-pipe checking.
6994 assert(!(post_sync_flags
& (PIPE_CONTROL_WRITE_DEPTH_COUNT
|
6995 PIPE_CONTROL_WRITE_TIMESTAMP
)));
6998 if (GEN_GEN
< 11 && (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
6999 /* From the PIPE_CONTROL instruction table, bit 1:
7001 * "This bit is ignored if Depth Stall Enable is set.
7002 * Further, the render cache is not flushed even if Write Cache
7003 * Flush Enable bit is set."
7005 * We assert that the caller doesn't do this combination, to try and
7006 * prevent mistakes. It shouldn't hurt the GPU, though.
7008 * We skip this check on Gen11+ as the "Stall at Pixel Scoreboard"
7009 * and "Render Target Flush" combo is explicitly required for BTI
7010 * update workarounds.
7012 assert(!(flags
& (PIPE_CONTROL_DEPTH_STALL
|
7013 PIPE_CONTROL_RENDER_TARGET_FLUSH
)));
7016 /* PIPE_CONTROL page workarounds ------------------------------------- */
7018 if (GEN_GEN
<= 8 && (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
)) {
7019 /* From the PIPE_CONTROL page itself:
7022 * Restriction: Pipe_control with CS-stall bit set must be issued
7023 * before a pipe-control command that has the State Cache
7024 * Invalidate bit set."
7026 flags
|= PIPE_CONTROL_CS_STALL
;
7029 if (flags
& PIPE_CONTROL_FLUSH_LLC
) {
7030 /* From the PIPE_CONTROL instruction table, bit 26 (Flush LLC):
7033 * SW must always program Post-Sync Operation to "Write Immediate
7034 * Data" when Flush LLC is set."
7036 * For now, we just require the caller to do it.
7038 assert(flags
& PIPE_CONTROL_WRITE_IMMEDIATE
);
7041 /* "Post-Sync Operation" workarounds -------------------------------- */
7043 /* Project: All / Argument: Global Snapshot Count Reset [19]
7045 * "This bit must not be exercised on any product.
7046 * Requires stall bit ([20] of DW1) set."
7048 * We don't use this, so we just assert that it isn't used. The
7049 * PIPE_CONTROL instruction page indicates that they intended this
7050 * as a debug feature and don't think it is useful in production,
7051 * but it may actually be usable, should we ever want to.
7053 assert((flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) == 0);
7055 if (flags
& (PIPE_CONTROL_MEDIA_STATE_CLEAR
|
7056 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
)) {
7057 /* Project: All / Arguments:
7059 * - Generic Media State Clear [16]
7060 * - Indirect State Pointers Disable [16]
7062 * "Requires stall bit ([20] of DW1) set."
7064 * Also, the PIPE_CONTROL instruction table, bit 16 (Generic Media
7065 * State Clear) says:
7067 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
7068 * programmed prior to programming a PIPECONTROL command with "Media
7069 * State Clear" set in GPGPU mode of operation"
7071 * This is a subset of the earlier rule, so there's nothing to do.
7073 flags
|= PIPE_CONTROL_CS_STALL
;
7076 if (flags
& PIPE_CONTROL_STORE_DATA_INDEX
) {
7077 /* Project: All / Argument: Store Data Index
7079 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
7082 * For now, we just assert that the caller does this. We might want to
7083 * automatically add a write to the workaround BO...
7085 assert(non_lri_post_sync_flags
!= 0);
7088 if (flags
& PIPE_CONTROL_SYNC_GFDT
) {
7089 /* Project: All / Argument: Sync GFDT
7091 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
7092 * than '0' or 0x2520[13] must be set."
7094 * For now, we just assert that the caller does this.
7096 assert(non_lri_post_sync_flags
!= 0);
7099 if (flags
& PIPE_CONTROL_TLB_INVALIDATE
) {
7100 /* Project: IVB+ / Argument: TLB inv
7102 * "Requires stall bit ([20] of DW1) set."
7104 * Also, from the PIPE_CONTROL instruction table:
7107 * Post Sync Operation or CS stall must be set to ensure a TLB
7108 * invalidation occurs. Otherwise no cycle will occur to the TLB
7109 * cache to invalidate."
7111 * This is not a subset of the earlier rule, so there's nothing to do.
7113 flags
|= PIPE_CONTROL_CS_STALL
;
7116 if (GEN_GEN
>= 12 && ((flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) ||
7117 (flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
))) {
7118 /* From the PIPE_CONTROL instruction table, bit 28 (Tile Cache Flush
7121 * Unified Cache (Tile Cache Disabled):
7123 * When the Color and Depth (Z) streams are enabled to be cached in
7124 * the DC space of L2, Software must use "Render Target Cache Flush
7125 * Enable" and "Depth Cache Flush Enable" along with "Tile Cache
7126 * Flush" for getting the color and depth (Z) write data to be
7127 * globally observable. In this mode of operation it is not required
7128 * to set "CS Stall" upon setting "Tile Cache Flush" bit.
7130 flags
|= PIPE_CONTROL_TILE_CACHE_FLUSH
;
7133 if (GEN_GEN
== 9 && devinfo
->gt
== 4) {
7134 /* TODO: The big Skylake GT4 post sync op workaround */
7137 /* "GPGPU specific workarounds" (both post-sync and flush) ------------ */
7139 if (IS_COMPUTE_PIPELINE(batch
)) {
7140 if (GEN_GEN
>= 9 && (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
)) {
7141 /* Project: SKL+ / Argument: Tex Invalidate
7142 * "Requires stall bit ([20] of DW) set for all GPGPU Workloads."
7144 flags
|= PIPE_CONTROL_CS_STALL
;
7147 if (GEN_GEN
== 8 && (post_sync_flags
||
7148 (flags
& (PIPE_CONTROL_NOTIFY_ENABLE
|
7149 PIPE_CONTROL_DEPTH_STALL
|
7150 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
7151 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
7152 PIPE_CONTROL_DATA_CACHE_FLUSH
)))) {
7153 /* Project: BDW / Arguments:
7155 * - LRI Post Sync Operation [23]
7156 * - Post Sync Op [15:14]
7158 * - Depth Stall [13]
7159 * - Render Target Cache Flush [12]
7160 * - Depth Cache Flush [0]
7161 * - DC Flush Enable [5]
7163 * "Requires stall bit ([20] of DW) set for all GPGPU and Media
7166 flags
|= PIPE_CONTROL_CS_STALL
;
7168 /* Also, from the PIPE_CONTROL instruction table, bit 20:
7171 * This bit must be always set when PIPE_CONTROL command is
7172 * programmed by GPGPU and MEDIA workloads, except for the cases
7173 * when only Read Only Cache Invalidation bits are set (State
7174 * Cache Invalidation Enable, Instruction cache Invalidation
7175 * Enable, Texture Cache Invalidation Enable, Constant Cache
7176 * Invalidation Enable). This is to WA FFDOP CG issue, this WA
7177 * need not implemented when FF_DOP_CG is disable via "Fixed
7178 * Function DOP Clock Gate Disable" bit in RC_PSMI_CTRL register."
7180 * It sounds like we could avoid CS stalls in some cases, but we
7181 * don't currently bother. This list isn't exactly the list above,
7187 /* "Stall" workarounds ----------------------------------------------
7188 * These have to come after the earlier ones because we may have added
7189 * some additional CS stalls above.
7192 if (GEN_GEN
< 9 && (flags
& PIPE_CONTROL_CS_STALL
)) {
7193 /* Project: PRE-SKL, VLV, CHV
7195 * "[All Stepping][All SKUs]:
7197 * One of the following must also be set:
7199 * - Render Target Cache Flush Enable ([12] of DW1)
7200 * - Depth Cache Flush Enable ([0] of DW1)
7201 * - Stall at Pixel Scoreboard ([1] of DW1)
7202 * - Depth Stall ([13] of DW1)
7203 * - Post-Sync Operation ([13] of DW1)
7204 * - DC Flush Enable ([5] of DW1)"
7206 * If we don't already have one of those bits set, we choose to add
7207 * "Stall at Pixel Scoreboard". Some of the other bits require a
7208 * CS stall as a workaround (see above), which would send us into
7209 * an infinite recursion of PIPE_CONTROLs. "Stall at Pixel Scoreboard"
7210 * appears to be safe, so we choose that.
7212 const uint32_t wa_bits
= PIPE_CONTROL_RENDER_TARGET_FLUSH
|
7213 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
7214 PIPE_CONTROL_WRITE_IMMEDIATE
|
7215 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
7216 PIPE_CONTROL_WRITE_TIMESTAMP
|
7217 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
7218 PIPE_CONTROL_DEPTH_STALL
|
7219 PIPE_CONTROL_DATA_CACHE_FLUSH
;
7220 if (!(flags
& wa_bits
))
7221 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
7224 if (GEN_GEN
>= 12 && (flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
)) {
7225 /* GEN:BUG:1409600907:
7227 * "PIPE_CONTROL with Depth Stall Enable bit must be set
7228 * with any PIPE_CONTROL with Depth Flush Enable bit set.
7230 flags
|= PIPE_CONTROL_DEPTH_STALL
;
7233 /* Emit --------------------------------------------------------------- */
7235 if (INTEL_DEBUG
& DEBUG_PIPE_CONTROL
) {
7237 " PC [%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%"PRIx64
"]: %s\n",
7238 (flags
& PIPE_CONTROL_FLUSH_ENABLE
) ? "PipeCon " : "",
7239 (flags
& PIPE_CONTROL_CS_STALL
) ? "CS " : "",
7240 (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
) ? "Scoreboard " : "",
7241 (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) ? "VF " : "",
7242 (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) ? "RT " : "",
7243 (flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
) ? "Const " : "",
7244 (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
) ? "TC " : "",
7245 (flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
) ? "DC " : "",
7246 (flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
) ? "ZFlush " : "",
7247 (flags
& PIPE_CONTROL_DEPTH_STALL
) ? "ZStall " : "",
7248 (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
) ? "State " : "",
7249 (flags
& PIPE_CONTROL_TLB_INVALIDATE
) ? "TLB " : "",
7250 (flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
) ? "Inst " : "",
7251 (flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
) ? "MediaClear " : "",
7252 (flags
& PIPE_CONTROL_NOTIFY_ENABLE
) ? "Notify " : "",
7253 (flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) ?
7255 (flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
) ?
7257 (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
) ? "WriteImm " : "",
7258 (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
) ? "WriteZCount " : "",
7259 (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
) ? "WriteTimestamp " : "",
7260 (flags
& PIPE_CONTROL_FLUSH_HDC
) ? "HDC " : "",
7264 iris_emit_cmd(batch
, GENX(PIPE_CONTROL
), pc
) {
7266 pc
.TileCacheFlushEnable
= flags
& PIPE_CONTROL_TILE_CACHE_FLUSH
;
7269 pc
.HDCPipelineFlushEnable
= flags
& PIPE_CONTROL_FLUSH_HDC
;
7271 pc
.LRIPostSyncOperation
= NoLRIOperation
;
7272 pc
.PipeControlFlushEnable
= flags
& PIPE_CONTROL_FLUSH_ENABLE
;
7273 pc
.DCFlushEnable
= flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
;
7274 pc
.StoreDataIndex
= 0;
7275 pc
.CommandStreamerStallEnable
= flags
& PIPE_CONTROL_CS_STALL
;
7276 pc
.GlobalSnapshotCountReset
=
7277 flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
;
7278 pc
.TLBInvalidate
= flags
& PIPE_CONTROL_TLB_INVALIDATE
;
7279 pc
.GenericMediaStateClear
= flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
;
7280 pc
.StallAtPixelScoreboard
= flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
;
7281 pc
.RenderTargetCacheFlushEnable
=
7282 flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
;
7283 pc
.DepthCacheFlushEnable
= flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
;
7284 pc
.StateCacheInvalidationEnable
=
7285 flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
;
7286 pc
.VFCacheInvalidationEnable
= flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
;
7287 pc
.ConstantCacheInvalidationEnable
=
7288 flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
;
7289 pc
.PostSyncOperation
= flags_to_post_sync_op(flags
);
7290 pc
.DepthStallEnable
= flags
& PIPE_CONTROL_DEPTH_STALL
;
7291 pc
.InstructionCacheInvalidateEnable
=
7292 flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
;
7293 pc
.NotifyEnable
= flags
& PIPE_CONTROL_NOTIFY_ENABLE
;
7294 pc
.IndirectStatePointersDisable
=
7295 flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
;
7296 pc
.TextureCacheInvalidationEnable
=
7297 flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
7298 pc
.Address
= rw_bo(bo
, offset
);
7299 pc
.ImmediateData
= imm
;
7305 * Preemption on Gen9 has to be enabled or disabled in various cases.
7307 * See these workarounds for preemption:
7308 * - WaDisableMidObjectPreemptionForGSLineStripAdj
7309 * - WaDisableMidObjectPreemptionForTrifanOrPolygon
7310 * - WaDisableMidObjectPreemptionForLineLoop
7313 * We don't put this in the vtable because it's only used on Gen9.
7316 gen9_toggle_preemption(struct iris_context
*ice
,
7317 struct iris_batch
*batch
,
7318 const struct pipe_draw_info
*draw
)
7320 struct iris_genx_state
*genx
= ice
->state
.genx
;
7321 bool object_preemption
= true;
7323 /* WaDisableMidObjectPreemptionForGSLineStripAdj
7325 * "WA: Disable mid-draw preemption when draw-call is a linestrip_adj
7326 * and GS is enabled."
7328 if (draw
->mode
== PIPE_PRIM_LINE_STRIP_ADJACENCY
&&
7329 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
])
7330 object_preemption
= false;
7332 /* WaDisableMidObjectPreemptionForTrifanOrPolygon
7334 * "TriFan miscompare in Execlist Preemption test. Cut index that is
7335 * on a previous context. End the previous, the resume another context
7336 * with a tri-fan or polygon, and the vertex count is corrupted. If we
7337 * prempt again we will cause corruption.
7339 * WA: Disable mid-draw preemption when draw-call has a tri-fan."
7341 if (draw
->mode
== PIPE_PRIM_TRIANGLE_FAN
)
7342 object_preemption
= false;
7344 /* WaDisableMidObjectPreemptionForLineLoop
7346 * "VF Stats Counters Missing a vertex when preemption enabled.
7348 * WA: Disable mid-draw preemption when the draw uses a lineloop
7351 if (draw
->mode
== PIPE_PRIM_LINE_LOOP
)
7352 object_preemption
= false;
7356 * "VF is corrupting GAFS data when preempted on an instance boundary
7357 * and replayed with instancing enabled.
7359 * WA: Disable preemption when using instanceing."
7361 if (draw
->instance_count
> 1)
7362 object_preemption
= false;
7364 if (genx
->object_preemption
!= object_preemption
) {
7365 iris_enable_obj_preemption(batch
, object_preemption
);
7366 genx
->object_preemption
= object_preemption
;
7372 iris_lost_genx_state(struct iris_context
*ice
, struct iris_batch
*batch
)
7374 struct iris_genx_state
*genx
= ice
->state
.genx
;
7376 memset(genx
->last_index_buffer
, 0, sizeof(genx
->last_index_buffer
));
7380 iris_emit_mi_report_perf_count(struct iris_batch
*batch
,
7382 uint32_t offset_in_bytes
,
7385 iris_emit_cmd(batch
, GENX(MI_REPORT_PERF_COUNT
), mi_rpc
) {
7386 mi_rpc
.MemoryAddress
= rw_bo(bo
, offset_in_bytes
);
7387 mi_rpc
.ReportID
= report_id
;
7392 * Update the pixel hashing modes that determine the balancing of PS threads
7393 * across subslices and slices.
7395 * \param width Width bound of the rendering area (already scaled down if \p
7396 * scale is greater than 1).
7397 * \param height Height bound of the rendering area (already scaled down if \p
7398 * scale is greater than 1).
7399 * \param scale The number of framebuffer samples that could potentially be
7400 * affected by an individual channel of the PS thread. This is
7401 * typically one for single-sampled rendering, but for operations
7402 * like CCS resolves and fast clears a single PS invocation may
7403 * update a huge number of pixels, in which case a finer
7404 * balancing is desirable in order to maximally utilize the
7405 * bandwidth available. UINT_MAX can be used as shorthand for
7406 * "finest hashing mode available".
7409 genX(emit_hashing_mode
)(struct iris_context
*ice
, struct iris_batch
*batch
,
7410 unsigned width
, unsigned height
, unsigned scale
)
7413 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
7414 const unsigned slice_hashing
[] = {
7415 /* Because all Gen9 platforms with more than one slice require
7416 * three-way subslice hashing, a single "normal" 16x16 slice hashing
7417 * block is guaranteed to suffer from substantial imbalance, with one
7418 * subslice receiving twice as much work as the other two in the
7421 * The performance impact of that would be particularly severe when
7422 * three-way hashing is also in use for slice balancing (which is the
7423 * case for all Gen9 GT4 platforms), because one of the slices
7424 * receives one every three 16x16 blocks in either direction, which
7425 * is roughly the periodicity of the underlying subslice imbalance
7426 * pattern ("roughly" because in reality the hardware's
7427 * implementation of three-way hashing doesn't do exact modulo 3
7428 * arithmetic, which somewhat decreases the magnitude of this effect
7429 * in practice). This leads to a systematic subslice imbalance
7430 * within that slice regardless of the size of the primitive. The
7431 * 32x32 hashing mode guarantees that the subslice imbalance within a
7432 * single slice hashing block is minimal, largely eliminating this
7436 /* Finest slice hashing mode available. */
7439 const unsigned subslice_hashing
[] = {
7440 /* 16x16 would provide a slight cache locality benefit especially
7441 * visible in the sampler L1 cache efficiency of low-bandwidth
7442 * non-LLC platforms, but it comes at the cost of greater subslice
7443 * imbalance for primitives of dimensions approximately intermediate
7444 * between 16x4 and 16x16.
7447 /* Finest subslice hashing mode available. */
7450 /* Dimensions of the smallest hashing block of a given hashing mode. If
7451 * the rendering area is smaller than this there can't possibly be any
7452 * benefit from switching to this mode, so we optimize out the
7455 const unsigned min_size
[][2] = {
7459 const unsigned idx
= scale
> 1;
7461 if (width
> min_size
[idx
][0] || height
> min_size
[idx
][1]) {
7464 iris_pack_state(GENX(GT_MODE
), >_mode
, reg
) {
7465 reg
.SliceHashing
= (devinfo
->num_slices
> 1 ? slice_hashing
[idx
] : 0);
7466 reg
.SliceHashingMask
= (devinfo
->num_slices
> 1 ? -1 : 0);
7467 reg
.SubsliceHashing
= subslice_hashing
[idx
];
7468 reg
.SubsliceHashingMask
= -1;
7471 iris_emit_raw_pipe_control(batch
,
7472 "workaround: CS stall before GT_MODE LRI",
7473 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
7474 PIPE_CONTROL_CS_STALL
,
7477 iris_emit_lri(batch
, GT_MODE
, gt_mode
);
7479 ice
->state
.current_hash_scale
= scale
;
7485 iris_set_frontend_noop(struct pipe_context
*ctx
, bool enable
)
7487 struct iris_context
*ice
= (struct iris_context
*) ctx
;
7489 ice
->state
.dirty
|= iris_batch_prepare_noop(&ice
->batches
[IRIS_BATCH_RENDER
],
7491 IRIS_ALL_DIRTY_FOR_RENDER
);
7492 ice
->state
.dirty
|= iris_batch_prepare_noop(&ice
->batches
[IRIS_BATCH_COMPUTE
],
7494 IRIS_ALL_DIRTY_FOR_COMPUTE
);
7498 genX(init_state
)(struct iris_context
*ice
)
7500 struct pipe_context
*ctx
= &ice
->ctx
;
7501 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
7503 ctx
->create_blend_state
= iris_create_blend_state
;
7504 ctx
->create_depth_stencil_alpha_state
= iris_create_zsa_state
;
7505 ctx
->create_rasterizer_state
= iris_create_rasterizer_state
;
7506 ctx
->create_sampler_state
= iris_create_sampler_state
;
7507 ctx
->create_sampler_view
= iris_create_sampler_view
;
7508 ctx
->create_surface
= iris_create_surface
;
7509 ctx
->create_vertex_elements_state
= iris_create_vertex_elements
;
7510 ctx
->bind_blend_state
= iris_bind_blend_state
;
7511 ctx
->bind_depth_stencil_alpha_state
= iris_bind_zsa_state
;
7512 ctx
->bind_sampler_states
= iris_bind_sampler_states
;
7513 ctx
->bind_rasterizer_state
= iris_bind_rasterizer_state
;
7514 ctx
->bind_vertex_elements_state
= iris_bind_vertex_elements_state
;
7515 ctx
->delete_blend_state
= iris_delete_state
;
7516 ctx
->delete_depth_stencil_alpha_state
= iris_delete_state
;
7517 ctx
->delete_rasterizer_state
= iris_delete_state
;
7518 ctx
->delete_sampler_state
= iris_delete_state
;
7519 ctx
->delete_vertex_elements_state
= iris_delete_state
;
7520 ctx
->set_blend_color
= iris_set_blend_color
;
7521 ctx
->set_clip_state
= iris_set_clip_state
;
7522 ctx
->set_constant_buffer
= iris_set_constant_buffer
;
7523 ctx
->set_shader_buffers
= iris_set_shader_buffers
;
7524 ctx
->set_shader_images
= iris_set_shader_images
;
7525 ctx
->set_sampler_views
= iris_set_sampler_views
;
7526 ctx
->set_tess_state
= iris_set_tess_state
;
7527 ctx
->set_framebuffer_state
= iris_set_framebuffer_state
;
7528 ctx
->set_polygon_stipple
= iris_set_polygon_stipple
;
7529 ctx
->set_sample_mask
= iris_set_sample_mask
;
7530 ctx
->set_scissor_states
= iris_set_scissor_states
;
7531 ctx
->set_stencil_ref
= iris_set_stencil_ref
;
7532 ctx
->set_vertex_buffers
= iris_set_vertex_buffers
;
7533 ctx
->set_viewport_states
= iris_set_viewport_states
;
7534 ctx
->sampler_view_destroy
= iris_sampler_view_destroy
;
7535 ctx
->surface_destroy
= iris_surface_destroy
;
7536 ctx
->draw_vbo
= iris_draw_vbo
;
7537 ctx
->launch_grid
= iris_launch_grid
;
7538 ctx
->create_stream_output_target
= iris_create_stream_output_target
;
7539 ctx
->stream_output_target_destroy
= iris_stream_output_target_destroy
;
7540 ctx
->set_stream_output_targets
= iris_set_stream_output_targets
;
7541 ctx
->set_frontend_noop
= iris_set_frontend_noop
;
7543 screen
->vtbl
.destroy_state
= iris_destroy_state
;
7544 screen
->vtbl
.init_render_context
= iris_init_render_context
;
7545 screen
->vtbl
.init_compute_context
= iris_init_compute_context
;
7546 screen
->vtbl
.upload_render_state
= iris_upload_render_state
;
7547 screen
->vtbl
.update_surface_base_address
= iris_update_surface_base_address
;
7548 screen
->vtbl
.upload_compute_state
= iris_upload_compute_state
;
7549 screen
->vtbl
.emit_raw_pipe_control
= iris_emit_raw_pipe_control
;
7550 screen
->vtbl
.emit_mi_report_perf_count
= iris_emit_mi_report_perf_count
;
7551 screen
->vtbl
.rebind_buffer
= iris_rebind_buffer
;
7552 screen
->vtbl
.load_register_reg32
= iris_load_register_reg32
;
7553 screen
->vtbl
.load_register_reg64
= iris_load_register_reg64
;
7554 screen
->vtbl
.load_register_imm32
= iris_load_register_imm32
;
7555 screen
->vtbl
.load_register_imm64
= iris_load_register_imm64
;
7556 screen
->vtbl
.load_register_mem32
= iris_load_register_mem32
;
7557 screen
->vtbl
.load_register_mem64
= iris_load_register_mem64
;
7558 screen
->vtbl
.store_register_mem32
= iris_store_register_mem32
;
7559 screen
->vtbl
.store_register_mem64
= iris_store_register_mem64
;
7560 screen
->vtbl
.store_data_imm32
= iris_store_data_imm32
;
7561 screen
->vtbl
.store_data_imm64
= iris_store_data_imm64
;
7562 screen
->vtbl
.copy_mem_mem
= iris_copy_mem_mem
;
7563 screen
->vtbl
.derived_program_state_size
= iris_derived_program_state_size
;
7564 screen
->vtbl
.store_derived_program_state
= iris_store_derived_program_state
;
7565 screen
->vtbl
.create_so_decl_list
= iris_create_so_decl_list
;
7566 screen
->vtbl
.populate_vs_key
= iris_populate_vs_key
;
7567 screen
->vtbl
.populate_tcs_key
= iris_populate_tcs_key
;
7568 screen
->vtbl
.populate_tes_key
= iris_populate_tes_key
;
7569 screen
->vtbl
.populate_gs_key
= iris_populate_gs_key
;
7570 screen
->vtbl
.populate_fs_key
= iris_populate_fs_key
;
7571 screen
->vtbl
.populate_cs_key
= iris_populate_cs_key
;
7572 screen
->vtbl
.lost_genx_state
= iris_lost_genx_state
;
7574 ice
->state
.dirty
= ~0ull;
7576 ice
->state
.statistics_counters_enabled
= true;
7578 ice
->state
.sample_mask
= 0xffff;
7579 ice
->state
.num_viewports
= 1;
7580 ice
->state
.prim_mode
= PIPE_PRIM_MAX
;
7581 ice
->state
.genx
= calloc(1, sizeof(struct iris_genx_state
));
7582 ice
->draw
.derived_params
.drawid
= -1;
7584 /* Make a 1x1x1 null surface for unbound textures */
7585 void *null_surf_map
=
7586 upload_state(ice
->state
.surface_uploader
, &ice
->state
.unbound_tex
,
7587 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
7588 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
, isl_extent3d(1, 1, 1));
7589 ice
->state
.unbound_tex
.offset
+=
7590 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.unbound_tex
.res
));
7592 /* Default all scissor rectangles to be empty regions. */
7593 for (int i
= 0; i
< IRIS_MAX_VIEWPORTS
; i
++) {
7594 ice
->state
.scissors
[i
] = (struct pipe_scissor_state
) {
7595 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,