nir/lower_psiz_mov: stop clobbering existing exports
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 3 Feb 2022 15:21:19 +0000 (10:21 -0500)
committerMarge Bot <emma+marge@anholt.net>
Mon, 28 Feb 2022 15:42:19 +0000 (15:42 +0000)
for this pass to work with xfb, the original value in the shader must be
preserved when xfb is active, and the driver must export only the newly
created output

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15184>

src/compiler/nir/nir_lower_point_size_mov.c

index 58d1868..4a71d75 100644 (file)
@@ -38,7 +38,7 @@ lower_impl(nir_function_impl *impl,
 {
    nir_shader *shader = impl->function->shader;
    nir_builder b;
-   nir_variable *in;
+   nir_variable *in, *new_out = NULL;
 
    nir_builder_init(&b, impl);
 
@@ -51,12 +51,19 @@ lower_impl(nir_function_impl *impl,
          pointsize_state_tokens,
          sizeof(in->state_slots[0].tokens));
 
+   /* the existing output can't be removed in order to avoid breaking xfb.
+    * drivers must check var->data.explicit_location to find the original output
+    * and only emit that one for xfb
+    */
+   if (!out || shader->info.has_transform_feedback_varyings) {
+      new_out = nir_variable_create(shader, nir_var_shader_out,
+                                    glsl_float_type(), "gl_PointSizeMESA");
+      new_out->data.location = VARYING_SLOT_PSIZ;
+   }
+
    if (!out) {
-      out = nir_variable_create(shader, nir_var_shader_out,
-                                glsl_float_type(), "gl_PointSize");
-      out->data.location = VARYING_SLOT_PSIZ;
       b.cursor = nir_before_cf_list(&impl->body);
-      nir_copy_var(&b, out, in);
+      nir_copy_var(&b, new_out, in);
    } else {
       nir_foreach_block_safe(block, impl) {
          nir_foreach_instr_safe(instr, block) {
@@ -66,7 +73,7 @@ lower_impl(nir_function_impl *impl,
                   nir_variable *var = nir_intrinsic_get_var(intr, 0);
                   if (var == out) {
                      b.cursor = nir_after_instr(instr);
-                     nir_copy_var(&b, out, in);
+                     nir_copy_var(&b, new_out ? new_out : out, in);
                   }
                }
             }