zink: translate gl_FragColor to gl_FragData before ntv to fix multi-rt output
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 6 Jul 2020 12:58:28 +0000 (08:58 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 8 Jul 2020 14:51:34 +0000 (14:51 +0000)
according to EXT_multiview_draw_buffers, gl_FragColor outputs to all available
render targets when used, so we need to translate this to gl_FragData[PIPE_MAX_COLOR_BUFS]
in order to correctly handle more than one color buffer attachment

this fixes the rest of spec@arb_framebuffer_object tests in piglit

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5687>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/zink_compiler.c

index 76fd90ed24b5926e89274109a12d0e63e988bec7..095b8e08fcf7aa5edbeb8ee9b079fa3f23f18bf2 100644 (file)
@@ -394,15 +394,14 @@ emit_output(struct ntv_context *ctx, struct nir_variable *var)
       ctx->so_output_gl_types[var->data.location] = var->type;
       ctx->so_output_types[var->data.location] = var_type;
    } else if (ctx->stage == MESA_SHADER_FRAGMENT) {
-      if (var->data.location >= FRAG_RESULT_DATA0)
+      if (var->data.location >= FRAG_RESULT_DATA0) {
          spirv_builder_emit_location(&ctx->builder, var_id,
                                      var->data.location - FRAG_RESULT_DATA0);
-      else {
+         spirv_builder_emit_index(&ctx->builder, var_id, var->data.index);
+      } else {
          switch (var->data.location) {
          case FRAG_RESULT_COLOR:
-            spirv_builder_emit_location(&ctx->builder, var_id, 0);
-            spirv_builder_emit_index(&ctx->builder, var_id, var->data.index);
-            break;
+            unreachable("gl_FragColor should be lowered by now");
 
          case FRAG_RESULT_DEPTH:
             spirv_builder_emit_builtin(&ctx->builder, var_id, SpvBuiltInFragDepth);
@@ -411,6 +410,7 @@ emit_output(struct ntv_context *ctx, struct nir_variable *var)
          default:
             spirv_builder_emit_location(&ctx->builder, var_id,
                                         var->data.driver_location);
+            spirv_builder_emit_index(&ctx->builder, var_id, var->data.index);
          }
       }
    }
index 9761b8e18058d53f3890ab6a9b600bf9bb403f25..65d4a2e33901aff12274925640e9479099e16825 100644 (file)
@@ -191,6 +191,7 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir,
    optimize_nir(nir);
    NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp, NULL);
    NIR_PASS_V(nir, lower_discard_if);
+   NIR_PASS_V(nir, nir_lower_fragcolor);
    NIR_PASS_V(nir, nir_convert_from_ssa, true);
 
    if (zink_debug & ZINK_DEBUG_NIR) {