const int block = block_const->u32[0];
const int offset = offset_const->u32[0] / 32;
- /* Won't fit in our bitfield */
+ /* Avoid shifting by larger than the width of our bitfield, as this
+ * is undefined in C. Even if we require multiple bits to represent
+ * the entire value, it's OK to record a partial value - the backend
+ * is capable of falling back to pull loads for later components of
+ * vectors, as it has to shrink ranges for other reasons anyway.
+ */
if (offset >= 64)
continue;
+ /* The value might span multiple 32-byte chunks. */
+ const int bytes = nir_intrinsic_dest_components(intrin) *
+ (nir_dest_bit_size(intrin->dest) / 8);
+ const int start = ROUND_DOWN_TO(offset_const->u32[0], 32);
+ const int end = ALIGN(offset_const->u32[0] + bytes, 32);
+ const int chunks = (end - start) / 32;
+
/* TODO: should we count uses in loops as higher benefit? */
struct ubo_block_info *info = get_block_info(state, block);
- info->offsets |= 1ull << offset;
+ info->offsets |= ((1ull << chunks) - 1) << offset;
info->uses[offset]++;
}
}