softpipe: fix unreliable FS variant binding bug
authorBrian Paul <brianp@vmware.com>
Fri, 14 Dec 2012 17:34:33 +0000 (10:34 -0700)
committerBrian Paul <brianp@vmware.com>
Wed, 19 Dec 2012 16:02:08 +0000 (09:02 -0700)
In exec_prepare() we were comparing pointers to see if the fragment
shader variant had changed before calling tgsi_exec_machine_bind_shader().
This didn't work reliably when there was a lot of shader token malloc/
freeing going on because the memory might get reused.
Instead, bind the shader variant during regular state validation.

Fixes http://bugs.freedesktop.org/show_bug.cgi?id=40404
(fixes a couple of piglit's glsl-max-varyings test)

Note: This is a candidate for the stable branches.

src/gallium/drivers/softpipe/sp_fs_exec.c
src/gallium/drivers/softpipe/sp_quad_fs.c
src/gallium/drivers/softpipe/sp_state_derived.c

index 779b8c4995c98e1a9a3a18af5f08dab025718879..f5344924a1d42960f7e8348248dff454a77e8bb7 100644 (file)
@@ -66,14 +66,11 @@ exec_prepare( const struct sp_fragment_shader_variant *var,
 {
    /*
     * Bind tokens/shader to the interpreter's machine state.
-    * Avoid redundant binding.
     */
-   if (machine->Tokens != var->tokens) {
-      tgsi_exec_machine_bind_shader( machine,
-                                     var->tokens,
-                                     PIPE_MAX_SAMPLERS,
-                                     samplers );
-   }
+   tgsi_exec_machine_bind_shader(machine,
+                                 var->tokens,
+                                 PIPE_MAX_SAMPLERS,
+                                 samplers);
 }
 
 
index 892d9c6c11d883550b96adcf4e19ea7619d9a730..f32fe5f40686ab9c05554594f7e6395bf4539f44 100644 (file)
@@ -148,13 +148,6 @@ shade_quads(struct quad_stage *qs,
 static void
 shade_begin(struct quad_stage *qs)
 {
-   struct softpipe_context *softpipe = qs->softpipe;
-
-   softpipe->fs_variant->prepare( softpipe->fs_variant, 
-                                  softpipe->fs_machine,
-                                  (struct tgsi_sampler **)
-                                  softpipe->tgsi.samplers_list[PIPE_SHADER_FRAGMENT] );
-
    qs->next->begin(qs->next);
 }
 
index cb954a17ef67dc63eea4fb6312a56841815ab9c3..e4a5a632097068d0d946019a054ac15e847335d6 100644 (file)
@@ -242,6 +242,12 @@ update_fragment_shader(struct softpipe_context *softpipe, unsigned prim)
    if (softpipe->fs) {
       softpipe->fs_variant = softpipe_find_fs_variant(softpipe,
                                                       softpipe->fs, &key);
+
+      /* prepare the TGSI interpreter for FS execution */
+      softpipe->fs_variant->prepare(softpipe->fs_variant, 
+                                    softpipe->fs_machine,
+                                    (struct tgsi_sampler **) softpipe->
+                                    tgsi.samplers_list[PIPE_SHADER_FRAGMENT]);
    }
    else {
       softpipe->fs_variant = NULL;