treewide: use uint64_t / (u)intptr_t in image address calculations
16K * 16K * 16bpp = 4G, which overflows int32, so layer_stride needs to have 64 bits. More generally, any "byte_stride * height" computation can overflow int32. Use (u)intptr_t in some gallium and st/mesa places where we do CPU access. Use uint64_t otherwise. Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23389>
This commit is contained in:
+18
-15
@@ -85,9 +85,12 @@ util_copy_rect(void * dst_in,
|
||||
src += src_y * src_stride_pos;
|
||||
width *= blocksize;
|
||||
|
||||
if (width == dst_stride && width == (unsigned)src_stride)
|
||||
memcpy(dst, src, height * width);
|
||||
else {
|
||||
if (width == dst_stride && width == (unsigned)src_stride) {
|
||||
uint64_t size = (uint64_t)height * width;
|
||||
|
||||
assert(size <= SIZE_MAX);
|
||||
memcpy(dst, src, size);
|
||||
} else {
|
||||
for (i = 0; i < height; i++) {
|
||||
memcpy(dst, src, width);
|
||||
dst += dst_stride;
|
||||
@@ -420,7 +423,7 @@ util_format_read_4(enum pipe_format format,
|
||||
assert(x % format_desc->block.width == 0);
|
||||
assert(y % format_desc->block.height == 0);
|
||||
|
||||
src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
|
||||
src_row = (const uint8_t *)src + (uint64_t)y*src_stride + x*(format_desc->block.bits/8);
|
||||
|
||||
util_format_unpack_rgba_rect(format, dst, dst_stride, src_row, src_stride, w, h);
|
||||
}
|
||||
@@ -442,7 +445,7 @@ util_format_write_4(enum pipe_format format,
|
||||
assert(x % format_desc->block.width == 0);
|
||||
assert(y % format_desc->block.height == 0);
|
||||
|
||||
dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
|
||||
dst_row = (uint8_t *)dst + (uint64_t)y*dst_stride + x*(format_desc->block.bits/8);
|
||||
|
||||
if (util_format_is_pure_uint(format))
|
||||
pack->pack_rgba_uint(dst_row, dst_stride, src, src_stride, w, h);
|
||||
@@ -464,7 +467,7 @@ util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride,
|
||||
assert(x % format_desc->block.width == 0);
|
||||
assert(y % format_desc->block.height == 0);
|
||||
|
||||
src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
|
||||
src_row = (const uint8_t *)src + (uint64_t)y*src_stride + x*(format_desc->block.bits/8);
|
||||
|
||||
util_format_unpack_rgba_8unorm_rect(format, dst, dst_stride, src_row, src_stride, w, h);
|
||||
}
|
||||
@@ -484,7 +487,7 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_
|
||||
assert(x % format_desc->block.width == 0);
|
||||
assert(y % format_desc->block.height == 0);
|
||||
|
||||
dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
|
||||
dst_row = (uint8_t *)dst + (uint64_t)y*dst_stride + x*(format_desc->block.bits/8);
|
||||
src_row = src;
|
||||
|
||||
pack->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
|
||||
@@ -680,8 +683,8 @@ util_format_translate(enum pipe_format dst_format,
|
||||
assert(src_x % src_format_desc->block.width == 0);
|
||||
assert(src_y % src_format_desc->block.height == 0);
|
||||
|
||||
dst_row = (uint8_t *)dst + dst_y*dst_stride + dst_x*(dst_format_desc->block.bits/8);
|
||||
src_row = (const uint8_t *)src + src_y*src_stride + src_x*(src_format_desc->block.bits/8);
|
||||
dst_row = (uint8_t *)dst + (uint64_t)dst_y*dst_stride + dst_x*(dst_format_desc->block.bits/8);
|
||||
src_row = (const uint8_t *)src + (uint64_t)src_y*src_stride + src_x*(src_format_desc->block.bits/8);
|
||||
|
||||
/*
|
||||
* This works because all pixel formats have pixel blocks with power of two
|
||||
@@ -750,7 +753,7 @@ util_format_translate(enum pipe_format dst_format,
|
||||
}
|
||||
|
||||
tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
|
||||
tmp_row = malloc(y_step * tmp_stride);
|
||||
tmp_row = malloc((uint64_t)y_step * tmp_stride);
|
||||
if (!tmp_row)
|
||||
return false;
|
||||
|
||||
@@ -781,7 +784,7 @@ util_format_translate(enum pipe_format dst_format,
|
||||
}
|
||||
|
||||
tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
|
||||
tmp_row = malloc(y_step * tmp_stride);
|
||||
tmp_row = malloc((uint64_t)y_step * tmp_stride);
|
||||
if (!tmp_row)
|
||||
return false;
|
||||
|
||||
@@ -812,7 +815,7 @@ util_format_translate(enum pipe_format dst_format,
|
||||
}
|
||||
|
||||
tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
|
||||
tmp_row = malloc(y_step * tmp_stride);
|
||||
tmp_row = malloc((uint64_t)y_step * tmp_stride);
|
||||
if (!tmp_row)
|
||||
return false;
|
||||
|
||||
@@ -842,7 +845,7 @@ util_format_translate(enum pipe_format dst_format,
|
||||
}
|
||||
|
||||
tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
|
||||
tmp_row = malloc(y_step * tmp_stride);
|
||||
tmp_row = malloc((uint64_t)y_step * tmp_stride);
|
||||
if (!tmp_row)
|
||||
return false;
|
||||
|
||||
@@ -868,12 +871,12 @@ util_format_translate(enum pipe_format dst_format,
|
||||
bool
|
||||
util_format_translate_3d(enum pipe_format dst_format,
|
||||
void *dst, unsigned dst_stride,
|
||||
unsigned dst_slice_stride,
|
||||
uint64_t dst_slice_stride,
|
||||
unsigned dst_x, unsigned dst_y,
|
||||
unsigned dst_z,
|
||||
enum pipe_format src_format,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned src_slice_stride,
|
||||
uint64_t src_slice_stride,
|
||||
unsigned src_x, unsigned src_y,
|
||||
unsigned src_z, unsigned width,
|
||||
unsigned height, unsigned depth)
|
||||
|
||||
+10
-10
@@ -914,28 +914,28 @@ util_format_get_nblocksz(enum pipe_format format,
|
||||
return (z + blockdepth - 1) / blockdepth;
|
||||
}
|
||||
|
||||
static inline unsigned
|
||||
static inline uint64_t
|
||||
util_format_get_nblocks(enum pipe_format format,
|
||||
unsigned width,
|
||||
unsigned height)
|
||||
{
|
||||
assert(util_format_get_blockdepth(format) == 1);
|
||||
return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height);
|
||||
return (uint64_t)util_format_get_nblocksx(format, width) *
|
||||
util_format_get_nblocksy(format, height);
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
static inline unsigned
|
||||
util_format_get_stride(enum pipe_format format,
|
||||
unsigned width)
|
||||
{
|
||||
return (size_t)util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
|
||||
return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
util_format_get_2d_size(enum pipe_format format,
|
||||
size_t stride,
|
||||
static inline uint64_t
|
||||
util_format_get_2d_size(enum pipe_format format, unsigned stride,
|
||||
unsigned height)
|
||||
{
|
||||
return util_format_get_nblocksy(format, height) * stride;
|
||||
return (uint64_t)util_format_get_nblocksy(format, height) * stride;
|
||||
}
|
||||
|
||||
static inline unsigned
|
||||
@@ -1646,12 +1646,12 @@ util_format_translate(enum pipe_format dst_format,
|
||||
bool
|
||||
util_format_translate_3d(enum pipe_format dst_format,
|
||||
void *dst, unsigned dst_stride,
|
||||
unsigned dst_slice_stride,
|
||||
uint64_t dst_slice_stride,
|
||||
unsigned dst_x, unsigned dst_y,
|
||||
unsigned dst_z,
|
||||
enum pipe_format src_format,
|
||||
const void *src, unsigned src_stride,
|
||||
unsigned src_slice_stride,
|
||||
uint64_t src_slice_stride,
|
||||
unsigned src_x, unsigned src_y,
|
||||
unsigned src_z, unsigned width,
|
||||
unsigned height, unsigned depth);
|
||||
|
||||
Reference in New Issue
Block a user