From c4d465a514ffa739c4ca27e83a8ff80f992ec3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 27 May 2023 02:31:59 -0400 Subject: [PATCH] radeonsi: add helpers to create and clone a sized pm4 state to simplify si_init_cs_preamble_state and it will be used in the following commits Reviewed-by: Qiang Yu Part-of: --- src/gallium/drivers/radeonsi/si_pm4.c | 20 ++++++++++++++++++++ src/gallium/drivers/radeonsi/si_pm4.h | 2 ++ src/gallium/drivers/radeonsi/si_state.c | 16 +++------------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_pm4.c b/src/gallium/drivers/radeonsi/si_pm4.c index dddf56b8a2f..52af57dc47e 100644 --- a/src/gallium/drivers/radeonsi/si_pm4.c +++ b/src/gallium/drivers/radeonsi/si_pm4.c @@ -153,3 +153,23 @@ void si_pm4_reset_emitted(struct si_context *sctx) sctx->dirty_states |= BITFIELD_BIT(i); } } + +struct si_pm4_state *si_pm4_create_sized(unsigned max_dw) +{ + struct si_pm4_state *pm4; + unsigned size = sizeof(*pm4) + 4 * (max_dw - ARRAY_SIZE(pm4->pm4)); + + pm4 = (struct si_pm4_state *)calloc(1, size); + if (pm4) + pm4->max_dw = max_dw; + return pm4; +} + +struct si_pm4_state *si_pm4_clone(struct si_pm4_state *orig) +{ + struct si_pm4_state *pm4 = si_pm4_create_sized(orig->max_dw); + + if (pm4) + memcpy(pm4, orig, sizeof(*pm4) + 4 * (pm4->max_dw - ARRAY_SIZE(pm4->pm4))); + return pm4; +} diff --git a/src/gallium/drivers/radeonsi/si_pm4.h b/src/gallium/drivers/radeonsi/si_pm4.h index 38f34d186a0..483b8881453 100644 --- a/src/gallium/drivers/radeonsi/si_pm4.h +++ b/src/gallium/drivers/radeonsi/si_pm4.h @@ -57,6 +57,8 @@ void si_pm4_free_state(struct si_context *sctx, struct si_pm4_state *state, unsi void si_pm4_emit(struct si_context *sctx, struct si_pm4_state *state); void si_pm4_reset_emitted(struct si_context *sctx); +struct si_pm4_state *si_pm4_create_sized(unsigned max_dw); +struct si_pm4_state *si_pm4_clone(struct si_pm4_state *orig); #ifdef __cplusplus } diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 1a7a8d48594..bf356fda855 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -5547,18 +5547,11 @@ void si_init_cs_preamble_state(struct si_context *sctx, bool uses_reg_shadowing) S_00B858_SH1_CU_EN(sscreen->info.spi_cu_en); bool has_clear_state = sscreen->info.has_clear_state; - struct si_cs_preamble { - struct si_pm4_state pm4; - uint32_t more_pm4[150]; /* Add more space because the preamble is large. */ - }; - struct si_pm4_state *pm4 = (struct si_pm4_state *)CALLOC_STRUCT(si_cs_preamble); - + /* We need more space because the preamble is large. */ + struct si_pm4_state *pm4 = si_pm4_create_sized(214); if (!pm4) return; - /* Add all the space that we allocated. */ - pm4->max_dw = (sizeof(struct si_cs_preamble) - offsetof(struct si_cs_preamble, pm4.pm4)) / 4; - if (sctx->has_graphics && !uses_reg_shadowing) { si_pm4_cmd_add(pm4, PKT3(PKT3_CONTEXT_CONTROL, 1, 0)); si_pm4_cmd_add(pm4, CC0_UPDATE_LOAD_ENABLES(1)); @@ -6032,8 +6025,5 @@ void si_init_cs_preamble_state(struct si_context *sctx, bool uses_reg_shadowing) done: sctx->cs_preamble_state = pm4; - - /* Make a copy of the preamble for TMZ. */ - sctx->cs_preamble_state_tmz = (struct si_pm4_state *)CALLOC_STRUCT(si_cs_preamble); - memcpy(sctx->cs_preamble_state_tmz, sctx->cs_preamble_state, sizeof(struct si_cs_preamble)); + sctx->cs_preamble_state_tmz = si_pm4_clone(pm4); /* Make a copy of the preamble for TMZ. */ }