Mesa (staging/21.3): llvmpipe: fix compressed image sizes.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 17 20:07:01 UTC 2021


Module: Mesa
Branch: staging/21.3
Commit: f2de11b9261495a939d50a3f9823d479b8993ef4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f2de11b9261495a939d50a3f9823d479b8993ef4

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Nov  1 14:12:20 2021 +1000

llvmpipe: fix compressed image sizes.

VK CTS just added some new tests to write to a compressed image
from a compute shader, which was overrunning memory.

The image width/height need to be sized according to the block
sizes to avoid overwriting memory.

dEQP-VK.image.sample_texture.*bit_compressed*

Cc: mesa-stable

Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13618>
(cherry picked from commit 27903abbb67482e2d772c508e9d00e49029b8364)

---

 .pick_status.json                               |  2 +-
 src/gallium/drivers/llvmpipe/lp_setup.c         |  4 ++++
 src/gallium/drivers/llvmpipe/lp_state_cs.c      |  4 ++++
 src/gallium/drivers/llvmpipe/lp_state_sampler.c | 12 ++++++++++--
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 3d9e8c90a7d..b27a44e6610 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1120,7 +1120,7 @@
         "description": "llvmpipe: fix compressed image sizes.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index cc0651ab46c..50f3cea7b00 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -732,7 +732,11 @@ lp_setup_set_fs_images(struct lp_setup_context *setup,
 
          if (llvmpipe_resource_is_texture(res)) {
             uint32_t mip_offset = lp_res->mip_offsets[image->u.tex.level];
+            const uint32_t bw = util_format_get_blockwidth(image->resource->format);
+            const uint32_t bh = util_format_get_blockheight(image->resource->format);
 
+            jit_image->width = DIV_ROUND_UP(jit_image->width, bw);
+            jit_image->height = DIV_ROUND_UP(jit_image->height, bh);
             jit_image->width = u_minify(jit_image->width, image->u.tex.level);
             jit_image->height = u_minify(jit_image->height, image->u.tex.level);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index c655a5477a9..fb86e544ca8 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -1150,7 +1150,11 @@ lp_csctx_set_cs_images(struct lp_cs_context *csctx,
 
          if (llvmpipe_resource_is_texture(res)) {
             uint32_t mip_offset = lp_res->mip_offsets[image->u.tex.level];
+            const uint32_t bw = util_format_get_blockwidth(image->resource->format);
+            const uint32_t bh = util_format_get_blockheight(image->resource->format);
 
+            jit_image->width = DIV_ROUND_UP(jit_image->width, bw);
+            jit_image->height = DIV_ROUND_UP(jit_image->height, bh);
             jit_image->width = u_minify(jit_image->width, image->u.tex.level);
             jit_image->height = u_minify(jit_image->height, image->u.tex.level);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
index aa47cab3ab6..b5e8c31c729 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
@@ -469,11 +469,19 @@ prepare_shader_images(
          if (!img)
             continue;
 
-         unsigned width = u_minify(img->width0, view->u.tex.level);
-         unsigned height = u_minify(img->height0, view->u.tex.level);
+         unsigned width = img->width0;
+         unsigned height = img->height0;
          unsigned num_layers = img->depth0;
          unsigned num_samples = img->nr_samples;
 
+         const uint32_t bw = util_format_get_blockwidth(view->resource->format);
+         const uint32_t bh = util_format_get_blockheight(view->resource->format);
+
+         width = DIV_ROUND_UP(width, bw);
+         height = DIV_ROUND_UP(height, bh);
+         width = u_minify(width, view->u.tex.level);
+         height = u_minify(height, view->u.tex.level);
+
          if (!lp_img->dt) {
             /* regular texture - setup array of mipmap level offsets */
             struct pipe_resource *res = view->resource;



More information about the mesa-commit mailing list