gallium/util: Fix depth/stencil blit shaders
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 27 Nov 2020 12:07:21 +0000 (13:07 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 11 Dec 2020 09:47:38 +0000 (09:47 +0000)
When loading the depth, we want to store component X of the texel fetch
result into position.Z which can't be expressed without an extra MOV
unless the backend replicates the depth.

Stencil is always expected in the Y component, but some TGSI shaders
assume it will also be available in X, which only works if the backend
replicates the stencil value.

Let's fix those shaders so backend drivers are not forced to replicate
the depth/stencil values.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7922>

src/gallium/auxiliary/util/u_simple_shaders.c

index d2f77c4..a905150 100644 (file)
@@ -423,12 +423,12 @@ util_make_fs_blit_zs(struct pipe_context *pipe, unsigned zs_mask,
                              TGSI_RETURN_TYPE_UINT,
                              TGSI_RETURN_TYPE_UINT);
 
-      ureg_load_tex(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_X), coord,
+      ureg_load_tex(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_Y), coord,
                     stencil_sampler, tex_target, load_level_zero, use_txf);
 
       stencil = ureg_DECL_output(ureg, TGSI_SEMANTIC_STENCIL, 0);
       ureg_MOV(ureg, ureg_writemask(stencil, TGSI_WRITEMASK_Y),
-               ureg_scalar(ureg_src(tmp), TGSI_SWIZZLE_X));
+               ureg_scalar(ureg_src(tmp), TGSI_SWIZZLE_Y));
    }
 
    ureg_END(ureg);
@@ -530,6 +530,7 @@ util_make_fs_blit_msaa_gen(struct pipe_context *pipe,
                            const char *samp_type,
                            const char *output_semantic,
                            const char *output_mask,
+                           const char *swizzle,
                            const char *conversion_decl,
                            const char *conversion)
 {
@@ -545,7 +546,7 @@ util_make_fs_blit_msaa_gen(struct pipe_context *pipe,
          "F2U TEMP[0], IN[0]\n"
          "TXF TEMP[0], TEMP[0], SAMP[0], %s\n"
          "%s"
-         "MOV OUT[0]%s, TEMP[0]\n"
+         "MOV OUT[0]%s, TEMP[0]%s\n"
          "END\n";
 
    const char *type = tgsi_texture_names[tgsi_tex];
@@ -557,7 +558,7 @@ util_make_fs_blit_msaa_gen(struct pipe_context *pipe,
           tgsi_tex == TGSI_TEXTURE_2D_ARRAY_MSAA);
 
    snprintf(text, sizeof(text), shader_templ, type, samp_type,
-            output_semantic, conversion_decl, type, conversion, output_mask);
+            output_semantic, conversion_decl, type, conversion, output_mask, swizzle);
 
    if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) {
       puts(text);
@@ -608,7 +609,7 @@ util_make_fs_blit_msaa_color(struct pipe_context *pipe,
    }
 
    return util_make_fs_blit_msaa_gen(pipe, tgsi_tex, samp_type,
-                                     "COLOR[0]", "", conversion_decl,
+                                     "COLOR[0]", "", "", conversion_decl,
                                      conversion);
 }
 
@@ -623,7 +624,7 @@ util_make_fs_blit_msaa_depth(struct pipe_context *pipe,
                              enum tgsi_texture_type tgsi_tex)
 {
    return util_make_fs_blit_msaa_gen(pipe, tgsi_tex, "FLOAT",
-                                     "POSITION", ".z", "", "");
+                                     "POSITION", ".z", ".xxxx", "", "");
 }
 
 
@@ -637,7 +638,7 @@ util_make_fs_blit_msaa_stencil(struct pipe_context *pipe,
                                enum tgsi_texture_type tgsi_tex)
 {
    return util_make_fs_blit_msaa_gen(pipe, tgsi_tex, "UINT",
-                                     "STENCIL", ".y", "", "");
+                                     "STENCIL", ".y", "", "", "");
 }
 
 
@@ -660,10 +661,11 @@ util_make_fs_blit_msaa_depthstencil(struct pipe_context *pipe,
          "DCL SVIEW[1], %s, UINT\n"
          "DCL OUT[0], POSITION\n"
          "DCL OUT[1], STENCIL\n"
-         "DCL TEMP[0]\n"
+         "DCL TEMP[0..1]\n"
 
          "F2U TEMP[0], IN[0]\n"
-         "TXF OUT[0].z, TEMP[0], SAMP[0], %s\n"
+         "TXF TEMP[1], TEMP[0], SAMP[0], %s\n"
+         "MOV OUT[0].z, TEMP[1].xxxx\n"
          "TXF OUT[1].y, TEMP[0], SAMP[1], %s\n"
          "END\n";