gallivm/nir: fixup compact TCS variable storage.
authorDave Airlie <airlied@redhat.com>
Tue, 7 Apr 2020 01:11:51 +0000 (11:11 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 19 Aug 2020 00:16:36 +0000 (10:16 +1000)
This fixes a lot of tessellation shaders, since tess factors
get emitted with spir-v now.

Fixes a bunch of:
dEQP-VK.tessellation*
along with 7000 others.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6339>

src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
src/gallium/drivers/swr/swr_shader.cpp

index 22644aa5eabcd46b12dd0787f6492a8e110b78e3..aabece0ce135403f1ce7f5c7d81086cb12ce932f 100644 (file)
@@ -3189,6 +3189,7 @@ draw_tcs_llvm_emit_store_output(const struct lp_build_tcs_iface *tes_iface,
                                 LLVMValueRef vertex_index,
                                 boolean is_aindex_indirect,
                                 LLVMValueRef attrib_index,
+                                boolean is_sindex_indirect,
                                 LLVMValueRef swizzle_index,
                                 LLVMValueRef value,
                                 LLVMValueRef mask_vec)
@@ -3200,13 +3201,14 @@ draw_tcs_llvm_emit_store_output(const struct lp_build_tcs_iface *tes_iface,
    LLVMValueRef res;
    struct lp_type type = bld->type;
 
-   if (is_vindex_indirect || is_aindex_indirect) {
+   if (is_vindex_indirect || is_aindex_indirect || is_sindex_indirect) {
       int i;
 
       for (i = 0; i < type.length; ++i) {
          LLVMValueRef idx = lp_build_const_int32(gallivm, i);
          LLVMValueRef vert_chan_index = vertex_index ? vertex_index : lp_build_const_int32(gallivm, 0);
          LLVMValueRef attr_chan_index = attrib_index;
+         LLVMValueRef swiz_chan_index = swizzle_index;
          LLVMValueRef channel_vec;
 
          if (is_vindex_indirect) {
@@ -3218,9 +3220,14 @@ draw_tcs_llvm_emit_store_output(const struct lp_build_tcs_iface *tes_iface,
                                                       attrib_index, idx, "");
          }
 
+         if (is_sindex_indirect) {
+            swiz_chan_index = LLVMBuildExtractElement(builder,
+                                                      swizzle_index, idx, "");
+         }
+
          indices[0] = vert_chan_index;
          indices[1] = attr_chan_index;
-         indices[2] = swizzle_index;
+         indices[2] = swiz_chan_index;
 
          channel_vec = LLVMBuildGEP(builder, tcs->output, indices, 3, "");
 
index b07e556ecc91d7559d9a219b77c3745f1251b064..ad6df764f6fbee35637ead1d4c4f6589e9e13b99 100644 (file)
@@ -487,6 +487,7 @@ static void emit_store_chan(struct lp_build_nir_context *bld_base,
 }
 
 static void emit_store_tcs_chan(struct lp_build_nir_context *bld_base,
+                                bool is_compact,
                                 unsigned bit_size,
                                 unsigned location,
                                 unsigned const_index,
@@ -512,9 +513,13 @@ static void emit_store_tcs_chan(struct lp_build_nir_context *bld_base,
    LLVMValueRef attrib_index_val;
    LLVMValueRef swizzle_index_val = lp_build_const_int32(gallivm, swizzle);
 
-   if (indir_index)
-      attrib_index_val = lp_build_add(&bld_base->uint_bld, indir_index, lp_build_const_int_vec(gallivm, bld_base->uint_bld.type, location));
-   else
+   if (indir_index) {
+      if (is_compact) {
+         swizzle_index_val = lp_build_add(&bld_base->uint_bld, indir_index, lp_build_const_int_vec(gallivm, bld_base->uint_bld.type, swizzle));
+         attrib_index_val = lp_build_const_int32(gallivm, const_index + location);
+      } else
+         attrib_index_val = lp_build_add(&bld_base->uint_bld, indir_index, lp_build_const_int_vec(gallivm, bld_base->uint_bld.type, location));
+   } else
       attrib_index_val = lp_build_const_int32(gallivm, const_index + location);
    if (bit_size == 64) {
       LLVMValueRef split_vals[2];
@@ -524,21 +529,25 @@ static void emit_store_tcs_chan(struct lp_build_nir_context *bld_base,
                                         indir_vertex_index ? true : false,
                                         indir_vertex_index,
                                         indir_index ? true : false,
-                                        attrib_index_val, swizzle_index_val,
+                                        attrib_index_val,
+                                        false, swizzle_index_val,
                                         split_vals[0], mask_vec(bld_base));
       bld->tcs_iface->emit_store_output(bld->tcs_iface, &bld_base->base, 0,
                                         indir_vertex_index ? true : false,
                                         indir_vertex_index,
                                         indir_index ? true : false,
-                                        attrib_index_val, swizzle_index_val2,
+                                        attrib_index_val,
+                                        false, swizzle_index_val2,
                                         split_vals[1], mask_vec(bld_base));
    } else {
       chan_val = LLVMBuildBitCast(builder, chan_val, bld_base->base.vec_type, "");
       bld->tcs_iface->emit_store_output(bld->tcs_iface, &bld_base->base, 0,
                                         indir_vertex_index ? true : false,
                                         indir_vertex_index,
-                                        indir_index ? true : false,
-                                        attrib_index_val, swizzle_index_val,
+                                        indir_index && !is_compact ? true : false,
+                                        attrib_index_val,
+                                        indir_index && is_compact ? true : false,
+                                        swizzle_index_val,
                                         chan_val, mask_vec(bld_base));
    }
 }
@@ -567,11 +576,17 @@ static void emit_store_var(struct lp_build_nir_context *bld_base,
             comp = 2;
       }
 
+      if (var->data.compact) {
+         location += const_index / 4;
+         comp += const_index % 4;
+         const_index = 0;
+      }
+
       for (unsigned chan = 0; chan < num_components; chan++) {
          if (writemask & (1u << chan)) {
             LLVMValueRef chan_val = (num_components == 1) ? dst : LLVMBuildExtractValue(builder, dst, chan, "");
             if (bld->tcs_iface) {
-               emit_store_tcs_chan(bld_base, bit_size, location, const_index, indir_vertex_index, indir_index, comp, chan, chan_val);
+               emit_store_tcs_chan(bld_base, var->data.compact, bit_size, location, const_index, indir_vertex_index, indir_index, comp, chan, chan_val);
             } else
                emit_store_chan(bld_base, deref_mode, bit_size, location + const_index, comp, chan, chan_val);
          }
index 856cea40c55ebd600deb4a1e2835af2af642c1c4..12bf55b3f40b8c3b38116e619c255969b54a1420 100644 (file)
@@ -459,6 +459,7 @@ struct lp_build_tcs_iface
                              LLVMValueRef vertex_index,
                              boolean is_aindex_indirect,
                              LLVMValueRef attrib_index,
+                             boolean is_sindex_indirect,
                              LLVMValueRef swizzle_index,
                              LLVMValueRef value,
                              LLVMValueRef mask_vec);
index f3f339923dbc246957fb073b3f8217bc571e997e..5104a572c4dc78ba2274817e2cee1af09fef60e9 100644 (file)
@@ -1763,6 +1763,7 @@ emit_store_tcs_output(struct lp_build_tgsi_context *bld_base,
                                           vertex_index,
                                           reg->Register.Indirect,
                                           attrib_index,
+                                          false,
                                           channel_index,
                                           value,
                                           mask_vec(bld_base));
index cc3bf717653fd6c09a1eb109818123e45c34b6dc..e5f0074033a88755c7e7aef8c423f16a0ecd3c68 100644 (file)
@@ -611,6 +611,7 @@ void swr_tcs_llvm_store_output(const struct lp_build_tcs_iface *tcs_iface,
                          LLVMValueRef vertex_index,
                          boolean is_aindex_indirect,
                          LLVMValueRef attrib_index,
+                         boolean is_sindex_indirect,
                          LLVMValueRef swizzle_index,
                          LLVMValueRef value,
                          LLVMValueRef mask_vec)