X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fnir%2Fnir_format_convert.h;h=a9de69e695fcb416acefc142c5175c0ccf195c38;hb=41e4eb9948d0ca62e9586b491c720a1a05904802;hp=9c8d0d21e0a89b694b7d7ee04a9740950a2e7196;hpb=4407e688cdf65b1a25f09bcfdb577d5c175aeb9a;p=mesa.git diff --git a/src/compiler/nir/nir_format_convert.h b/src/compiler/nir/nir_format_convert.h index 9c8d0d21e0a..a9de69e695f 100644 --- a/src/compiler/nir/nir_format_convert.h +++ b/src/compiler/nir/nir_format_convert.h @@ -53,10 +53,11 @@ nir_mask_shift_or(struct nir_builder *b, nir_ssa_def *dst, nir_ssa_def *src, static inline nir_ssa_def * nir_format_mask_uvec(nir_builder *b, nir_ssa_def *src, const unsigned *bits) { - nir_const_value mask; + nir_const_value mask[NIR_MAX_VEC_COMPONENTS]; + memset(mask, 0, sizeof(mask)); for (unsigned i = 0; i < src->num_components; i++) { assert(bits[i] < 32); - mask.u32[i] = (1u << bits[i]) - 1; + mask[i].u32 = (1u << bits[i]) - 1; } return nir_iand(b, src, nir_build_imm(b, src->num_components, 32, mask)); } @@ -90,19 +91,24 @@ nir_format_unpack_int(nir_builder *b, nir_ssa_def *packed, return packed; } + unsigned next_chan = 0; unsigned offset = 0; for (unsigned i = 0; i < num_components; i++) { assert(bits[i] < bit_size); assert(offset + bits[i] <= bit_size); + nir_ssa_def *chan = nir_channel(b, packed, next_chan); nir_ssa_def *lshift = nir_imm_int(b, bit_size - (offset + bits[i])); nir_ssa_def *rshift = nir_imm_int(b, bit_size - bits[i]); if (sign_extend) - comps[i] = nir_ishr(b, nir_ishl(b, packed, lshift), rshift); + comps[i] = nir_ishr(b, nir_ishl(b, chan, lshift), rshift); else - comps[i] = nir_ushr(b, nir_ishl(b, packed, lshift), rshift); + comps[i] = nir_ushr(b, nir_ishl(b, chan, lshift), rshift); offset += bits[i]; + if (offset >= bit_size) { + next_chan++; + offset -= bit_size; + } } - assert(offset <= bit_size); return nir_vec(b, comps, num_components); } @@ -205,10 +211,11 @@ _nir_format_norm_factor(nir_builder *b, const unsigned *bits, unsigned num_components, bool is_signed) { - nir_const_value factor; + nir_const_value factor[NIR_MAX_VEC_COMPONENTS]; + memset(factor, 0, sizeof(factor)); for (unsigned i = 0; i < num_components; i++) { - assert(bits[i] < 32); - factor.f32[i] = (1ul << (bits[i] - is_signed)) - 1; + assert(bits[i] <= 32); + factor[i].f32 = (1ull << (bits[i] - is_signed)) - 1; } return nir_build_imm(b, num_components, 32, factor); } @@ -304,10 +311,11 @@ nir_format_clamp_uint(nir_builder *b, nir_ssa_def *f, const unsigned *bits) if (bits[0] == 32) return f; - nir_const_value max; + nir_const_value max[NIR_MAX_VEC_COMPONENTS]; + memset(max, 0, sizeof(max)); for (unsigned i = 0; i < f->num_components; i++) { assert(bits[i] < 32); - max.i32[i] = (1 << (bits[i] - 1)) - 1; + max[i].u32 = (1 << bits[i]) - 1; } return nir_umin(b, f, nir_build_imm(b, f->num_components, 32, max)); } @@ -321,11 +329,13 @@ nir_format_clamp_sint(nir_builder *b, nir_ssa_def *f, const unsigned *bits) if (bits[0] == 32) return f; - nir_const_value min, max; + nir_const_value min[NIR_MAX_VEC_COMPONENTS], max[NIR_MAX_VEC_COMPONENTS]; + memset(min, 0, sizeof(min)); + memset(max, 0, sizeof(max)); for (unsigned i = 0; i < f->num_components; i++) { assert(bits[i] < 32); - max.i32[i] = (1 << (bits[i] - 1)) - 1; - min.i32[i] = -(1 << (bits[i] - 1)); + max[i].i32 = (1 << (bits[i] - 1)) - 1; + min[i].i32 = -(1 << (bits[i] - 1)); } f = nir_imin(b, f, nir_build_imm(b, f->num_components, 32, max)); f = nir_imax(b, f, nir_build_imm(b, f->num_components, 32, min));