gallivm: pass jit_context pointer through to sampling
authorRoland Scheidegger <sroland@vmware.com>
Wed, 25 Mar 2015 02:10:10 +0000 (03:10 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Fri, 27 Mar 2015 18:25:53 +0000 (19:25 +0100)
The callbacks used for getting the dynamic texture/sampler state were using
the jit_context from the generated jit function. This works just fine, however
that way it's impossible to generate separate functions for texture sampling,
as will be done in the next commit. Hence, pass this pointer through all
interfaces so it can be passed to a separate function (technically, it would
probably be possible to extract this pointer from the current function instead,
but this feels hacky and would probably require some more hacks if we'd use
real functions instead of inlining all shader functions at some point).
There should be no difference in the generated code for now.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h
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/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_tex_sample.c
src/gallium/drivers/llvmpipe/lp_tex_sample.h

index 6e1fb407c53b26a3de049e056f18e4484e4a3cff..1e6e69938147f4753418a204bf5b00b88145d2c7 100644 (file)
@@ -620,6 +620,7 @@ generate_vs(struct draw_llvm_variant *variant,
                      system_values,
                      inputs,
                      outputs,
+                     context_ptr,
                      draw_sampler,
                      &llvm->draw->vs.vertex_shader->info,
                      NULL);
@@ -1630,9 +1631,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
    LLVMBuildStore(builder, lp_build_zero(gallivm, lp_int_type(vs_type)), clipmask_bool_ptr);
 
    /* code generated texture sampling */
-   sampler = draw_llvm_sampler_soa_create(
-      draw_llvm_variant_key_samplers(key),
-      context_ptr);
+   sampler = draw_llvm_sampler_soa_create(draw_llvm_variant_key_samplers(key));
 
    if (elts) {
       start = zero;
@@ -2163,8 +2162,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
       draw_gs_jit_context_num_constants(variant->gallivm, context_ptr);
 
    /* code generated texture sampling */
-   sampler = draw_llvm_sampler_soa_create(variant->key.samplers,
-                                          context_ptr);
+   sampler = draw_llvm_sampler_soa_create(variant->key.samplers);
 
    mask_val = generate_mask_value(variant, gs_type);
    lp_build_mask_begin(&mask, gallivm, gs_type, mask_val);
@@ -2187,6 +2185,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
                      &system_values,
                      NULL,
                      outputs,
+                     context_ptr,
                      sampler,
                      &llvm->draw->gs.geometry_shader->info,
                      (const struct lp_build_tgsi_gs_iface *)&gs_iface);
index af1960e5fe1a1ae1d07913091f30eadef97a9254..9565fc68af9a468ef2f6392202d6d94ffd939cfa 100644 (file)
@@ -526,8 +526,7 @@ void
 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
 
 struct lp_build_sampler_soa *
-draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
-                             LLVMValueRef context_ptr);
+draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state);
 
 void
 draw_llvm_set_sampler_state(struct draw_context *draw, unsigned shader_stage);
index a6341fae3cdc36daf36bedb99b758a9dd8d67369..16d075cec0aca7c2441635d62878a65f42a8f9d5 100644 (file)
@@ -59,8 +59,6 @@ struct draw_llvm_sampler_dynamic_state
    struct lp_sampler_dynamic_state base;
 
    const struct draw_sampler_static_state *static_state;
-
-   LLVMValueRef context_ptr;
 };
 
 
@@ -86,14 +84,13 @@ struct draw_llvm_sampler_soa
 static LLVMValueRef
 draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
                          struct gallivm_state *gallivm,
+                         LLVMValueRef context_ptr,
                          unsigned texture_unit,
                          unsigned member_index,
                          const char *member_name,
                          boolean emit_load)
 {
    LLVMBuilderRef builder = gallivm->builder;
-   struct draw_llvm_sampler_dynamic_state *state =
-      (struct draw_llvm_sampler_dynamic_state *)base;
    LLVMValueRef indices[4];
    LLVMValueRef ptr;
    LLVMValueRef res;
@@ -109,7 +106,7 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
-   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, Elements(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -133,14 +130,13 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
 static LLVMValueRef
 draw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
                          struct gallivm_state *gallivm,
+                         LLVMValueRef context_ptr,
                          unsigned sampler_unit,
                          unsigned member_index,
                          const char *member_name,
                          boolean emit_load)
 {
    LLVMBuilderRef builder = gallivm->builder;
-   struct draw_llvm_sampler_dynamic_state *state =
-      (struct draw_llvm_sampler_dynamic_state *)base;
    LLVMValueRef indices[4];
    LLVMValueRef ptr;
    LLVMValueRef res;
@@ -156,7 +152,7 @@ draw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
    /* context[0].samplers[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
-   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, Elements(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -182,9 +178,11 @@ draw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
    static LLVMValueRef \
    draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
                               struct gallivm_state *gallivm,               \
+                              LLVMValueRef context_ptr,                    \
                               unsigned texture_unit)                       \
    { \
-      return draw_llvm_texture_member(base, gallivm, texture_unit, _index, #_name, _emit_load ); \
+      return draw_llvm_texture_member(base, gallivm, context_ptr, \
+                                      texture_unit, _index, #_name, _emit_load ); \
    }
 
 
@@ -203,9 +201,11 @@ DRAW_LLVM_TEXTURE_MEMBER(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE)
    static LLVMValueRef \
    draw_llvm_sampler_##_name( const struct lp_sampler_dynamic_state *base, \
                               struct gallivm_state *gallivm,               \
+                              LLVMValueRef context_ptr,                    \
                               unsigned sampler_unit)                       \
    { \
-      return draw_llvm_sampler_member(base, gallivm, sampler_unit, _index, #_name, _emit_load ); \
+      return draw_llvm_sampler_member(base, gallivm, context_ptr, \
+                                      sampler_unit, _index, #_name, _emit_load ); \
    }
 
 
@@ -233,6 +233,7 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
                                        boolean is_fetch,
                                        unsigned texture_index,
                                        unsigned sampler_index,
+                                       LLVMValueRef context_ptr,
                                        const LLVMValueRef *coords,
                                        const LLVMValueRef *offsets,
                                        const struct lp_derivatives *derivs,
@@ -254,6 +255,7 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
                        is_fetch,
                        texture_index,
                        sampler_index,
+                       context_ptr,
                        coords,
                        offsets,
                        derivs,
@@ -271,6 +273,7 @@ draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                       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 */
@@ -286,6 +289,7 @@ draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                            type,
                            texture_unit,
                            target,
+                           context_ptr,
                            is_sviewinfo,
                            lod_property,
                            explicit_lod,
@@ -293,8 +297,7 @@ draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
 }
 
 struct lp_build_sampler_soa *
-draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
-                             LLVMValueRef context_ptr)
+draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state)
 {
    struct draw_llvm_sampler_soa *sampler;
 
@@ -319,7 +322,6 @@ draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_stat
    sampler->dynamic_state.base.lod_bias = draw_llvm_sampler_lod_bias;
    sampler->dynamic_state.base.border_color = draw_llvm_sampler_border_color;
    sampler->dynamic_state.static_state = static_state;
-   sampler->dynamic_state.context_ptr = context_ptr;
 
    return &sampler->base;
 }
index 7d18ee592ba2ec1155df6413c6ec2424910f7f2f..5b220450bf31318d2c10b95dc35200e348a37d0f 100644 (file)
@@ -246,8 +246,8 @@ lp_build_rho(struct lp_build_sample_context *bld,
     * the messy cube maps for now) when requested.
     */
 
-   first_level = bld->dynamic_state->first_level(bld->dynamic_state,
-                                                 bld->gallivm, texture_unit);
+   first_level = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
+                                                 bld->context_ptr, texture_unit);
    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);
@@ -714,6 +714,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
 
 {
    LLVMBuilderRef builder = bld->gallivm->builder;
+   struct lp_sampler_dynamic_state *dynamic_state = bld->dynamic_state;
    struct lp_build_context *lodf_bld = &bld->lodf_bld;
    LLVMValueRef lod;
 
@@ -744,8 +745,8 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
        * This is hit during mipmap generation.
        */
       LLVMValueRef min_lod =
-         bld->dynamic_state->min_lod(bld->dynamic_state,
-                                     bld->gallivm, sampler_unit);
+         dynamic_state->min_lod(dynamic_state, bld->gallivm,
+                                bld->context_ptr, sampler_unit);
 
       lod = lp_build_broadcast_scalar(lodf_bld, min_lod);
    }
