gallivm: convert size query to using a set of parameters.
authorDave Airlie <airlied@redhat.com>
Mon, 18 Apr 2016 01:45:12 +0000 (11:45 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 18 Apr 2016 21:33:39 +0000 (07:33 +1000)
This isn't currently that easy to expand, so fix it up
before expanding it later to include dynamic samplers.

[airlied: use some local variables (Roland)]

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
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/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
src/gallium/drivers/llvmpipe/lp_tex_sample.c
src/gallium/drivers/swr/swr_tex_sample.cpp

index cb31695616236914c80e0a604279304ca0063956..1845c0560a958b606577398e8cb3f31472a2e877 100644 (file)
@@ -251,30 +251,16 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 static void
 draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                       struct gallivm_state *gallivm,
-                                      struct lp_type type,
-                                      unsigned texture_unit,
-                                      unsigned target,
-                                      LLVMValueRef context_ptr,
-                                      boolean is_sviewinfo,
-                                      enum lp_sampler_lod_property lod_property,
-                                      LLVMValueRef explicit_lod, /* optional */
-                                      LLVMValueRef *sizes_out)
+                                      const struct lp_sampler_size_query_params *params)
 {
    struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
 
-   assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+   assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    lp_build_size_query_soa(gallivm,
-                           &sampler->dynamic_state.static_state[texture_unit].texture_state,
+                           &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
                            &sampler->dynamic_state.base,
-                           type,
-                           texture_unit,
-                           target,
-                           context_ptr,
-                           is_sviewinfo,
-                           lod_property,
-                           explicit_lod,
-                           sizes_out);
+                           params);
 }
 
 struct lp_build_sampler_soa *
index 902ae41f96068c09a858b7e9884a5b5b6ec5509b..9ec051a340b7103c9e094625840c401ee2aa3971 100644 (file)
@@ -110,7 +110,17 @@ struct lp_sampler_params
    LLVMValueRef *texel;
 };
 
-
+struct lp_sampler_size_query_params
+{
+   struct lp_type int_type;
+   unsigned texture_unit;
+   unsigned target;
+   LLVMValueRef context_ptr;
+   boolean is_sviewinfo;
+   enum lp_sampler_lod_property lod_property;
+   LLVMValueRef explicit_lod;
+   LLVMValueRef *sizes_out;
+};
 /**
  * Texture static state.
  *
@@ -606,14 +616,7 @@ void
 lp_build_size_query_soa(struct gallivm_state *gallivm,
                         const struct lp_static_texture_state *static_state,
                         struct lp_sampler_dynamic_state *dynamic_state,
-                        struct lp_type int_type,
-                        unsigned texture_unit,
-                        unsigned target,
-                        LLVMValueRef context_ptr,
-                        boolean is_sviewinfo,
-                        enum lp_sampler_lod_property lod_property,
-                        LLVMValueRef explicit_lod,
-                        LLVMValueRef *sizes_out);
+                        const struct lp_sampler_size_query_params *params);
 
 void
 lp_build_sample_nop(struct gallivm_state *gallivm, 
index 937948bbb02e62a16ce8877ef05bf863dcf25e1d..83db0edc82f2081c8776e3ca7879f4f5e03c1fd4 100644 (file)
@@ -3439,14 +3439,7 @@ void
 lp_build_size_query_soa(struct gallivm_state *gallivm,
                         const struct lp_static_texture_state *static_state,
                         struct lp_sampler_dynamic_state *dynamic_state,
-                        struct lp_type int_type,
-                        unsigned texture_unit,
-                        unsigned target,
-                        LLVMValueRef context_ptr,
-                        boolean is_sviewinfo,
-                        enum lp_sampler_lod_property lod_property,
-                        LLVMValueRef explicit_lod,
-                        LLVMValueRef *sizes_out)
+                        const struct lp_sampler_size_query_params *params)
 {
    LLVMValueRef lod, level, size;
    LLVMValueRef first_level = NULL;
@@ -3454,6 +3447,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
    boolean has_array;
    unsigned num_lods = 1;
    struct lp_build_context bld_int_vec4;
+   LLVMValueRef context_ptr = params->context_ptr;
+   unsigned texture_unit = params->texture_unit;
+   unsigned target = params->target;
 
    if (static_state->format == PIPE_FORMAT_NONE) {
       /*
@@ -3461,9 +3457,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
        * all zero as mandated by d3d10 in this case.
        */
       unsigned chan;
