From a0ee1ac2b7a459ef26082bc386cbe71f77798bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ondra=C4=8Dka?= Date: Fri, 5 Apr 2024 21:12:54 +0200 Subject: [PATCH] r300: replace constant size field with usemask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To have more flexibility in case there are some empty slots (e.g., if the specific slot was converted to inline constant or constant swizzle). Signed-off-by: Pavel Ondračka Reviewed-by: Filip Gawin Part-of: --- .../drivers/r300/compiler/radeon_code.c | 32 +++++++++++-------- .../drivers/r300/compiler/radeon_code.h | 2 +- src/gallium/drivers/r300/r300_tgsi_to_rc.c | 4 +-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/gallium/drivers/r300/compiler/radeon_code.c b/src/gallium/drivers/r300/compiler/radeon_code.c index 4cb40f49027..1c7e4800d82 100644 --- a/src/gallium/drivers/r300/compiler/radeon_code.c +++ b/src/gallium/drivers/r300/compiler/radeon_code.c @@ -77,7 +77,7 @@ unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state0, un memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_STATE; - constant.Size = 4; + constant.UseMask = RC_MASK_XYZW; constant.u.State[0] = state0; constant.u.State[1] = state1; @@ -103,7 +103,7 @@ unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const floa memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_IMMEDIATE; - constant.Size = 4; + constant.UseMask = RC_MASK_XYZW; memcpy(constant.u.Immediate, data, sizeof(float) * 4); return rc_constants_add(c, &constant); @@ -116,35 +116,39 @@ unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const floa */ unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle) { - unsigned index; + unsigned index, free_comp; int free_index = -1; struct rc_constant constant; for(index = 0; index < c->Count; ++index) { if (c->Constants[index].Type == RC_CONSTANT_IMMEDIATE) { unsigned comp; - for(comp = 0; comp < c->Constants[index].Size; ++comp) { - if (c->Constants[index].u.Immediate[comp] == data) { - *swizzle = RC_MAKE_SWIZZLE_SMEAR(comp); - return index; + for(comp = 0; comp < 4; ++comp) { + if (c->Constants[index].UseMask & 1 << comp) { + if (c->Constants[index].u.Immediate[comp] == data) { + *swizzle = RC_MAKE_SWIZZLE_SMEAR(comp); + return index; + } + } else { + if (free_index == -1) { + free_index = index; + free_comp = comp; + } } } - - if (c->Constants[index].Size < 4) - free_index = index; } } if (free_index >= 0) { - unsigned comp = c->Constants[free_index].Size++; - c->Constants[free_index].u.Immediate[comp] = data; - *swizzle = RC_MAKE_SWIZZLE_SMEAR(comp); + c->Constants[free_index].u.Immediate[free_comp] = data; + c->Constants[free_index].UseMask |= 1 << free_comp; + *swizzle = RC_MAKE_SWIZZLE_SMEAR(free_comp); return free_index; } memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_IMMEDIATE; - constant.Size = 1; + constant.UseMask = RC_MASK_X; constant.u.Immediate[0] = data; *swizzle = RC_SWIZZLE_XXXX; diff --git a/src/gallium/drivers/r300/compiler/radeon_code.h b/src/gallium/drivers/r300/compiler/radeon_code.h index 048b75e4c96..0a56bda7a72 100644 --- a/src/gallium/drivers/r300/compiler/radeon_code.h +++ b/src/gallium/drivers/r300/compiler/radeon_code.h @@ -58,7 +58,7 @@ enum { struct rc_constant { unsigned Type:2; /**< RC_CONSTANT_xxx */ - unsigned Size:3; + unsigned UseMask:4; union { unsigned External; diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index 3947d4ea51d..7903fa7486b 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -241,7 +241,7 @@ static void handle_immediate(struct tgsi_to_rc * ttr, struct rc_constant constant; constant.Type = RC_CONSTANT_IMMEDIATE; - constant.Size = 4; + constant.UseMask = RC_MASK_XYZW; for (unsigned i = 0; i < 4; ++i) constant.u.Immediate[i] = imm->u[i].Float; rc_constants_add(&ttr->compiler->Program.Constants, &constant); @@ -264,7 +264,7 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, struct rc_constant constant; memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_EXTERNAL; - constant.Size = 4; + constant.UseMask = RC_MASK_XYZW; constant.u.External = i; rc_constants_add(&ttr->compiler->Program.Constants, &constant); }