From 2d0e8e0258004f09e3e5d6b2998c2eb0110ddc7d Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Tue, 30 May 2023 19:22:48 +0800 Subject: [PATCH] aco: use ac_get_image_dim for array check when image intrinsic This is to avoid missing array flag when <=GFX8 and 3D image in which case is treated as 2D array image. Reviewed-by: Rhys Perry Signed-off-by: Qiang Yu Part-of: --- src/amd/compiler/aco_instruction_selection.cpp | 31 +++++++++++++------------- src/amd/compiler/tests/test_d3d11_derivs.cpp | 6 ++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index 2b9c1bc..d18799f 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -5989,11 +5989,8 @@ emit_pack_v1(isel_context* ctx, const std::vector& unpacked) } static bool -should_declare_array(isel_context* ctx, enum glsl_sampler_dim sampler_dim, bool is_array) +should_declare_array(ac_image_dim dim) { - if (sampler_dim == GLSL_SAMPLER_DIM_BUF) - return false; - ac_image_dim dim = ac_get_sampler_dim(ctx->options->gfx_level, sampler_dim, is_array); return dim == ac_image_cube || dim == ac_image_1darray || dim == ac_image_2darray || dim == ac_image_2darraymsaa; } @@ -6349,8 +6346,9 @@ visit_image_load(isel_context* ctx, nir_intrinsic_instr* instr) load->da = is_array; load->sync = memory_sync_info(); } else { - load->dim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); - load->da = should_declare_array(ctx, dim, is_array); + ac_image_dim sdim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); + load->dim = sdim; + load->da = should_declare_array(sdim); load->sync = sync; } } @@ -6472,12 +6470,13 @@ visit_image_store(isel_context* ctx, nir_intrinsic_instr* instr) emit_mimg(bld, opcode, Temp(0, v1), resource, Operand(s4), coords, false, Operand(data)); store->glc = glc; store->dlc = false; - store->dim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); store->a16 = instr->src[1].ssa->bit_size == 16; store->d16 = d16; store->dmask = dmask; store->unrm = true; - store->da = should_declare_array(ctx, dim, is_array); + ac_image_dim sdim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); + store->dim = sdim; + store->da = should_declare_array(sdim); store->disable_wqm = true; store->sync = sync; ctx->program->needs_exact = true; @@ -6630,11 +6629,12 @@ visit_image_atomic(isel_context* ctx, nir_intrinsic_instr* instr) emit_mimg(bld, image_op, tmp, resource, Operand(s4), coords, false, Operand(data)); mimg->glc = return_previous; mimg->dlc = false; /* Not needed for atomics */ - mimg->dim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); mimg->dmask = (1 << data.size()) - 1; mimg->a16 = instr->src[1].ssa->bit_size == 16; mimg->unrm = true; - mimg->da = should_declare_array(ctx, dim, is_array); + ac_image_dim sdim = ac_get_image_dim(ctx->options->gfx_level, dim, is_array); + mimg->dim = sdim; + mimg->da = should_declare_array(sdim); mimg->disable_wqm = true; mimg->sync = sync; ctx->program->needs_exact = true; @@ -9469,7 +9469,12 @@ visit_tex(isel_context* ctx, nir_tex_instr* instr) has_derivs = true; } - bool da = should_declare_array(ctx, instr->sampler_dim, instr->is_array); + unsigned dim = 0; + bool da = false; + if (instr->sampler_dim != GLSL_SAMPLER_DIM_BUF) { + dim = ac_get_sampler_dim(ctx->options->gfx_level, instr->sampler_dim, instr->is_array); + da = should_declare_array((ac_image_dim)dim); + } /* Build tex instruction */ unsigned dmask = nir_ssa_def_components_read(&instr->dest.ssa) & 0xf; @@ -9477,10 +9482,6 @@ visit_tex(isel_context* ctx, nir_tex_instr* instr) dmask = u_bit_consecutive(0, util_last_bit(dmask)); if (instr->is_sparse) dmask = MAX2(dmask, 1) | 0x10; - unsigned dim = - ctx->options->gfx_level >= GFX10 && instr->sampler_dim != GLSL_SAMPLER_DIM_BUF - ? ac_get_sampler_dim(ctx->options->gfx_level, instr->sampler_dim, instr->is_array) - : 0; bool d16 = instr->dest.ssa.bit_size == 16; Temp dst = get_ssa_temp(ctx, &instr->dest.ssa); Temp tmp_dst = dst; diff --git a/src/amd/compiler/tests/test_d3d11_derivs.cpp b/src/amd/compiler/tests/test_d3d11_derivs.cpp index f2061c0..efb6493 100644 --- a/src/amd/compiler/tests/test_d3d11_derivs.cpp +++ b/src/amd/compiler/tests/test_d3d11_derivs.cpp @@ -203,7 +203,7 @@ BEGIN_TEST(d3d11_derivs.offset) //>> lv3: %wqm = p_start_linear_vgpr (kill)%vec //>> BB1 //>> v1: %offset = p_parallelcopy 0x201 - //>> v4: %_ = image_sample_o (kill)%_, (kill)%_, v1: undef, %wqm, (kill)%offset 1d + //>> v4: %_ = image_sample_o (kill)%_, (kill)%_, v1: undef, %wqm, (kill)%offset 2d //>> BB2 //>> BB6 //>> p_end_linear_vgpr (kill)%wqm @@ -333,7 +333,7 @@ BEGIN_TEST(d3d11_derivs.1d_gfx9) //>> v2: %vec = p_create_vector (kill)%x, 0.5 //>> lv2: %wqm = p_start_linear_vgpr (kill)%vec //>> BB1 - //>> v4: %_ = image_sample (kill)%_, (kill)%_, v1: undef, %wqm 1d + //>> v4: %_ = image_sample (kill)%_, (kill)%_, v1: undef, %wqm 2d //>> BB2 //>> BB6 //>> p_end_linear_vgpr (kill)%wqm @@ -373,7 +373,7 @@ BEGIN_TEST(d3d11_derivs.1d_array_gfx9) //>> v3: %vec = p_create_vector (kill)%x, 0.5, (kill)%layer //>> lv3: %wqm = p_start_linear_vgpr (kill)%vec //>> BB1 - //>> v4: %_ = image_sample (kill)%_, (kill)%_, v1: undef, %wqm 1d da + //>> v4: %_ = image_sample (kill)%_, (kill)%_, v1: undef, %wqm 2darray da //>> BB2 //>> BB6 //>> p_end_linear_vgpr (kill)%wqm -- 2.7.4