mesa: Emit full output write in st_pbo_create_vs().
authorEmma Anholt <emma@anholt.net>
Thu, 1 Jun 2023 19:35:09 +0000 (12:35 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 12 Jun 2023 17:37:54 +0000 (17:37 +0000)
In most VS creation paths in the frontend, nir_lower_io_to_temporaries()
is called, which ensures that all outputs have a single write to them
(with a full writemask).  The builtins don't, however, and this VS was an
oddball that overwrote one channel of an output that it had already
written.  We can avoid surprises for backends (such as d3d12 and v3d) by
emitting a single write per output here.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23114>

src/mesa/state_tracker/st_pbo.c

index 3b5f121..15f3718 100644 (file)
@@ -299,17 +299,18 @@ st_pbo_create_vs(struct st_context *st)
    nir_variable *out_pos = nir_create_variable_with_location(b.shader, nir_var_shader_out,
                                                              VARYING_SLOT_POS, vec4);
 
-   nir_copy_var(&b, out_pos, in_pos);
+   if (!st->pbo.use_gs)
+      nir_copy_var(&b, out_pos, in_pos);
 
    if (st->pbo.layers) {
       nir_variable *instance_id = nir_create_variable_with_location(b.shader, nir_var_system_value,
                                                                     SYSTEM_VALUE_INSTANCE_ID, glsl_int_type());
 
       if (st->pbo.use_gs) {
-         unsigned swiz_x[4] = {0, 0, 0, 0};
          nir_store_var(&b, out_pos,
-                       nir_swizzle(&b, nir_i2f32(&b, nir_load_var(&b, instance_id)), swiz_x, 4),
-                       (1 << 2));
+                       nir_vector_insert_imm(&b, nir_load_var(&b, in_pos),
+                                             nir_i2f32(&b, nir_load_var(&b, instance_id)), 2),
+                       0xf);
       } else {
          nir_variable *out_layer = nir_create_variable_with_location(b.shader, nir_var_shader_out,
                                                                      VARYING_SLOT_LAYER, glsl_int_type());