@@ -835,8 +836,8 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
       /* add sampler lod bias */
       if (bld->static_sampler_state->lod_bias_non_zero) {
          LLVMValueRef sampler_lod_bias =
-            bld->dynamic_state->lod_bias(bld->dynamic_state,
-                                         bld->gallivm, sampler_unit);
+            dynamic_state->lod_bias(dynamic_state, bld->gallivm,
+                                    bld->context_ptr, sampler_unit);
          sampler_lod_bias = lp_build_broadcast_scalar(lodf_bld,
                                                       sampler_lod_bias);
          lod = LLVMBuildFAdd(builder, lod, sampler_lod_bias, "sampler_lod_bias");
@@ -845,16 +846,16 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
       /* clamp lod */
       if (bld->static_sampler_state->apply_max_lod) {
          LLVMValueRef max_lod =
-            bld->dynamic_state->max_lod(bld->dynamic_state,
-                                        bld->gallivm, sampler_unit);
+            dynamic_state->max_lod(dynamic_state, bld->gallivm,
+                                   bld->context_ptr, sampler_unit);
          max_lod = lp_build_broadcast_scalar(lodf_bld, max_lod);
 
          lod = lp_build_min(lodf_bld, lod, max_lod);
       }
       if (bld->static_sampler_state->apply_min_lod) {
          LLVMValueRef min_lod =
-            bld->dynamic_state->min_lod(bld->dynamic_state,
-                                        bld->gallivm, sampler_unit);
+            dynamic_state->min_lod(dynamic_state, bld->gallivm,
+                                   bld->context_ptr, sampler_unit);
          min_lod = lp_build_broadcast_scalar(lodf_bld, min_lod);
 
          lod = lp_build_max(lodf_bld, lod, min_lod);
@@ -901,12 +902,13 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
                            LLVMValueRef *out_of_bounds)
 {
    struct lp_build_context *leveli_bld = &bld->leveli_bld;
+   struct lp_sampler_dynamic_state *dynamic_state = bld->dynamic_state;
    LLVMValueRef first_level, last_level, level;
 
-   first_level = bld->dynamic_state->first_level(bld->dynamic_state,
-                                                 bld->gallivm, texture_unit);
-   last_level = bld->dynamic_state->last_level(bld->dynamic_state,
-                                               bld->gallivm, texture_unit);
+   first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
+                                            bld->context_ptr, texture_unit);
+   last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
+                                          bld->context_ptr, texture_unit);
    first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
    last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
 
@@ -956,6 +958,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
                            LLVMValueRef *level1_out)
 {
    LLVMBuilderRef builder = bld->gallivm->builder;
+   struct lp_sampler_dynamic_state *dynamic_state = bld->dynamic_state;
    struct lp_build_context *leveli_bld = &bld->leveli_bld;
    struct lp_build_context *levelf_bld = &bld->levelf_bld;
    LLVMValueRef first_level, last_level;
@@ -964,10 +967,10 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
 
    assert(bld->num_lods == bld->num_mips);
 
-   first_level = bld->dynamic_state->first_level(bld->dynamic_state,
-                                                 bld->gallivm, texture_unit);
-   last_level = bld->dynamic_state->last_level(bld->dynamic_state,
-                                               bld->gallivm, texture_unit);
+   first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
+                                            bld->context_ptr, texture_unit);
+   last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
+                                          bld->context_ptr, texture_unit);
    first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
    last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
 
index be05b136edbe564be2588eab750f506a808839bd..be41ca02ae84263ece0982732574c3fc07be5f14 100644 (file)
@@ -138,79 +138,96 @@ struct lp_sampler_dynamic_state
 
    /** Obtain the base texture width (or number of elements) (returns int32) */
    LLVMValueRef
-   (*width)( const struct lp_sampler_dynamic_state *state,
-             struct gallivm_state *gallivm,
-             unsigned texture_unit);
+   (*width)(const struct lp_sampler_dynamic_state *state,
+            struct gallivm_state *gallivm,
+            LLVMValueRef context_ptr,
+            unsigned texture_unit);
 
    /** Obtain the base texture height (returns int32) */
    LLVMValueRef
-   (*height)( const struct lp_sampler_dynamic_state *state,
-              struct gallivm_state *gallivm,
-              unsigned texture_unit);
+   (*height)(const struct lp_sampler_dynamic_state *state,
+             struct gallivm_state *gallivm,
+             LLVMValueRef context_ptr,
+             unsigned texture_unit);
 
    /** Obtain the base texture depth (or array size) (returns int32) */
    LLVMValueRef
-   (*depth)( const struct lp_sampler_dynamic_state *state,
-             struct gallivm_state *gallivm,
-             unsigned texture_unit);
+   (*depth)(const struct lp_sampler_dynamic_state *state,
+            struct gallivm_state *gallivm,
+            LLVMValueRef context_ptr,
+            unsigned texture_unit);
 
    /** Obtain the first mipmap level (base level) (returns int32) */
    LLVMValueRef
