broadcom/vc5: Add lowering for txf_ms to a txf on a 2x2-scaled texture.
authorEric Anholt <eric@anholt.net>
Tue, 24 Oct 2017 19:16:50 +0000 (12:16 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 30 Oct 2017 20:31:27 +0000 (13:31 -0700)
The HW has no native sampler support for multisample textures, but since
we only need to support txf_ms and the layout is UIF, we just need to
scale up the texcoords and then add in the sample.

This drops the old TEXTURE_MSAA_ADDR special uniform, since we're treating
MSAA textures as textures, rather than basically texbos like VC4 had to.

src/broadcom/Makefile.sources
src/broadcom/compiler/meson.build
src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/v3d_nir_lower_txf_ms.c [new file with mode: 0644]
src/broadcom/compiler/vir.c
src/gallium/drivers/vc5/vc5_uniforms.c

index b60d2bcaa5d5c7040dbfa80d25270f928b83be66..bc3a695e915058a905d7d2df170554f522f7820a 100644 (file)
@@ -29,6 +29,7 @@ BROADCOM_FILES = \
        compiler/qpu_validate.c \
        compiler/v3d_compiler.h \
        compiler/v3d_nir_lower_io.c \
+       compiler/v3d_nir_lower_txf_ms.c \
        qpu/qpu_disasm.c \
        qpu/qpu_disasm.h \
        qpu/qpu_instr.c \
index 3c6281956f1cacee175e8c129f5fc334ed73c72d..fd4d05fdbb76490528921897e5a173aac5e59fa8 100644 (file)
@@ -32,6 +32,7 @@ libbroadcom_compiler_files = files(
   'qpu_validate.c',
   'v3d_compiler.h',
   'v3d_nir_lower_io.c',
+  'v3d_nir_lower_txf_ms.c',
 )
 
 libbroadcom_compiler = static_library(
index 56a9d143e3253f493037a5e01c215e8ab62cbbbe..1111102e6b13688a14ffdd9f3240500aa83e6051 100644 (file)
@@ -229,8 +229,6 @@ enum quniform_contents {
         QUNIFORM_TEXTURE_ARRAY_SIZE,
         QUNIFORM_TEXTURE_LEVELS,
 
-        QUNIFORM_TEXTURE_MSAA_ADDR,
-
         QUNIFORM_UBO_ADDR,
 
         QUNIFORM_TEXRECT_SCALE_X,
diff --git a/src/broadcom/compiler/v3d_nir_lower_txf_ms.c b/src/broadcom/compiler/v3d_nir_lower_txf_ms.c
new file mode 100644 (file)
index 0000000..ffaee0d
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2015 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "v3d_compiler.h"
+#include "compiler/nir/nir_builder.h"
+
+/** @file v3d_nir_lower_txf_ms.c
+ *
+ * V3D's MSAA surfaces are laid out in UIF textures where each pixel is a 2x2
+ * quad in the texture.  This pass lowers the txf_ms with a ms_index source to
+ * a plain txf with the sample_index pulling out the correct texel from the
+ * 2x2 quad.
+ */
+
+#define V3D_MAX_SAMPLES 4
+
+static void
+vc4_nir_lower_txf_ms_instr(struct v3d_compile *c, nir_builder *b,
+                           nir_tex_instr *instr)
+{
+        if (instr->op != nir_texop_txf_ms)
+                return;
+
+        b->cursor = nir_before_instr(&instr->instr);
+
+        int coord_index = nir_tex_instr_src_index(instr, nir_tex_src_coord);
+        int sample_index = nir_tex_instr_src_index(instr, nir_tex_src_ms_index);
+        nir_ssa_def *coord = instr->src[coord_index].src.ssa;
+        nir_ssa_def *sample = instr->src[sample_index].src.ssa;
+
+        nir_ssa_def *one = nir_imm_int(b, 1);
+        coord = nir_ishl(b, coord, nir_imm_int(b, 1));
+        coord = nir_vec2(b,
+                         nir_iadd(b,
+                                  nir_channel(b, coord, 0),
+                                  nir_iand(b, sample, one)),
+                         nir_iadd(b,
+                                  nir_channel(b, coord, 1),
+                                  nir_iand(b, nir_ushr(b, sample, one), one)));
+
+        nir_instr_rewrite_src(&instr->instr,
+                              &instr->src[nir_tex_src_coord].src,
+                              nir_src_for_ssa(coord));
+        nir_tex_instr_remove_src(instr, sample_index);
+        instr->op = nir_texop_txf;
+        instr->sampler_dim = GLSL_SAMPLER_DIM_2D;
+}
+
+void
+v3d_nir_lower_txf_ms(nir_shader *s, struct v3d_compile *c)
+{
+        nir_foreach_function(function, s) {
+                if (!function->impl)
+                        continue;
+
+                nir_builder b;
+                nir_builder_init(&b, function->impl);
+
+                nir_foreach_block(block, function->impl) {
+                        nir_foreach_instr_safe(instr, block) {
+                                if (instr->type != nir_instr_type_tex)
+                                        continue;
+
+                                vc4_nir_lower_txf_ms_instr(c, &b,
+                                                           nir_instr_as_tex(instr));
+                        }
+                }
+
+                nir_metadata_preserve(function->impl,
+                                      nir_metadata_block_index |
+                                      nir_metadata_dominance);
+        }
+}
index d9201e68dc541b34205a2c1d3fddc24ebc4c6341..e7c050923c7a5276ff7c322dbbffe9bb244f6764 100644 (file)
@@ -569,6 +569,7 @@ static void
 v3d_lower_nir_late(struct v3d_compile *c)
 {
         NIR_PASS_V(c->s, v3d_nir_lower_io, c);
+        NIR_PASS_V(c->s, v3d_nir_lower_txf_ms, c);
         NIR_PASS_V(c->s, nir_lower_idiv);
 }
 
index 0c8bee51784b5b6937ef241ec55c69910b0bb9bf..37354b8bb84c644816d7f8b2c77af01ea872c625 100644 (file)
@@ -324,7 +324,6 @@ vc5_write_uniforms(struct vc5_context *vc5, struct vc5_compiled_shader *shader,
                         break;
 
                 case QUNIFORM_TEXTURE_FIRST_LEVEL:
-                case QUNIFORM_TEXTURE_MSAA_ADDR:
                 case QUNIFORM_TEXTURE_BORDER_COLOR:
                         /* XXX */
                         break;
@@ -382,7 +381,6 @@ vc5_set_shader_uniform_dirty_flags(struct vc5_compiled_shader *shader)
                 case QUNIFORM_TEXTURE_CONFIG_P1:
                 case QUNIFORM_TEXTURE_BORDER_COLOR:
                 case QUNIFORM_TEXTURE_FIRST_LEVEL:
-                case QUNIFORM_TEXTURE_MSAA_ADDR:
                 case QUNIFORM_TEXRECT_SCALE_X:
                 case QUNIFORM_TEXRECT_SCALE_Y:
                 case QUNIFORM_TEXTURE_WIDTH: