lvmpipe/cs: Add support for 2d images created from buffers
authorAntonio Gomes <antoniospg100@gmail.com>
Mon, 12 Dec 2022 21:22:31 +0000 (18:22 -0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 7 Mar 2023 18:24:56 +0000 (18:24 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20378>

src/gallium/auxiliary/gallivm/lp_bld_sample.c
src/gallium/auxiliary/gallivm/lp_bld_sample.h
src/gallium/drivers/llvmpipe/lp_state_cs.c

index b6be63d..1b1c7b0 100644 (file)
@@ -117,7 +117,12 @@ lp_sampler_static_texture_state(struct lp_static_texture_state *state,
    assert(state->swizzle_b < PIPE_SWIZZLE_NONE);
    assert(state->swizzle_a < PIPE_SWIZZLE_NONE);
 
-   state->target = view->target;
+   /* check if it is a tex2d created from buf */
+   if (view->is_tex2d_from_buf)
+      state->target = PIPE_TEXTURE_2D;
+   else
+      state->target = view->target;
+
    state->pot_width = util_is_power_of_two_or_zero(texture->width0);
    state->pot_height = util_is_power_of_two_or_zero(texture->height0);
    state->pot_depth = util_is_power_of_two_or_zero(texture->depth0);
index b38f9e9..6badf58 100644 (file)
@@ -36,6 +36,7 @@
 #define LP_BLD_SAMPLE_H
 
 
+#include "pipe/p_state.h"
 #include "util/format/u_formats.h"
 #include "util/u_debug.h"
 #include "gallivm/lp_bld.h"
 extern "C" {
 #endif
 
-struct pipe_resource;
-struct pipe_sampler_view;
-struct pipe_sampler_state;
-struct pipe_image_view;
 struct util_format_description;
 struct lp_type;
 struct lp_build_context;
@@ -529,7 +526,6 @@ apply_sampler_swizzle(struct lp_build_sample_context *bld,
    lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles);
 }
 
-
 /*
  * not really dimension as such, this indicates the amount of
  * "normal" texture coords subject to minification, wrapping etc.
index 527396d..af119de 100644 (file)
@@ -1052,20 +1052,34 @@ lp_csctx_set_sampler_views(struct lp_cs_context *csctx,
                   }
                } else {
                   /*
-                   * For buffers, we don't have "offset", instead adjust
-                   * the size (stored as width) plus the base pointer.
+                   * For tex2d_from_buf, adjust width and height with application
+                   * values. If is_tex2d_from_buf is false (1D images),
+                   * adjust using size value (stored as width).
                    */
                   unsigned view_blocksize = util_format_get_blocksize(view->format);
-                  /* probably don't really need to fill that out */
+
                   jit_tex->mip_offsets[0] = 0;
-                  jit_tex->row_stride[0] = 0;
                   jit_tex->img_stride[0] = 0;
 
-                  /* everything specified in number of elements here. */
-                  jit_tex->width = view->u.buf.size / view_blocksize;
-                  jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.offset;
-                  /* XXX Unsure if we need to sanitize parameters? */
-                  assert(view->u.buf.offset + view->u.buf.size <= res->width0);
+                  /* If it's not a 2D texture view of a buffer, adjust using size. */
+                  if (!view->is_tex2d_from_buf) {
+                     /* everything specified in number of elements here. */
+                     jit_tex->width = view->u.buf.size / view_blocksize;
+                     jit_tex->row_stride[0] = 0;
+
+                     /* Adjust base pointer with offset. */
+                     jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.offset;
+
+                     /* XXX Unsure if we need to sanitize parameters? */
+                     assert(view->u.buf.offset + view->u.buf.size <= res->width0);
+                  } else {
+                     jit_tex->width = view->u.tex2d_from_buf.width;
+                     jit_tex->height = view->u.tex2d_from_buf.height;
+                     jit_tex->row_stride[0] = view->u.tex2d_from_buf.row_stride * view_blocksize;
+
+                     jit_tex->base = (uint8_t *)jit_tex->base + 
+                        view->u.tex2d_from_buf.offset * view_blocksize;
+                  }
                }
             }
          } else {
@@ -1219,9 +1233,29 @@ lp_csctx_set_cs_images(struct lp_cs_context *csctx,
             jit_image->sample_stride = lp_res->sample_stride;
             jit_image->base = (uint8_t *)jit_image->base + mip_offset;
          } else {
-            unsigned view_blocksize = util_format_get_blocksize(image->format);
-            jit_image->width = image->u.buf.size / view_blocksize;
-            jit_image->base = (uint8_t *)jit_image->base + image->u.buf.offset;
+            unsigned image_blocksize = util_format_get_blocksize(image->format);
+
+            jit_image->img_stride = 0;
+
+            /* If it's not a 2D image view of a buffer, adjust using size. */
+            if (!(image->access & PIPE_IMAGE_ACCESS_TEX2D_FROM_BUFFER)) {
+               /* everything specified in number of elements here. */
+               jit_image->width = image->u.buf.size / image_blocksize;
+               jit_image->row_stride = 0;
+
+               /* Adjust base pointer with offset. */
+               jit_image->base = (uint8_t *)jit_image->base + image->u.buf.offset;
+
+               /* XXX Unsure if we need to sanitize parameters? */
+               assert(image->u.buf.offset + image->u.buf.size <= res->width0);
+            } else {
+               jit_image->width = image->u.tex2d_from_buf.width;
+               jit_image->height = image->u.tex2d_from_buf.height;
+               jit_image->row_stride = image->u.tex2d_from_buf.row_stride * image_blocksize;
+
+               jit_image->base = (uint8_t *)jit_image->base +
+                  image->u.tex2d_from_buf.offset * image_blocksize;
+            }
          }
       }
    }