From: Dave Airlie Date: Tue, 7 Apr 2020 05:06:26 +0000 (+1000) Subject: gallivm/nir: fix image store conversions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13e5f331db77b8c353981469a95e5557e3e2073a;p=mesa.git gallivm/nir: fix image store conversions This fixes a few of the image store paths, to do the correct clamping of unsigned/signed values Fixes: KHR-GLES31.core.layout_binding.block_layout_binding_block_ComputeShader KHR-GL45.shader_image_load_store.basic-allFormats-store KHR-GL46.shader_image_load_store.multiple-uniforms Reviewed-by: Roland Scheidegger Part-of: --- diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c index ab130deb151..1fad4bc6fc6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c @@ -879,17 +879,23 @@ lp_build_insert_soa_chan(struct lp_build_context *bld, struct lp_type type = bld->type; const unsigned width = chan_desc.size; const unsigned start = chan_desc.shift; + const uint32_t chan_mask = (1ULL << width) - 1; ASSERTED const unsigned stop = start + width; LLVMValueRef chan = NULL; switch(chan_desc.type) { case UTIL_FORMAT_TYPE_UNSIGNED: - if (chan_desc.pure_integer) + if (chan_desc.pure_integer) { chan = LLVMBuildBitCast(builder, rgba, bld->int_vec_type, ""); + LLVMValueRef mask_val = lp_build_const_int_vec(gallivm, type, chan_mask); + LLVMValueRef mask = LLVMBuildICmp(builder, LLVMIntUGT, chan, mask_val, ""); + chan = LLVMBuildSelect(builder, mask, mask_val, chan, ""); + } else if (type.floating) { - if (chan_desc.normalized) + if (chan_desc.normalized) { + rgba = lp_build_clamp(bld, rgba, bld->zero, bld->one); chan = lp_build_clamped_float_to_unsigned_norm(gallivm, type, width, rgba); - else + } else chan = LLVMBuildFPToSI(builder, rgba, bld->vec_type, ""); } if (start) @@ -901,10 +907,10 @@ lp_build_insert_soa_chan(struct lp_build_context *bld, *output = LLVMBuildOr(builder, *output, chan, ""); break; case UTIL_FORMAT_TYPE_SIGNED: - if (chan_desc.pure_integer) + if (chan_desc.pure_integer) { chan = LLVMBuildBitCast(builder, rgba, bld->int_vec_type, ""); - else if (type.floating) { - uint32_t mask_val = (1UL << chan_desc.size) - 1; + chan = LLVMBuildAnd(builder, chan, lp_build_const_int_vec(gallivm, type, chan_mask), ""); + } else if (type.floating) { if (chan_desc.normalized) { char intrin[32]; double scale = ((1 << (chan_desc.size - 1)) - 1); @@ -915,7 +921,7 @@ lp_build_insert_soa_chan(struct lp_build_context *bld, rgba = lp_build_intrinsic_unary(builder, intrin, bld->vec_type, rgba); } chan = LLVMBuildFPToSI(builder, rgba, bld->int_vec_type, ""); - chan = LLVMBuildAnd(builder, chan, lp_build_const_int_vec(gallivm, type, mask_val), ""); + chan = LLVMBuildAnd(builder, chan, lp_build_const_int_vec(gallivm, type, chan_mask), ""); } if (start) chan = LLVMBuildShl(builder, chan,