gallivm/sample: pass indirect offset into texture/image units
authorDave Airlie <airlied@redhat.com>
Mon, 15 Jun 2020 07:00:20 +0000 (17:00 +1000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Jul 2020 04:12:17 +0000 (04:12 +0000)
This isn't needed for the basic indirect code, but it is needed for
texture size/image size unfortunately. They could be done with a super
switch, but it seems simple to query them.

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.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
src/gallium/drivers/swr/swr_tex_sample.cpp

index 26aa7fe1e31a3589f796f5c6325d2eea12357586..76b83730004ab341792129f9c17c3d8ac88a076b 100644 (file)
@@ -101,6 +101,7 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
                          struct gallivm_state *gallivm,
                          LLVMValueRef context_ptr,
                          unsigned texture_unit,
+                         LLVMValueRef texture_unit_offset,
                          unsigned member_index,
                          const char *member_name,
                          boolean emit_load)
@@ -192,6 +193,7 @@ draw_llvm_image_member(const struct lp_sampler_dynamic_state *base,
                        struct gallivm_state *gallivm,
                        LLVMValueRef context_ptr,
                        unsigned image_unit,
+                       LLVMValueRef image_unit_offset,
                        unsigned member_index,
                        const char *member_name,
                        boolean emit_load)
@@ -238,10 +240,12 @@ draw_llvm_image_member(const struct lp_sampler_dynamic_state *base,
    draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
                               struct gallivm_state *gallivm,               \
                               LLVMValueRef context_ptr,                    \
-                              unsigned texture_unit)                       \
+                              unsigned texture_unit,                       \
+                              LLVMValueRef texture_unit_offset)            \
    { \
       return draw_llvm_texture_member(base, gallivm, context_ptr, \
-                                      texture_unit, _index, #_name, _emit_load ); \
+                                      texture_unit, texture_unit_offset, \
+                                      _index, #_name, _emit_load );     \
    }
 
 
@@ -277,12 +281,13 @@ DRAW_LLVM_SAMPLER_MEMBER(border_color, DRAW_JIT_SAMPLER_BORDER_COLOR, FALSE)
 #define DRAW_LLVM_IMAGE_MEMBER(_name, _index, _emit_load)  \
    static LLVMValueRef \
    draw_llvm_image_##_name( const struct lp_sampler_dynamic_state *base, \
-                              struct gallivm_state *gallivm,               \
-                              LLVMValueRef context_ptr,                    \
-                              unsigned image_unit)                       \
+                            struct gallivm_state *gallivm,               \
+                            LLVMValueRef context_ptr,                    \
+                            unsigned image_unit, LLVMValueRef image_unit_offset) \
    { \
       return draw_llvm_image_member(base, gallivm, context_ptr, \
-                                      image_unit, _index, #_name, _emit_load ); \
+                                    image_unit, image_unit_offset, \
+                                    _index, #_name, _emit_load );  \
    }
 
 
index 8e453580b16e8a775d8579fda086d3ef2baefa41..18b780d4cb8c9b490f92bcf10a845119a74411cb 100644 (file)
@@ -282,7 +282,7 @@ lp_build_rho(struct lp_build_sample_context *bld,
     */
 
    first_level = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
-                                                 bld->context_ptr, texture_unit);
+                                                 bld->context_ptr, texture_unit, NULL);
    first_level_vec = lp_build_broadcast_scalar(int_size_bld, first_level);
    int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec, TRUE);
    float_size = lp_build_int_to_float(float_size_bld, int_size);
@@ -947,9 +947,9 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
    LLVMValueRef first_level, last_level, level;
 
    first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
-                                            bld->context_ptr, texture_unit);
+                                            bld->context_ptr, texture_unit, NULL);
    last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
-                                          bld->context_ptr, texture_unit);
+                                          bld->context_ptr, texture_unit, NULL);
    first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
    last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
 
@@ -1009,9 +1009,9 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
    assert(bld->num_lods == bld->num_mips);
 
    first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
-                                            bld->context_ptr, texture_unit);
+                                            bld->context_ptr, texture_unit, NULL);
    last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
-                                          bld->context_ptr, texture_unit);
+                                          bld->context_ptr, texture_unit, NULL);
    first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
    last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
 
