From 0bc7562466cb6ad212caa7c2060c53c3b88ffc2d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 14 Dec 2021 15:25:26 -0800 Subject: [PATCH] iris: Do primitive ID overrides in 3DSTATE_SBE not SBE_SWIZ Broadwell introduced new fields in 3DSTATE_SBE which allow us to ask the hardware to override Primitive ID for us, rather than requiring us to turn on attribute swizzling and specify per-attribute overrides in 3DSTATE_SBE_SWIZ. We unconditionally enable attribute swizzling today, but this is a step toward letting us think about disabling it in the future. Reviewed-by: Caio Oliveira Part-of: --- src/gallium/drivers/iris/iris_state.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index 63812c464df..f07302d0382 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -4095,18 +4095,6 @@ iris_emit_sbe_swiz(struct iris_batch *batch, attr->ComponentOverrideZ = true; continue; - case VARYING_SLOT_PRIMITIVE_ID: - /* Override if the previous shader stage didn't write gl_PrimitiveID. */ - if (slot == -1) { - attr->ComponentOverrideX = true; - attr->ComponentOverrideY = true; - attr->ComponentOverrideZ = true; - attr->ComponentOverrideW = true; - attr->ConstantSource = PRIM_ID; - continue; - } - break; - default: break; } @@ -4231,6 +4219,19 @@ iris_emit_sbe(struct iris_batch *batch, const struct iris_context *ice) sbe.AttributeActiveComponentFormat[i] = ACTIVE_COMPONENT_XYZW; } #endif + + /* Ask the hardware to supply PrimitiveID if the fragment shader + * reads it but a previous stage didn't write one. + */ + if ((wm_prog_data->inputs & VARYING_BIT_PRIMITIVE_ID) && + last_vue_map->varying_to_slot[VARYING_SLOT_PRIMITIVE_ID] == -1) { + sbe.PrimitiveIDOverrideAttributeSelect = + wm_prog_data->urb_setup[VARYING_SLOT_PRIMITIVE_ID]; + sbe.PrimitiveIDOverrideComponentX = true; + sbe.PrimitiveIDOverrideComponentY = true; + sbe.PrimitiveIDOverrideComponentZ = true; + sbe.PrimitiveIDOverrideComponentW = true; + } } iris_emit_sbe_swiz(batch, ice, last_vue_map, urb_read_offset,