gallivm,draw,llvmpipe: use base ptr + mip offsets instead of mip pointers
authorRoland Scheidegger <sroland@vmware.com>
Mon, 12 Nov 2012 19:35:04 +0000 (20:35 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Mon, 12 Nov 2012 20:02:59 +0000 (21:02 +0100)
This might have a slight overhead but handling mip offsets more like
the width (and image) strides should make some things easier (mip level
being just part of the offset calculation) later.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
14 files changed:
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
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/drivers/i915/i915_state.c
src/gallium/drivers/llvmpipe/lp_jit.c
src/gallium/drivers/llvmpipe/lp_jit.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_state_sampler.c
src/gallium/drivers/llvmpipe/lp_tex_sample.c

index 91dd2e1a20aef0a606c172e617ed9fcaec7af942..6980631b365c9b60a5e6dd212739cf537c90d697 100644 (file)
@@ -802,17 +802,19 @@ draw_set_mapped_texture(struct draw_context *draw,
                         unsigned sampler_idx,
                         uint32_t width, uint32_t height, uint32_t depth,
                         uint32_t first_level, uint32_t last_level,
+                        const void *base_ptr,
                         uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
                         uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
-                        const void *data[PIPE_MAX_TEXTURE_LEVELS])
+                        uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
 {
    if (shader_stage == PIPE_SHADER_VERTEX) {
 #ifdef HAVE_LLVM
       if (draw->llvm)
          draw_llvm_set_mapped_texture(draw,
                                       sampler_idx,
-                                      width, height, depth, first_level, last_level,
-                                      row_stride, img_stride, data);
+                                      width, height, depth, first_level,
+                                      last_level, base_ptr,
+                                      row_stride, img_stride, mip_offsets);
 #endif
    }
 }
