From 835c5b7ebf382ea246ed3437332ac8217c7bf897 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 31 Mar 2021 17:46:52 +0100 Subject: [PATCH] aco: fix integer tg4 workaround with unnormalized coordinates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same as LLVM from 2abf62d3483afd8f0de7f19d114d164de4741127. fossil-db (GFX8): Totals from 15 (0.01% of 147787) affected shaders: VGPRs: 744 -> 748 (+0.54%) CodeSize: 100472 -> 100732 (+0.26%) Instrs: 19995 -> 20059 (+0.32%) Latency: 1001530 -> 1001859 (+0.03%) InvThroughput: 378508 -> 378747 (+0.06%) SClause: 676 -> 675 (-0.15%) Copies: 1655 -> 1654 (-0.06%) PreSGPRs: 735 -> 742 (+0.95%) Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_instruction_selection.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index cf8d8c1aa1b..e921c70da86 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -9036,6 +9036,24 @@ void visit_tex(isel_context *ctx, nir_tex_instr *instr) half_texel[i] = bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), Operand(0xbf000000/*-0.5*/), half_texel[i]); } + if (instr->sampler_dim == GLSL_SAMPLER_DIM_2D && !instr->is_array) { + /* In vulkan, whether the sampler uses unnormalized + * coordinates or not is a dynamic property of the + * sampler. Hence, to figure out whether or not we + * need to divide by the texture size, we need to test + * the sampler at runtime. This tests the bit set by + * radv_init_sampler(). + */ + unsigned bit_idx = ffs(S_008F30_FORCE_UNNORMALIZED(1)) - 1; + Temp not_needed = bld.sopc(aco_opcode::s_bitcmp0_b32, bld.def(s1, scc), sampler, Operand(bit_idx)); + + not_needed = bool_to_vector_condition(ctx, not_needed); + half_texel[0] = bld.vop2(aco_opcode::v_cndmask_b32, bld.def(v1), + Operand(0xbf000000/*-0.5*/), half_texel[0], not_needed); + half_texel[1] = bld.vop2(aco_opcode::v_cndmask_b32, bld.def(v1), + Operand(0xbf000000/*-0.5*/), half_texel[1], not_needed); + } + Temp new_coords[2] = { bld.vop2(aco_opcode::v_add_f32, bld.def(v1), coords[0], half_texel[0]), bld.vop2(aco_opcode::v_add_f32, bld.def(v1), coords[1], half_texel[1])