From 3dc2582172c0b7e7b3a87859268dbe8893f9db11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 21 Nov 2025 19:10:26 -0500 Subject: [PATCH] mesa: merge mostly duplicated mesa_format_image_size & mesa_format_image_size64 One of them returned 32 bits, the other one returned 64 bits. Reviewed-by: Qiang Yu Part-of: --- src/mesa/main/formats.c | 38 ++++---------------------------------- src/mesa/main/formats.h | 6 +----- src/mesa/main/teximage.c | 4 ++-- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index 07853b92445..81df221a6cc 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -804,12 +804,12 @@ _mesa_format_has_color_component(mesa_format format, int component) * Return number of bytes needed to store an image of the given size * in the given format. */ -uint32_t +size_t _mesa_format_image_size(mesa_format format, int width, int height, int depth) { const struct mesa_format_info *info = _mesa_get_format_info(format); - uint32_t sz; + size_t sz; /* Strictly speaking, a conditional isn't needed here */ if (info->BlockWidth > 1 || info->BlockHeight > 1 || info->BlockDepth > 1) { /* compressed format (2D only for now) */ @@ -819,45 +819,15 @@ _mesa_format_image_size(mesa_format format, int width, const uint32_t wblocks = (width + bw - 1) / bw; const uint32_t hblocks = (height + bh - 1) / bh; const uint32_t dblocks = (depth + bd - 1) / bd; - sz = wblocks * hblocks * dblocks * info->BytesPerBlock; + sz = (size_t)wblocks * hblocks * dblocks * info->BytesPerBlock; } else /* non-compressed */ - sz = width * height * depth * info->BytesPerBlock; + sz = (size_t)width * height * depth * info->BytesPerBlock; return sz; } -/** - * Same as _mesa_format_image_size() but returns a 64-bit value to - * accommodate very large textures. - */ -uint64_t -_mesa_format_image_size64(mesa_format format, int width, - int height, int depth) -{ - const struct mesa_format_info *info = _mesa_get_format_info(format); - uint64_t sz; - /* Strictly speaking, a conditional isn't needed here */ - if (info->BlockWidth > 1 || info->BlockHeight > 1 || info->BlockDepth > 1) { - /* compressed format (2D only for now) */ - const uint64_t bw = info->BlockWidth; - const uint64_t bh = info->BlockHeight; - const uint64_t bd = info->BlockDepth; - const uint64_t wblocks = (width + bw - 1) / bw; - const uint64_t hblocks = (height + bh - 1) / bh; - const uint64_t dblocks = (depth + bd - 1) / bd; - sz = wblocks * hblocks * dblocks * info->BytesPerBlock; - } else - /* non-compressed */ - sz = ((uint64_t) width * (uint64_t) height * - (uint64_t) depth * info->BytesPerBlock); - - return sz; -} - - - int32_t _mesa_format_row_stride(mesa_format format, int width) { diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h index a295c584412..c8b6653705c 100644 --- a/src/mesa/main/formats.h +++ b/src/mesa/main/formats.h @@ -736,14 +736,10 @@ _mesa_is_format_color_format(mesa_format format); bool _mesa_is_format_srgb(mesa_format format); -extern uint32_t +extern size_t _mesa_format_image_size(mesa_format format, int width, int height, int depth); -extern uint64_t -_mesa_format_image_size64(mesa_format format, int width, - int height, int depth); - extern int32_t _mesa_format_row_stride(mesa_format format, int width); diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index e7c0ebc3a6b..895a22422d8 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1342,7 +1342,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, for (l = 0; l < numLevels; l++) { GLint nextWidth, nextHeight, nextDepth; - bytes += _mesa_format_image_size64(format, width, height, depth); + bytes += _mesa_format_image_size(format, width, height, depth); if (_mesa_next_mipmap_level_size(target, 0, width, height, depth, &nextWidth, &nextHeight, @@ -1358,7 +1358,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, /* We just compute the size of one mipmap level. This is the path * taken for glTexImage(GL_PROXY_TEXTURE_x). */ - bytes = _mesa_format_image_size64(format, width, height, depth); + bytes = _mesa_format_image_size(format, width, height, depth); } bytes *= _mesa_num_tex_faces(target);