index 24fc06ffe722c24ec832bd1f78962f7bb9c95e7a..22fab7445aa40a13771bbe331082256c46365e7a 100644 (file)
@@ -226,77 +226,77 @@ struct lp_sampler_dynamic_state
    (*width)(const struct lp_sampler_dynamic_state *state,
             struct gallivm_state *gallivm,
             LLVMValueRef context_ptr,
-            unsigned texture_unit);
+            unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain the base texture height (returns int32) */
    LLVMValueRef
    (*height)(const struct lp_sampler_dynamic_state *state,
              struct gallivm_state *gallivm,
              LLVMValueRef context_ptr,
-             unsigned texture_unit);
+             unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain the base texture depth (or array size) (returns int32) */
    LLVMValueRef
    (*depth)(const struct lp_sampler_dynamic_state *state,
             struct gallivm_state *gallivm,
             LLVMValueRef context_ptr,
-            unsigned texture_unit);
+            unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain the first mipmap level (base level) (returns int32) */
    LLVMValueRef
    (*first_level)(const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
                   LLVMValueRef context_ptr,
-                  unsigned texture_unit);
+                  unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain the number of mipmap levels minus one (returns int32) */
    LLVMValueRef
    (*last_level)(const struct lp_sampler_dynamic_state *state,
                  struct gallivm_state *gallivm,
                  LLVMValueRef context_ptr,
-                 unsigned texture_unit);
+                 unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain stride in bytes between image rows/blocks (returns int32) */
    LLVMValueRef
    (*row_stride)(const struct lp_sampler_dynamic_state *state,
                  struct gallivm_state *gallivm,
                  LLVMValueRef context_ptr,
-                 unsigned texture_unit);
+                 unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain stride in bytes between image slices (returns int32) */
    LLVMValueRef
    (*img_stride)(const struct lp_sampler_dynamic_state *state,
                  struct gallivm_state *gallivm,
                  LLVMValueRef context_ptr,
-                 unsigned texture_unit);
+                 unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain pointer to base of texture */
    LLVMValueRef
    (*base_ptr)(const struct lp_sampler_dynamic_state *state,
                struct gallivm_state *gallivm,
                LLVMValueRef context_ptr,
-               unsigned texture_unit);
+               unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain pointer to array of mipmap offsets */
    LLVMValueRef
    (*mip_offsets)(const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
                   LLVMValueRef context_ptr,
-                  unsigned texture_unit);
+                  unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain number of samples (returns int32) */
    LLVMValueRef
    (*num_samples)(const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
                   LLVMValueRef context_ptr,
-                  unsigned texture_unit);
+                  unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /** Obtain multisample stride (returns int32) */
    LLVMValueRef
    (*sample_stride)(const struct lp_sampler_dynamic_state *state,
                     struct gallivm_state *gallivm,
                     LLVMValueRef context_ptr,
-                    unsigned texture_unit);
+                    unsigned texture_unit, LLVMValueRef texture_unit_offset);
 
    /* These are callbacks for sampler state */
 
index 2422405fa30f1477cc718c4b18cc16f5b074a7f5..48f0e35d486d37fc956bed6861b99daec91673a1 100644 (file)
@@ -2035,7 +2035,7 @@ lp_build_layer_coord(struct lp_build_sample_context *bld,
    struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
 
    num_layers = bld->dynamic_state->depth(bld->dynamic_state, bld->gallivm,
-                                          bld->context_ptr, texture_unit);
+                                          bld->context_ptr, texture_unit, NULL);
 
    if (out_of_bounds) {
       LLVMValueRef out1, out;
@@ -2157,11 +2157,11 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
          last_level = bld->dynamic_state->last_level(bld->dynamic_state,
                                                      bld->gallivm,
                                                      bld->context_ptr,
-                                                     texture_index);
+                                                     texture_index, NULL);
          first_level = bld->dynamic_state->first_level(bld->dynamic_state,
                                                        bld->gallivm,
                                                        bld->context_ptr,
-                                                       texture_index);
+                                                       texture_index, NULL);
          last_level = lp_build_sub(&bld->int_bld, last_level, first_level);
          last_level = lp_build_int_to_float(&bld->float_bld, last_level);
          last_level = lp_build_broadcast_scalar(&bld->lodf_bld, last_level);
@@ -2203,7 +2203,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
       /* always use mip level 0 */
       first_level = bld->dynamic_state->first_level(bld->dynamic_state,
                                                     bld->gallivm, bld->context_ptr,
-                                                    texture_index);
+                                                    texture_index, NULL);
       first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level);
       *ilevel0 = first_level;
       break;
@@ -2650,7 +2650,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld,
       assert(bld->num_mips == 1);
       if (bld->static_texture_state->target != PIPE_BUFFER) {
          ilevel = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
-                                                  bld->context_ptr, texture_unit);
+                                                  bld->context_ptr, texture_unit, NULL);
       }
       else {
          ilevel = lp_build_const_int32(bld->gallivm, 0);
@@ -2719,7 +2719,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld,
    if (bld->fetch_ms) {
       LLVMValueRef num_samples;
       num_samples = bld->dynamic_state->num_samples(bld->dynamic_state, bld->gallivm,
-                                                    bld->context_ptr, texture_unit);
+                                                    bld->context_ptr, texture_unit, NULL);
       out1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, ms_index, int_coord_bld->zero);
       out_of_bounds = lp_build_or(int_coord_bld, out_of_bounds, out1);
       out1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, ms_index, lp_build_broadcast_scalar(int_coord_bld, num_samples));