index 30633233fb0f13cf91c2534f5c79fc994753da56..a4937b6165f4194165411405bfa912689c6e3234 100644 (file)
@@ -154,9 +154,10 @@ draw_set_mapped_texture(struct draw_context *draw,
                         unsigned sampler_idx,
                         uint32_t width, uint32_t height, uint32_t depth,
                         uint32_t first_level, uint32_t last_level,
+                        const void *base,
                         uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
                         uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
-                        const void *data[PIPE_MAX_TEXTURE_LEVELS]);
+                        uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
 
 
 /*
index ebfe437261cdce4c5db7da0159260aa1e066e54d..6f0e1de7481ace7a22d74c890cea0ac2d8b90417 100644 (file)
@@ -79,12 +79,12 @@ create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
    elem_types[DRAW_JIT_TEXTURE_DEPTH] =
    elem_types[DRAW_JIT_TEXTURE_FIRST_LEVEL] =
    elem_types[DRAW_JIT_TEXTURE_LAST_LEVEL] = int32_type;
+   elem_types[DRAW_JIT_TEXTURE_BASE] =
+      LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0);
    elem_types[DRAW_JIT_TEXTURE_ROW_STRIDE] =
    elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] =
+   elem_types[DRAW_JIT_TEXTURE_MIP_OFFSETS] =
       LLVMArrayType(int32_type, PIPE_MAX_TEXTURE_LEVELS);
-   elem_types[DRAW_JIT_TEXTURE_DATA] =
-      LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0),
-                    PIPE_MAX_TEXTURE_LEVELS);
    elem_types[DRAW_JIT_TEXTURE_MIN_LOD] =
    elem_types[DRAW_JIT_TEXTURE_MAX_LOD] =
    elem_types[DRAW_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(gallivm->context);
@@ -118,15 +118,18 @@ create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, last_level,
                           target, texture_type,
                           DRAW_JIT_TEXTURE_LAST_LEVEL);
+   LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, base,
+                          target, texture_type,
+                          DRAW_JIT_TEXTURE_BASE);
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, row_stride,
                           target, texture_type,
                           DRAW_JIT_TEXTURE_ROW_STRIDE);
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, img_stride,
                           target, texture_type,
                           DRAW_JIT_TEXTURE_IMG_STRIDE);
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, data,
+   LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, mip_offsets,
                           target, texture_type,
-                          DRAW_JIT_TEXTURE_DATA);
+                          DRAW_JIT_TEXTURE_MIP_OFFSETS);
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, min_lod,
                           target, texture_type,
                           DRAW_JIT_TEXTURE_MIN_LOD);
@@ -1364,9 +1367,10 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
                              unsigned sampler_idx,
                              uint32_t width, uint32_t height, uint32_t depth,
                              uint32_t first_level, uint32_t last_level,
+                             const void *base_ptr,
                              uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
                              uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
-                             const void *data[PIPE_MAX_TEXTURE_LEVELS])
+                             uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
 {
    unsigned j;
    struct draw_jit_texture *jit_tex;
@@ -1380,9 +1384,10 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
    jit_tex->depth = depth;
    jit_tex->first_level = first_level;
    jit_tex->last_level = last_level;
+   jit_tex->base = base_ptr;
 
    for (j = first_level; j <= last_level; j++) {
-      jit_tex->data[j] = data[j];
+      jit_tex->mip_offsets[j] = mip_offsets[j];
       jit_tex->row_stride[j] = row_stride[j];
       jit_tex->img_stride[j] = img_stride[j];
    }
index 9a291a4762766b94723ebc31052e64084a4b9049..d7a630eb015e44d62cd44ec90dc501efeb4eebbe 100644 (file)
@@ -47,9 +47,10 @@ struct draw_jit_texture
    uint32_t depth;
    uint32_t first_level;
    uint32_t last_level;
+   const void *base;
    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
-   const void *data[PIPE_MAX_TEXTURE_LEVELS];
+   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
    float min_lod;
    float max_lod;
    float lod_bias;
@@ -62,9 +63,10 @@ enum {
    DRAW_JIT_TEXTURE_DEPTH,
    DRAW_JIT_TEXTURE_FIRST_LEVEL,
    DRAW_JIT_TEXTURE_LAST_LEVEL,
+   DRAW_JIT_TEXTURE_BASE,
    DRAW_JIT_TEXTURE_ROW_STRIDE,
    DRAW_JIT_TEXTURE_IMG_STRIDE,
-   DRAW_JIT_TEXTURE_DATA,
+   DRAW_JIT_TEXTURE_MIP_OFFSETS,
    DRAW_JIT_TEXTURE_MIN_LOD,
    DRAW_JIT_TEXTURE_MAX_LOD,
    DRAW_JIT_TEXTURE_LOD_BIAS,
@@ -293,8 +295,9 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
                              unsigned sampler_idx,
                              uint32_t width, uint32_t height, uint32_t depth,
                              uint32_t first_level, uint32_t last_level,
+                             const void *base_ptr,
                              uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
                              uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
-                             const void *data[PIPE_MAX_TEXTURE_LEVELS]);
+                             uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
 
 #endif
index 53317165557322b0fdff9115c2212709d28714ca..0892d16bd6dcb85aea64d6f53d335a778e52472a 100644 (file)
@@ -146,9 +146,10 @@ DRAW_LLVM_TEXTURE_MEMBER(height,     DRAW_JIT_TEXTURE_HEIGHT, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(depth,      DRAW_JIT_TEXTURE_DEPTH, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE)
+DRAW_LLVM_TEXTURE_MEMBER(base_ptr,   DRAW_JIT_TEXTURE_BASE, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE)
 DRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE)
-DRAW_LLVM_TEXTURE_MEMBER(data_ptr,   DRAW_JIT_TEXTURE_DATA, FALSE)
+DRAW_LLVM_TEXTURE_MEMBER(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE)
 DRAW_LLVM_TEXTURE_MEMBER(min_lod,    DRAW_JIT_TEXTURE_MIN_LOD, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(max_lod,    DRAW_JIT_TEXTURE_MAX_LOD, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(lod_bias,   DRAW_JIT_TEXTURE_LOD_BIAS, TRUE)
@@ -238,7 +239,8 @@ draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
    sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level;
    sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride;
    sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride;
-   sampler->dynamic_state.base.data_ptr = draw_llvm_texture_data_ptr;
+   sampler->dynamic_state.base.base_ptr = draw_llvm_texture_base_ptr;
+   sampler->dynamic_state.base.mip_offsets = draw_llvm_texture_mip_offsets;
    sampler->dynamic_state.base.min_lod = draw_llvm_texture_min_lod;
    sampler->dynamic_state.base.max_lod = draw_llvm_texture_max_lod;
    sampler->dynamic_state.base.lod_bias = draw_llvm_texture_lod_bias;
index 63cf610ecadff5c49599f1abb7fbad8a0469420a..0727fd2b91af532d53daf78069a6ce2e7e54ed5a 100644 (file)
@@ -733,12 +733,13 @@ lp_build_get_mipmap_level(struct lp_build_sample_context *bld,
                           LLVMValueRef level)
 {
    LLVMBuilderRef builder = bld->gallivm->builder;
-   LLVMValueRef indexes[2], data_ptr;
+   LLVMValueRef indexes[2], data_ptr, mip_offset;
 
    indexes[0] = lp_build_const_int32(bld->gallivm, 0);
    indexes[1] = level;
-   data_ptr = LLVMBuildGEP(builder, bld->data_array, indexes, 2, "");
-   data_ptr = LLVMBuildLoad(builder, data_ptr, "");
+   mip_offset = LLVMBuildGEP(builder, bld->mip_offsets, indexes, 2, "");
+   mip_offset = LLVMBuildLoad(builder, mip_offset, "");
+   data_ptr = LLVMBuildGEP(builder, bld->base_ptr, &mip_offset, 1, "");
    return data_ptr;
 }
 
index 0f3d8ae6cb58ac6f6814822ef109ae3a62b87338..d8a068d5497a3f418549bae708016956b2df8fa6 100644 (file)
@@ -157,12 +157,18 @@ struct lp_sampler_dynamic_state
                   struct gallivm_state *gallivm,
                   unsigned unit);
 
-   /** Obtain pointer to array of pointers to mimpap levels */
+   /** Obtain pointer to base of texture */
    LLVMValueRef