-   (*first_level)( const struct lp_sampler_dynamic_state *state,
-                   struct gallivm_state *gallivm,
-                   unsigned texture_unit);
+   (*first_level)(const struct lp_sampler_dynamic_state *state,
+                  struct gallivm_state *gallivm,
+                  LLVMValueRef context_ptr,
+                  unsigned texture_unit);
 
    /** Obtain the number of mipmap levels minus one (returns int32) */
    LLVMValueRef
-   (*last_level)( const struct lp_sampler_dynamic_state *state,
-                  struct gallivm_state *gallivm,
-                  unsigned texture_unit);
+   (*last_level)(const struct lp_sampler_dynamic_state *state,
+                 struct gallivm_state *gallivm,
+                 LLVMValueRef context_ptr,
+                 unsigned texture_unit);
 
    /** Obtain stride in bytes between image rows/blocks (returns int32) */
    LLVMValueRef
-   (*row_stride)( const struct lp_sampler_dynamic_state *state,
-                  struct gallivm_state *gallivm,
-                  unsigned texture_unit);
+   (*row_stride)(const struct lp_sampler_dynamic_state *state,
+                 struct gallivm_state *gallivm,
+                 LLVMValueRef context_ptr,
+                 unsigned texture_unit);
 
    /** Obtain stride in bytes between image slices (returns int32) */
    LLVMValueRef
-   (*img_stride)( const struct lp_sampler_dynamic_state *state,
-                  struct gallivm_state *gallivm,
-                  unsigned texture_unit);
+   (*img_stride)(const struct lp_sampler_dynamic_state *state,
+                 struct gallivm_state *gallivm,
+                 LLVMValueRef context_ptr,
+                 unsigned texture_unit);
 
    /** Obtain pointer to base of texture */
    LLVMValueRef
-   (*base_ptr)( const struct lp_sampler_dynamic_state *state,
-                struct gallivm_state *gallivm,
-                unsigned texture_unit);
+   (*base_ptr)(const struct lp_sampler_dynamic_state *state,
+               struct gallivm_state *gallivm,
+               LLVMValueRef context_ptr,
+               unsigned texture_unit);
 
    /** Obtain pointer to array of mipmap offsets */
    LLVMValueRef
-   (*mip_offsets)( const struct lp_sampler_dynamic_state *state,
-                   struct gallivm_state *gallivm,
-                   unsigned texture_unit);
+   (*mip_offsets)(const struct lp_sampler_dynamic_state *state,
+                  struct gallivm_state *gallivm,
+                  LLVMValueRef context_ptr,
+                  unsigned texture_unit);
 
    /* These are callbacks for sampler state */
 
    /** Obtain texture min lod (returns float) */
    LLVMValueRef
    (*min_lod)(const struct lp_sampler_dynamic_state *state,
-              struct gallivm_state *gallivm, unsigned sampler_unit);
+              struct gallivm_state *gallivm,
+              LLVMValueRef context_ptr,
+              unsigned sampler_unit);
 
    /** Obtain texture max lod (returns float) */
    LLVMValueRef
    (*max_lod)(const struct lp_sampler_dynamic_state *state,
-              struct gallivm_state *gallivm, unsigned sampler_unit);
+              struct gallivm_state *gallivm,
+              LLVMValueRef context_ptr,
+              unsigned sampler_unit);
 
    /** Obtain texture lod bias (returns float) */
    LLVMValueRef
    (*lod_bias)(const struct lp_sampler_dynamic_state *state,
-               struct gallivm_state *gallivm, unsigned sampler_unit);
+               struct gallivm_state *gallivm,
+               LLVMValueRef context_ptr,
+               unsigned sampler_unit);
 
    /** Obtain texture border color (returns ptr to float[4]) */
    LLVMValueRef
    (*border_color)(const struct lp_sampler_dynamic_state *state,
-                   struct gallivm_state *gallivm, unsigned sampler_unit);
+                   struct gallivm_state *gallivm,
+                   LLVMValueRef context_ptr,
+                   unsigned sampler_unit);
 };
 
 
@@ -305,6 +322,8 @@ struct lp_build_sample_context
    LLVMValueRef int_size;
 
    LLVMValueRef border_color_clamped;
+
+   LLVMValueRef context_ptr;
 };
 
 
@@ -520,6 +539,7 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
                     boolean is_fetch,
                     unsigned texture_index,
                     unsigned sampler_index,
+                    LLVMValueRef context_ptr,
                     const LLVMValueRef *coords,
                     const LLVMValueRef *offsets,
                     const struct lp_derivatives *derivs,
