Mesa (master): svga: re-validate sampler view at draw time if needed

Brian Paul brianp at kemper.freedesktop.org
Fri Jun 30 14:29:54 UTC 2017


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

Author: Charmaine Lee <charmainel at vmware.com>
Date:   Tue Jun 27 10:47:01 2017 -0600

svga: re-validate sampler view at draw time if needed

This patch validates those sampler views with backing copy
of texture whose original copy has been updated since the
view is last validated.
This is done here at draw time because the texture binding might not
have modified, hence validation is not triggered at state update time,
and yet the texture might have been updated in another context, so
we need to re-validate the sampler view in order to update the backing
copy of the updated texture.

This fixes a rendering flickering issue with Photoshop running in
Linux VM with HWversion 11. The problem is Photoshop renders to texture A
in context X, and then bind texture A to context Y. The first time
when texture A is bound to context Y, cso calls pipe->set_sampler_views().
Validation of sampler views is done, rendering is fine.
But when texture A is rendered to again in context X, and rebound in
context Y, cso skips pipe->set_sampler_views() because texture A is already
bound in context Y. SVGA driver is not given a chance to re-validate
the texture binding, the backing copy of the texture is not updated,
and hence causes black image.

Tested with Photoshop, MTT glretrace, piglit.
Fixes VMware bug 1769103.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/drivers/svga/svga_context.c   |  1 +
 src/gallium/drivers/svga/svga_context.h   |  3 +++
 src/gallium/drivers/svga/svga_draw.c      | 19 +++++++++++++++++++
 src/gallium/drivers/svga/svga_state_tss.c | 14 ++++++++++++--
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index 71505f646a..940ce19a1f 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -253,6 +253,7 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
    memset(svga->state.hw_draw.sampler_views, 0,
           sizeof(svga->state.hw_draw.sampler_views));
    svga->state.hw_draw.num_views = 0;
+   svga->state.hw_draw.num_backed_views = 0;
    svga->state.hw_draw.rasterizer_discard = FALSE;
 
    /* Initialize the shader pointers */
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index b1ccfc8775..d0306c036f 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -348,9 +348,12 @@ struct svga_hw_draw_state
    unsigned rs[SVGA3D_RS_MAX];
    /** VGPU9 texture sampler and bindings state */
    unsigned ts[SVGA3D_PIXEL_SAMPLERREG_MAX][SVGA3D_TS_MAX];
+
    /** VGPU9 texture views */
    unsigned num_views;
+   unsigned num_backed_views; /* views with backing copy of texture */
    struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
+
    /** VGPU9 constant buffer values */
    float cb[PIPE_SHADER_TYPES][SVGA3D_CONSTREG_MAX][4];
 
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index d6b024d532..6510c42443 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -38,6 +38,7 @@
 #include "svga_resource.h"
 #include "svga_resource_buffer.h"
 #include "svga_resource_texture.h"
+#include "svga_sampler_view.h"
 #include "svga_shader.h"
 #include "svga_surface.h"
 #include "svga_winsys.h"
@@ -199,6 +200,24 @@ draw_vgpu9(struct svga_hwtnl *hwtnl)
    SVGA3dPrimitiveRange *prim;
    unsigned i;
 
+   /* Re-validate those sampler views with backing copy
+    * of texture whose original copy has been updated.
+    * This is done here at draw time because the texture binding might not
+    * have modified, hence validation is not triggered at state update time,
+    * and yet the texture might have been updated in another context, so
+    * we need to re-validate the sampler view in order to update the backing
+    * copy of the updated texture.
+    */
+   if (svga->state.hw_draw.num_backed_views) {
+      for (i = 0; i < svga->state.hw_draw.num_views; i++) {
+         struct svga_hw_view_state *view = &svga->state.hw_draw.views[i];
+         struct svga_texture *tex = svga_texture(view->texture);
+         struct svga_sampler_view *sv = view->v;
+         if (sv && tex && sv->handle != tex->handle && sv->age < tex->age)
+            svga_validate_sampler_view(svga, view->v);
+      }
+   }
+
    for (i = 0; i < hwtnl->cmd.vdecl_count; i++) {
       unsigned j = hwtnl->cmd.vdecl_buffer_index[i];
       handle = svga_buffer_handle(svga, hwtnl->cmd.vbufs[j].buffer.resource,
diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c
index 43b45e54f1..455b1733b8 100644
--- a/src/gallium/drivers/svga/svga_state_tss.c
+++ b/src/gallium/drivers/svga/svga_state_tss.c
@@ -28,6 +28,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_math.h"
 
+#include "svga_resource_texture.h"
 #include "svga_sampler_view.h"
 #include "svga_winsys.h"
 #include "svga_context.h"
@@ -175,6 +176,8 @@ update_tss_binding(struct svga_context *svga,
                             &queue);
    }
 
+   svga->state.hw_draw.num_backed_views = 0;
+
    if (queue.bind_count) {
       SVGA3dTextureState *ts;
 
@@ -185,12 +188,19 @@ update_tss_binding(struct svga_context *svga,
 
       for (i = 0; i < queue.bind_count; i++) {
          struct svga_winsys_surface *handle;
+         struct svga_hw_view_state *view = queue.bind[i].view;
 
          ts[i].stage = queue.bind[i].unit;
          ts[i].name = SVGA3D_TS_BIND_TEXTURE;
 
-         if (queue.bind[i].view->v) {
-            handle = queue.bind[i].view->v->handle;
+         if (view->v) {
+            handle = view->v->handle;
+
+            /* Keep track of number of views with a backing copy
+             * of texture.
+             */
+            if (handle != svga_texture(view->texture)->handle)
+               svga->state.hw_draw.num_backed_views++;
          }
          else {
             handle = NULL;




More information about the mesa-commit mailing list