diff --git a/src/compiler/glsl/gl_nir_link_varyings.c b/src/compiler/glsl/gl_nir_link_varyings.c index 6d0fd05de00..08b56b7c11f 100644 --- a/src/compiler/glsl/gl_nir_link_varyings.c +++ b/src/compiler/glsl/gl_nir_link_varyings.c @@ -2424,9 +2424,17 @@ static int varying_matches_xfb_comparator(const void *x_generic, const void *y_generic) { const struct match *x = (const struct match *) x_generic; - - if (x->producer_var != NULL && x->producer_var->data.is_xfb_only) - return varying_matches_match_comparator(x_generic, y_generic); + const struct match *y = (const struct match *) y_generic; + /* if both varying are used by transform feedback, sort them */ + if (x->producer_var != NULL && x->producer_var->data.is_xfb_only) { + if (y->producer_var != NULL && y->producer_var->data.is_xfb_only) + return 0; + /* if x is varying and y is not, put y first */ + return +1; + } else if (y->producer_var != NULL && y->producer_var->data.is_xfb_only) { + /* if y is varying and x is not, leave x first */ + return -1; + } /* FIXME: When the comparator returns 0 it means the elements being * compared are equivalent. However the qsort documentation says: @@ -2449,8 +2457,11 @@ static int varying_matches_not_xfb_comparator(const void *x_generic, const void *y_generic) { const struct match *x = (const struct match *) x_generic; + const struct match *y = (const struct match *) y_generic; - if (x->producer_var != NULL && !x->producer_var->data.is_xfb) + if ( (x->producer_var != NULL && !x->producer_var->data.is_xfb) + && (y->producer_var != NULL && !y->producer_var->data.is_xfb) ) + /* if both are non-xfb, then sort them */ return varying_matches_match_comparator(x_generic, y_generic); /* FIXME: When the comparator returns 0 it means the elements being