r300: don't convert to constant swizzles when translating from TGSI

We currently convert it twice for unknown reasons, first when
translating from TGSI and later in constant folding. Not only is this
unnecessary, the first translation doesn't check for non-native
swizzles, so removing it actually saves few instructions and gains
a single Unigine shader for R300 at the expense of few more constant
loads and temps.

Also fixes few dEQPs because we could previously generate code like
TEX temp[1], none.01__, 2D[0];
and the native swizzle rewrite pass was not ready for it.

RV370 shader-db:

total instructions in shared programs: 84441 -> 84436 (<.01%)
instructions in affected programs: 63 -> 58 (-7.94%)
helped: 4
HURT: 0

total temps in shared programs: 12398 -> 12400 (0.02%)
temps in affected programs: 10 -> 12 (20.00%)
helped: 1
HURT: 3

total consts in shared programs: 79081 -> 79090 (0.01%)
consts in affected programs: 12 -> 21 (75.00%)
helped: 0
HURT: 7

GAINED: shaders/tropics/465.shader_test FS

No shader-db change with RV530.

Signed-off-by: Pavel Ondračka <pavel.ondracka@gmail.com>
Reviewed-by: Filip Gawin <filip@gawin.net>
Tested-by: Filip Gawin <filip@gawin.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20484>
This commit is contained in:
Pavel Ondračka
2023-01-02 17:23:44 +01:00
committed by Marge Bot
parent 7decc7efba
commit 421bf657bf
5 changed files with 5 additions and 60 deletions

View File

@@ -616,11 +616,8 @@ dEQP-GLES2.functional.shaders.loops.while_uniform_iterations.unconditional_conti
dEQP-GLES2.functional.shaders.loops.while_uniform_iterations.unconditional_continue_vertex,Fail
dEQP-GLES2.functional.shaders.loops.while_uniform_iterations.vector_counter_fragment,Fail
dEQP-GLES2.functional.shaders.loops.while_uniform_iterations.vector_counter_vertex,Fail
dEQP-GLES2.functional.shaders.random.all_features.fragment.1,Fail
dEQP-GLES2.functional.shaders.random.all_features.fragment.5,Fail
dEQP-GLES2.functional.shaders.random.all_features.fragment.6,Fail
dEQP-GLES2.functional.shaders.random.texture.fragment.141,Fail
dEQP-GLES2.functional.shaders.random.texture.fragment.42,Fail
dEQP-GLES2.functional.shaders.return.return_in_dynamic_loop_dynamic_fragment,Fail
dEQP-GLES2.functional.shaders.return.return_in_dynamic_loop_dynamic_vertex,Fail
dEQP-GLES2.functional.shaders.return.return_in_dynamic_loop_never_fragment,Fail

View File

@@ -463,7 +463,6 @@ static void r300_translate_fragment_shader(
/* Translate TGSI to our internal representation */
ttr.compiler = &compiler.Base;
ttr.info = &shader->info;
ttr.use_half_swizzles = TRUE;
r300_tgsi_to_rc(&ttr, tokens);

View File

@@ -175,8 +175,6 @@ static void transform_srcreg(
struct rc_src_register * dst,
struct tgsi_full_src_register * src)
{
unsigned i, j;
dst->File = translate_register_file(src->Register.File);
dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index);
dst->RelAddr = src->Register.Indirect;
@@ -186,21 +184,6 @@ static void transform_srcreg(
dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 3) << 9;
dst->Abs = src->Register.Absolute;
dst->Negate = src->Register.Negate ? RC_MASK_XYZW : 0;
if (src->Register.File == TGSI_FILE_IMMEDIATE) {
for (i = 0; i < ttr->imms_to_swizzle_count; i++) {
if (ttr->imms_to_swizzle[i].index == src->Register.Index) {
dst->File = RC_FILE_TEMPORARY;
dst->Index = 0;
dst->Swizzle = 0;
for (j = 0; j < 4; j++) {
dst->Swizzle |= GET_SWZ(ttr->imms_to_swizzle[i].swizzle,
tgsi_util_get_full_src_register_swizzle(src, j)) << (j * 3);
}
break;
}
}
}
}
static void transform_texture(struct rc_instruction * dst, struct tgsi_instruction_texture src,
@@ -301,34 +284,12 @@ static void handle_immediate(struct tgsi_to_rc * ttr,
unsigned index)
{
struct rc_constant constant;
unsigned swizzle = 0;
boolean can_swizzle = TRUE;
unsigned i;
for (i = 0; i < 4; i++) {
if (imm->u[i].Float == 0.0f) {
swizzle |= RC_SWIZZLE_ZERO << (i * 3);
} else if (imm->u[i].Float == 0.5f && ttr->use_half_swizzles) {
swizzle |= RC_SWIZZLE_HALF << (i * 3);
} else if (imm->u[i].Float == 1.0f) {
swizzle |= RC_SWIZZLE_ONE << (i * 3);
} else {
can_swizzle = FALSE;
break;
}
}
if (can_swizzle) {
ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].index = index;
ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].swizzle = swizzle;
ttr->imms_to_swizzle_count++;
} else {
constant.Type = RC_CONSTANT_IMMEDIATE;
constant.Size = 4;
for(i = 0; i < 4; ++i)
constant.u.Immediate[i] = imm->u[i].Float;
rc_constants_add(&ttr->compiler->Program.Constants, &constant);
}
constant.Type = RC_CONSTANT_IMMEDIATE;
constant.Size = 4;
for (unsigned i = 0; i < 4; ++i)
constant.u.Immediate[i] = imm->u[i].Float;
rc_constants_add(&ttr->compiler->Program.Constants, &constant);
}
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr,
@@ -355,9 +316,6 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr,
ttr->immediate_offset = ttr->compiler->Program.Constants.Count;
ttr->imms_to_swizzle = malloc(ttr->info->immediate_count * sizeof(struct swizzled_imms));
ttr->imms_to_swizzle_count = 0;
tgsi_parse_init(&parser, tokens);
while (!tgsi_parse_end_of_tokens(&parser)) {
@@ -383,7 +341,5 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr,
tgsi_parse_free(&parser);
free(ttr->imms_to_swizzle);
rc_calculate_inputs_outputs(ttr->compiler);
}

View File

@@ -41,12 +41,6 @@ struct tgsi_to_rc {
const struct tgsi_shader_info * info;
int immediate_offset;
struct swizzled_imms * imms_to_swizzle;
unsigned imms_to_swizzle_count;
/* Vertex shaders have no half swizzles, and no way to handle them, so
* until rc grows proper support, indicate if they're safe to use. */
boolean use_half_swizzles;
/* If an error occurred. */
boolean error;

View File

@@ -214,7 +214,6 @@ void r300_translate_vertex_shader(struct r300_context *r300,
/* Translate TGSI to our internal representation */
ttr.compiler = &compiler.Base;
ttr.info = &vs->info;
ttr.use_half_swizzles = FALSE;
r300_tgsi_to_rc(&ttr, shader->state.tokens);