@@ -3063,19 +3063,19 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
 
    /* Get the dynamic state */
    tex_width = dynamic_state->width(dynamic_state, gallivm,
-                                    context_ptr, texture_index);
+                                    context_ptr, texture_index, NULL);
    bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm,
-                                                    context_ptr, texture_index);
+                                                    context_ptr, texture_index, NULL);
    bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm,
-                                                    context_ptr, texture_index);
+                                                    context_ptr, texture_index, NULL);
    bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm,
-                                          context_ptr, texture_index);
+                                          context_ptr, texture_index, NULL);
    bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm,
-                                                context_ptr, texture_index);
+                                                context_ptr, texture_index, NULL);
 
    if (fetch_ms)
       bld.sample_stride = lp_build_broadcast_scalar(&bld.int_coord_bld, dynamic_state->sample_stride(dynamic_state, gallivm,
-                                                                                                     context_ptr, texture_index));
+                                                                                                     context_ptr, texture_index, NULL));
    /* Note that mip_offsets is an array[level] of offsets to texture images */
 
    if (dynamic_state->cache_ptr && thread_data_ptr) {
@@ -3094,14 +3094,14 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
       if (dims >= 2) {
          LLVMValueRef tex_height =
             dynamic_state->height(dynamic_state, gallivm,
-                                  context_ptr, texture_index);
+                                  context_ptr, texture_index, NULL);
          bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
                                                tex_height,
                                                LLVMConstInt(i32t, 1, 0), "");
          if (dims >= 3) {
             LLVMValueRef tex_depth =
                dynamic_state->depth(dynamic_state, gallivm, context_ptr,
-                                    texture_index);
+                                    texture_index, NULL);
             bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
                                                   tex_depth,
                                                   LLVMConstInt(i32t, 2, 0), "");
@@ -3906,7 +3906,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
    if (params->samples_only) {
       params->sizes_out[0] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, params->int_type),
                                                 dynamic_state->num_samples(dynamic_state, gallivm,
-                                                                           context_ptr, texture_unit));
+                                                                           context_ptr, texture_unit, NULL));
       return;
    }
    if (params->explicit_lod) {
@@ -3914,7 +3914,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
       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);
+                                               context_ptr, texture_unit, NULL);
       level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level");
       lod = lp_build_broadcast_scalar(&bld_int_vec4, level);
    } else {
@@ -3925,20 +3925,20 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
 
    size = LLVMBuildInsertElement(gallivm->builder, size,
                                  dynamic_state->width(dynamic_state, gallivm,
-                                                      context_ptr, texture_unit),
+                                                      context_ptr, texture_unit, NULL),
                                  lp_build_const_int32(gallivm, 0), "");
 
    if (dims >= 2) {
       size = LLVMBuildInsertElement(gallivm->builder, size,
                                     dynamic_state->height(dynamic_state, gallivm,
-                                                          context_ptr, texture_unit),
+                                                          context_ptr, texture_unit, NULL),
                                     lp_build_const_int32(gallivm, 1), "");
    }
 
    if (dims >= 3) {
       size = LLVMBuildInsertElement(gallivm->builder, size,
                                     dynamic_state->depth(dynamic_state, gallivm,
-                                                         context_ptr, texture_unit),
+                                                         context_ptr, texture_unit, NULL),
                                     lp_build_const_int32(gallivm, 2), "");
    }
 
@@ -3946,7 +3946,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
 
    if (has_array) {
       LLVMValueRef layers = dynamic_state->depth(dynamic_state, gallivm,
-                                                 context_ptr, texture_unit);
+                                                 context_ptr, texture_unit, NULL);
       if (target == PIPE_TEXTURE_CUBE_ARRAY) {
          /*
           * It looks like GL wants number of cubes, d3d10.1 has it undefined?
@@ -3972,7 +3972,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
       /* everything is scalar for now */
       lp_build_context_init(&leveli_bld, gallivm, lp_type_int_vec(32, 32));
       last_level = dynamic_state->last_level(dynamic_state, gallivm,
-                                             context_ptr, texture_unit);
+                                             context_ptr, texture_unit, NULL);
 
       out = lp_build_cmp(&leveli_bld, PIPE_FUNC_LESS, level, first_level);
       out1 = lp_build_cmp(&leveli_bld, PIPE_FUNC_GREATER, level, last_level);
@@ -4013,7 +4013,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
          LLVMValueRef last_level;
 
          last_level = dynamic_state->last_level(dynamic_state, gallivm,
-                                                context_ptr, texture_unit);
+                                                context_ptr, texture_unit, NULL);
          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);
       }
