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 <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38587>
This commit is contained in:
Marek Olšák
2025-11-21 19:10:26 -05:00
committed by Marge Bot
parent 6507e8ec65
commit 3dc2582172
3 changed files with 7 additions and 41 deletions
+4 -34
View File
@@ -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)
{
+1 -5
View File
@@ -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);
+2 -2
View File
@@ -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);