-   (*data_ptr)( const struct lp_sampler_dynamic_state *state,
+   (*base_ptr)( const struct lp_sampler_dynamic_state *state,
                 struct gallivm_state *gallivm,
                 unsigned unit);
 
+   /** Obtain pointer to array of mipmap offsets */
+   LLVMValueRef
+   (*mip_offsets)( const struct lp_sampler_dynamic_state *state,
+                   struct gallivm_state *gallivm,
+                   unsigned unit);
+
    /** Obtain texture min lod (returns float) */
    LLVMValueRef
    (*min_lod)(const struct lp_sampler_dynamic_state *state,
@@ -246,7 +252,8 @@ struct lp_build_sample_context
    /* Common dynamic state values */
    LLVMValueRef row_stride_array;
    LLVMValueRef img_stride_array;
-   LLVMValueRef data_array;
+   LLVMValueRef base_ptr;
+   LLVMValueRef mip_offsets;
 
    /** Integer vector with texture width, height, depth */
    LLVMValueRef int_size;
index aaef797063577a190cdfa82d9d3ad16228c5f862..00a5b187bcb09849fe6bb8fe21886896c870f4c2 100644 (file)
@@ -1298,8 +1298,9 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
    tex_depth = dynamic_state->depth(dynamic_state, gallivm, unit);
    bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit);
    bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit);
-   bld.data_array = dynamic_state->data_ptr(dynamic_state, gallivm, unit);
-   /* Note that data_array is an array[level] of pointers to texture images */
+   bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm, unit);
+   bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm, unit);
+   /* Note that mip_offsets is an array[level] of offsets to texture images */
 
    s = coords[0];
    t = coords[1];
@@ -1439,7 +1440,8 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
             bld4.dims = bld.dims;
             bld4.row_stride_array = bld.row_stride_array;
             bld4.img_stride_array = bld.img_stride_array;
-            bld4.data_array = bld.data_array;
+            bld4.base_ptr = bld.base_ptr;
+            bld4.mip_offsets = bld.mip_offsets;
             bld4.int_size = bld.int_size;
 
             bld4.vector_width = lp_type_width(type4);
index 7fa648fc4d92e051216958d23fb54f5e1c9249c2..37ad1ed61c8ec4c3484e3dff2da1176a80714b84 100644 (file)
@@ -360,7 +360,7 @@ i915_prepare_vertex_sampling(struct i915_context *i915)
    unsigned i,j;
    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
-   const void* data[PIPE_MAX_TEXTURE_LEVELS];
+   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
    unsigned num = i915->num_vertex_sampler_views;
    struct pipe_sampler_view **views = i915->vertex_sampler_views;
 
@@ -381,16 +381,15 @@ i915_prepare_vertex_sampling(struct i915_context *i915)
           */
          pipe_resource_reference(&i915->mapped_vs_tex[i], tex);
 
-        i915->mapped_vs_tex_buffer[i] = i915_tex->buffer;
+         i915->mapped_vs_tex_buffer[i] = i915_tex->buffer;
          addr = iws->buffer_map(iws,
                                 i915_tex->buffer,
                                 FALSE /* read only */);
 
          /* Setup array of mipmap level pointers */