@@ -545,6 +565,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
                         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,
index 99309fe75bda7a5691b7f79353524daa38820422..a90278ea889fb7945bf88f382a64fe5db59008ae 100644 (file)
@@ -1678,8 +1678,8 @@ lp_build_layer_coord(struct lp_build_sample_context *bld,
    LLVMValueRef num_layers;
    struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
 
-   num_layers = bld->dynamic_state->depth(bld->dynamic_state,
-                                          bld->gallivm, texture_unit);
+   num_layers = bld->dynamic_state->depth(bld->dynamic_state, bld->gallivm,
+                                          bld->context_ptr, texture_unit);
 
    if (out_of_bounds) {
       LLVMValueRef out1, out;
@@ -1815,7 +1815,8 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
    case PIPE_TEX_MIPFILTER_NONE:
       /* always use mip level 0 */
       first_level = bld->dynamic_state->first_level(bld->dynamic_state,
-                                                    bld->gallivm, texture_index);
+                                                    bld->gallivm, bld->context_ptr,
+                                                    texture_index);
       first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level);
       *ilevel0 = first_level;
       break;
@@ -1840,8 +1841,8 @@ lp_build_clamp_border_color(struct lp_build_sample_context *bld,
    struct gallivm_state *gallivm = bld->gallivm;
    LLVMBuilderRef builder = gallivm->builder;
    LLVMValueRef border_color_ptr =
-      bld->dynamic_state->border_color(bld->dynamic_state,
-                                        gallivm, sampler_unit);
+      bld->dynamic_state->border_color(bld->dynamic_state, gallivm,
+                                       bld->context_ptr, sampler_unit);
    LLVMValueRef border_color;
    const struct util_format_description *format_desc = bld->format_desc;
    struct lp_type vec4_type = bld->texel_type;
@@ -2246,8 +2247,8 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld,
    else {
       assert(bld->num_mips == 1);
       if (bld->static_texture_state->target != PIPE_BUFFER) {
-         ilevel = bld->dynamic_state->first_level(bld->dynamic_state,
-                                                  bld->gallivm, texture_unit);
+         ilevel = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
+                                                  bld->context_ptr, texture_unit);
       }
       else {
          ilevel = lp_build_const_int32(bld->gallivm, 0);
@@ -2372,6 +2373,7 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
                     boolean is_fetch,
                     unsigned texture_index,
                     unsigned sampler_index,
+                    LLVMValueRef context_ptr,
                     const LLVMValueRef *coords,
                     const LLVMValueRef *offsets,
                     const struct lp_derivatives *derivs, /* optional */
@@ -2413,6 +2415,7 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
    /* Setup our build context */
    memset(&bld, 0, sizeof bld);
    bld.gallivm = gallivm;
+   bld.context_ptr = context_ptr;
    bld.static_sampler_state = &derived_sampler_state;
    bld.static_texture_state = static_texture_state;
    bld.dynamic_state = dynamic_state;
@@ -2578,11 +2581,16 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
    lp_build_context_init(&bld.lodi_bld, gallivm, bld.lodi_type);
 
    /* Get the dynamic state */
-   tex_width = dynamic_state->width(dynamic_state, gallivm, texture_index);
-   bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, texture_index);
-   bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, texture_index);
-   bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm, texture_index);
-   bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm, texture_index);
+   tex_width = dynamic_state->width(dynamic_state, gallivm,
+                                    context_ptr, texture_index);
+   bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm,
+                                                    context_ptr, texture_index);
+   bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm,
+                                                    context_ptr, texture_index);
+   bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm,
+                                          context_ptr, texture_index);
+   bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm,
+                                                context_ptr, texture_index);
    /* Note that mip_offsets is an array[level] of offsets to texture images */
 
    /* width, height, depth as single int vector */
@@ -2591,17 +2599,22 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
    }
    else {
       bld.int_size = LLVMBuildInsertElement(builder, bld.int_size_in_bld.undef,
-                                            tex_width, LLVMConstInt(i32t, 0, 0), "");
+                                            tex_width,
+                                            LLVMConstInt(i32t, 0, 0), "");
       if (dims >= 2) {
          LLVMValueRef tex_height =
-            dynamic_state->height(dynamic_state, gallivm, texture_index);
+            dynamic_state->height(dynamic_state, gallivm,
+                                  context_ptr, texture_index);
          bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
-                                               tex_height, LLVMConstInt(i32t, 1, 0), "");
+                                               tex_height,
+                                               LLVMConstInt(i32t, 1, 0), "");
          if (dims >= 3) {
             LLVMValueRef tex_depth =
-               dynamic_state->depth(dynamic_state, gallivm, texture_index);
+               dynamic_state->depth(dynamic_state, gallivm, context_ptr,
+                                    texture_index);
             bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
-                                                  tex_depth, LLVMConstInt(i32t, 2, 0), "");
+                                                  tex_depth,
+                                                  LLVMConstInt(i32t, 2, 0), "");
          }
       }
    }
