Mesa (master): st/mesa: Fix grabbing the wrong variant if glDrawPixels is called

Marek Olšák mareko at kemper.freedesktop.org
Fri Jul 7 23:51:45 UTC 2017


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

Author: Matias N. Goldberg <dark_sylinc at yahoo.com.ar>
Date:   Wed Jul  5 14:02:50 2017 -0300

st/mesa: Fix grabbing the wrong variant if glDrawPixels is called

By design pixel shaders can have up to 3 variants:
* The standard one.
* glDrawPixels variant.
* glBitmap variant.
However "shader_has_one_variant" ignores this fact, and therefore
st_update_fp would select the wrong variant if glDrawPixels or glBitmap
was ever called.

This patch fixes the problem. If the standard variant has been created,
calling glDrawPixels or glBitmap will append the variant to the second
entry of the linked list, so that st_update_fp still selects the right
one if shader_has_one_variant is set.

If the standard variant hasn't been created yet and glDrawPixel/Bitmap
has been called, st_update_fp will will see this and take the slow path
instead. The standard variant will then be added at the front of the
linked list, so that the next time the fast path is taken.

Blender in particular is hit by this bug.

v2: Marek - cosmetic changes

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=101596

Signed-off-by: Marek Olšák <marek.olsak at amd.com>

---

 src/mesa/state_tracker/st_atom_shader.c |  4 +++-
 src/mesa/state_tracker/st_program.c     | 22 +++++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 46f2bd7e3b..b5ba33a488 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -108,7 +108,9 @@ st_update_fp( struct st_context *st )
    if (st->shader_has_one_variant[MESA_SHADER_FRAGMENT] &&
        !stfp->ati_fs && /* ATI_fragment_shader always has multiple variants */
        !stfp->Base.ExternalSamplersUsed && /* external samplers need variants */
-       stfp->variants) {
+       stfp->variants &&
+       !stfp->variants->key.drawpixels &&
+       !stfp->variants->key.bitmap) {
       shader = stfp->variants->driver_shader;
    } else {
       memset(&key, 0, sizeof(key));
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 6b6d41536c..41ebfa9003 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1248,9 +1248,25 @@ st_get_fp_variant(struct st_context *st,
       /* create new */
       fpv = st_create_fp_variant(st, stfp, key);
       if (fpv) {
-         /* insert into list */
-         fpv->next = stfp->variants;
-         stfp->variants = fpv;
+         if (key->bitmap || key->drawpixels) {
+            /* Regular variants should always come before the
+             * bitmap & drawpixels variants, (unless there
+             * are no regular variants) so that
+             * st_update_fp can take a fast path when
+             * shader_has_one_variant is set.
+             */
+            if (!stfp->variants) {
+               stfp->variants = fpv;
+            } else {
+               /* insert into list after the first one */
+               fpv->next = stfp->variants->next;
+               stfp->variants->next = fpv;
+            }
+         } else {
+            /* insert into list */
+            fpv->next = stfp->variants;
+            stfp->variants = fpv;
+         }
       }
    }
 




More information about the mesa-commit mailing list