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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
37 #include "pipe/p_defines.h"
38 #include "pipe/p_state.h"
39 #include "pipe/p_context.h"
40 #include "pipe/p_screen.h"
41 #include "util/u_inlines.h"
42 #include "util/u_format.h"
43 #include "util/u_framebuffer.h"
44 #include "util/u_transfer.h"
45 #include "util/u_upload_mgr.h"
46 #include "util/u_viewport.h"
49 #include "intel/compiler/brw_compiler.h"
50 #include "intel/common/gen_l3_config.h"
51 #include "intel/common/gen_sample_positions.h"
52 #include "iris_batch.h"
53 #include "iris_context.h"
54 #include "iris_pipe.h"
55 #include "iris_resource.h"
57 #define __gen_address_type struct iris_address
58 #define __gen_user_data struct iris_batch
60 #define ARRAY_BYTES(x) (sizeof(uint32_t) * ARRAY_SIZE(x))
63 __gen_combine_address(struct iris_batch
*batch
, void *location
,
64 struct iris_address addr
, uint32_t delta
)
66 uint64_t result
= addr
.offset
+ delta
;
69 iris_use_pinned_bo(batch
, addr
.bo
, addr
.write
);
70 /* Assume this is a general address, not relative to a base. */
71 result
+= addr
.bo
->gtt_offset
;
77 #define __genxml_cmd_length(cmd) cmd ## _length
78 #define __genxml_cmd_length_bias(cmd) cmd ## _length_bias
79 #define __genxml_cmd_header(cmd) cmd ## _header
80 #define __genxml_cmd_pack(cmd) cmd ## _pack
82 #define _iris_pack_command(batch, cmd, dst, name) \
83 for (struct cmd name = { __genxml_cmd_header(cmd) }, \
84 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
85 ({ __genxml_cmd_pack(cmd)(batch, (void *)_dst, &name); \
89 #define iris_pack_command(cmd, dst, name) \
90 _iris_pack_command(NULL, cmd, dst, name)
92 #define iris_pack_state(cmd, dst, name) \
93 for (struct cmd name = {}, \
94 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
95 __genxml_cmd_pack(cmd)(NULL, (void *)_dst, &name), \
98 #define iris_emit_cmd(batch, cmd, name) \
99 _iris_pack_command(batch, cmd, iris_get_command_space(batch, 4 * __genxml_cmd_length(cmd)), name)
101 #define iris_emit_merge(batch, dwords0, dwords1, num_dwords) \
103 uint32_t *dw = iris_get_command_space(batch, 4 * num_dwords); \
104 for (uint32_t i = 0; i < num_dwords; i++) \
105 dw[i] = (dwords0)[i] | (dwords1)[i]; \
106 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, num_dwords)); \
109 #include "genxml/genX_pack.h"
110 #include "genxml/gen_macros.h"
111 #include "genxml/genX_bits.h"
113 #define MOCS_WB (2 << 1)
115 UNUSED
static void pipe_asserts()
117 #define PIPE_ASSERT(x) STATIC_ASSERT((int)x)
119 /* pipe_logicop happens to match the hardware. */
120 PIPE_ASSERT(PIPE_LOGICOP_CLEAR
== LOGICOP_CLEAR
);
121 PIPE_ASSERT(PIPE_LOGICOP_NOR
== LOGICOP_NOR
);
122 PIPE_ASSERT(PIPE_LOGICOP_AND_INVERTED
== LOGICOP_AND_INVERTED
);
123 PIPE_ASSERT(PIPE_LOGICOP_COPY_INVERTED
== LOGICOP_COPY_INVERTED
);
124 PIPE_ASSERT(PIPE_LOGICOP_AND_REVERSE
== LOGICOP_AND_REVERSE
);
125 PIPE_ASSERT(PIPE_LOGICOP_INVERT
== LOGICOP_INVERT
);
126 PIPE_ASSERT(PIPE_LOGICOP_XOR
== LOGICOP_XOR
);
127 PIPE_ASSERT(PIPE_LOGICOP_NAND
== LOGICOP_NAND
);
128 PIPE_ASSERT(PIPE_LOGICOP_AND
== LOGICOP_AND
);
129 PIPE_ASSERT(PIPE_LOGICOP_EQUIV
== LOGICOP_EQUIV
);
130 PIPE_ASSERT(PIPE_LOGICOP_NOOP
== LOGICOP_NOOP
);
131 PIPE_ASSERT(PIPE_LOGICOP_OR_INVERTED
== LOGICOP_OR_INVERTED
);
132 PIPE_ASSERT(PIPE_LOGICOP_COPY
== LOGICOP_COPY
);
133 PIPE_ASSERT(PIPE_LOGICOP_OR_REVERSE
== LOGICOP_OR_REVERSE
);
134 PIPE_ASSERT(PIPE_LOGICOP_OR
== LOGICOP_OR
);
135 PIPE_ASSERT(PIPE_LOGICOP_SET
== LOGICOP_SET
);
137 /* pipe_blend_func happens to match the hardware. */
138 PIPE_ASSERT(PIPE_BLENDFACTOR_ONE
== BLENDFACTOR_ONE
);
139 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_COLOR
== BLENDFACTOR_SRC_COLOR
);
140 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA
== BLENDFACTOR_SRC_ALPHA
);
141 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_ALPHA
== BLENDFACTOR_DST_ALPHA
);
142 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_COLOR
== BLENDFACTOR_DST_COLOR
);
143 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
== BLENDFACTOR_SRC_ALPHA_SATURATE
);
144 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_COLOR
== BLENDFACTOR_CONST_COLOR
);
145 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_ALPHA
== BLENDFACTOR_CONST_ALPHA
);
146 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_COLOR
== BLENDFACTOR_SRC1_COLOR
);
147 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_ALPHA
== BLENDFACTOR_SRC1_ALPHA
);
148 PIPE_ASSERT(PIPE_BLENDFACTOR_ZERO
== BLENDFACTOR_ZERO
);
149 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_COLOR
== BLENDFACTOR_INV_SRC_COLOR
);
150 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_ALPHA
== BLENDFACTOR_INV_SRC_ALPHA
);
151 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_ALPHA
== BLENDFACTOR_INV_DST_ALPHA
);
152 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_COLOR
== BLENDFACTOR_INV_DST_COLOR
);
153 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_COLOR
== BLENDFACTOR_INV_CONST_COLOR
);
154 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_ALPHA
== BLENDFACTOR_INV_CONST_ALPHA
);
155 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_COLOR
== BLENDFACTOR_INV_SRC1_COLOR
);
156 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_ALPHA
== BLENDFACTOR_INV_SRC1_ALPHA
);
158 /* pipe_blend_func happens to match the hardware. */
159 PIPE_ASSERT(PIPE_BLEND_ADD
== BLENDFUNCTION_ADD
);
160 PIPE_ASSERT(PIPE_BLEND_SUBTRACT
== BLENDFUNCTION_SUBTRACT
);
161 PIPE_ASSERT(PIPE_BLEND_REVERSE_SUBTRACT
== BLENDFUNCTION_REVERSE_SUBTRACT
);
162 PIPE_ASSERT(PIPE_BLEND_MIN
== BLENDFUNCTION_MIN
);
163 PIPE_ASSERT(PIPE_BLEND_MAX
== BLENDFUNCTION_MAX
);
165 /* pipe_stencil_op happens to match the hardware. */
166 PIPE_ASSERT(PIPE_STENCIL_OP_KEEP
== STENCILOP_KEEP
);
167 PIPE_ASSERT(PIPE_STENCIL_OP_ZERO
== STENCILOP_ZERO
);
168 PIPE_ASSERT(PIPE_STENCIL_OP_REPLACE
== STENCILOP_REPLACE
);
169 PIPE_ASSERT(PIPE_STENCIL_OP_INCR
== STENCILOP_INCRSAT
);
170 PIPE_ASSERT(PIPE_STENCIL_OP_DECR
== STENCILOP_DECRSAT
);
171 PIPE_ASSERT(PIPE_STENCIL_OP_INCR_WRAP
== STENCILOP_INCR
);
172 PIPE_ASSERT(PIPE_STENCIL_OP_DECR_WRAP
== STENCILOP_DECR
);
173 PIPE_ASSERT(PIPE_STENCIL_OP_INVERT
== STENCILOP_INVERT
);
175 /* pipe_sprite_coord_mode happens to match 3DSTATE_SBE */
176 PIPE_ASSERT(PIPE_SPRITE_COORD_UPPER_LEFT
== UPPERLEFT
);
177 PIPE_ASSERT(PIPE_SPRITE_COORD_LOWER_LEFT
== LOWERLEFT
);
182 translate_prim_type(enum pipe_prim_type prim
, uint8_t verts_per_patch
)
184 static const unsigned map
[] = {
185 [PIPE_PRIM_POINTS
] = _3DPRIM_POINTLIST
,
186 [PIPE_PRIM_LINES
] = _3DPRIM_LINELIST
,
187 [PIPE_PRIM_LINE_LOOP
] = _3DPRIM_LINELOOP
,
188 [PIPE_PRIM_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
189 [PIPE_PRIM_TRIANGLES
] = _3DPRIM_TRILIST
,
190 [PIPE_PRIM_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
191 [PIPE_PRIM_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
192 [PIPE_PRIM_QUADS
] = _3DPRIM_QUADLIST
,
193 [PIPE_PRIM_QUAD_STRIP
] = _3DPRIM_QUADSTRIP
,
194 [PIPE_PRIM_POLYGON
] = _3DPRIM_POLYGON
,
195 [PIPE_PRIM_LINES_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
196 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
197 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
198 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
199 [PIPE_PRIM_PATCHES
] = _3DPRIM_PATCHLIST_1
- 1,
202 return map
[prim
] + (prim
== PIPE_PRIM_PATCHES
? verts_per_patch
: 0);
206 translate_compare_func(enum pipe_compare_func pipe_func
)
208 static const unsigned map
[] = {
209 [PIPE_FUNC_NEVER
] = COMPAREFUNCTION_NEVER
,
210 [PIPE_FUNC_LESS
] = COMPAREFUNCTION_LESS
,
211 [PIPE_FUNC_EQUAL
] = COMPAREFUNCTION_EQUAL
,
212 [PIPE_FUNC_LEQUAL
] = COMPAREFUNCTION_LEQUAL
,
213 [PIPE_FUNC_GREATER
] = COMPAREFUNCTION_GREATER
,
214 [PIPE_FUNC_NOTEQUAL
] = COMPAREFUNCTION_NOTEQUAL
,
215 [PIPE_FUNC_GEQUAL
] = COMPAREFUNCTION_GEQUAL
,
216 [PIPE_FUNC_ALWAYS
] = COMPAREFUNCTION_ALWAYS
,
218 return map
[pipe_func
];
222 translate_shadow_func(enum pipe_compare_func pipe_func
)
224 /* Gallium specifies the result of shadow comparisons as:
226 * 1 if ref <op> texel,
231 * 0 if texel <op> ref,
234 * So we need to flip the operator and also negate.
236 static const unsigned map
[] = {
237 [PIPE_FUNC_NEVER
] = PREFILTEROPALWAYS
,
238 [PIPE_FUNC_LESS
] = PREFILTEROPLEQUAL
,
239 [PIPE_FUNC_EQUAL
] = PREFILTEROPNOTEQUAL
,
240 [PIPE_FUNC_LEQUAL
] = PREFILTEROPLESS
,
241 [PIPE_FUNC_GREATER
] = PREFILTEROPGEQUAL
,
242 [PIPE_FUNC_NOTEQUAL
] = PREFILTEROPEQUAL
,
243 [PIPE_FUNC_GEQUAL
] = PREFILTEROPGREATER
,
244 [PIPE_FUNC_ALWAYS
] = PREFILTEROPNEVER
,
246 return map
[pipe_func
];
250 translate_cull_mode(unsigned pipe_face
)
252 static const unsigned map
[4] = {
253 [PIPE_FACE_NONE
] = CULLMODE_NONE
,
254 [PIPE_FACE_FRONT
] = CULLMODE_FRONT
,
255 [PIPE_FACE_BACK
] = CULLMODE_BACK
,
256 [PIPE_FACE_FRONT_AND_BACK
] = CULLMODE_BOTH
,
258 return map
[pipe_face
];
262 translate_fill_mode(unsigned pipe_polymode
)
264 static const unsigned map
[4] = {
265 [PIPE_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
266 [PIPE_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
267 [PIPE_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
268 [PIPE_POLYGON_MODE_FILL_RECTANGLE
] = FILL_MODE_SOLID
,
270 return map
[pipe_polymode
];
273 static struct iris_address
274 ro_bo(struct iris_bo
*bo
, uint64_t offset
)
277 return (struct iris_address
) { .bo
= bo
, .offset
= offset
};
280 static struct iris_address
281 rw_bo(struct iris_bo
*bo
, uint64_t offset
)
284 return (struct iris_address
) { .bo
= bo
, .offset
= offset
, .write
= true };
288 upload_state(struct u_upload_mgr
*uploader
,
289 struct iris_state_ref
*ref
,
294 u_upload_alloc(uploader
, 0, size
, alignment
, &ref
->offset
, &ref
->res
, &p
);
299 stream_state(struct iris_batch
*batch
,
300 struct u_upload_mgr
*uploader
,
301 struct pipe_resource
**out_res
,
304 uint32_t *out_offset
)
308 u_upload_alloc(uploader
, 0, size
, alignment
, out_offset
, out_res
, &ptr
);
310 struct iris_bo
*bo
= iris_resource_bo(*out_res
);
311 iris_use_pinned_bo(batch
, bo
, false);
313 *out_offset
+= iris_bo_offset_from_base_address(bo
);
319 emit_state(struct iris_batch
*batch
,
320 struct u_upload_mgr
*uploader
,
321 struct pipe_resource
**out_res
,
328 stream_state(batch
, uploader
, out_res
, size
, alignment
, &offset
);
331 memcpy(map
, data
, size
);
336 #define cso_changed(x) (!old_cso || (old_cso->x != new_cso->x))
337 #define cso_changed_memcmp(x) \
338 (!old_cso || memcmp(old_cso->x, new_cso->x, sizeof(old_cso->x)) != 0)
341 iris_init_render_context(struct iris_screen
*screen
,
342 struct iris_batch
*batch
,
343 struct iris_vtable
*vtbl
,
344 struct pipe_debug_callback
*dbg
)
346 iris_init_batch(batch
, screen
, vtbl
, dbg
, I915_EXEC_RENDER
);
348 /* XXX: PIPE_CONTROLs */
350 iris_emit_cmd(batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
352 // XXX: MOCS is stupid for this.
353 sba
.GeneralStateMemoryObjectControlState
= MOCS_WB
;
354 sba
.StatelessDataPortAccessMemoryObjectControlState
= MOCS_WB
;
355 sba
.SurfaceStateMemoryObjectControlState
= MOCS_WB
;
356 sba
.DynamicStateMemoryObjectControlState
= MOCS_WB
;
357 sba
.IndirectObjectMemoryObjectControlState
= MOCS_WB
;
358 sba
.InstructionMemoryObjectControlState
= MOCS_WB
;
359 sba
.BindlessSurfaceStateMemoryObjectControlState
= MOCS_WB
;
362 sba
.GeneralStateBaseAddressModifyEnable
= true;
363 sba
.SurfaceStateBaseAddressModifyEnable
= true;
364 sba
.DynamicStateBaseAddressModifyEnable
= true;
365 sba
.IndirectObjectBaseAddressModifyEnable
= true;
366 sba
.InstructionBaseAddressModifyEnable
= true;
367 sba
.GeneralStateBufferSizeModifyEnable
= true;
368 sba
.DynamicStateBufferSizeModifyEnable
= true;
369 sba
.BindlessSurfaceStateBaseAddressModifyEnable
= true;
370 sba
.IndirectObjectBufferSizeModifyEnable
= true;
371 sba
.InstructionBuffersizeModifyEnable
= true;
373 sba
.InstructionBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_SHADER_START
);
374 sba
.SurfaceStateBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_SURFACE_START
);
375 sba
.DynamicStateBaseAddress
= ro_bo(NULL
, IRIS_MEMZONE_DYNAMIC_START
);
377 sba
.GeneralStateBufferSize
= 0xfffff;
378 sba
.IndirectObjectBufferSize
= 0xfffff;
379 sba
.InstructionBufferSize
= 0xfffff;
380 sba
.DynamicStateBufferSize
= 0xfffff;
383 iris_emit_cmd(batch
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
384 rect
.ClippedDrawingRectangleXMax
= UINT16_MAX
;
385 rect
.ClippedDrawingRectangleYMax
= UINT16_MAX
;
387 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_PATTERN
), pat
) {
388 GEN_SAMPLE_POS_1X(pat
._1xSample
);
389 GEN_SAMPLE_POS_2X(pat
._2xSample
);
390 GEN_SAMPLE_POS_4X(pat
._4xSample
);
391 GEN_SAMPLE_POS_8X(pat
._8xSample
);
392 GEN_SAMPLE_POS_16X(pat
._16xSample
);
394 iris_emit_cmd(batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
), foo
);
395 iris_emit_cmd(batch
, GENX(3DSTATE_WM_CHROMAKEY
), foo
);
396 iris_emit_cmd(batch
, GENX(3DSTATE_WM_HZ_OP
), foo
);
397 /* XXX: may need to set an offset for origin-UL framebuffers */
398 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), foo
);
400 /* Just assign a static partitioning. */
401 for (int i
= 0; i
<= MESA_SHADER_FRAGMENT
; i
++) {
402 iris_emit_cmd(batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
), alloc
) {
403 alloc
._3DCommandSubOpcode
= 18 + i
;
404 alloc
.ConstantBufferOffset
= 6 * i
;
405 alloc
.ConstantBufferSize
= i
== MESA_SHADER_FRAGMENT
? 8 : 6;
410 struct iris_vertex_buffer_state
{
411 uint32_t vertex_buffers
[1 + 33 * GENX(VERTEX_BUFFER_STATE_length
)];
412 struct pipe_resource
*resources
[33];
413 unsigned num_buffers
;
416 struct iris_depth_buffer_state
{
417 uint32_t packets
[GENX(3DSTATE_DEPTH_BUFFER_length
) +
418 GENX(3DSTATE_STENCIL_BUFFER_length
) +
419 GENX(3DSTATE_HIER_DEPTH_BUFFER_length
) +
420 GENX(3DSTATE_CLEAR_PARAMS_length
)];
424 * State that can't be stored directly in iris_context because the data
425 * layout varies per generation.
427 struct iris_genx_state
{
428 /** SF_CLIP_VIEWPORT */
429 uint32_t sf_cl_vp
[GENX(SF_CLIP_VIEWPORT_length
) * IRIS_MAX_VIEWPORTS
];
431 struct iris_vertex_buffer_state vertex_buffers
;
432 struct iris_depth_buffer_state depth_buffer
;
434 uint32_t so_buffers
[4 * GENX(3DSTATE_SO_BUFFER_length
)];
435 uint32_t streamout
[4 * GENX(3DSTATE_STREAMOUT_length
)];
439 iris_launch_grid(struct pipe_context
*ctx
, const struct pipe_grid_info
*info
)
444 iris_set_blend_color(struct pipe_context
*ctx
,
445 const struct pipe_blend_color
*state
)
447 struct iris_context
*ice
= (struct iris_context
*) ctx
;
449 memcpy(&ice
->state
.blend_color
, state
, sizeof(struct pipe_blend_color
));
450 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
453 struct iris_blend_state
{
454 /** Partial 3DSTATE_PS_BLEND */
455 uint32_t ps_blend
[GENX(3DSTATE_PS_BLEND_length
)];
457 /** Partial BLEND_STATE */
458 uint32_t blend_state
[GENX(BLEND_STATE_length
) +
459 BRW_MAX_DRAW_BUFFERS
* GENX(BLEND_STATE_ENTRY_length
)];
461 bool alpha_to_coverage
; /* for shader key */
465 iris_create_blend_state(struct pipe_context
*ctx
,
466 const struct pipe_blend_state
*state
)
468 struct iris_blend_state
*cso
= malloc(sizeof(struct iris_blend_state
));
469 uint32_t *blend_state
= cso
->blend_state
;
471 cso
->alpha_to_coverage
= state
->alpha_to_coverage
;
473 iris_pack_command(GENX(3DSTATE_PS_BLEND
), cso
->ps_blend
, pb
) {
474 /* pb.HasWriteableRT is filled in at draw time. */
475 /* pb.AlphaTestEnable is filled in at draw time. */
476 pb
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
477 pb
.IndependentAlphaBlendEnable
= state
->independent_blend_enable
;
479 pb
.ColorBufferBlendEnable
= state
->rt
[0].blend_enable
;
481 pb
.SourceBlendFactor
= state
->rt
[0].rgb_src_factor
;
482 pb
.SourceAlphaBlendFactor
= state
->rt
[0].alpha_func
;
483 pb
.DestinationBlendFactor
= state
->rt
[0].rgb_dst_factor
;
484 pb
.DestinationAlphaBlendFactor
= state
->rt
[0].alpha_dst_factor
;
487 iris_pack_state(GENX(BLEND_STATE
), blend_state
, bs
) {
488 bs
.AlphaToCoverageEnable
= state
->alpha_to_coverage
;
489 bs
.IndependentAlphaBlendEnable
= state
->independent_blend_enable
;
490 bs
.AlphaToOneEnable
= state
->alpha_to_one
;
491 bs
.AlphaToCoverageDitherEnable
= state
->alpha_to_coverage
;
492 bs
.ColorDitherEnable
= state
->dither
;
493 /* bl.AlphaTestEnable and bs.AlphaTestFunction are filled in later. */
496 blend_state
+= GENX(BLEND_STATE_length
);
498 for (int i
= 0; i
< BRW_MAX_DRAW_BUFFERS
; i
++) {
499 iris_pack_state(GENX(BLEND_STATE_ENTRY
), blend_state
, be
) {
500 be
.LogicOpEnable
= state
->logicop_enable
;
501 be
.LogicOpFunction
= state
->logicop_func
;
503 be
.PreBlendSourceOnlyClampEnable
= false;
504 be
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
505 be
.PreBlendColorClampEnable
= true;
506 be
.PostBlendColorClampEnable
= true;
508 be
.ColorBufferBlendEnable
= state
->rt
[i
].blend_enable
;
510 be
.ColorBlendFunction
= state
->rt
[i
].rgb_func
;
511 be
.AlphaBlendFunction
= state
->rt
[i
].alpha_func
;
512 be
.SourceBlendFactor
= state
->rt
[i
].rgb_src_factor
;
513 be
.SourceAlphaBlendFactor
= state
->rt
[i
].alpha_func
;
514 be
.DestinationBlendFactor
= state
->rt
[i
].rgb_dst_factor
;
515 be
.DestinationAlphaBlendFactor
= state
->rt
[i
].alpha_dst_factor
;
517 be
.WriteDisableRed
= !(state
->rt
[i
].colormask
& PIPE_MASK_R
);
518 be
.WriteDisableGreen
= !(state
->rt
[i
].colormask
& PIPE_MASK_G
);
519 be
.WriteDisableBlue
= !(state
->rt
[i
].colormask
& PIPE_MASK_B
);
520 be
.WriteDisableAlpha
= !(state
->rt
[i
].colormask
& PIPE_MASK_A
);
522 blend_state
+= GENX(BLEND_STATE_ENTRY_length
);
529 iris_bind_blend_state(struct pipe_context
*ctx
, void *state
)
531 struct iris_context
*ice
= (struct iris_context
*) ctx
;
532 ice
->state
.cso_blend
= state
;
533 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
;
534 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
535 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_BLEND
];
538 struct iris_depth_stencil_alpha_state
{
539 /** Partial 3DSTATE_WM_DEPTH_STENCIL */
540 uint32_t wmds
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
542 /** Outbound to BLEND_STATE, 3DSTATE_PS_BLEND, COLOR_CALC_STATE */
543 struct pipe_alpha_state alpha
;
547 iris_create_zsa_state(struct pipe_context
*ctx
,
548 const struct pipe_depth_stencil_alpha_state
*state
)
550 struct iris_depth_stencil_alpha_state
*cso
=
551 malloc(sizeof(struct iris_depth_stencil_alpha_state
));
553 cso
->alpha
= state
->alpha
;
555 bool two_sided_stencil
= state
->stencil
[1].enabled
;
557 /* The state tracker needs to optimize away EQUAL writes for us. */
558 assert(!(state
->depth
.func
== PIPE_FUNC_EQUAL
&& state
->depth
.writemask
));
560 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), cso
->wmds
, wmds
) {
561 wmds
.StencilFailOp
= state
->stencil
[0].fail_op
;
562 wmds
.StencilPassDepthFailOp
= state
->stencil
[0].zfail_op
;
563 wmds
.StencilPassDepthPassOp
= state
->stencil
[0].zpass_op
;
564 wmds
.StencilTestFunction
=
565 translate_compare_func(state
->stencil
[0].func
);
566 wmds
.BackfaceStencilFailOp
= state
->stencil
[1].fail_op
;
567 wmds
.BackfaceStencilPassDepthFailOp
= state
->stencil
[1].zfail_op
;
568 wmds
.BackfaceStencilPassDepthPassOp
= state
->stencil
[1].zpass_op
;
569 wmds
.BackfaceStencilTestFunction
=
570 translate_compare_func(state
->stencil
[1].func
);
571 wmds
.DepthTestFunction
= translate_compare_func(state
->depth
.func
);
572 wmds
.DoubleSidedStencilEnable
= two_sided_stencil
;
573 wmds
.StencilTestEnable
= state
->stencil
[0].enabled
;
574 wmds
.StencilBufferWriteEnable
=
575 state
->stencil
[0].writemask
!= 0 ||
576 (two_sided_stencil
&& state
->stencil
[1].writemask
!= 0);
577 wmds
.DepthTestEnable
= state
->depth
.enabled
;
578 wmds
.DepthBufferWriteEnable
= state
->depth
.writemask
;
579 wmds
.StencilTestMask
= state
->stencil
[0].valuemask
;
580 wmds
.StencilWriteMask
= state
->stencil
[0].writemask
;
581 wmds
.BackfaceStencilTestMask
= state
->stencil
[1].valuemask
;
582 wmds
.BackfaceStencilWriteMask
= state
->stencil
[1].writemask
;
583 /* wmds.[Backface]StencilReferenceValue are merged later */
590 iris_bind_zsa_state(struct pipe_context
*ctx
, void *state
)
592 struct iris_context
*ice
= (struct iris_context
*) ctx
;
593 struct iris_depth_stencil_alpha_state
*old_cso
= ice
->state
.cso_zsa
;
594 struct iris_depth_stencil_alpha_state
*new_cso
= state
;
597 if (cso_changed(alpha
.ref_value
))
598 ice
->state
.dirty
|= IRIS_DIRTY_COLOR_CALC_STATE
;
600 if (cso_changed(alpha
.enabled
))
601 ice
->state
.dirty
|= IRIS_DIRTY_PS_BLEND
| IRIS_DIRTY_BLEND_STATE
;
603 if (cso_changed(alpha
.func
))
604 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
607 ice
->state
.cso_zsa
= new_cso
;
608 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
609 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
610 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_DEPTH_STENCIL_ALPHA
];
613 struct iris_rasterizer_state
{
614 uint32_t sf
[GENX(3DSTATE_SF_length
)];
615 uint32_t clip
[GENX(3DSTATE_CLIP_length
)];
616 uint32_t raster
[GENX(3DSTATE_RASTER_length
)];
617 uint32_t wm
[GENX(3DSTATE_WM_length
)];
618 uint32_t line_stipple
[GENX(3DSTATE_LINE_STIPPLE_length
)];
620 bool clip_halfz
; /* for CC_VIEWPORT */
621 bool depth_clip_near
; /* for CC_VIEWPORT */
622 bool depth_clip_far
; /* for CC_VIEWPORT */
623 bool flatshade
; /* for shader state */
624 bool flatshade_first
; /* for stream output */
625 bool clamp_fragment_color
; /* for shader state */
626 bool light_twoside
; /* for shader state */
627 bool rasterizer_discard
; /* for 3DSTATE_STREAMOUT */
628 bool half_pixel_center
; /* for 3DSTATE_MULTISAMPLE */
629 bool line_stipple_enable
;
630 bool poly_stipple_enable
;
632 bool force_persample_interp
;
633 enum pipe_sprite_coord_mode sprite_coord_mode
; /* PIPE_SPRITE_* */
634 uint16_t sprite_coord_enable
;
638 iris_create_rasterizer_state(struct pipe_context
*ctx
,
639 const struct pipe_rasterizer_state
*state
)
641 struct iris_rasterizer_state
*cso
=
642 malloc(sizeof(struct iris_rasterizer_state
));
645 point_quad_rasterization
-> SBE
?
650 force_persample_interp
- ?
653 offset_units_unscaled
- cap
not exposed
657 cso
->multisample
= state
->multisample
;
658 cso
->force_persample_interp
= state
->force_persample_interp
;
659 cso
->clip_halfz
= state
->clip_halfz
;
660 cso
->depth_clip_near
= state
->depth_clip_near
;
661 cso
->depth_clip_far
= state
->depth_clip_far
;
662 cso
->flatshade
= state
->flatshade
;
663 cso
->flatshade_first
= state
->flatshade_first
;
664 cso
->clamp_fragment_color
= state
->clamp_fragment_color
;
665 cso
->light_twoside
= state
->light_twoside
;
666 cso
->rasterizer_discard
= state
->rasterizer_discard
;
667 cso
->half_pixel_center
= state
->half_pixel_center
;
668 cso
->sprite_coord_mode
= state
->sprite_coord_mode
;
669 cso
->sprite_coord_enable
= state
->sprite_coord_enable
;
670 cso
->line_stipple_enable
= state
->line_stipple_enable
;
671 cso
->poly_stipple_enable
= state
->poly_stipple_enable
;
673 iris_pack_command(GENX(3DSTATE_SF
), cso
->sf
, sf
) {
674 sf
.StatisticsEnable
= true;
675 sf
.ViewportTransformEnable
= true;
676 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
677 sf
.LineEndCapAntialiasingRegionWidth
=
678 state
->line_smooth
? _10pixels
: _05pixels
;
679 sf
.LastPixelEnable
= state
->line_last_pixel
;
680 sf
.LineWidth
= state
->line_width
;
681 sf
.SmoothPointEnable
= state
->point_smooth
;
682 sf
.PointWidthSource
= state
->point_size_per_vertex
? Vertex
: State
;
683 sf
.PointWidth
= state
->point_size
;
685 if (state
->flatshade_first
) {
686 sf
.TriangleFanProvokingVertexSelect
= 1;
688 sf
.TriangleStripListProvokingVertexSelect
= 2;
689 sf
.TriangleFanProvokingVertexSelect
= 2;
690 sf
.LineStripListProvokingVertexSelect
= 1;
694 iris_pack_command(GENX(3DSTATE_RASTER
), cso
->raster
, rr
) {
695 rr
.FrontWinding
= state
->front_ccw
? CounterClockwise
: Clockwise
;
696 rr
.CullMode
= translate_cull_mode(state
->cull_face
);
697 rr
.FrontFaceFillMode
= translate_fill_mode(state
->fill_front
);
698 rr
.BackFaceFillMode
= translate_fill_mode(state
->fill_back
);
699 rr
.DXMultisampleRasterizationEnable
= state
->multisample
;
700 rr
.GlobalDepthOffsetEnableSolid
= state
->offset_tri
;
701 rr
.GlobalDepthOffsetEnableWireframe
= state
->offset_line
;
702 rr
.GlobalDepthOffsetEnablePoint
= state
->offset_point
;
703 rr
.GlobalDepthOffsetConstant
= state
->offset_units
* 2;
704 rr
.GlobalDepthOffsetScale
= state
->offset_scale
;
705 rr
.GlobalDepthOffsetClamp
= state
->offset_clamp
;
706 rr
.SmoothPointEnable
= state
->point_smooth
;
707 rr
.AntialiasingEnable
= state
->line_smooth
;
708 rr
.ScissorRectangleEnable
= state
->scissor
;
709 rr
.ViewportZNearClipTestEnable
= state
->depth_clip_near
;
710 rr
.ViewportZFarClipTestEnable
= state
->depth_clip_far
;
711 //rr.ConservativeRasterizationEnable = not yet supported by Gallium...
714 iris_pack_command(GENX(3DSTATE_CLIP
), cso
->clip
, cl
) {
715 /* cl.NonPerspectiveBarycentricEnable is filled in at draw time from
716 * the FS program; cl.ForceZeroRTAIndexEnable is filled in from the FB.
718 cl
.StatisticsEnable
= true;
719 cl
.EarlyCullEnable
= true;
720 cl
.UserClipDistanceClipTestEnableBitmask
= state
->clip_plane_enable
;
721 cl
.ForceUserClipDistanceClipTestEnableBitmask
= true;
722 cl
.APIMode
= state
->clip_halfz
? APIMODE_D3D
: APIMODE_OGL
;
723 cl
.GuardbandClipTestEnable
= true;
724 cl
.ClipMode
= CLIPMODE_NORMAL
;
725 cl
.ClipEnable
= true;
726 cl
.ViewportXYClipTestEnable
= state
->point_tri_clip
;
727 cl
.MinimumPointWidth
= 0.125;
728 cl
.MaximumPointWidth
= 255.875;
730 if (state
->flatshade_first
) {
731 cl
.TriangleFanProvokingVertexSelect
= 1;
733 cl
.TriangleStripListProvokingVertexSelect
= 2;
734 cl
.TriangleFanProvokingVertexSelect
= 2;
735 cl
.LineStripListProvokingVertexSelect
= 1;
739 iris_pack_command(GENX(3DSTATE_WM
), cso
->wm
, wm
) {
740 /* wm.BarycentricInterpolationMode and wm.EarlyDepthStencilControl are
741 * filled in at draw time from the FS program.
743 wm
.LineAntialiasingRegionWidth
= _10pixels
;
744 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
745 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
746 wm
.StatisticsEnable
= true;
747 wm
.LineStippleEnable
= state
->line_stipple_enable
;
748 wm
.PolygonStippleEnable
= state
->poly_stipple_enable
;
751 /* Remap from 0..255 back to 1..256 */
752 const unsigned line_stipple_factor
= state
->line_stipple_factor
+ 1;
754 iris_pack_command(GENX(3DSTATE_LINE_STIPPLE
), cso
->line_stipple
, line
) {
755 line
.LineStipplePattern
= state
->line_stipple_pattern
;
756 line
.LineStippleInverseRepeatCount
= 1.0f
/ line_stipple_factor
;
757 line
.LineStippleRepeatCount
= line_stipple_factor
;
764 iris_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
766 struct iris_context
*ice
= (struct iris_context
*) ctx
;
767 struct iris_rasterizer_state
*old_cso
= ice
->state
.cso_rast
;
768 struct iris_rasterizer_state
*new_cso
= state
;
771 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
772 if (cso_changed_memcmp(line_stipple
))
773 ice
->state
.dirty
|= IRIS_DIRTY_LINE_STIPPLE
;
775 if (cso_changed(half_pixel_center
))
776 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
778 if (cso_changed(line_stipple_enable
) || cso_changed(poly_stipple_enable
))
779 ice
->state
.dirty
|= IRIS_DIRTY_WM
;
781 if (cso_changed(rasterizer_discard
) || cso_changed(flatshade_first
))
782 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
784 if (cso_changed(depth_clip_near
) || cso_changed(depth_clip_far
) ||
785 cso_changed(clip_halfz
))
786 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
788 if (cso_changed(sprite_coord_enable
))
789 ice
->state
.dirty
|= IRIS_DIRTY_SBE
;
792 ice
->state
.cso_rast
= new_cso
;
793 ice
->state
.dirty
|= IRIS_DIRTY_RASTER
;
794 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
795 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_RASTERIZER
];
799 translate_wrap(unsigned pipe_wrap
)
801 static const unsigned map
[] = {
802 [PIPE_TEX_WRAP_REPEAT
] = TCM_WRAP
,
803 [PIPE_TEX_WRAP_CLAMP
] = TCM_HALF_BORDER
,
804 [PIPE_TEX_WRAP_CLAMP_TO_EDGE
] = TCM_CLAMP
,
805 [PIPE_TEX_WRAP_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
806 [PIPE_TEX_WRAP_MIRROR_REPEAT
] = TCM_MIRROR
,
807 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
809 /* These are unsupported. */
810 [PIPE_TEX_WRAP_MIRROR_CLAMP
] = -1,
811 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
] = -1,
813 return map
[pipe_wrap
];
817 * Return true if the given wrap mode requires the border color to exist.
820 wrap_mode_needs_border_color(unsigned wrap_mode
)
822 return wrap_mode
== TCM_CLAMP_BORDER
|| wrap_mode
== TCM_HALF_BORDER
;
826 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip
)
828 static const unsigned map
[] = {
829 [PIPE_TEX_MIPFILTER_NEAREST
] = MIPFILTER_NEAREST
,
830 [PIPE_TEX_MIPFILTER_LINEAR
] = MIPFILTER_LINEAR
,
831 [PIPE_TEX_MIPFILTER_NONE
] = MIPFILTER_NONE
,
833 return map
[pipe_mip
];
836 struct iris_sampler_state
{
837 struct pipe_sampler_state base
;
839 bool needs_border_color
;
841 uint32_t sampler_state
[GENX(SAMPLER_STATE_length
)];
845 iris_create_sampler_state(struct pipe_context
*ctx
,
846 const struct pipe_sampler_state
*state
)
848 struct iris_sampler_state
*cso
= CALLOC_STRUCT(iris_sampler_state
);
853 memcpy(&cso
->base
, state
, sizeof(*state
));
855 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST
== MAPFILTER_NEAREST
);
856 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR
== MAPFILTER_LINEAR
);
858 unsigned wrap_s
= translate_wrap(state
->wrap_s
);
859 unsigned wrap_t
= translate_wrap(state
->wrap_t
);
860 unsigned wrap_r
= translate_wrap(state
->wrap_r
);
862 cso
->needs_border_color
= wrap_mode_needs_border_color(wrap_s
) ||
863 wrap_mode_needs_border_color(wrap_t
) ||
864 wrap_mode_needs_border_color(wrap_r
);
866 iris_pack_state(GENX(SAMPLER_STATE
), cso
->sampler_state
, samp
) {
867 samp
.TCXAddressControlMode
= wrap_s
;
868 samp
.TCYAddressControlMode
= wrap_t
;
869 samp
.TCZAddressControlMode
= wrap_r
;
870 samp
.CubeSurfaceControlMode
= state
->seamless_cube_map
;
871 samp
.NonnormalizedCoordinateEnable
= !state
->normalized_coords
;
872 samp
.MinModeFilter
= state
->min_img_filter
;
873 samp
.MagModeFilter
= state
->mag_img_filter
;
874 samp
.MipModeFilter
= translate_mip_filter(state
->min_mip_filter
);
875 samp
.MaximumAnisotropy
= RATIO21
;
877 if (state
->max_anisotropy
>= 2) {
878 if (state
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
879 samp
.MinModeFilter
= MAPFILTER_ANISOTROPIC
;
880 samp
.AnisotropicAlgorithm
= EWAApproximation
;
883 if (state
->mag_img_filter
== PIPE_TEX_FILTER_LINEAR
)
884 samp
.MagModeFilter
= MAPFILTER_ANISOTROPIC
;
886 samp
.MaximumAnisotropy
=
887 MIN2((state
->max_anisotropy
- 2) / 2, RATIO161
);
890 /* Set address rounding bits if not using nearest filtering. */
891 if (state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
892 samp
.UAddressMinFilterRoundingEnable
= true;
893 samp
.VAddressMinFilterRoundingEnable
= true;
894 samp
.RAddressMinFilterRoundingEnable
= true;
897 if (state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
) {
898 samp
.UAddressMagFilterRoundingEnable
= true;
899 samp
.VAddressMagFilterRoundingEnable
= true;
900 samp
.RAddressMagFilterRoundingEnable
= true;
903 if (state
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
904 samp
.ShadowFunction
= translate_shadow_func(state
->compare_func
);
906 const float hw_max_lod
= GEN_GEN
>= 7 ? 14 : 13;
908 samp
.LODPreClampMode
= CLAMP_MODE_OGL
;
909 samp
.MinLOD
= CLAMP(state
->min_lod
, 0, hw_max_lod
);
910 samp
.MaxLOD
= CLAMP(state
->max_lod
, 0, hw_max_lod
);
911 samp
.TextureLODBias
= CLAMP(state
->lod_bias
, -16, 15);
913 /* .BorderColorPointer is filled in by iris_bind_sampler_states. */
920 iris_bind_sampler_states(struct pipe_context
*ctx
,
921 enum pipe_shader_type p_stage
,
922 unsigned start
, unsigned count
,
925 struct iris_context
*ice
= (struct iris_context
*) ctx
;
926 gl_shader_stage stage
= stage_from_pipe(p_stage
);
928 assert(start
+ count
<= IRIS_MAX_TEXTURE_SAMPLERS
);
929 ice
->state
.num_samplers
[stage
] =
930 MAX2(ice
->state
.num_samplers
[stage
], start
+ count
);
932 for (int i
= 0; i
< count
; i
++) {
933 ice
->state
.samplers
[stage
][start
+ i
] = states
[i
];
936 /* Assemble the SAMPLER_STATEs into a contiguous table that lives
937 * in the dynamic state memory zone, so we can point to it via the
938 * 3DSTATE_SAMPLER_STATE_POINTERS_* commands.
940 void *map
= upload_state(ice
->state
.dynamic_uploader
,
941 &ice
->state
.sampler_table
[stage
],
942 count
* 4 * GENX(SAMPLER_STATE_length
), 32);
946 struct pipe_resource
*res
= ice
->state
.sampler_table
[stage
].res
;
947 ice
->state
.sampler_table
[stage
].offset
+=
948 iris_bo_offset_from_base_address(iris_resource_bo(res
));
950 /* Make sure all land in the same BO */
951 iris_border_color_pool_reserve(ice
, IRIS_MAX_TEXTURE_SAMPLERS
);
953 for (int i
= 0; i
< count
; i
++) {
954 struct iris_sampler_state
*state
= ice
->state
.samplers
[stage
][i
];
956 /* Save a pointer to the iris_sampler_state, a few fields need
957 * to inform draw-time decisions.
959 ice
->state
.samplers
[stage
][start
+ i
] = state
;
962 memset(map
, 0, 4 * GENX(SAMPLER_STATE_length
));
963 } else if (!state
->needs_border_color
) {
964 memcpy(map
, state
->sampler_state
, 4 * GENX(SAMPLER_STATE_length
));
966 ice
->state
.need_border_colors
= true;
968 /* Stream out the border color and merge the pointer. */
970 iris_upload_border_color(ice
, &state
->base
.border_color
);
972 uint32_t dynamic
[GENX(SAMPLER_STATE_length
)];
973 iris_pack_state(GENX(SAMPLER_STATE
), dynamic
, dyns
) {
974 dyns
.BorderColorPointer
= offset
;
977 for (uint32_t j
= 0; j
< GENX(SAMPLER_STATE_length
); j
++)
978 ((uint32_t *) map
)[j
] = state
->sampler_state
[j
] | dynamic
[j
];
981 map
+= GENX(SAMPLER_STATE_length
);
984 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
;
987 struct iris_sampler_view
{
988 struct pipe_sampler_view pipe
;
989 struct isl_view view
;
991 /** The resource (BO) holding our SURFACE_STATE. */
992 struct iris_state_ref surface_state
;
996 * Convert an swizzle enumeration (i.e. PIPE_SWIZZLE_X) to one of the Gen7.5+
997 * "Shader Channel Select" enumerations (i.e. HSW_SCS_RED). The mappings are
999 * SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_ZERO, SWIZZLE_ONE
1002 * SCS_RED, SCS_GREEN, SCS_BLUE, SCS_ALPHA, SCS_ZERO, SCS_ONE
1004 * which is simply adding 4 then modding by 8 (or anding with 7).
1006 * We then may need to apply workarounds for textureGather hardware bugs.
1008 static enum isl_channel_select
1009 pipe_swizzle_to_isl_channel(enum pipe_swizzle swizzle
)
1011 return (swizzle
+ 4) & 7;
1014 static struct pipe_sampler_view
*
1015 iris_create_sampler_view(struct pipe_context
*ctx
,
1016 struct pipe_resource
*tex
,
1017 const struct pipe_sampler_view
*tmpl
)
1019 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1020 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1021 struct iris_resource
*itex
= (struct iris_resource
*) tex
;
1022 struct iris_sampler_view
*isv
= calloc(1, sizeof(struct iris_sampler_view
));
1027 /* initialize base object */
1029 isv
->pipe
.context
= ctx
;
1030 isv
->pipe
.texture
= NULL
;
1031 pipe_reference_init(&isv
->pipe
.reference
, 1);
1032 pipe_resource_reference(&isv
->pipe
.texture
, tex
);
1034 void *map
= upload_state(ice
->state
.surface_uploader
, &isv
->surface_state
,
1035 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
1039 struct iris_bo
*state_bo
= iris_resource_bo(isv
->surface_state
.res
);
1040 isv
->surface_state
.offset
+= iris_bo_offset_from_base_address(state_bo
);
1042 /* XXX: do we need brw_get_texture_swizzle hacks here? */
1043 isv
->view
= (struct isl_view
) {
1044 .format
= iris_isl_format_for_pipe_format(tmpl
->format
),
1045 .swizzle
= (struct isl_swizzle
) {
1046 .r
= pipe_swizzle_to_isl_channel(tmpl
->swizzle_r
),
1047 .g
= pipe_swizzle_to_isl_channel(tmpl
->swizzle_g
),
1048 .b
= pipe_swizzle_to_isl_channel(tmpl
->swizzle_b
),
1049 .a
= pipe_swizzle_to_isl_channel(tmpl
->swizzle_a
),
1051 .usage
= ISL_SURF_USAGE_TEXTURE_BIT
|
1052 (itex
->surf
.usage
& ISL_SURF_USAGE_CUBE_BIT
),
1055 if (tmpl
->target
!= PIPE_BUFFER
) {
1056 isv
->view
.base_level
= tmpl
->u
.tex
.first_level
;
1057 isv
->view
.levels
= tmpl
->u
.tex
.last_level
- tmpl
->u
.tex
.first_level
+ 1;
1058 isv
->view
.base_array_layer
= tmpl
->u
.tex
.first_layer
;
1059 isv
->view
.array_len
=
1060 tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1;
1062 isl_surf_fill_state(&screen
->isl_dev
, map
,
1063 .surf
= &itex
->surf
, .view
= &isv
->view
,
1065 .address
= itex
->bo
->gtt_offset
);
1067 // .clear_color = clear_color,
1069 // XXX: what to do about isv->view? other drivers don't use it for bufs
1070 const struct isl_format_layout
*fmtl
=
1071 isl_format_get_layout(isv
->view
.format
);
1072 const unsigned cpp
= fmtl
->bpb
/ 8;
1074 isl_buffer_fill_state(&screen
->isl_dev
, map
,
1075 .address
= itex
->bo
->gtt_offset
+
1077 // XXX: buffer_texture_range_size from i965?
1078 .size_B
= tmpl
->u
.buf
.size
,
1079 .format
= isv
->view
.format
,
1087 static struct pipe_surface
*
1088 iris_create_surface(struct pipe_context
*ctx
,
1089 struct pipe_resource
*tex
,
1090 const struct pipe_surface
*tmpl
)
1092 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1093 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1094 struct iris_surface
*surf
= calloc(1, sizeof(struct iris_surface
));
1095 struct pipe_surface
*psurf
= &surf
->pipe
;
1096 struct iris_resource
*res
= (struct iris_resource
*) tex
;
1101 pipe_reference_init(&psurf
->reference
, 1);
1102 pipe_resource_reference(&psurf
->texture
, tex
);
1103 psurf
->context
= ctx
;
1104 psurf
->format
= tmpl
->format
;
1105 psurf
->width
= tex
->width0
;
1106 psurf
->height
= tex
->height0
;
1107 psurf
->texture
= tex
;
1108 psurf
->u
.tex
.first_layer
= tmpl
->u
.tex
.first_layer
;
1109 psurf
->u
.tex
.last_layer
= tmpl
->u
.tex
.last_layer
;
1110 psurf
->u
.tex
.level
= tmpl
->u
.tex
.level
;
1114 usage
= ISL_SURF_USAGE_STORAGE_BIT
;
1115 else if (util_format_is_depth_or_stencil(tmpl
->format
))
1116 usage
= ISL_SURF_USAGE_DEPTH_BIT
;
1118 usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
1120 surf
->view
= (struct isl_view
) {
1121 .format
= iris_isl_format_for_pipe_format(tmpl
->format
),
1122 .base_level
= tmpl
->u
.tex
.level
,
1124 .base_array_layer
= tmpl
->u
.tex
.first_layer
,
1125 .array_len
= tmpl
->u
.tex
.last_layer
- tmpl
->u
.tex
.first_layer
+ 1,
1126 .swizzle
= ISL_SWIZZLE_IDENTITY
,
1130 /* Bail early for depth/stencil */
1131 if (res
->surf
.usage
& (ISL_SURF_USAGE_DEPTH_BIT
|
1132 ISL_SURF_USAGE_STENCIL_BIT
))
1136 void *map
= upload_state(ice
->state
.surface_uploader
, &surf
->surface_state
,
1137 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
1141 struct iris_bo
*state_bo
= iris_resource_bo(surf
->surface_state
.res
);
1142 surf
->surface_state
.offset
+= iris_bo_offset_from_base_address(state_bo
);
1144 isl_surf_fill_state(&screen
->isl_dev
, map
,
1145 .surf
= &res
->surf
, .view
= &surf
->view
,
1147 .address
= res
->bo
->gtt_offset
);
1149 // .clear_color = clear_color,
1155 iris_set_sampler_views(struct pipe_context
*ctx
,
1156 enum pipe_shader_type p_stage
,
1157 unsigned start
, unsigned count
,
1158 struct pipe_sampler_view
**views
)
1160 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1161 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1164 for (i
= 0; i
< count
; i
++) {
1165 pipe_sampler_view_reference((struct pipe_sampler_view
**)
1166 &ice
->state
.textures
[stage
][i
], views
[i
]);
1168 for (; i
< ice
->state
.num_textures
[stage
]; i
++) {
1169 pipe_sampler_view_reference((struct pipe_sampler_view
**)
1170 &ice
->state
.textures
[stage
][i
], NULL
);
1173 ice
->state
.num_textures
[stage
] = count
;
1175 ice
->state
.dirty
|= (IRIS_DIRTY_BINDINGS_VS
<< stage
);
1179 iris_set_clip_state(struct pipe_context
*ctx
,
1180 const struct pipe_clip_state
*state
)
1185 iris_set_polygon_stipple(struct pipe_context
*ctx
,
1186 const struct pipe_poly_stipple
*state
)
1188 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1189 memcpy(&ice
->state
.poly_stipple
, state
, sizeof(*state
));
1190 ice
->state
.dirty
|= IRIS_DIRTY_POLYGON_STIPPLE
;
1194 iris_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
1196 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1198 ice
->state
.sample_mask
= sample_mask
== 0xffffffff ? 1 : sample_mask
;
1199 ice
->state
.dirty
|= IRIS_DIRTY_SAMPLE_MASK
;
1203 iris_set_scissor_states(struct pipe_context
*ctx
,
1204 unsigned start_slot
,
1205 unsigned num_scissors
,
1206 const struct pipe_scissor_state
*states
)
1208 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1210 for (unsigned i
= 0; i
< num_scissors
; i
++) {
1211 ice
->state
.scissors
[start_slot
+ i
] = states
[i
];
1214 ice
->state
.dirty
|= IRIS_DIRTY_SCISSOR_RECT
;
1218 iris_set_stencil_ref(struct pipe_context
*ctx
,
1219 const struct pipe_stencil_ref
*state
)
1221 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1222 memcpy(&ice
->state
.stencil_ref
, state
, sizeof(*state
));
1223 ice
->state
.dirty
|= IRIS_DIRTY_WM_DEPTH_STENCIL
;
1227 viewport_extent(const struct pipe_viewport_state
*state
, int axis
, float sign
)
1229 return copysignf(state
->scale
[axis
], sign
) + state
->translate
[axis
];
1234 calculate_guardband_size(uint32_t fb_width
, uint32_t fb_height
,
1235 float m00
, float m11
, float m30
, float m31
,
1236 float *xmin
, float *xmax
,
1237 float *ymin
, float *ymax
)
1239 /* According to the "Vertex X,Y Clamping and Quantization" section of the
1240 * Strips and Fans documentation:
1242 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
1243 * fixed-point "guardband" range supported by the rasterization hardware"
1247 * "In almost all circumstances, if an object’s vertices are actually
1248 * modified by this clamping (i.e., had X or Y coordinates outside of
1249 * the guardband extent the rendered object will not match the intended
1250 * result. Therefore software should take steps to ensure that this does
1251 * not happen - e.g., by clipping objects such that they do not exceed
1252 * these limits after the Drawing Rectangle is applied."
1254 * I believe the fundamental restriction is that the rasterizer (in
1255 * the SF/WM stages) have a limit on the number of pixels that can be
1256 * rasterized. We need to ensure any coordinates beyond the rasterizer
1257 * limit are handled by the clipper. So effectively that limit becomes
1258 * the clipper's guardband size.
1260 * It goes on to say:
1262 * "In addition, in order to be correctly rendered, objects must have a
1263 * screenspace bounding box not exceeding 8K in the X or Y direction.
1264 * This additional restriction must also be comprehended by software,
1265 * i.e., enforced by use of clipping."
1267 * This makes no sense. Gen7+ hardware supports 16K render targets,
1268 * and you definitely need to be able to draw polygons that fill the
1269 * surface. Our assumption is that the rasterizer was limited to 8K
1270 * on Sandybridge, which only supports 8K surfaces, and it was actually
1271 * increased to 16K on Ivybridge and later.
1273 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
1275 const float gb_size
= GEN_GEN
>= 7 ? 16384.0f
: 8192.0f
;
1277 if (m00
!= 0 && m11
!= 0) {
1278 /* First, we compute the screen-space render area */
1279 const float ss_ra_xmin
= MIN3( 0, m30
+ m00
, m30
- m00
);
1280 const float ss_ra_xmax
= MAX3( fb_width
, m30
+ m00
, m30
- m00
);
1281 const float ss_ra_ymin
= MIN3( 0, m31
+ m11
, m31
- m11
);
1282 const float ss_ra_ymax
= MAX3(fb_height
, m31
+ m11
, m31
- m11
);
1284 /* We want the guardband to be centered on that */
1285 const float ss_gb_xmin
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 - gb_size
;
1286 const float ss_gb_xmax
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 + gb_size
;
1287 const float ss_gb_ymin
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 - gb_size
;
1288 const float ss_gb_ymax
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 + gb_size
;
1290 /* Now we need it in native device coordinates */
1291 const float ndc_gb_xmin
= (ss_gb_xmin
- m30
) / m00
;
1292 const float ndc_gb_xmax
= (ss_gb_xmax
- m30
) / m00
;
1293 const float ndc_gb_ymin
= (ss_gb_ymin
- m31
) / m11
;
1294 const float ndc_gb_ymax
= (ss_gb_ymax
- m31
) / m11
;
1296 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
1297 * flipped upside-down. X should be fine though.
1299 assert(ndc_gb_xmin
<= ndc_gb_xmax
);
1300 *xmin
= ndc_gb_xmin
;
1301 *xmax
= ndc_gb_xmax
;
1302 *ymin
= MIN2(ndc_gb_ymin
, ndc_gb_ymax
);
1303 *ymax
= MAX2(ndc_gb_ymin
, ndc_gb_ymax
);
1305 /* The viewport scales to 0, so nothing will be rendered. */
1315 iris_set_viewport_states(struct pipe_context
*ctx
,
1316 unsigned start_slot
,
1318 const struct pipe_viewport_state
*states
)
1320 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1321 struct iris_genx_state
*genx
= ice
->state
.genx
;
1322 uint32_t *vp_map
= &genx
->sf_cl_vp
[start_slot
];
1324 for (unsigned i
= 0; i
< count
; i
++) {
1325 const struct pipe_viewport_state
*state
= &states
[i
];
1327 memcpy(&ice
->state
.viewports
[start_slot
+ i
], state
, sizeof(*state
));
1329 iris_pack_state(GENX(SF_CLIP_VIEWPORT
), vp_map
, vp
) {
1330 vp
.ViewportMatrixElementm00
= state
->scale
[0];
1331 vp
.ViewportMatrixElementm11
= state
->scale
[1];
1332 vp
.ViewportMatrixElementm22
= state
->scale
[2];
1333 vp
.ViewportMatrixElementm30
= state
->translate
[0];
1334 vp
.ViewportMatrixElementm31
= state
->translate
[1];
1335 vp
.ViewportMatrixElementm32
= state
->translate
[2];
1336 /* XXX: in i965 this is computed based on the drawbuffer size,
1337 * but we don't have that here...
1339 vp
.XMinClipGuardband
= -1.0;
1340 vp
.XMaxClipGuardband
= 1.0;
1341 vp
.YMinClipGuardband
= -1.0;
1342 vp
.YMaxClipGuardband
= 1.0;
1343 vp
.XMinViewPort
= viewport_extent(state
, 0, -1.0f
);
1344 vp
.XMaxViewPort
= viewport_extent(state
, 0, 1.0f
) - 1;
1345 vp
.YMinViewPort
= viewport_extent(state
, 1, -1.0f
);
1346 vp
.YMaxViewPort
= viewport_extent(state
, 1, 1.0f
) - 1;
1349 vp_map
+= GENX(SF_CLIP_VIEWPORT_length
);
1352 ice
->state
.dirty
|= IRIS_DIRTY_SF_CL_VIEWPORT
;
1354 if (ice
->state
.cso_rast
&& (!ice
->state
.cso_rast
->depth_clip_near
||
1355 !ice
->state
.cso_rast
->depth_clip_far
))
1356 ice
->state
.dirty
|= IRIS_DIRTY_CC_VIEWPORT
;
1360 iris_set_framebuffer_state(struct pipe_context
*ctx
,
1361 const struct pipe_framebuffer_state
*state
)
1363 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1364 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1365 struct isl_device
*isl_dev
= &screen
->isl_dev
;
1366 struct pipe_framebuffer_state
*cso
= &ice
->state
.framebuffer
;
1368 unsigned samples
= util_framebuffer_get_num_samples(state
);
1370 if (cso
->samples
!= samples
) {
1371 ice
->state
.dirty
|= IRIS_DIRTY_MULTISAMPLE
;
1374 if (cso
->nr_cbufs
!= state
->nr_cbufs
) {
1375 ice
->state
.dirty
|= IRIS_DIRTY_BLEND_STATE
;
1378 if ((cso
->layers
== 0) != (state
->layers
== 0)) {
1379 ice
->state
.dirty
|= IRIS_DIRTY_CLIP
;
1382 util_copy_framebuffer_state(cso
, state
);
1383 cso
->samples
= samples
;
1385 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
1387 struct isl_view view
= {
1390 .base_array_layer
= 0,
1392 .swizzle
= ISL_SWIZZLE_IDENTITY
,
1395 struct isl_depth_stencil_hiz_emit_info info
= {
1400 struct iris_resource
*zres
=
1401 (void *) (cso
->zsbuf
? cso
->zsbuf
->texture
: NULL
);
1404 view
.usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
1406 info
.depth_surf
= &zres
->surf
;
1407 info
.depth_address
= zres
->bo
->gtt_offset
;
1409 view
.format
= zres
->surf
.format
;
1411 view
.base_level
= cso
->zsbuf
->u
.tex
.level
;
1412 view
.base_array_layer
= cso
->zsbuf
->u
.tex
.first_layer
;
1414 cso
->zsbuf
->u
.tex
.last_layer
- cso
->zsbuf
->u
.tex
.first_layer
+ 1;
1416 info
.hiz_usage
= ISL_AUX_USAGE_NONE
;
1421 view
.usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
1422 info
.stencil_surf
= &stencil_mt
->surf
;
1425 view
.base_level
= stencil_irb
->mt_level
- stencil_irb
->mt
->first_level
;
1426 view
.base_array_layer
= stencil_irb
->mt_layer
;
1427 view
.array_len
= MAX2(stencil_irb
->layer_count
, 1);
1428 view
.format
= stencil_mt
->surf
.format
;
1431 uint32_t stencil_offset
= 0;
1432 info
.stencil_address
= stencil_mt
->bo
->gtt_offset
+ stencil_mt
->offset
;
1436 isl_emit_depth_stencil_hiz_s(isl_dev
, cso_z
->packets
, &info
);
1438 ice
->state
.dirty
|= IRIS_DIRTY_DEPTH_BUFFER
;
1440 /* Render target change */
1441 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_FS
;
1443 ice
->state
.dirty
|= ice
->state
.dirty_for_nos
[IRIS_NOS_FRAMEBUFFER
];
1447 iris_set_constant_buffer(struct pipe_context
*ctx
,
1448 enum pipe_shader_type p_stage
, unsigned index
,
1449 const struct pipe_constant_buffer
*input
)
1451 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1452 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1453 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1454 struct iris_shader_state
*shs
= &ice
->shaders
.state
[stage
];
1455 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[index
];
1457 if (input
&& (input
->buffer
|| input
->user_buffer
)) {
1458 if (input
->user_buffer
) {
1459 u_upload_data(ctx
->const_uploader
, 0, input
->buffer_size
, 32,
1460 input
->user_buffer
, &cbuf
->data
.offset
,
1463 pipe_resource_reference(&cbuf
->data
.res
, input
->buffer
);
1466 // XXX: these are not retained forever, use a separate uploader?
1468 upload_state(ice
->state
.surface_uploader
, &cbuf
->surface_state
,
1469 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
1470 if (!unlikely(map
)) {
1471 pipe_resource_reference(&cbuf
->data
.res
, NULL
);
1475 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
1476 struct iris_bo
*surf_bo
= iris_resource_bo(cbuf
->surface_state
.res
);
1477 cbuf
->surface_state
.offset
+= iris_bo_offset_from_base_address(surf_bo
);
1479 isl_buffer_fill_state(&screen
->isl_dev
, map
,
1480 .address
= res
->bo
->gtt_offset
+ cbuf
->data
.offset
,
1481 .size_B
= input
->buffer_size
,
1482 .format
= ISL_FORMAT_R32G32B32A32_FLOAT
,
1486 pipe_resource_reference(&cbuf
->data
.res
, NULL
);
1487 pipe_resource_reference(&cbuf
->surface_state
.res
, NULL
);
1490 ice
->state
.dirty
|= IRIS_DIRTY_CONSTANTS_VS
<< stage
;
1491 // XXX: maybe not necessary all the time...?
1492 // XXX: we need 3DS_BTP to commit these changes, and if we fell back to
1493 // XXX: pull model we may need actual new bindings...
1494 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
1498 iris_set_shader_buffers(struct pipe_context
*ctx
,
1499 enum pipe_shader_type p_stage
,
1500 unsigned start_slot
, unsigned count
,
1501 const struct pipe_shader_buffer
*buffers
)
1503 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1504 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
1505 gl_shader_stage stage
= stage_from_pipe(p_stage
);
1506 struct iris_shader_state
*shs
= &ice
->shaders
.state
[stage
];
1508 for (unsigned i
= 0; i
< count
; i
++) {
1509 if (buffers
&& buffers
[i
].buffer
) {
1510 const struct pipe_shader_buffer
*buffer
= &buffers
[i
];
1511 struct iris_resource
*res
= (void *) buffer
->buffer
;
1512 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], &res
->base
);
1514 // XXX: these are not retained forever, use a separate uploader?
1516 upload_state(ice
->state
.surface_uploader
,
1517 &shs
->ssbo_surface_state
[start_slot
+ i
],
1518 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
1519 if (!unlikely(map
)) {
1520 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], NULL
);
1524 struct iris_bo
*surf_state_bo
=
1525 iris_resource_bo(shs
->ssbo_surface_state
[start_slot
+ i
].res
);
1526 shs
->ssbo_surface_state
[start_slot
+ i
].offset
+=
1527 iris_bo_offset_from_base_address(surf_state_bo
);
1529 isl_buffer_fill_state(&screen
->isl_dev
, map
,
1531 res
->bo
->gtt_offset
+ buffer
->buffer_offset
,
1532 .size_B
= buffer
->buffer_size
,
1533 .format
= ISL_FORMAT_RAW
,
1537 pipe_resource_reference(&shs
->ssbo
[start_slot
+ i
], NULL
);
1538 pipe_resource_reference(&shs
->ssbo_surface_state
[start_slot
+ i
].res
,
1543 ice
->state
.dirty
|= IRIS_DIRTY_BINDINGS_VS
<< stage
;
1547 iris_sampler_view_destroy(struct pipe_context
*ctx
,
1548 struct pipe_sampler_view
*state
)
1550 struct iris_sampler_view
*isv
= (void *) state
;
1551 pipe_resource_reference(&state
->texture
, NULL
);
1552 pipe_resource_reference(&isv
->surface_state
.res
, NULL
);
1558 iris_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
*p_surf
)
1560 struct iris_surface
*surf
= (void *) p_surf
;
1561 pipe_resource_reference(&p_surf
->texture
, NULL
);
1562 pipe_resource_reference(&surf
->surface_state
.res
, NULL
);
1567 iris_delete_state(struct pipe_context
*ctx
, void *state
)
1573 iris_free_vertex_buffers(struct iris_vertex_buffer_state
*cso
)
1575 for (unsigned i
= 0; i
< cso
->num_buffers
; i
++)
1576 pipe_resource_reference(&cso
->resources
[i
], NULL
);
1580 iris_set_vertex_buffers(struct pipe_context
*ctx
,
1581 unsigned start_slot
, unsigned count
,
1582 const struct pipe_vertex_buffer
*buffers
)
1584 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1585 struct iris_vertex_buffer_state
*cso
= &ice
->state
.genx
->vertex_buffers
;
1587 iris_free_vertex_buffers(&ice
->state
.genx
->vertex_buffers
);
1592 cso
->num_buffers
= count
;
1594 iris_pack_command(GENX(3DSTATE_VERTEX_BUFFERS
), cso
->vertex_buffers
, vb
) {
1595 vb
.DWordLength
= 4 * MAX2(cso
->num_buffers
, 1) - 1;
1598 uint32_t *vb_pack_dest
= &cso
->vertex_buffers
[1];
1601 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), vb_pack_dest
, vb
) {
1602 vb
.VertexBufferIndex
= start_slot
;
1603 vb
.NullVertexBuffer
= true;
1604 vb
.AddressModifyEnable
= true;
1608 for (unsigned i
= 0; i
< count
; i
++) {
1609 assert(!buffers
[i
].is_user_buffer
);
1611 pipe_resource_reference(&cso
->resources
[i
], buffers
[i
].buffer
.resource
);
1612 struct iris_resource
*res
= (void *) cso
->resources
[i
];
1614 iris_pack_state(GENX(VERTEX_BUFFER_STATE
), vb_pack_dest
, vb
) {
1615 vb
.VertexBufferIndex
= start_slot
+ i
;
1617 vb
.AddressModifyEnable
= true;
1618 vb
.BufferPitch
= buffers
[i
].stride
;
1619 vb
.BufferSize
= res
->bo
->size
;
1620 vb
.BufferStartingAddress
=
1621 ro_bo(NULL
, res
->bo
->gtt_offset
+ buffers
[i
].buffer_offset
);
1624 vb_pack_dest
+= GENX(VERTEX_BUFFER_STATE_length
);
1627 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_BUFFERS
;
1630 struct iris_vertex_element_state
{
1631 uint32_t vertex_elements
[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length
)];
1632 uint32_t vf_instancing
[33 * GENX(3DSTATE_VF_INSTANCING_length
)];
1637 iris_create_vertex_elements(struct pipe_context
*ctx
,
1639 const struct pipe_vertex_element
*state
)
1641 struct iris_vertex_element_state
*cso
=
1642 malloc(sizeof(struct iris_vertex_element_state
));
1647 * - create edge flag one
1649 * - if those are necessary, use count + 1/2/3... OR in the length
1651 iris_pack_command(GENX(3DSTATE_VERTEX_ELEMENTS
), cso
->vertex_elements
, ve
) {
1653 1 + GENX(VERTEX_ELEMENT_STATE_length
) * MAX2(count
, 1) - 2;
1656 uint32_t *ve_pack_dest
= &cso
->vertex_elements
[1];
1657 uint32_t *vfi_pack_dest
= cso
->vf_instancing
;
1660 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
1662 ve
.SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
;
1663 ve
.Component0Control
= VFCOMP_STORE_0
;
1664 ve
.Component1Control
= VFCOMP_STORE_0
;
1665 ve
.Component2Control
= VFCOMP_STORE_0
;
1666 ve
.Component3Control
= VFCOMP_STORE_1_FP
;
1669 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
1673 for (int i
= 0; i
< count
; i
++) {
1674 enum isl_format isl_format
=
1675 iris_isl_format_for_pipe_format(state
[i
].src_format
);
1676 unsigned comp
[4] = { VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
,
1677 VFCOMP_STORE_SRC
, VFCOMP_STORE_SRC
};
1679 switch (isl_format_get_num_channels(isl_format
)) {
1680 case 0: comp
[0] = VFCOMP_STORE_0
;
1681 case 1: comp
[1] = VFCOMP_STORE_0
;
1682 case 2: comp
[2] = VFCOMP_STORE_0
;
1684 comp
[3] = isl_format_has_int_channel(isl_format
) ? VFCOMP_STORE_1_INT
1685 : VFCOMP_STORE_1_FP
;
1688 iris_pack_state(GENX(VERTEX_ELEMENT_STATE
), ve_pack_dest
, ve
) {
1689 ve
.VertexBufferIndex
= state
[i
].vertex_buffer_index
;
1691 ve
.SourceElementOffset
= state
[i
].src_offset
;
1692 ve
.SourceElementFormat
= isl_format
;
1693 ve
.Component0Control
= comp
[0];
1694 ve
.Component1Control
= comp
[1];
1695 ve
.Component2Control
= comp
[2];
1696 ve
.Component3Control
= comp
[3];
1699 iris_pack_command(GENX(3DSTATE_VF_INSTANCING
), vfi_pack_dest
, vi
) {
1700 vi
.VertexElementIndex
= i
;
1701 vi
.InstancingEnable
= state
[i
].instance_divisor
> 0;
1702 vi
.InstanceDataStepRate
= state
[i
].instance_divisor
;
1705 ve_pack_dest
+= GENX(VERTEX_ELEMENT_STATE_length
);
1706 vfi_pack_dest
+= GENX(3DSTATE_VF_INSTANCING_length
);
1713 iris_bind_vertex_elements_state(struct pipe_context
*ctx
, void *state
)
1715 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1716 struct iris_vertex_element_state
*old_cso
= ice
->state
.cso_vertex_elements
;
1717 struct iris_vertex_element_state
*new_cso
= state
;
1719 if (new_cso
&& cso_changed(count
))
1720 ice
->state
.dirty
|= IRIS_DIRTY_VF_SGVS
;
1722 ice
->state
.cso_vertex_elements
= state
;
1723 ice
->state
.dirty
|= IRIS_DIRTY_VERTEX_ELEMENTS
;
1727 iris_create_compute_state(struct pipe_context
*ctx
,
1728 const struct pipe_compute_state
*state
)
1733 struct iris_stream_output_target
{
1734 struct pipe_stream_output_target base
;
1736 uint32_t so_buffer
[GENX(3DSTATE_SO_BUFFER_length
)];
1738 struct iris_state_ref offset
;
1741 static struct pipe_stream_output_target
*
1742 iris_create_stream_output_target(struct pipe_context
*ctx
,
1743 struct pipe_resource
*res
,
1744 unsigned buffer_offset
,
1745 unsigned buffer_size
)
1747 struct iris_stream_output_target
*cso
= calloc(1, sizeof(*cso
));
1751 pipe_reference_init(&cso
->base
.reference
, 1);
1752 pipe_resource_reference(&cso
->base
.buffer
, res
);
1753 cso
->base
.buffer_offset
= buffer_offset
;
1754 cso
->base
.buffer_size
= buffer_size
;
1755 cso
->base
.context
= ctx
;
1757 upload_state(ctx
->stream_uploader
, &cso
->offset
, 4, 4);
1759 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), cso
->so_buffer
, sob
) {
1760 sob
.SurfaceBaseAddress
=
1761 rw_bo(NULL
, iris_resource_bo(res
)->gtt_offset
+ buffer_offset
);
1762 sob
.SOBufferEnable
= true;
1763 sob
.StreamOffsetWriteEnable
= true;
1764 sob
.StreamOutputBufferOffsetAddressEnable
= true;
1765 sob
.MOCS
= MOCS_WB
; // XXX: MOCS
1767 sob
.SurfaceSize
= MAX2(buffer_size
/ 4, 1) - 1;
1768 sob
.StreamOutputBufferOffsetAddress
=
1769 rw_bo(NULL
, iris_resource_bo(cso
->offset
.res
)->gtt_offset
+ cso
->offset
.offset
);
1771 /* .SOBufferIndex and .StreamOffset are filled in later */
1778 iris_stream_output_target_destroy(struct pipe_context
*ctx
,
1779 struct pipe_stream_output_target
*state
)
1781 struct iris_stream_output_target
*cso
= (void *) state
;
1783 pipe_resource_reference(&cso
->base
.buffer
, NULL
);
1784 pipe_resource_reference(&cso
->offset
.res
, NULL
);
1790 iris_set_stream_output_targets(struct pipe_context
*ctx
,
1791 unsigned num_targets
,
1792 struct pipe_stream_output_target
**targets
,
1793 const unsigned *offsets
)
1795 struct iris_context
*ice
= (struct iris_context
*) ctx
;
1796 struct iris_genx_state
*genx
= ice
->state
.genx
;
1797 uint32_t *so_buffers
= genx
->so_buffers
;
1799 const bool active
= num_targets
> 0;
1800 if (ice
->state
.streamout_active
!= active
) {
1801 ice
->state
.streamout_active
= active
;
1802 ice
->state
.dirty
|= IRIS_DIRTY_STREAMOUT
;
1805 for (int i
= 0; i
< 4; i
++) {
1806 pipe_so_target_reference(&ice
->state
.so_target
[i
],
1807 i
< num_targets
? targets
[i
] : NULL
);
1810 /* No need to update 3DSTATE_SO_BUFFER unless SOL is active. */
1814 for (unsigned i
= 0; i
< 4; i
++,
1815 so_buffers
+= GENX(3DSTATE_SO_BUFFER_length
)) {
1817 if (i
>= num_targets
|| !targets
[i
]) {
1818 iris_pack_command(GENX(3DSTATE_SO_BUFFER
), so_buffers
, sob
)
1819 sob
.SOBufferIndex
= i
;
1823 /* Note that offsets[i] will either be 0, causing us to zero
1824 * the value in the buffer, or 0xFFFFFFFF, which happens to mean
1825 * "continue appending at the existing offset."
1827 assert(offsets
[i
] == 0 || offsets
[i
] == 0xFFFFFFFF);
1829 uint32_t dynamic
[GENX(3DSTATE_SO_BUFFER_length
)];
1830 iris_pack_state(GENX(3DSTATE_SO_BUFFER
), dynamic
, dyns
) {
1831 dyns
.SOBufferIndex
= i
;
1832 dyns
.StreamOffset
= offsets
[i
];
1835 struct iris_stream_output_target
*tgt
= (void *) targets
[i
];
1836 for (uint32_t j
= 0; j
< GENX(3DSTATE_SO_BUFFER_length
); j
++) {
1837 so_buffers
[j
] = tgt
->so_buffer
[j
] | dynamic
[j
];
1841 ice
->state
.dirty
|= IRIS_DIRTY_SO_BUFFERS
;
1845 iris_create_so_decl_list(const struct pipe_stream_output_info
*info
,
1846 const struct brw_vue_map
*vue_map
)
1848 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
1849 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
1850 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
1851 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
1853 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
1855 memset(so_decl
, 0, sizeof(so_decl
));
1857 /* Construct the list of SO_DECLs to be emitted. The formatting of the
1858 * command feels strange -- each dword pair contains a SO_DECL per stream.
1860 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
1861 const struct pipe_stream_output
*output
= &info
->output
[i
];
1862 const int buffer
= output
->output_buffer
;
1863 const int varying
= output
->register_index
;
1864 const unsigned stream_id
= output
->stream
;
1865 assert(stream_id
< MAX_VERTEX_STREAMS
);
1867 buffer_mask
[stream_id
] |= 1 << buffer
;
1869 assert(vue_map
->varying_to_slot
[varying
] >= 0);
1871 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
1872 * array. Instead, it simply increments DstOffset for the following
1873 * input by the number of components that should be skipped.
1875 * Our hardware is unusual in that it requires us to program SO_DECLs
1876 * for fake "hole" components, rather than simply taking the offset
1877 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
1878 * program as many size = 4 holes as we can, then a final hole to
1879 * accommodate the final 1, 2, or 3 remaining.
1881 int skip_components
= output
->dst_offset
- next_offset
[buffer
];
1883 while (skip_components
> 0) {
1884 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
1886 .OutputBufferSlot
= output
->output_buffer
,
1887 .ComponentMask
= (1 << MIN2(skip_components
, 4)) - 1,
1889 skip_components
-= 4;
1892 next_offset
[buffer
] = output
->dst_offset
+ output
->num_components
;
1894 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
1895 .OutputBufferSlot
= output
->output_buffer
,
1896 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
1898 ((1 << output
->num_components
) - 1) << output
->start_component
,
1901 if (decls
[stream_id
] > max_decls
)
1902 max_decls
= decls
[stream_id
];
1905 unsigned dwords
= GENX(3DSTATE_STREAMOUT_length
) + (3 + 2 * max_decls
);
1906 uint32_t *map
= ralloc_size(NULL
, sizeof(uint32_t) * dwords
);
1907 uint32_t *so_decl_map
= map
+ GENX(3DSTATE_STREAMOUT_length
);
1909 iris_pack_command(GENX(3DSTATE_STREAMOUT
), map
, sol
) {
1910 int urb_entry_read_offset
= 0;
1911 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
1912 urb_entry_read_offset
;
1914 /* We always read the whole vertex. This could be reduced at some
1915 * point by reading less and offsetting the register index in the
1918 sol
.Stream0VertexReadOffset
= urb_entry_read_offset
;
1919 sol
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
1920 sol
.Stream1VertexReadOffset
= urb_entry_read_offset
;
1921 sol
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
1922 sol
.Stream2VertexReadOffset
= urb_entry_read_offset
;
1923 sol
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
1924 sol
.Stream3VertexReadOffset
= urb_entry_read_offset
;
1925 sol
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
1927 /* Set buffer pitches; 0 means unbound. */
1928 sol
.Buffer0SurfacePitch
= 4 * info
->stride
[0];
1929 sol
.Buffer1SurfacePitch
= 4 * info
->stride
[1];
1930 sol
.Buffer2SurfacePitch
= 4 * info
->stride
[2];
1931 sol
.Buffer3SurfacePitch
= 4 * info
->stride
[3];
1934 iris_pack_command(GENX(3DSTATE_SO_DECL_LIST
), so_decl_map
, list
) {
1935 list
.DWordLength
= 3 + 2 * max_decls
- 2;
1936 list
.StreamtoBufferSelects0
= buffer_mask
[0];
1937 list
.StreamtoBufferSelects1
= buffer_mask
[1];
1938 list
.StreamtoBufferSelects2
= buffer_mask
[2];
1939 list
.StreamtoBufferSelects3
= buffer_mask
[3];
1940 list
.NumEntries0
= decls
[0];
1941 list
.NumEntries1
= decls
[1];
1942 list
.NumEntries2
= decls
[2];
1943 list
.NumEntries3
= decls
[3];
1946 for (int i
= 0; i
< max_decls
; i
++) {
1947 iris_pack_state(GENX(SO_DECL_ENTRY
), so_decl_map
+ 3 + i
* 2, entry
) {
1948 entry
.Stream0Decl
= so_decl
[0][i
];
1949 entry
.Stream1Decl
= so_decl
[1][i
];
1950 entry
.Stream2Decl
= so_decl
[2][i
];
1951 entry
.Stream3Decl
= so_decl
[3][i
];
1959 iris_compute_sbe_urb_read_interval(uint64_t fs_input_slots
,
1960 const struct brw_vue_map
*last_vue_map
,
1961 bool two_sided_color
,
1962 unsigned *out_offset
,
1963 unsigned *out_length
)
1965 /* The compiler computes the first URB slot without considering COL/BFC
1966 * swizzling (because it doesn't know whether it's enabled), so we need
1967 * to do that here too. This may result in a smaller offset, which
1970 const unsigned first_slot
=
1971 brw_compute_first_urb_slot_required(fs_input_slots
, last_vue_map
);
1973 /* This becomes the URB read offset (counted in pairs of slots). */
1974 assert(first_slot
% 2 == 0);
1975 *out_offset
= first_slot
/ 2;
1977 /* We need to adjust the inputs read to account for front/back color
1978 * swizzling, as it can make the URB length longer.
1980 for (int c
= 0; c
<= 1; c
++) {
1981 if (fs_input_slots
& (VARYING_BIT_COL0
<< c
)) {
1982 /* If two sided color is enabled, the fragment shader's gl_Color
1983 * (COL0) input comes from either the gl_FrontColor (COL0) or
1984 * gl_BackColor (BFC0) input varyings. Mark BFC as used, too.
1986 if (two_sided_color
)
1987 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
1989 /* If front color isn't written, we opt to give them back color
1990 * instead of an undefined value. Switch from COL to BFC.
1992 if (last_vue_map
->varying_to_slot
[VARYING_SLOT_COL0
+ c
] == -1) {
1993 fs_input_slots
&= ~(VARYING_BIT_COL0
<< c
);
1994 fs_input_slots
|= (VARYING_BIT_BFC0
<< c
);
1999 /* Compute the minimum URB Read Length necessary for the FS inputs.
2001 * From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
2002 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
2004 * "This field should be set to the minimum length required to read the
2005 * maximum source attribute. The maximum source attribute is indicated
2006 * by the maximum value of the enabled Attribute # Source Attribute if
2007 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
2008 * enable is not set.
2009 * read_length = ceiling((max_source_attr + 1) / 2)
2011 * [errata] Corruption/Hang possible if length programmed larger than
2014 * Similar text exists for Ivy Bridge.
2016 * We find the last URB slot that's actually read by the FS.
2018 unsigned last_read_slot
= last_vue_map
->num_slots
- 1;
2019 while (last_read_slot
> first_slot
&& !(fs_input_slots
&
2020 (1ull << last_vue_map
->slot_to_varying
[last_read_slot
])))
2023 /* The URB read length is the difference of the two, counted in pairs. */
2024 *out_length
= DIV_ROUND_UP(last_read_slot
- first_slot
+ 1, 2);
2028 iris_emit_sbe_swiz(struct iris_batch
*batch
,
2029 const struct iris_context
*ice
,
2030 unsigned urb_read_offset
,
2031 unsigned sprite_coord_enables
)
2033 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = {};
2034 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
2035 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
2036 const struct brw_vue_map
*vue_map
= ice
->shaders
.last_vue_map
;
2037 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
2039 /* XXX: this should be generated when putting programs in place */
2041 // XXX: raster->sprite_coord_enable
2043 for (int fs_attr
= 0; fs_attr
< VARYING_SLOT_MAX
; fs_attr
++) {
2044 const int input_index
= wm_prog_data
->urb_setup
[fs_attr
];
2045 if (input_index
< 0 || input_index
>= 16)
2048 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
=
2049 &attr_overrides
[input_index
];
2051 /* Viewport and Layer are stored in the VUE header. We need to override
2052 * them to zero if earlier stages didn't write them, as GL requires that
2053 * they read back as zero when not explicitly set.
2056 case VARYING_SLOT_VIEWPORT
:
2057 case VARYING_SLOT_LAYER
:
2058 attr
->ComponentOverrideX
= true;
2059 attr
->ComponentOverrideW
= true;
2060 attr
->ConstantSource
= CONST_0000
;
2062 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
2063 attr
->ComponentOverrideY
= true;
2064 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
2065 attr
->ComponentOverrideZ
= true;
2068 case VARYING_SLOT_PRIMITIVE_ID
:
2069 attr
->ComponentOverrideX
= true;
2070 attr
->ComponentOverrideY
= true;
2071 attr
->ComponentOverrideZ
= true;
2072 attr
->ComponentOverrideW
= true;
2073 attr
->ConstantSource
= PRIM_ID
;
2080 if (sprite_coord_enables
& (1 << input_index
))
2083 int slot
= vue_map
->varying_to_slot
[fs_attr
];
2085 /* If there was only a back color written but not front, use back
2086 * as the color instead of undefined.
2088 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
2089 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
2090 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
2091 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
2093 /* Not written by the previous stage - undefined. */
2095 attr
->ComponentOverrideX
= true;
2096 attr
->ComponentOverrideY
= true;
2097 attr
->ComponentOverrideZ
= true;
2098 attr
->ComponentOverrideW
= true;
2099 attr
->ConstantSource
= CONST_0001_FLOAT
;
2103 /* Compute the location of the attribute relative to the read offset,
2104 * which is counted in 256-bit increments (two 128-bit VUE slots).
2106 const int source_attr
= slot
- 2 * urb_read_offset
;
2107 assert(source_attr
>= 0 && source_attr
<= 32);
2108 attr
->SourceAttribute
= source_attr
;
2110 /* If we are doing two-sided color, and the VUE slot following this one
2111 * represents a back-facing color, then we need to instruct the SF unit
2112 * to do back-facing swizzling.
2114 if (cso_rast
->light_twoside
&&
2115 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
2116 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
2117 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
2118 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
)))
2119 attr
->SwizzleSelect
= INPUTATTR_FACING
;
2122 iris_emit_cmd(batch
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
2123 for (int i
= 0; i
< 16; i
++)
2124 sbes
.Attribute
[i
] = attr_overrides
[i
];
2129 iris_calculate_point_sprite_overrides(const struct brw_wm_prog_data
*prog_data
,
2130 const struct iris_rasterizer_state
*cso
)
2132 unsigned overrides
= 0;
2134 if (prog_data
->urb_setup
[VARYING_SLOT_PNTC
] != -1)
2135 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_PNTC
];
2137 for (int i
= 0; i
< 8; i
++) {
2138 if ((cso
->sprite_coord_enable
& (1 << i
)) &&
2139 prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
] != -1)
2140 overrides
|= 1 << prog_data
->urb_setup
[VARYING_SLOT_TEX0
+ i
];
2147 iris_emit_sbe(struct iris_batch
*batch
, const struct iris_context
*ice
)
2149 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
2150 const struct brw_wm_prog_data
*wm_prog_data
= (void *)
2151 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
2152 struct pipe_shader_state
*p_fs
=
2153 (void *) ice
->shaders
.uncompiled
[MESA_SHADER_FRAGMENT
];
2154 assert(p_fs
->type
== PIPE_SHADER_IR_NIR
);
2155 nir_shader
*fs_nir
= p_fs
->ir
.nir
;
2157 unsigned urb_read_offset
, urb_read_length
;
2158 iris_compute_sbe_urb_read_interval(fs_nir
->info
.inputs_read
,
2159 ice
->shaders
.last_vue_map
,
2160 cso_rast
->light_twoside
,
2161 &urb_read_offset
, &urb_read_length
);
2163 unsigned sprite_coord_overrides
=
2164 iris_calculate_point_sprite_overrides(wm_prog_data
, cso_rast
);
2166 iris_emit_cmd(batch
, GENX(3DSTATE_SBE
), sbe
) {
2167 sbe
.AttributeSwizzleEnable
= true;
2168 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
2169 sbe
.PointSpriteTextureCoordinateOrigin
= cso_rast
->sprite_coord_mode
;
2170 sbe
.VertexURBEntryReadOffset
= urb_read_offset
;
2171 sbe
.VertexURBEntryReadLength
= urb_read_length
;
2172 sbe
.ForceVertexURBEntryReadOffset
= true;
2173 sbe
.ForceVertexURBEntryReadLength
= true;
2174 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
2175 sbe
.PointSpriteTextureCoordinateEnable
= sprite_coord_overrides
;
2177 for (int i
= 0; i
< 32; i
++) {
2178 sbe
.AttributeActiveComponentFormat
[i
] = ACTIVE_COMPONENT_XYZW
;
2182 iris_emit_sbe_swiz(batch
, ice
, urb_read_offset
, sprite_coord_overrides
);
2186 iris_bind_compute_state(struct pipe_context
*ctx
, void *state
)
2191 iris_populate_sampler_key(const struct iris_context
*ice
,
2192 struct brw_sampler_prog_key_data
*key
)
2194 for (int i
= 0; i
< MAX_SAMPLERS
; i
++) {
2195 key
->swizzles
[i
] = 0x688; /* XYZW */
2200 iris_populate_vs_key(const struct iris_context
*ice
,
2201 struct brw_vs_prog_key
*key
)
2203 iris_populate_sampler_key(ice
, &key
->tex
);
2207 iris_populate_tcs_key(const struct iris_context
*ice
,
2208 struct brw_tcs_prog_key
*key
)
2210 iris_populate_sampler_key(ice
, &key
->tex
);
2214 iris_populate_tes_key(const struct iris_context
*ice
,
2215 struct brw_tes_prog_key
*key
)
2217 iris_populate_sampler_key(ice
, &key
->tex
);
2221 iris_populate_gs_key(const struct iris_context
*ice
,
2222 struct brw_gs_prog_key
*key
)
2224 iris_populate_sampler_key(ice
, &key
->tex
);
2228 iris_populate_fs_key(const struct iris_context
*ice
,
2229 struct brw_wm_prog_key
*key
)
2231 iris_populate_sampler_key(ice
, &key
->tex
);
2233 /* XXX: dirty flags? */
2234 const struct pipe_framebuffer_state
*fb
= &ice
->state
.framebuffer
;
2235 const struct iris_depth_stencil_alpha_state
*zsa
= ice
->state
.cso_zsa
;
2236 const struct iris_rasterizer_state
*rast
= ice
->state
.cso_rast
;
2237 const struct iris_blend_state
*blend
= ice
->state
.cso_blend
;
2239 key
->nr_color_regions
= fb
->nr_cbufs
;
2241 key
->clamp_fragment_color
= rast
->clamp_fragment_color
;
2243 key
->replicate_alpha
= fb
->nr_cbufs
> 1 &&
2244 (zsa
->alpha
.enabled
|| blend
->alpha_to_coverage
);
2246 /* XXX: only bother if COL0/1 are read */
2247 key
->flat_shade
= rast
->flatshade
;
2249 key
->persample_interp
= rast
->force_persample_interp
;
2250 key
->multisample_fbo
= rast
->multisample
&& fb
->samples
> 1;
2252 key
->coherent_fb_fetch
= true;
2254 // XXX: uint64_t input_slots_valid; - for >16 inputs
2256 // XXX: key->force_dual_color_blend for unigine
2257 // XXX: respect hint for high_quality_derivatives:1;
2261 // XXX: these need to go in INIT_THREAD_DISPATCH_FIELDS
2262 pkt
.SamplerCount
= \
2263 DIV_ROUND_UP(CLAMP(stage_state
->sampler_count
, 0, 16), 4); \
2264 pkt
.PerThreadScratchSpace
= prog_data
->total_scratch
== 0 ? 0 : \
2265 ffs(stage_state
->per_thread_scratch
) - 11; \
2270 KSP(const struct iris_compiled_shader
*shader
)
2272 struct iris_resource
*res
= (void *) shader
->assembly
.res
;
2273 return iris_bo_offset_from_base_address(res
->bo
) + shader
->assembly
.offset
;
2276 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix) \
2277 pkt.KernelStartPointer = KSP(shader); \
2278 pkt.BindingTableEntryCount = prog_data->binding_table.size_bytes / 4; \
2279 pkt.FloatingPointMode = prog_data->use_alt_mode; \
2281 pkt.DispatchGRFStartRegisterForURBData = \
2282 prog_data->dispatch_grf_start_reg; \
2283 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
2284 pkt.prefix##URBEntryReadOffset = 0; \
2286 pkt.StatisticsEnable = true; \
2290 iris_store_vs_state(const struct gen_device_info
*devinfo
,
2291 struct iris_compiled_shader
*shader
)
2293 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
2294 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
2296 iris_pack_command(GENX(3DSTATE_VS
), shader
->derived_data
, vs
) {
2297 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
);
2298 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
2299 vs
.SIMD8DispatchEnable
= true;
2300 vs
.UserClipDistanceCullTestEnableBitmask
=
2301 vue_prog_data
->cull_distance_mask
;
2306 iris_store_tcs_state(const struct gen_device_info
*devinfo
,
2307 struct iris_compiled_shader
*shader
)
2309 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
2310 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
2311 struct brw_tcs_prog_data
*tcs_prog_data
= (void *) prog_data
;
2313 iris_pack_command(GENX(3DSTATE_HS
), shader
->derived_data
, hs
) {
2314 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
);
2316 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
2317 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
2318 hs
.IncludeVertexHandles
= true;
2323 iris_store_tes_state(const struct gen_device_info
*devinfo
,
2324 struct iris_compiled_shader
*shader
)
2326 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
2327 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
2328 struct brw_tes_prog_data
*tes_prog_data
= (void *) prog_data
;
2330 uint32_t *te_state
= (void *) shader
->derived_data
;
2331 uint32_t *ds_state
= te_state
+ GENX(3DSTATE_TE_length
);
2333 iris_pack_command(GENX(3DSTATE_TE
), te_state
, te
) {
2334 te
.Partitioning
= tes_prog_data
->partitioning
;
2335 te
.OutputTopology
= tes_prog_data
->output_topology
;
2336 te
.TEDomain
= tes_prog_data
->domain
;
2338 te
.MaximumTessellationFactorOdd
= 63.0;
2339 te
.MaximumTessellationFactorNotOdd
= 64.0;
2342 iris_pack_command(GENX(3DSTATE_DS
), ds_state
, ds
) {
2343 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
);
2345 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
2346 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
2347 ds
.ComputeWCoordinateEnable
=
2348 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
2350 ds
.UserClipDistanceCullTestEnableBitmask
=
2351 vue_prog_data
->cull_distance_mask
;
2357 iris_store_gs_state(const struct gen_device_info
*devinfo
,
2358 struct iris_compiled_shader
*shader
)
2360 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
2361 struct brw_vue_prog_data
*vue_prog_data
= (void *) prog_data
;
2362 struct brw_gs_prog_data
*gs_prog_data
= (void *) prog_data
;
2364 iris_pack_command(GENX(3DSTATE_GS
), shader
->derived_data
, gs
) {
2365 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
);
2367 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
2368 gs
.OutputTopology
= gs_prog_data
->output_topology
;
2369 gs
.ControlDataHeaderSize
=
2370 gs_prog_data
->control_data_header_size_hwords
;
2371 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
2372 gs
.DispatchMode
= DISPATCH_MODE_SIMD8
;
2373 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
2374 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
2375 gs
.ReorderMode
= TRAILING
;
2376 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
2377 gs
.MaximumNumberofThreads
=
2378 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
2379 : (devinfo
->max_gs_threads
- 1);
2381 if (gs_prog_data
->static_vertex_count
!= -1) {
2382 gs
.StaticOutput
= true;
2383 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
2385 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
2387 gs
.UserClipDistanceCullTestEnableBitmask
=
2388 vue_prog_data
->cull_distance_mask
;
2390 const int urb_entry_write_offset
= 1;
2391 const uint32_t urb_entry_output_length
=
2392 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
2393 urb_entry_write_offset
;
2395 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
2396 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
2401 iris_store_fs_state(const struct gen_device_info
*devinfo
,
2402 struct iris_compiled_shader
*shader
)
2404 struct brw_stage_prog_data
*prog_data
= shader
->prog_data
;
2405 struct brw_wm_prog_data
*wm_prog_data
= (void *) shader
->prog_data
;
2407 uint32_t *ps_state
= (void *) shader
->derived_data
;
2408 uint32_t *psx_state
= ps_state
+ GENX(3DSTATE_PS_length
);
2410 iris_pack_command(GENX(3DSTATE_PS
), ps_state
, ps
) {
2411 ps
.VectorMaskEnable
= true;
2412 //ps.SamplerCount = ...
2413 ps
.BindingTableEntryCount
= prog_data
->binding_table
.size_bytes
/ 4;
2414 ps
.FloatingPointMode
= prog_data
->use_alt_mode
;
2415 ps
.MaximumNumberofThreadsPerPSD
= 64 - (GEN_GEN
== 8 ? 2 : 1);
2417 ps
.PushConstantEnable
= prog_data
->nr_params
> 0 ||
2418 prog_data
->ubo_ranges
[0].length
> 0;
2420 /* From the documentation for this packet:
2421 * "If the PS kernel does not need the Position XY Offsets to
2422 * compute a Position Value, then this field should be programmed
2423 * to POSOFFSET_NONE."
2425 * "SW Recommendation: If the PS kernel needs the Position Offsets
2426 * to compute a Position XY value, this field should match Position
2427 * ZW Interpolation Mode to ensure a consistent position.xyzw
2430 * We only require XY sample offsets. So, this recommendation doesn't
2431 * look useful at the moment. We might need this in future.
2433 ps
.PositionXYOffsetSelect
=
2434 wm_prog_data
->uses_pos_offset
? POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
2435 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
2436 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
2437 ps
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
2439 // XXX: Disable SIMD32 with 16x MSAA
2441 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
2442 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 0);
2443 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
2444 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 1);
2445 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
2446 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 2);
2448 ps
.KernelStartPointer0
=
2449 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 0);
2450 ps
.KernelStartPointer1
=
2451 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 1);
2452 ps
.KernelStartPointer2
=
2453 KSP(shader
) + brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 2);
2456 iris_pack_command(GENX(3DSTATE_PS_EXTRA
), psx_state
, psx
) {
2457 psx
.PixelShaderValid
= true;
2458 psx
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
2459 psx
.PixelShaderKillsPixel
= wm_prog_data
->uses_kill
;
2460 psx
.AttributeEnable
= wm_prog_data
->num_varying_inputs
!= 0;
2461 psx
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
2462 psx
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
2463 psx
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
2465 if (wm_prog_data
->uses_sample_mask
) {
2466 /* TODO: conservative rasterization */
2467 if (wm_prog_data
->post_depth_coverage
)
2468 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
2470 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
2473 psx
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
2474 psx
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
2475 psx
.PixelShaderComputesStencil
= wm_prog_data
->computed_stencil
;
2482 iris_derived_program_state_size(enum iris_program_cache_id cache_id
)
2484 assert(cache_id
<= IRIS_CACHE_BLORP
);
2486 static const unsigned dwords
[] = {
2487 [IRIS_CACHE_VS
] = GENX(3DSTATE_VS_length
),
2488 [IRIS_CACHE_TCS
] = GENX(3DSTATE_HS_length
),
2489 [IRIS_CACHE_TES
] = GENX(3DSTATE_TE_length
) + GENX(3DSTATE_DS_length
),
2490 [IRIS_CACHE_GS
] = GENX(3DSTATE_GS_length
),
2492 GENX(3DSTATE_PS_length
) + GENX(3DSTATE_PS_EXTRA_length
),
2493 [IRIS_CACHE_CS
] = 0,
2494 [IRIS_CACHE_BLORP
] = 0,
2497 return sizeof(uint32_t) * dwords
[cache_id
];
2501 iris_store_derived_program_state(const struct gen_device_info
*devinfo
,
2502 enum iris_program_cache_id cache_id
,
2503 struct iris_compiled_shader
*shader
)
2507 iris_store_vs_state(devinfo
, shader
);
2509 case IRIS_CACHE_TCS
:
2510 iris_store_tcs_state(devinfo
, shader
);
2512 case IRIS_CACHE_TES
:
2513 iris_store_tes_state(devinfo
, shader
);
2516 iris_store_gs_state(devinfo
, shader
);
2519 iris_store_fs_state(devinfo
, shader
);
2522 case IRIS_CACHE_BLORP
:
2530 iris_upload_urb_config(struct iris_context
*ice
, struct iris_batch
*batch
)
2532 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
2533 const unsigned push_size_kB
= 32;
2534 unsigned entries
[4];
2538 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
2539 if (!ice
->shaders
.prog
[i
]) {
2542 struct brw_vue_prog_data
*vue_prog_data
=
2543 (void *) ice
->shaders
.prog
[i
]->prog_data
;
2544 size
[i
] = vue_prog_data
->urb_entry_size
;
2546 assert(size
[i
] != 0);
2549 gen_get_urb_config(devinfo
, 1024 * push_size_kB
,
2550 1024 * ice
->shaders
.urb_size
,
2551 ice
->shaders
.prog
[MESA_SHADER_TESS_EVAL
] != NULL
,
2552 ice
->shaders
.prog
[MESA_SHADER_GEOMETRY
] != NULL
,
2553 size
, entries
, start
);
2555 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
2556 iris_emit_cmd(batch
, GENX(3DSTATE_URB_VS
), urb
) {
2557 urb
._3DCommandSubOpcode
+= i
;
2558 urb
.VSURBStartingAddress
= start
[i
];
2559 urb
.VSURBEntryAllocationSize
= size
[i
] - 1;
2560 urb
.VSNumberofURBEntries
= entries
[i
];
2565 static const uint32_t push_constant_opcodes
[] = {
2566 [MESA_SHADER_VERTEX
] = 21,
2567 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
2568 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
2569 [MESA_SHADER_GEOMETRY
] = 22,
2570 [MESA_SHADER_FRAGMENT
] = 23,
2571 [MESA_SHADER_COMPUTE
] = 0,
2575 * Add a surface to the validation list, as well as the buffer containing
2576 * the corresponding SURFACE_STATE.
2578 * Returns the binding table entry (offset to SURFACE_STATE).
2581 use_surface(struct iris_batch
*batch
,
2582 struct pipe_surface
*p_surf
,
2585 struct iris_surface
*surf
= (void *) p_surf
;
2587 iris_use_pinned_bo(batch
, iris_resource_bo(p_surf
->texture
), writeable
);
2588 iris_use_pinned_bo(batch
, iris_resource_bo(surf
->surface_state
.res
), false);
2590 return surf
->surface_state
.offset
;
2594 use_sampler_view(struct iris_batch
*batch
, struct iris_sampler_view
*isv
)
2596 iris_use_pinned_bo(batch
, iris_resource_bo(isv
->pipe
.texture
), false);
2597 iris_use_pinned_bo(batch
, iris_resource_bo(isv
->surface_state
.res
), false);
2599 return isv
->surface_state
.offset
;
2603 use_const_buffer(struct iris_batch
*batch
, struct iris_const_buffer
*cbuf
)
2605 iris_use_pinned_bo(batch
, iris_resource_bo(cbuf
->data
.res
), false);
2606 iris_use_pinned_bo(batch
, iris_resource_bo(cbuf
->surface_state
.res
), false);
2608 return cbuf
->surface_state
.offset
;
2612 use_null_surface(struct iris_batch
*batch
, struct iris_context
*ice
)
2614 struct iris_bo
*state_bo
= iris_resource_bo(ice
->state
.unbound_tex
.res
);
2616 iris_use_pinned_bo(batch
, state_bo
, false);
2618 return ice
->state
.unbound_tex
.offset
;
2622 use_ssbo(struct iris_batch
*batch
, struct iris_context
*ice
,
2623 struct iris_shader_state
*shs
, int i
)
2626 return use_null_surface(batch
, ice
);
2628 struct iris_state_ref
*surf_state
= &shs
->ssbo_surface_state
[i
];
2630 iris_use_pinned_bo(batch
, iris_resource_bo(shs
->ssbo
[i
]), true);
2631 iris_use_pinned_bo(batch
, iris_resource_bo(surf_state
->res
), false);
2633 return surf_state
->offset
;
2637 iris_populate_binding_table(struct iris_context
*ice
,
2638 struct iris_batch
*batch
,
2639 gl_shader_stage stage
)
2641 const struct iris_binder
*binder
= &batch
->binder
;
2642 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
2646 const struct shader_info
*info
= iris_get_shader_info(ice
, stage
);
2647 struct iris_shader_state
*shs
= &ice
->shaders
.state
[stage
];
2651 // - ubos/ssbos/abos
2654 // - render targets - write and read
2656 //struct brw_stage_prog_data *prog_data = (void *) shader->prog_data;
2657 uint32_t *bt_map
= binder
->map
+ binder
->bt_offset
[stage
];
2660 if (stage
== MESA_SHADER_FRAGMENT
) {
2661 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
2662 for (unsigned i
= 0; i
< cso_fb
->nr_cbufs
; i
++) {
2663 bt_map
[s
++] = use_surface(batch
, cso_fb
->cbufs
[i
], true);
2667 //assert(prog_data->binding_table.texture_start ==
2668 //(ice->state.num_textures[stage] ? s : 0xd0d0d0d0));
2670 for (int i
= 0; i
< ice
->state
.num_textures
[stage
]; i
++) {
2671 struct iris_sampler_view
*view
= ice
->state
.textures
[stage
][i
];
2672 bt_map
[s
++] = view
? use_sampler_view(batch
, view
)
2673 : use_null_surface(batch
, ice
);
2676 for (int i
= 0; i
< 1 + info
->num_ubos
; i
++) {
2677 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[i
];
2678 if (!cbuf
->surface_state
.res
)
2681 bt_map
[s
++] = use_const_buffer(batch
, cbuf
);
2684 /* XXX: st is wasting 16 binding table slots for ABOs. Should add a cap
2685 * for changing nir_lower_atomics_to_ssbos setting and buffer_base offset
2686 * in st_atom_storagebuf.c so it'll compact them into one range, with
2687 * SSBOs starting at info->num_abos. Ideally it'd reset num_abos to 0 too
2689 if (info
->num_abos
+ info
->num_ssbos
> 0) {
2690 for (int i
= 0; i
< IRIS_MAX_ABOS
+ info
->num_ssbos
; i
++) {
2691 bt_map
[s
++] = use_ssbo(batch
, ice
, shs
, i
);
2696 // XXX: not implemented yet
2697 assert(prog_data
->binding_table
.pull_constants_start
== 0xd0d0d0d0);
2698 assert(prog_data
->binding_table
.ubo_start
== 0xd0d0d0d0);
2699 assert(prog_data
->binding_table
.ssbo_start
== 0xd0d0d0d0);
2700 assert(prog_data
->binding_table
.image_start
== 0xd0d0d0d0);
2701 assert(prog_data
->binding_table
.shader_time_start
== 0xd0d0d0d0);
2702 //assert(prog_data->binding_table.plane_start[1] == 0xd0d0d0d0);
2703 //assert(prog_data->binding_table.plane_start[2] == 0xd0d0d0d0);
2708 iris_use_optional_res(struct iris_batch
*batch
,
2709 struct pipe_resource
*res
,
2713 struct iris_bo
*bo
= iris_resource_bo(res
);
2714 iris_use_pinned_bo(batch
, bo
, writeable
);
2720 * Pin any BOs which were installed by a previous batch, and restored
2721 * via the hardware logical context mechanism.
2723 * We don't need to re-emit all state every batch - the hardware context
2724 * mechanism will save and restore it for us. This includes pointers to
2725 * various BOs...which won't exist unless we ask the kernel to pin them
2726 * by adding them to the validation list.
2728 * We can skip buffers if we've re-emitted those packets, as we're
2729 * overwriting those stale pointers with new ones, and don't actually
2730 * refer to the old BOs.
2733 iris_restore_context_saved_bos(struct iris_context
*ice
,
2734 struct iris_batch
*batch
,
2735 const struct pipe_draw_info
*draw
)
2737 // XXX: whack IRIS_SHADER_DIRTY_BINDING_TABLE on new batch
2739 const uint64_t clean
= ~ice
->state
.dirty
;
2741 if (clean
& IRIS_DIRTY_CC_VIEWPORT
) {
2742 iris_use_optional_res(batch
, ice
->state
.last_res
.cc_vp
, false);
2745 if (clean
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
2746 iris_use_optional_res(batch
, ice
->state
.last_res
.sf_cl_vp
, false);
2749 if (clean
& IRIS_DIRTY_BLEND_STATE
) {
2750 iris_use_optional_res(batch
, ice
->state
.last_res
.blend
, false);
2753 if (clean
& IRIS_DIRTY_COLOR_CALC_STATE
) {
2754 iris_use_optional_res(batch
, ice
->state
.last_res
.color_calc
, false);
2757 if (clean
& IRIS_DIRTY_SCISSOR_RECT
) {
2758 iris_use_optional_res(batch
, ice
->state
.last_res
.scissor
, false);
2761 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
2762 if (clean
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
))
2765 struct iris_shader_state
*shs
= &ice
->shaders
.state
[stage
];
2766 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
2771 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
2773 for (int i
= 0; i
< 4; i
++) {
2774 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
2776 if (range
->length
== 0)
2779 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[range
->block
];
2780 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
2783 iris_use_pinned_bo(batch
, res
->bo
, false);
2785 iris_use_pinned_bo(batch
, batch
->screen
->workaround_bo
, false);
2789 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
2790 struct pipe_resource
*res
= ice
->state
.sampler_table
[stage
].res
;
2792 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
2795 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
2796 if (clean
& (IRIS_DIRTY_VS
<< stage
)) {
2797 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
2799 struct iris_bo
*bo
= iris_resource_bo(shader
->assembly
.res
);
2800 iris_use_pinned_bo(batch
, bo
, false);
2803 // XXX: scratch buffer
2807 if (clean
& IRIS_DIRTY_DEPTH_BUFFER
) {
2808 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
2810 if (cso_fb
->zsbuf
) {
2811 struct iris_resource
*zres
= (void *) cso_fb
->zsbuf
->texture
;
2812 // XXX: depth might not be writable...
2813 iris_use_pinned_bo(batch
, zres
->bo
, true);
2817 if (draw
->index_size
> 0) {
2818 // XXX: index buffer
2821 if (clean
& IRIS_DIRTY_VERTEX_BUFFERS
) {
2822 struct iris_vertex_buffer_state
*cso
= &ice
->state
.genx
->vertex_buffers
;
2823 for (unsigned i
= 0; i
< cso
->num_buffers
; i
++) {
2824 struct iris_resource
*res
= (void *) cso
->resources
[i
];
2825 iris_use_pinned_bo(batch
, res
->bo
, false);
2831 iris_upload_render_state(struct iris_context
*ice
,
2832 struct iris_batch
*batch
,
2833 const struct pipe_draw_info
*draw
)
2835 const uint64_t dirty
= ice
->state
.dirty
;
2837 struct iris_genx_state
*genx
= ice
->state
.genx
;
2838 struct brw_wm_prog_data
*wm_prog_data
= (void *)
2839 ice
->shaders
.prog
[MESA_SHADER_FRAGMENT
]->prog_data
;
2841 if (dirty
& IRIS_DIRTY_CC_VIEWPORT
) {
2842 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
2843 uint32_t cc_vp_address
;
2845 /* XXX: could avoid streaming for depth_clip [0,1] case. */
2846 uint32_t *cc_vp_map
=
2847 stream_state(batch
, ice
->state
.dynamic_uploader
,
2848 &ice
->state
.last_res
.cc_vp
,
2849 4 * ice
->state
.num_viewports
*
2850 GENX(CC_VIEWPORT_length
), 32, &cc_vp_address
);
2851 for (int i
= 0; i
< ice
->state
.num_viewports
; i
++) {
2853 util_viewport_zmin_zmax(&ice
->state
.viewports
[i
],
2854 cso_rast
->clip_halfz
, &zmin
, &zmax
);
2855 if (cso_rast
->depth_clip_near
)
2857 if (cso_rast
->depth_clip_far
)
2860 iris_pack_state(GENX(CC_VIEWPORT
), cc_vp_map
, ccv
) {
2861 ccv
.MinimumDepth
= zmin
;
2862 ccv
.MaximumDepth
= zmax
;
2865 cc_vp_map
+= GENX(CC_VIEWPORT_length
);
2868 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), ptr
) {
2869 ptr
.CCViewportPointer
= cc_vp_address
;
2873 if (dirty
& IRIS_DIRTY_SF_CL_VIEWPORT
) {
2874 iris_emit_cmd(batch
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
2875 ptr
.SFClipViewportPointer
=
2876 emit_state(batch
, ice
->state
.dynamic_uploader
,
2877 &ice
->state
.last_res
.sf_cl_vp
,
2878 genx
->sf_cl_vp
, 4 * GENX(SF_CLIP_VIEWPORT_length
) *
2879 ice
->state
.num_viewports
, 64);
2885 // XXX: this is only flagged at setup, we assume a static configuration
2886 if (dirty
& IRIS_DIRTY_URB
) {
2887 iris_upload_urb_config(ice
, batch
);
2890 if (dirty
& IRIS_DIRTY_BLEND_STATE
) {
2891 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
2892 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
2893 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
2894 const int num_dwords
= 4 * (GENX(BLEND_STATE_length
) +
2895 cso_fb
->nr_cbufs
* GENX(BLEND_STATE_ENTRY_length
));
2896 uint32_t blend_offset
;
2897 uint32_t *blend_map
=
2898 stream_state(batch
, ice
->state
.dynamic_uploader
,
2899 &ice
->state
.last_res
.blend
,
2900 4 * num_dwords
, 64, &blend_offset
);
2902 uint32_t blend_state_header
;
2903 iris_pack_state(GENX(BLEND_STATE
), &blend_state_header
, bs
) {
2904 bs
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
2905 bs
.AlphaTestFunction
= translate_compare_func(cso_zsa
->alpha
.func
);
2908 blend_map
[0] = blend_state_header
| cso_blend
->blend_state
[0];
2909 memcpy(&blend_map
[1], &cso_blend
->blend_state
[1],
2910 sizeof(cso_blend
->blend_state
) - sizeof(uint32_t));
2912 iris_emit_cmd(batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
2913 ptr
.BlendStatePointer
= blend_offset
;
2914 ptr
.BlendStatePointerValid
= true;
2918 if (dirty
& IRIS_DIRTY_COLOR_CALC_STATE
) {
2919 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
2922 stream_state(batch
, ice
->state
.dynamic_uploader
,
2923 &ice
->state
.last_res
.color_calc
,
2924 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length
),
2926 iris_pack_state(GENX(COLOR_CALC_STATE
), cc_map
, cc
) {
2927 cc
.AlphaTestFormat
= ALPHATEST_FLOAT32
;
2928 cc
.AlphaReferenceValueAsFLOAT32
= cso
->alpha
.ref_value
;
2929 cc
.BlendConstantColorRed
= ice
->state
.blend_color
.color
[0];
2930 cc
.BlendConstantColorGreen
= ice
->state
.blend_color
.color
[1];
2931 cc
.BlendConstantColorBlue
= ice
->state
.blend_color
.color
[2];
2932 cc
.BlendConstantColorAlpha
= ice
->state
.blend_color
.color
[3];
2934 iris_emit_cmd(batch
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
2935 ptr
.ColorCalcStatePointer
= cc_offset
;
2936 ptr
.ColorCalcStatePointerValid
= true;
2940 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
2941 // XXX: wrong dirty tracking...
2942 if (!(dirty
& (IRIS_DIRTY_CONSTANTS_VS
<< stage
)))
2945 struct iris_shader_state
*shs
= &ice
->shaders
.state
[stage
];
2946 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
2951 struct brw_stage_prog_data
*prog_data
= (void *) shader
->prog_data
;
2953 iris_emit_cmd(batch
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
2954 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
2956 /* The Skylake PRM contains the following restriction:
2958 * "The driver must ensure The following case does not occur
2959 * without a flush to the 3D engine: 3DSTATE_CONSTANT_* with
2960 * buffer 3 read length equal to zero committed followed by a
2961 * 3DSTATE_CONSTANT_* with buffer 0 read length not equal to
2964 * To avoid this, we program the buffers in the highest slots.
2965 * This way, slot 0 is only used if slot 3 is also used.
2969 for (int i
= 3; i
>= 0; i
--) {
2970 const struct brw_ubo_range
*range
= &prog_data
->ubo_ranges
[i
];
2972 if (range
->length
== 0)
2975 // XXX: is range->block a constbuf index? it would be nice
2976 struct iris_const_buffer
*cbuf
= &shs
->constbuf
[range
->block
];
2977 struct iris_resource
*res
= (void *) cbuf
->data
.res
;
2979 assert(cbuf
->data
.offset
% 32 == 0);
2981 pkt
.ConstantBody
.ReadLength
[n
] = range
->length
;
2982 pkt
.ConstantBody
.Buffer
[n
] =
2983 res
? ro_bo(res
->bo
, range
->start
* 32 + cbuf
->data
.offset
)
2984 : ro_bo(batch
->screen
->workaround_bo
, 0);
2991 struct iris_binder
*binder
= &batch
->binder
;
2993 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
2994 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
2995 iris_emit_cmd(batch
, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), ptr
) {
2996 ptr
._3DCommandSubOpcode
= 38 + stage
;
2997 ptr
.PointertoVSBindingTable
= binder
->bt_offset
[stage
];
3002 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
3003 if (dirty
& (IRIS_DIRTY_BINDINGS_VS
<< stage
)) {
3004 iris_populate_binding_table(ice
, batch
, stage
);
3008 if (ice
->state
.need_border_colors
)
3009 iris_use_pinned_bo(batch
, ice
->state
.border_color_pool
.bo
, false);
3011 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
3012 if (!(dirty
& (IRIS_DIRTY_SAMPLER_STATES_VS
<< stage
)) ||
3013 !ice
->shaders
.prog
[stage
])
3016 struct pipe_resource
*res
= ice
->state
.sampler_table
[stage
].res
;
3018 iris_use_pinned_bo(batch
, iris_resource_bo(res
), false);
3020 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ptr
) {
3021 ptr
._3DCommandSubOpcode
= 43 + stage
;
3022 ptr
.PointertoVSSamplerState
= ice
->state
.sampler_table
[stage
].offset
;
3026 if (dirty
& IRIS_DIRTY_MULTISAMPLE
) {
3027 iris_emit_cmd(batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
3029 ice
->state
.cso_rast
->half_pixel_center
? CENTER
: UL_CORNER
;
3030 if (ice
->state
.framebuffer
.samples
> 0)
3031 ms
.NumberofMultisamples
= ffs(ice
->state
.framebuffer
.samples
) - 1;
3035 if (dirty
& IRIS_DIRTY_SAMPLE_MASK
) {
3036 iris_emit_cmd(batch
, GENX(3DSTATE_SAMPLE_MASK
), ms
) {
3037 ms
.SampleMask
= MAX2(ice
->state
.sample_mask
, 1);
3041 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
3042 if (!(dirty
& (IRIS_DIRTY_VS
<< stage
)))
3045 struct iris_compiled_shader
*shader
= ice
->shaders
.prog
[stage
];
3048 struct iris_resource
*cache
= (void *) shader
->assembly
.res
;
3049 iris_use_pinned_bo(batch
, cache
->bo
, false);
3050 iris_batch_emit(batch
, shader
->derived_data
,
3051 iris_derived_program_state_size(stage
));
3053 if (stage
== MESA_SHADER_TESS_EVAL
) {
3054 iris_emit_cmd(batch
, GENX(3DSTATE_HS
), hs
);
3055 iris_emit_cmd(batch
, GENX(3DSTATE_TE
), te
);
3056 iris_emit_cmd(batch
, GENX(3DSTATE_DS
), ds
);
3057 } else if (stage
== MESA_SHADER_GEOMETRY
) {
3058 iris_emit_cmd(batch
, GENX(3DSTATE_GS
), gs
);
3063 if (ice
->state
.streamout_active
) {
3064 if (dirty
& IRIS_DIRTY_SO_BUFFERS
) {
3065 iris_batch_emit(batch
, genx
->so_buffers
,
3066 4 * 4 * GENX(3DSTATE_SO_BUFFER_length
));
3067 for (int i
= 0; i
< 4; i
++) {
3068 struct iris_stream_output_target
*tgt
=
3069 (void *) ice
->state
.so_target
[i
];
3071 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->base
.buffer
),
3073 iris_use_pinned_bo(batch
, iris_resource_bo(tgt
->offset
.res
),
3079 if ((dirty
& IRIS_DIRTY_SO_DECL_LIST
) && ice
->state
.streamout
) {
3080 uint32_t *decl_list
=
3081 ice
->state
.streamout
+ GENX(3DSTATE_STREAMOUT_length
);
3082 iris_batch_emit(batch
, decl_list
, 4 * ((decl_list
[0] & 0xff) + 2));
3085 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
3086 const struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3088 uint32_t dynamic_sol
[GENX(3DSTATE_STREAMOUT_length
)];
3089 iris_pack_command(GENX(3DSTATE_STREAMOUT
), dynamic_sol
, sol
) {
3090 sol
.SOFunctionEnable
= true;
3091 sol
.SOStatisticsEnable
= true;
3093 // XXX: GL_PRIMITIVES_GENERATED query
3094 sol
.RenderingDisable
= cso_rast
->rasterizer_discard
;
3095 sol
.ReorderMode
= cso_rast
->flatshade_first
? LEADING
: TRAILING
;
3098 assert(ice
->state
.streamout
);
3100 iris_emit_merge(batch
, ice
->state
.streamout
, dynamic_sol
,
3101 GENX(3DSTATE_STREAMOUT_length
));
3104 if (dirty
& IRIS_DIRTY_STREAMOUT
) {
3105 iris_emit_cmd(batch
, GENX(3DSTATE_STREAMOUT
), sol
);
3109 if (dirty
& IRIS_DIRTY_CLIP
) {
3110 struct iris_rasterizer_state
*cso_rast
= ice
->state
.cso_rast
;
3111 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
3113 uint32_t dynamic_clip
[GENX(3DSTATE_CLIP_length
)];
3114 iris_pack_command(GENX(3DSTATE_CLIP
), &dynamic_clip
, cl
) {
3115 if (wm_prog_data
->barycentric_interp_modes
&
3116 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
3117 cl
.NonPerspectiveBarycentricEnable
= true;
3119 cl
.ForceZeroRTAIndexEnable
= cso_fb
->layers
== 0;
3120 cl
.MaximumVPIndex
= ice
->state
.num_viewports
- 1;
3122 iris_emit_merge(batch
, cso_rast
->clip
, dynamic_clip
,
3123 ARRAY_SIZE(cso_rast
->clip
));
3126 if (dirty
& IRIS_DIRTY_RASTER
) {
3127 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
3128 iris_batch_emit(batch
, cso
->raster
, sizeof(cso
->raster
));
3129 iris_batch_emit(batch
, cso
->sf
, sizeof(cso
->sf
));
3133 /* XXX: FS program updates needs to flag IRIS_DIRTY_WM */
3134 if (dirty
& IRIS_DIRTY_WM
) {
3135 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
3136 uint32_t dynamic_wm
[GENX(3DSTATE_WM_length
)];
3138 iris_pack_command(GENX(3DSTATE_WM
), &dynamic_wm
, wm
) {
3139 wm
.BarycentricInterpolationMode
=
3140 wm_prog_data
->barycentric_interp_modes
;
3142 if (wm_prog_data
->early_fragment_tests
)
3143 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
3144 else if (wm_prog_data
->has_side_effects
)
3145 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
3147 iris_emit_merge(batch
, cso
->wm
, dynamic_wm
, ARRAY_SIZE(cso
->wm
));
3151 // XXX: 3DSTATE_SBE, 3DSTATE_SBE_SWIZ
3152 // -> iris_raster_state (point sprite texture coordinate origin)
3153 // -> bunch of shader state...
3154 iris_emit_sbe(batch
, ice
);
3157 if (dirty
& IRIS_DIRTY_PS_BLEND
) {
3158 struct iris_blend_state
*cso_blend
= ice
->state
.cso_blend
;
3159 struct iris_depth_stencil_alpha_state
*cso_zsa
= ice
->state
.cso_zsa
;
3160 uint32_t dynamic_pb
[GENX(3DSTATE_PS_BLEND_length
)];
3161 iris_pack_command(GENX(3DSTATE_PS_BLEND
), &dynamic_pb
, pb
) {
3162 pb
.HasWriteableRT
= true; // XXX: comes from somewhere :(
3163 pb
.AlphaTestEnable
= cso_zsa
->alpha
.enabled
;
3166 iris_emit_merge(batch
, cso_blend
->ps_blend
, dynamic_pb
,
3167 ARRAY_SIZE(cso_blend
->ps_blend
));
3170 if (dirty
& IRIS_DIRTY_WM_DEPTH_STENCIL
) {
3171 struct iris_depth_stencil_alpha_state
*cso
= ice
->state
.cso_zsa
;
3172 struct pipe_stencil_ref
*p_stencil_refs
= &ice
->state
.stencil_ref
;
3174 uint32_t stencil_refs
[GENX(3DSTATE_WM_DEPTH_STENCIL_length
)];
3175 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL
), &stencil_refs
, wmds
) {
3176 wmds
.StencilReferenceValue
= p_stencil_refs
->ref_value
[0];
3177 wmds
.BackfaceStencilReferenceValue
= p_stencil_refs
->ref_value
[1];
3179 iris_emit_merge(batch
, cso
->wmds
, stencil_refs
, ARRAY_SIZE(cso
->wmds
));
3182 if (dirty
& IRIS_DIRTY_SCISSOR_RECT
) {
3183 uint32_t scissor_offset
=
3184 emit_state(batch
, ice
->state
.dynamic_uploader
,
3185 &ice
->state
.last_res
.scissor
,
3186 ice
->state
.scissors
,
3187 sizeof(struct pipe_scissor_state
) *
3188 ice
->state
.num_viewports
, 32);
3190 iris_emit_cmd(batch
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
3191 ptr
.ScissorRectPointer
= scissor_offset
;
3195 if (dirty
& IRIS_DIRTY_DEPTH_BUFFER
) {
3196 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
3197 struct iris_depth_buffer_state
*cso_z
= &ice
->state
.genx
->depth_buffer
;
3199 iris_batch_emit(batch
, cso_z
->packets
, sizeof(cso_z
->packets
));
3201 if (cso_fb
->zsbuf
) {
3202 struct iris_resource
*zres
= (void *) cso_fb
->zsbuf
->texture
;
3203 // XXX: depth might not be writable...
3204 iris_use_pinned_bo(batch
, zres
->bo
, true);
3208 if (dirty
& IRIS_DIRTY_POLYGON_STIPPLE
) {
3209 iris_emit_cmd(batch
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
3210 for (int i
= 0; i
< 32; i
++) {
3211 poly
.PatternRow
[i
] = ice
->state
.poly_stipple
.stipple
[i
];
3216 if (dirty
& IRIS_DIRTY_LINE_STIPPLE
) {
3217 struct iris_rasterizer_state
*cso
= ice
->state
.cso_rast
;
3218 iris_batch_emit(batch
, cso
->line_stipple
, sizeof(cso
->line_stipple
));
3222 iris_emit_cmd(batch
, GENX(3DSTATE_VF_TOPOLOGY
), topo
) {
3223 topo
.PrimitiveTopologyType
=
3224 translate_prim_type(draw
->mode
, draw
->vertices_per_patch
);
3228 if (draw
->index_size
> 0) {
3229 struct iris_resource
*res
= NULL
;
3232 if (draw
->has_user_indices
) {
3233 u_upload_data(ice
->ctx
.stream_uploader
, 0,
3234 draw
->count
* draw
->index_size
, 4, draw
->index
.user
,
3235 &offset
, (struct pipe_resource
**) &res
);
3237 res
= (struct iris_resource
*) draw
->index
.resource
;
3241 iris_emit_cmd(batch
, GENX(3DSTATE_INDEX_BUFFER
), ib
) {
3242 ib
.IndexFormat
= draw
->index_size
>> 1;
3244 ib
.BufferSize
= res
->bo
->size
;
3245 ib
.BufferStartingAddress
= ro_bo(res
->bo
, offset
);
3249 if (dirty
& IRIS_DIRTY_VERTEX_BUFFERS
) {
3250 struct iris_vertex_buffer_state
*cso
= &ice
->state
.genx
->vertex_buffers
;
3251 const unsigned vb_dwords
= GENX(VERTEX_BUFFER_STATE_length
);
3253 if (cso
->num_buffers
> 0) {
3254 iris_batch_emit(batch
, cso
->vertex_buffers
, sizeof(uint32_t) *
3255 (1 + vb_dwords
* cso
->num_buffers
));
3257 for (unsigned i
= 0; i
< cso
->num_buffers
; i
++) {
3258 struct iris_resource
*res
= (void *) cso
->resources
[i
];
3259 iris_use_pinned_bo(batch
, res
->bo
, false);
3264 if (dirty
& IRIS_DIRTY_VERTEX_ELEMENTS
) {
3265 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
3266 const unsigned entries
= MAX2(cso
->count
, 1);
3267 iris_batch_emit(batch
, cso
->vertex_elements
, sizeof(uint32_t) *
3268 (1 + entries
* GENX(VERTEX_ELEMENT_STATE_length
)));
3269 iris_batch_emit(batch
, cso
->vf_instancing
, sizeof(uint32_t) *
3270 entries
* GENX(3DSTATE_VF_INSTANCING_length
));
3273 if (dirty
& IRIS_DIRTY_VF_SGVS
) {
3274 const struct brw_vs_prog_data
*vs_prog_data
= (void *)
3275 ice
->shaders
.prog
[MESA_SHADER_VERTEX
]->prog_data
;
3276 struct iris_vertex_element_state
*cso
= ice
->state
.cso_vertex_elements
;
3278 iris_emit_cmd(batch
, GENX(3DSTATE_VF_SGVS
), sgv
) {
3279 if (vs_prog_data
->uses_vertexid
) {
3280 sgv
.VertexIDEnable
= true;
3281 sgv
.VertexIDComponentNumber
= 2;
3282 sgv
.VertexIDElementOffset
= cso
->count
;
3285 if (vs_prog_data
->uses_instanceid
) {
3286 sgv
.InstanceIDEnable
= true;
3287 sgv
.InstanceIDComponentNumber
= 3;
3288 sgv
.InstanceIDElementOffset
= cso
->count
;
3294 iris_emit_cmd(batch
, GENX(3DSTATE_VF
), vf
) {
3295 if (draw
->primitive_restart
) {
3296 vf
.IndexedDrawCutIndexEnable
= true;
3297 vf
.CutIndex
= draw
->restart_index
;
3302 // XXX: Gen8 - PMA fix
3304 #define _3DPRIM_END_OFFSET 0x2420
3305 #define _3DPRIM_START_VERTEX 0x2430
3306 #define _3DPRIM_VERTEX_COUNT 0x2434
3307 #define _3DPRIM_INSTANCE_COUNT 0x2438
3308 #define _3DPRIM_START_INSTANCE 0x243C
3309 #define _3DPRIM_BASE_VERTEX 0x2440
3311 if (draw
->indirect
) {
3312 /* We don't support this MultidrawIndirect. */
3313 assert(!draw
->indirect
->indirect_draw_count
);
3315 struct iris_bo
*bo
= iris_resource_bo(draw
->indirect
->buffer
);
3318 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3319 lrm
.RegisterAddress
= _3DPRIM_VERTEX_COUNT
;
3320 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 0);
3322 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3323 lrm
.RegisterAddress
= _3DPRIM_INSTANCE_COUNT
;
3324 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 4);
3326 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3327 lrm
.RegisterAddress
= _3DPRIM_START_VERTEX
;
3328 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 8);
3330 if (draw
->index_size
) {
3331 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3332 lrm
.RegisterAddress
= _3DPRIM_BASE_VERTEX
;
3333 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
3335 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3336 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
3337 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 16);
3340 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
3341 lrm
.RegisterAddress
= _3DPRIM_START_INSTANCE
;
3342 lrm
.MemoryAddress
= ro_bo(bo
, draw
->indirect
->offset
+ 12);
3344 iris_emit_cmd(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
3345 lri
.RegisterOffset
= _3DPRIM_BASE_VERTEX
;
3351 iris_emit_cmd(batch
, GENX(3DPRIMITIVE
), prim
) {
3352 prim
.StartInstanceLocation
= draw
->start_instance
;
3353 prim
.InstanceCount
= draw
->instance_count
;
3354 prim
.VertexCountPerInstance
= draw
->count
;
3355 prim
.VertexAccessType
= draw
->index_size
> 0 ? RANDOM
: SEQUENTIAL
;
3357 // XXX: this is probably bonkers.
3358 prim
.StartVertexLocation
= draw
->start
;
3360 prim
.IndirectParameterEnable
= draw
->indirect
!= NULL
;
3362 if (draw
->index_size
) {
3363 prim
.BaseVertexLocation
+= draw
->index_bias
;
3365 prim
.StartVertexLocation
+= draw
->index_bias
;
3368 //prim.BaseVertexLocation = ...;
3371 if (!batch
->contains_draw
) {
3372 iris_restore_context_saved_bos(ice
, batch
, draw
);
3373 batch
->contains_draw
= true;
3378 * State module teardown.
3381 iris_destroy_state(struct iris_context
*ice
)
3383 iris_free_vertex_buffers(&ice
->state
.genx
->vertex_buffers
);
3385 // XXX: unreference resources/surfaces.
3386 for (unsigned i
= 0; i
< ice
->state
.framebuffer
.nr_cbufs
; i
++) {
3387 pipe_surface_reference(&ice
->state
.framebuffer
.cbufs
[i
], NULL
);
3389 pipe_surface_reference(&ice
->state
.framebuffer
.zsbuf
, NULL
);
3391 for (int stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
3392 pipe_resource_reference(&ice
->state
.sampler_table
[stage
].res
, NULL
);
3394 free(ice
->state
.genx
);
3396 pipe_resource_reference(&ice
->state
.last_res
.cc_vp
, NULL
);
3397 pipe_resource_reference(&ice
->state
.last_res
.sf_cl_vp
, NULL
);
3398 pipe_resource_reference(&ice
->state
.last_res
.color_calc
, NULL
);
3399 pipe_resource_reference(&ice
->state
.last_res
.scissor
, NULL
);
3400 pipe_resource_reference(&ice
->state
.last_res
.blend
, NULL
);
3404 flags_to_post_sync_op(uint32_t flags
)
3406 if (flags
& PIPE_CONTROL_WRITE_IMMEDIATE
)
3407 return WriteImmediateData
;
3409 if (flags
& PIPE_CONTROL_WRITE_DEPTH_COUNT
)
3410 return WritePSDepthCount
;
3412 if (flags
& PIPE_CONTROL_WRITE_TIMESTAMP
)
3413 return WriteTimestamp
;
3419 * Do the given flags have a Post Sync or LRI Post Sync operation?
3421 static enum pipe_control_flags
3422 get_post_sync_flags(enum pipe_control_flags flags
)
3424 flags
&= PIPE_CONTROL_WRITE_IMMEDIATE
|
3425 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
3426 PIPE_CONTROL_WRITE_TIMESTAMP
|
3427 PIPE_CONTROL_LRI_POST_SYNC_OP
;
3429 /* Only one "Post Sync Op" is allowed, and it's mutually exclusive with
3430 * "LRI Post Sync Operation". So more than one bit set would be illegal.
3432 assert(util_bitcount(flags
) <= 1);
3437 // XXX: compute support
3438 #define IS_COMPUTE_PIPELINE(batch) (batch->ring != I915_EXEC_RENDER)
3441 * Emit a series of PIPE_CONTROL commands, taking into account any
3442 * workarounds necessary to actually accomplish the caller's request.
3444 * Unless otherwise noted, spec quotations in this function come from:
3446 * Synchronization of the 3D Pipeline > PIPE_CONTROL Command > Programming
3447 * Restrictions for PIPE_CONTROL.
3450 iris_emit_raw_pipe_control(struct iris_batch
*batch
, uint32_t flags
,
3451 struct iris_bo
*bo
, uint32_t offset
, uint64_t imm
)
3453 UNUSED
const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
3454 enum pipe_control_flags post_sync_flags
= get_post_sync_flags(flags
);
3455 enum pipe_control_flags non_lri_post_sync_flags
=
3456 post_sync_flags
& ~PIPE_CONTROL_LRI_POST_SYNC_OP
;
3458 /* Recursive PIPE_CONTROL workarounds --------------------------------
3459 * (http://knowyourmeme.com/memes/xzibit-yo-dawg)
3461 * We do these first because we want to look at the original operation,
3462 * rather than any workarounds we set.
3464 if (GEN_GEN
== 9 && (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
)) {
3465 /* The PIPE_CONTROL "VF Cache Invalidation Enable" bit description
3466 * lists several workarounds:
3468 * "Project: SKL, KBL, BXT
3470 * If the VF Cache Invalidation Enable is set to a 1 in a
3471 * PIPE_CONTROL, a separate Null PIPE_CONTROL, all bitfields
3472 * sets to 0, with the VF Cache Invalidation Enable set to 0
3473 * needs to be sent prior to the PIPE_CONTROL with VF Cache
3474 * Invalidation Enable set to a 1."
3476 iris_emit_raw_pipe_control(batch
, 0, NULL
, 0, 0);
3479 if (GEN_GEN
== 9 && IS_COMPUTE_PIPELINE(batch
) && post_sync_flags
) {
3480 /* Project: SKL / Argument: LRI Post Sync Operation [23]
3482 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
3483 * programmed prior to programming a PIPECONTROL command with "LRI
3484 * Post Sync Operation" in GPGPU mode of operation (i.e when
3485 * PIPELINE_SELECT command is set to GPGPU mode of operation)."
3487 * The same text exists a few rows below for Post Sync Op.
3489 iris_emit_raw_pipe_control(batch
, PIPE_CONTROL_CS_STALL
, bo
, offset
, imm
);
3492 if (GEN_GEN
== 10 && (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
)) {
3494 * "Before sending a PIPE_CONTROL command with bit 12 set, SW must issue
3495 * another PIPE_CONTROL with Render Target Cache Flush Enable (bit 12)
3496 * = 0 and Pipe Control Flush Enable (bit 7) = 1"
3498 iris_emit_raw_pipe_control(batch
, PIPE_CONTROL_FLUSH_ENABLE
, bo
,
3502 /* "Flush Types" workarounds ---------------------------------------------
3503 * We do these now because they may add post-sync operations or CS stalls.
3506 if (flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
) {
3507 /* Project: BDW, SKL+ (stopping at CNL) / Argument: VF Invalidate
3509 * "'Post Sync Operation' must be enabled to 'Write Immediate Data' or
3510 * 'Write PS Depth Count' or 'Write Timestamp'."
3513 flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
3514 post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
3515 non_lri_post_sync_flags
|= PIPE_CONTROL_WRITE_IMMEDIATE
;
3516 bo
= batch
->screen
->workaround_bo
;
3520 /* #1130 from Gen10 workarounds page:
3522 * "Enable Depth Stall on every Post Sync Op if Render target Cache
3523 * Flush is not enabled in same PIPE CONTROL and Enable Pixel score
3524 * board stall if Render target cache flush is enabled."
3526 * Applicable to CNL B0 and C0 steppings only.
3528 * The wording here is unclear, and this workaround doesn't look anything
3529 * like the internal bug report recommendations, but leave it be for now...
3531 if (GEN_GEN
== 10) {
3532 if (flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
) {
3533 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
3534 } else if (flags
& non_lri_post_sync_flags
) {
3535 flags
|= PIPE_CONTROL_DEPTH_STALL
;
3539 if (flags
& PIPE_CONTROL_DEPTH_STALL
) {
3540 /* From the PIPE_CONTROL instruction table, bit 13 (Depth Stall Enable):
3542 * "This bit must be DISABLED for operations other than writing
3545 * This seems like nonsense. An Ivybridge workaround requires us to
3546 * emit a PIPE_CONTROL with a depth stall and write immediate post-sync
3547 * operation. Gen8+ requires us to emit depth stalls and depth cache
3548 * flushes together. So, it's hard to imagine this means anything other
3549 * than "we originally intended this to be used for PS_DEPTH_COUNT".
3551 * We ignore the supposed restriction and do nothing.
3555 if (flags
& (PIPE_CONTROL_RENDER_TARGET_FLUSH
|
3556 PIPE_CONTROL_STALL_AT_SCOREBOARD
)) {
3557 /* From the PIPE_CONTROL instruction table, bit 12 and bit 1:
3559 * "This bit must be DISABLED for End-of-pipe (Read) fences,
3560 * PS_DEPTH_COUNT or TIMESTAMP queries."
3562 * TODO: Implement end-of-pipe checking.
3564 assert(!(post_sync_flags
& (PIPE_CONTROL_WRITE_DEPTH_COUNT
|
3565 PIPE_CONTROL_WRITE_TIMESTAMP
)));
3568 if (flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
) {
3569 /* From the PIPE_CONTROL instruction table, bit 1:
3571 * "This bit is ignored if Depth Stall Enable is set.
3572 * Further, the render cache is not flushed even if Write Cache
3573 * Flush Enable bit is set."
3575 * We assert that the caller doesn't do this combination, to try and
3576 * prevent mistakes. It shouldn't hurt the GPU, though.
3578 assert(!(flags
& (PIPE_CONTROL_DEPTH_STALL
|
3579 PIPE_CONTROL_RENDER_TARGET_FLUSH
)));
3582 /* PIPE_CONTROL page workarounds ------------------------------------- */
3584 if (GEN_GEN
<= 8 && (flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
)) {
3585 /* From the PIPE_CONTROL page itself:
3588 * Restriction: Pipe_control with CS-stall bit set must be issued
3589 * before a pipe-control command that has the State Cache
3590 * Invalidate bit set."
3592 flags
|= PIPE_CONTROL_CS_STALL
;
3595 if (flags
& PIPE_CONTROL_FLUSH_LLC
) {
3596 /* From the PIPE_CONTROL instruction table, bit 26 (Flush LLC):
3599 * SW must always program Post-Sync Operation to "Write Immediate
3600 * Data" when Flush LLC is set."
3602 * For now, we just require the caller to do it.
3604 assert(flags
& PIPE_CONTROL_WRITE_IMMEDIATE
);
3607 /* "Post-Sync Operation" workarounds -------------------------------- */
3609 /* Project: All / Argument: Global Snapshot Count Reset [19]
3611 * "This bit must not be exercised on any product.
3612 * Requires stall bit ([20] of DW1) set."
3614 * We don't use this, so we just assert that it isn't used. The
3615 * PIPE_CONTROL instruction page indicates that they intended this
3616 * as a debug feature and don't think it is useful in production,
3617 * but it may actually be usable, should we ever want to.
3619 assert((flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
) == 0);
3621 if (flags
& (PIPE_CONTROL_MEDIA_STATE_CLEAR
|
3622 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
)) {
3623 /* Project: All / Arguments:
3625 * - Generic Media State Clear [16]
3626 * - Indirect State Pointers Disable [16]
3628 * "Requires stall bit ([20] of DW1) set."
3630 * Also, the PIPE_CONTROL instruction table, bit 16 (Generic Media
3631 * State Clear) says:
3633 * "PIPECONTROL command with “Command Streamer Stall Enable” must be
3634 * programmed prior to programming a PIPECONTROL command with "Media
3635 * State Clear" set in GPGPU mode of operation"
3637 * This is a subset of the earlier rule, so there's nothing to do.
3639 flags
|= PIPE_CONTROL_CS_STALL
;
3642 if (flags
& PIPE_CONTROL_STORE_DATA_INDEX
) {
3643 /* Project: All / Argument: Store Data Index
3645 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
3648 * For now, we just assert that the caller does this. We might want to
3649 * automatically add a write to the workaround BO...
3651 assert(non_lri_post_sync_flags
!= 0);
3654 if (flags
& PIPE_CONTROL_SYNC_GFDT
) {
3655 /* Project: All / Argument: Sync GFDT
3657 * "Post-Sync Operation ([15:14] of DW1) must be set to something other
3658 * than '0' or 0x2520[13] must be set."
3660 * For now, we just assert that the caller does this.
3662 assert(non_lri_post_sync_flags
!= 0);
3665 if (flags
& PIPE_CONTROL_TLB_INVALIDATE
) {
3666 /* Project: IVB+ / Argument: TLB inv
3668 * "Requires stall bit ([20] of DW1) set."
3670 * Also, from the PIPE_CONTROL instruction table:
3673 * Post Sync Operation or CS stall must be set to ensure a TLB
3674 * invalidation occurs. Otherwise no cycle will occur to the TLB
3675 * cache to invalidate."
3677 * This is not a subset of the earlier rule, so there's nothing to do.
3679 flags
|= PIPE_CONTROL_CS_STALL
;
3682 if (GEN_GEN
== 9 && devinfo
->gt
== 4) {
3683 /* TODO: The big Skylake GT4 post sync op workaround */
3686 /* "GPGPU specific workarounds" (both post-sync and flush) ------------ */
3688 if (IS_COMPUTE_PIPELINE(batch
)) {
3689 if (GEN_GEN
>= 9 && (flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
)) {
3690 /* Project: SKL+ / Argument: Tex Invalidate
3691 * "Requires stall bit ([20] of DW) set for all GPGPU Workloads."
3693 flags
|= PIPE_CONTROL_CS_STALL
;
3696 if (GEN_GEN
== 8 && (post_sync_flags
||
3697 (flags
& (PIPE_CONTROL_NOTIFY_ENABLE
|
3698 PIPE_CONTROL_DEPTH_STALL
|
3699 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
3700 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
3701 PIPE_CONTROL_DATA_CACHE_FLUSH
)))) {
3702 /* Project: BDW / Arguments:
3704 * - LRI Post Sync Operation [23]
3705 * - Post Sync Op [15:14]
3707 * - Depth Stall [13]
3708 * - Render Target Cache Flush [12]
3709 * - Depth Cache Flush [0]
3710 * - DC Flush Enable [5]
3712 * "Requires stall bit ([20] of DW) set for all GPGPU and Media
3715 flags
|= PIPE_CONTROL_CS_STALL
;
3717 /* Also, from the PIPE_CONTROL instruction table, bit 20:
3720 * This bit must be always set when PIPE_CONTROL command is
3721 * programmed by GPGPU and MEDIA workloads, except for the cases
3722 * when only Read Only Cache Invalidation bits are set (State
3723 * Cache Invalidation Enable, Instruction cache Invalidation
3724 * Enable, Texture Cache Invalidation Enable, Constant Cache
3725 * Invalidation Enable). This is to WA FFDOP CG issue, this WA
3726 * need not implemented when FF_DOP_CG is disable via "Fixed
3727 * Function DOP Clock Gate Disable" bit in RC_PSMI_CTRL register."
3729 * It sounds like we could avoid CS stalls in some cases, but we
3730 * don't currently bother. This list isn't exactly the list above,
3736 /* "Stall" workarounds ----------------------------------------------
3737 * These have to come after the earlier ones because we may have added
3738 * some additional CS stalls above.
3741 if (GEN_GEN
< 9 && (flags
& PIPE_CONTROL_CS_STALL
)) {
3742 /* Project: PRE-SKL, VLV, CHV
3744 * "[All Stepping][All SKUs]:
3746 * One of the following must also be set:
3748 * - Render Target Cache Flush Enable ([12] of DW1)
3749 * - Depth Cache Flush Enable ([0] of DW1)
3750 * - Stall at Pixel Scoreboard ([1] of DW1)
3751 * - Depth Stall ([13] of DW1)
3752 * - Post-Sync Operation ([13] of DW1)
3753 * - DC Flush Enable ([5] of DW1)"
3755 * If we don't already have one of those bits set, we choose to add
3756 * "Stall at Pixel Scoreboard". Some of the other bits require a
3757 * CS stall as a workaround (see above), which would send us into
3758 * an infinite recursion of PIPE_CONTROLs. "Stall at Pixel Scoreboard"
3759 * appears to be safe, so we choose that.
3761 const uint32_t wa_bits
= PIPE_CONTROL_RENDER_TARGET_FLUSH
|
3762 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
3763 PIPE_CONTROL_WRITE_IMMEDIATE
|
3764 PIPE_CONTROL_WRITE_DEPTH_COUNT
|
3765 PIPE_CONTROL_WRITE_TIMESTAMP
|
3766 PIPE_CONTROL_STALL_AT_SCOREBOARD
|
3767 PIPE_CONTROL_DEPTH_STALL
|
3768 PIPE_CONTROL_DATA_CACHE_FLUSH
;
3769 if (!(flags
& wa_bits
))
3770 flags
|= PIPE_CONTROL_STALL_AT_SCOREBOARD
;
3773 /* Emit --------------------------------------------------------------- */
3775 iris_emit_cmd(batch
, GENX(PIPE_CONTROL
), pc
) {
3776 pc
.LRIPostSyncOperation
= NoLRIOperation
;
3777 pc
.PipeControlFlushEnable
= flags
& PIPE_CONTROL_FLUSH_ENABLE
;
3778 pc
.DCFlushEnable
= flags
& PIPE_CONTROL_DATA_CACHE_FLUSH
;
3779 pc
.StoreDataIndex
= 0;
3780 pc
.CommandStreamerStallEnable
= flags
& PIPE_CONTROL_CS_STALL
;
3781 pc
.GlobalSnapshotCountReset
=
3782 flags
& PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
;
3783 pc
.TLBInvalidate
= flags
& PIPE_CONTROL_TLB_INVALIDATE
;
3784 pc
.GenericMediaStateClear
= flags
& PIPE_CONTROL_MEDIA_STATE_CLEAR
;
3785 pc
.StallAtPixelScoreboard
= flags
& PIPE_CONTROL_STALL_AT_SCOREBOARD
;
3786 pc
.RenderTargetCacheFlushEnable
=
3787 flags
& PIPE_CONTROL_RENDER_TARGET_FLUSH
;
3788 pc
.DepthCacheFlushEnable
= flags
& PIPE_CONTROL_DEPTH_CACHE_FLUSH
;
3789 pc
.StateCacheInvalidationEnable
=
3790 flags
& PIPE_CONTROL_STATE_CACHE_INVALIDATE
;
3791 pc
.VFCacheInvalidationEnable
= flags
& PIPE_CONTROL_VF_CACHE_INVALIDATE
;
3792 pc
.ConstantCacheInvalidationEnable
=
3793 flags
& PIPE_CONTROL_CONST_CACHE_INVALIDATE
;
3794 pc
.PostSyncOperation
= flags_to_post_sync_op(flags
);
3795 pc
.DepthStallEnable
= flags
& PIPE_CONTROL_DEPTH_STALL
;
3796 pc
.InstructionCacheInvalidateEnable
=
3797 flags
& PIPE_CONTROL_INSTRUCTION_INVALIDATE
;
3798 pc
.NotifyEnable
= flags
& PIPE_CONTROL_NOTIFY_ENABLE
;
3799 pc
.IndirectStatePointersDisable
=
3800 flags
& PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
;
3801 pc
.TextureCacheInvalidationEnable
=
3802 flags
& PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
3803 pc
.Address
= ro_bo(bo
, offset
);
3804 pc
.ImmediateData
= imm
;
3809 genX(init_state
)(struct iris_context
*ice
)
3811 struct pipe_context
*ctx
= &ice
->ctx
;
3812 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
3814 ctx
->create_blend_state
= iris_create_blend_state
;
3815 ctx
->create_depth_stencil_alpha_state
= iris_create_zsa_state
;
3816 ctx
->create_rasterizer_state
= iris_create_rasterizer_state
;
3817 ctx
->create_sampler_state
= iris_create_sampler_state
;
3818 ctx
->create_sampler_view
= iris_create_sampler_view
;
3819 ctx
->create_surface
= iris_create_surface
;
3820 ctx
->create_vertex_elements_state
= iris_create_vertex_elements
;
3821 ctx
->create_compute_state
= iris_create_compute_state
;
3822 ctx
->bind_blend_state
= iris_bind_blend_state
;
3823 ctx
->bind_depth_stencil_alpha_state
= iris_bind_zsa_state
;
3824 ctx
->bind_sampler_states
= iris_bind_sampler_states
;
3825 ctx
->bind_rasterizer_state
= iris_bind_rasterizer_state
;
3826 ctx
->bind_vertex_elements_state
= iris_bind_vertex_elements_state
;
3827 ctx
->bind_compute_state
= iris_bind_compute_state
;
3828 ctx
->delete_blend_state
= iris_delete_state
;
3829 ctx
->delete_depth_stencil_alpha_state
= iris_delete_state
;
3830 ctx
->delete_fs_state
= iris_delete_state
;
3831 ctx
->delete_rasterizer_state
= iris_delete_state
;
3832 ctx
->delete_sampler_state
= iris_delete_state
;
3833 ctx
->delete_vertex_elements_state
= iris_delete_state
;
3834 ctx
->delete_compute_state
= iris_delete_state
;
3835 ctx
->delete_tcs_state
= iris_delete_state
;
3836 ctx
->delete_tes_state
= iris_delete_state
;
3837 ctx
->delete_gs_state
= iris_delete_state
;
3838 ctx
->delete_vs_state
= iris_delete_state
;
3839 ctx
->set_blend_color
= iris_set_blend_color
;
3840 ctx
->set_clip_state
= iris_set_clip_state
;
3841 ctx
->set_constant_buffer
= iris_set_constant_buffer
;
3842 ctx
->set_shader_buffers
= iris_set_shader_buffers
;
3843 ctx
->set_sampler_views
= iris_set_sampler_views
;
3844 ctx
->set_framebuffer_state
= iris_set_framebuffer_state
;
3845 ctx
->set_polygon_stipple
= iris_set_polygon_stipple
;
3846 ctx
->set_sample_mask
= iris_set_sample_mask
;
3847 ctx
->set_scissor_states
= iris_set_scissor_states
;
3848 ctx
->set_stencil_ref
= iris_set_stencil_ref
;
3849 ctx
->set_vertex_buffers
= iris_set_vertex_buffers
;
3850 ctx
->set_viewport_states
= iris_set_viewport_states
;
3851 ctx
->sampler_view_destroy
= iris_sampler_view_destroy
;
3852 ctx
->surface_destroy
= iris_surface_destroy
;
3853 ctx
->draw_vbo
= iris_draw_vbo
;
3854 ctx
->launch_grid
= iris_launch_grid
;
3855 ctx
->create_stream_output_target
= iris_create_stream_output_target
;
3856 ctx
->stream_output_target_destroy
= iris_stream_output_target_destroy
;
3857 ctx
->set_stream_output_targets
= iris_set_stream_output_targets
;
3859 ice
->vtbl
.destroy_state
= iris_destroy_state
;
3860 ice
->vtbl
.init_render_context
= iris_init_render_context
;
3861 ice
->vtbl
.upload_render_state
= iris_upload_render_state
;
3862 ice
->vtbl
.emit_raw_pipe_control
= iris_emit_raw_pipe_control
;
3863 ice
->vtbl
.derived_program_state_size
= iris_derived_program_state_size
;
3864 ice
->vtbl
.store_derived_program_state
= iris_store_derived_program_state
;
3865 ice
->vtbl
.create_so_decl_list
= iris_create_so_decl_list
;
3866 ice
->vtbl
.populate_vs_key
= iris_populate_vs_key
;
3867 ice
->vtbl
.populate_tcs_key
= iris_populate_tcs_key
;
3868 ice
->vtbl
.populate_tes_key
= iris_populate_tes_key
;
3869 ice
->vtbl
.populate_gs_key
= iris_populate_gs_key
;
3870 ice
->vtbl
.populate_fs_key
= iris_populate_fs_key
;
3872 ice
->state
.dirty
= ~0ull;
3874 ice
->state
.num_viewports
= 1;
3875 ice
->state
.genx
= calloc(1, sizeof(struct iris_genx_state
));
3877 /* Make a 1x1x1 null surface for unbound textures */
3878 void *null_surf_map
=
3879 upload_state(ice
->state
.surface_uploader
, &ice
->state
.unbound_tex
,
3880 4 * GENX(RENDER_SURFACE_STATE_length
), 64);
3881 isl_null_fill_state(&screen
->isl_dev
, null_surf_map
, isl_extent3d(1, 1, 1));