gallivm/nir: refactor image operations for indirect support.
authorDave Airlie <airlied@redhat.com>
Tue, 16 Jun 2020 02:49:30 +0000 (12:49 +1000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Jul 2020 04:12:17 +0000 (04:12 +0000)
This just refactors the image code, so that outdata is passed
explicitly, and refactors the internal handling of NONE formats.

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

src/gallium/auxiliary/draw/draw_llvm_sample.c
src/gallium/auxiliary/gallivm/lp_bld_sample.h
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
src/gallium/drivers/llvmpipe/lp_tex_sample.c

index ed78066d6900fc1938eddfec14f78968ef0d0d99..fa5729e3ef65dca541b70657458e5be56f82c6ca 100644 (file)
@@ -422,7 +422,7 @@ draw_llvm_image_soa_emit_op(const struct lp_build_image_soa *base,
 
    lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state,
                        &image->dynamic_state.base,
-                       gallivm, params);
+                       gallivm, params, params->outdata);
 }
 /**
  * Fetch the texture size.
index 9b42d3faad5c17f2cc28d1f3fd2a3cf2577acd0f..399c24df1d6094de7d1ea7ac196e96924d372cbe 100644 (file)
@@ -706,9 +706,10 @@ lp_build_minify(struct lp_build_context *bld,
 
 void
 lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
-                      struct lp_sampler_dynamic_state *dynamic_state,
-                      struct gallivm_state *gallivm,
-                      const struct lp_img_params *params);
+                    struct lp_sampler_dynamic_state *dynamic_state,
+                    struct gallivm_state *gallivm,
+                    const struct lp_img_params *params,
+                    LLVMValueRef outdata[4]);
 
 void
 lp_build_sample_array_init_soa(struct lp_build_sample_array_switch *switch_info,
index a05b9efcc42ab3839153d35799ec29e2ece9e2e1..a852490f041da9fc8dd49bd461ef9dbac6edaf90 100644 (file)
@@ -4093,11 +4093,29 @@ lp_build_do_atomic_soa(struct gallivm_state *gallivm,
    atomic_result[0] = LLVMBuildLoad(gallivm->builder, atom_res, "");
 }
 
+static void
+lp_build_img_op_no_format(struct gallivm_state *gallivm,
+                          const struct lp_img_params *params,
+                          LLVMValueRef outdata[4])
+{
+   /*
+    * If there's nothing bound, format is NONE, and we must return
+    * all zero as mandated by d3d10 in this case.
+       */
+   if (params->img_op != LP_IMG_STORE) {
+      LLVMValueRef zero = lp_build_zero(gallivm, params->type);
+      for (unsigned chan = 0; chan < (params->img_op == LP_IMG_LOAD ? 4 : 1); chan++) {
+         outdata[chan] = zero;
+      }
+   }
+}
+
 void
 lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
                     struct lp_sampler_dynamic_state *dynamic_state,
                     struct gallivm_state *gallivm,
-                    const struct lp_img_params *params)
+                    const struct lp_img_params *params,
+                    LLVMValueRef outdata[4])
 {
    unsigned target = params->target;
    unsigned dims = texture_dims(target);
@@ -4113,6 +4131,10 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
    lp_build_context_init(&int_bld, gallivm, int_type);
    lp_build_context_init(&int_coord_bld, gallivm, int_coord_type);
 
+   if (static_texture_state->format == PIPE_FORMAT_NONE) {
+      lp_build_img_op_no_format(gallivm, params, outdata);
+      return;
+   }
    LLVMValueRef offset, i, j;
 
    LLVMValueRef row_stride = dynamic_state->row_stride(dynamic_state, gallivm,
@@ -4184,19 +4206,6 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
          }
       }
 
-      if (static_texture_state->format == PIPE_FORMAT_NONE) {
-         /*
-          * If there's nothing bound, format is NONE, and we must return
-          * all zero as mandated by d3d10 in this case.
-          */
-         unsigned chan;
-         LLVMValueRef zero = lp_build_zero(gallivm, params->type);
-         for (chan = 0; chan < 4; chan++) {
-            params->outdata[chan] = zero;
-         }
-         return;
-      }
-
       offset = lp_build_andnot(&int_coord_bld, offset, out_of_bounds);
       struct lp_build_context texel_bld;
       lp_build_context_init(&texel_bld, gallivm, texel_type);
@@ -4206,28 +4215,18 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
                               base_ptr, offset,
                               i, j,
                               NULL,
-                              params->outdata);
+                              outdata);
 
       for (unsigned chan = 0; chan < 4; chan++) {
-         params->outdata[chan] = lp_build_select(&texel_bld, out_of_bounds,
-                                                 texel_bld.zero, params->outdata[chan]);
+         outdata[chan] = lp_build_select(&texel_bld, out_of_bounds,
+                                         texel_bld.zero, outdata[chan]);
       }
    } else if (params->img_op == LP_IMG_STORE) {
-      if (static_texture_state->format == PIPE_FORMAT_NONE)
-         return;
       lp_build_store_rgba_soa(gallivm, format_desc, params->type, params->exec_mask, base_ptr, offset, out_of_bounds,
                               params->indata);
    } else {
-      if (static_texture_state->format == PIPE_FORMAT_NONE) {
-         /*
-         * For atomic operation just return 0 in the unbound case to avoid a crash.
-          */
-         LLVMValueRef zero = lp_build_zero(gallivm, params->type);
-         params->outdata[0] = zero;
-         return;
-      }
       lp_build_do_atomic_soa(gallivm, format_desc, params->type, params->exec_mask, base_ptr, offset, out_of_bounds,
-                             params->img_op, params->op, params->indata, params->indata2, params->outdata);
+                             params->img_op, params->op, params->indata, params->indata2, outdata);
    }
 }
 
index 1f29be56bf1deb6d7a579c11ebc13fb0af189e8f..6197275b761d5471d1172022567c9df0d8724b1a 100644 (file)
@@ -474,7 +474,7 @@ lp_llvm_image_soa_emit_op(const struct lp_build_image_soa *base,
 
    lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state,
                        &image->dynamic_state.base,
-                       gallivm, params);
+                       gallivm, params, params->outdata);
 }
 
 /**