From 421bf657bf33200b1aa97d7ae887971e561ef556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ondra=C4=8Dka?= Date: Mon, 2 Jan 2023 17:23:44 +0100 Subject: [PATCH] r300: don't convert to constant swizzles when translating from TGSI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Filip Gawin Tested-by: Filip Gawin Part-of: --- .../drivers/r300/ci/r300-r480-fails.txt | 3 -- src/gallium/drivers/r300/r300_fs.c | 1 - src/gallium/drivers/r300/r300_tgsi_to_rc.c | 54 ++----------------- src/gallium/drivers/r300/r300_tgsi_to_rc.h | 6 --- src/gallium/drivers/r300/r300_vs.c | 1 - 5 files changed, 5 insertions(+), 60 deletions(-) diff --git a/src/gallium/drivers/r300/ci/r300-r480-fails.txt b/src/gallium/drivers/r300/ci/r300-r480-fails.txt index 097ec698524..b08ff8104e2 100644 --- a/src/gallium/drivers/r300/ci/r300-r480-fails.txt +++ b/src/gallium/drivers/r300/ci/r300-r480-fails.txt @@ -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 diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index 13abe6fe031..94a5505e3c6 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -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); diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index b1e2dd1627e..3068f78125e 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -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); } diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.h b/src/gallium/drivers/r300/r300_tgsi_to_rc.h index 21f35e15ca2..551b4de18d2 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.h +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.h @@ -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; diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c index 76413b0a040..dfa26de1c84 100644 --- a/src/gallium/drivers/r300/r300_vs.c +++ b/src/gallium/drivers/r300/r300_vs.c @@ -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);