From 4d49a7ac737f298b136ab6447e18c6e4654f8ad5 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 6 Jan 2020 10:21:04 +0100 Subject: [PATCH] aco: handle nir_intrinsic_image_deref_{load,store} with lod MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use image_load_mip and image_store_mip respectively if the lod parameter isn't zero. Signed-off-by: Samuel Pitoiset Reviewed-by: Daniel Schürmann Reviewed-by: Bas Nieuwenhuizen --- .../compiler/aco_instruction_selection.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index bf8da815750..00310c0975b 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -4078,6 +4078,15 @@ static Temp get_image_coords(isel_context *ctx, const nir_intrinsic_instr *instr coords[i] = Operand(emit_extract_vector(ctx, src0, i, v1)); } + if (instr->intrinsic == nir_intrinsic_image_deref_load || + instr->intrinsic == nir_intrinsic_image_deref_store) { + int lod_index = instr->intrinsic == nir_intrinsic_image_deref_load ? 3 : 4; + bool level_zero = nir_src_is_const(instr->src[lod_index]) && nir_src_as_uint(instr->src[lod_index]) == 0; + + if (!level_zero) + coords.emplace_back(Operand(get_ssa_temp(ctx, instr->src[lod_index].ssa))); + } + aco_ptr vec{create_instruction(aco_opcode::p_create_vector, Format::PSEUDO, coords.size(), 1)}; for (unsigned i = 0; i < coords.size(); i++) vec->operands[i] = coords[i]; @@ -4151,7 +4160,10 @@ void visit_image_load(isel_context *ctx, nir_intrinsic_instr *instr) else tmp = {ctx->program->allocateId(), RegClass(RegType::vgpr, num_components)}; - aco_ptr load{create_instruction(aco_opcode::image_load, Format::MIMG, 2, 1)}; + bool level_zero = nir_src_is_const(instr->src[3]) && nir_src_as_uint(instr->src[3]) == 0; + aco_opcode opcode = level_zero ? aco_opcode::image_load : aco_opcode::image_load_mip; + + aco_ptr load{create_instruction(opcode, Format::MIMG, 2, 1)}; load->operands[0] = Operand(coords); load->operands[1] = Operand(resource); load->definitions[0] = Definition(tmp); @@ -4217,7 +4229,10 @@ void visit_image_store(isel_context *ctx, nir_intrinsic_instr *instr) Temp coords = get_image_coords(ctx, instr, type); Temp resource = get_sampler_desc(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr), ACO_DESC_IMAGE, nullptr, true, true); - aco_ptr store{create_instruction(aco_opcode::image_store, Format::MIMG, 4, 0)}; + bool level_zero = nir_src_is_const(instr->src[4]) && nir_src_as_uint(instr->src[4]) == 0; + aco_opcode opcode = level_zero ? aco_opcode::image_store : aco_opcode::image_store_mip; + + aco_ptr store{create_instruction(opcode, Format::MIMG, 4, 0)}; store->operands[0] = Operand(coords); store->operands[1] = Operand(resource); store->operands[2] = Operand(s4); -- 2.30.2