draw: add support for indirect texture access
authorDave Airlie <airlied@redhat.com>
Tue, 19 May 2020 02:18:20 +0000 (12:18 +1000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Jul 2020 04:12:17 +0000 (04:12 +0000)
This hooks up the switch statement generator to the draw code.

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

index eee0c6319e5631e5e493612002ef64a5cc9d843c..26aa7fe1e31a3589f796f5c6325d2eea12357586 100644 (file)
@@ -318,10 +318,27 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
    assert(texture_index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
    assert(sampler_index < PIPE_MAX_SAMPLERS);
 
-   lp_build_sample_soa(&sampler->dynamic_state.static_state[texture_index].texture_state,
-                       &sampler->dynamic_state.static_state[sampler_index].sampler_state,
-                       &sampler->dynamic_state.base,
-                       gallivm, params);
+   if (params->texture_index_offset) {
+      struct lp_build_sample_array_switch switch_info;
+      memset(&switch_info, 0, sizeof(switch_info));
+      LLVMValueRef unit = LLVMBuildAdd(gallivm->builder, params->texture_index_offset,
+                                       lp_build_const_int32(gallivm, texture_index), "");
+      lp_build_sample_array_init_soa(&switch_info, gallivm, params, unit,
+                                     0, sampler->nr_samplers);
+
+      for (unsigned i = 0; i < sampler->nr_samplers; i++) {
+         lp_build_sample_array_case_soa(&switch_info, i,
+                                        &sampler->dynamic_state.static_state[i].texture_state,
+                                        &sampler->dynamic_state.static_state[i].sampler_state,
+                                        &sampler->dynamic_state.base);
+      }
+      lp_build_sample_array_fini_soa(&switch_info);
+   } else {
+      lp_build_sample_soa(&sampler->dynamic_state.static_state[texture_index].texture_state,
+                          &sampler->dynamic_state.static_state[sampler_index].sampler_state,
+                          &sampler->dynamic_state.base,
+                          gallivm, params);
+   }
 }