[Mesa-dev] [PATCH] svga: avoid emitting redundant SetSamplers() commands

Charmaine Lee charmainel at vmware.com
Thu Dec 10 17:26:19 PST 2015


>From: Brian Paul <brianp at vmware.com>
>Sent: Thursday, December 10, 2015 2:05 PM
>To: mesa-dev at lists.freedesktop.org
>Cc: Jose Fonseca; Charmaine Lee
>Subject: [PATCH] svga: avoid emitting redundant SetSamplers() commands

>This greatly reduces the number of SetSamplers() commands for some
>applications.
>---
> src/gallium/drivers/svga/svga_context.h       |  3 +++
> src/gallium/drivers/svga/svga_state_sampler.c | 22 +++++++++++++++-------
> 2 files changed, 18 insertions(+), 7 deletions(-)

>diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
>index db9491b..78e346a 100644
>--- a/src/gallium/drivers/svga/svga_context.h
>+++ b/src/gallium/drivers/svga/svga_context.h
>@@ -347,6 +347,9 @@ struct svga_hw_draw_state
>    SVGA3dSurfaceFormat ib_format;
>    unsigned ib_offset;
>
>+   unsigned num_samplers[PIPE_SHADER_TYPES];
>+   SVGA3dSamplerId samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
>+
>    /* used for rebinding */
>    unsigned num_sampler_views[PIPE_SHADER_TYPES];
>    unsigned default_constbuf_size[PIPE_SHADER_TYPES];
>diff --git a/src/gallium/drivers/svga/svga_state_sampler.c b/src/gallium/drivers/svga/svga_state_sampler.c
>index c5d52bb..b070f65 100644
>--- a/src/gallium/drivers/svga/svga_state_sampler.c
>+++ b/src/gallium/drivers/svga/svga_state_sampler.c
>@@ -301,13 +301,21 @@ update_samplers(struct svga_context *svga, unsigned dirty )
>       }
>
>       if (count > 0) {
>-         ret = SVGA3D_vgpu10_SetSamplers(svga->swc,
>-                                         count,
>-                                         0,                        /* start */
>-                                         svga_shader_type(shader), /* type */
>-                                         ids);
>-         if (ret != PIPE_OK)
>-            return ret;
>+         if (count != svga->state.hw_draw.num_samplers[shader] ||
>+             memcmp(ids, svga->state.hw_draw.samplers[shader],
>+                    count * sizeof(ids[0])) != 0) {
>+            /* HW state is really changing */
>+            ret = SVGA3D_vgpu10_SetSamplers(svga->swc,
>+                                            count,
>+                                            0,                       /* start */
>+                                            svga_shader_type(shader), /* type */
>+                                            ids);
>+            if (ret != PIPE_OK)
>+               return ret;
>+            memcpy(svga->state.hw_draw.samplers[shader], ids,
>+                   count * sizeof(ids[0]));
>+            svga->state.hw_draw.num_samplers[shader] = count;
>+         }
>       }
>    }

Don't we need to call SVGA3D_vgpu10_SetSamplers() to unbind the to-be-unbind
sampler states? We should also remove the check for (count > 0).

-Charmaine


More information about the mesa-dev mailing list