vc4: use unsigned types when performing bitshifting
Ensure unsigned integers of proper size are used instead of signed ones when performing left bit shifts. This has been detected by the Undefined Behaviour Sanitizer (UBSan). Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29911>
This commit is contained in:

committed by
Marge Bot

parent
1bcf9c5da9
commit
5e09b2b3f3
@@ -126,7 +126,7 @@ enum vc4_packet {
|
||||
/* Size of a full resolution color or Z tile buffer load/store. */
|
||||
#define VC4_TILE_BUFFER_SIZE (64 * 64 * 4)
|
||||
|
||||
#define VC4_MASK(high, low) (((1 << ((high) - (low) + 1)) - 1) << (low))
|
||||
#define VC4_MASK(high, low) (((1u << ((high) - (low) + 1)) - 1) << (low))
|
||||
/* Using the GNU statement expression extension */
|
||||
#define VC4_SET_FIELD(value, field) \
|
||||
({ \
|
||||
|
@@ -130,7 +130,7 @@ static nir_def *
|
||||
vc4_nir_set_packed_chan(nir_builder *b, nir_def *src0, nir_def *src1,
|
||||
int chan)
|
||||
{
|
||||
unsigned chan_mask = 0xff << (chan * 8);
|
||||
unsigned chan_mask = 0xffu << (chan * 8);
|
||||
return nir_ior(b,
|
||||
nir_iand_imm(b, src0, ~chan_mask),
|
||||
nir_iand_imm(b, src1, chan_mask));
|
||||
@@ -492,7 +492,7 @@ vc4_nir_blend_pipeline(struct vc4_compile *c, nir_builder *b, nir_def *src,
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (format_swiz[i] < 4 &&
|
||||
!(c->fs_key->blend.colormask & (1 << format_swiz[i]))) {
|
||||
colormask &= ~(0xff << (i * 8));
|
||||
colormask &= ~(0xffu << (i * 8));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -260,12 +260,12 @@ vc4_create_depth_stencil_alpha_state(struct pipe_context *pctx,
|
||||
back_writemask_bits =
|
||||
tlb_stencil_setup_writemask(back->writemask);
|
||||
|
||||
so->stencil_uniforms[0] |= (1 << 30);
|
||||
so->stencil_uniforms[0] |= (UINT32_C(1) << 30);
|
||||
so->stencil_uniforms[1] =
|
||||
tlb_stencil_setup_bits(back, back_writemask_bits);
|
||||
so->stencil_uniforms[1] |= (2 << 30);
|
||||
so->stencil_uniforms[1] |= (UINT32_C(2) << 30);
|
||||
} else {
|
||||
so->stencil_uniforms[0] |= (3 << 30);
|
||||
so->stencil_uniforms[0] |= (UINT32_C(3) << 30);
|
||||
}
|
||||
|
||||
if (front_writemask_bits == 0xff ||
|
||||
|
@@ -72,20 +72,20 @@ swizzle_lt_x(int x, int cpp)
|
||||
switch (cpp) {
|
||||
case 1:
|
||||
/* 8x8 inside of 4x4 */
|
||||
return ((x & 0x7) << (0 - 0) |
|
||||
(x & ~0x7) << (6 - 3));
|
||||
return (((uint32_t)x & 0x7) << (0 - 0) |
|
||||
((uint32_t)x & ~0x7) << (6 - 3));
|
||||
case 2:
|
||||
/* 8x4 inside of 4x4 */
|
||||
return ((x & 0x7) << (1 - 0) |
|
||||
(x & ~0x7) << (6 - 3));
|
||||
return (((uint32_t)x & 0x7) << (1 - 0) |
|
||||
((uint32_t)x & ~0x7) << (6 - 3));
|
||||
case 4:
|
||||
/* 4x4 inside of 4x4 */
|
||||
return ((x & 0x3) << (2 - 0) |
|
||||
(x & ~0x3) << (6 - 2));
|
||||
return (((uint32_t)x & 0x3) << (2 - 0) |
|
||||
((uint32_t)x & ~0x3) << (6 - 2));
|
||||
case 8:
|
||||
/* 2x4 inside of 4x4 */
|
||||
return ((x & 0x1) << (3 - 0) |
|
||||
(x & ~0x1) << (6 - 1));
|
||||
return (((uint32_t)x & 0x1) << (3 - 0) |
|
||||
((uint32_t)x & ~0x1) << (6 - 1));
|
||||
default:
|
||||
unreachable("bad cpp");
|
||||
}
|
||||
|
@@ -316,7 +316,7 @@ vc4_write_uniforms(struct vc4_context *vc4, struct vc4_compiled_shader *shader,
|
||||
if (format_swiz[i] >= 4)
|
||||
continue;
|
||||
|
||||
color |= (vc4->blend_color.ub[format_swiz[i]] <<
|
||||
color |= ((uint32_t)vc4->blend_color.ub[format_swiz[i]] <<
|
||||
(i * 8));
|
||||
}
|
||||
cl_aligned_u32(&uniforms, color);
|
||||
@@ -324,7 +324,7 @@ vc4_write_uniforms(struct vc4_context *vc4, struct vc4_compiled_shader *shader,
|
||||
}
|
||||
|
||||
case QUNIFORM_BLEND_CONST_COLOR_AAAA: {
|
||||
uint8_t a = vc4->blend_color.ub[3];
|
||||
uint32_t a = vc4->blend_color.ub[3];
|
||||
cl_aligned_u32(&uniforms, ((a) |
|
||||
(a << 8) |
|
||||
(a << 16) |
|
||||
|
Reference in New Issue
Block a user