From 0776628d1d3656ccfc4a09c4f20335a627c349b6 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 22 Jul 2021 13:20:29 +1000 Subject: [PATCH] gallivm/nir: handle conversion to 16-bit texel fetch Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index a5914484a91..8d2cbc0ce48 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -27,6 +27,7 @@ #include "lp_bld_arit.h" #include "lp_bld_bitarit.h" #include "lp_bld_const.h" +#include "lp_bld_conv.h" #include "lp_bld_gather.h" #include "lp_bld_logic.h" #include "lp_bld_quad.h" @@ -2170,8 +2171,12 @@ static void visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *inst if (nir_dest_bit_size(instr->dest) != 32) { assert(nir_dest_bit_size(instr->dest) == 16); - LLVMTypeRef vec_type; + LLVMTypeRef vec_type = NULL; + bool is_float = false; switch (nir_alu_type_get_base_type(instr->dest_type)) { + case nir_type_float: + is_float = true; + break; case nir_type_int: vec_type = bld_base->int16_bld.vec_type; break; @@ -2182,12 +2187,17 @@ static void visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *inst unreachable("unexpected alu type"); } for (int i = 0; i < nir_dest_num_components(instr->dest); ++i) { - texel[i] = LLVMBuildBitCast(builder, texel[i], bld_base->int_bld.vec_type, ""); - texel[i] = LLVMBuildTrunc(builder, texel[i], vec_type, ""); + if (is_float) { + texel[i] = lp_build_float_to_half(gallivm, texel[i]); + } else { + texel[i] = LLVMBuildBitCast(builder, texel[i], bld_base->int_bld.vec_type, ""); + texel[i] = LLVMBuildTrunc(builder, texel[i], vec_type, ""); + } } } assign_dest(bld_base, &instr->dest, texel); + } static void visit_ssa_undef(struct lp_build_nir_context *bld_base,