-        /* FIXME: handle 3D textures? */
+         /* FIXME: handle 3D textures? */
          for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
-            unsigned offset = i915_texture_offset(i915_tex, j , 0 /* FIXME depth */);
-            data[j] = addr + offset;
+            mip_offsets[j] = i915_texture_offset(i915_tex, j , 0 /* FIXME depth */);
             row_stride[j] = i915_tex->stride;
             img_stride[j] = 0; /* FIXME */;
          }
@@ -400,7 +399,8 @@ i915_prepare_vertex_sampling(struct i915_context *i915)
                                  i,
                                  tex->width0, tex->height0, tex->depth0,
                                  view->u.tex.first_level, tex->last_level,
-                                 row_stride, img_stride, data);
+                                 addr,
+                                 row_stride, img_stride, mip_offsets);
       } else
          i915->mapped_vs_tex[i] = NULL;
    }
index 7a85eab41a041c4908322fa18ad8e6789af0f13c..20c53cbcf7f3d2407121729fc4e972a91362fa7f 100644 (file)
@@ -55,13 +55,12 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp)
       elem_types[LP_JIT_TEXTURE_HEIGHT] =
       elem_types[LP_JIT_TEXTURE_DEPTH] =
       elem_types[LP_JIT_TEXTURE_FIRST_LEVEL] =
-      elem_types[LP_JIT_TEXTURE_LAST_LEVEL] =  LLVMInt32TypeInContext(lc);
+      elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32TypeInContext(lc);
+      elem_types[LP_JIT_TEXTURE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
       elem_types[LP_JIT_TEXTURE_ROW_STRIDE] =
       elem_types[LP_JIT_TEXTURE_IMG_STRIDE] =
+      elem_types[LP_JIT_TEXTURE_MIP_OFFSETS] =
          LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TEXTURE_LEVELS);
-      elem_types[LP_JIT_TEXTURE_DATA] =
-         LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(lc), 0),
-                       LP_MAX_TEXTURE_LEVELS);
       elem_types[LP_JIT_TEXTURE_MIN_LOD] =
       elem_types[LP_JIT_TEXTURE_MAX_LOD] =
       elem_types[LP_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(lc);
@@ -91,15 +90,18 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp)
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, last_level,
                              gallivm->target, texture_type,
                              LP_JIT_TEXTURE_LAST_LEVEL);
+      LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, base,
+                             gallivm->target, texture_type,
+                             LP_JIT_TEXTURE_BASE);
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, row_stride,
                              gallivm->target, texture_type,
                              LP_JIT_TEXTURE_ROW_STRIDE);
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, img_stride,
                              gallivm->target, texture_type,
                              LP_JIT_TEXTURE_IMG_STRIDE);
-      LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, data,
+      LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, mip_offsets,
                              gallivm->target, texture_type,
-                             LP_JIT_TEXTURE_DATA);
+                             LP_JIT_TEXTURE_MIP_OFFSETS);
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, min_lod,
                              gallivm->target, texture_type,
                              LP_JIT_TEXTURE_MIN_LOD);
index 584d2c8fd816648f4d28458cb39d87c736d730c5..94a2bb5ff3651f1053253ddee02db60600826c67 100644 (file)
@@ -53,9 +53,10 @@ struct lp_jit_texture
    uint32_t depth;
    uint32_t first_level;
    uint32_t last_level;
+   const void *base;
    uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
-   const void *data[LP_MAX_TEXTURE_LEVELS];
+   uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
    /* sampler state, actually */
    float min_lod;
    float max_lod;
