Mesa (staging/20.0): nir: fix crash in varying packing on interface mismatch

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 1 16:06:15 UTC 2020


Module: Mesa
Branch: staging/20.0
Commit: 9c8dab082f8564ce643104287a4533a2f470069b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9c8dab082f8564ce643104287a4533a2f470069b

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Sat Mar 28 02:17:54 2020 +1100

nir: fix crash in varying packing on interface mismatch

For example when the outputs are scalars but the inputs are struct
members.

Fixes: 26aa460940f6 ("nir: rewrite varying component packing")

Reviewed-By: Timur Kristóf <timur.kristof at gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4351>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4351>
(cherry picked from commit 0f4a81430e65e09db13d2472fd46105a95ea625d)

---

 .pick_status.json                      |  2 +-
 src/compiler/nir/nir_linking_helpers.c | 24 ++++++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f6ee36e8648..e8d093daf1e 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -301,7 +301,7 @@
         "description": "nir: fix crash in varying packing on interface mismatch",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "26aa460940f6222565ad5eb40a21c2377c59c3a6"
     },
diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c
index 7864f042636..ec1bd77928c 100644
--- a/src/compiler/nir/nir_linking_helpers.c
+++ b/src/compiler/nir/nir_linking_helpers.c
@@ -569,6 +569,7 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
             vc_info->is_32bit = glsl_type_is_32bit(type);
             vc_info->is_patch = in_var->data.patch;
             vc_info->is_intra_stage_only = false;
+            vc_info->initialised = true;
          }
       }
    }
@@ -604,8 +605,14 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
 
             unsigned var_info_idx =
                store_varying_info_idx[location][out_var->data.location_frac];
-            if (!var_info_idx)
-               continue;
+            if (!var_info_idx) {
+               /* Something went wrong, the shader interfaces didn't match, so
+                * abandon packing. This can happen for example when the
+                * inputs are scalars but the outputs are struct members.
+                */
+               *varying_comp_info_size = 0;
+               break;
+            }
 
             struct varying_component *vc_info =
                &(*varying_comp_info)[var_info_idx-1];
@@ -624,10 +631,23 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
                vc_info->is_32bit = glsl_type_is_32bit(type);
                vc_info->is_patch = out_var->data.patch;
                vc_info->is_intra_stage_only = true;
+               vc_info->initialised = true;
             }
          }
       }
    }
+
+   for (unsigned i = 0; i < *varying_comp_info_size; i++ ) {
+      struct varying_component *vc_info = &(*varying_comp_info)[i];
+      if (!vc_info->initialised) {
+         /* Something went wrong, the shader interfaces didn't match, so
+          * abandon packing. This can happen for example when the outputs are
+          * scalars but the inputs are struct members.
+          */
+         *varying_comp_info_size = 0;
+         break;
+      }
+   }
 }
 
 static void



More information about the mesa-commit mailing list