-      LLVMValueRef zero = lp_build_const_vec(gallivm, int_type, 0.0F);
+      LLVMValueRef zero = lp_build_const_vec(gallivm, params->int_type, 0.0F);
       for (chan = 0; chan < 4; chan++) {
-         sizes_out[chan] = zero;
+         params->sizes_out[chan] = zero;
       }
       return;
    }
@@ -3508,13 +3504,13 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
       break;
    }
 
-   assert(!int_type.floating);
+   assert(!params->int_type.floating);
 
    lp_build_context_init(&bld_int_vec4, gallivm, lp_type_int_vec(32, 128));
 
-   if (explicit_lod) {
+   if (params->explicit_lod) {
       /* FIXME: this needs to honor per-element lod */
-      lod = LLVMBuildExtractElement(gallivm->builder, explicit_lod,
+      lod = LLVMBuildExtractElement(gallivm->builder, params->explicit_lod,
                                     lp_build_const_int32(gallivm, 0), "");
       first_level = dynamic_state->first_level(dynamic_state, gallivm,
                                                context_ptr, texture_unit);
@@ -3568,7 +3564,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
     * if level is out of bounds (note this can't cover unbound texture
     * here, which also requires returning zero).
     */
-   if (explicit_lod && is_sviewinfo) {
+   if (params->explicit_lod && params->is_sviewinfo) {
       LLVMValueRef last_level, out, out1;
       struct lp_build_context leveli_bld;
 
@@ -3590,13 +3586,13 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
       size = lp_build_andnot(&bld_int_vec4, size, out);
    }
    for (i = 0; i < dims + (has_array ? 1 : 0); i++) {
-      sizes_out[i] = lp_build_extract_broadcast(gallivm, bld_int_vec4.type, int_type,
+      params->sizes_out[i] = lp_build_extract_broadcast(gallivm, bld_int_vec4.type, params->int_type,
                                                 size,
                                                 lp_build_const_int32(gallivm, i));
    }
-   if (is_sviewinfo) {
+   if (params->is_sviewinfo) {
       for (; i < 4; i++) {
-         sizes_out[i] = lp_build_const_vec(gallivm, int_type, 0.0);
+         params->sizes_out[i] = lp_build_const_vec(gallivm, params->int_type, 0.0);
       }
    }
 
@@ -3604,7 +3600,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
     * if there's no explicit_lod (buffers, rects) queries requiring nr of
     * mips would be illegal.
     */
-   if (is_sviewinfo && explicit_lod) {
+   if (params->is_sviewinfo && params->explicit_lod) {
       struct lp_build_context bld_int_scalar;
       LLVMValueRef num_levels;
       lp_build_context_init(&bld_int_scalar, gallivm, lp_type_int(32));
@@ -3620,7 +3616,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
          num_levels = lp_build_sub(&bld_int_scalar, last_level, first_level);
          num_levels = lp_build_add(&bld_int_scalar, num_levels, bld_int_scalar.one);
       }
-      sizes_out[3] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, int_type),
+      params->sizes_out[3] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, params->int_type),
                                         num_levels);
    }
 }
index b005d7a0ac15b81887524130928a205f27480628..b9094dcf597c62cdf92271e2590676d236877f75 100644 (file)
@@ -194,14 +194,7 @@ struct lp_build_sampler_soa
    void
    (*emit_size_query)( const struct lp_build_sampler_soa *sampler,
                        struct gallivm_state *gallivm,
-                       struct lp_type type,
-                       unsigned unit,
-                       unsigned target,
-                       LLVMValueRef context_ptr,
-                       boolean need_nr_mips,
-                       enum lp_sampler_lod_property,
-                       LLVMValueRef explicit_lod, /* optional */
-                       LLVMValueRef *sizes_out);
+                       const struct lp_sampler_size_query_params *params);
 };
 
 