@@ -70,9 +71,10 @@ enum {
    LP_JIT_TEXTURE_DEPTH,
    LP_JIT_TEXTURE_FIRST_LEVEL,
    LP_JIT_TEXTURE_LAST_LEVEL,
+   LP_JIT_TEXTURE_BASE,
    LP_JIT_TEXTURE_ROW_STRIDE,
    LP_JIT_TEXTURE_IMG_STRIDE,
-   LP_JIT_TEXTURE_DATA,
+   LP_JIT_TEXTURE_MIP_OFFSETS,
    LP_JIT_TEXTURE_MIN_LOD,
    LP_JIT_TEXTURE_MAX_LOD,
    LP_JIT_TEXTURE_LOD_BIAS,
index e5c84bbacdca674aefe4b9a2a19bb3d09d1ca111..60144c34bacdb29831700a6cf51f9bded28e06f6 100644 (file)
@@ -663,24 +663,46 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
          pipe_resource_reference(&setup->fs.current_tex[i], tex);
 
          if (!lp_tex->dt) {
-            /* regular texture - setup array of mipmap level pointers */
+            /* regular texture - setup array of mipmap level offsets */
+            void *mip_ptr;
             int j;
+            /*
+             * XXX this is messed up we don't want to accidentally trigger
+             * tiled->linear conversion for levels we don't need.
+             * So ask for first_level data (which will allocate all levels)
+             * then if successful get base ptr.
+             */
+            mip_ptr = llvmpipe_get_texture_image_all(lp_tex, view->u.tex.first_level,
+                                                     LP_TEX_USAGE_READ,
+                                                     LP_TEX_LAYOUT_LINEAR);
+            if ((LP_PERF & PERF_TEX_MEM) || !mip_ptr) {
+               /* out of memory - use dummy tile memory */
+               jit_tex->base = lp_dummy_tile;
+               jit_tex->width = TILE_SIZE/8;
+               jit_tex->height = TILE_SIZE/8;
+               jit_tex->depth = 1;
+               jit_tex->first_level = 0;
+               jit_tex->last_level = 0;
+            }
+            else {
+               jit_tex->base = lp_tex->linear_img.data;
+            }
             for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
-               jit_tex->data[j] =
-                  llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ,
-                                                 LP_TEX_LAYOUT_LINEAR);
+               mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
+                                                        LP_TEX_USAGE_READ,
+                                                        LP_TEX_LAYOUT_LINEAR);
+               jit_tex->mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)jit_tex->base;
+               /*
+                * could get mip offset directly but need call above to
+                * invoke tiled->linear conversion.
+                */
+               assert(lp_tex->linear_mip_offsets[j] == jit_tex->mip_offsets[j]);
                jit_tex->row_stride[j] = lp_tex->row_stride[j];
                jit_tex->img_stride[j] = lp_tex->img_stride[j];
 
-               if ((LP_PERF & PERF_TEX_MEM) ||
-                  !jit_tex->data[j]) {
+               if (jit_tex->base == lp_dummy_tile) {
                   /* out of memory - use dummy tile memory */
-                  jit_tex->data[j] = lp_dummy_tile;
-                  jit_tex->width = TILE_SIZE/8;
-                  jit_tex->height = TILE_SIZE/8;
-                  jit_tex->depth = 1;
-                  jit_tex->first_level = 0;
-                  jit_tex->last_level = 0;
+                  jit_tex->mip_offsets[j] = 0;
                   jit_tex->row_stride[j] = 0;
                   jit_tex->img_stride[j] = 0;
                }
@@ -693,11 +715,12 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
              */
             struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
             struct sw_winsys *winsys = screen->winsys;
-            jit_tex->data[0] = winsys->displaytarget_map(winsys, lp_tex->dt,
-                                                        PIPE_TRANSFER_READ);
+            jit_tex->base = winsys->displaytarget_map(winsys, lp_tex->dt,
+                                                         PIPE_TRANSFER_READ);
             jit_tex->row_stride[0] = lp_tex->row_stride[0];
             jit_tex->img_stride[0] = lp_tex->img_stride[0];
-            assert(jit_tex->data[0]);
+            jit_tex->mip_offsets[0] = 0;
+            assert(jit_tex->base);
          }
       }
    }
index 0be900ed299f995111d9993302acca41461b4dfb..58fac3f54d45abc5aec07cb12137fd6a0d8cf585 100644 (file)
@@ -255,7 +255,8 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
    unsigned i;
    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
-   const void *data[PIPE_MAX_TEXTURE_LEVELS];
+   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
+   const void *addr;
 
    assert(num <= PIPE_MAX_SAMPLERS);
    if (!num)
