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_inlines.h"
92 #include "util/u_format.h"
93 #include "util/u_framebuffer.h"
94 #include "util/u_transfer.h"
95 #include "util/u_upload_mgr.h"
96 #include "util/u_viewport.h"
97 #include "drm-uapi/i915_drm.h"
99 #include "intel/compiler/brw_compiler.h"
100 #include "intel/common/gen_l3_config.h"
101 #include "intel/common/gen_sample_positions.h"
102 #include "iris_batch.h"
103 #include "iris_context.h"
104 #include "iris_defines.h"
105 #include "iris_pipe.h"
106 #include "iris_resource.h"
108 #define __gen_address_type struct iris_address
109 #define __gen_user_data struct iris_batch
111 #define ARRAY_BYTES(x) (sizeof(uint32_t) * ARRAY_SIZE(x))
114 __gen_combine_address(struct iris_batch
*batch
, void *location
,
115 struct iris_address addr
, uint32_t delta
)
117 uint64_t result
= addr
.offset
+ delta
;
120 iris_use_pinned_bo(batch
, addr
.bo
, addr
.write
);
121 /* Assume this is a general address, not relative to a base. */
122 result
+= addr
.bo
->gtt_offset
;
128 #define __genxml_cmd_length(cmd) cmd ## _length
129 #define __genxml_cmd_length_bias(cmd) cmd ## _length_bias
130 #define __genxml_cmd_header(cmd) cmd ## _header
131 #define __genxml_cmd_pack(cmd) cmd ## _pack
133 #define _iris_pack_command(batch, cmd, dst, name) \
134 for (struct cmd name = { __genxml_cmd_header(cmd) }, \
135 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
136 ({ __genxml_cmd_pack(cmd)(batch, (void *)_dst, &name); \
140 #define iris_pack_command(cmd, dst, name) \
141 _iris_pack_command(NULL, cmd, dst, name)
143 #define iris_pack_state(cmd, dst, name) \
144 for (struct cmd name = {}, \
145 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
146 __genxml_cmd_pack(cmd)(NULL, (void *)_dst, &name), \
149 #define iris_emit_cmd(batch, cmd, name) \
150 _iris_pack_command(batch, cmd, iris_get_command_space(batch, 4 * __genxml_cmd_length(cmd)), name)
152 #define iris_emit_merge(batch, dwords0, dwords1, num_dwords) \
154 uint32_t *dw = iris_get_command_space(batch, 4 * num_dwords); \
155 for (uint32_t i = 0; i < num_dwords; i++) \
156 dw[i] = (dwords0)[i] | (dwords1)[i]; \
157 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, num_dwords)); \
160 #include "genxml/genX_pack.h"
161 #include "genxml/gen_macros.h"
162 #include "genxml/genX_bits.h"
165 #define MOCS_PTE 0x18
168 #define MOCS_PTE (1 << 1)
169 #define MOCS_WB (2 << 1)
173 mocs(const struct iris_bo
*bo
)
175 return bo
&& bo
->external
? MOCS_PTE
: MOCS_WB
;
179 * Statically assert that PIPE_* enums match the hardware packets.
180 * (As long as they match, we don't need to translate them.)
182 UNUSED
static void pipe_asserts()
184 #define PIPE_ASSERT(x) STATIC_ASSERT((int)x)
186 /* pipe_logicop happens to match the hardware. */
187 PIPE_ASSERT(PIPE_LOGICOP_CLEAR
== LOGICOP_CLEAR
);
188 PIPE_ASSERT(PIPE_LOGICOP_NOR
== LOGICOP_NOR
);
189 PIPE_ASSERT(PIPE_LOGICOP_AND_INVERTED
== LOGICOP_AND_INVERTED
);
190 PIPE_ASSERT(PIPE_LOGICOP_COPY_INVERTED
== LOGICOP_COPY_INVERTED
);
191 PIPE_ASSERT(PIPE_LOGICOP_AND_REVERSE
== LOGICOP_AND_REVERSE
);
192 PIPE_ASSERT(PIPE_LOGICOP_INVERT
== LOGICOP_INVERT
);
193 PIPE_ASSERT(PIPE_LOGICOP_XOR
== LOGICOP_XOR
);
194 PIPE_ASSERT(PIPE_LOGICOP_NAND
== LOGICOP_NAND
);
195 PIPE_ASSERT(PIPE_LOGICOP_AND
== LOGICOP_AND
);
196 PIPE_ASSERT(PIPE_LOGICOP_EQUIV
== LOGICOP_EQUIV
);
197 PIPE_ASSERT(PIPE_LOGICOP_NOOP
== LOGICOP_NOOP
);
198 PIPE_ASSERT(PIPE_LOGICOP_OR_INVERTED
== LOGICOP_OR_INVERTED
);
199 PIPE_ASSERT(PIPE_LOGICOP_COPY
== LOGICOP_COPY
);
200 PIPE_ASSERT(PIPE_LOGICOP_OR_REVERSE
== LOGICOP_OR_REVERSE
);
201 PIPE_ASSERT(PIPE_LOGICOP_OR
== LOGICOP_OR
);
202 PIPE_ASSERT(PIPE_LOGICOP_SET
== LOGICOP_SET
);
204 /* pipe_blend_func happens to match the hardware. */
205 PIPE_ASSERT(PIPE_BLENDFACTOR_ONE
== BLENDFACTOR_ONE
);
206 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_COLOR
== BLENDFACTOR_SRC_COLOR
);
207 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA
== BLENDFACTOR_SRC_ALPHA
);
208 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_ALPHA
== BLENDFACTOR_DST_ALPHA
);
209 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_COLOR
== BLENDFACTOR_DST_COLOR
);
210 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
== BLENDFACTOR_SRC_ALPHA_SATURATE
);
211 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_COLOR
== BLENDFACTOR_CONST_COLOR
);
212 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_ALPHA
== BLENDFACTOR_CONST_ALPHA
);
213 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_COLOR
== BLENDFACTOR_SRC1_COLOR
);
214 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_ALPHA
== BLENDFACTOR_SRC1_ALPHA
);
215 PIPE_ASSERT(PIPE_BLENDFACTOR_ZERO
== BLENDFACTOR_ZERO
);
216 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_COLOR
== BLENDFACTOR_INV_SRC_COLOR
);
217 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_ALPHA
== BLENDFACTOR_INV_SRC_ALPHA
);
218 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_ALPHA
== BLENDFACTOR_INV_DST_ALPHA
);
219 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_COLOR
== BLENDFACTOR_INV_DST_COLOR
);
220 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_COLOR
== BLENDFACTOR_INV_CONST_COLOR
);
221 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_ALPHA
== BLENDFACTOR_INV_CONST_ALPHA
);
222 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_COLOR
== BLENDFACTOR_INV_SRC1_COLOR
);
223 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_ALPHA
== BLENDFACTOR_INV_SRC1_ALPHA
);
225 /* pipe_blend_func happens to match the hardware. */
226 PIPE_ASSERT(PIPE_BLEND_ADD
== BLENDFUNCTION_ADD
);
227 PIPE_ASSERT(PIPE_BLEND_SUBTRACT
== BLENDFUNCTION_SUBTRACT
);
228 PIPE_ASSERT(PIPE_BLEND_REVERSE_SUBTRACT
== BLENDFUNCTION_REVERSE_SUBTRACT
);
229 PIPE_ASSERT(PIPE_BLEND_MIN
== BLENDFUNCTION_MIN
);
230 PIPE_ASSERT(PIPE_BLEND_MAX
== BLENDFUNCTION_MAX
);
232 /* pipe_stencil_op happens to match the hardware. */
233 PIPE_ASSERT(PIPE_STENCIL_OP_KEEP
== STENCILOP_KEEP
);
234 PIPE_ASSERT(PIPE_STENCIL_OP_ZERO
== STENCILOP_ZERO
);
235 PIPE_ASSERT(PIPE_STENCIL_OP_REPLACE
== STENCILOP_REPLACE
);
236 PIPE_ASSERT(PIPE_STENCIL_OP_INCR
== STENCILOP_INCRSAT
);
237 PIPE_ASSERT(PIPE_STENCIL_OP_DECR
== STENCILOP_DECRSAT
);
238 PIPE_ASSERT(PIPE_STENCIL_OP_INCR_WRAP
== STENCILOP_INCR
);
239 PIPE_ASSERT(PIPE_STENCIL_OP_DECR_WRAP
== STENCILOP_DECR
);
240 PIPE_ASSERT(PIPE_STENCIL_OP_INVERT
== STENCILOP_INVERT
);
242 /* pipe_sprite_coord_mode happens to match 3DSTATE_SBE */
243 PIPE_ASSERT(PIPE_SPRITE_COORD_UPPER_LEFT
== UPPERLEFT
);
244 PIPE_ASSERT(PIPE_SPRITE_COORD_LOWER_LEFT
== LOWERLEFT
);
249 translate_prim_type(enum pipe_prim_type prim
, uint8_t verts_per_patch
)
251 static const unsigned map
[] = {
252 [PIPE_PRIM_POINTS
] = _3DPRIM_POINTLIST
,
253 [PIPE_PRIM_LINES
] = _3DPRIM_LINELIST
,
254 [PIPE_PRIM_LINE_LOOP
] = _3DPRIM_LINELOOP
,
255 [PIPE_PRIM_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
256 [PIPE_PRIM_TRIANGLES
] = _3DPRIM_TRILIST
,
257 [PIPE_PRIM_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
258 [PIPE_PRIM_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
259 [PIPE_PRIM_QUADS
] = _3DPRIM_QUADLIST
,
260 [PIPE_PRIM_QUAD_STRIP
] = _3DPRIM_QUADSTRIP
,
261 [PIPE_PRIM_POLYGON
] = _3DPRIM_POLYGON
,
262 [PIPE_PRIM_LINES_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
263 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
264 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
265 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
266 [PIPE_PRIM_PATCHES
] = _3DPRIM_PATCHLIST_1
- 1,
269 return map
[prim
] + (prim
== PIPE_PRIM_PATCHES
? verts_per_patch
: 0);
273 translate_compare_func(enum pipe_compare_func pipe_func
)
275 static const unsigned map
[] = {
276 [PIPE_FUNC_NEVER
] = COMPAREFUNCTION_NEVER
,
277 [PIPE_FUNC_LESS
] = COMPAREFUNCTION_LESS
,
278 [PIPE_FUNC_EQUAL
] = COMPAREFUNCTION_EQUAL
,
279 [PIPE_FUNC_LEQUAL
] = COMPAREFUNCTION_LEQUAL
,
280 [PIPE_FUNC_GREATER
] = COMPAREFUNCTION_GREATER
,
281 [PIPE_FUNC_NOTEQUAL
] = COMPAREFUNCTION_NOTEQUAL
,
282 [PIPE_FUNC_GEQUAL
] = COMPAREFUNCTION_GEQUAL
,
283 [PIPE_FUNC_ALWAYS
] = COMPAREFUNCTION_ALWAYS
,
285 return map
[pipe_func
];
289 translate_shadow_func(enum pipe_compare_func pipe_func
)
291 /* Gallium specifies the result of shadow comparisons as:
293 * 1 if ref <op> texel,
298 * 0 if texel <op> ref,
301 * So we need to flip the operator and also negate.
303 static const unsigned map
[] = {
304 [PIPE_FUNC_NEVER
] = PREFILTEROPALWAYS
,
305 [PIPE_FUNC_LESS
] = PREFILTEROPLEQUAL
,
306 [PIPE_FUNC_EQUAL
] = PREFILTEROPNOTEQUAL
,
307 [PIPE_FUNC_LEQUAL
] = PREFILTEROPLESS
,
308 [PIPE_FUNC_GREATER
] = PREFILTEROPGEQUAL
,
309 [PIPE_FUNC_NOTEQUAL
] = PREFILTEROPEQUAL
,
310 [PIPE_FUNC_GEQUAL
] = PREFILTEROPGREATER
,
311 [PIPE_FUNC_ALWAYS
] = PREFILTEROPNEVER
,
313 return map
[pipe_func
];
317 translate_cull_mode(unsigned pipe_face
)
319 static const unsigned map
[4] = {
320 [PIPE_FACE_NONE
] = CULLMODE_NONE
,
321 [PIPE_FACE_FRONT
] = CULLMODE_FRONT
,
322 [PIPE_FACE_BACK
] = CULLMODE_BACK
,
323 [PIPE_FACE_FRONT_AND_BACK
] = CULLMODE_BOTH
,
325 return map
[pipe_face
];
329 translate_fill_mode(unsigned pipe_polymode
)
331 static const unsigned map
[4] = {
332 [PIPE_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
333 [PIPE_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
334 [PIPE_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
335 [PIPE_POLYGON_MODE_FILL_RECTANGLE
] = FILL_MODE_SOLID
,
337 return map
[pipe_polymode
];
341 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip
)
343 static const unsigned map
[] = {
344 [PIPE_TEX_MIPFILTER_NEAREST
] = MIPFILTER_NEAREST
,
345 [PIPE_TEX_MIPFILTER_LINEAR
] = MIPFILTER_LINEAR
,
346 [PIPE_TEX_MIPFILTER_NONE
] = MIPFILTER_NONE
,
348 return map
[pipe_mip
];
352 translate_wrap(unsigned pipe_wrap
)
354 static const unsigned map
[] = {
355 [PIPE_TEX_WRAP_REPEAT
] = TCM_WRAP
,
356 [PIPE_TEX_WRAP_CLAMP
] = TCM_HALF_BORDER
,
357 [PIPE_TEX_WRAP_CLAMP_TO_EDGE
] = TCM_CLAMP
,
358 [PIPE_TEX_WRAP_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
359 [PIPE_TEX_WRAP_MIRROR_REPEAT
] = TCM_MIRROR
,
360 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
362 /* These are unsupported. */
363 [PIPE_TEX_WRAP_MIRROR_CLAMP
] = -1,
364 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
] = -1,
366 return map
[pipe_wrap
];
369 static struct iris_address
370 ro_bo(struct iris_bo
*bo
, uint64_t offset
)
372 /* CSOs must pass NULL for bo! Otherwise it will add the BO to the
373 * validation list at CSO creation time, instead of draw time.
375 return (struct iris_address
) { .bo
= bo
, .offset
= offset
};
378 static struct iris_address
379 rw_bo(struct iris_bo
*bo
, uint64_t offset
)
381 /* CSOs must pass NULL for bo! Otherwise it will add the BO to the
382 * validation list at CSO creation time, instead of draw time.
384 return (struct iris_address
) { .bo
= bo
, .offset
= offset
, .write
= true };
388 * Allocate space for some indirect state.
390 * Return a pointer to the map (to fill it out) and a state ref (for
391 * referring to the state in GPU commands).
394 upload_state(struct u_upload_mgr
*uploader
,
395 struct iris_state_ref
*ref
,
400 u_upload_alloc(uploader
, 0, size
, alignment
, &ref
->offset
, &ref
->res
, &p
);
405 * Stream out temporary/short-lived state.
407 * This allocates space, pins the BO, and includes the BO address in the
408 * returned offset (which works because all state lives in 32-bit memory
412 stream_state(struct iris_batch
*batch
,
413 struct u_upload_mgr
*uploader
,
414 struct pipe_resource
**out_res
,
417 uint32_t *out_offset
)
421 u_upload_alloc(uploader
, 0, size
, alignment
, out_offset
, out_res
, &ptr
);
423 struct iris_bo
*bo
= iris_resource_bo(*out_res
);
424 iris_use_pinned_bo(batch
, bo
, false);
426 *out_offset
+= iris_bo_offset_from_base_address(bo
);
432 * stream_state() + memcpy.
435 emit_state(struct iris_batch
*batch
,
436 struct u_upload_mgr
*uploader
,
437 struct pipe_resource
**out_res
,
444 stream_state(batch
, uploader
, out_res
, size
, alignment
, &offset
);
447 memcpy(map
, data
, size
);
453 * Did field 'x' change between 'old_cso' and 'new_cso'?
455 * (If so, we may want to set some dirty flags.)
457 #define cso_changed(x) (!old_cso || (old_cso->x != new_cso->x))
458 #define cso_changed_memcmp(x) \
459 (!old_cso || memcmp(old_cso->x, new_cso->x, sizeof(old_cso->x)) != 0)
462 flush_for_state_base_change(struct iris_batch
*batch
)
464 /* Flush before emitting STATE_BASE_ADDRESS.
466 * This isn't documented anywhere in the PRM. However, it seems to be
467 * necessary prior to changing the surface state base adress. We've
468 * seen issues in Vulkan where we get GPU hangs when using multi-level
469 * command buffers which clear depth, reset state base address, and then
472 * Normally, in GL, we would trust the kernel to do sufficient stalls
473 * and flushes prior to executing our batch. However, it doesn't seem
474 * as if the kernel's flushing is always sufficient and we don't want to
477 * We make this an end-of-pipe sync instead of a normal flush because we
478 * do not know the current status of the GPU. On Haswell at least,
479 * having a fast-clear operation in flight at the same time as a normal
480 * rendering operation can cause hangs. Since the kernel's flushing is
481 * insufficient, we need to ensure that any rendering operations from
482 * other processes are definitely complete before we try to do our own
483 * rendering. It's a bit of a big hammer but it appears to work.
485 iris_emit_end_of_pipe_sync(batch
,
486 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
487 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
488 PIPE_CONTROL_DATA_CACHE_FLUSH
);
492 _iris_emit_lri(struct iris_batch
*batch
, uint32_t reg
, uint32_t val
)
494 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
495 lri
.RegisterOffset
= reg
;
499 #define iris_emit_lri(b, r, v) _iris_emit_lri(b, GENX(r##_num), v)
502 _iris_emit_lrr(struct iris_batch
*batch
, uint32_t dst
, uint32_t src
)
504 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_REG
), lrr
) {
505 lrr
.SourceRegisterAddress
= src
;
506 lrr
.DestinationRegisterAddress
= dst
;
511 emit_pipeline_select(struct iris_batch
*batch
, uint32_t pipeline
)
513 #if GEN_GEN >= 8 && GEN_GEN < 10
514 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
516 * Software must clear the COLOR_CALC_STATE Valid field in
517 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
518 * with Pipeline Select set to GPGPU.
520 * The internal hardware docs recommend the same workaround for Gen9
523 if (pipeline
== GPGPU
)
524 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), t
);
528 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
529 * PIPELINE_SELECT [DevBWR+]":
533 * Software must ensure all the write caches are flushed through a
534 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
535 * command to invalidate read only caches prior to programming
536 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode."
538 iris_emit_pipe_control_flush(batch
,
539 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
540 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
541 PIPE_CONTROL_DATA_CACHE_FLUSH
|
542 PIPE_CONTROL_CS_STALL
);
544 iris_emit_pipe_control_flush(batch
,
545 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
546 PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
547 PIPE_CONTROL_STATE_CACHE_INVALIDATE
|
548 PIPE_CONTROL_INSTRUCTION_INVALIDATE
);
550 iris_emit_cmd(batch
, GENX(PIPELINE_SELECT
), sel
) {
554 sel
.PipelineSelection
= pipeline
;
559 init_glk_barrier_mode(struct iris_batch
*batch
, uint32_t value
)
564 * "This chicken bit works around a hardware issue with barrier
565 * logic encountered when switching between GPGPU and 3D pipelines.
566 * To workaround the issue, this mode bit should be set after a
567 * pipeline is selected."
570 iris_pack_state(GENX(SLICE_COMMON_ECO_CHICKEN1
), ®_val
, reg
) {
571 reg
.GLKBarrierMode
= value
;
572 reg
.GLKBarrierModeMask
= 1;
574 iris_emit_lri(batch
, SLICE_COMMON_ECO_CHICKEN1
, reg_val
);
579 init_state_base_address(struct iris_batch
*batch
)
581 flush_for_state_base_change(batch
);
583 /* We program most base addresses once at context initialization time.
584 * Each base address points at a 4GB memory zone, and never needs to
585 * change. See iris_bufmgr.h for a description of the memory zones.
587 * The one exception is Surface State Base Address, which needs to be
588 * updated occasionally. See iris_binder.c for the details there.
590 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
591 sba
.GeneralStateMOCS
= MOCS_WB
;
592 sba
.StatelessDataPortAccessMOCS
= MOCS_WB
;
593 sba
.DynamicStateMOCS
= MOCS_WB
;
594 sba
.IndirectObjectMOCS
= MOCS_WB
;
595 sba
.InstructionMOCS
= MOCS_WB
;
597 sba
.GeneralStateBaseAddressModifyEnable
= true;
598 sba
.DynamicStateBaseAddressModifyEnable
= true;
599 sba
.IndirectObjectBaseAddressModifyEnable
= true;
600 sba
.InstructionBaseAddressModifyEnable
= true;
601 sba
.GeneralStateBufferSizeModifyEnable
= true;
602 sba
.DynamicStateBufferSizeModifyEnable
= true;
604 sba
.BindlessSurfaceStateBaseAddressModifyEnable
= true;
605 sba
.BindlessSurfaceStateMOCS
= MOCS_WB
;
607 sba
.IndirectObjectBufferSizeModifyEnable
= true;
608 sba
.InstructionBuffersizeModifyEnable
= true;
610 sba
.InstructionBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_SHADER_START
);
611 sba
.DynamicStateBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_DYNAMIC_START
);
613 sba
.GeneralStateBufferSize
= 0xfffff;
614 sba
.IndirectObjectBufferSize
= 0xfffff;
615 sba
.InstructionBufferSize
= 0xfffff;
616 sba
.DynamicStateBufferSize
= 0xfffff;
621 iris_emit_l3_config(struct iris_batch
*batch
, const struct gen_l3_config
*cfg
,
622 bool has_slm
, bool wants_dc_cache
)
625 iris_pack_state(GENX(L3CNTLREG
), ®_val
, reg
) {
626 reg
.SLMEnable
= has_slm
;
628 /* WA_1406697149: Bit 9 "Error Detection Behavior Control" must be set
629 * in L3CNTLREG register. The default setting of the bit is not the
630 * desirable behavior.
632 reg
.ErrorDetectionBehaviorControl
= true;
634 reg
.URBAllocation
= cfg
->n
[GEN_L3P_URB
];
635 reg
.ROAllocation
= cfg
->n
[GEN_L3P_RO
];
636 reg
.DCAllocation
= cfg
->n
[GEN_L3P_DC
];
637 reg
.AllAllocation
= cfg
->n
[GEN_L3P_ALL
];
639 iris_emit_lri(batch
, L3CNTLREG
, reg_val
);
643 iris_emit_default_l3_config(struct iris_batch
*batch
,
644 const struct gen_device_info
*devinfo
,
647 bool wants_dc_cache
= true;
648 bool has_slm
= compute
;
649 const struct gen_l3_weights w
=
650 gen_get_default_l3_weights(devinfo
, wants_dc_cache
, has_slm
);
651 const struct gen_l3_config
*cfg
= gen_get_l3_config(devinfo
, w
);
652 iris_emit_l3_config(batch
, cfg
, has_slm
, wants_dc_cache
);
656 * Upload the initial GPU state for a render context.
658 * This sets some invariant state that needs to be programmed a particular
659 * way, but we never actually change.
662 iris_init_render_context(struct iris_screen
*screen
,
663 struct iris_batch
*batch
,
664 struct iris_vtable
*vtbl
,
665 struct pipe_debug_callback
*dbg
)
667 UNUSED
const struct gen_device_info
*devinfo
= &screen
->devinfo
;
670 emit_pipeline_select(batch
, _3D
);
672 iris_emit_default_l3_config(batch
, devinfo
, false);
674 init_state_base_address(batch
);
677 iris_pack_state(GENX(CS_DEBUG_MODE2
), ®_val
, reg
) {
678 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
679 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
681 iris_emit_lri(batch
, CS_DEBUG_MODE2
, reg_val
);
683 iris_pack_state(GENX(INSTPM
), ®_val
, reg
) {
684 reg
.CONSTANT_BUFFERAddressOffsetDisable
= true;
685 reg
.CONSTANT_BUFFERAddressOffsetDisableMask
= true;
687 iris_emit_lri(batch
, INSTPM
, reg_val
);
691 iris_pack_state(GENX(CACHE_MODE_1
), ®_val
, reg
) {
692 reg
.FloatBlendOptimizationEnable
= true;
693 reg
.FloatBlendOptimizationEnableMask
= true;
694 reg
.PartialResolveDisableInVC
= true;
695 reg
.PartialResolveDisableInVCMask
= true;
697 iris_emit_lri(batch
, CACHE_MODE_1
, reg_val
);
699 if (devinfo
->is_geminilake
)
700 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_3D_HULL
);
704 iris_pack_state(GENX(SAMPLER_MODE
), ®_val
, reg
) {
705 reg
.HeaderlessMessageforPreemptableContexts
= 1;
706 reg
.HeaderlessMessageforPreemptableContextsMask
= 1;
708 iris_emit_lri(batch
, SAMPLER_MODE
, reg_val
);
713 /* 3DSTATE_DRAWING_RECTANGLE is non-pipelined, so we want to avoid
714 * changing it dynamically. We set it to the maximum size here, and
715 * instead include the render target dimensions in the viewport, so
716 * viewport extents clipping takes care of pruning stray geometry.
718 iris_emit_cmd(batch
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
719 rect
.ClippedDrawingRectangleXMax
= UINT16_MAX
;
720 rect
.ClippedDrawingRectangleYMax
= UINT16_MAX
;
723 /* Set the initial MSAA sample positions. */
724 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_PATTERN
), pat
) {
725 GEN_SAMPLE_POS_1X(pat
._1xSample
);
726 GEN_SAMPLE_POS_2X(pat
._2xSample
);
727 GEN_SAMPLE_POS_4X(pat
._4xSample
);
728 GEN_SAMPLE_POS_8X(pat
._8xSample
);
730 GEN_SAMPLE_POS_16X(pat
._16xSample
);
734 /* Use the legacy AA line coverage computation. */
735 iris_emit_cmd(batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
), foo
);
737 /* Disable chromakeying (it's for media) */
738 iris_emit_cmd(batch
, GENX(3DSTATE_WM_CHROMAKEY
), foo
);
740 /* We want regular rendering, not special HiZ operations. */
741 iris_emit_cmd(batch
, GENX(3DSTATE_WM_HZ_OP
), foo
);
743 /* No polygon stippling offsets are necessary. */
744 /* TODO: may need to set an offset for origin-UL framebuffers */
745 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), foo
);
747 /* Set a static partitioning of the push constant area. */
748 /* TODO: this may be a bad idea...could starve the push ringbuffers... */
749 for (int i
= 0; i
<= MESA_SHADER_FRAGMENT
; i
++) {
750 iris_emit_cmd(batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
), alloc
) {
751 alloc
._3DCommandSubOpcode
= 18 + i
;
752 alloc
.ConstantBufferOffset
= 6 * i
;
753 alloc
.ConstantBufferSize
= i
== MESA_SHADER_FRAGMENT
? 8 : 6;
759 iris_init_compute_context(struct iris_screen
*screen
,
760 struct iris_batch
*batch
,
761 struct iris_vtable
*vtbl
,
762 struct pipe_debug_callback
*dbg
)
764 UNUSED
const struct gen_device_info
*devinfo
= &screen
->devinfo
;
766 emit_pipeline_select(batch
, GPGPU
);
768 iris_emit_default_l3_config(batch
, devinfo
, true);
770 init_state_base_address(batch
);
773 if (devinfo
->is_geminilake
)
774 init_glk_barrier_mode(batch
, GLK_BARRIER_MODE_GPGPU
);
778 struct iris_vertex_buffer_state
{
779 /** The VERTEX_BUFFER_STATE hardware structure. */
780 uint32_t state
[GENX(VERTEX_BUFFER_STATE_length
)];
782 /** The resource to source vertex data from. */
783 struct pipe_resource
*resource
;
786 struct iris_depth_buffer_state
{
787 /* Depth/HiZ/Stencil related hardware packets. */
788 uint32_t packets
[GENX(3DSTATE_DEPTH_BUFFER_length
) +
789 GENX(3DSTATE_STENCIL_BUFFER_length
) +
790 GENX(3DSTATE_HIER_DEPTH_BUFFER_length
) +
791 GENX(3DSTATE_CLEAR_PARAMS_length
)];
795 * Generation-specific context state (ice->state.genx->...).
797 * Most state can go in iris_context directly, but these encode hardware
798 * packets which vary by generation.
800 struct iris_genx_state
{
801 struct iris_vertex_buffer_state vertex_buffers
[33];
803 struct iris_depth_buffer_state depth_buffer
;
805 uint32_t so_buffers
[4 * GENX(3DSTATE_SO_BUFFER_length
)];
809 * The pipe->set_blend_color() driver hook.
811 * This corresponds to our COLOR_CALC_STATE.
814 iris_set_blend_color(struct pipe_context
*ctx
,
815 const struct pipe_blend_color
*state
)
817 struct iris_context
*ice
= (struct iris_context
*) ctx
;
819 /* Our COLOR_CALC_STATE is exactly pipe_blend_color, so just memcpy */
820 memcpy(&ice
->state
.blend_color
, state
, sizeof(struct pipe_blend_color
));
821 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
825 * Gallium CSO for blend state (see pipe_blend_state).
827 struct iris_blend_state
{
828 /** Partial 3DSTATE_PS_BLEND */
829 uint32_t ps_blend
[GENX(3DSTATE_PS_BLEND_length
)];
831 /** Partial BLEND_STATE */
832 uint32_t blend_state
[GENX(BLEND_STATE_length
) +
833 BRW_MAX_DRAW_BUFFERS
* GENX(BLEND_STATE_ENTRY_length
)];
835 bool alpha_to_coverage
; /* for shader key */
837 /** Bitfield of whether blending is enabled for RT[i] - for aux resolves */
838 uint8_t blend_enables
;
840 /** Bitfield of whether color writes are enabled for RT[i] */
841 uint8_t color_write_enables
;
844 static enum pipe_blendfactor
845 fix_blendfactor(enum pipe_blendfactor f
, bool alpha_to_one
)
848 if (f
== PIPE_BLENDFACTOR_SRC1_ALPHA
)
849 return PIPE_BLENDFACTOR_ONE
;
851 if (f
== PIPE_BLENDFACTOR_INV_SRC1_ALPHA
)
852 return PIPE_BLENDFACTOR_ZERO
;
859 * The pipe->create_blend_state() driver hook.
861 * Translates a pipe_blend_state into iris_blend_state.
864 iris_create_blend_state(struct pipe_context
*ctx
,
865 const struct pipe_blend_state
*state
)
867 struct iris_blend_state
*cso
= malloc(sizeof(struct iris_blend_state
));
868 uint32_t *blend_entry
= cso
->blend_state
+ GENX(BLEND_STATE_length
);
870 cso
->blend_enables
= 0;
871 cso
->color_write_enables
= 0;
872 STATIC_ASSERT(BRW_MAX_DRAW_BUFFERS
<= 8);
874 cso
->alpha_to_coverage
= state
->alpha_to_coverage
;
876 bool indep_alpha_blend
= false;
878 for (int i
= 0; i
< BRW_MAX_DRAW_BUFFERS
; i
++) {
879 const struct pipe_rt_blend_state
*rt
=
880 &state
->rt
[state
->independent_blend_enable
? i
: 0];
882 enum pipe_blendfactor src_rgb
=
883 fix_blendfactor(rt
->rgb_src_factor
, state
->alpha_to_one
);
884 enum pipe_blendfactor src_alpha
=
885 fix_blendfactor(rt
->alpha_src_factor
, state
->alpha_to_one
);
886 enum pipe_blendfactor dst_rgb
=
887 fix_blendfactor(rt
->rgb_dst_factor
, state
->alpha_to_one
);
888 enum pipe_blendfactor dst_alpha
=
889 fix_blendfactor(rt
->alpha_dst_factor
, state
->alpha_to_one
);
891 if (rt
->rgb_func
!= rt
->alpha_func
||
892 src_rgb
!= src_alpha
|| dst_rgb
!= dst_alpha
)
893 indep_alpha_blend
= true;
895 if (rt
->blend_enable
)
896 cso
->blend_enables
|= 1u << i
;
899 cso
->color_write_enables
|= 1u << i
;
901 iris_pack_state(GENX(BLEND_STATE_ENTRY
), blend_entry
, be
) {
902 be
.LogicOpEnable
= state
->logicop_enable
;
903 be
.LogicOpFunction
= state
->logicop_func
;
905 be
.PreBlendSourceOnlyClampEnable
= false;
906 be
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
907 be
.PreBlendColorClampEnable
= true;
908 be
.PostBlendColorClampEnable
= true;
910 be
.ColorBufferBlendEnable
= rt
->blend_enable
;
912 be
.ColorBlendFunction
= rt
->rgb_func
;
913 be
.AlphaBlendFunction
= rt
->alpha_func
;
914 be
.SourceBlendFactor
= src_rgb
;
915 be
.SourceAlphaBlendFactor
= src_alpha
;
916 be
.DestinationBlendFactor
= dst_rgb
;
917 be
.DestinationAlphaBlendFactor
= dst_alpha
;
919 be
.WriteDisableRed
= !(rt
->colormask
& PIPE_MASK_R
);
920 be
.WriteDisableGreen
= !(rt
->colormask
& PIPE_MASK_G
);
921 be
.WriteDisableBlue
= !(rt
->colormask
& PIPE_MASK_B
);
922 be
.WriteDisableAlpha
= !(rt
->colormask
& PIPE_MASK_A
);
924 blend_entry
+= GENX(BLEND_STATE_ENTRY_length
);
927 iris_pack_command(GENX(3DSTATE_PS_BLEND
), cso
->ps_blend
, pb
) {
928 /* pb.HasWriteableRT is filled in at draw time. */
929 /* pb.AlphaTestEnable is filled in at draw time. */
930 pb
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
931 pb
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
933 pb
.ColorBufferBlendEnable
= state
->rt
[0].blend_enable
;
935 pb
.SourceBlendFactor
=
936 fix_blendfactor(state
->rt
[0].rgb_src_factor
, state
->alpha_to_one
);
937 pb
.SourceAlphaBlendFactor
=
938 fix_blendfactor(state
->rt
[0].alpha_src_factor
, state
->alpha_to_one
);
939 pb
.DestinationBlendFactor
=
940 fix_blendfactor(state
->rt
[0].rgb_dst_factor
, state
->alpha_to_one
);
941 pb
.DestinationAlphaBlendFactor
=
942 fix_blendfactor(state
->rt
[0].alpha_dst_factor
, state
->alpha_to_one
);
945 iris_pack_state(GENX(BLEND_STATE
), cso
->blend_state
, bs
) {
946 bs
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
947 bs
.IndependentAlphaBlendEnable
= indep_alpha_blend
;
948 bs
.AlphaToOneEnable
= state
->alpha_to_one
;
949 bs
.AlphaToCoverageDitherEnable
= state
->alpha_to_coverage
;
950 bs
.ColorDitherEnable
= state
->dither
;
951 /* bl.AlphaTestEnable and bs.AlphaTestFunction are filled in later. */
959 * The pipe->bind_blend_state() driver hook.
961 * Bind a blending CSO and flag related dirty bits.
964 iris_bind_blend_state(struct pipe_context
*ctx
, void *state
)
966 struct iris_context
*ice
= (struct iris_context
*) ctx
;
967 struct iris_blend_state
*cso
= state
;
969 ice
->state
.cso_blend
= cso
;
970 ice
->state
.blend_enables
= cso
? cso
->blend_enables
: 0;
972 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
;
973 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
974 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
975 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_BLEND
];
979 * Return true if the FS writes to any color outputs which are not disabled
983 has_writeable_rt(const struct iris_blend_state
*cso_blend
,
984 const struct shader_info
*fs_info
)
989 unsigned rt_outputs
= fs_info
->outputs_written
>> FRAG_RESULT_DATA0
;
991 if (fs_info
->outputs_written
& BITFIELD64_BIT(FRAG_RESULT_COLOR
))
992 rt_outputs
= (1 << BRW_MAX_DRAW_BUFFERS
) - 1;
994 return cso_blend
->color_write_enables
& rt_outputs
;
998 * Gallium CSO for depth, stencil, and alpha testing state.
1000 struct iris_depth_stencil_alpha_state
{
1001 /** Partial 3DSTATE_WM_DEPTH_STENCIL. */
1002 uint32_t wmds
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
1004 /** Outbound to BLEND_STATE, 3DSTATE_PS_BLEND, COLOR_CALC_STATE. */
1005 struct pipe_alpha_state alpha
;
1007 /** Outbound to resolve and cache set tracking. */
1008 bool depth_writes_enabled
;
1009 bool stencil_writes_enabled
;
1013 * The pipe->create_depth_stencil_alpha_state() driver hook.
1015 * We encode most of 3DSTATE_WM_DEPTH_STENCIL, and just save off the alpha
1016 * testing state since we need pieces of it in a variety of places.
1019 iris_create_zsa_state(struct pipe_context
*ctx
,
1020 const struct pipe_depth_stencil_alpha_state
*state
)
1022 struct iris_depth_stencil_alpha_state
*cso
=
1023 malloc(sizeof(struct iris_depth_stencil_alpha_state
));
1025 bool two_sided_stencil
= state
->stencil
[1].enabled
;
1027 cso
->alpha
= state
->alpha
;
1028 cso
->depth_writes_enabled
= state
->depth
.writemask
;
1029 cso
->stencil_writes_enabled
=
1030 state
->stencil
[0].writemask
!= 0 ||
1031 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1033 /* The state tracker needs to optimize away EQUAL writes for us. */
1034 assert(!(state
->depth
.func
== PIPE_FUNC_EQUAL
&& state
->depth
.writemask
));
1036 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), cso
->wmds
, wmds
) {
1037 wmds
.StencilFailOp
= state
->stencil
[0].fail_op
;
1038 wmds
.StencilPassDepthFailOp
= state
->stencil
[0].zfail_op
;
1039 wmds
.StencilPassDepthPassOp
= state
->stencil
[0].zpass_op
;
1040 wmds
.StencilTestFunction
=
1041 translate_compare_func(state
->stencil
[0].func
);
1042 wmds
.BackfaceStencilFailOp
= state
->stencil
[1].fail_op
;
1043 wmds
.BackfaceStencilPassDepthFailOp
= state
->stencil
[1].zfail_op
;
1044 wmds
.BackfaceStencilPassDepthPassOp
= state
->stencil
[1].zpass_op
;
1045 wmds
.BackfaceStencilTestFunction
=
1046 translate_compare_func(state
->stencil
[1].func
);
1047 wmds
.DepthTestFunction
= translate_compare_func(state
->depth
.func
);
1048 wmds
.DoubleSidedStencilEnable
= two_sided_stencil
;
1049 wmds
.StencilTestEnable
= state
->stencil
[0].enabled
;
1050 wmds
.StencilBufferWriteEnable
=
1051 state
->stencil
[0].writemask
!= 0 ||
1052 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
1053 wmds
.DepthTestEnable
= state
->depth
.enabled
;
1054 wmds
.DepthBufferWriteEnable
= state
->depth
.writemask
;
1055 wmds
.StencilTestMask
= state
->stencil
[0].valuemask
;
1056 wmds
.StencilWriteMask
= state
->stencil
[0].writemask
;
1057 wmds
.BackfaceStencilTestMask
= state
->stencil
[1].valuemask
;
1058 wmds
.BackfaceStencilWriteMask
= state
->stencil
[1].writemask
;
1059 /* wmds.[Backface]StencilReferenceValue are merged later */
1066 * The pipe->bind_depth_stencil_alpha_state() driver hook.
1068 * Bind a depth/stencil/alpha CSO and flag related dirty bits.
1071 iris_bind_zsa_state(struct pipe_context
*ctx
, void *state
)
1073 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1074 struct iris_depth_stencil_alpha_state
*old_cso
= ice
->state
.cso_zsa
;
1075 struct iris_depth_stencil_alpha_state
*new_cso
= state
;
1078 if (cso_changed(alpha
.ref_value
))
1079 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
1081 if (cso_changed(alpha
.enabled
))
1082 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
| IRIS_DIRTY_BLEND_STATE
;
1084 if (cso_changed(alpha
.func
))
1085 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1087 if (cso_changed(depth_writes_enabled
))
1088 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1090 ice
->state
.depth_writes_enabled
= new_cso
->depth_writes_enabled
;
1091 ice
->state
.stencil_writes_enabled
= new_cso
->stencil_writes_enabled
;
1094 ice
->state
.cso_zsa
= new_cso
;
1095 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1096 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
1097 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_DEPTH_STENCIL_ALPHA
];
1101 * Gallium CSO for rasterizer state.
1103 struct iris_rasterizer_state
{
1104 uint32_t sf
[GENX(3DSTATE_SF_length
)];
1105 uint32_t clip
[GENX(3DSTATE_CLIP_length
)];
1106 uint32_t raster
[GENX(3DSTATE_RASTER_length
)];
1107 uint32_t wm
[GENX(3DSTATE_WM_length
)];
1108 uint32_t line_stipple
[GENX(3DSTATE_LINE_STIPPLE_length
)];
1110 uint8_t num_clip_plane_consts
;
1111 bool clip_halfz
; /* for CC_VIEWPORT */
1112 bool depth_clip_near
; /* for CC_VIEWPORT */
1113 bool depth_clip_far
; /* for CC_VIEWPORT */
1114 bool flatshade
; /* for shader state */
1115 bool flatshade_first
; /* for stream output */
1116 bool clamp_fragment_color
; /* for shader state */
1117 bool light_twoside
; /* for shader state */
1118 bool rasterizer_discard
; /* for 3DSTATE_STREAMOUT and 3DSTATE_CLIP */
1119 bool half_pixel_center
; /* for 3DSTATE_MULTISAMPLE */
1120 bool line_stipple_enable
;
1121 bool poly_stipple_enable
;
1123 bool force_persample_interp
;
1124 enum pipe_sprite_coord_mode sprite_coord_mode
; /* PIPE_SPRITE_* */
1125 uint16_t sprite_coord_enable
;
1129 get_line_width(const struct pipe_rasterizer_state
*state
)
1131 float line_width
= state
->line_width
;
1133 /* From the OpenGL 4.4 spec:
1135 * "The actual width of non-antialiased lines is determined by rounding
1136 * the supplied width to the nearest integer, then clamping it to the
1137 * implementation-dependent maximum non-antialiased line width."
1139 if (!state
->multisample
&& !state
->line_smooth
)
1140 line_width
= roundf(state
->line_width
);
1142 if (!state
->multisample
&& state
->line_smooth
&& line_width
< 1.5f
) {
1143 /* For 1 pixel line thickness or less, the general anti-aliasing
1144 * algorithm gives up, and a garbage line is generated. Setting a
1145 * Line Width of 0.0 specifies the rasterization of the "thinnest"
1146 * (one-pixel-wide), non-antialiased lines.
1148 * Lines rendered with zero Line Width are rasterized using the
1149 * "Grid Intersection Quantization" rules as specified by the
1150 * "Zero-Width (Cosmetic) Line Rasterization" section of the docs.
1159 * The pipe->create_rasterizer_state() driver hook.
1162 iris_create_rasterizer_state(struct pipe_context
*ctx
,
1163 const struct pipe_rasterizer_state
*state
)
1165 struct iris_rasterizer_state
*cso
=
1166 malloc(sizeof(struct iris_rasterizer_state
));
1168 cso
->multisample
= state
->multisample
;
1169 cso
->force_persample_interp
= state
->force_persample_interp
;
1170 cso
->clip_halfz
= state
->clip_halfz
;
1171 cso
->depth_clip_near
= state
->depth_clip_near
;
1172 cso
->depth_clip_far
= state
->depth_clip_far
;
1173 cso
->flatshade
= state
->flatshade
;
1174 cso
->flatshade_first
= state
->flatshade_first
;
1175 cso
->clamp_fragment_color
= state
->clamp_fragment_color
;
1176 cso
->light_twoside
= state
->light_twoside
;
1177 cso
->rasterizer_discard
= state
->rasterizer_discard
;
1178 cso
->half_pixel_center
= state
->half_pixel_center
;
1179 cso
->sprite_coord_mode
= state
->sprite_coord_mode
;
1180 cso
->sprite_coord_enable
= state
->sprite_coord_enable
;
1181 cso
->line_stipple_enable
= state
->line_stipple_enable
;
1182 cso
->poly_stipple_enable
= state
->poly_stipple_enable
;
1184 if (state
->clip_plane_enable
!= 0)
1185 cso
->num_clip_plane_consts
= util_logbase2(state
->clip_plane_enable
) + 1;
1187 cso
->num_clip_plane_consts
= 0;
1189 float line_width
= get_line_width(state
);
1191 iris_pack_command(GENX(3DSTATE_SF
), cso
->sf
, sf
) {
1192 sf
.StatisticsEnable
= true;
1193 sf
.ViewportTransformEnable
= true;
1194 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
1195 sf
.LineEndCapAntialiasingRegionWidth
=
1196 state
->line_smooth
? _10pixels
: _05pixels
;
1197 sf
.LastPixelEnable
= state
->line_last_pixel
;
1198 sf
.LineWidth
= line_width
;
1199 sf
.SmoothPointEnable
= (state
->point_smooth
|| state
->multisample
) &&
1200 !state
->point_quad_rasterization
;
1201 sf
.PointWidthSource
= state
->point_size_per_vertex
? Vertex
: State
;
1202 sf
.PointWidth
= state
->point_size
;
1204 if (state
->flatshade_first
) {
1205 sf
.TriangleFanProvokingVertexSelect
= 1;
1207 sf
.TriangleStripListProvokingVertexSelect
= 2;
1208 sf
.TriangleFanProvokingVertexSelect
= 2;
1209 sf
.LineStripListProvokingVertexSelect
= 1;
1213 iris_pack_command(GENX(3DSTATE_RASTER
), cso
->raster
, rr
) {
1214 rr
.FrontWinding
= state
->front_ccw
? CounterClockwise
: Clockwise
;
1215 rr
.CullMode
= translate_cull_mode(state
->cull_face
);
1216 rr
.FrontFaceFillMode
= translate_fill_mode(state
->fill_front
);
1217 rr
.BackFaceFillMode
= translate_fill_mode(state
->fill_back
);
1218 rr
.DXMultisampleRasterizationEnable
= state
->multisample
;
1219 rr
.GlobalDepthOffsetEnableSolid
= state
->offset_tri
;
1220 rr
.GlobalDepthOffsetEnableWireframe
= state
->offset_line
;
1221 rr
.GlobalDepthOffsetEnablePoint
= state
->offset_point
;
1222 rr
.GlobalDepthOffsetConstant
= state
->offset_units
* 2;
1223 rr
.GlobalDepthOffsetScale
= state
->offset_scale
;
1224 rr
.GlobalDepthOffsetClamp
= state
->offset_clamp
;
1225 rr
.SmoothPointEnable
= state
->point_smooth
;
1226 rr
.AntialiasingEnable
= state
->line_smooth
;
1227 rr
.ScissorRectangleEnable
= state
->scissor
;
1229 rr
.ViewportZNearClipTestEnable
= state
->depth_clip_near
;
1230 rr
.ViewportZFarClipTestEnable
= state
->depth_clip_far
;
1232 rr
.ViewportZClipTestEnable
= (state
->depth_clip_near
|| state
->depth_clip_far
);
1234 /* TODO: ConservativeRasterizationEnable */
1237 iris_pack_command(GENX(3DSTATE_CLIP
), cso
->clip
, cl
) {
1238 /* cl.NonPerspectiveBarycentricEnable is filled in at draw time from
1239 * the FS program; cl.ForceZeroRTAIndexEnable is filled in from the FB.
1241 cl
.EarlyCullEnable
= true;
1242 cl
.UserClipDistanceClipTestEnableBitmask
= state
->clip_plane_enable
;
1243 cl
.ForceUserClipDistanceClipTestEnableBitmask
= true;
1244 cl
.APIMode
= state
->clip_halfz
? APIMODE_D3D
: APIMODE_OGL
;
1245 cl
.GuardbandClipTestEnable
= true;
1246 cl
.ClipEnable
= true;
1247 cl
.ViewportXYClipTestEnable
= state
->point_tri_clip
;
1248 cl
.MinimumPointWidth
= 0.125;
1249 cl
.MaximumPointWidth
= 255.875;
1251 if (state
->flatshade_first
) {
1252 cl
.TriangleFanProvokingVertexSelect
= 1;
1254 cl
.TriangleStripListProvokingVertexSelect
= 2;
1255 cl
.TriangleFanProvokingVertexSelect
= 2;
1256 cl
.LineStripListProvokingVertexSelect
= 1;
1260 iris_pack_command(GENX(3DSTATE_WM
), cso
->wm
, wm
) {
1261 /* wm.BarycentricInterpolationMode and wm.EarlyDepthStencilControl are
1262 * filled in at draw time from the FS program.
1264 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1265 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1266 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1267 wm
.LineStippleEnable
= state
->line_stipple_enable
;
1268 wm
.PolygonStippleEnable
= state
->poly_stipple_enable
;
1271 /* Remap from 0..255 back to 1..256 */
1272 const unsigned line_stipple_factor
= state
->line_stipple_factor
+ 1;
1274 iris_pack_command(GENX(3DSTATE_LINE_STIPPLE
), cso
->line_stipple
, line
) {
1275 line
.LineStipplePattern
= state
->line_stipple_pattern
;
1276 line
.LineStippleInverseRepeatCount
= 1.0f
/ line_stipple_factor
;
1277 line
.LineStippleRepeatCount
= line_stipple_factor
;
1284 * The pipe->bind_rasterizer_state() driver hook.
1286 * Bind a rasterizer CSO and flag related dirty bits.
1289 iris_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
1291 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1292 struct iris_rasterizer_state
*old_cso
= ice
->state
.cso_rast
;
1293 struct iris_rasterizer_state
*new_cso
= state
;
1296 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
1297 if (cso_changed_memcmp(line_stipple
))
1298 ice
->state
.dirty
|= IRIS_DIRTY_LINE_STIPPLE
;
1300 if (cso_changed(half_pixel_center
))
1301 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
1303 if (cso_changed(line_stipple_enable
) || cso_changed(poly_stipple_enable
))
1304 ice
->state
.dirty
|= IRIS_DIRTY_WM
;
1306 if (cso_changed(rasterizer_discard
))
1307 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
| IRIS_DIRTY_CLIP
;
1309 if (cso_changed(flatshade_first
))
1310 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
1312 if (cso_changed(depth_clip_near
) || cso_changed(depth_clip_far
) ||
1313 cso_changed(clip_halfz
))
1314 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1316 if (cso_changed(sprite_coord_enable
) ||
1317 cso_changed(sprite_coord_mode
) ||
1318 cso_changed(light_twoside
))
1319 ice
->state
.dirty
|= IRIS_DIRTY_SBE
;
1322 ice
->state
.cso_rast
= new_cso
;
1323 ice
->state
.dirty
|= IRIS_DIRTY_RASTER
;
1324 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
1325 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_RASTERIZER
];
1329 * Return true if the given wrap mode requires the border color to exist.
1331 * (We can skip uploading it if the sampler isn't going to use it.)
1334 wrap_mode_needs_border_color(unsigned wrap_mode
)
1336 return wrap_mode
== TCM_CLAMP_BORDER
|| wrap_mode
== TCM_HALF_BORDER
;
1340 * Gallium CSO for sampler state.
1342 struct iris_sampler_state
{
1343 union pipe_color_union border_color
;
1344 bool needs_border_color
;
1346 uint32_t sampler_state
[GENX(SAMPLER_STATE_length
)];
1350 * The pipe->create_sampler_state() driver hook.
1352 * We fill out SAMPLER_STATE (except for the border color pointer), and
1353 * store that on the CPU. It doesn't make sense to upload it to a GPU
1354 * buffer object yet, because 3DSTATE_SAMPLER_STATE_POINTERS requires
1355 * all bound sampler states to be in contiguous memor.
1358 iris_create_sampler_state(struct pipe_context
*ctx
,
1359 const struct pipe_sampler_state
*state
)
1361 struct iris_sampler_state
*cso
= CALLOC_STRUCT(iris_sampler_state
);
1366 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST
== MAPFILTER_NEAREST
);
1367 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR
== MAPFILTER_LINEAR
);
1369 unsigned wrap_s
= translate_wrap(state
->wrap_s
);
1370 unsigned wrap_t
= translate_wrap(state
->wrap_t
);
1371 unsigned wrap_r
= translate_wrap(state
->wrap_r
);
1373 memcpy(&cso
->border_color
, &state
->border_color
, sizeof(cso
->border_color
));
1375 cso
->needs_border_color
= wrap_mode_needs_border_color(wrap_s
) ||
1376 wrap_mode_needs_border_color(wrap_t
) ||
1377 wrap_mode_needs_border_color(wrap_r
);
1379 float min_lod
= state
->min_lod
;
1380 unsigned mag_img_filter
= state
->mag_img_filter
;
1382 // XXX: explain this code ported from ilo...I don't get it at all...
1383 if (state
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
&&
1384 state
->min_lod
> 0.0f
) {
1386 mag_img_filter
= state
->min_img_filter
;
1389 iris_pack_state(GENX(SAMPLER_STATE
), cso
->sampler_state
, samp
) {
1390 samp
.TCXAddressControlMode
= wrap_s
;
1391 samp
.TCYAddressControlMode
= wrap_t
;
1392 samp
.TCZAddressControlMode
= wrap_r
;
1393 samp
.CubeSurfaceControlMode
= state
->seamless_cube_map
;
1394 samp
.NonnormalizedCoordinateEnable
= !state
->normalized_coords
;
1395 samp
.MinModeFilter
= state
->min_img_filter
;
1396 samp
.MagModeFilter
= mag_img_filter
;
1397 samp
.MipModeFilter
= translate_mip_filter(state
->min_mip_filter
);
1398 samp
.MaximumAnisotropy
= RATIO21
;
1400 if (state
->max_anisotropy
>= 2) {
1401 if (state
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
1402 samp
.MinModeFilter
= MAPFILTER_ANISOTROPIC
;
1403 samp
.AnisotropicAlgorithm
= EWAApproximation
;
1406 if (state
->mag_img_filter
== PIPE_TEX_FILTER_LINEAR
)
1407 samp
.MagModeFilter
= MAPFILTER_ANISOTROPIC
;
1409 samp
.MaximumAnisotropy
=
1410 MIN2((state
->max_anisotropy
- 2) / 2, RATIO161
);
1413 /* Set address rounding bits if not using nearest filtering. */
1414 if (state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1415 samp
.UAddressMinFilterRoundingEnable
= true;
1416 samp
.VAddressMinFilterRoundingEnable
= true;
1417 samp
.RAddressMinFilterRoundingEnable
= true;
1420 if (state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
1421 samp
.UAddressMagFilterRoundingEnable
= true;
1422 samp
.VAddressMagFilterRoundingEnable
= true;
1423 samp
.RAddressMagFilterRoundingEnable
= true;
1426 if (state
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
1427 samp
.ShadowFunction
= translate_shadow_func(state
->compare_func
);
1429 const float hw_max_lod
= GEN_GEN
>= 7 ? 14 : 13;
1431 samp
.LODPreClampMode
= CLAMP_MODE_OGL
;
1432 samp
.MinLOD
= CLAMP(min_lod
, 0, hw_max_lod
);
1433 samp
.MaxLOD
= CLAMP(state
->max_lod
, 0, hw_max_lod
);
1434 samp
.TextureLODBias
= CLAMP(state
->lod_bias
, -16, 15);
1436 /* .BorderColorPointer is filled in by iris_bind_sampler_states. */
1443 * The pipe->bind_sampler_states() driver hook.
1446 iris_bind_sampler_states(struct pipe_context
*ctx
,
1447 enum pipe_shader_type p_stage
,
1448 unsigned start
, unsigned count
,
1451 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1452 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1453 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1455 assert(start
+ count
<= IRIS_MAX_TEXTURE_SAMPLERS
);
1457 for (int i
= 0; i
< count
; i
++) {
1458 shs
->samplers
[start
+ i
] = states
[i
];
1461 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
;
1465 * Upload the sampler states into a contiguous area of GPU memory, for
1466 * for 3DSTATE_SAMPLER_STATE_POINTERS_*.
1468 * Also fill out the border color state pointers.
1471 iris_upload_sampler_states(struct iris_context
*ice
, gl_shader_stage stage
)
1473 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1474 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
1476 /* We assume the state tracker will call pipe->bind_sampler_states()
1477 * if the program's number of textures changes.
1479 unsigned count
= info
? util_last_bit(info
->textures_used
) : 0;
1484 /* Assemble the SAMPLER_STATEs into a contiguous table that lives
1485 * in the dynamic state memory zone, so we can point to it via the
1486 * 3DSTATE_SAMPLER_STATE_POINTERS_* commands.
1489 upload_state(ice
->state
.dynamic_uploader
, &shs
->sampler_table
,
1490 count
* 4 * GENX(SAMPLER_STATE_length
), 32);
1494 struct pipe_resource
*res
= shs
->sampler_table
.res
;
1495 shs
->sampler_table
.offset
+=
1496 iris_bo_offset_from_base_address(iris_resource_bo(res
));
1498 /* Make sure all land in the same BO */
1499 iris_border_color_pool_reserve(ice
, IRIS_MAX_TEXTURE_SAMPLERS
);
1501 ice
->state
.need_border_colors
&= ~(1 << stage
);
1503 for (int i
= 0; i
< count
; i
++) {
1504 struct iris_sampler_state
*state
= shs
->samplers
[i
];
1505 struct iris_sampler_view
*tex
= shs
->textures
[i
];
1508 memset(map
, 0, 4 * GENX(SAMPLER_STATE_length
));
1509 } else if (!state
->needs_border_color
) {
1510 memcpy(map
, state
->sampler_state
, 4 * GENX(SAMPLER_STATE_length
));
1512 ice
->state
.need_border_colors
|= 1 << stage
;
1514 /* We may need to swizzle the border color for format faking.
1515 * A/LA formats are faked as R/RG with 000R or R00G swizzles.
1516 * This means we need to move the border color's A channel into
1517 * the R or G channels so that those read swizzles will move it
1520 union pipe_color_union
*color
= &state
->border_color
;
1522 union pipe_color_union tmp
;
1523 enum pipe_format internal_format
= tex
->res
->internal_format
;
1525 if (util_format_is_alpha(internal_format
)) {
1526 unsigned char swz
[4] = {
1527 PIPE_SWIZZLE_W
, PIPE_SWIZZLE_0
,
1528 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
1530 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
1532 } else if (util_format_is_luminance_alpha(internal_format
) &&
1533 internal_format
!= PIPE_FORMAT_L8A8_SRGB
) {
1534 unsigned char swz
[4] = {
1535 PIPE_SWIZZLE_X
, PIPE_SWIZZLE_W
,
1536 PIPE_SWIZZLE_0
, PIPE_SWIZZLE_0
1538 util_format_apply_color_swizzle(&tmp
, color
, swz
, true);
1543 /* Stream out the border color and merge the pointer. */
1544 uint32_t offset
= iris_upload_border_color(ice
, color
);
1546 uint32_t dynamic
[GENX(SAMPLER_STATE_length
)];
1547 iris_pack_state(GENX(SAMPLER_STATE
), dynamic
, dyns
) {
1548 dyns
.BorderColorPointer
= offset
;
1551 for (uint32_t j
= 0; j
< GENX(SAMPLER_STATE_length
); j
++)
1552 map
[j
] = state
->sampler_state
[j
] | dynamic
[j
];
1555 map
+= GENX(SAMPLER_STATE_length
);
1559 static enum isl_channel_select
1560 fmt_swizzle(const struct iris_format_info
*fmt
, enum pipe_swizzle swz
)
1563 case PIPE_SWIZZLE_X
: return fmt
->swizzle
.r
;
1564 case PIPE_SWIZZLE_Y
: return fmt
->swizzle
.g
;
1565 case PIPE_SWIZZLE_Z
: return fmt
->swizzle
.b
;
1566 case PIPE_SWIZZLE_W
: return fmt
->swizzle
.a
;
1567 case PIPE_SWIZZLE_1
: return SCS_ONE
;
1568 case PIPE_SWIZZLE_0
: return SCS_ZERO
;
1569 default: unreachable("invalid swizzle");
1574 fill_buffer_surface_state(struct isl_device
*isl_dev
,
1577 enum isl_format format
,
1578 struct isl_swizzle swizzle
,
1582 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
1583 const unsigned cpp
= format
== ISL_FORMAT_RAW
? 1 : fmtl
->bpb
/ 8;
1585 /* The ARB_texture_buffer_specification says:
1587 * "The number of texels in the buffer texture's texel array is given by
1589 * floor(<buffer_size> / (<components> * sizeof(<base_type>)),
1591 * where <buffer_size> is the size of the buffer object, in basic
1592 * machine units and <components> and <base_type> are the element count
1593 * and base data type for elements, as specified in Table X.1. The
1594 * number of texels in the texel array is then clamped to the
1595 * implementation-dependent limit MAX_TEXTURE_BUFFER_SIZE_ARB."
1597 * We need to clamp the size in bytes to MAX_TEXTURE_BUFFER_SIZE * stride,
1598 * so that when ISL divides by stride to obtain the number of texels, that
1599 * texel count is clamped to MAX_TEXTURE_BUFFER_SIZE.
1601 unsigned final_size
=
1602 MIN3(size
, bo
->size
- offset
, IRIS_MAX_TEXTURE_BUFFER_SIZE
* cpp
);
1604 isl_buffer_fill_state(isl_dev
, map
,
1605 .address
= bo
->gtt_offset
+ offset
,
1606 .size_B
= final_size
,
1613 #define SURFACE_STATE_ALIGNMENT 64
1616 * Allocate several contiguous SURFACE_STATE structures, one for each
1617 * supported auxiliary surface mode.
1620 alloc_surface_states(struct u_upload_mgr
*mgr
,
1621 struct iris_state_ref
*ref
,
1622 unsigned aux_usages
)
1624 const unsigned surf_size
= 4 * GENX(RENDER_SURFACE_STATE_length
);
1626 /* If this changes, update this to explicitly align pointers */
1627 STATIC_ASSERT(surf_size
== SURFACE_STATE_ALIGNMENT
);
1629 assert(aux_usages
!= 0);
1632 upload_state(mgr
, ref
, util_bitcount(aux_usages
) * surf_size
,
1633 SURFACE_STATE_ALIGNMENT
);
1635 ref
->offset
+= iris_bo_offset_from_base_address(iris_resource_bo(ref
->res
));
1641 fill_surface_state(struct isl_device
*isl_dev
,
1643 struct iris_resource
*res
,
1644 struct isl_view
*view
,
1647 struct isl_surf_fill_state_info f
= {
1650 .mocs
= mocs(res
->bo
),
1651 .address
= res
->bo
->gtt_offset
,
1654 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
1655 f
.aux_surf
= &res
->aux
.surf
;
1656 f
.aux_usage
= aux_usage
;
1657 f
.aux_address
= res
->aux
.bo
->gtt_offset
+ res
->aux
.offset
;
1658 f
.clear_color
= res
->aux
.clear_color
;
1661 isl_surf_fill_state_s(isl_dev
, map
, &f
);
1665 * The pipe->create_sampler_view() driver hook.
1667 static struct pipe_sampler_view
*
1668 iris_create_sampler_view(struct pipe_context
*ctx
,
1669 struct pipe_resource
*tex
,
1670 const struct pipe_sampler_view
*tmpl
)
1672 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1673 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1674 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1675 struct iris_sampler_view
*isv
= calloc(1, sizeof(struct iris_sampler_view
));
1680 /* initialize base object */
1682 isv
->base
.context
= ctx
;
1683 isv
->base
.texture
= NULL
;
1684 pipe_reference_init(&isv
->base
.reference
, 1);
1685 pipe_resource_reference(&isv
->base
.texture
, tex
);
1687 if (util_format_is_depth_or_stencil(tmpl
->format
)) {
1688 struct iris_resource
*zres
, *sres
;
1689 const struct util_format_description
*desc
=
1690 util_format_description(tmpl
->format
);
1692 iris_get_depth_stencil_resources(tex
, &zres
, &sres
);
1694 tex
= util_format_has_depth(desc
) ? &zres
->base
: &sres
->base
;
1697 isv
->res
= (struct iris_resource
*) tex
;
1699 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
1700 &isv
->surface_state
,
1701 isv
->res
->aux
.possible_usages
);
1705 isl_surf_usage_flags_t usage
= ISL_SURF_USAGE_TEXTURE_BIT
;
1707 if (isv
->base
.target
== PIPE_TEXTURE_CUBE
||
1708 isv
->base
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1709 usage
|= ISL_SURF_USAGE_CUBE_BIT
;
1711 const struct iris_format_info fmt
=
1712 iris_format_for_usage(devinfo
, tmpl
->format
, usage
);
1714 isv
->clear_color
= isv
->res
->aux
.clear_color
;
1716 isv
->view
= (struct isl_view
) {
1718 .swizzle
= (struct isl_swizzle
) {
1719 .r
= fmt_swizzle(&fmt
, tmpl
->swizzle_r
),
1720 .g
= fmt_swizzle(&fmt
, tmpl
->swizzle_g
),
1721 .b
= fmt_swizzle(&fmt
, tmpl
->swizzle_b
),
1722 .a
= fmt_swizzle(&fmt
, tmpl
->swizzle_a
),
1727 /* Fill out SURFACE_STATE for this view. */
1728 if (tmpl
->target
!= PIPE_BUFFER
) {
1729 isv
->view
.base_level
= tmpl
->u
.tex
.first_level
;
1730 isv
->view
.levels
= tmpl
->u
.tex
.last_level
- tmpl
->u
.tex
.first_level
+ 1;
1731 // XXX: do I need to port f9fd0cf4790cb2a530e75d1a2206dbb9d8af7cb2?
1732 isv
->view
.base_array_layer
= tmpl
->u
.tex
.first_layer
;
1733 isv
->view
.array_len
=
1734 tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
1736 unsigned aux_modes
= isv
->res
->aux
.possible_usages
;
1738 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
1740 /* If we have a multisampled depth buffer, do not create a sampler
1741 * surface state with HiZ.
1743 if (!(aux_usage
== ISL_AUX_USAGE_HIZ
&& isv
->res
->surf
.samples
> 1)) {
1744 fill_surface_state(&screen
->isl_dev
, map
, isv
->res
, &isv
->view
,
1748 map
+= SURFACE_STATE_ALIGNMENT
;
1751 fill_buffer_surface_state(&screen
->isl_dev
, isv
->res
->bo
, map
,
1752 isv
->view
.format
, isv
->view
.swizzle
,
1753 tmpl
->u
.buf
.offset
, tmpl
->u
.buf
.size
);
1760 iris_sampler_view_destroy(struct pipe_context
*ctx
,
1761 struct pipe_sampler_view
*state
)
1763 struct iris_sampler_view
*isv
= (void *) state
;
1764 pipe_resource_reference(&state
->texture
, NULL
);
1765 pipe_resource_reference(&isv
->surface_state
.res
, NULL
);
1770 * The pipe->create_surface() driver hook.
1772 * In Gallium nomenclature, "surfaces" are a view of a resource that
1773 * can be bound as a render target or depth/stencil buffer.
1775 static struct pipe_surface
*
1776 iris_create_surface(struct pipe_context
*ctx
,
1777 struct pipe_resource
*tex
,
1778 const struct pipe_surface
*tmpl
)
1780 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1781 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1782 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1783 struct iris_surface
*surf
= calloc(1, sizeof(struct iris_surface
));
1784 struct pipe_surface
*psurf
= &surf
->base
;
1785 struct iris_resource
*res
= (struct iris_resource
*) tex
;
1790 pipe_reference_init(&psurf
->reference
, 1);
1791 pipe_resource_reference(&psurf
->texture
, tex
);
1792 psurf
->context
= ctx
;
1793 psurf
->format
= tmpl
->format
;
1794 psurf
->width
= tex
->width0
;
1795 psurf
->height
= tex
->height0
;
1796 psurf
->texture
= tex
;
1797 psurf
->u
.tex
.first_layer
= tmpl
->u
.tex
.first_layer
;
1798 psurf
->u
.tex
.last_layer
= tmpl
->u
.tex
.last_layer
;
1799 psurf
->u
.tex
.level
= tmpl
->u
.tex
.level
;
1801 isl_surf_usage_flags_t usage
= 0;
1803 usage
= ISL_SURF_USAGE_STORAGE_BIT
;
1804 else if (util_format_is_depth_or_stencil(tmpl
->format
))
1805 usage
= ISL_SURF_USAGE_DEPTH_BIT
;
1807 usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
1809 const struct iris_format_info fmt
=
1810 iris_format_for_usage(devinfo
, psurf
->format
, usage
);
1812 if ((usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) &&
1813 !isl_format_supports_rendering(devinfo
, fmt
.fmt
)) {
1814 /* Framebuffer validation will reject this invalid case, but it
1815 * hasn't had the opportunity yet. In the meantime, we need to
1816 * avoid hitting ISL asserts about unsupported formats below.
1822 surf
->view
= (struct isl_view
) {
1824 .base_level
= tmpl
->u
.tex
.level
,
1826 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
1827 .array_len
= tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1,
1828 .swizzle
= ISL_SWIZZLE_IDENTITY
,
1832 surf
->clear_color
= res
->aux
.clear_color
;
1834 /* Bail early for depth/stencil - we don't want SURFACE_STATE for them. */
1835 if (res
->surf
.usage
& (ISL_SURF_USAGE_DEPTH_BIT
|
1836 ISL_SURF_USAGE_STENCIL_BIT
))
1840 void *map
= alloc_surface_states(ice
->state
.surface_uploader
,
1841 &surf
->surface_state
,
1842 res
->aux
.possible_usages
);
1846 unsigned aux_modes
= res
->aux
.possible_usages
;
1848 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
1850 fill_surface_state(&screen
->isl_dev
, map
, res
, &surf
->view
, aux_usage
);
1852 map
+= SURFACE_STATE_ALIGNMENT
;
1860 fill_default_image_param(struct brw_image_param
*param
)
1862 memset(param
, 0, sizeof(*param
));
1863 /* Set the swizzling shifts to all-ones to effectively disable swizzling --
1864 * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
1865 * detailed explanation of these parameters.
1867 param
->swizzling
[0] = 0xff;
1868 param
->swizzling
[1] = 0xff;
1872 fill_buffer_image_param(struct brw_image_param
*param
,
1873 enum pipe_format pfmt
,
1876 const unsigned cpp
= util_format_get_blocksize(pfmt
);
1878 fill_default_image_param(param
);
1879 param
->size
[0] = size
/ cpp
;
1880 param
->stride
[0] = cpp
;
1883 #define isl_surf_fill_image_param(x, ...)
1884 #define fill_default_image_param(x, ...)
1885 #define fill_buffer_image_param(x, ...)
1889 * The pipe->set_shader_images() driver hook.
1892 iris_set_shader_images(struct pipe_context
*ctx
,
1893 enum pipe_shader_type p_stage
,
1894 unsigned start_slot
, unsigned count
,
1895 const struct pipe_image_view
*p_images
)
1897 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1898 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1899 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1900 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1901 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
1903 shs
->bound_image_views
&= ~u_bit_consecutive(start_slot
, count
);
1905 for (unsigned i
= 0; i
< count
; i
++) {
1906 if (p_images
&& p_images
[i
].resource
) {
1907 const struct pipe_image_view
*img
= &p_images
[i
];
1908 struct iris_resource
*res
= (void *) img
->resource
;
1909 pipe_resource_reference(&shs
->image
[start_slot
+ i
].res
, &res
->base
);
1911 shs
->bound_image_views
|= 1 << (start_slot
+ i
);
1913 res
->bind_history
|= PIPE_BIND_SHADER_IMAGE
;
1915 // XXX: these are not retained forever, use a separate uploader?
1917 alloc_surface_states(ice
->state
.surface_uploader
,
1918 &shs
->image
[start_slot
+ i
].surface_state
,
1919 1 << ISL_AUX_USAGE_NONE
);
1920 if (!unlikely(map
)) {
1921 pipe_resource_reference(&shs
->image
[start_slot
+ i
].res
, NULL
);
1925 isl_surf_usage_flags_t usage
= ISL_SURF_USAGE_STORAGE_BIT
;
1926 enum isl_format isl_fmt
=
1927 iris_format_for_usage(devinfo
, img
->format
, usage
).fmt
;
1929 bool untyped_fallback
= false;
1931 if (img
->shader_access
& PIPE_IMAGE_ACCESS_READ
) {
1932 /* On Gen8, try to use typed surfaces reads (which support a
1933 * limited number of formats), and if not possible, fall back
1936 untyped_fallback
= GEN_GEN
== 8 &&
1937 !isl_has_matching_typed_storage_image_format(devinfo
, isl_fmt
);
1939 if (untyped_fallback
)
1940 isl_fmt
= ISL_FORMAT_RAW
;
1942 isl_fmt
= isl_lower_storage_image_format(devinfo
, isl_fmt
);
1945 shs
->image
[start_slot
+ i
].access
= img
->shader_access
;
1947 if (res
->base
.target
!= PIPE_BUFFER
) {
1948 struct isl_view view
= {
1950 .base_level
= img
->u
.tex
.level
,
1952 .base_array_layer
= img
->u
.tex
.first_layer
,
1953 .array_len
= img
->u
.tex
.last_layer
- img
->u
.tex
.first_layer
+ 1,
1954 .swizzle
= ISL_SWIZZLE_IDENTITY
,
1958 if (untyped_fallback
) {
1959 fill_buffer_surface_state(&screen
->isl_dev
, res
->bo
, map
,
1960 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
1963 /* Images don't support compression */
1964 unsigned aux_modes
= 1 << ISL_AUX_USAGE_NONE
;
1966 enum isl_aux_usage usage
= u_bit_scan(&aux_modes
);
1968 fill_surface_state(&screen
->isl_dev
, map
, res
, &view
, usage
);
1970 map
+= SURFACE_STATE_ALIGNMENT
;
1974 isl_surf_fill_image_param(&screen
->isl_dev
,
1975 &shs
->image
[start_slot
+ i
].param
,
1978 fill_buffer_surface_state(&screen
->isl_dev
, res
->bo
, map
,
1979 isl_fmt
, ISL_SWIZZLE_IDENTITY
,
1980 img
->u
.buf
.offset
, img
->u
.buf
.size
);
1981 fill_buffer_image_param(&shs
->image
[start_slot
+ i
].param
,
1982 img
->format
, img
->u
.buf
.size
);
1985 pipe_resource_reference(&shs
->image
[start_slot
+ i
].res
, NULL
);
1986 pipe_resource_reference(&shs
->image
[start_slot
+ i
].surface_state
.res
,
1988 fill_default_image_param(&shs
->image
[start_slot
+ i
].param
);
1992 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
1994 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
1995 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
1997 /* Broadwell also needs brw_image_params re-uploaded */
1999 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
2000 shs
->cbuf0_needs_upload
= true;
2006 * The pipe->set_sampler_views() driver hook.
2009 iris_set_sampler_views(struct pipe_context
*ctx
,
2010 enum pipe_shader_type p_stage
,
2011 unsigned start
, unsigned count
,
2012 struct pipe_sampler_view
**views
)
2014 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2015 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2016 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2018 shs
->bound_sampler_views
&= ~u_bit_consecutive(start
, count
);
2020 for (unsigned i
= 0; i
< count
; i
++) {
2021 pipe_sampler_view_reference((struct pipe_sampler_view
**)
2022 &shs
->textures
[start
+ i
], views
[i
]);
2023 struct iris_sampler_view
*view
= (void *) views
[i
];
2025 view
->res
->bind_history
|= PIPE_BIND_SAMPLER_VIEW
;
2026 shs
->bound_sampler_views
|= 1 << (start
+ i
);
2030 ice
->state
.dirty
|= (IRIS_DIRTY_BINDINGS_VS
<< stage
);
2032 stage
== MESA_SHADER_COMPUTE
? IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES
2033 : IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2037 * The pipe->set_tess_state() driver hook.
2040 iris_set_tess_state(struct pipe_context
*ctx
,
2041 const float default_outer_level
[4],
2042 const float default_inner_level
[2])
2044 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2045 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_TESS_CTRL
];
2047 memcpy(&ice
->state
.default_outer_level
[0], &default_outer_level
[0], 4 * sizeof(float));
2048 memcpy(&ice
->state
.default_inner_level
[0], &default_inner_level
[0], 2 * sizeof(float));
2050 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_TCS
;
2051 shs
->cbuf0_needs_upload
= true;
2055 iris_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
*p_surf
)
2057 struct iris_surface
*surf
= (void *) p_surf
;
2058 pipe_resource_reference(&p_surf
->texture
, NULL
);
2059 pipe_resource_reference(&surf
->surface_state
.res
, NULL
);
2064 iris_set_clip_state(struct pipe_context
*ctx
,
2065 const struct pipe_clip_state
*state
)
2067 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2068 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_VERTEX
];
2070 memcpy(&ice
->state
.clip_planes
, state
, sizeof(*state
));
2072 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
;
2073 shs
->cbuf0_needs_upload
= true;
2077 * The pipe->set_polygon_stipple() driver hook.
2080 iris_set_polygon_stipple(struct pipe_context
*ctx
,
2081 const struct pipe_poly_stipple
*state
)
2083 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2084 memcpy(&ice
->state
.poly_stipple
, state
, sizeof(*state
));
2085 ice
->state
.dirty
|= IRIS_DIRTY_POLYGON_STIPPLE
;
2089 * The pipe->set_sample_mask() driver hook.
2092 iris_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
2094 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2096 /* We only support 16x MSAA, so we have 16 bits of sample maks.
2097 * st/mesa may pass us 0xffffffff though, meaning "enable all samples".
2099 ice
->state
.sample_mask
= sample_mask
& 0xffff;
2100 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLE_MASK
;
2104 * The pipe->set_scissor_states() driver hook.
2106 * This corresponds to our SCISSOR_RECT state structures. It's an
2107 * exact match, so we just store them, and memcpy them out later.
2110 iris_set_scissor_states(struct pipe_context
*ctx
,
2111 unsigned start_slot
,
2112 unsigned num_scissors
,
2113 const struct pipe_scissor_state
*rects
)
2115 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2117 for (unsigned i
= 0; i
< num_scissors
; i
++) {
2118 if (rects
[i
].minx
== rects
[i
].maxx
|| rects
[i
].miny
== rects
[i
].maxy
) {
2119 /* If the scissor was out of bounds and got clamped to 0 width/height
2120 * at the bounds, the subtraction of 1 from maximums could produce a
2121 * negative number and thus not clip anything. Instead, just provide
2122 * a min > max scissor inside the bounds, which produces the expected
2125 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2126 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,
2129 ice
->state
.scissors
[start_slot
+ i
] = (struct pipe_scissor_state
) {
2130 .minx
= rects
[i
].minx
, .miny
= rects
[i
].miny
,
2131 .maxx
= rects
[i
].maxx
- 1, .maxy
= rects
[i
].maxy
- 1,
2136 ice
->state
.dirty
|= IRIS_DIRTY_SCISSOR_RECT
;
2140 * The pipe->set_stencil_ref() driver hook.
2142 * This is added to 3DSTATE_WM_DEPTH_STENCIL dynamically at draw time.
2145 iris_set_stencil_ref(struct pipe_context
*ctx
,
2146 const struct pipe_stencil_ref
*state
)
2148 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2149 memcpy(&ice
->state
.stencil_ref
, state
, sizeof(*state
));
2151 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
2153 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
2157 viewport_extent(const struct pipe_viewport_state
*state
, int axis
, float sign
)
2159 return copysignf(state
->scale
[axis
], sign
) + state
->translate
[axis
];
2163 calculate_guardband_size(uint32_t fb_width
, uint32_t fb_height
,
2164 float m00
, float m11
, float m30
, float m31
,
2165 float *xmin
, float *xmax
,
2166 float *ymin
, float *ymax
)
2168 /* According to the "Vertex X,Y Clamping and Quantization" section of the
2169 * Strips and Fans documentation:
2171 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
2172 * fixed-point "guardband" range supported by the rasterization hardware"
2176 * "In almost all circumstances, if an object’s vertices are actually
2177 * modified by this clamping (i.e., had X or Y coordinates outside of
2178 * the guardband extent the rendered object will not match the intended
2179 * result. Therefore software should take steps to ensure that this does
2180 * not happen - e.g., by clipping objects such that they do not exceed
2181 * these limits after the Drawing Rectangle is applied."
2183 * I believe the fundamental restriction is that the rasterizer (in
2184 * the SF/WM stages) have a limit on the number of pixels that can be
2185 * rasterized. We need to ensure any coordinates beyond the rasterizer
2186 * limit are handled by the clipper. So effectively that limit becomes
2187 * the clipper's guardband size.
2189 * It goes on to say:
2191 * "In addition, in order to be correctly rendered, objects must have a
2192 * screenspace bounding box not exceeding 8K in the X or Y direction.
2193 * This additional restriction must also be comprehended by software,
2194 * i.e., enforced by use of clipping."
2196 * This makes no sense. Gen7+ hardware supports 16K render targets,
2197 * and you definitely need to be able to draw polygons that fill the
2198 * surface. Our assumption is that the rasterizer was limited to 8K
2199 * on Sandybridge, which only supports 8K surfaces, and it was actually
2200 * increased to 16K on Ivybridge and later.
2202 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
2204 const float gb_size
= GEN_GEN
>= 7 ? 16384.0f
: 8192.0f
;
2206 if (m00
!= 0 && m11
!= 0) {
2207 /* First, we compute the screen-space render area */
2208 const float ss_ra_xmin
= MIN3( 0, m30
+ m00
, m30
- m00
);
2209 const float ss_ra_xmax
= MAX3( fb_width
, m30
+ m00
, m30
- m00
);
2210 const float ss_ra_ymin
= MIN3( 0, m31
+ m11
, m31
- m11
);
2211 const float ss_ra_ymax
= MAX3(fb_height
, m31
+ m11
, m31
- m11
);
2213 /* We want the guardband to be centered on that */
2214 const float ss_gb_xmin
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 - gb_size
;
2215 const float ss_gb_xmax
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 + gb_size
;
2216 const float ss_gb_ymin
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 - gb_size
;
2217 const float ss_gb_ymax
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 + gb_size
;
2219 /* Now we need it in native device coordinates */
2220 const float ndc_gb_xmin
= (ss_gb_xmin
- m30
) / m00
;
2221 const float ndc_gb_xmax
= (ss_gb_xmax
- m30
) / m00
;
2222 const float ndc_gb_ymin
= (ss_gb_ymin
- m31
) / m11
;
2223 const float ndc_gb_ymax
= (ss_gb_ymax
- m31
) / m11
;
2225 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
2226 * flipped upside-down. X should be fine though.
2228 assert(ndc_gb_xmin
<= ndc_gb_xmax
);
2229 *xmin
= ndc_gb_xmin
;
2230 *xmax
= ndc_gb_xmax
;
2231 *ymin
= MIN2(ndc_gb_ymin
, ndc_gb_ymax
);
2232 *ymax
= MAX2(ndc_gb_ymin
, ndc_gb_ymax
);
2234 /* The viewport scales to 0, so nothing will be rendered. */
2243 * The pipe->set_viewport_states() driver hook.
2245 * This corresponds to our SF_CLIP_VIEWPORT states. We can't calculate
2246 * the guardband yet, as we need the framebuffer dimensions, but we can
2247 * at least fill out the rest.
2250 iris_set_viewport_states(struct pipe_context
*ctx
,
2251 unsigned start_slot
,
2253 const struct pipe_viewport_state
*states
)
2255 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2257 memcpy(&ice
->state
.viewports
[start_slot
], states
, sizeof(*states
) * count
);
2259 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
2261 if (ice
->state
.cso_rast
&& (!ice
->state
.cso_rast
->depth_clip_near
||
2262 !ice
->state
.cso_rast
->depth_clip_far
))
2263 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
2267 * The pipe->set_framebuffer_state() driver hook.
2269 * Sets the current draw FBO, including color render targets, depth,
2270 * and stencil buffers.
2273 iris_set_framebuffer_state(struct pipe_context
*ctx
,
2274 const struct pipe_framebuffer_state
*state
)
2276 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2277 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2278 struct isl_device
*isl_dev
= &screen
->isl_dev
;
2279 struct pipe_framebuffer_state
*cso
= &ice
->state
.framebuffer
;
2280 struct iris_resource
*zres
;
2281 struct iris_resource
*stencil_res
;
2283 unsigned samples
= util_framebuffer_get_num_samples(state
);
2284 unsigned layers
= util_framebuffer_get_num_layers(state
);
2286 if (cso
->samples
!= samples
) {
2287 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
2290 if (cso
->nr_cbufs
!= state
->nr_cbufs
) {
2291 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
2294 if ((cso
->layers
== 0) != (layers
== 0)) {
2295 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
2298 if (cso
->width
!= state
->width
|| cso
->height
!= state
->height
) {
2299 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
2302 util_copy_framebuffer_state(cso
, state
);
2303 cso
->samples
= samples
;
2304 cso
->layers
= layers
;
2306 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
2308 struct isl_view view
= {
2311 .base_array_layer
= 0,
2313 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2316 struct isl_depth_stencil_hiz_emit_info info
= { .view
= &view
};
2319 iris_get_depth_stencil_resources(cso
->zsbuf
->texture
, &zres
,
2322 view
.base_level
= cso
->zsbuf
->u
.tex
.level
;
2323 view
.base_array_layer
= cso
->zsbuf
->u
.tex
.first_layer
;
2325 cso
->zsbuf
->u
.tex
.last_layer
- cso
->zsbuf
->u
.tex
.first_layer
+ 1;
2328 view
.usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
2330 info
.depth_surf
= &zres
->surf
;
2331 info
.depth_address
= zres
->bo
->gtt_offset
;
2332 info
.mocs
= mocs(zres
->bo
);
2334 view
.format
= zres
->surf
.format
;
2336 if (iris_resource_level_has_hiz(zres
, view
.base_level
)) {
2337 info
.hiz_usage
= ISL_AUX_USAGE_HIZ
;
2338 info
.hiz_surf
= &zres
->aux
.surf
;
2339 info
.hiz_address
= zres
->aux
.bo
->gtt_offset
;
2344 view
.usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
2345 info
.stencil_surf
= &stencil_res
->surf
;
2346 info
.stencil_address
= stencil_res
->bo
->gtt_offset
;
2348 view
.format
= stencil_res
->surf
.format
;
2349 info
.mocs
= mocs(stencil_res
->bo
);
2354 isl_emit_depth_stencil_hiz_s(isl_dev
, cso_z
->packets
, &info
);
2356 /* Make a null surface for unbound buffers */
2357 void *null_surf_map
=
2358 upload_state(ice
->state
.surface_uploader
, &ice
->state
.null_fb
,
2359 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
2360 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
,
2361 isl_extent3d(MAX2(cso
->width
, 1),
2362 MAX2(cso
->height
, 1),
2363 cso
->layers
? cso
->layers
: 1));
2364 ice
->state
.null_fb
.offset
+=
2365 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.null_fb
.res
));
2367 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BUFFER
;
2369 /* Render target change */
2370 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_FS
;
2372 ice
->state
.dirty
|= IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES
;
2374 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_FRAMEBUFFER
];
2377 // XXX: we may want to flag IRIS_DIRTY_MULTISAMPLE (or SAMPLE_MASK?)
2378 // XXX: see commit 979fc1bc9bcc64027ff2cfafd285676f31b930a6
2380 /* The PIPE_CONTROL command description says:
2382 * "Whenever a Binding Table Index (BTI) used by a Render Target Message
2383 * points to a different RENDER_SURFACE_STATE, SW must issue a Render
2384 * Target Cache Flush by enabling this bit. When render target flush
2385 * is set due to new association of BTI, PS Scoreboard Stall bit must
2386 * be set in this packet."
2388 // XXX: does this need to happen at 3DSTATE_BTP_PS time?
2389 iris_emit_pipe_control_flush(&ice
->batches
[IRIS_BATCH_RENDER
],
2390 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
2391 PIPE_CONTROL_STALL_AT_SCOREBOARD
);
2396 upload_ubo_surf_state(struct iris_context
*ice
,
2397 struct iris_const_buffer
*cbuf
,
2398 unsigned buffer_size
)
2400 struct pipe_context
*ctx
= &ice
->ctx
;
2401 struct iris_screen
*screen
= (struct iris_screen
*) ctx
->screen
;
2403 // XXX: these are not retained forever, use a separate uploader?
2405 upload_state(ice
->state
.surface_uploader
, &cbuf
->surface_state
,
2406 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
2407 if (!unlikely(map
)) {
2408 pipe_resource_reference(&cbuf
->data
.res
, NULL
);
2412 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
2413 struct iris_bo
*surf_bo
= iris_resource_bo(cbuf
->surface_state
.res
);
2414 cbuf
->surface_state
.offset
+= iris_bo_offset_from_base_address(surf_bo
);
2416 isl_buffer_fill_state(&screen
->isl_dev
, map
,
2417 .address
= res
->bo
->gtt_offset
+ cbuf
->data
.offset
,
2418 .size_B
= MIN2(buffer_size
,
2419 res
->bo
->size
- cbuf
->data
.offset
),
2420 .format
= ISL_FORMAT_R32G32B32A32_FLOAT
,
2421 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2423 .mocs
= mocs(res
->bo
))
2427 * The pipe->set_constant_buffer() driver hook.
2429 * This uploads any constant data in user buffers, and references
2430 * any UBO resources containing constant data.
2433 iris_set_constant_buffer(struct pipe_context
*ctx
,
2434 enum pipe_shader_type p_stage
, unsigned index
,
2435 const struct pipe_constant_buffer
*input
)
2437 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2438 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2439 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2440 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[index
];
2442 if (input
&& input
->buffer
) {
2445 pipe_resource_reference(&cbuf
->data
.res
, input
->buffer
);
2446 cbuf
->data
.offset
= input
->buffer_offset
;
2448 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
2449 res
->bind_history
|= PIPE_BIND_CONSTANT_BUFFER
;
2451 upload_ubo_surf_state(ice
, cbuf
, input
->buffer_size
);
2453 pipe_resource_reference(&cbuf
->data
.res
, NULL
);
2454 pipe_resource_reference(&cbuf
->surface_state
.res
, NULL
);
2459 memcpy(&shs
->cbuf0
, input
, sizeof(shs
->cbuf0
));
2461 memset(&shs
->cbuf0
, 0, sizeof(shs
->cbuf0
));
2463 shs
->cbuf0_needs_upload
= true;
2466 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
2467 // XXX: maybe not necessary all the time...?
2468 // XXX: we need 3DS_BTP to commit these changes, and if we fell back to
2469 // XXX: pull model we may need actual new bindings...
2470 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
2474 upload_uniforms(struct iris_context
*ice
,
2475 gl_shader_stage stage
)
2477 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2478 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[0];
2479 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
2481 unsigned upload_size
= shader
->num_system_values
* sizeof(uint32_t) +
2482 shs
->cbuf0
.buffer_size
;
2484 if (upload_size
== 0)
2488 upload_state(ice
->ctx
.const_uploader
, &cbuf
->data
, upload_size
, 64);
2490 for (int i
= 0; i
< shader
->num_system_values
; i
++) {
2491 uint32_t sysval
= shader
->system_values
[i
];
2494 if (BRW_PARAM_DOMAIN(sysval
) == BRW_PARAM_DOMAIN_IMAGE
) {
2495 unsigned img
= BRW_PARAM_IMAGE_IDX(sysval
);
2496 unsigned offset
= BRW_PARAM_IMAGE_OFFSET(sysval
);
2497 struct brw_image_param
*param
= &shs
->image
[img
].param
;
2499 assert(offset
< sizeof(struct brw_image_param
));
2500 value
= ((uint32_t *) param
)[offset
];
2501 } else if (sysval
== BRW_PARAM_BUILTIN_ZERO
) {
2503 } else if (BRW_PARAM_BUILTIN_IS_CLIP_PLANE(sysval
)) {
2504 int plane
= BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(sysval
);
2505 int comp
= BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(sysval
);
2506 value
= fui(ice
->state
.clip_planes
.ucp
[plane
][comp
]);
2507 } else if (sysval
== BRW_PARAM_BUILTIN_PATCH_VERTICES_IN
) {
2508 if (stage
== MESA_SHADER_TESS_CTRL
) {
2509 value
= ice
->state
.vertices_per_patch
;
2511 assert(stage
== MESA_SHADER_TESS_EVAL
);
2512 const struct shader_info
*tcs_info
=
2513 iris_get_shader_info(ice
, MESA_SHADER_TESS_CTRL
);
2515 value
= tcs_info
->tess
.tcs_vertices_out
;
2517 value
= ice
->state
.vertices_per_patch
;
2519 } else if (sysval
>= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
&&
2520 sysval
<= BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W
) {
2521 unsigned i
= sysval
- BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X
;
2522 value
= fui(ice
->state
.default_outer_level
[i
]);
2523 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X
) {
2524 value
= fui(ice
->state
.default_inner_level
[0]);
2525 } else if (sysval
== BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y
) {
2526 value
= fui(ice
->state
.default_inner_level
[1]);
2528 assert(!"unhandled system value");
2534 if (shs
->cbuf0
.user_buffer
) {
2535 memcpy(map
, shs
->cbuf0
.user_buffer
, shs
->cbuf0
.buffer_size
);
2538 upload_ubo_surf_state(ice
, cbuf
, upload_size
);
2542 * The pipe->set_shader_buffers() driver hook.
2544 * This binds SSBOs and ABOs. Unfortunately, we need to stream out
2545 * SURFACE_STATE here, as the buffer offset may change each time.
2548 iris_set_shader_buffers(struct pipe_context
*ctx
,
2549 enum pipe_shader_type p_stage
,
2550 unsigned start_slot
, unsigned count
,
2551 const struct pipe_shader_buffer
*buffers
)
2553 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2554 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2555 gl_shader_stage stage
= stage_from_pipe(p_stage
);
2556 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
2558 for (unsigned i
= 0; i
< count
; i
++) {
2559 if (buffers
&& buffers
[i
].buffer
) {
2560 const struct pipe_shader_buffer
*buffer
= &buffers
[i
];
2561 struct iris_resource
*res
= (void *) buffer
->buffer
;
2562 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], &res
->base
);
2564 res
->bind_history
|= PIPE_BIND_SHADER_BUFFER
;
2566 // XXX: these are not retained forever, use a separate uploader?
2568 upload_state(ice
->state
.surface_uploader
,
2569 &shs
->ssbo_surface_state
[start_slot
+ i
],
2570 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
2571 if (!unlikely(map
)) {
2572 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], NULL
);
2576 struct iris_bo
*surf_state_bo
=
2577 iris_resource_bo(shs
->ssbo_surface_state
[start_slot
+ i
].res
);
2578 shs
->ssbo_surface_state
[start_slot
+ i
].offset
+=
2579 iris_bo_offset_from_base_address(surf_state_bo
);
2581 isl_buffer_fill_state(&screen
->isl_dev
, map
,
2583 res
->bo
->gtt_offset
+ buffer
->buffer_offset
,
2585 MIN2(buffer
->buffer_size
,
2586 res
->bo
->size
- buffer
->buffer_offset
),
2587 .format
= ISL_FORMAT_RAW
,
2588 .swizzle
= ISL_SWIZZLE_IDENTITY
,
2590 .mocs
= mocs(res
->bo
));
2592 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], NULL
);
2593 pipe_resource_reference(&shs
->ssbo_surface_state
[start_slot
+ i
].res
,
2598 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
2602 iris_delete_state(struct pipe_context
*ctx
, void *state
)
2608 * The pipe->set_vertex_buffers() driver hook.
2610 * This translates pipe_vertex_buffer to our 3DSTATE_VERTEX_BUFFERS packet.
2613 iris_set_vertex_buffers(struct pipe_context
*ctx
,
2614 unsigned start_slot
, unsigned count
,
2615 const struct pipe_vertex_buffer
*buffers
)
2617 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2618 struct iris_genx_state
*genx
= ice
->state
.genx
;
2620 ice
->state
.bound_vertex_buffers
&= ~u_bit_consecutive64(start_slot
, count
);
2622 for (unsigned i
= 0; i
< count
; i
++) {
2623 const struct pipe_vertex_buffer
*buffer
= buffers
? &buffers
[i
] : NULL
;
2624 struct iris_vertex_buffer_state
*state
=
2625 &genx
->vertex_buffers
[start_slot
+ i
];
2628 pipe_resource_reference(&state
->resource
, NULL
);
2632 assert(!buffer
->is_user_buffer
);
2634 pipe_resource_reference(&state
->resource
, buffer
->buffer
.resource
);
2635 struct iris_resource
*res
= (void *) state
->resource
;
2638 ice
->state
.bound_vertex_buffers
|= 1ull << (start_slot
+ i
);
2639 res
->bind_history
|= PIPE_BIND_VERTEX_BUFFER
;
2642 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
2643 vb
.VertexBufferIndex
= start_slot
+ i
;
2644 vb
.AddressModifyEnable
= true;
2645 vb
.BufferPitch
= buffer
->stride
;
2647 vb
.BufferSize
= res
->bo
->size
- (int) buffer
->buffer_offset
;
2648 vb
.BufferStartingAddress
=
2649 ro_bo(NULL
, res
->bo
->gtt_offset
+ (int) buffer
->buffer_offset
);
2650 vb
.MOCS
= mocs(res
->bo
);
2652 vb
.NullVertexBuffer
= true;
2657 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
2661 * Gallium CSO for vertex elements.
2663 struct iris_vertex_element_state
{
2664 uint32_t vertex_elements
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
2665 uint32_t vf_instancing
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
2666 uint32_t edgeflag_ve
[GENX(VERTEX_ELEMENT_STATE_length
)];
2667 uint32_t edgeflag_vfi
[GENX(3DSTATE_VF_INSTANCING_length
)];
2672 * The pipe->create_vertex_elements() driver hook.
2674 * This translates pipe_vertex_element to our 3DSTATE_VERTEX_ELEMENTS
2675 * and 3DSTATE_VF_INSTANCING commands. The vertex_elements and vf_instancing
2676 * arrays are ready to be emitted at draw time if no EdgeFlag or SGVs are
2677 * needed. In these cases we will need information available at draw time.
2678 * We setup edgeflag_ve and edgeflag_vfi as alternatives last
2679 * 3DSTATE_VERTEX_ELEMENT and 3DSTATE_VF_INSTANCING that can be used at
2680 * draw time if we detect that EdgeFlag is needed by the Vertex Shader.
2683 iris_create_vertex_elements(struct pipe_context
*ctx
,
2685 const struct pipe_vertex_element
*state
)
2687 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
2688 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2689 struct iris_vertex_element_state
*cso
=
2690 malloc(sizeof(struct iris_vertex_element_state
));
2694 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
), cso
->vertex_elements
, ve
) {
2696 1 + GENX(VERTEX_ELEMENT_STATE_length
) * MAX2(count
, 1) - 2;
2699 uint32_t *ve_pack_dest
= &cso
->vertex_elements
[1];
2700 uint32_t *vfi_pack_dest
= cso
->vf_instancing
;
2703 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
2705 ve
.SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
2706 ve
.Component0Control
= VFCOMP_STORE_0
;
2707 ve
.Component1Control
= VFCOMP_STORE_0
;
2708 ve
.Component2Control
= VFCOMP_STORE_0
;
2709 ve
.Component3Control
= VFCOMP_STORE_1_FP
;
2712 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
2716 for (int i
= 0; i
< count
; i
++) {
2717 const struct iris_format_info fmt
=
2718 iris_format_for_usage(devinfo
, state
[i
].src_format
, 0);
2719 unsigned comp
[4] = { VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
,
2720 VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
};
2722 switch (isl_format_get_num_channels(fmt
.fmt
)) {
2723 case 0: comp
[0] = VFCOMP_STORE_0
; /* fallthrough */
2724 case 1: comp
[1] = VFCOMP_STORE_0
; /* fallthrough */
2725 case 2: comp
[2] = VFCOMP_STORE_0
; /* fallthrough */
2727 comp
[3] = isl_format_has_int_channel(fmt
.fmt
) ? VFCOMP_STORE_1_INT
2728 : VFCOMP_STORE_1_FP
;
2731 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
2732 ve
.EdgeFlagEnable
= false;
2733 ve
.VertexBufferIndex
= state
[i
].vertex_buffer_index
;
2735 ve
.SourceElementOffset
= state
[i
].src_offset
;
2736 ve
.SourceElementFormat
= fmt
.fmt
;
2737 ve
.Component0Control
= comp
[0];
2738 ve
.Component1Control
= comp
[1];
2739 ve
.Component2Control
= comp
[2];
2740 ve
.Component3Control
= comp
[3];
2743 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
2744 vi
.VertexElementIndex
= i
;
2745 vi
.InstancingEnable
= state
[i
].instance_divisor
> 0;
2746 vi
.InstanceDataStepRate
= state
[i
].instance_divisor
;
2749 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
2750 vfi_pack_dest
+= GENX(3DSTATE_VF_INSTANCING_length
);
2753 /* An alternative version of the last VE and VFI is stored so it
2754 * can be used at draw time in case Vertex Shader uses EdgeFlag
2757 const unsigned edgeflag_index
= count
- 1;
2758 const struct iris_format_info fmt
=
2759 iris_format_for_usage(devinfo
, state
[edgeflag_index
].src_format
, 0);
2760 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), cso
->edgeflag_ve
, ve
) {
2761 ve
.EdgeFlagEnable
= true ;
2762 ve
.VertexBufferIndex
= state
[edgeflag_index
].vertex_buffer_index
;
2764 ve
.SourceElementOffset
= state
[edgeflag_index
].src_offset
;
2765 ve
.SourceElementFormat
= fmt
.fmt
;
2766 ve
.Component0Control
= VFCOMP_STORE_SRC
;
2767 ve
.Component1Control
= VFCOMP_STORE_0
;
2768 ve
.Component2Control
= VFCOMP_STORE_0
;
2769 ve
.Component3Control
= VFCOMP_STORE_0
;
2771 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), cso
->edgeflag_vfi
, vi
) {
2772 /* The vi.VertexElementIndex of the EdgeFlag Vertex Element is filled
2773 * at draw time, as it should change if SGVs are emitted.
2775 vi
.InstancingEnable
= state
[edgeflag_index
].instance_divisor
> 0;
2776 vi
.InstanceDataStepRate
= state
[edgeflag_index
].instance_divisor
;
2784 * The pipe->bind_vertex_elements_state() driver hook.
2787 iris_bind_vertex_elements_state(struct pipe_context
*ctx
, void *state
)
2789 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2790 struct iris_vertex_element_state
*old_cso
= ice
->state
.cso_vertex_elements
;
2791 struct iris_vertex_element_state
*new_cso
= state
;
2793 /* 3DSTATE_VF_SGVs overrides the last VE, so if the count is changing,
2794 * we need to re-emit it to ensure we're overriding the right one.
2796 if (new_cso
&& cso_changed(count
))
2797 ice
->state
.dirty
|= IRIS_DIRTY_VF_SGVS
;
2799 ice
->state
.cso_vertex_elements
= state
;
2800 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_ELEMENTS
;
2804 * The pipe->create_stream_output_target() driver hook.
2806 * "Target" here refers to a destination buffer. We translate this into
2807 * a 3DSTATE_SO_BUFFER packet. We can handle most fields, but don't yet
2808 * know which buffer this represents, or whether we ought to zero the
2809 * write-offsets, or append. Those are handled in the set() hook.
2811 static struct pipe_stream_output_target
*
2812 iris_create_stream_output_target(struct pipe_context
*ctx
,
2813 struct pipe_resource
*p_res
,
2814 unsigned buffer_offset
,
2815 unsigned buffer_size
)
2817 struct iris_resource
*res
= (void *) p_res
;
2818 struct iris_stream_output_target
*cso
= calloc(1, sizeof(*cso
));
2822 res
->bind_history
|= PIPE_BIND_STREAM_OUTPUT
;
2824 pipe_reference_init(&cso
->base
.reference
, 1);
2825 pipe_resource_reference(&cso
->base
.buffer
, p_res
);
2826 cso
->base
.buffer_offset
= buffer_offset
;
2827 cso
->base
.buffer_size
= buffer_size
;
2828 cso
->base
.context
= ctx
;
2830 upload_state(ctx
->stream_uploader
, &cso
->offset
, sizeof(uint32_t), 4);
2836 iris_stream_output_target_destroy(struct pipe_context
*ctx
,
2837 struct pipe_stream_output_target
*state
)
2839 struct iris_stream_output_target
*cso
= (void *) state
;
2841 pipe_resource_reference(&cso
->base
.buffer
, NULL
);
2842 pipe_resource_reference(&cso
->offset
.res
, NULL
);
2848 * The pipe->set_stream_output_targets() driver hook.
2850 * At this point, we know which targets are bound to a particular index,
2851 * and also whether we want to append or start over. We can finish the
2852 * 3DSTATE_SO_BUFFER packets we started earlier.
2855 iris_set_stream_output_targets(struct pipe_context
*ctx
,
2856 unsigned num_targets
,
2857 struct pipe_stream_output_target
**targets
,
2858 const unsigned *offsets
)
2860 struct iris_context
*ice
= (struct iris_context
*) ctx
;
2861 struct iris_genx_state
*genx
= ice
->state
.genx
;
2862 uint32_t *so_buffers
= genx
->so_buffers
;
2864 const bool active
= num_targets
> 0;
2865 if (ice
->state
.streamout_active
!= active
) {
2866 ice
->state
.streamout_active
= active
;
2867 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
2869 /* We only emit 3DSTATE_SO_DECL_LIST when streamout is active, because
2870 * it's a non-pipelined command. If we're switching streamout on, we
2871 * may have missed emitting it earlier, so do so now. (We're already
2872 * taking a stall to update 3DSTATE_SO_BUFFERS anyway...)
2875 ice
->state
.dirty
|= IRIS_DIRTY_SO_DECL_LIST
;
2878 for (int i
= 0; i
< 4; i
++) {
2879 pipe_so_target_reference(&ice
->state
.so_target
[i
],
2880 i
< num_targets
? targets
[i
] : NULL
);
2883 /* No need to update 3DSTATE_SO_BUFFER unless SOL is active. */
2887 for (unsigned i
= 0; i
< 4; i
++,
2888 so_buffers
+= GENX(3DSTATE_SO_BUFFER_length
)) {
2890 if (i
>= num_targets
|| !targets
[i
]) {
2891 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
)
2892 sob
.SOBufferIndex
= i
;
2896 struct iris_stream_output_target
*tgt
= (void *) targets
[i
];
2897 struct iris_resource
*res
= (void *) tgt
->base
.buffer
;
2899 /* Note that offsets[i] will either be 0, causing us to zero
2900 * the value in the buffer, or 0xFFFFFFFF, which happens to mean
2901 * "continue appending at the existing offset."
2903 assert(offsets
[i
] == 0 || offsets
[i
] == 0xFFFFFFFF);
2905 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
) {
2906 sob
.SurfaceBaseAddress
=
2907 rw_bo(NULL
, res
->bo
->gtt_offset
+ tgt
->base
.buffer_offset
);
2908 sob
.SOBufferEnable
= true;
2909 sob
.StreamOffsetWriteEnable
= true;
2910 sob
.StreamOutputBufferOffsetAddressEnable
= true;
2911 sob
.MOCS
= mocs(res
->bo
);
2913 sob
.SurfaceSize
= MAX2(tgt
->base
.buffer_size
/ 4, 1) - 1;
2915 sob
.SOBufferIndex
= i
;
2916 sob
.StreamOffset
= offsets
[i
];
2917 sob
.StreamOutputBufferOffsetAddress
=
2918 rw_bo(NULL
, iris_resource_bo(tgt
->offset
.res
)->gtt_offset
+
2919 tgt
->offset
.offset
);
2923 ice
->state
.dirty
|= IRIS_DIRTY_SO_BUFFERS
;
2927 * An iris-vtable helper for encoding the 3DSTATE_SO_DECL_LIST and
2928 * 3DSTATE_STREAMOUT packets.
2930 * 3DSTATE_SO_DECL_LIST is a list of shader outputs we want the streamout
2931 * hardware to record. We can create it entirely based on the shader, with
2932 * no dynamic state dependencies.
2934 * 3DSTATE_STREAMOUT is an annoying mix of shader-based information and
2935 * state-based settings. We capture the shader-related ones here, and merge
2936 * the rest in at draw time.
2939 iris_create_so_decl_list(const struct pipe_stream_output_info
*info
,
2940 const struct brw_vue_map
*vue_map
)
2942 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
2943 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2944 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2945 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2947 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
2949 memset(so_decl
, 0, sizeof(so_decl
));
2951 /* Construct the list of SO_DECLs to be emitted. The formatting of the
2952 * command feels strange -- each dword pair contains a SO_DECL per stream.
2954 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
2955 const struct pipe_stream_output
*output
= &info
->output
[i
];
2956 const int buffer
= output
->output_buffer
;
2957 const int varying
= output
->register_index
;
2958 const unsigned stream_id
= output
->stream
;
2959 assert(stream_id
< MAX_VERTEX_STREAMS
);
2961 buffer_mask
[stream_id
] |= 1 << buffer
;
2963 assert(vue_map
->varying_to_slot
[varying
] >= 0);
2965 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
2966 * array. Instead, it simply increments DstOffset for the following
2967 * input by the number of components that should be skipped.
2969 * Our hardware is unusual in that it requires us to program SO_DECLs
2970 * for fake "hole" components, rather than simply taking the offset
2971 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
2972 * program as many size = 4 holes as we can, then a final hole to
2973 * accommodate the final 1, 2, or 3 remaining.
2975 int skip_components
= output
->dst_offset
- next_offset
[buffer
];
2977 while (skip_components
> 0) {
2978 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
2980 .OutputBufferSlot
= output
->output_buffer
,
2981 .ComponentMask
= (1 << MIN2(skip_components
, 4)) - 1,
2983 skip_components
-= 4;
2986 next_offset
[buffer
] = output
->dst_offset
+ output
->num_components
;
2988 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
2989 .OutputBufferSlot
= output
->output_buffer
,
2990 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
2992 ((1 << output
->num_components
) - 1) << output
->start_component
,
2995 if (decls
[stream_id
] > max_decls
)
2996 max_decls
= decls
[stream_id
];
2999 unsigned dwords
= GENX(3DSTATE_STREAMOUT_length
) + (3 + 2 * max_decls
);
3000 uint32_t *map
= ralloc_size(NULL
, sizeof(uint32_t) * dwords
);
3001 uint32_t *so_decl_map
= map
+ GENX(3DSTATE_STREAMOUT_length
);
3003 iris_pack_command(GENX(3DSTATE_STREAMOUT
), map
, sol
) {
3004 int urb_entry_read_offset
= 0;
3005 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
3006 urb_entry_read_offset
;
3008 /* We always read the whole vertex. This could be reduced at some
3009 * point by reading less and offsetting the register index in the
3012 sol
.Stream0VertexReadOffset
= urb_entry_read_offset
;
3013 sol
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
3014 sol
.Stream1VertexReadOffset
= urb_entry_read_offset
;
3015 sol
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
3016 sol
.Stream2VertexReadOffset
= urb_entry_read_offset
;
3017 sol
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
3018 sol
.Stream3VertexReadOffset
= urb_entry_read_offset
;
3019 sol
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
3021 /* Set buffer pitches; 0 means unbound. */
3022 sol
.Buffer0SurfacePitch
= 4 * info
->stride
[0];
3023 sol
.Buffer1SurfacePitch
= 4 * info
->stride
[1];
3024 sol
.Buffer2SurfacePitch
= 4 * info
->stride
[2];
3025 sol
.Buffer3SurfacePitch
= 4 * info
->stride
[3];
3028 iris_pack_command(GENX(3DSTATE_SO_DECL_LIST
), so_decl_map
, list
) {
3029 list
.DWordLength
= 3 + 2 * max_decls
- 2;
3030 list
.StreamtoBufferSelects0
= buffer_mask
[0];
3031 list
.StreamtoBufferSelects1
= buffer_mask
[1];
3032 list
.StreamtoBufferSelects2
= buffer_mask
[2];
3033 list
.StreamtoBufferSelects3
= buffer_mask
[3];
3034 list
.NumEntries0
= decls
[0];
3035 list
.NumEntries1
= decls
[1];
3036 list
.NumEntries2
= decls
[2];
3037 list
.NumEntries3
= decls
[3];
3040 for (int i
= 0; i
< max_decls
; i
++) {
3041 iris_pack_state(GENX(SO_DECL_ENTRY
), so_decl_map
+ 3 + i
* 2, entry
) {
3042 entry
.Stream0Decl
= so_decl
[0][i
];
3043 entry
.Stream1Decl
= so_decl
[1][i
];
3044 entry
.Stream2Decl
= so_decl
[2][i
];
3045 entry
.Stream3Decl
= so_decl
[3][i
];
3053 iris_compute_sbe_urb_read_interval(uint64_t fs_input_slots
,
3054 const struct brw_vue_map
*last_vue_map
,
3055 bool two_sided_color
,
3056 unsigned *out_offset
,
3057 unsigned *out_length
)
3059 /* The compiler computes the first URB slot without considering COL/BFC
3060 * swizzling (because it doesn't know whether it's enabled), so we need
3061 * to do that here too. This may result in a smaller offset, which
3064 const unsigned first_slot
=
3065 brw_compute_first_urb_slot_required(fs_input_slots
, last_vue_map
);
3067 /* This becomes the URB read offset (counted in pairs of slots). */
3068 assert(first_slot
% 2 == 0);
3069 *out_offset
= first_slot
/ 2;
3071 /* We need to adjust the inputs read to account for front/back color
3072 * swizzling, as it can make the URB length longer.
3074 for (int c
= 0; c
<= 1; c
++) {
3075 if (fs_input_slots
& (VARYING_BIT_COL0
<< c
)) {
3076 /* If two sided color is enabled, the fragment shader's gl_Color
3077 * (COL0) input comes from either the gl_FrontColor (COL0) or
3078 * gl_BackColor (BFC0) input varyings. Mark BFC as used, too.
3080 if (two_sided_color
)
3081 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3083 /* If front color isn't written, we opt to give them back color
3084 * instead of an undefined value. Switch from COL to BFC.
3086 if (last_vue_map
->varying_to_slot
[VARYING_SLOT_COL0
+ c
] == -1) {
3087 fs_input_slots
&= ~(VARYING_BIT_COL0
<< c
);
3088 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
3093 /* Compute the minimum URB Read Length necessary for the FS inputs.
3095 * From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
3096 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
3098 * "This field should be set to the minimum length required to read the
3099 * maximum source attribute. The maximum source attribute is indicated
3100 * by the maximum value of the enabled Attribute # Source Attribute if
3101 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
3102 * enable is not set.
3103 * read_length = ceiling((max_source_attr + 1) / 2)
3105 * [errata] Corruption/Hang possible if length programmed larger than
3108 * Similar text exists for Ivy Bridge.
3110 * We find the last URB slot that's actually read by the FS.
3112 unsigned last_read_slot
= last_vue_map
->num_slots
- 1;
3113 while (last_read_slot
> first_slot
&& !(fs_input_slots
&
3114 (1ull << last_vue_map
->slot_to_varying
[last_read_slot
])))
3117 /* The URB read length is the difference of the two, counted in pairs. */
3118 *out_length
= DIV_ROUND_UP(last_read_slot
- first_slot
+ 1, 2);
3122 iris_emit_sbe_swiz(struct iris_batch
*batch
,
3123 const struct iris_context
*ice
,
3124 unsigned urb_read_offset
,
3125 unsigned sprite_coord_enables
)
3127 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = {};
3128 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3129 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3130 const struct brw_vue_map
*vue_map
= ice
->shaders
.last_vue_map
;
3131 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3133 /* XXX: this should be generated when putting programs in place */
3135 for (int fs_attr
= 0; fs_attr
< VARYING_SLOT_MAX
; fs_attr
++) {
3136 const int input_index
= wm_prog_data
->urb_setup
[fs_attr
];
3137 if (input_index
< 0 || input_index
>= 16)
3140 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
=
3141 &attr_overrides
[input_index
];
3142 int slot
= vue_map
->varying_to_slot
[fs_attr
];
3144 /* Viewport and Layer are stored in the VUE header. We need to override
3145 * them to zero if earlier stages didn't write them, as GL requires that
3146 * they read back as zero when not explicitly set.
3149 case VARYING_SLOT_VIEWPORT
:
3150 case VARYING_SLOT_LAYER
:
3151 attr
->ComponentOverrideX
= true;
3152 attr
->ComponentOverrideW
= true;
3153 attr
->ConstantSource
= CONST_0000
;
3155 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
3156 attr
->ComponentOverrideY
= true;
3157 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
3158 attr
->ComponentOverrideZ
= true;
3161 case VARYING_SLOT_PRIMITIVE_ID
:
3162 /* Override if the previous shader stage didn't write gl_PrimitiveID. */
3164 attr
->ComponentOverrideX
= true;
3165 attr
->ComponentOverrideY
= true;
3166 attr
->ComponentOverrideZ
= true;
3167 attr
->ComponentOverrideW
= true;
3168 attr
->ConstantSource
= PRIM_ID
;
3176 if (sprite_coord_enables
& (1 << input_index
))
3179 /* If there was only a back color written but not front, use back
3180 * as the color instead of undefined.
3182 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
3183 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
3184 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
3185 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
3187 /* Not written by the previous stage - undefined. */
3189 attr
->ComponentOverrideX
= true;
3190 attr
->ComponentOverrideY
= true;
3191 attr
->ComponentOverrideZ
= true;
3192 attr
->ComponentOverrideW
= true;
3193 attr
->ConstantSource
= CONST_0001_FLOAT
;
3197 /* Compute the location of the attribute relative to the read offset,
3198 * which is counted in 256-bit increments (two 128-bit VUE slots).
3200 const int source_attr
= slot
- 2 * urb_read_offset
;
3201 assert(source_attr
>= 0 && source_attr
<= 32);
3202 attr
->SourceAttribute
= source_attr
;
3204 /* If we are doing two-sided color, and the VUE slot following this one
3205 * represents a back-facing color, then we need to instruct the SF unit
3206 * to do back-facing swizzling.
3208 if (cso_rast
->light_twoside
&&
3209 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
3210 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
3211 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
3212 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
)))
3213 attr
->SwizzleSelect
= INPUTATTR_FACING
;
3216 iris_emit_cmd(batch
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
3217 for (int i
= 0; i
< 16; i
++)
3218 sbes
.Attribute
[i
] = attr_overrides
[i
];
3223 iris_calculate_point_sprite_overrides(const struct brw_wm_prog_data
*prog_data
,
3224 const struct iris_rasterizer_state
*cso
)
3226 unsigned overrides
= 0;
3228 if (prog_data
->urb_setup
[VARYING_SLOT_PNTC
] != -1)
3229 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_PNTC
];
3231 for (int i
= 0; i
< 8; i
++) {
3232 if ((cso
->sprite_coord_enable
& (1 << i
)) &&
3233 prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
] != -1)
3234 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
];
3241 iris_emit_sbe(struct iris_batch
*batch
, const struct iris_context
*ice
)
3243 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3244 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
3245 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
3246 const struct shader_info
*fs_info
=
3247 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
3249 unsigned urb_read_offset
, urb_read_length
;
3250 iris_compute_sbe_urb_read_interval(fs_info
->inputs_read
,
3251 ice
->shaders
.last_vue_map
,
3252 cso_rast
->light_twoside
,
3253 &urb_read_offset
, &urb_read_length
);
3255 unsigned sprite_coord_overrides
=
3256 iris_calculate_point_sprite_overrides(wm_prog_data
, cso_rast
);
3258 iris_emit_cmd(batch
, GENX(3DSTATE_SBE
), sbe
) {
3259 sbe
.AttributeSwizzleEnable
= true;
3260 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
3261 sbe
.PointSpriteTextureCoordinateOrigin
= cso_rast
->sprite_coord_mode
;
3262 sbe
.VertexURBEntryReadOffset
= urb_read_offset
;
3263 sbe
.VertexURBEntryReadLength
= urb_read_length
;
3264 sbe
.ForceVertexURBEntryReadOffset
= true;
3265 sbe
.ForceVertexURBEntryReadLength
= true;
3266 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
3267 sbe
.PointSpriteTextureCoordinateEnable
= sprite_coord_overrides
;
3269 for (int i
= 0; i
< 32; i
++) {
3270 sbe
.AttributeActiveComponentFormat
[i
] = ACTIVE_COMPONENT_XYZW
;
3275 iris_emit_sbe_swiz(batch
, ice
, urb_read_offset
, sprite_coord_overrides
);
3278 /* ------------------------------------------------------------------- */
3281 * Populate VS program key fields based on the current state.
3284 iris_populate_vs_key(const struct iris_context
*ice
,
3285 const struct shader_info
*info
,
3286 struct brw_vs_prog_key
*key
)
3288 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3290 if (info
->clip_distance_array_size
== 0 &&
3291 (info
->outputs_written
& (VARYING_BIT_POS
| VARYING_BIT_CLIP_VERTEX
)))
3292 key
->nr_userclip_plane_consts
= cso_rast
->num_clip_plane_consts
;
3296 * Populate TCS program key fields based on the current state.
3299 iris_populate_tcs_key(const struct iris_context
*ice
,
3300 struct brw_tcs_prog_key
*key
)
3305 * Populate TES program key fields based on the current state.
3308 iris_populate_tes_key(const struct iris_context
*ice
,
3309 struct brw_tes_prog_key
*key
)
3314 * Populate GS program key fields based on the current state.
3317 iris_populate_gs_key(const struct iris_context
*ice
,
3318 struct brw_gs_prog_key
*key
)
3323 * Populate FS program key fields based on the current state.
3326 iris_populate_fs_key(const struct iris_context
*ice
,
3327 struct brw_wm_prog_key
*key
)
3329 const struct pipe_framebuffer_state
*fb
= &ice
->state
.framebuffer
;
3330 const struct iris_depth_stencil_alpha_state
*zsa
= ice
->state
.cso_zsa
;
3331 const struct iris_rasterizer_state
*rast
= ice
->state
.cso_rast
;
3332 const struct iris_blend_state
*blend
= ice
->state
.cso_blend
;
3334 key
->nr_color_regions
= fb
->nr_cbufs
;
3336 key
->clamp_fragment_color
= rast
->clamp_fragment_color
;
3338 key
->replicate_alpha
= fb
->nr_cbufs
> 1 &&
3339 (zsa
->alpha
.enabled
|| blend
->alpha_to_coverage
);
3341 /* XXX: only bother if COL0/1 are read */
3342 key
->flat_shade
= rast
->flatshade
;
3344 key
->persample_interp
= rast
->force_persample_interp
;
3345 key
->multisample_fbo
= rast
->multisample
&& fb
->samples
> 1;
3347 key
->coherent_fb_fetch
= true;
3349 /* TODO: support key->force_dual_color_blend for Unigine */
3350 /* TODO: Respect glHint for key->high_quality_derivatives */
3354 iris_populate_cs_key(const struct iris_context
*ice
,
3355 struct brw_cs_prog_key
*key
)
3360 KSP(const struct iris_compiled_shader
*shader
)
3362 struct iris_resource
*res
= (void *) shader
->assembly
.res
;
3363 return iris_bo_offset_from_base_address(res
->bo
) + shader
->assembly
.offset
;
3366 /* Gen11 workaround table #2056 WABTPPrefetchDisable suggests to disable
3367 * prefetching of binding tables in A0 and B0 steppings. XXX: Revisit
3368 * this WA on C0 stepping.
3370 * TODO: Fill out SamplerCount for prefetching?
3373 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix, stage) \
3374 pkt.KernelStartPointer = KSP(shader); \
3375 pkt.BindingTableEntryCount = GEN_GEN == 11 ? 0 : \
3376 prog_data->binding_table.size_bytes / 4; \
3377 pkt.FloatingPointMode = prog_data->use_alt_mode; \
3379 pkt.DispatchGRFStartRegisterForURBData = \
3380 prog_data->dispatch_grf_start_reg; \
3381 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
3382 pkt.prefix##URBEntryReadOffset = 0; \
3384 pkt.StatisticsEnable = true; \
3385 pkt.Enable = true; \
3387 if (prog_data->total_scratch) { \
3388 struct iris_bo *bo = \
3389 iris_get_scratch_space(ice, prog_data->total_scratch, stage); \
3390 uint32_t scratch_addr = bo->gtt_offset; \
3391 pkt.PerThreadScratchSpace = ffs(prog_data->total_scratch) - 11; \
3392 pkt.ScratchSpaceBasePointer = rw_bo(NULL, scratch_addr); \
3396 * Encode most of 3DSTATE_VS based on the compiled shader.
3399 iris_store_vs_state(struct iris_context
*ice
,
3400 const struct gen_device_info
*devinfo
,
3401 struct iris_compiled_shader
*shader
)
3403 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3404 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
3406 iris_pack_command(GENX(3DSTATE_VS
), shader
->derived_data
, vs
) {
3407 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
, MESA_SHADER_VERTEX
);
3408 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
3409 vs
.SIMD8DispatchEnable
= true;
3410 vs
.UserClipDistanceCullTestEnableBitmask
=
3411 vue_prog_data
->cull_distance_mask
;
3416 * Encode most of 3DSTATE_HS based on the compiled shader.
3419 iris_store_tcs_state(struct iris_context
*ice
,
3420 const struct gen_device_info
*devinfo
,
3421 struct iris_compiled_shader
*shader
)
3423 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3424 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
3425 struct brw_tcs_prog_data
*tcs_prog_data
= (void *) prog_data
;
3427 iris_pack_command(GENX(3DSTATE_HS
), shader
->derived_data
, hs
) {
3428 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
, MESA_SHADER_TESS_CTRL
);
3430 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
3431 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
3432 hs
.IncludeVertexHandles
= true;
3437 * Encode 3DSTATE_TE and most of 3DSTATE_DS based on the compiled shader.
3440 iris_store_tes_state(struct iris_context
*ice
,
3441 const struct gen_device_info
*devinfo
,
3442 struct iris_compiled_shader
*shader
)
3444 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3445 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
3446 struct brw_tes_prog_data
*tes_prog_data
= (void *) prog_data
;
3448 uint32_t *te_state
= (void *) shader
->derived_data
;
3449 uint32_t *ds_state
= te_state
+ GENX(3DSTATE_TE_length
);
3451 iris_pack_command(GENX(3DSTATE_TE
), te_state
, te
) {
3452 te
.Partitioning
= tes_prog_data
->partitioning
;
3453 te
.OutputTopology
= tes_prog_data
->output_topology
;
3454 te
.TEDomain
= tes_prog_data
->domain
;
3456 te
.MaximumTessellationFactorOdd
= 63.0;
3457 te
.MaximumTessellationFactorNotOdd
= 64.0;
3460 iris_pack_command(GENX(3DSTATE_DS
), ds_state
, ds
) {
3461 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
, MESA_SHADER_TESS_EVAL
);
3463 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
3464 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
3465 ds
.ComputeWCoordinateEnable
=
3466 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
3468 ds
.UserClipDistanceCullTestEnableBitmask
=
3469 vue_prog_data
->cull_distance_mask
;
3475 * Encode most of 3DSTATE_GS based on the compiled shader.
3478 iris_store_gs_state(struct iris_context
*ice
,
3479 const struct gen_device_info
*devinfo
,
3480 struct iris_compiled_shader
*shader
)
3482 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3483 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
3484 struct brw_gs_prog_data
*gs_prog_data
= (void *) prog_data
;
3486 iris_pack_command(GENX(3DSTATE_GS
), shader
->derived_data
, gs
) {
3487 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
, MESA_SHADER_GEOMETRY
);
3489 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
3490 gs
.OutputTopology
= gs_prog_data
->output_topology
;
3491 gs
.ControlDataHeaderSize
=
3492 gs_prog_data
->control_data_header_size_hwords
;
3493 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
3494 gs
.DispatchMode
= DISPATCH_MODE_SIMD8
;
3495 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
3496 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
3497 gs
.ReorderMode
= TRAILING
;
3498 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
3499 gs
.MaximumNumberofThreads
=
3500 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
3501 : (devinfo
->max_gs_threads
- 1);
3503 if (gs_prog_data
->static_vertex_count
!= -1) {
3504 gs
.StaticOutput
= true;
3505 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
3507 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
3509 gs
.UserClipDistanceCullTestEnableBitmask
=
3510 vue_prog_data
->cull_distance_mask
;
3512 const int urb_entry_write_offset
= 1;
3513 const uint32_t urb_entry_output_length
=
3514 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
3515 urb_entry_write_offset
;
3517 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
3518 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
3523 * Encode most of 3DSTATE_PS and 3DSTATE_PS_EXTRA based on the shader.
3526 iris_store_fs_state(struct iris_context
*ice
,
3527 const struct gen_device_info
*devinfo
,
3528 struct iris_compiled_shader
*shader
)
3530 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3531 struct brw_wm_prog_data
*wm_prog_data
= (void *) shader
->prog_data
;
3533 uint32_t *ps_state
= (void *) shader
->derived_data
;
3534 uint32_t *psx_state
= ps_state
+ GENX(3DSTATE_PS_length
);
3536 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
3537 ps
.VectorMaskEnable
= true;
3538 // XXX: WABTPPrefetchDisable, see above, drop at C0
3539 ps
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 :
3540 prog_data
->binding_table
.size_bytes
/ 4;
3541 ps
.FloatingPointMode
= prog_data
->use_alt_mode
;
3542 ps
.MaximumNumberofThreadsPerPSD
= 64 - (GEN_GEN
== 8 ? 2 : 1);
3544 ps
.PushConstantEnable
= prog_data
->ubo_ranges
[0].length
> 0;
3546 /* From the documentation for this packet:
3547 * "If the PS kernel does not need the Position XY Offsets to
3548 * compute a Position Value, then this field should be programmed
3549 * to POSOFFSET_NONE."
3551 * "SW Recommendation: If the PS kernel needs the Position Offsets
3552 * to compute a Position XY value, this field should match Position
3553 * ZW Interpolation Mode to ensure a consistent position.xyzw
3556 * We only require XY sample offsets. So, this recommendation doesn't
3557 * look useful at the moment. We might need this in future.
3559 ps
.PositionXYOffsetSelect
=
3560 wm_prog_data
->uses_pos_offset
? POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
3561 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
3562 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
3563 ps
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
3565 // XXX: Disable SIMD32 with 16x MSAA
3567 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
3568 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 0);
3569 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
3570 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 1);
3571 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
3572 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 2);
3574 ps
.KernelStartPointer0
=
3575 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 0);
3576 ps
.KernelStartPointer1
=
3577 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 1);
3578 ps
.KernelStartPointer2
=
3579 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 2);
3581 if (prog_data
->total_scratch
) {
3582 struct iris_bo
*bo
=
3583 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
3584 MESA_SHADER_FRAGMENT
);
3585 uint32_t scratch_addr
= bo
->gtt_offset
;
3586 ps
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
3587 ps
.ScratchSpaceBasePointer
= rw_bo(NULL
, scratch_addr
);
3591 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
3592 psx
.PixelShaderValid
= true;
3593 psx
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
3594 psx
.PixelShaderKillsPixel
= wm_prog_data
->uses_kill
;
3595 psx
.AttributeEnable
= wm_prog_data
->num_varying_inputs
!= 0;
3596 psx
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
3597 psx
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
3598 psx
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
3599 psx
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
3602 if (wm_prog_data
->uses_sample_mask
) {
3603 /* TODO: conservative rasterization */
3604 if (wm_prog_data
->post_depth_coverage
)
3605 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
3607 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
3610 psx
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
3611 psx
.PixelShaderComputesStencil
= wm_prog_data
->computed_stencil
;
3613 psx
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
3620 * Compute the size of the derived data (shader command packets).
3622 * This must match the data written by the iris_store_xs_state() functions.
3625 iris_store_cs_state(struct iris_context
*ice
,
3626 const struct gen_device_info
*devinfo
,
3627 struct iris_compiled_shader
*shader
)
3629 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3630 struct brw_cs_prog_data
*cs_prog_data
= (void *) shader
->prog_data
;
3631 void *map
= shader
->derived_data
;
3633 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), map
, desc
) {
3634 desc
.KernelStartPointer
= KSP(shader
);
3635 desc
.ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
;
3636 desc
.NumberofThreadsinGPGPUThreadGroup
= cs_prog_data
->threads
;
3637 desc
.SharedLocalMemorySize
=
3638 encode_slm_size(GEN_GEN
, prog_data
->total_shared
);
3639 desc
.BarrierEnable
= cs_prog_data
->uses_barrier
;
3640 desc
.CrossThreadConstantDataReadLength
=
3641 cs_prog_data
->push
.cross_thread
.regs
;
3646 iris_derived_program_state_size(enum iris_program_cache_id cache_id
)
3648 assert(cache_id
<= IRIS_CACHE_BLORP
);
3650 static const unsigned dwords
[] = {
3651 [IRIS_CACHE_VS
] = GENX(3DSTATE_VS_length
),
3652 [IRIS_CACHE_TCS
] = GENX(3DSTATE_HS_length
),
3653 [IRIS_CACHE_TES
] = GENX(3DSTATE_TE_length
) + GENX(3DSTATE_DS_length
),
3654 [IRIS_CACHE_GS
] = GENX(3DSTATE_GS_length
),
3656 GENX(3DSTATE_PS_length
) + GENX(3DSTATE_PS_EXTRA_length
),
3657 [IRIS_CACHE_CS
] = GENX(INTERFACE_DESCRIPTOR_DATA_length
),
3658 [IRIS_CACHE_BLORP
] = 0,
3661 return sizeof(uint32_t) * dwords
[cache_id
];
3665 * Create any state packets corresponding to the given shader stage
3666 * (i.e. 3DSTATE_VS) and save them as "derived data" in the shader variant.
3667 * This means that we can look up a program in the in-memory cache and
3668 * get most of the state packet without having to reconstruct it.
3671 iris_store_derived_program_state(struct iris_context
*ice
,
3672 enum iris_program_cache_id cache_id
,
3673 struct iris_compiled_shader
*shader
)
3675 struct iris_screen
*screen
= (void *) ice
->ctx
.screen
;
3676 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
3680 iris_store_vs_state(ice
, devinfo
, shader
);
3682 case IRIS_CACHE_TCS
:
3683 iris_store_tcs_state(ice
, devinfo
, shader
);
3685 case IRIS_CACHE_TES
:
3686 iris_store_tes_state(ice
, devinfo
, shader
);
3689 iris_store_gs_state(ice
, devinfo
, shader
);
3692 iris_store_fs_state(ice
, devinfo
, shader
);
3695 iris_store_cs_state(ice
, devinfo
, shader
);
3696 case IRIS_CACHE_BLORP
:
3703 /* ------------------------------------------------------------------- */
3705 static const uint32_t push_constant_opcodes
[] = {
3706 [MESA_SHADER_VERTEX
] = 21,
3707 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
3708 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
3709 [MESA_SHADER_GEOMETRY
] = 22,
3710 [MESA_SHADER_FRAGMENT
] = 23,
3711 [MESA_SHADER_COMPUTE
] = 0,
3715 use_null_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
3717 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.unbound_tex
.res
);
3719 iris_use_pinned_bo(batch
, state_bo
, false);
3721 return ice
->state
.unbound_tex
.offset
;
3725 use_null_fb_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
3727 /* If set_framebuffer_state() was never called, fall back to 1x1x1 */
3728 if (!ice
->state
.null_fb
.res
)
3729 return use_null_surface(batch
, ice
);
3731 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.null_fb
.res
);
3733 iris_use_pinned_bo(batch
, state_bo
, false);
3735 return ice
->state
.null_fb
.offset
;
3739 surf_state_offset_for_aux(struct iris_resource
*res
,
3740 enum isl_aux_usage aux_usage
)
3742 return SURFACE_STATE_ALIGNMENT
*
3743 util_bitcount(res
->aux
.possible_usages
& ((1 << aux_usage
) - 1));
3747 surf_state_update_clear_value(struct iris_batch
*batch
,
3748 struct iris_resource
*res
,
3749 struct iris_state_ref
*state
,
3750 enum isl_aux_usage aux_usage
)
3752 struct isl_device
*isl_dev
= &batch
->screen
->isl_dev
;
3753 struct iris_bo
*state_bo
= iris_resource_bo(state
->res
);
3754 uint64_t real_offset
= state
->offset
+
3755 IRIS_MEMZONE_BINDER_START
;
3756 uint32_t offset_into_bo
= real_offset
- state_bo
->gtt_offset
;
3757 uint32_t clear_offset
= offset_into_bo
+
3758 isl_dev
->ss
.clear_value_offset
+
3759 surf_state_offset_for_aux(res
, aux_usage
);
3761 batch
->vtbl
->copy_mem_mem(batch
, state_bo
, clear_offset
,
3762 res
->aux
.clear_color_bo
,
3763 res
->aux
.clear_color_offset
,
3764 isl_dev
->ss
.clear_value_size
);
3768 update_clear_value(struct iris_batch
*batch
,
3769 struct iris_resource
*res
,
3770 struct iris_state_ref
*state
)
3772 unsigned aux_modes
= res
->aux
.possible_usages
;
3773 aux_modes
&= ~ISL_AUX_USAGE_NONE
;
3776 enum isl_aux_usage aux_usage
= u_bit_scan(&aux_modes
);
3777 surf_state_update_clear_value(batch
, res
, state
, aux_usage
);
3782 * Add a surface to the validation list, as well as the buffer containing
3783 * the corresponding SURFACE_STATE.
3785 * Returns the binding table entry (offset to SURFACE_STATE).
3788 use_surface(struct iris_batch
*batch
,
3789 struct pipe_surface
*p_surf
,
3791 enum isl_aux_usage aux_usage
)
3793 struct iris_surface
*surf
= (void *) p_surf
;
3794 struct iris_resource
*res
= (void *) p_surf
->texture
;
3796 iris_use_pinned_bo(batch
, iris_resource_bo(p_surf
->texture
), writeable
);
3797 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state
.res
), false);
3800 iris_use_pinned_bo(batch
, res
->aux
.bo
, writeable
);
3801 iris_use_pinned_bo(batch
, res
->aux
.clear_color_bo
, false);
3803 if (memcmp(&res
->aux
.clear_color
, &surf
->clear_color
,
3804 sizeof(surf
->clear_color
)) != 0) {
3805 update_clear_value(batch
, res
, &surf
->surface_state
);
3806 surf
->clear_color
= res
->aux
.clear_color
;
3810 return surf
->surface_state
.offset
+
3811 surf_state_offset_for_aux(res
, aux_usage
);
3815 use_sampler_view(struct iris_context
*ice
,
3816 struct iris_batch
*batch
,
3817 struct iris_sampler_view
*isv
)
3820 enum isl_aux_usage aux_usage
=
3821 iris_resource_texture_aux_usage(ice
, isv
->res
, isv
->view
.format
, 0);
3823 iris_use_pinned_bo(batch
, isv
->res
->bo
, false);
3824 iris_use_pinned_bo(batch
, iris_resource_bo(isv
->surface_state
.res
), false);
3826 if (isv
->res
->aux
.bo
) {
3827 iris_use_pinned_bo(batch
, isv
->res
->aux
.bo
, false);
3828 iris_use_pinned_bo(batch
, isv
->res
->aux
.clear_color_bo
, false);
3829 if (memcmp(&isv
->res
->aux
.clear_color
, &isv
->clear_color
,
3830 sizeof(isv
->clear_color
)) != 0) {
3831 update_clear_value(batch
, isv
->res
, &isv
->surface_state
);
3832 isv
->clear_color
= isv
->res
->aux
.clear_color
;
3836 return isv
->surface_state
.offset
+
3837 surf_state_offset_for_aux(isv
->res
, aux_usage
);
3841 use_const_buffer(struct iris_batch
*batch
,
3842 struct iris_context
*ice
,
3843 struct iris_const_buffer
*cbuf
)
3845 if (!cbuf
->surface_state
.res
)
3846 return use_null_surface(batch
, ice
);
3848 iris_use_pinned_bo(batch
, iris_resource_bo(cbuf
->data
.res
), false);
3849 iris_use_pinned_bo(batch
, iris_resource_bo(cbuf
->surface_state
.res
), false);
3851 return cbuf
->surface_state
.offset
;
3855 use_ssbo(struct iris_batch
*batch
, struct iris_context
*ice
,
3856 struct iris_shader_state
*shs
, int i
)
3859 return use_null_surface(batch
, ice
);
3861 struct iris_state_ref
*surf_state
= &shs
->ssbo_surface_state
[i
];
3863 iris_use_pinned_bo(batch
, iris_resource_bo(shs
->ssbo
[i
]), true);
3864 iris_use_pinned_bo(batch
, iris_resource_bo(surf_state
->res
), false);
3866 return surf_state
->offset
;
3870 use_image(struct iris_batch
*batch
, struct iris_context
*ice
,
3871 struct iris_shader_state
*shs
, int i
)
3873 if (!shs
->image
[i
].res
)
3874 return use_null_surface(batch
, ice
);
3876 struct iris_resource
*res
= (void *) shs
->image
[i
].res
;
3877 struct iris_state_ref
*surf_state
= &shs
->image
[i
].surface_state
;
3878 bool write
= shs
->image
[i
].access
& PIPE_IMAGE_ACCESS_WRITE
;
3880 iris_use_pinned_bo(batch
, res
->bo
, write
);
3881 iris_use_pinned_bo(batch
, iris_resource_bo(surf_state
->res
), false);
3884 iris_use_pinned_bo(batch
, res
->aux
.bo
, write
);
3886 return surf_state
->offset
;
3889 #define push_bt_entry(addr) \
3890 assert(addr >= binder_addr); \
3891 assert(s < prog_data->binding_table.size_bytes / sizeof(uint32_t)); \
3892 if (!pin_only) bt_map[s++] = (addr) - binder_addr;
3894 #define bt_assert(section, exists) \
3895 if (!pin_only) assert(prog_data->binding_table.section == \
3896 (exists) ? s : 0xd0d0d0d0)
3899 * Populate the binding table for a given shader stage.
3901 * This fills out the table of pointers to surfaces required by the shader,
3902 * and also adds those buffers to the validation list so the kernel can make
3903 * resident before running our batch.
3906 iris_populate_binding_table(struct iris_context
*ice
,
3907 struct iris_batch
*batch
,
3908 gl_shader_stage stage
,
3911 const struct iris_binder
*binder
= &ice
->state
.binder
;
3912 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
3916 UNUSED
struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
3917 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
3918 uint32_t binder_addr
= binder
->bo
->gtt_offset
;
3920 //struct brw_stage_prog_data *prog_data = (void *) shader->prog_data;
3921 uint32_t *bt_map
= binder
->map
+ binder
->bt_offset
[stage
];
3924 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
3926 /* TCS passthrough doesn't need a binding table. */
3927 assert(stage
== MESA_SHADER_TESS_CTRL
);
3931 if (stage
== MESA_SHADER_COMPUTE
) {
3932 /* surface for gl_NumWorkGroups */
3933 struct iris_state_ref
*grid_data
= &ice
->state
.grid_size
;
3934 struct iris_state_ref
*grid_state
= &ice
->state
.grid_surf_state
;
3935 iris_use_pinned_bo(batch
, iris_resource_bo(grid_data
->res
), false);
3936 iris_use_pinned_bo(batch
, iris_resource_bo(grid_state
->res
), false);
3937 push_bt_entry(grid_state
->offset
);
3940 if (stage
== MESA_SHADER_FRAGMENT
) {
3941 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
3942 /* Note that cso_fb->nr_cbufs == fs_key->nr_color_regions. */
3943 if (cso_fb
->nr_cbufs
) {
3944 for (unsigned i
= 0; i
< cso_fb
->nr_cbufs
; i
++) {
3946 if (cso_fb
->cbufs
[i
]) {
3947 addr
= use_surface(batch
, cso_fb
->cbufs
[i
], true,
3948 ice
->state
.draw_aux_usage
[i
]);
3950 addr
= use_null_fb_surface(batch
, ice
);
3952 push_bt_entry(addr
);
3955 uint32_t addr
= use_null_fb_surface(batch
, ice
);
3956 push_bt_entry(addr
);
3960 unsigned num_textures
= util_last_bit(info
->textures_used
);
3962 bt_assert(texture_start
, num_textures
> 0);
3964 for (int i
= 0; i
< num_textures
; i
++) {
3965 struct iris_sampler_view
*view
= shs
->textures
[i
];
3966 uint32_t addr
= view
? use_sampler_view(ice
, batch
, view
)
3967 : use_null_surface(batch
, ice
);
3968 push_bt_entry(addr
);
3971 bt_assert(image_start
, info
->num_images
> 0);
3973 for (int i
= 0; i
< info
->num_images
; i
++) {
3974 uint32_t addr
= use_image(batch
, ice
, shs
, i
);
3975 push_bt_entry(addr
);
3978 bt_assert(ubo_start
, shader
->num_cbufs
> 0);
3980 for (int i
= 0; i
< shader
->num_cbufs
; i
++) {
3981 uint32_t addr
= use_const_buffer(batch
, ice
, &shs
->constbuf
[i
]);
3982 push_bt_entry(addr
);
3985 bt_assert(ssbo_start
, info
->num_abos
+ info
->num_ssbos
> 0);
3987 /* XXX: st is wasting 16 binding table slots for ABOs. Should add a cap
3988 * for changing nir_lower_atomics_to_ssbos setting and buffer_base offset
3989 * in st_atom_storagebuf.c so it'll compact them into one range, with
3990 * SSBOs starting at info->num_abos. Ideally it'd reset num_abos to 0 too
3992 if (info
->num_abos
+ info
->num_ssbos
> 0) {
3993 for (int i
= 0; i
< IRIS_MAX_ABOS
+ info
->num_ssbos
; i
++) {
3994 uint32_t addr
= use_ssbo(batch
, ice
, shs
, i
);
3995 push_bt_entry(addr
);
4000 /* XXX: YUV surfaces not implemented yet */
4001 bt_assert(plane_start
[1], ...);
4002 bt_assert(plane_start
[2], ...);
4007 iris_use_optional_res(struct iris_batch
*batch
,
4008 struct pipe_resource
*res
,
4012 struct iris_bo
*bo
= iris_resource_bo(res
);
4013 iris_use_pinned_bo(batch
, bo
, writeable
);
4018 pin_depth_and_stencil_buffers(struct iris_batch
*batch
,
4019 struct pipe_surface
*zsbuf
,
4020 struct iris_depth_stencil_alpha_state
*cso_zsa
)
4025 struct iris_resource
*zres
, *sres
;
4026 iris_get_depth_stencil_resources(zsbuf
->texture
, &zres
, &sres
);
4029 iris_use_pinned_bo(batch
, zres
->bo
, cso_zsa
->depth_writes_enabled
);
4031 iris_use_pinned_bo(batch
, zres
->aux
.bo
,
4032 cso_zsa
->depth_writes_enabled
);
4037 iris_use_pinned_bo(batch
, sres
->bo
, cso_zsa
->stencil_writes_enabled
);
4041 /* ------------------------------------------------------------------- */
4044 * Pin any BOs which were installed by a previous batch, and restored
4045 * via the hardware logical context mechanism.
4047 * We don't need to re-emit all state every batch - the hardware context
4048 * mechanism will save and restore it for us. This includes pointers to
4049 * various BOs...which won't exist unless we ask the kernel to pin them
4050 * by adding them to the validation list.
4052 * We can skip buffers if we've re-emitted those packets, as we're
4053 * overwriting those stale pointers with new ones, and don't actually
4054 * refer to the old BOs.
4057 iris_restore_render_saved_bos(struct iris_context
*ice
,
4058 struct iris_batch
*batch
,
4059 const struct pipe_draw_info
*draw
)
4061 struct iris_genx_state
*genx
= ice
->state
.genx
;
4063 const uint64_t clean
= ~ice
->state
.dirty
;
4065 if (clean
& IRIS_DIRTY_CC_VIEWPORT
) {
4066 iris_use_optional_res(batch
, ice
->state
.last_res
.cc_vp
, false);
4069 if (clean
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
4070 iris_use_optional_res(batch
, ice
->state
.last_res
.sf_cl_vp
, false);
4073 if (clean
& IRIS_DIRTY_BLEND_STATE
) {
4074 iris_use_optional_res(batch
, ice
->state
.last_res
.blend
, false);
4077 if (clean
& IRIS_DIRTY_COLOR_CALC_STATE
) {
4078 iris_use_optional_res(batch
, ice
->state
.last_res
.color_calc
, false);
4081 if (clean
& IRIS_DIRTY_SCISSOR_RECT
) {
4082 iris_use_optional_res(batch
, ice
->state
.last_res
.scissor
, false);
4085 if (ice
->state
.streamout_active
&& (clean
& IRIS_DIRTY_SO_BUFFERS
)) {
4086 for (int i
= 0; i
< 4; i
++) {
4087 struct iris_stream_output_target
*tgt
=
4088 (void *) ice
->state
.so_target
[i
];
4090 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
4092 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
4098 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4099 if (!(clean
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
4102 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4103 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4108 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
4110 for (int i
= 0; i
< 4; i
++) {
4111 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
4113 if (range
->length
== 0)
4116 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[range
->block
];
4117 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
4120 iris_use_pinned_bo(batch
, res
->bo
, false);
4122 iris_use_pinned_bo(batch
, batch
->screen
->workaround_bo
, false);
4126 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4127 if (clean
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
4128 /* Re-pin any buffers referred to by the binding table. */
4129 iris_populate_binding_table(ice
, batch
, stage
, true);
4133 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4134 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4135 struct pipe_resource
*res
= shs
->sampler_table
.res
;
4137 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4140 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4141 if (clean
& (IRIS_DIRTY_VS
<< stage
)) {
4142 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4145 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
4146 iris_use_pinned_bo(batch
, bo
, false);
4148 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4150 if (prog_data
->total_scratch
> 0) {
4151 struct iris_bo
*bo
=
4152 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
4153 iris_use_pinned_bo(batch
, bo
, true);
4159 if ((clean
& IRIS_DIRTY_DEPTH_BUFFER
) &&
4160 (clean
& IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
4161 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4162 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
4165 if (draw
->index_size
== 0 && ice
->state
.last_res
.index_buffer
) {
4166 /* This draw didn't emit a new index buffer, so we are inheriting the
4167 * older index buffer. This draw didn't need it, but future ones may.
4169 struct iris_bo
*bo
= iris_resource_bo(ice
->state
.last_res
.index_buffer
);
4170 iris_use_pinned_bo(batch
, bo
, false);
4173 if (clean
& IRIS_DIRTY_VERTEX_BUFFERS
) {
4174 uint64_t bound
= ice
->state
.bound_vertex_buffers
;
4176 const int i
= u_bit_scan64(&bound
);
4177 struct pipe_resource
*res
= genx
->vertex_buffers
[i
].resource
;
4178 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4184 iris_restore_compute_saved_bos(struct iris_context
*ice
,
4185 struct iris_batch
*batch
,
4186 const struct pipe_grid_info
*grid
)
4188 const uint64_t clean
= ~ice
->state
.dirty
;
4190 const int stage
= MESA_SHADER_COMPUTE
;
4191 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4193 if (clean
& IRIS_DIRTY_CONSTANTS_CS
) {
4194 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4197 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
4198 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[0];
4200 if (range
->length
> 0) {
4201 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[range
->block
];
4202 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
4205 iris_use_pinned_bo(batch
, res
->bo
, false);
4207 iris_use_pinned_bo(batch
, batch
->screen
->workaround_bo
, false);
4212 if (clean
& IRIS_DIRTY_BINDINGS_CS
) {
4213 /* Re-pin any buffers referred to by the binding table. */
4214 iris_populate_binding_table(ice
, batch
, stage
, true);
4217 struct pipe_resource
*sampler_res
= shs
->sampler_table
.res
;
4219 iris_use_pinned_bo(batch
, iris_resource_bo(sampler_res
), false);
4221 if (clean
& IRIS_DIRTY_CS
) {
4222 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4225 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
4226 iris_use_pinned_bo(batch
, bo
, false);
4228 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
4230 if (prog_data
->total_scratch
> 0) {
4231 struct iris_bo
*bo
=
4232 iris_get_scratch_space(ice
, prog_data
->total_scratch
, stage
);
4233 iris_use_pinned_bo(batch
, bo
, true);
4240 * Possibly emit STATE_BASE_ADDRESS to update Surface State Base Address.
4243 iris_update_surface_base_address(struct iris_batch
*batch
,
4244 struct iris_binder
*binder
)
4246 if (batch
->last_surface_base_address
== binder
->bo
->gtt_offset
)
4249 flush_for_state_base_change(batch
);
4251 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
4252 sba
.SurfaceStateMOCS
= MOCS_WB
;
4253 sba
.SurfaceStateBaseAddressModifyEnable
= true;
4254 sba
.SurfaceStateBaseAddress
= ro_bo(binder
->bo
, 0);
4257 batch
->last_surface_base_address
= binder
->bo
->gtt_offset
;
4261 iris_upload_dirty_render_state(struct iris_context
*ice
,
4262 struct iris_batch
*batch
,
4263 const struct pipe_draw_info
*draw
)
4265 const uint64_t dirty
= ice
->state
.dirty
;
4267 if (!(dirty
& IRIS_ALL_DIRTY_FOR_RENDER
))
4270 struct iris_genx_state
*genx
= ice
->state
.genx
;
4271 struct iris_binder
*binder
= &ice
->state
.binder
;
4272 struct brw_wm_prog_data
*wm_prog_data
= (void *)
4273 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
4275 if (dirty
& IRIS_DIRTY_CC_VIEWPORT
) {
4276 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4277 uint32_t cc_vp_address
;
4279 /* XXX: could avoid streaming for depth_clip [0,1] case. */
4280 uint32_t *cc_vp_map
=
4281 stream_state(batch
, ice
->state
.dynamic_uploader
,
4282 &ice
->state
.last_res
.cc_vp
,
4283 4 * ice
->state
.num_viewports
*
4284 GENX(CC_VIEWPORT_length
), 32, &cc_vp_address
);
4285 for (int i
= 0; i
< ice
->state
.num_viewports
; i
++) {
4287 util_viewport_zmin_zmax(&ice
->state
.viewports
[i
],
4288 cso_rast
->clip_halfz
, &zmin
, &zmax
);
4289 if (cso_rast
->depth_clip_near
)
4291 if (cso_rast
->depth_clip_far
)
4294 iris_pack_state(GENX(CC_VIEWPORT
), cc_vp_map
, ccv
) {
4295 ccv
.MinimumDepth
= zmin
;
4296 ccv
.MaximumDepth
= zmax
;
4299 cc_vp_map
+= GENX(CC_VIEWPORT_length
);
4302 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), ptr
) {
4303 ptr
.CCViewportPointer
= cc_vp_address
;
4307 if (dirty
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
4308 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4309 uint32_t sf_cl_vp_address
;
4311 stream_state(batch
, ice
->state
.dynamic_uploader
,
4312 &ice
->state
.last_res
.sf_cl_vp
,
4313 4 * ice
->state
.num_viewports
*
4314 GENX(SF_CLIP_VIEWPORT_length
), 64, &sf_cl_vp_address
);
4316 for (unsigned i
= 0; i
< ice
->state
.num_viewports
; i
++) {
4317 const struct pipe_viewport_state
*state
= &ice
->state
.viewports
[i
];
4318 float gb_xmin
, gb_xmax
, gb_ymin
, gb_ymax
;
4320 float vp_xmin
= viewport_extent(state
, 0, -1.0f
);
4321 float vp_xmax
= viewport_extent(state
, 0, 1.0f
);
4322 float vp_ymin
= viewport_extent(state
, 1, -1.0f
);
4323 float vp_ymax
= viewport_extent(state
, 1, 1.0f
);
4325 calculate_guardband_size(cso_fb
->width
, cso_fb
->height
,
4326 state
->scale
[0], state
->scale
[1],
4327 state
->translate
[0], state
->translate
[1],
4328 &gb_xmin
, &gb_xmax
, &gb_ymin
, &gb_ymax
);
4330 iris_pack_state(GENX(SF_CLIP_VIEWPORT
), vp_map
, vp
) {
4331 vp
.ViewportMatrixElementm00
= state
->scale
[0];
4332 vp
.ViewportMatrixElementm11
= state
->scale
[1];
4333 vp
.ViewportMatrixElementm22
= state
->scale
[2];
4334 vp
.ViewportMatrixElementm30
= state
->translate
[0];
4335 vp
.ViewportMatrixElementm31
= state
->translate
[1];
4336 vp
.ViewportMatrixElementm32
= state
->translate
[2];
4337 vp
.XMinClipGuardband
= gb_xmin
;
4338 vp
.XMaxClipGuardband
= gb_xmax
;
4339 vp
.YMinClipGuardband
= gb_ymin
;
4340 vp
.YMaxClipGuardband
= gb_ymax
;
4341 vp
.XMinViewPort
= MAX2(vp_xmin
, 0);
4342 vp
.XMaxViewPort
= MIN2(vp_xmax
, cso_fb
->width
) - 1;
4343 vp
.YMinViewPort
= MAX2(vp_ymin
, 0);
4344 vp
.YMaxViewPort
= MIN2(vp_ymax
, cso_fb
->height
) - 1;
4347 vp_map
+= GENX(SF_CLIP_VIEWPORT_length
);
4350 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
4351 ptr
.SFClipViewportPointer
= sf_cl_vp_address
;
4355 if (dirty
& IRIS_DIRTY_URB
) {
4358 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
4359 if (!ice
->shaders
.prog
[i
]) {
4362 struct brw_vue_prog_data
*vue_prog_data
=
4363 (void *) ice
->shaders
.prog
[i
]->prog_data
;
4364 size
[i
] = vue_prog_data
->urb_entry_size
;
4366 assert(size
[i
] != 0);
4369 genX(emit_urb_setup
)(ice
, batch
, size
,
4370 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
] != NULL
,
4371 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] != NULL
);
4374 if (dirty
& IRIS_DIRTY_BLEND_STATE
) {
4375 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
4376 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4377 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
4378 const int header_dwords
= GENX(BLEND_STATE_length
);
4380 /* Always write at least one BLEND_STATE - the final RT message will
4381 * reference BLEND_STATE[0] even if there aren't color writes. There
4382 * may still be alpha testing, computed depth, and so on.
4384 const int rt_dwords
=
4385 MAX2(cso_fb
->nr_cbufs
, 1) * GENX(BLEND_STATE_ENTRY_length
);
4387 uint32_t blend_offset
;
4388 uint32_t *blend_map
=
4389 stream_state(batch
, ice
->state
.dynamic_uploader
,
4390 &ice
->state
.last_res
.blend
,
4391 4 * (header_dwords
+ rt_dwords
), 64, &blend_offset
);
4393 uint32_t blend_state_header
;
4394 iris_pack_state(GENX(BLEND_STATE
), &blend_state_header
, bs
) {
4395 bs
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
4396 bs
.AlphaTestFunction
= translate_compare_func(cso_zsa
->alpha
.func
);
4399 blend_map
[0] = blend_state_header
| cso_blend
->blend_state
[0];
4400 memcpy(&blend_map
[1], &cso_blend
->blend_state
[1], 4 * rt_dwords
);
4402 iris_emit_cmd(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
4403 ptr
.BlendStatePointer
= blend_offset
;
4404 ptr
.BlendStatePointerValid
= true;
4408 if (dirty
& IRIS_DIRTY_COLOR_CALC_STATE
) {
4409 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
4411 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
4415 stream_state(batch
, ice
->state
.dynamic_uploader
,
4416 &ice
->state
.last_res
.color_calc
,
4417 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length
),
4419 iris_pack_state(GENX(COLOR_CALC_STATE
), cc_map
, cc
) {
4420 cc
.AlphaTestFormat
= ALPHATEST_FLOAT32
;
4421 cc
.AlphaReferenceValueAsFLOAT32
= cso
->alpha
.ref_value
;
4422 cc
.BlendConstantColorRed
= ice
->state
.blend_color
.color
[0];
4423 cc
.BlendConstantColorGreen
= ice
->state
.blend_color
.color
[1];
4424 cc
.BlendConstantColorBlue
= ice
->state
.blend_color
.color
[2];
4425 cc
.BlendConstantColorAlpha
= ice
->state
.blend_color
.color
[3];
4427 cc
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
4428 cc
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
4431 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
4432 ptr
.ColorCalcStatePointer
= cc_offset
;
4433 ptr
.ColorCalcStatePointerValid
= true;
4437 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4438 if (!(dirty
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
4441 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4442 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4447 if (shs
->cbuf0_needs_upload
)
4448 upload_uniforms(ice
, stage
);
4450 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
4452 iris_emit_cmd(batch
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
4453 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
4455 /* The Skylake PRM contains the following restriction:
4457 * "The driver must ensure The following case does not occur
4458 * without a flush to the 3D engine: 3DSTATE_CONSTANT_* with
4459 * buffer 3 read length equal to zero committed followed by a
4460 * 3DSTATE_CONSTANT_* with buffer 0 read length not equal to
4463 * To avoid this, we program the buffers in the highest slots.
4464 * This way, slot 0 is only used if slot 3 is also used.
4468 for (int i
= 3; i
>= 0; i
--) {
4469 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
4471 if (range
->length
== 0)
4474 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[range
->block
];
4475 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
4477 assert(cbuf
->data
.offset
% 32 == 0);
4479 pkt
.ConstantBody
.ReadLength
[n
] = range
->length
;
4480 pkt
.ConstantBody
.Buffer
[n
] =
4481 res
? ro_bo(res
->bo
, range
->start
* 32 + cbuf
->data
.offset
)
4482 : ro_bo(batch
->screen
->workaround_bo
, 0);
4489 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4490 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
4491 iris_emit_cmd(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), ptr
) {
4492 ptr
._3DCommandSubOpcode
= 38 + stage
;
4493 ptr
.PointertoVSBindingTable
= binder
->bt_offset
[stage
];
4498 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4499 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
4500 iris_populate_binding_table(ice
, batch
, stage
, false);
4504 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4505 if (!(dirty
& (IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
)) ||
4506 !ice
->shaders
.prog
[stage
])
4509 iris_upload_sampler_states(ice
, stage
);
4511 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
4512 struct pipe_resource
*res
= shs
->sampler_table
.res
;
4514 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
4516 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ptr
) {
4517 ptr
._3DCommandSubOpcode
= 43 + stage
;
4518 ptr
.PointertoVSSamplerState
= shs
->sampler_table
.offset
;
4522 if (ice
->state
.need_border_colors
)
4523 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
4525 if (dirty
& IRIS_DIRTY_MULTISAMPLE
) {
4526 iris_emit_cmd(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
4528 ice
->state
.cso_rast
->half_pixel_center
? CENTER
: UL_CORNER
;
4529 if (ice
->state
.framebuffer
.samples
> 0)
4530 ms
.NumberofMultisamples
= ffs(ice
->state
.framebuffer
.samples
) - 1;
4534 if (dirty
& IRIS_DIRTY_SAMPLE_MASK
) {
4535 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_MASK
), ms
) {
4536 ms
.SampleMask
= ice
->state
.sample_mask
;
4540 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
4541 if (!(dirty
& (IRIS_DIRTY_VS
<< stage
)))
4544 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
4547 struct iris_resource
*cache
= (void *) shader
->assembly
.res
;
4548 iris_use_pinned_bo(batch
, cache
->bo
, false);
4549 iris_batch_emit(batch
, shader
->derived_data
,
4550 iris_derived_program_state_size(stage
));
4552 if (stage
== MESA_SHADER_TESS_EVAL
) {
4553 iris_emit_cmd(batch
, GENX(3DSTATE_HS
), hs
);
4554 iris_emit_cmd(batch
, GENX(3DSTATE_TE
), te
);
4555 iris_emit_cmd(batch
, GENX(3DSTATE_DS
), ds
);
4556 } else if (stage
== MESA_SHADER_GEOMETRY
) {
4557 iris_emit_cmd(batch
, GENX(3DSTATE_GS
), gs
);
4562 if (ice
->state
.streamout_active
) {
4563 if (dirty
& IRIS_DIRTY_SO_BUFFERS
) {
4564 iris_batch_emit(batch
, genx
->so_buffers
,
4565 4 * 4 * GENX(3DSTATE_SO_BUFFER_length
));
4566 for (int i
= 0; i
< 4; i
++) {
4567 struct iris_stream_output_target
*tgt
=
4568 (void *) ice
->state
.so_target
[i
];
4570 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
4572 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
4578 if ((dirty
& IRIS_DIRTY_SO_DECL_LIST
) && ice
->state
.streamout
) {
4579 uint32_t *decl_list
=
4580 ice
->state
.streamout
+ GENX(3DSTATE_STREAMOUT_length
);
4581 iris_batch_emit(batch
, decl_list
, 4 * ((decl_list
[0] & 0xff) + 2));
4584 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
4585 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4587 uint32_t dynamic_sol
[GENX(3DSTATE_STREAMOUT_length
)];
4588 iris_pack_command(GENX(3DSTATE_STREAMOUT
), dynamic_sol
, sol
) {
4589 sol
.SOFunctionEnable
= true;
4590 sol
.SOStatisticsEnable
= true;
4592 sol
.RenderingDisable
= cso_rast
->rasterizer_discard
&&
4593 !ice
->state
.prims_generated_query_active
;
4594 sol
.ReorderMode
= cso_rast
->flatshade_first
? LEADING
: TRAILING
;
4597 assert(ice
->state
.streamout
);
4599 iris_emit_merge(batch
, ice
->state
.streamout
, dynamic_sol
,
4600 GENX(3DSTATE_STREAMOUT_length
));
4603 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
4604 iris_emit_cmd(batch
, GENX(3DSTATE_STREAMOUT
), sol
);
4608 if (dirty
& IRIS_DIRTY_CLIP
) {
4609 struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
4610 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4612 uint32_t dynamic_clip
[GENX(3DSTATE_CLIP_length
)];
4613 iris_pack_command(GENX(3DSTATE_CLIP
), &dynamic_clip
, cl
) {
4614 cl
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
4615 cl
.ClipMode
= cso_rast
->rasterizer_discard
? CLIPMODE_REJECT_ALL
4617 if (wm_prog_data
->barycentric_interp_modes
&
4618 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
4619 cl
.NonPerspectiveBarycentricEnable
= true;
4621 cl
.ForceZeroRTAIndexEnable
= cso_fb
->layers
== 0;
4622 cl
.MaximumVPIndex
= ice
->state
.num_viewports
- 1;
4624 iris_emit_merge(batch
, cso_rast
->clip
, dynamic_clip
,
4625 ARRAY_SIZE(cso_rast
->clip
));
4628 if (dirty
& IRIS_DIRTY_RASTER
) {
4629 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
4630 iris_batch_emit(batch
, cso
->raster
, sizeof(cso
->raster
));
4631 iris_batch_emit(batch
, cso
->sf
, sizeof(cso
->sf
));
4635 if (dirty
& IRIS_DIRTY_WM
) {
4636 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
4637 uint32_t dynamic_wm
[GENX(3DSTATE_WM_length
)];
4639 iris_pack_command(GENX(3DSTATE_WM
), &dynamic_wm
, wm
) {
4640 wm
.StatisticsEnable
= ice
->state
.statistics_counters_enabled
;
4642 wm
.BarycentricInterpolationMode
=
4643 wm_prog_data
->barycentric_interp_modes
;
4645 if (wm_prog_data
->early_fragment_tests
)
4646 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
4647 else if (wm_prog_data
->has_side_effects
)
4648 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
4650 /* We could skip this bit if color writes are enabled. */
4651 if (wm_prog_data
->has_side_effects
|| wm_prog_data
->uses_kill
)
4652 wm
.ForceThreadDispatchEnable
= ForceON
;
4654 iris_emit_merge(batch
, cso
->wm
, dynamic_wm
, ARRAY_SIZE(cso
->wm
));
4657 if (dirty
& IRIS_DIRTY_SBE
) {
4658 iris_emit_sbe(batch
, ice
);
4661 if (dirty
& IRIS_DIRTY_PS_BLEND
) {
4662 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
4663 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
4664 const struct shader_info
*fs_info
=
4665 iris_get_shader_info(ice
, MESA_SHADER_FRAGMENT
);
4667 uint32_t dynamic_pb
[GENX(3DSTATE_PS_BLEND_length
)];
4668 iris_pack_command(GENX(3DSTATE_PS_BLEND
), &dynamic_pb
, pb
) {
4669 pb
.HasWriteableRT
= has_writeable_rt(cso_blend
, fs_info
);
4670 pb
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
4673 iris_emit_merge(batch
, cso_blend
->ps_blend
, dynamic_pb
,
4674 ARRAY_SIZE(cso_blend
->ps_blend
));
4677 if (dirty
& IRIS_DIRTY_WM_DEPTH_STENCIL
) {
4678 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
4680 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
4681 uint32_t stencil_refs
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
4682 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), &stencil_refs
, wmds
) {
4683 wmds
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
4684 wmds
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
4686 iris_emit_merge(batch
, cso
->wmds
, stencil_refs
, ARRAY_SIZE(cso
->wmds
));
4688 iris_batch_emit(batch
, cso
->wmds
, sizeof(cso
->wmds
));
4692 if (dirty
& IRIS_DIRTY_SCISSOR_RECT
) {
4693 uint32_t scissor_offset
=
4694 emit_state(batch
, ice
->state
.dynamic_uploader
,
4695 &ice
->state
.last_res
.scissor
,
4696 ice
->state
.scissors
,
4697 sizeof(struct pipe_scissor_state
) *
4698 ice
->state
.num_viewports
, 32);
4700 iris_emit_cmd(batch
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
4701 ptr
.ScissorRectPointer
= scissor_offset
;
4705 if (dirty
& IRIS_DIRTY_DEPTH_BUFFER
) {
4706 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
4708 /* Do not emit the clear params yets. We need to update the clear value
4711 uint32_t clear_length
= GENX(3DSTATE_CLEAR_PARAMS_length
) * 4;
4712 uint32_t cso_z_size
= sizeof(cso_z
->packets
) - clear_length
;
4713 iris_batch_emit(batch
, cso_z
->packets
, cso_z_size
);
4715 union isl_color_value clear_value
= { .f32
= { 0, } };
4717 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4718 if (cso_fb
->zsbuf
) {
4719 struct iris_resource
*zres
, *sres
;
4720 iris_get_depth_stencil_resources(cso_fb
->zsbuf
->texture
,
4722 if (zres
&& zres
->aux
.bo
)
4723 clear_value
= iris_resource_get_clear_color(zres
, NULL
, NULL
);
4726 uint32_t clear_params
[GENX(3DSTATE_CLEAR_PARAMS_length
)];
4727 iris_pack_command(GENX(3DSTATE_CLEAR_PARAMS
), clear_params
, clear
) {
4728 clear
.DepthClearValueValid
= true;
4729 clear
.DepthClearValue
= clear_value
.f32
[0];
4731 iris_batch_emit(batch
, clear_params
, clear_length
);
4734 if (dirty
& (IRIS_DIRTY_DEPTH_BUFFER
| IRIS_DIRTY_WM_DEPTH_STENCIL
)) {
4735 /* Listen for buffer changes, and also write enable changes. */
4736 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
4737 pin_depth_and_stencil_buffers(batch
, cso_fb
->zsbuf
, ice
->state
.cso_zsa
);
4740 if (dirty
& IRIS_DIRTY_POLYGON_STIPPLE
) {
4741 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
4742 for (int i
= 0; i
< 32; i
++) {
4743 poly
.PatternRow
[i
] = ice
->state
.poly_stipple
.stipple
[i
];
4748 if (dirty
& IRIS_DIRTY_LINE_STIPPLE
) {
4749 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
4750 iris_batch_emit(batch
, cso
->line_stipple
, sizeof(cso
->line_stipple
));
4753 if (dirty
& IRIS_DIRTY_VF_TOPOLOGY
) {
4754 iris_emit_cmd(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
4755 topo
.PrimitiveTopologyType
=
4756 translate_prim_type(draw
->mode
, draw
->vertices_per_patch
);
4760 if (dirty
& IRIS_DIRTY_VERTEX_BUFFERS
) {
4761 int count
= util_bitcount64(ice
->state
.bound_vertex_buffers
);
4762 int dynamic_bound
= ice
->state
.bound_vertex_buffers
;
4764 if (ice
->state
.vs_uses_draw_params
) {
4765 if (ice
->draw
.draw_params_offset
== 0) {
4766 u_upload_data(ice
->state
.dynamic_uploader
, 0, sizeof(ice
->draw
.params
),
4767 4, &ice
->draw
.params
, &ice
->draw
.draw_params_offset
,
4768 &ice
->draw
.draw_params_res
);
4770 assert(ice
->draw
.draw_params_res
);
4772 struct iris_vertex_buffer_state
*state
=
4773 &(ice
->state
.genx
->vertex_buffers
[count
]);
4774 pipe_resource_reference(&state
->resource
, ice
->draw
.draw_params_res
);
4775 struct iris_resource
*res
= (void *) state
->resource
;
4777 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
4778 vb
.VertexBufferIndex
= count
;
4779 vb
.AddressModifyEnable
= true;
4781 vb
.BufferSize
= res
->bo
->size
- ice
->draw
.draw_params_offset
;
4782 vb
.BufferStartingAddress
=
4783 ro_bo(NULL
, res
->bo
->gtt_offset
+
4784 (int) ice
->draw
.draw_params_offset
);
4785 vb
.MOCS
= mocs(res
->bo
);
4787 dynamic_bound
|= 1ull << count
;
4791 if (ice
->state
.vs_uses_derived_draw_params
) {
4792 u_upload_data(ice
->state
.dynamic_uploader
, 0,
4793 sizeof(ice
->draw
.derived_params
), 4,
4794 &ice
->draw
.derived_params
,
4795 &ice
->draw
.derived_draw_params_offset
,
4796 &ice
->draw
.derived_draw_params_res
);
4798 struct iris_vertex_buffer_state
*state
=
4799 &(ice
->state
.genx
->vertex_buffers
[count
]);
4800 pipe_resource_reference(&state
->resource
,
4801 ice
->draw
.derived_draw_params_res
);
4802 struct iris_resource
*res
= (void *) ice
->draw
.derived_draw_params_res
;
4804 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), state
->state
, vb
) {
4805 vb
.VertexBufferIndex
= count
;
4806 vb
.AddressModifyEnable
= true;
4809 res
->bo
->size
- ice
->draw
.derived_draw_params_offset
;
4810 vb
.BufferStartingAddress
=
4811 ro_bo(NULL
, res
->bo
->gtt_offset
+
4812 (int) ice
->draw
.derived_draw_params_offset
);
4813 vb
.MOCS
= mocs(res
->bo
);
4815 dynamic_bound
|= 1ull << count
;
4820 /* The VF cache designers cut corners, and made the cache key's
4821 * <VertexBufferIndex, Memory Address> tuple only consider the bottom
4822 * 32 bits of the address. If you have two vertex buffers which get
4823 * placed exactly 4 GiB apart and use them in back-to-back draw calls,
4824 * you can get collisions (even within a single batch).
4826 * So, we need to do a VF cache invalidate if the buffer for a VB
4827 * slot slot changes [48:32] address bits from the previous time.
4829 unsigned flush_flags
= 0;
4831 uint64_t bound
= dynamic_bound
;
4833 const int i
= u_bit_scan64(&bound
);
4834 uint16_t high_bits
= 0;
4836 struct iris_resource
*res
=
4837 (void *) genx
->vertex_buffers
[i
].resource
;
4839 iris_use_pinned_bo(batch
, res
->bo
, false);
4841 high_bits
= res
->bo
->gtt_offset
>> 32ull;
4842 if (high_bits
!= ice
->state
.last_vbo_high_bits
[i
]) {
4843 flush_flags
|= PIPE_CONTROL_VF_CACHE_INVALIDATE
|
4844 PIPE_CONTROL_CS_STALL
;
4845 ice
->state
.last_vbo_high_bits
[i
] = high_bits
;
4848 /* If the buffer was written to by streamout, we may need
4849 * to stall so those writes land and become visible to the
4852 * TODO: This may stall more than necessary.
4854 if (res
->bind_history
& PIPE_BIND_STREAM_OUTPUT
)
4855 flush_flags
|= PIPE_CONTROL_CS_STALL
;
4860 iris_emit_pipe_control_flush(batch
, flush_flags
);
4862 const unsigned vb_dwords
= GENX(VERTEX_BUFFER_STATE_length
);
4865 iris_get_command_space(batch
, 4 * (1 + vb_dwords
* count
));
4866 _iris_pack_command(batch
, GENX(3DSTATE_VERTEX_BUFFERS
), map
, vb
) {
4867 vb
.DWordLength
= (vb_dwords
* count
+ 1) - 2;
4871 bound
= dynamic_bound
;
4873 const int i
= u_bit_scan64(&bound
);
4874 memcpy(map
, genx
->vertex_buffers
[i
].state
,
4875 sizeof(uint32_t) * vb_dwords
);
4881 if (dirty
& IRIS_DIRTY_VERTEX_ELEMENTS
) {
4882 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
4883 const unsigned entries
= MAX2(cso
->count
, 1);
4884 if (!(ice
->state
.vs_needs_sgvs_element
||
4885 ice
->state
.vs_uses_derived_draw_params
||
4886 ice
->state
.vs_needs_edge_flag
)) {
4887 iris_batch_emit(batch
, cso
->vertex_elements
, sizeof(uint32_t) *
4888 (1 + entries
* GENX(VERTEX_ELEMENT_STATE_length
)));
4890 uint32_t dynamic_ves
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
4891 const unsigned dyn_count
= cso
->count
+
4892 ice
->state
.vs_needs_sgvs_element
+
4893 ice
->state
.vs_uses_derived_draw_params
;
4895 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
),
4898 1 + GENX(VERTEX_ELEMENT_STATE_length
) * dyn_count
- 2;
4900 memcpy(&dynamic_ves
[1], &cso
->vertex_elements
[1],
4901 (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
4902 GENX(VERTEX_ELEMENT_STATE_length
) * sizeof(uint32_t));
4903 uint32_t *ve_pack_dest
=
4904 &dynamic_ves
[1 + (cso
->count
- ice
->state
.vs_needs_edge_flag
) *
4905 GENX(VERTEX_ELEMENT_STATE_length
)];
4907 if (ice
->state
.vs_needs_sgvs_element
) {
4908 uint32_t base_ctrl
= ice
->state
.vs_uses_draw_params
?
4909 VFCOMP_STORE_SRC
: VFCOMP_STORE_0
;
4910 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
4912 ve
.VertexBufferIndex
=
4913 util_bitcount64(ice
->state
.bound_vertex_buffers
);
4914 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
4915 ve
.Component0Control
= base_ctrl
;
4916 ve
.Component1Control
= base_ctrl
;
4917 ve
.Component2Control
= VFCOMP_STORE_0
;
4918 ve
.Component3Control
= VFCOMP_STORE_0
;
4920 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
4922 if (ice
->state
.vs_uses_derived_draw_params
) {
4923 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
4925 ve
.VertexBufferIndex
=
4926 util_bitcount64(ice
->state
.bound_vertex_buffers
) +
4927 ice
->state
.vs_uses_draw_params
;
4928 ve
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
4929 ve
.Component0Control
= VFCOMP_STORE_SRC
;
4930 ve
.Component1Control
= VFCOMP_STORE_SRC
;
4931 ve
.Component2Control
= VFCOMP_STORE_0
;
4932 ve
.Component3Control
= VFCOMP_STORE_0
;
4934 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
4936 if (ice
->state
.vs_needs_edge_flag
) {
4937 for (int i
= 0; i
< GENX(VERTEX_ELEMENT_STATE_length
); i
++)
4938 ve_pack_dest
[i
] = cso
->edgeflag_ve
[i
];
4941 iris_batch_emit(batch
, &dynamic_ves
, sizeof(uint32_t) *
4942 (1 + dyn_count
* GENX(VERTEX_ELEMENT_STATE_length
)));
4945 if (!ice
->state
.vs_needs_edge_flag
) {
4946 iris_batch_emit(batch
, cso
->vf_instancing
, sizeof(uint32_t) *
4947 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
4949 assert(cso
->count
> 0);
4950 const unsigned edgeflag_index
= cso
->count
- 1;
4951 uint32_t dynamic_vfi
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
4952 memcpy(&dynamic_vfi
[0], cso
->vf_instancing
, edgeflag_index
*
4953 GENX(3DSTATE_VF_INSTANCING_length
) * sizeof(uint32_t));
4955 uint32_t *vfi_pack_dest
= &dynamic_vfi
[0] +
4956 edgeflag_index
* GENX(3DSTATE_VF_INSTANCING_length
);
4957 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
4958 vi
.VertexElementIndex
= edgeflag_index
+
4959 ice
->state
.vs_needs_sgvs_element
+
4960 ice
->state
.vs_uses_derived_draw_params
;
4962 for (int i
= 0; i
< GENX(3DSTATE_VF_INSTANCING_length
); i
++)
4963 vfi_pack_dest
[i
] |= cso
->edgeflag_vfi
[i
];
4965 iris_batch_emit(batch
, &dynamic_vfi
[0], sizeof(uint32_t) *
4966 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
4970 if (dirty
& IRIS_DIRTY_VF_SGVS
) {
4971 const struct brw_vs_prog_data
*vs_prog_data
= (void *)
4972 ice
->shaders
.prog
[MESA_SHADER_VERTEX
]->prog_data
;
4973 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
4975 iris_emit_cmd(batch
, GENX(3DSTATE_VF_SGVS
), sgv
) {
4976 if (vs_prog_data
->uses_vertexid
) {
4977 sgv
.VertexIDEnable
= true;
4978 sgv
.VertexIDComponentNumber
= 2;
4979 sgv
.VertexIDElementOffset
=
4980 cso
->count
- ice
->state
.vs_needs_edge_flag
;
4983 if (vs_prog_data
->uses_instanceid
) {
4984 sgv
.InstanceIDEnable
= true;
4985 sgv
.InstanceIDComponentNumber
= 3;
4986 sgv
.InstanceIDElementOffset
=
4987 cso
->count
- ice
->state
.vs_needs_edge_flag
;
4992 if (dirty
& IRIS_DIRTY_VF
) {
4993 iris_emit_cmd(batch
, GENX(3DSTATE_VF
), vf
) {
4994 if (draw
->primitive_restart
) {
4995 vf
.IndexedDrawCutIndexEnable
= true;
4996 vf
.CutIndex
= draw
->restart_index
;
5001 /* TODO: Gen8 PMA fix */
5005 iris_upload_render_state(struct iris_context
*ice
,
5006 struct iris_batch
*batch
,
5007 const struct pipe_draw_info
*draw
)
5009 /* Always pin the binder. If we're emitting new binding table pointers,
5010 * we need it. If not, we're probably inheriting old tables via the
5011 * context, and need it anyway. Since true zero-bindings cases are
5012 * practically non-existent, just pin it and avoid last_res tracking.
5014 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
5016 if (!batch
->contains_draw
) {
5017 iris_restore_render_saved_bos(ice
, batch
, draw
);
5018 batch
->contains_draw
= true;
5021 iris_upload_dirty_render_state(ice
, batch
, draw
);
5023 if (draw
->index_size
> 0) {
5026 if (draw
->has_user_indices
) {
5027 u_upload_data(ice
->ctx
.stream_uploader
, 0,
5028 draw
->count
* draw
->index_size
, 4, draw
->index
.user
,
5029 &offset
, &ice
->state
.last_res
.index_buffer
);
5031 struct iris_resource
*res
= (void *) draw
->index
.resource
;
5032 res
->bind_history
|= PIPE_BIND_INDEX_BUFFER
;
5034 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
,
5035 draw
->index
.resource
);
5039 struct iris_bo
*bo
= iris_resource_bo(ice
->state
.last_res
.index_buffer
);
5041 iris_emit_cmd(batch
, GENX(3DSTATE_INDEX_BUFFER
), ib
) {
5042 ib
.IndexFormat
= draw
->index_size
>> 1;
5044 ib
.BufferSize
= bo
->size
- offset
;
5045 ib
.BufferStartingAddress
= ro_bo(bo
, offset
);
5048 /* The VF cache key only uses 32-bits, see vertex buffer comment above */
5049 uint16_t high_bits
= bo
->gtt_offset
>> 32ull;
5050 if (high_bits
!= ice
->state
.last_index_bo_high_bits
) {
5051 iris_emit_pipe_control_flush(batch
, PIPE_CONTROL_VF_CACHE_INVALIDATE
|
5052 PIPE_CONTROL_CS_STALL
);
5053 ice
->state
.last_index_bo_high_bits
= high_bits
;
5057 #define _3DPRIM_END_OFFSET 0x2420
5058 #define _3DPRIM_START_VERTEX 0x2430
5059 #define _3DPRIM_VERTEX_COUNT 0x2434
5060 #define _3DPRIM_INSTANCE_COUNT 0x2438
5061 #define _3DPRIM_START_INSTANCE 0x243C
5062 #define _3DPRIM_BASE_VERTEX 0x2440
5064 if (draw
->indirect
) {
5065 /* We don't support this MultidrawIndirect. */
5066 assert(!draw
->indirect
->indirect_draw_count
);
5068 struct iris_bo
*bo
= iris_resource_bo(draw
->indirect
->buffer
);
5071 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5072 lrm
.RegisterAddress
= _3DPRIM_VERTEX_COUNT
;
5073 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 0);
5075 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5076 lrm
.RegisterAddress
= _3DPRIM_INSTANCE_COUNT
;
5077 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 4);
5079 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5080 lrm
.RegisterAddress
= _3DPRIM_START_VERTEX
;
5081 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 8);
5083 if (draw
->index_size
) {
5084 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5085 lrm
.RegisterAddress
= _3DPRIM_BASE_VERTEX
;
5086 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
5088 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5089 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
5090 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 16);
5093 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5094 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
5095 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
5097 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
5098 lri
.RegisterOffset
= _3DPRIM_BASE_VERTEX
;
5102 } else if (draw
->count_from_stream_output
) {
5103 struct iris_stream_output_target
*so
=
5104 (void *) draw
->count_from_stream_output
;
5106 /* XXX: Replace with actual cache tracking */
5107 iris_emit_pipe_control_flush(batch
, PIPE_CONTROL_CS_STALL
);
5109 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5110 lrm
.RegisterAddress
= CS_GPR(0);
5112 ro_bo(iris_resource_bo(so
->offset
.res
), so
->offset
.offset
);
5114 iris_math_div32_gpr0(ice
, batch
, so
->stride
);
5115 _iris_emit_lrr(batch
, _3DPRIM_VERTEX_COUNT
, CS_GPR(0));
5117 _iris_emit_lri(batch
, _3DPRIM_START_VERTEX
, 0);
5118 _iris_emit_lri(batch
, _3DPRIM_BASE_VERTEX
, 0);
5119 _iris_emit_lri(batch
, _3DPRIM_START_INSTANCE
, 0);
5120 _iris_emit_lri(batch
, _3DPRIM_INSTANCE_COUNT
, draw
->instance_count
);
5123 iris_emit_cmd(batch
, GENX(3DPRIMITIVE
), prim
) {
5124 prim
.VertexAccessType
= draw
->index_size
> 0 ? RANDOM
: SEQUENTIAL
;
5125 prim
.PredicateEnable
=
5126 ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
;
5128 if (draw
->indirect
|| draw
->count_from_stream_output
) {
5129 prim
.IndirectParameterEnable
= true;
5131 prim
.StartInstanceLocation
= draw
->start_instance
;
5132 prim
.InstanceCount
= draw
->instance_count
;
5133 prim
.VertexCountPerInstance
= draw
->count
;
5135 // XXX: this is probably bonkers.
5136 prim
.StartVertexLocation
= draw
->start
;
5138 if (draw
->index_size
) {
5139 prim
.BaseVertexLocation
+= draw
->index_bias
;
5141 prim
.StartVertexLocation
+= draw
->index_bias
;
5144 //prim.BaseVertexLocation = ...;
5150 iris_upload_compute_state(struct iris_context
*ice
,
5151 struct iris_batch
*batch
,
5152 const struct pipe_grid_info
*grid
)
5154 const uint64_t dirty
= ice
->state
.dirty
;
5155 struct iris_screen
*screen
= batch
->screen
;
5156 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
5157 struct iris_binder
*binder
= &ice
->state
.binder
;
5158 struct iris_shader_state
*shs
= &ice
->state
.shaders
[MESA_SHADER_COMPUTE
];
5159 struct iris_compiled_shader
*shader
=
5160 ice
->shaders
.prog
[MESA_SHADER_COMPUTE
];
5161 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
5162 struct brw_cs_prog_data
*cs_prog_data
= (void *) prog_data
;
5164 /* Always pin the binder. If we're emitting new binding table pointers,
5165 * we need it. If not, we're probably inheriting old tables via the
5166 * context, and need it anyway. Since true zero-bindings cases are
5167 * practically non-existent, just pin it and avoid last_res tracking.
5169 iris_use_pinned_bo(batch
, ice
->state
.binder
.bo
, false);
5171 if ((dirty
& IRIS_DIRTY_CONSTANTS_CS
) && shs
->cbuf0_needs_upload
)
5172 upload_uniforms(ice
, MESA_SHADER_COMPUTE
);
5174 if (dirty
& IRIS_DIRTY_BINDINGS_CS
)
5175 iris_populate_binding_table(ice
, batch
, MESA_SHADER_COMPUTE
, false);
5177 if (dirty
& IRIS_DIRTY_SAMPLER_STATES_CS
)
5178 iris_upload_sampler_states(ice
, MESA_SHADER_COMPUTE
);
5180 iris_use_optional_res(batch
, shs
->sampler_table
.res
, false);
5181 iris_use_pinned_bo(batch
, iris_resource_bo(shader
->assembly
.res
), false);
5183 if (ice
->state
.need_border_colors
)
5184 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
5186 if (dirty
& IRIS_DIRTY_CS
) {
5187 /* The MEDIA_VFE_STATE documentation for Gen8+ says:
5189 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
5190 * the only bits that are changed are scoreboard related: Scoreboard
5191 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard Delta. For
5192 * these scoreboard related states, a MEDIA_STATE_FLUSH is
5195 iris_emit_pipe_control_flush(batch
, PIPE_CONTROL_CS_STALL
);
5197 iris_emit_cmd(batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
5198 if (prog_data
->total_scratch
) {
5199 struct iris_bo
*bo
=
5200 iris_get_scratch_space(ice
, prog_data
->total_scratch
,
5201 MESA_SHADER_COMPUTE
);
5202 vfe
.PerThreadScratchSpace
= ffs(prog_data
->total_scratch
) - 11;
5203 vfe
.ScratchSpaceBasePointer
= rw_bo(bo
, 0);
5206 vfe
.MaximumNumberofThreads
=
5207 devinfo
->max_cs_threads
* screen
->subslice_total
- 1;
5209 vfe
.ResetGatewayTimer
=
5210 Resettingrelativetimerandlatchingtheglobaltimestamp
;
5213 vfe
.BypassGatewayControl
= true;
5215 vfe
.NumberofURBEntries
= 2;
5216 vfe
.URBEntryAllocationSize
= 2;
5218 vfe
.CURBEAllocationSize
=
5219 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
5220 cs_prog_data
->push
.cross_thread
.regs
, 2);
5224 /* TODO: Combine subgroup-id with cbuf0 so we can push regular uniforms */
5225 uint32_t curbe_data_offset
= 0;
5226 assert(cs_prog_data
->push
.cross_thread
.dwords
== 0 &&
5227 cs_prog_data
->push
.per_thread
.dwords
== 1 &&
5228 cs_prog_data
->base
.param
[0] == BRW_PARAM_BUILTIN_SUBGROUP_ID
);
5229 struct pipe_resource
*curbe_data_res
= NULL
;
5230 uint32_t *curbe_data_map
=
5231 stream_state(batch
, ice
->state
.dynamic_uploader
, &curbe_data_res
,
5232 ALIGN(cs_prog_data
->push
.total
.size
, 64), 64,
5233 &curbe_data_offset
);
5234 assert(curbe_data_map
);
5235 memset(curbe_data_map
, 0x5a, ALIGN(cs_prog_data
->push
.total
.size
, 64));
5236 iris_fill_cs_push_const_buffer(cs_prog_data
, curbe_data_map
);
5238 if (dirty
& IRIS_DIRTY_CONSTANTS_CS
) {
5239 iris_emit_cmd(batch
, GENX(MEDIA_CURBE_LOAD
), curbe
) {
5240 curbe
.CURBETotalDataLength
=
5241 ALIGN(cs_prog_data
->push
.total
.size
, 64);
5242 curbe
.CURBEDataStartAddress
= curbe_data_offset
;
5246 if (dirty
& (IRIS_DIRTY_SAMPLER_STATES_CS
|
5247 IRIS_DIRTY_BINDINGS_CS
|
5248 IRIS_DIRTY_CONSTANTS_CS
|
5250 struct pipe_resource
*desc_res
= NULL
;
5251 uint32_t desc
[GENX(INTERFACE_DESCRIPTOR_DATA_length
)];
5253 iris_pack_state(GENX(INTERFACE_DESCRIPTOR_DATA
), desc
, idd
) {
5254 idd
.SamplerStatePointer
= shs
->sampler_table
.offset
;
5255 idd
.BindingTablePointer
= binder
->bt_offset
[MESA_SHADER_COMPUTE
];
5258 for (int i
= 0; i
< GENX(INTERFACE_DESCRIPTOR_DATA_length
); i
++)
5259 desc
[i
] |= ((uint32_t *) shader
->derived_data
)[i
];
5261 iris_emit_cmd(batch
, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD
), load
) {
5262 load
.InterfaceDescriptorTotalLength
=
5263 GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t);
5264 load
.InterfaceDescriptorDataStartAddress
=
5265 emit_state(batch
, ice
->state
.dynamic_uploader
,
5266 &desc_res
, desc
, sizeof(desc
), 32);
5269 pipe_resource_reference(&desc_res
, NULL
);
5272 uint32_t group_size
= grid
->block
[0] * grid
->block
[1] * grid
->block
[2];
5273 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
5274 uint32_t right_mask
;
5277 right_mask
= ~0u >> (32 - remainder
);
5279 right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
5281 #define GPGPU_DISPATCHDIMX 0x2500
5282 #define GPGPU_DISPATCHDIMY 0x2504
5283 #define GPGPU_DISPATCHDIMZ 0x2508
5285 if (grid
->indirect
) {
5286 struct iris_state_ref
*grid_size
= &ice
->state
.grid_size
;
5287 struct iris_bo
*bo
= iris_resource_bo(grid_size
->res
);
5288 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5289 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMX
;
5290 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 0);
5292 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5293 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMY
;
5294 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 4);
5296 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5297 lrm
.RegisterAddress
= GPGPU_DISPATCHDIMZ
;
5298 lrm
.MemoryAddress
= ro_bo(bo
, grid_size
->offset
+ 8);
5302 iris_emit_cmd(batch
, GENX(GPGPU_WALKER
), ggw
) {
5303 ggw
.IndirectParameterEnable
= grid
->indirect
!= NULL
;
5304 ggw
.SIMDSize
= cs_prog_data
->simd_size
/ 16;
5305 ggw
.ThreadDepthCounterMaximum
= 0;
5306 ggw
.ThreadHeightCounterMaximum
= 0;
5307 ggw
.ThreadWidthCounterMaximum
= cs_prog_data
->threads
- 1;
5308 ggw
.ThreadGroupIDXDimension
= grid
->grid
[0];
5309 ggw
.ThreadGroupIDYDimension
= grid
->grid
[1];
5310 ggw
.ThreadGroupIDZDimension
= grid
->grid
[2];
5311 ggw
.RightExecutionMask
= right_mask
;
5312 ggw
.BottomExecutionMask
= 0xffffffff;
5315 iris_emit_cmd(batch
, GENX(MEDIA_STATE_FLUSH
), msf
);
5317 if (!batch
->contains_draw
) {
5318 iris_restore_compute_saved_bos(ice
, batch
, grid
);
5319 batch
->contains_draw
= true;
5324 * State module teardown.
5327 iris_destroy_state(struct iris_context
*ice
)
5329 struct iris_genx_state
*genx
= ice
->state
.genx
;
5331 uint64_t bound_vbs
= ice
->state
.bound_vertex_buffers
;
5333 const int i
= u_bit_scan64(&bound_vbs
);
5334 pipe_resource_reference(&genx
->vertex_buffers
[i
].resource
, NULL
);
5336 free(ice
->state
.genx
);
5338 for (unsigned i
= 0; i
< ice
->state
.framebuffer
.nr_cbufs
; i
++) {
5339 pipe_surface_reference(&ice
->state
.framebuffer
.cbufs
[i
], NULL
);
5341 pipe_surface_reference(&ice
->state
.framebuffer
.zsbuf
, NULL
);
5343 for (int stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
5344 struct iris_shader_state
*shs
= &ice
->state
.shaders
[stage
];
5345 pipe_resource_reference(&shs
->sampler_table
.res
, NULL
);
5346 for (int i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
5347 pipe_resource_reference(&shs
->constbuf
[i
].data
.res
, NULL
);
5348 pipe_resource_reference(&shs
->constbuf
[i
].surface_state
.res
, NULL
);
5350 for (int i
= 0; i
< PIPE_MAX_SHADER_IMAGES
; i
++) {
5351 pipe_resource_reference(&shs
->image
[i
].res
, NULL
);
5352 pipe_resource_reference(&shs
->image
[i
].surface_state
.res
, NULL
);
5354 for (int i
= 0; i
< PIPE_MAX_SHADER_BUFFERS
; i
++) {
5355 pipe_resource_reference(&shs
->ssbo
[i
], NULL
);
5356 pipe_resource_reference(&shs
->ssbo_surface_state
[i
].res
, NULL
);
5358 for (int i
= 0; i
< IRIS_MAX_TEXTURE_SAMPLERS
; i
++) {
5359 pipe_sampler_view_reference((struct pipe_sampler_view
**)
5360 &shs
->textures
[i
], NULL
);
5364 pipe_resource_reference(&ice
->state
.grid_size
.res
, NULL
);
5365 pipe_resource_reference(&ice
->state
.grid_surf_state
.res
, NULL
);
5367 pipe_resource_reference(&ice
->state
.null_fb
.res
, NULL
);
5368 pipe_resource_reference(&ice
->state
.unbound_tex
.res
, NULL
);
5370 pipe_resource_reference(&ice
->state
.last_res
.cc_vp
, NULL
);
5371 pipe_resource_reference(&ice
->state
.last_res
.sf_cl_vp
, NULL
);
5372 pipe_resource_reference(&ice
->state
.last_res
.color_calc
, NULL
);
5373 pipe_resource_reference(&ice
->state
.last_res
.scissor
, NULL
);
5374 pipe_resource_reference(&ice
->state
.last_res
.blend
, NULL
);
5375 pipe_resource_reference(&ice
->state
.last_res
.index_buffer
, NULL
);
5378 /* ------------------------------------------------------------------- */
5381 iris_load_register_reg32(struct iris_batch
*batch
, uint32_t dst
,
5384 _iris_emit_lrr(batch
, dst
, src
);
5388 iris_load_register_reg64(struct iris_batch
*batch
, uint32_t dst
,
5391 _iris_emit_lrr(batch
, dst
, src
);
5392 _iris_emit_lrr(batch
, dst
+ 4, src
+ 4);
5396 iris_load_register_imm32(struct iris_batch
*batch
, uint32_t reg
,
5399 _iris_emit_lri(batch
, reg
, val
);
5403 iris_load_register_imm64(struct iris_batch
*batch
, uint32_t reg
,
5406 _iris_emit_lri(batch
, reg
+ 0, val
& 0xffffffff);
5407 _iris_emit_lri(batch
, reg
+ 4, val
>> 32);
5411 * Emit MI_LOAD_REGISTER_MEM to load a 32-bit MMIO register from a buffer.
5414 iris_load_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
5415 struct iris_bo
*bo
, uint32_t offset
)
5417 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
5418 lrm
.RegisterAddress
= reg
;
5419 lrm
.MemoryAddress
= ro_bo(bo
, offset
);
5424 * Load a 64-bit value from a buffer into a MMIO register via
5425 * two MI_LOAD_REGISTER_MEM commands.
5428 iris_load_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
5429 struct iris_bo
*bo
, uint32_t offset
)
5431 iris_load_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0);
5432 iris_load_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4);
5436 iris_store_register_mem32(struct iris_batch
*batch
, uint32_t reg
,
5437 struct iris_bo
*bo
, uint32_t offset
,
5440 iris_emit_cmd(batch
, GENX(MI_STORE_REGISTER_MEM
), srm
) {
5441 srm
.RegisterAddress
= reg
;
5442 srm
.MemoryAddress
= rw_bo(bo
, offset
);
5443 srm
.PredicateEnable
= predicated
;
5448 iris_store_register_mem64(struct iris_batch
*batch
, uint32_t reg
,
5449 struct iris_bo
*bo
, uint32_t offset
,
5452 iris_store_register_mem32(batch
, reg
+ 0, bo
, offset
+ 0, predicated
);
5453 iris_store_register_mem32(batch
, reg
+ 4, bo
, offset
+ 4, predicated
);
5457 iris_store_data_imm32(struct iris_batch
*batch
,
5458 struct iris_bo
*bo
, uint32_t offset
,
5461 iris_emit_cmd(batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
5462 sdi
.Address
= rw_bo(bo
, offset
);
5463 sdi
.ImmediateData
= imm
;
5468 iris_store_data_imm64(struct iris_batch
*batch
,
5469 struct iris_bo
*bo
, uint32_t offset
,
5472 /* Can't use iris_emit_cmd because MI_STORE_DATA_IMM has a length of
5473 * 2 in genxml but it's actually variable length and we need 5 DWords.
5475 void *map
= iris_get_command_space(batch
, 4 * 5);
5476 _iris_pack_command(batch
, GENX(MI_STORE_DATA_IMM
), map
, sdi
) {
5477 sdi
.DWordLength
= 5 - 2;
5478 sdi
.Address
= rw_bo(bo
, offset
);
5479 sdi
.ImmediateData
= imm
;
5484 iris_copy_mem_mem(struct iris_batch
*batch
,
5485 struct iris_bo
*dst_bo
, uint32_t dst_offset
,
5486 struct iris_bo
*src_bo
, uint32_t src_offset
,
5489 /* MI_COPY_MEM_MEM operates on DWords. */
5490 assert(bytes
% 4 == 0);
5491 assert(dst_offset
% 4 == 0);
5492 assert(src_offset
% 4 == 0);
5494 for (unsigned i
= 0; i
< bytes
; i
+= 4) {
5495 iris_emit_cmd(batch
, GENX(MI_COPY_MEM_MEM
), cp
) {
5496 cp
.DestinationMemoryAddress
= rw_bo(dst_bo
, dst_offset
+ i
);
5497 cp
.SourceMemoryAddress
= ro_bo(src_bo
, src_offset
+ i
);
5502 /* ------------------------------------------------------------------- */
5505 flags_to_post_sync_op(uint32_t flags
)
5507 if (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
)
5508 return WriteImmediateData
;
5510 if (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
)
5511 return WritePSDepthCount
;
5513 if (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
)
5514 return WriteTimestamp
;
5520 * Do the given flags have a Post Sync or LRI Post Sync operation?
5522 static enum pipe_control_flags
5523 get_post_sync_flags(enum pipe_control_flags flags
)
5525 flags
&= PIPE_CONTROL_WRITE_IMMEDIATE
|
5526 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
5527 PIPE_CONTROL_WRITE_TIMESTAMP
|
5528 PIPE_CONTROL_LRI_POST_SYNC_OP
;
5530 /* Only one "Post Sync Op" is allowed, and it's mutually exclusive with
5531 * "LRI Post Sync Operation". So more than one bit set would be illegal.
5533 assert(util_bitcount(flags
) <= 1);
5538 #define IS_COMPUTE_PIPELINE(batch) (batch->name == IRIS_BATCH_COMPUTE)
5541 * Emit a series of PIPE_CONTROL commands, taking into account any
5542 * workarounds necessary to actually accomplish the caller's request.
5544 * Unless otherwise noted, spec quotations in this function come from:
5546 * Synchronization of the 3D Pipeline > PIPE_CONTROL Command > Programming
5547 * Restrictions for PIPE_CONTROL.
5549 * You should not use this function directly. Use the helpers in
5550 * iris_pipe_control.c instead, which may split the pipe control further.
5553 iris_emit_raw_pipe_control(struct iris_batch
*batch
, uint32_t flags
,
5554 struct iris_bo
*bo
, uint32_t offset
, uint64_t imm
)
5556 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
5557 enum pipe_control_flags post_sync_flags
= get_post_sync_flags(flags
);
5558 enum pipe_control_flags non_lri_post_sync_flags
=
5559 post_sync_flags
& ~PIPE_CONTROL_LRI_POST_SYNC_OP
;
5561 /* Recursive PIPE_CONTROL workarounds --------------------------------
5562 * (http://knowyourmeme.com/memes/xzibit-yo-dawg)
5564 * We do these first because we want to look at the original operation,
5565 * rather than any workarounds we set.
5567 if (GEN_GEN
== 9 && (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
)) {
5568 /* The PIPE_CONTROL "VF Cache Invalidation Enable" bit description
5569 * lists several workarounds:
5571 * "Project: SKL, KBL, BXT
5573 * If the VF Cache Invalidation Enable is set to a 1 in a
5574 * PIPE_CONTROL, a separate Null PIPE_CONTROL, all bitfields
5575 * sets to 0, with the VF Cache Invalidation Enable set to 0
5576 * needs to be sent prior to the PIPE_CONTROL with VF Cache
5577 * Invalidation Enable set to a 1."
5579 iris_emit_raw_pipe_control(batch
, 0, NULL
, 0, 0);
5582 if (GEN_GEN
== 9 && IS_COMPUTE_PIPELINE(batch
) && post_sync_flags
) {
5583 /* Project: SKL / Argument: LRI Post Sync Operation [23]
5585 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
5586 * programmed prior to programming a PIPECONTROL command with "LRI
5587 * Post Sync Operation" in GPGPU mode of operation (i.e when
5588 * PIPELINE_SELECT command is set to GPGPU mode of operation)."
5590 * The same text exists a few rows below for Post Sync Op.
5592 iris_emit_raw_pipe_control(batch
, PIPE_CONTROL_CS_STALL
, bo
, offset
, imm
);
5595 if (GEN_GEN
== 10 && (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
)) {
5597 * "Before sending a PIPE_CONTROL command with bit 12 set, SW must issue
5598 * another PIPE_CONTROL with Render Target Cache Flush Enable (bit 12)
5599 * = 0 and Pipe Control Flush Enable (bit 7) = 1"
5601 iris_emit_raw_pipe_control(batch
, PIPE_CONTROL_FLUSH_ENABLE
, bo
,
5605 /* "Flush Types" workarounds ---------------------------------------------
5606 * We do these now because they may add post-sync operations or CS stalls.
5609 if (GEN_GEN
< 11 && flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) {
5610 /* Project: BDW, SKL+ (stopping at CNL) / Argument: VF Invalidate
5612 * "'Post Sync Operation' must be enabled to 'Write Immediate Data' or
5613 * 'Write PS Depth Count' or 'Write Timestamp'."
5616 flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
5617 post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
5618 non_lri_post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
5619 bo
= batch
->screen
->workaround_bo
;
5623 /* #1130 from Gen10 workarounds page:
5625 * "Enable Depth Stall on every Post Sync Op if Render target Cache
5626 * Flush is not enabled in same PIPE CONTROL and Enable Pixel score
5627 * board stall if Render target cache flush is enabled."
5629 * Applicable to CNL B0 and C0 steppings only.
5631 * The wording here is unclear, and this workaround doesn't look anything
5632 * like the internal bug report recommendations, but leave it be for now...
5634 if (GEN_GEN
== 10) {
5635 if (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) {
5636 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
5637 } else if (flags
& non_lri_post_sync_flags
) {
5638 flags
|= PIPE_CONTROL_DEPTH_STALL
;
5642 if (flags
& PIPE_CONTROL_DEPTH_STALL
) {
5643 /* From the PIPE_CONTROL instruction table, bit 13 (Depth Stall Enable):
5645 * "This bit must be DISABLED for operations other than writing
5648 * This seems like nonsense. An Ivybridge workaround requires us to
5649 * emit a PIPE_CONTROL with a depth stall and write immediate post-sync
5650 * operation. Gen8+ requires us to emit depth stalls and depth cache
5651 * flushes together. So, it's hard to imagine this means anything other
5652 * than "we originally intended this to be used for PS_DEPTH_COUNT".
5654 * We ignore the supposed restriction and do nothing.
5658 if (flags
& (PIPE_CONTROL_RENDER_TARGET_FLUSH
|
5659 PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
5660 /* From the PIPE_CONTROL instruction table, bit 12 and bit 1:
5662 * "This bit must be DISABLED for End-of-pipe (Read) fences,
5663 * PS_DEPTH_COUNT or TIMESTAMP queries."
5665 * TODO: Implement end-of-pipe checking.
5667 assert(!(post_sync_flags
& (PIPE_CONTROL_WRITE_DEPTH_COUNT
|
5668 PIPE_CONTROL_WRITE_TIMESTAMP
)));
5671 if (GEN_GEN
< 11 && (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
5672 /* From the PIPE_CONTROL instruction table, bit 1:
5674 * "This bit is ignored if Depth Stall Enable is set.
5675 * Further, the render cache is not flushed even if Write Cache
5676 * Flush Enable bit is set."
5678 * We assert that the caller doesn't do this combination, to try and
5679 * prevent mistakes. It shouldn't hurt the GPU, though.
5681 * We skip this check on Gen11+ as the "Stall at Pixel Scoreboard"
5682 * and "Render Target Flush" combo is explicitly required for BTI
5683 * update workarounds.
5685 assert(!(flags
& (PIPE_CONTROL_DEPTH_STALL
|
5686 PIPE_CONTROL_RENDER_TARGET_FLUSH
)));
5689 /* PIPE_CONTROL page workarounds ------------------------------------- */
5691 if (GEN_GEN
<= 8 && (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
)) {
5692 /* From the PIPE_CONTROL page itself:
5695 * Restriction: Pipe_control with CS-stall bit set must be issued
5696 * before a pipe-control command that has the State Cache
5697 * Invalidate bit set."
5699 flags
|= PIPE_CONTROL_CS_STALL
;
5702 if (flags
& PIPE_CONTROL_FLUSH_LLC
) {
5703 /* From the PIPE_CONTROL instruction table, bit 26 (Flush LLC):
5706 * SW must always program Post-Sync Operation to "Write Immediate
5707 * Data" when Flush LLC is set."
5709 * For now, we just require the caller to do it.
5711 assert(flags
& PIPE_CONTROL_WRITE_IMMEDIATE
);
5714 /* "Post-Sync Operation" workarounds -------------------------------- */
5716 /* Project: All / Argument: Global Snapshot Count Reset [19]
5718 * "This bit must not be exercised on any product.
5719 * Requires stall bit ([20] of DW1) set."
5721 * We don't use this, so we just assert that it isn't used. The
5722 * PIPE_CONTROL instruction page indicates that they intended this
5723 * as a debug feature and don't think it is useful in production,
5724 * but it may actually be usable, should we ever want to.
5726 assert((flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) == 0);
5728 if (flags
& (PIPE_CONTROL_MEDIA_STATE_CLEAR
|
5729 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
)) {
5730 /* Project: All / Arguments:
5732 * - Generic Media State Clear [16]
5733 * - Indirect State Pointers Disable [16]
5735 * "Requires stall bit ([20] of DW1) set."
5737 * Also, the PIPE_CONTROL instruction table, bit 16 (Generic Media
5738 * State Clear) says:
5740 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
5741 * programmed prior to programming a PIPECONTROL command with "Media
5742 * State Clear" set in GPGPU mode of operation"
5744 * This is a subset of the earlier rule, so there's nothing to do.
5746 flags
|= PIPE_CONTROL_CS_STALL
;
5749 if (flags
& PIPE_CONTROL_STORE_DATA_INDEX
) {
5750 /* Project: All / Argument: Store Data Index
5752 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
5755 * For now, we just assert that the caller does this. We might want to
5756 * automatically add a write to the workaround BO...
5758 assert(non_lri_post_sync_flags
!= 0);
5761 if (flags
& PIPE_CONTROL_SYNC_GFDT
) {
5762 /* Project: All / Argument: Sync GFDT
5764 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
5765 * than '0' or 0x2520[13] must be set."
5767 * For now, we just assert that the caller does this.
5769 assert(non_lri_post_sync_flags
!= 0);
5772 if (flags
& PIPE_CONTROL_TLB_INVALIDATE
) {
5773 /* Project: IVB+ / Argument: TLB inv
5775 * "Requires stall bit ([20] of DW1) set."
5777 * Also, from the PIPE_CONTROL instruction table:
5780 * Post Sync Operation or CS stall must be set to ensure a TLB
5781 * invalidation occurs. Otherwise no cycle will occur to the TLB
5782 * cache to invalidate."
5784 * This is not a subset of the earlier rule, so there's nothing to do.
5786 flags
|= PIPE_CONTROL_CS_STALL
;
5789 if (GEN_GEN
== 9 && devinfo
->gt
== 4) {
5790 /* TODO: The big Skylake GT4 post sync op workaround */
5793 /* "GPGPU specific workarounds" (both post-sync and flush) ------------ */
5795 if (IS_COMPUTE_PIPELINE(batch
)) {
5796 if (GEN_GEN
>= 9 && (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
)) {
5797 /* Project: SKL+ / Argument: Tex Invalidate
5798 * "Requires stall bit ([20] of DW) set for all GPGPU Workloads."
5800 flags
|= PIPE_CONTROL_CS_STALL
;
5803 if (GEN_GEN
== 8 && (post_sync_flags
||
5804 (flags
& (PIPE_CONTROL_NOTIFY_ENABLE
|
5805 PIPE_CONTROL_DEPTH_STALL
|
5806 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
5807 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
5808 PIPE_CONTROL_DATA_CACHE_FLUSH
)))) {
5809 /* Project: BDW / Arguments:
5811 * - LRI Post Sync Operation [23]
5812 * - Post Sync Op [15:14]
5814 * - Depth Stall [13]
5815 * - Render Target Cache Flush [12]
5816 * - Depth Cache Flush [0]
5817 * - DC Flush Enable [5]
5819 * "Requires stall bit ([20] of DW) set for all GPGPU and Media
5822 flags
|= PIPE_CONTROL_CS_STALL
;
5824 /* Also, from the PIPE_CONTROL instruction table, bit 20:
5827 * This bit must be always set when PIPE_CONTROL command is
5828 * programmed by GPGPU and MEDIA workloads, except for the cases
5829 * when only Read Only Cache Invalidation bits are set (State
5830 * Cache Invalidation Enable, Instruction cache Invalidation
5831 * Enable, Texture Cache Invalidation Enable, Constant Cache
5832 * Invalidation Enable). This is to WA FFDOP CG issue, this WA
5833 * need not implemented when FF_DOP_CG is disable via "Fixed
5834 * Function DOP Clock Gate Disable" bit in RC_PSMI_CTRL register."
5836 * It sounds like we could avoid CS stalls in some cases, but we
5837 * don't currently bother. This list isn't exactly the list above,
5843 /* "Stall" workarounds ----------------------------------------------
5844 * These have to come after the earlier ones because we may have added
5845 * some additional CS stalls above.
5848 if (GEN_GEN
< 9 && (flags
& PIPE_CONTROL_CS_STALL
)) {
5849 /* Project: PRE-SKL, VLV, CHV
5851 * "[All Stepping][All SKUs]:
5853 * One of the following must also be set:
5855 * - Render Target Cache Flush Enable ([12] of DW1)
5856 * - Depth Cache Flush Enable ([0] of DW1)
5857 * - Stall at Pixel Scoreboard ([1] of DW1)
5858 * - Depth Stall ([13] of DW1)
5859 * - Post-Sync Operation ([13] of DW1)
5860 * - DC Flush Enable ([5] of DW1)"
5862 * If we don't already have one of those bits set, we choose to add
5863 * "Stall at Pixel Scoreboard". Some of the other bits require a
5864 * CS stall as a workaround (see above), which would send us into
5865 * an infinite recursion of PIPE_CONTROLs. "Stall at Pixel Scoreboard"
5866 * appears to be safe, so we choose that.
5868 const uint32_t wa_bits
= PIPE_CONTROL_RENDER_TARGET_FLUSH
|
5869 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
5870 PIPE_CONTROL_WRITE_IMMEDIATE
|
5871 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
5872 PIPE_CONTROL_WRITE_TIMESTAMP
|
5873 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
5874 PIPE_CONTROL_DEPTH_STALL
|
5875 PIPE_CONTROL_DATA_CACHE_FLUSH
;
5876 if (!(flags
& wa_bits
))
5877 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
5880 /* Emit --------------------------------------------------------------- */
5882 iris_emit_cmd(batch
, GENX(PIPE_CONTROL
), pc
) {
5883 pc
.LRIPostSyncOperation
= NoLRIOperation
;
5884 pc
.PipeControlFlushEnable
= flags
& PIPE_CONTROL_FLUSH_ENABLE
;
5885 pc
.DCFlushEnable
= flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
;
5886 pc
.StoreDataIndex
= 0;
5887 pc
.CommandStreamerStallEnable
= flags
& PIPE_CONTROL_CS_STALL
;
5888 pc
.GlobalSnapshotCountReset
=
5889 flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
;
5890 pc
.TLBInvalidate
= flags
& PIPE_CONTROL_TLB_INVALIDATE
;
5891 pc
.GenericMediaStateClear
= flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
;
5892 pc
.StallAtPixelScoreboard
= flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
;
5893 pc
.RenderTargetCacheFlushEnable
=
5894 flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
;
5895 pc
.DepthCacheFlushEnable
= flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
;
5896 pc
.StateCacheInvalidationEnable
=
5897 flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
;
5898 pc
.VFCacheInvalidationEnable
= flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
;
5899 pc
.ConstantCacheInvalidationEnable
=
5900 flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
;
5901 pc
.PostSyncOperation
= flags_to_post_sync_op(flags
);
5902 pc
.DepthStallEnable
= flags
& PIPE_CONTROL_DEPTH_STALL
;
5903 pc
.InstructionCacheInvalidateEnable
=
5904 flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
;
5905 pc
.NotifyEnable
= flags
& PIPE_CONTROL_NOTIFY_ENABLE
;
5906 pc
.IndirectStatePointersDisable
=
5907 flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
;
5908 pc
.TextureCacheInvalidationEnable
=
5909 flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
5910 pc
.Address
= rw_bo(bo
, offset
);
5911 pc
.ImmediateData
= imm
;
5916 genX(emit_urb_setup
)(struct iris_context
*ice
,
5917 struct iris_batch
*batch
,
5918 const unsigned size
[4],
5919 bool tess_present
, bool gs_present
)
5921 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
5922 const unsigned push_size_kB
= 32;
5923 unsigned entries
[4];
5926 ice
->shaders
.last_vs_entry_size
= size
[MESA_SHADER_VERTEX
];
5928 gen_get_urb_config(devinfo
, 1024 * push_size_kB
,
5929 1024 * ice
->shaders
.urb_size
,
5930 tess_present
, gs_present
,
5931 size
, entries
, start
);
5933 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
5934 iris_emit_cmd(batch
, GENX(3DSTATE_URB_VS
), urb
) {
5935 urb
._3DCommandSubOpcode
+= i
;
5936 urb
.VSURBStartingAddress
= start
[i
];
5937 urb
.VSURBEntryAllocationSize
= size
[i
] - 1;
5938 urb
.VSNumberofURBEntries
= entries
[i
];
5944 genX(init_state
)(struct iris_context
*ice
)
5946 struct pipe_context
*ctx
= &ice
->ctx
;
5947 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
5949 ctx
->create_blend_state
= iris_create_blend_state
;
5950 ctx
->create_depth_stencil_alpha_state
= iris_create_zsa_state
;
5951 ctx
->create_rasterizer_state
= iris_create_rasterizer_state
;
5952 ctx
->create_sampler_state
= iris_create_sampler_state
;
5953 ctx
->create_sampler_view
= iris_create_sampler_view
;
5954 ctx
->create_surface
= iris_create_surface
;
5955 ctx
->create_vertex_elements_state
= iris_create_vertex_elements
;
5956 ctx
->bind_blend_state
= iris_bind_blend_state
;
5957 ctx
->bind_depth_stencil_alpha_state
= iris_bind_zsa_state
;
5958 ctx
->bind_sampler_states
= iris_bind_sampler_states
;
5959 ctx
->bind_rasterizer_state
= iris_bind_rasterizer_state
;
5960 ctx
->bind_vertex_elements_state
= iris_bind_vertex_elements_state
;
5961 ctx
->delete_blend_state
= iris_delete_state
;
5962 ctx
->delete_depth_stencil_alpha_state
= iris_delete_state
;
5963 ctx
->delete_rasterizer_state
= iris_delete_state
;
5964 ctx
->delete_sampler_state
= iris_delete_state
;
5965 ctx
->delete_vertex_elements_state
= iris_delete_state
;
5966 ctx
->set_blend_color
= iris_set_blend_color
;
5967 ctx
->set_clip_state
= iris_set_clip_state
;
5968 ctx
->set_constant_buffer
= iris_set_constant_buffer
;
5969 ctx
->set_shader_buffers
= iris_set_shader_buffers
;
5970 ctx
->set_shader_images
= iris_set_shader_images
;
5971 ctx
->set_sampler_views
= iris_set_sampler_views
;
5972 ctx
->set_tess_state
= iris_set_tess_state
;
5973 ctx
->set_framebuffer_state
= iris_set_framebuffer_state
;
5974 ctx
->set_polygon_stipple
= iris_set_polygon_stipple
;
5975 ctx
->set_sample_mask
= iris_set_sample_mask
;
5976 ctx
->set_scissor_states
= iris_set_scissor_states
;
5977 ctx
->set_stencil_ref
= iris_set_stencil_ref
;
5978 ctx
->set_vertex_buffers
= iris_set_vertex_buffers
;
5979 ctx
->set_viewport_states
= iris_set_viewport_states
;
5980 ctx
->sampler_view_destroy
= iris_sampler_view_destroy
;
5981 ctx
->surface_destroy
= iris_surface_destroy
;
5982 ctx
->draw_vbo
= iris_draw_vbo
;
5983 ctx
->launch_grid
= iris_launch_grid
;
5984 ctx
->create_stream_output_target
= iris_create_stream_output_target
;
5985 ctx
->stream_output_target_destroy
= iris_stream_output_target_destroy
;
5986 ctx
->set_stream_output_targets
= iris_set_stream_output_targets
;
5988 ice
->vtbl
.destroy_state
= iris_destroy_state
;
5989 ice
->vtbl
.init_render_context
= iris_init_render_context
;
5990 ice
->vtbl
.init_compute_context
= iris_init_compute_context
;
5991 ice
->vtbl
.upload_render_state
= iris_upload_render_state
;
5992 ice
->vtbl
.update_surface_base_address
= iris_update_surface_base_address
;
5993 ice
->vtbl
.upload_compute_state
= iris_upload_compute_state
;
5994 ice
->vtbl
.emit_raw_pipe_control
= iris_emit_raw_pipe_control
;
5995 ice
->vtbl
.load_register_reg32
= iris_load_register_reg32
;
5996 ice
->vtbl
.load_register_reg64
= iris_load_register_reg64
;
5997 ice
->vtbl
.load_register_imm32
= iris_load_register_imm32
;
5998 ice
->vtbl
.load_register_imm64
= iris_load_register_imm64
;
5999 ice
->vtbl
.load_register_mem32
= iris_load_register_mem32
;
6000 ice
->vtbl
.load_register_mem64
= iris_load_register_mem64
;
6001 ice
->vtbl
.store_register_mem32
= iris_store_register_mem32
;
6002 ice
->vtbl
.store_register_mem64
= iris_store_register_mem64
;
6003 ice
->vtbl
.store_data_imm32
= iris_store_data_imm32
;
6004 ice
->vtbl
.store_data_imm64
= iris_store_data_imm64
;
6005 ice
->vtbl
.copy_mem_mem
= iris_copy_mem_mem
;
6006 ice
->vtbl
.derived_program_state_size
= iris_derived_program_state_size
;
6007 ice
->vtbl
.store_derived_program_state
= iris_store_derived_program_state
;
6008 ice
->vtbl
.create_so_decl_list
= iris_create_so_decl_list
;
6009 ice
->vtbl
.populate_vs_key
= iris_populate_vs_key
;
6010 ice
->vtbl
.populate_tcs_key
= iris_populate_tcs_key
;
6011 ice
->vtbl
.populate_tes_key
= iris_populate_tes_key
;
6012 ice
->vtbl
.populate_gs_key
= iris_populate_gs_key
;
6013 ice
->vtbl
.populate_fs_key
= iris_populate_fs_key
;
6014 ice
->vtbl
.populate_cs_key
= iris_populate_cs_key
;
6015 ice
->vtbl
.mocs
= mocs
;
6017 ice
->state
.dirty
= ~0ull;
6019 ice
->state
.statistics_counters_enabled
= true;
6021 ice
->state
.sample_mask
= 0xffff;
6022 ice
->state
.num_viewports
= 1;
6023 ice
->state
.genx
= calloc(1, sizeof(struct iris_genx_state
));
6025 /* Make a 1x1x1 null surface for unbound textures */
6026 void *null_surf_map
=
6027 upload_state(ice
->state
.surface_uploader
, &ice
->state
.unbound_tex
,
6028 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
6029 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
, isl_extent3d(1, 1, 1));
6030 ice
->state
.unbound_tex
.offset
+=
6031 iris_bo_offset_from_base_address(iris_resource_bo(ice
->state
.unbound_tex
.res
));
6033 /* Default all scissor rectangles to be empty regions. */
6034 for (int i
= 0; i
< IRIS_MAX_VIEWPORTS
; i
++) {
6035 ice
->state
.scissors
[i
] = (struct pipe_scissor_state
) {
6036 .minx
= 1, .maxx
= 0, .miny
= 1, .maxy
= 0,