From: Rob Clark Date: Thu, 7 May 2020 18:09:17 +0000 (-0700) Subject: freedreno/ir3: don't allow negative const_offset X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c4dc877cb5df63a6a86013e32695f72c604625ad;p=mesa.git freedreno/ir3: don't allow negative const_offset Signed-off-by: Rob Clark Part-of: --- diff --git a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c index d2fe65cd0e3..d8a285073f1 100644 --- a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c +++ b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c @@ -143,7 +143,7 @@ gather_ubo_ranges(nir_shader *nir, nir_intrinsic_instr *instr, * with (ie. not requiring value range tracking) */ static void -handle_partial_const(nir_builder *b, nir_ssa_def **srcp, unsigned *offp) +handle_partial_const(nir_builder *b, nir_ssa_def **srcp, int *offp) { if ((*srcp)->parent_instr->type != nir_instr_type_alu) return; @@ -233,7 +233,7 @@ lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b, } nir_ssa_def *ubo_offset = nir_ssa_for_src(b, instr->src[1], 1); - unsigned const_offset = 0; + int const_offset = 0; handle_partial_const(b, &ubo_offset, &const_offset); @@ -262,9 +262,20 @@ lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b, const_offset >>= 2; } - const int range_offset = (range->offset - range->start) / 4; + const int range_offset = ((int)range->offset - (int)range->start) / 4; const_offset += range_offset; + /* The range_offset could be negative, if if only part of the UBO + * block is accessed, range->start can be greater than range->offset. + * But we can't underflow const_offset. If necessary we need to + * insert nir instructions to compensate (which can hopefully be + * optimized away) + */ + if (const_offset < 0) { + uniform_offset = nir_iadd_imm(b, uniform_offset, const_offset); + const_offset = 0; + } + nir_intrinsic_instr *uniform = nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_uniform); uniform->num_components = instr->num_components;