diff --git a/src/gallium/auxiliary/driver_ddebug/dd_draw.c b/src/gallium/auxiliary/driver_ddebug/dd_draw.c index 9e6b6e45002..68ca5e2bcb7 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_draw.c +++ b/src/gallium/auxiliary/driver_ddebug/dd_draw.c @@ -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; diff --git a/src/gallium/auxiliary/driver_ddebug/dd_pipe.h b/src/gallium/auxiliary/driver_ddebug/dd_pipe.h index d1234c144bd..d9a24789830 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_pipe.h +++ b/src/gallium/auxiliary/driver_ddebug/dd_pipe.h @@ -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 diff --git a/src/gallium/auxiliary/driver_noop/noop_pipe.c b/src/gallium/auxiliary/driver_noop/noop_pipe.c index b6e1306579e..d61a7c6540d 100644 --- a/src/gallium/auxiliary/driver_noop/noop_pipe.c +++ b/src/gallium/auxiliary/driver_noop/noop_pipe.c @@ -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) { } diff --git a/src/gallium/auxiliary/driver_trace/tr_context.c b/src/gallium/auxiliary/driver_trace/tr_context.c index a6c88a533b9..88a34e14b4f 100644 --- a/src/gallium/auxiliary/driver_trace/tr_context.c +++ b/src/gallium/auxiliary/driver_trace/tr_context.c @@ -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; diff --git a/src/gallium/auxiliary/driver_trace/tr_dump.c b/src/gallium/auxiliary/driver_trace/tr_dump.c index 410c9d7065a..ae46ebc7f31 100644 --- a/src/gallium/auxiliary/driver_trace/tr_dump.c +++ b/src/gallium/auxiliary/driver_trace/tr_dump.c @@ -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); } diff --git a/src/gallium/auxiliary/driver_trace/tr_dump.h b/src/gallium/auxiliary/driver_trace/tr_dump.h index 298fe46a89b..300d820d251 100644 --- a/src/gallium/auxiliary/driver_trace/tr_dump.h +++ b/src/gallium/auxiliary/driver_trace/tr_dump.h @@ -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); diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index cd51fd34b4e..cbacf6c2710 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -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); diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index 1ca8ca31416..3cbb4bfff6e 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -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); diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index d4b0f7e5285..e48c90a6fa8 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -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; diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c index ba3f578caff..01ca534a1b7 100644 --- a/src/gallium/auxiliary/util/u_transfer.c +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -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; diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h index 5999d92a520..7c4f73d787c 100644 --- a/src/gallium/auxiliary/util/u_transfer.h +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -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, diff --git a/src/gallium/auxiliary/util/u_transfer_helper.c b/src/gallium/auxiliary/util/u_transfer_helper.c index 82ffa642ef3..1dc42018ef0 100644 --- a/src/gallium/auxiliary/util/u_transfer_helper.c +++ b/src/gallium/auxiliary/util/u_transfer_helper.c @@ -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) diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c b/src/gallium/drivers/etnaviv/etnaviv_resource.c index 92cb5ce7fa3..c7dbb8e9e3a 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c @@ -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; diff --git a/src/gallium/drivers/i915/i915_resource.h b/src/gallium/drivers/i915/i915_resource.h index bee9436de4c..4741b6b8096 100644 --- a/src/gallium/drivers/i915/i915_resource.h +++ b/src/gallium/drivers/i915/i915_resource.h @@ -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 */ diff --git a/src/gallium/drivers/i915/i915_resource_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c index 4b78bc51ad6..73eebf6f546 100644 --- a/src/gallium/drivers/i915/i915_resource_texture.c +++ b/src/gallium/drivers/i915/i915_resource_texture.c @@ -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 diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c index 182944d316d..9c602aaeb99 100644 --- a/src/gallium/drivers/iris/iris_resource.c +++ b/src/gallium/drivers/iris/iris_resource.c @@ -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; diff --git a/src/gallium/drivers/lima/lima_resource.c b/src/gallium/drivers/lima/lima_resource.c index 9a48da4c47e..f63099b0dcd 100644 --- a/src/gallium/drivers/lima/lima_resource.c +++ b/src/gallium/drivers/lima/lima_resource.c @@ -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); diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c index 662ffe7c313..babed50d9fc 100644 --- a/src/gallium/drivers/r600/r600_texture.c +++ b/src/gallium/drivers/r600/r600_texture.c @@ -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; diff --git a/src/gallium/drivers/radeonsi/si_test_image_copy_region.c b/src/gallium/drivers/radeonsi/si_test_image_copy_region.c index d70c3cad3c7..f363c32e5e5 100644 --- a/src/gallium/drivers/radeonsi/si_test_image_copy_region.c +++ b/src/gallium/drivers/radeonsi/si_test_image_copy_region.c @@ -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) { diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c index 6846342ad7b..a5f33dc928e 100644 --- a/src/gallium/drivers/radeonsi/si_texture.c +++ b/src/gallium/drivers/radeonsi/si_texture.c @@ -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; diff --git a/src/gallium/drivers/tegra/tegra_context.c b/src/gallium/drivers/tegra/tegra_context.c index 6e268a696e1..4e5ac42fa47 100644 --- a/src/gallium/drivers/tegra/tegra_context.c +++ b/src/gallium/drivers/tegra/tegra_context.c @@ -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); diff --git a/src/gallium/drivers/v3d/v3d_resource.c b/src/gallium/drivers/v3d/v3d_resource.c index b7298f56563..a0a210ccad5 100644 --- a/src/gallium/drivers/v3d/v3d_resource.c +++ b/src/gallium/drivers/v3d/v3d_resource.c @@ -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]; diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c index 4952fab06f5..ad2791aa972 100644 --- a/src/gallium/drivers/vc4/vc4_resource.c +++ b/src/gallium/drivers/vc4/vc4_resource.c @@ -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]; diff --git a/src/gallium/drivers/virgl/virgl_encode.c b/src/gallium/drivers/virgl/virgl_encode.c index 518bca5050c..284c1eb0f77 100644 --- a/src/gallium/drivers/virgl/virgl_encode.c +++ b/src/gallium/drivers/virgl/virgl_encode.c @@ -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; diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c index b31355c0fe8..64a0dfa3051 100644 --- a/src/gallium/drivers/virgl/virgl_resource.c +++ b/src/gallium/drivers/virgl/virgl_resource.c @@ -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; diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index b06dd2a2fd0..e4216d51b30 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -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; diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 7bee316d898..d3940d5f2a2 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -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) diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 87dabeb1bd6..df9dc17fa16 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -127,7 +127,7 @@ pub trait CLImageDescInfo { fn pixels(&self) -> usize; fn bx(&self) -> CLResult; fn row_pitch(&self) -> CLResult; - fn slice_pitch(&self) -> CLResult; + fn slice_pitch(&self) -> CLResult; fn width(&self) -> CLResult; fn height(&self) -> CLResult; fn size(&self) -> CLVec; @@ -204,7 +204,7 @@ impl CLImageDescInfo for cl_image_desc { .map_err(|_| CL_OUT_OF_HOST_MEMORY) } - fn slice_pitch(&self) -> CLResult { + fn slice_pitch(&self) -> CLResult { self.image_slice_pitch .try_into() .map_err(|_| CL_OUT_OF_HOST_MEMORY) diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index b22c12cc555..0a7bbe84ecd 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -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()( diff --git a/src/gallium/frontends/rusticl/mesa/pipe/transfer.rs b/src/gallium/frontends/rusticl/mesa/pipe/transfer.rs index f662d70c36f..819135c4a3d 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/transfer.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/transfer.rs @@ -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 } } diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index ea206a985b2..d6a88554b11 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -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. diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 3a7d82c5d82..73c6e1cd72b 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -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. diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 3b922e72ec1..728f78aebc5 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -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; } diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h index e64213ff23d..7dd2e45691b 100644 --- a/src/mesa/main/image.h +++ b/src/mesa/main/image.h @@ -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 ); diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 66cd8cc1cb2..6d0db242cff 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -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); diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 1a9db071294..a8fd97d9f63 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -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 diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 7c5b24b17da..7be6a0acb41 100755 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -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); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 338c3cf1d79..207e3638788 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -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); diff --git a/src/mesa/state_tracker/st_pbo_compute.c b/src/mesa/state_tracker/st_pbo_compute.c index 2a4ec9fd2aa..03e7d4d545e 100644 --- a/src/mesa/state_tracker/st_pbo_compute.c +++ b/src/mesa/state_tracker/st_pbo_compute.c @@ -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)); diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index bfbefc6176d..59dba8b2c16 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -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) diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 5c24ab6f745..2a9b84f6f00 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -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);