Mesa (master): mesa: Account for block depth in _mesa_format_image_size()

Anuj Phogat aphogat at kemper.freedesktop.org
Tue May 3 10:39:58 UTC 2016


Module: Mesa
Branch: master
Commit: 63a7a9d115ce5f961d536838e289f585676b771a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=63a7a9d115ce5f961d536838e289f585676b771a

Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Thu Feb 11 10:08:49 2016 -0800

mesa: Account for block depth in _mesa_format_image_size()

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/formats.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 999e627..9d9830f 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -861,20 +861,22 @@ _mesa_format_image_size(mesa_format format, GLsizei width,
                         GLsizei height, GLsizei depth)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
+   GLuint sz;
    /* Strictly speaking, a conditional isn't needed here */
-   if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+   if (info->BlockWidth > 1 || info->BlockHeight > 1 || info->BlockDepth > 1) {
       /* compressed format (2D only for now) */
-      const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
+      const GLuint bw = info->BlockWidth;
+      const GLuint bh = info->BlockHeight;
+      const GLuint bd = info->BlockDepth;
       const GLuint wblocks = (width + bw - 1) / bw;
       const GLuint hblocks = (height + bh - 1) / bh;
-      const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
-      return sz * depth;
-   }
-   else {
+      const GLuint dblocks = (depth + bd - 1) / bd;
+      sz = wblocks * hblocks * dblocks * info->BytesPerBlock;
+   } else
       /* non-compressed */
-      const GLuint sz = width * height * depth * info->BytesPerBlock;
-      return sz;
-   }
+      sz = width * height * depth * info->BytesPerBlock;
+
+   return sz;
 }
 
 
@@ -887,23 +889,23 @@ _mesa_format_image_size64(mesa_format format, GLsizei width,
                           GLsizei height, GLsizei depth)
 {
    const struct gl_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) {
+   if (info->BlockWidth > 1 || info->BlockHeight > 1 || info->BlockDepth > 1) {
       /* compressed format (2D only for now) */
-      const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
+      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 sz = wblocks * hblocks * info->BytesPerBlock;
-      return sz * depth;
-   }
-   else {
+      const uint64_t dblocks = (depth + bd - 1) / bd;
+      sz = wblocks * hblocks * dblocks * info->BytesPerBlock;
+   } else
       /* non-compressed */
-      const uint64_t sz = ((uint64_t) width *
-                           (uint64_t) height *
-                           (uint64_t) depth *
-                           info->BytesPerBlock);
-      return sz;
-   }
+      sz = ((uint64_t) width * (uint64_t) height *
+            (uint64_t) depth * info->BytesPerBlock);
+
+   return sz;
 }
 
 




More information about the mesa-commit mailing list