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:
Marek Olšák 2023-06-02 04:01:40 -04:00 committed by Marge Bot
parent d72d13bbb5
commit 68735f4e86
41 changed files with 103 additions and 91 deletions

View file

@ -1807,7 +1807,7 @@ dd_context_texture_subdata(struct pipe_context *_pipe,
unsigned level, unsigned usage,
const struct pipe_box *box,
const void *data, unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;

View file

@ -170,7 +170,7 @@ struct call_texture_subdata {
struct pipe_box box;
const void *data;
unsigned stride;
unsigned layer_stride;
uintptr_t layer_stride;
};
struct dd_call

View file

@ -269,7 +269,7 @@ static void noop_texture_subdata(struct pipe_context *pipe,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
}

View file

@ -1797,7 +1797,7 @@ trace_context_transfer_unmap(struct pipe_context *_context,
unsigned usage = transfer->usage;
const struct pipe_box *box = &transfer->box;
unsigned stride = transfer->stride;
unsigned layer_stride = transfer->layer_stride;
uintptr_t layer_stride = transfer->layer_stride;
if (resource->target == PIPE_BUFFER) {
unsigned offset = box->x;
@ -1896,7 +1896,7 @@ trace_context_texture_subdata(struct pipe_context *_context,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct trace_context *tr_context = trace_context(_context);
struct pipe_context *context = tr_context->pipe;

View file

@ -501,17 +501,18 @@ void trace_dump_box_bytes(const void *data,
struct pipe_resource *resource,
const struct pipe_box *box,
unsigned stride,
unsigned slice_stride)
uint64_t slice_stride)
{
enum pipe_format format = resource->format;
size_t size;
uint64_t size;
assert(box->height > 0);
assert(box->depth > 0);
size = util_format_get_nblocksx(format, box->width ) * util_format_get_blocksize(format)
+ (util_format_get_nblocksy(format, box->height) - 1) * stride
+ (box->depth - 1) * slice_stride;
size = util_format_get_nblocksx(format, box->width ) *
(uint64_t)util_format_get_blocksize(format) +
(util_format_get_nblocksy(format, box->height) - 1) *
(uint64_t)stride + (box->depth - 1) * slice_stride;
/*
* Only dump buffer transfers to avoid huge files.
@ -521,6 +522,7 @@ void trace_dump_box_bytes(const void *data,
size = 0;
}
assert(size <= SIZE_MAX);
trace_dump_bytes(data, size);
}

View file

@ -91,7 +91,7 @@ void trace_dump_box_bytes(const void *data,
struct pipe_resource *resource,
const struct pipe_box *box,
unsigned stride,
unsigned slice_stride);
uint64_t slice_stride);
void trace_dump_string(const char *str);
void trace_dump_enum(const char *value);
void trace_dump_array_begin(void);

View file

@ -64,11 +64,11 @@ u_surface_default_template(struct pipe_surface *surf,
void
util_copy_box(ubyte * dst,
enum pipe_format format,
unsigned dst_stride, unsigned dst_slice_stride,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const ubyte * src,
int src_stride, unsigned src_slice_stride,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z)
{
unsigned z;
@ -117,7 +117,7 @@ util_fill_rect(ubyte * dst,
height = (height + blockheight - 1)/blockheight;
dst += dst_x * blocksize;
dst += dst_y * dst_stride;
dst += (uint64_t)dst_y * dst_stride;
width_size = width * blocksize;
switch (blocksize) {
@ -169,7 +169,7 @@ void
util_fill_box(ubyte * dst,
enum pipe_format format,
unsigned stride,
unsigned layer_stride,
uintptr_t layer_stride,
unsigned x,
unsigned y,
unsigned z,
@ -475,7 +475,7 @@ util_fill_zs_rect(ubyte *dst_map,
case 1:
assert(format == PIPE_FORMAT_S8_UINT);
if(dst_stride == width)
memset(dst_map, (uint8_t) zstencil, height * width);
memset(dst_map, (uint8_t) zstencil, (uint64_t)height * width);
else {
for (i = 0; i < height; i++) {
memset(dst_map, (uint8_t) zstencil, width);

View file

@ -47,11 +47,11 @@ u_surface_default_template(struct pipe_surface *view,
extern void
util_copy_box(ubyte * dst,
enum pipe_format format,
unsigned dst_stride, unsigned dst_slice_stride,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const ubyte * src,
int src_stride, unsigned src_slice_stride,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z);
extern void
@ -61,7 +61,7 @@ util_fill_rect(ubyte * dst, enum pipe_format format,
extern void
util_fill_box(ubyte * dst, enum pipe_format format,
unsigned stride, unsigned layer_stride,
unsigned stride, uintptr_t layer_stride,
unsigned x, unsigned y, unsigned z,
unsigned width, unsigned height, unsigned depth,
union util_color *uc);

View file

@ -3145,9 +3145,10 @@ tc_buffer_subdata(struct pipe_context *_pipe,
struct tc_texture_subdata {
struct tc_call_base base;
unsigned level, usage, stride, layer_stride;
unsigned level, usage, stride;
struct pipe_box box;
struct pipe_resource *resource;
uintptr_t layer_stride;
char slot[0]; /* more will be allocated if needed */
};
@ -3168,16 +3169,16 @@ tc_texture_subdata(struct pipe_context *_pipe,
unsigned level, unsigned usage,
const struct pipe_box *box,
const void *data, unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct threaded_context *tc = threaded_context(_pipe);
unsigned size;
uint64_t size;
assert(box->height >= 1);
assert(box->depth >= 1);
size = (box->depth - 1) * layer_stride +
(box->height - 1) * stride +
(box->height - 1) * (uint64_t)stride +
box->width * util_format_get_blocksize(resource->format);
if (!size)
return;
@ -3204,8 +3205,11 @@ tc_texture_subdata(struct pipe_context *_pipe,
format = util_format_get_depth_only(format);
else if (usage & PIPE_MAP_STENCIL_ONLY)
format = PIPE_FORMAT_S8_UINT;
unsigned stride = util_format_get_stride(format, box->width);
unsigned layer_stride = util_format_get_2d_size(format, stride, box->height);
uint64_t layer_stride = util_format_get_2d_size(format, stride, box->height);
assert(layer_stride * box->depth <= UINT32_MAX);
struct pipe_resource *pres = pipe_buffer_create_with_data(pipe, 0, PIPE_USAGE_STREAM, layer_stride * box->depth, data);
struct pipe_box src_box = *box;
src_box.x = src_box.y = src_box.z = 0;

View file

@ -78,7 +78,7 @@ void u_default_texture_subdata(struct pipe_context *pipe,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct pipe_transfer *transfer = NULL;
const uint8_t *src_data = data;

View file

@ -29,7 +29,7 @@ void u_default_texture_subdata(struct pipe_context *pipe,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride);
uintptr_t layer_stride);
void u_default_transfer_flush_region( struct pipe_context *pipe,
struct pipe_transfer *transfer,

View file

@ -291,7 +291,7 @@ u_transfer_helper_transfer_map(struct pipe_context *pctx,
ptrans->usage = usage;
ptrans->box = *box;
ptrans->stride = util_format_get_stride(format, box->width);
ptrans->layer_stride = ptrans->stride * box->height;
ptrans->layer_stride = (uint64_t)ptrans->stride * box->height;
trans->staging = malloc(ptrans->layer_stride);
if (!trans->staging)

View file

@ -708,7 +708,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
* The stride of the BO must be greater or equal to our padded
* stride. The size of the BO must accomodate the padded height. */
if (level->stride < util_format_get_stride(tmpl->format, level->padded_width)) {
BUG("BO stride %u is too small for RS engine width padding (%zu, format %s)",
BUG("BO stride %u is too small for RS engine width padding (%u, format %s)",
level->stride, util_format_get_stride(tmpl->format, level->padded_width),
util_format_name(tmpl->format));
goto fail;

View file

@ -150,6 +150,6 @@ void i915_texture_subdata(struct pipe_context *pipe,
struct pipe_resource *resource, unsigned level,
unsigned usage, const struct pipe_box *box,
const void *data, unsigned stride,
unsigned layer_stride);
uintptr_t layer_stride);
#endif /* I915_RESOURCE_H */

View file

@ -893,7 +893,7 @@ i915_texture_transfer_unmap(struct pipe_context *pipe,
void
i915_texture_subdata(struct pipe_context *pipe, struct pipe_resource *resource,
unsigned level, unsigned usage, const struct pipe_box *box,
const void *data, unsigned stride, unsigned layer_stride)
const void *data, unsigned stride, uintptr_t layer_stride)
{
/* i915's cube and 3D maps are not laid out such that one could use a
* layer_stride to get from one layer to the next, so we have to walk the

View file

@ -2709,7 +2709,7 @@ iris_texture_subdata(struct pipe_context *ctx,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct iris_context *ice = (struct iris_context *)ctx;
struct iris_resource *res = (struct iris_resource *)resource;

View file

@ -891,7 +891,7 @@ lima_texture_subdata(struct pipe_context *pctx,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct lima_context *ctx = lima_context(pctx);
struct lima_resource *res = lima_resource(prsc);

View file

@ -175,7 +175,7 @@ static unsigned r600_texture_get_offset(struct r600_common_screen *rscreen,
struct r600_texture *rtex, unsigned level,
const struct pipe_box *box,
unsigned *stride,
unsigned *layer_stride)
uintptr_t *layer_stride)
{
*stride = rtex->surface.u.legacy.level[level].nblk_x *
rtex->surface.bpe;

View file

@ -377,7 +377,7 @@ static void set_random_image_attrs(struct pipe_resource *templ, bool allow_msaa,
templ->array_size = (rand() % max_tex_size) + 1;
/* Keep reducing the size until it we get a small enough size. */
while ((uint64_t)util_format_get_nblocks(templ->format, templ->width0, templ->height0) *
while (util_format_get_nblocks(templ->format, templ->width0, templ->height0) *
templ->depth0 * templ->array_size * util_format_get_blocksize(templ->format) >
MAX_ALLOC_SIZE) {
switch (rand() % 3) {

View file

@ -110,9 +110,9 @@ static void si_copy_from_staging_texture(struct pipe_context *ctx, struct si_tra
transfer->box.z, src, 0, &sbox);
}
static unsigned si_texture_get_offset(struct si_screen *sscreen, struct si_texture *tex,
static uint64_t si_texture_get_offset(struct si_screen *sscreen, struct si_texture *tex,
unsigned level, const struct pipe_box *box, unsigned *stride,
unsigned *layer_stride)
uintptr_t *layer_stride)
{
if (sscreen->info.gfx_level >= GFX9) {
unsigned pitch;
@ -1824,7 +1824,7 @@ static void *si_texture_transfer_map(struct pipe_context *ctx, struct pipe_resou
struct si_texture *tex = (struct si_texture *)texture;
struct si_transfer *trans;
struct si_resource *buf;
unsigned offset = 0;
uint64_t offset = 0;
char *map;
bool use_staging_texture = tex->buffer.flags & RADEON_FLAG_ENCRYPTED;
unsigned real_level = texture->nr_samples > 1 ? 0 : level;

View file

@ -1000,7 +1000,7 @@ tegra_texture_subdata(struct pipe_context *pcontext,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct tegra_resource *resource = to_tegra_resource(presource);
struct tegra_context *context = to_tegra_context(pcontext);

View file

@ -348,7 +348,7 @@ v3d_texture_subdata(struct pipe_context *pctx,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct v3d_resource *rsc = v3d_resource(prsc);
struct v3d_resource_slice *slice = &rsc->slices[level];

View file

@ -226,7 +226,7 @@ vc4_texture_subdata(struct pipe_context *pctx,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned layer_stride)
uintptr_t layer_stride)
{
struct vc4_resource *rsc = vc4_resource(prsc);
struct vc4_resource_slice *slice = &rsc->slices[level];

View file

@ -891,7 +891,7 @@ static void virgl_encoder_transfer3d_common(struct virgl_screen *vs,
{
struct pipe_transfer *transfer = &xfer->base;
unsigned stride;
unsigned layer_stride;
uintptr_t layer_stride;
if (encode_stride == virgl_transfer3d_explicit_stride) {
stride = transfer->stride;

View file

@ -309,12 +309,12 @@ virgl_resource_transfer_prepare(struct virgl_context *vctx,
static unsigned
virgl_transfer_map_size(struct virgl_transfer *vtransfer,
unsigned *out_stride,
unsigned *out_layer_stride)
uintptr_t *out_layer_stride)
{
struct pipe_resource *pres = vtransfer->base.resource;
struct pipe_box *box = &vtransfer->base.box;
unsigned stride;
unsigned layer_stride;
uintptr_t layer_stride;
unsigned size;
assert(out_stride);
@ -349,7 +349,7 @@ virgl_staging_map(struct virgl_context *vctx,
unsigned size;
unsigned align_offset;
unsigned stride;
unsigned layer_stride;
uintptr_t layer_stride;
void *map_addr;
bool alloc_succeeded;

View file

@ -2373,12 +2373,12 @@ copy_depth_rect(ubyte * dst,
static void
copy_depth_box(ubyte *dst,
enum pipe_format dst_format,
unsigned dst_stride, unsigned dst_slice_stride,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const ubyte * src,
enum pipe_format src_format,
int src_stride, unsigned src_slice_stride,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z)
{
dst += dst_z * dst_slice_stride;

View file

@ -105,7 +105,7 @@ impl<'a> HelperContext<'a> {
bx: &pipe_box,
data: *const c_void,
stride: u32,
layer_stride: u32,
layer_stride: usize,
) {
self.lock
.texture_subdata(res, bx, data, stride, layer_stride)

View file

@ -127,7 +127,7 @@ pub trait CLImageDescInfo {
fn pixels(&self) -> usize;
fn bx(&self) -> CLResult<pipe_box>;
fn row_pitch(&self) -> CLResult<u32>;
fn slice_pitch(&self) -> CLResult<u32>;
fn slice_pitch(&self) -> CLResult<usize>;
fn width(&self) -> CLResult<u32>;
fn height(&self) -> CLResult<u32>;
fn size(&self) -> CLVec<usize>;
@ -204,7 +204,7 @@ impl CLImageDescInfo for cl_image_desc {
.map_err(|_| CL_OUT_OF_HOST_MEMORY)
}
fn slice_pitch(&self) -> CLResult<u32> {
fn slice_pitch(&self) -> CLResult<usize> {
self.image_slice_pitch
.try_into()
.map_err(|_| CL_OUT_OF_HOST_MEMORY)

View file

@ -94,7 +94,7 @@ impl PipeContext {
bx: &pipe_box,
data: *const c_void,
stride: u32,
layer_stride: u32,
layer_stride: usize,
) {
unsafe {
self.pipe.as_ref().texture_subdata.unwrap()(

View file

@ -58,7 +58,7 @@ impl PipeTransfer {
unsafe { (*self.pipe).stride }
}
pub fn slice_pitch(&self) -> u32 {
pub fn slice_pitch(&self) -> usize {
unsafe { (*self.pipe).layer_stride }
}

View file

@ -893,7 +893,7 @@ struct pipe_context {
const struct pipe_box *,
const void *data,
unsigned stride,
unsigned layer_stride);
uintptr_t layer_stride);
/**
* Flush any pending framebuffer writes and invalidate texture caches.

View file

@ -638,7 +638,7 @@ struct pipe_transfer
unsigned level:8; /**< texture mipmap level */
struct pipe_box box; /**< region of the resource to access */
unsigned stride; /**< row stride in bytes */
unsigned layer_stride; /**< image/layer stride in bytes */
uintptr_t layer_stride; /**< image/layer stride in bytes */
/* Offset into a driver-internal staging buffer to make use of unused
* padding in this structure.

View file

@ -338,12 +338,13 @@ _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
* Compute the stride between images in a 3D texture (in bytes) for the given
* pixel packing parameters and image width, format and type.
*/
GLint
intptr_t
_mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
GLint width, GLint height,
GLenum format, GLenum type )
{
GLint bytesPerRow, bytesPerImage, remainder;
GLint bytesPerRow, remainder;
intptr_t bytesPerImage;
assert(packing);
@ -373,9 +374,9 @@ _mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
bytesPerRow += (packing->Alignment - remainder);
if (packing->ImageHeight == 0)
bytesPerImage = bytesPerRow * height;
bytesPerImage = (intptr_t)bytesPerRow * height;
else
bytesPerImage = bytesPerRow * packing->ImageHeight;
bytesPerImage = (intptr_t)bytesPerRow * packing->ImageHeight;
return bytesPerImage;
}

View file

@ -82,7 +82,7 @@ _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
GLint width, GLenum format, GLenum type );
extern GLint
extern intptr_t
_mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
GLint width, GLint height,
GLenum format, GLenum type );

View file

@ -1393,7 +1393,7 @@ get_texture_image(struct gl_context *ctx,
{
struct gl_texture_image *texImage;
unsigned firstFace, numFaces, i;
GLint imageStride;
intptr_t imageStride;
FLUSH_VERTICES(ctx, 0, 0);

View file

@ -3886,7 +3886,7 @@ texturesubimage(struct gl_context *ctx, GLuint dims,
/* Must handle special case GL_TEXTURE_CUBE_MAP. */
if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
GLint imageStride;
intptr_t imageStride;
/*
* What do we do if the user created a texture with the following code

View file

@ -109,7 +109,7 @@ _mesa_memcpy_texture(struct gl_context *ctx,
{
const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
srcFormat, srcType);
const GLint srcImageStride = _mesa_image_image_stride(srcPacking,
const intptr_t srcImageStride = _mesa_image_image_stride(srcPacking,
srcWidth, srcHeight, srcFormat, srcType);
const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
@ -729,7 +729,7 @@ texstore_rgba(TEXSTORE_PARAMS)
*/
GLint swapSize = _mesa_sizeof_packed_type(srcType);
if (swapSize == 2 || swapSize == 4) {
int imageStride = _mesa_image_image_stride(srcPacking, srcWidth,
intptr_t imageStride = _mesa_image_image_stride(srcPacking, srcWidth,
srcHeight, srcFormat,
srcType);
int bufferSize = imageStride * srcDepth;
@ -989,7 +989,7 @@ store_texsubimage(struct gl_context *ctx,
const GLenum target = texImage->TexObject->Target;
GLboolean success = GL_FALSE;
GLuint dims, slice, numSlices = 1, sliceOffset = 0;
GLint srcImageStride = 0;
intptr_t srcImageStride = 0;
const GLubyte *src;
assert(xoffset + width <= texImage->Width);

View file

@ -2105,7 +2105,8 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
texImage->TexFormat, format, type,
unpack)) {
struct pipe_box box;
unsigned stride, layer_stride;
unsigned stride;
intptr_t layer_stride;
void *data;
stride = _mesa_image_row_stride(unpack, width, format, type);

View file

@ -1126,13 +1126,14 @@ download_texture_compute(struct st_context *st,
}
/* Set up destination buffer */
unsigned img_stride = src->target == PIPE_TEXTURE_3D ||
intptr_t img_stride = src->target == PIPE_TEXTURE_3D ||
src->target == PIPE_TEXTURE_2D_ARRAY ||
src->target == PIPE_TEXTURE_CUBE_ARRAY ?
/* only use image stride for 3d images to avoid pulling in IMAGE_HEIGHT pixelstore */
_mesa_image_image_stride(pack, width, height, format, type) :
_mesa_image_row_stride(pack, width, format, type) * height;
unsigned buffer_size = (depth + (dim == 3 ? pack->SkipImages : 0)) * img_stride;
intptr_t buffer_size = (depth + (dim == 3 ? pack->SkipImages : 0)) * img_stride;
assert(buffer_size <= UINT32_MAX);
{
struct pipe_shader_buffer buffer;
memset(&buffer, 0, sizeof(buffer));

View file

@ -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)

View file

@ -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);