svga: avoid emitting redundant SetSamplers() commands
authorBrian Paul <brianp@vmware.com>
Thu, 10 Dec 2015 21:55:33 +0000 (14:55 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 11 Dec 2015 23:54:58 +0000 (16:54 -0700)
This greatly reduces the number of SetSamplers() commands for some
applications.

Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/svga/svga_state_sampler.c

index db9491bc282ed920def0686cacbf87b8466d2d20..78e346a92b970cd3825074adebf122f7ed07b928 100644 (file)
@@ -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];
index c5d52bbfd149d2165e5477bae729e2cf2188c839..b070f65feaf0643129c7dce7a6e6ad3fd5350dde 100644 (file)
@@ -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;
+         }
       }
    }