Mesa (main): i915: Disable vertex texturing and delete the code.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 18 05:01:19 UTC 2021


Module: Mesa
Branch: main
Commit: 7378c6479278983de7f1f39902aade0567a53965
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7378c6479278983de7f1f39902aade0567a53965

Author: Emma Anholt <emma at anholt.net>
Date:   Tue Jun  8 12:05:42 2021 -0700

i915: Disable vertex texturing and delete the code.

It's not a required feature of the GL2.1 or GLES2, and you really don't
want to be doing SW VS access of the write-combined texture data.  Also,
avoids memory corruption in deqp:

Test case 'dEQP-GLES2.functional.texture.vertex.cube.filtering.linear_mipmap_nearest_linear_repeat'..
Mesa: User error: GL_INVALID_ENUM in glGetIntegerv(pname=GL_MAJOR_VERSION)
  Fail (Image comparison failed)

Test case 'dEQP-GLES2.functional.fragment_ops.depth_stencil.stencil_depth_funcs.stencil_equal_depth_always'..
==559181== Invalid read of size 4
==559181==    at 0x641E8D0: i915_drm_buffer_unmap (i915_drm_buffer.c:204)
==559181==    by 0x64151EB: i915_cleanup_vertex_sampling (i915_state.c:449)
==559181==    by 0x640AEA7: i915_draw_vbo (i915_context.c:134)
==559181==    by 0x640AEA7: i915_draw_vbo (i915_context.c:55)
==559181==    by 0x61367B1: cso_draw_vbo (cso_context.c:1524)
[...]

Reviewed-by: Adam Jackson <ajax at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11329>

---

 src/gallium/drivers/i915/i915_context.c |   6 -
 src/gallium/drivers/i915/i915_context.h |  14 ---
 src/gallium/drivers/i915/i915_screen.c  |   5 +-
 src/gallium/drivers/i915/i915_state.c   | 196 +++-----------------------------
 4 files changed, 19 insertions(+), 202 deletions(-)

diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c
index e007486fea1..98851841fc3 100644
--- a/src/gallium/drivers/i915/i915_context.c
+++ b/src/gallium/drivers/i915/i915_context.c
@@ -113,9 +113,6 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
    else
       draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, NULL, 0);
 
-   if (i915->num_vertex_sampler_views > 0)
-      i915_prepare_vertex_sampling(i915);
-
    /*
     * Do the drawing
     */
@@ -130,9 +127,6 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
    if (mapped_indices)
       draw_set_indexes(draw, NULL, 0, 0);
 
-   if (i915->num_vertex_sampler_views > 0)
-      i915_cleanup_vertex_sampling(i915);
-
    /*
     * Instead of flushing on every state change, we flush once here
     * when we fire the vbo.
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h
index 7db4174cb21..8a90644bc34 100644
--- a/src/gallium/drivers/i915/i915_context.h
+++ b/src/gallium/drivers/i915/i915_context.h
@@ -247,18 +247,12 @@ struct i915_context {
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
    struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
-   struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_SAMPLERS];
    struct pipe_viewport_state viewport;
 
    unsigned dirty;
 
-   struct pipe_resource *mapped_vs_tex[PIPE_MAX_SAMPLERS];
-   struct i915_winsys_buffer* mapped_vs_tex_buffer[PIPE_MAX_SAMPLERS];
-
    unsigned num_samplers;
    unsigned num_fragment_sampler_views;
-   unsigned num_vertex_samplers;
-   unsigned num_vertex_sampler_views;
 
    struct i915_winsys_batchbuffer *batch;
 
@@ -357,14 +351,6 @@ struct draw_stage *i915_draw_render_stage( struct i915_context *i915 );
 struct draw_stage *i915_draw_vbuf_stage( struct i915_context *i915 );
 
 
-/***********************************************************************
- * i915_state.c:
- */
-void i915_prepare_vertex_sampling(struct i915_context *i915);
-void i915_cleanup_vertex_sampling(struct i915_context *i915);
-
-
-
 /***********************************************************************
  * i915_state_emit.c: 
  */
diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
index fed0e3b10e5..54c6f4122a1 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -117,10 +117,7 @@ i915_get_shader_param(struct pipe_screen *screen,
       switch (cap) {
       case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
       case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
-         if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
-            return PIPE_MAX_SAMPLERS;
-         else
-            return 0;
+         return 0;
       case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
       case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
          return 0;
diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c
index 818b7277c06..bc38908d0d4 100644
--- a/src/gallium/drivers/i915/i915_state.c
+++ b/src/gallium/drivers/i915/i915_state.c
@@ -293,46 +293,16 @@ i915_create_sampler_state(struct pipe_context *pipe,
 }
 
 static void
-i915_bind_vertex_sampler_states(struct pipe_context *pipe,
-                                unsigned start,
-                                unsigned num,
-                                void **samplers)
+i915_bind_sampler_states(struct pipe_context *pipe,
+                         enum pipe_shader_type shader,
+                         unsigned start, unsigned num,
+                         void **samplers)
 {
-   struct i915_context *i915 = i915_context(pipe);
-   unsigned i;
-
-   assert(start + num <= ARRAY_SIZE(i915->vertex_samplers));
-
-   /* Check for no-op */
-   if (num == i915->num_vertex_samplers &&
-       !memcmp(i915->vertex_samplers + start, samplers,
-	       num * sizeof(void *)))
+   if (shader != PIPE_SHADER_FRAGMENT) {
+      assert(num == 0);
       return;
-
-   for (i = 0; i < num; ++i)
-      i915->vertex_samplers[i + start] = samplers[i];
-
-   /* find highest non-null samplers[] entry */
-   {
-      unsigned j = MAX2(i915->num_vertex_samplers, start + num);
-      while (j > 0 && i915->vertex_samplers[j - 1] == NULL)
-         j--;
-      i915->num_vertex_samplers = j;
    }
 
-   draw_set_samplers(i915->draw,
-                     PIPE_SHADER_VERTEX,
-                     i915->vertex_samplers,
-                     i915->num_vertex_samplers);
-}
-
-
-
-static void i915_bind_fragment_sampler_states(struct pipe_context *pipe,
-                                              unsigned start,
-                                              unsigned num,
-                                              void **samplers)
-{
    struct i915_context *i915 = i915_context(pipe);
    unsigned i;
 
@@ -357,25 +327,6 @@ static void i915_bind_fragment_sampler_states(struct pipe_context *pipe,
 }
 
 
-static void
-i915_bind_sampler_states(struct pipe_context *pipe,
-                         enum pipe_shader_type shader,
-                         unsigned start, unsigned num_samplers,
-                         void **samplers)
-{
-   switch (shader) {
-   case PIPE_SHADER_VERTEX:
-      i915_bind_vertex_sampler_states(pipe, start, num_samplers, samplers);
-      break;
-   case PIPE_SHADER_FRAGMENT:
-      i915_bind_fragment_sampler_states(pipe, start, num_samplers, samplers);
-      break;
-   default:
-      ;
-   }
-}
-
-
 static void i915_delete_sampler_state(struct pipe_context *pipe,
                                       void *sampler)
 {
@@ -383,77 +334,6 @@ static void i915_delete_sampler_state(struct pipe_context *pipe,
 }
 
 
-/**
- * Called before drawing VBO to map vertex samplers and hand them to draw
- */
-void
-i915_prepare_vertex_sampling(struct i915_context *i915)
-{
-   struct i915_winsys *iws = i915->iws;
-   unsigned i,j;
-   uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
-   uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
-   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
-   unsigned num = i915->num_vertex_sampler_views;
-   struct pipe_sampler_view **views = i915->vertex_sampler_views;
-
-   assert(num <= PIPE_MAX_SAMPLERS);
-   if (!num)
-      return;
-
-   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
-
-      if (view) {
-         struct pipe_resource *tex = view->texture;
-         struct i915_texture *i915_tex = i915_texture(tex);
-         ubyte *addr;
-
-         /* We're referencing the texture's internal data, so save a
-          * reference to it.
-          */
-         pipe_resource_reference(&i915->mapped_vs_tex[i], tex);
-
-         i915->mapped_vs_tex_buffer[i] = i915_tex->buffer;
-         addr = iws->buffer_map(iws,
-                                i915_tex->buffer,
-                                FALSE /* read only */);
-
-         /* Setup array of mipmap level pointers */
-         /* FIXME: handle 3D textures? */
-         for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
-            mip_offsets[j] = i915_texture_offset(i915_tex, j , 0 /* FIXME depth */);
-            row_stride[j] = i915_tex->stride;
-            img_stride[j] = 0; /* FIXME */
-         }
-
-         draw_set_mapped_texture(i915->draw,
-                                 PIPE_SHADER_VERTEX,
-                                 i,
-                                 tex->width0, tex->height0, tex->depth0,
-                                 view->u.tex.first_level, tex->last_level,
-                                 0, 0, addr,
-                                 row_stride, img_stride, mip_offsets);
-      } else
-         i915->mapped_vs_tex[i] = NULL;
-   }
-}
-
-void
-i915_cleanup_vertex_sampling(struct i915_context *i915)
-{
-   struct i915_winsys *iws = i915->iws;
-   unsigned i;
-   for (i = 0; i < ARRAY_SIZE(i915->mapped_vs_tex); i++) {
-      if (i915->mapped_vs_tex_buffer[i]) { 
-         iws->buffer_unmap(iws, i915->mapped_vs_tex_buffer[i]);
-         pipe_resource_reference(&i915->mapped_vs_tex[i], NULL);
-      }
-   }
-}
-
-
-
 /** XXX move someday?  Or consolidate all these simple state setters
  * into one file.
  */
@@ -736,10 +616,19 @@ static void i915_set_constant_buffer(struct pipe_context *pipe,
 }
 
 
-static void i915_set_fragment_sampler_views(struct pipe_context *pipe,
-                                            unsigned num,
-                                            struct pipe_sampler_view **views)
+static void
+i915_set_sampler_views(struct pipe_context *pipe, enum pipe_shader_type shader,
+                       unsigned start, unsigned num, unsigned unbind_num_trailing_slots,
+                       struct pipe_sampler_view **views)
 {
+   if (shader != PIPE_SHADER_FRAGMENT) {
+      /* No support for VS samplers, because it would mean accessing the
+       * write-combined maps of the textures, which is very slow.  VS samplers
+       * are not a required feature of GL2.1 or GLES2.
+       */
+      assert(num == 0);
+      return;
+   }
    struct i915_context *i915 = i915_context(pipe);
    uint i;
 
@@ -762,55 +651,6 @@ static void i915_set_fragment_sampler_views(struct pipe_context *pipe,
    i915->dirty |= I915_NEW_SAMPLER_VIEW;
 }
 
-static void
-i915_set_vertex_sampler_views(struct pipe_context *pipe,
-                              unsigned num,
-                              struct pipe_sampler_view **views)
-{
-   struct i915_context *i915 = i915_context(pipe);
-   uint i;
-
-   assert(num <= ARRAY_SIZE(i915->vertex_sampler_views));
-
-   /* Check for no-op */
-   if (views && num == i915->num_vertex_sampler_views &&
-       !memcmp(i915->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) {
-      return;
-   }
-
-   for (i = 0; i < ARRAY_SIZE(i915->vertex_sampler_views); i++) {
-      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
-
-      pipe_sampler_view_reference(&i915->vertex_sampler_views[i], view);
-   }
-
-   i915->num_vertex_sampler_views = num;
-
-   draw_set_sampler_views(i915->draw,
-                          PIPE_SHADER_VERTEX,
-                          i915->vertex_sampler_views,
-                          i915->num_vertex_sampler_views);
-}
-
-
-static void
-i915_set_sampler_views(struct pipe_context *pipe, enum pipe_shader_type shader,
-                       unsigned start, unsigned num, unsigned unbind_num_trailing_slots,
-                       struct pipe_sampler_view **views)
-{
-   assert(start == 0);
-   switch (shader) {
-   case PIPE_SHADER_FRAGMENT:
-      i915_set_fragment_sampler_views(pipe, num, views);
-      break;
-   case PIPE_SHADER_VERTEX:
-      i915_set_vertex_sampler_views(pipe, num, views);
-      break;
-   default:
-      ;
-   }
-}
-
 
 struct pipe_sampler_view *
 i915_create_sampler_view_custom(struct pipe_context *pipe,



More information about the mesa-commit mailing list