index a19be8a503ab4773a5456560d699ecc775063e10..13fd877083a790ca3f8e7abd7af46f657083b9c3 100644 (file)
@@ -2664,6 +2664,7 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld,
    unsigned i;
    unsigned unit = inst->Src[1].Register.Index;
    unsigned target, pipe_target;
+   struct lp_sampler_size_query_params params;
 
    if (is_sviewinfo) {
       target = bld->sv[unit].Resource;
@@ -2701,15 +2702,18 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld,
 
    pipe_target = tgsi_to_pipe_tex_target(target);
 
+   params.int_type = bld->bld_base.int_bld.type;
+   params.texture_unit = unit;
+   params.target = pipe_target;
+   params.context_ptr = bld->context_ptr;
+   params.is_sviewinfo = TRUE;
+   params.lod_property = lod_property;
+   params.explicit_lod = explicit_lod;
+   params.sizes_out = sizes_out;
+
    bld->sampler->emit_size_query(bld->sampler,
                                  bld->bld_base.base.gallivm,
-                                 bld->bld_base.int_bld.type,
-                                 unit, pipe_target,
-                                 bld->context_ptr,
-                                 TRUE,
-                                 lod_property,
-                                 explicit_lod,
-                                 sizes_out);
+                                 &params);
 }
 
 static boolean
index 5762b7b483344c4cf67948aaea6d151e052482ae..8adaa8e77d905c9eefb7eb7ef60e289270f82f68 100644 (file)
@@ -276,30 +276,16 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 static void
 lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                     struct gallivm_state *gallivm,
-                                    struct lp_type type,
-                                    unsigned texture_unit,
-                                    unsigned target,
-                                    LLVMValueRef context_ptr,
-                                    boolean is_sviewinfo,
-                                    enum lp_sampler_lod_property lod_property,
-                                    LLVMValueRef explicit_lod, /* optional */
-                                    LLVMValueRef *sizes_out)
+                                    const struct lp_sampler_size_query_params *params)
 {
    struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base;
 
-   assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+   assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    lp_build_size_query_soa(gallivm,
-                           &sampler->dynamic_state.static_state[texture_unit].texture_state,
+                           &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
                            &sampler->dynamic_state.base,
-                           type,
-                           texture_unit,
-                           target,
-                           context_ptr,
-                           is_sviewinfo,
-                           lod_property,
-                           explicit_lod,
-                           sizes_out);
+                           params);
 }
 
 
index 8172c820f2261656ff151263868b4188347beb6f..66d6b0fdea58fc6ebf4b97eba0ecfc852e74971a 100644 (file)
@@ -302,31 +302,17 @@ swr_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 static void
 swr_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                 struct gallivm_state *gallivm,
-                                struct lp_type type,
-                                unsigned texture_unit,
-                                unsigned target,
-                                LLVMValueRef context_ptr,
-                                boolean is_sviewinfo,
-                                enum lp_sampler_lod_property lod_property,
-                                LLVMValueRef explicit_lod, /* optional */
-                                LLVMValueRef *sizes_out)
+                                const struct lp_sampler_size_query_params *params)
 {
    struct swr_sampler_soa *sampler = (struct swr_sampler_soa *)base;
 
-   assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+   assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    lp_build_size_query_soa(
       gallivm,
-      &sampler->dynamic_state.static_state[texture_unit].texture_state,
+      &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
       &sampler->dynamic_state.base,
-      type,
-      texture_unit,
-      target,
-      context_ptr,
-      is_sviewinfo,
-      lod_property,
-      explicit_lod,
-      sizes_out);
+      params);
 }