@@ -4114,23 +4114,23 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
    LLVMValueRef offset, i, j;
 
    LLVMValueRef row_stride = dynamic_state->row_stride(dynamic_state, gallivm,
-                                                       params->context_ptr, params->image_index);
+                                                       params->context_ptr, params->image_index, NULL);
    LLVMValueRef img_stride = dynamic_state->img_stride(dynamic_state, gallivm,
-                                                       params->context_ptr, params->image_index);
+                                                       params->context_ptr, params->image_index, NULL);
    LLVMValueRef base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm,
-                                                   params->context_ptr, params->image_index);
+                                                   params->context_ptr, params->image_index, NULL);
    LLVMValueRef width = dynamic_state->width(dynamic_state, gallivm,
-                                                params->context_ptr, params->image_index);
+                                                params->context_ptr, params->image_index, NULL);
    LLVMValueRef height = dynamic_state->height(dynamic_state, gallivm,
-                                               params->context_ptr, params->image_index);
+                                               params->context_ptr, params->image_index, NULL);
    LLVMValueRef depth = dynamic_state->depth(dynamic_state, gallivm,
-                                              params->context_ptr, params->image_index);
+                                              params->context_ptr, params->image_index, NULL);
    LLVMValueRef num_samples = NULL, sample_stride = NULL;
    if (ms_index) {
       num_samples = dynamic_state->num_samples(dynamic_state, gallivm,
-                                               params->context_ptr, params->image_index);
+                                               params->context_ptr, params->image_index, NULL);
       sample_stride = dynamic_state->sample_stride(dynamic_state, gallivm,
-                                                   params->context_ptr, params->image_index);
+                                                   params->context_ptr, params->image_index, NULL);
    }
 
    boolean layer_coord = has_layer_coord(target);
index 0b1d7198e8f33b10c24f6cd94b640242d492acbe..a8d18d772d92552bbb6520812ffb35d200ffed9f 100644 (file)
@@ -110,6 +110,7 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
                        struct gallivm_state *gallivm,
                        LLVMValueRef context_ptr,
                        unsigned texture_unit,
+                       LLVMValueRef texture_unit_offset,
                        unsigned member_index,
                        const char *member_name,
                        boolean emit_load)
@@ -157,10 +158,12 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    lp_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
                             struct gallivm_state *gallivm, \
                             LLVMValueRef context_ptr, \
-                            unsigned texture_unit) \
+                            unsigned texture_unit,    \
+                            LLVMValueRef texture_unit_offset) \
    { \
       return lp_llvm_texture_member(base, gallivm, context_ptr, \
-                                    texture_unit, _index, #_name, _emit_load ); \
+                                    texture_unit, texture_unit_offset,  \
+                                    _index, #_name, _emit_load );       \
    }
 
 
@@ -254,6 +257,7 @@ lp_llvm_image_member(const struct lp_sampler_dynamic_state *base,
                      struct gallivm_state *gallivm,
                      LLVMValueRef context_ptr,
                      unsigned image_unit,
+                     LLVMValueRef image_unit_offset,
                      unsigned member_index,
                      const char *member_name,
                      boolean emit_load)
@@ -299,12 +303,13 @@ lp_llvm_image_member(const struct lp_sampler_dynamic_state *base,
 #define LP_LLVM_IMAGE_MEMBER(_name, _index, _emit_load)  \
    static LLVMValueRef \
    lp_llvm_image_##_name( const struct lp_sampler_dynamic_state *base, \
-                            struct gallivm_state *gallivm, \
-                            LLVMValueRef context_ptr, \
-                            unsigned image_unit) \
+                          struct gallivm_state *gallivm,               \
+                          LLVMValueRef context_ptr,                     \
+                          unsigned image_unit, LLVMValueRef image_unit_offset) \
    { \
       return lp_llvm_image_member(base, gallivm, context_ptr, \
-                                    image_unit, _index, #_name, _emit_load ); \
+                                  image_unit, image_unit_offset, \
+                                  _index, #_name, _emit_load );  \
    }
 
 
index 40731aceb970b4227b540b03dc671db921fa34a3..1cf00b2924972e6375f1c8183464216dba0bd2b2 100644 (file)
@@ -169,7 +169,8 @@ swr_texture_member(const struct lp_sampler_dynamic_state *base,
       const struct lp_sampler_dynamic_state *base,                           \
       struct gallivm_state *gallivm,                                         \
       LLVMValueRef context_ptr,                                              \
-      unsigned texture_unit)                                                 \
+      unsigned texture_unit,                                                 \
+      LLVMValueRef texture_unit_offset)                                      \
    {                                                                         \
       return swr_texture_member(base,                                        \
                                 gallivm,                                     \