@@ -275,11 +276,24 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
 
          if (!lp_tex->dt) {
             /* regular texture - setup array of mipmap level pointers */
+            /* XXX this may fail due to OOM ? */
             int j;
+            void *mip_ptr;
+            /* must trigger allocation first before we can get base ptr */
+            mip_ptr = llvmpipe_get_texture_image_all(lp_tex, view->u.tex.first_level,
+                                                     LP_TEX_USAGE_READ,
+                                                     LP_TEX_LAYOUT_LINEAR);
+            addr = lp_tex->linear_img.data;
             for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
-               data[j] =
-                  llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ,
-                                                 LP_TEX_LAYOUT_LINEAR);
+               mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
+                                                        LP_TEX_USAGE_READ,
+                                                        LP_TEX_LAYOUT_LINEAR);
+               mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)addr;
+               /*
+                * could get mip offset directly but need call above to
+                * invoke tiled->linear conversion.
+                */
+               assert(lp_tex->linear_mip_offsets[j] == mip_offsets[j]);
                row_stride[j] = lp_tex->row_stride[j];
                img_stride[j] = lp_tex->img_stride[j];
             }
@@ -291,18 +305,20 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
              */
             struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
             struct sw_winsys *winsys = screen->winsys;
-            data[0] = winsys->displaytarget_map(winsys, lp_tex->dt,
+            addr = winsys->displaytarget_map(winsys, lp_tex->dt,
                                                 PIPE_TRANSFER_READ);
             row_stride[0] = lp_tex->row_stride[0];
             img_stride[0] = lp_tex->img_stride[0];
-            assert(data[0]);
+            mip_offsets[0] = 0;
+            assert(addr);
          }
          draw_set_mapped_texture(lp->draw,
                                  PIPE_SHADER_VERTEX,
                                  i,
                                  tex->width0, tex->height0, tex->depth0,
                                  view->u.tex.first_level, tex->last_level,
-                                 row_stride, img_stride, data);
+                                 addr,
+                                 row_stride, img_stride, mip_offsets);
       }
    }
 }
index 9151e427ba7c99046714009e72f0bf0996d18ce1..1c5c009b556dc3265021495fc9db995f7e434442 100644 (file)
@@ -151,9 +151,10 @@ LP_LLVM_TEXTURE_MEMBER(height,     LP_JIT_TEXTURE_HEIGHT, TRUE)
 LP_LLVM_TEXTURE_MEMBER(depth,      LP_JIT_TEXTURE_DEPTH, TRUE)
 LP_LLVM_TEXTURE_MEMBER(first_level, LP_JIT_TEXTURE_FIRST_LEVEL, TRUE)
 LP_LLVM_TEXTURE_MEMBER(last_level, LP_JIT_TEXTURE_LAST_LEVEL, TRUE)
+LP_LLVM_TEXTURE_MEMBER(base_ptr,   LP_JIT_TEXTURE_BASE, TRUE)
 LP_LLVM_TEXTURE_MEMBER(row_stride, LP_JIT_TEXTURE_ROW_STRIDE, FALSE)
 LP_LLVM_TEXTURE_MEMBER(img_stride, LP_JIT_TEXTURE_IMG_STRIDE, FALSE)
-LP_LLVM_TEXTURE_MEMBER(data_ptr,   LP_JIT_TEXTURE_DATA, FALSE)
+LP_LLVM_TEXTURE_MEMBER(mip_offsets, LP_JIT_TEXTURE_MIP_OFFSETS, FALSE)
 LP_LLVM_TEXTURE_MEMBER(min_lod,    LP_JIT_TEXTURE_MIN_LOD, TRUE)
 LP_LLVM_TEXTURE_MEMBER(max_lod,    LP_JIT_TEXTURE_MAX_LOD, TRUE)
 LP_LLVM_TEXTURE_MEMBER(lod_bias,   LP_JIT_TEXTURE_LOD_BIAS, TRUE)
@@ -246,9 +247,10 @@ lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
    sampler->dynamic_state.base.depth = lp_llvm_texture_depth;
    sampler->dynamic_state.base.first_level = lp_llvm_texture_first_level;
    sampler->dynamic_state.base.last_level = lp_llvm_texture_last_level;
+   sampler->dynamic_state.base.base_ptr = lp_llvm_texture_base_ptr;
    sampler->dynamic_state.base.row_stride = lp_llvm_texture_row_stride;
    sampler->dynamic_state.base.img_stride = lp_llvm_texture_img_stride;
-   sampler->dynamic_state.base.data_ptr = lp_llvm_texture_data_ptr;
+   sampler->dynamic_state.base.mip_offsets = lp_llvm_texture_mip_offsets;
    sampler->dynamic_state.base.min_lod = lp_llvm_texture_min_lod;
    sampler->dynamic_state.base.max_lod = lp_llvm_texture_max_lod;
    sampler->dynamic_state.base.lod_bias = lp_llvm_texture_lod_bias;