@@ -2717,6 +2730,7 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
          /* Setup our build context */
          memset(&bld4, 0, sizeof bld4);
          bld4.gallivm = bld.gallivm;
+         bld4.context_ptr = bld.context_ptr;
          bld4.static_texture_state = bld.static_texture_state;
          bld4.static_sampler_state = bld.static_sampler_state;
          bld4.dynamic_state = bld.dynamic_state;
@@ -2876,6 +2890,7 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
    }
 }
 
+
 void
 lp_build_size_query_soa(struct gallivm_state *gallivm,
                         const struct lp_static_texture_state *static_state,
@@ -2883,6 +2898,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
                         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,
@@ -2954,8 +2970,10 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
 
    if (explicit_lod) {
       /* FIXME: this needs to honor per-element lod */
-      lod = LLVMBuildExtractElement(gallivm->builder, explicit_lod, lp_build_const_int32(gallivm, 0), "");
-      first_level = dynamic_state->first_level(dynamic_state, gallivm, texture_unit);
+      lod = LLVMBuildExtractElement(gallivm->builder, explicit_lod,
+                                    lp_build_const_int32(gallivm, 0), "");
+      first_level = dynamic_state->first_level(dynamic_state, gallivm,
+                                               context_ptr, texture_unit);
       level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level");
       lod = lp_build_broadcast_scalar(&bld_int_vec4, level);
    } else {
@@ -2965,25 +2983,29 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
    size = bld_int_vec4.undef;
 
    size = LLVMBuildInsertElement(gallivm->builder, size,
-                                 dynamic_state->width(dynamic_state, gallivm, texture_unit),
+                                 dynamic_state->width(dynamic_state, gallivm,
+                                                      context_ptr, texture_unit),
                                  lp_build_const_int32(gallivm, 0), "");
 
    if (dims >= 2) {
       size = LLVMBuildInsertElement(gallivm->builder, size,
-                                    dynamic_state->height(dynamic_state, gallivm, texture_unit),
+                                    dynamic_state->height(dynamic_state, gallivm,
+                                                          context_ptr, texture_unit),
                                     lp_build_const_int32(gallivm, 1), "");
    }
 
    if (dims >= 3) {
       size = LLVMBuildInsertElement(gallivm->builder, size,
-                                    dynamic_state->depth(dynamic_state, gallivm, texture_unit),
+                                    dynamic_state->depth(dynamic_state, gallivm,
+                                                         context_ptr, texture_unit),
                                     lp_build_const_int32(gallivm, 2), "");
    }
 
    size = lp_build_minify(&bld_int_vec4, size, lod, TRUE);
 
    if (has_array) {
-      LLVMValueRef layers = dynamic_state->depth(dynamic_state, gallivm, texture_unit);
+      LLVMValueRef layers = dynamic_state->depth(dynamic_state, gallivm,
+                                                 context_ptr, texture_unit);
       if (target == PIPE_TEXTURE_CUBE_ARRAY) {
          /*
           * It looks like GL wants number of cubes, d3d10.1 has it undefined?
@@ -3008,7 +3030,8 @@ 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, texture_unit);
+      last_level = dynamic_state->last_level(dynamic_state, gallivm,
+                                             context_ptr, texture_unit);
 
       out = lp_build_cmp(&leveli_bld, PIPE_FUNC_LESS, level, first_level);
       out1 = lp_build_cmp(&leveli_bld, PIPE_FUNC_GREATER, level, last_level);
@@ -3048,7 +3071,8 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
       else {
          LLVMValueRef last_level;
 
-         last_level = dynamic_state->last_level(dynamic_state, gallivm, texture_unit);
+         last_level = dynamic_state->last_level(dynamic_state, gallivm,
+                                                context_ptr, texture_unit);
          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);
       }
index b411f05674d2e3c2fda56d616c4f71161974c8b1..8d53607b934d500382a01ddbf8e6c186a784b8ac 100644 (file)
@@ -188,6 +188,7 @@ struct lp_build_sampler_soa
                         boolean is_fetch,
                         unsigned texture_index,
                         unsigned sampler_index,
+                        LLVMValueRef context_ptr,
                         const LLVMValueRef *coords,
                         const LLVMValueRef *offsets,
                         const struct lp_derivatives *derivs,
@@ -202,6 +203,7 @@ struct lp_build_sampler_soa
                        struct lp_type type,
                        unsigned unit,
                        unsigned target,
+                       LLVMValueRef context_ptr,
                        boolean need_nr_mips,
                        enum lp_sampler_lod_property,
                        LLVMValueRef explicit_lod, /* optional */
@@ -237,6 +239,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
                   const struct lp_bld_tgsi_system_values *system_values,
                   const LLVMValueRef (*inputs)[4],
                   LLVMValueRef (*outputs)[4],
+                  LLVMValueRef context_ptr,
                   struct lp_build_sampler_soa *sampler,
                   const struct tgsi_shader_info *info,
                   const struct lp_build_tgsi_gs_iface *gs_iface);
@@ -449,6 +452,7 @@ struct lp_build_tgsi_soa_context
    LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS];
    const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
    LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
+   LLVMValueRef context_ptr;
 
    const struct lp_build_sampler_soa *sampler;
 
index 3b2097f8521bac5cf1c88edfeb5e3c9e1d879884..3e82036150ba282ef42f0ed52ba780dbb202d01c 100644 (file)
@@ -2151,6 +2151,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
                                   bld->bld_base.base.type,
                                   FALSE,
                                   unit, unit,
+                                  bld->context_ptr,
                                   coords,
                                   offsets,
                                   deriv_ptr,
@@ -2314,6 +2315,7 @@ emit_sample(struct lp_build_tgsi_soa_context *bld,
                                   bld->bld_base.base.type,
                                   FALSE,
                                   texture_unit, sampler_unit,
+                                  bld->context_ptr,
                                   coords,
                                   offsets,
                                   deriv_ptr,
@@ -2424,6 +2426,7 @@ emit_fetch_texels( struct lp_build_tgsi_soa_context *bld,
                                   bld->bld_base.base.type,
                                   TRUE,
                                   unit, unit,
+                                  bld->context_ptr,
                                   coords,
                                   offsets,
                                   NULL,
@@ -2498,6 +2501,7 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld,
                                  bld->bld_base.base.gallivm,
                                  bld->bld_base.int_bld.type,
                                  unit, pipe_target,
+                                 bld->context_ptr,
                                  TRUE,
                                  lod_property,
                                  explicit_lod,
@@ -3656,6 +3660,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
                   const struct lp_bld_tgsi_system_values *system_values,
                   const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
                   LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
+                  LLVMValueRef context_ptr,
                   struct lp_build_sampler_soa *sampler,
                   const struct tgsi_shader_info *info,
                   const struct lp_build_tgsi_gs_iface *gs_iface)
@@ -3684,6 +3689,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
    bld.sampler = sampler;
    bld.bld_base.info = info;
    bld.indirect_files = info->indirect_files;
+   bld.context_ptr = context_ptr;
 
    /*
     * If the number of temporaries is rather large then we just
index 14fd6b91063a1ed8ea8af19ee4a787b20f6c4300..35fe7b201810b07e37b8d9bf56ec389853bf62da 100644 (file)
@@ -417,7 +417,8 @@ generate_fs_loop(struct gallivm_state *gallivm,
    lp_build_tgsi_soa(gallivm, tokens, type, &mask,
                      consts_ptr, num_consts_ptr, &system_values,
                      interp->inputs,
-                     outputs, sampler, &shader->info.base, NULL);
+                     outputs, context_ptr,
+                     sampler, &shader->info.base, NULL);
 
    /* Alpha test */
    if (key->alpha.enabled) {
@@ -2302,7 +2303,7 @@ generate_fragment(struct llvmpipe_context *lp,
    LLVMPositionBuilderAtEnd(builder, block);
 
    /* code generated texture sampling */
-   sampler = lp_llvm_sampler_soa_create(key->state, context_ptr);
+   sampler = lp_llvm_sampler_soa_create(key->state);
 
    num_fs = 16 / fs_type.length; /* number of loops per 4x4 stamp */
    /* for 1d resources only run "upper half" of stamp */
index f0a4a342bc2c1e15ca909aa2f9432de759c5a111..1828069bf1a7916cb0edbd4108b51c28f6a5205a 100644 (file)
@@ -65,8 +65,6 @@ struct llvmpipe_sampler_dynamic_state
    struct lp_sampler_dynamic_state base;
 
    const struct lp_sampler_static_state *static_state;
-
-   LLVMValueRef context_ptr;
 };
 
 
@@ -92,13 +90,12 @@ struct lp_llvm_sampler_soa
 static LLVMValueRef
 lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
                        struct gallivm_state *gallivm,
+                       LLVMValueRef context_ptr,
                        unsigned texture_unit,
                        unsigned member_index,
                        const char *member_name,
                        boolean emit_load)
 {
-   struct llvmpipe_sampler_dynamic_state *state =
-      (struct llvmpipe_sampler_dynamic_state *)base;
    LLVMBuilderRef builder = gallivm->builder;
    LLVMValueRef indices[4];
    LLVMValueRef ptr;
@@ -115,7 +112,7 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
-   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, Elements(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -141,9 +138,11 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    static LLVMValueRef \
    lp_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
                             struct gallivm_state *gallivm, \
+                            LLVMValueRef context_ptr, \
                             unsigned texture_unit) \
    { \
-      return lp_llvm_texture_member(base, gallivm, texture_unit, _index, #_name, _emit_load ); \
+      return lp_llvm_texture_member(base, gallivm, context_ptr, \
+                                    texture_unit, _index, #_name, _emit_load ); \
    }
 
 
@@ -169,13 +168,12 @@ LP_LLVM_TEXTURE_MEMBER(mip_offsets, LP_JIT_TEXTURE_MIP_OFFSETS, FALSE)
 static LLVMValueRef
 lp_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
                        struct gallivm_state *gallivm,
+                       LLVMValueRef context_ptr,
                        unsigned sampler_unit,
                        unsigned member_index,
                        const char *member_name,
                        boolean emit_load)
 {
-   struct llvmpipe_sampler_dynamic_state *state =
-      (struct llvmpipe_sampler_dynamic_state *)base;
    LLVMBuilderRef builder = gallivm->builder;
    LLVMValueRef indices[4];
    LLVMValueRef ptr;
@@ -192,7 +190,7 @@ lp_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
    /* context[0].samplers[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
-   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, Elements(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -209,9 +207,11 @@ lp_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
    static LLVMValueRef \
    lp_llvm_sampler_##_name( const struct lp_sampler_dynamic_state *base, \
                             struct gallivm_state *gallivm, \
+                            LLVMValueRef context_ptr, \
                             unsigned sampler_unit) \
    { \
-      return lp_llvm_sampler_member(base, gallivm, sampler_unit, _index, #_name, _emit_load ); \
+      return lp_llvm_sampler_member(base, gallivm, context_ptr, \
+                                    sampler_unit, _index, #_name, _emit_load ); \
    }
 
 
@@ -239,6 +239,7 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
                                      boolean is_fetch,
                                      unsigned texture_index,
                                      unsigned sampler_index,
+                                     LLVMValueRef context_ptr,
                                      const LLVMValueRef *coords,
                                      const LLVMValueRef *offsets,
                                      const struct lp_derivatives *derivs,
@@ -265,6 +266,7 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
                        is_fetch,
                        texture_index,
                        sampler_index,
+                       context_ptr,
                        coords,
                        offsets,
                        derivs,
@@ -281,6 +283,7 @@ lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                     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 */
@@ -296,6 +299,7 @@ lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                            type,
                            texture_unit,
                            target,
+                           context_ptr,
                            is_sviewinfo,
                            lod_property,
                            explicit_lod,
@@ -304,8 +308,7 @@ lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
 
 
 struct lp_build_sampler_soa *
-lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
-                           LLVMValueRef context_ptr)
+lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state)
 {
    struct lp_llvm_sampler_soa *sampler;
 
@@ -331,7 +334,6 @@ lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
    sampler->dynamic_state.base.border_color = lp_llvm_sampler_border_color;
 
    sampler->dynamic_state.static_state = static_state;
-   sampler->dynamic_state.context_ptr = context_ptr;
 
    return &sampler->base;
 }
index bca92d974c4a63eda72def8495caa521082d267d..f4aff226ce1b2f09401067bbc5d1f988f60698c9 100644 (file)
@@ -38,11 +38,9 @@ struct lp_sampler_static_state;
 /**
  * Pure-LLVM texture sampling code generator.
  *
- * @param context_ptr LLVM value with the pointer to the struct lp_jit_context.
  */
 struct lp_build_sampler_soa *
-lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *key,
-                           LLVMValueRef context_ptr);
+lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *key);
 
 
 #endif /* LP_TEX_SAMPLE_H */