~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/gallivm/lp_bld_sample.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "lp_bld_const.h"
41
41
#include "lp_bld_arit.h"
42
42
#include "lp_bld_type.h"
43
 
#include "lp_bld_format.h"
44
43
#include "lp_bld_sample.h"
45
44
 
46
45
 
51
50
 */
52
51
void
53
52
lp_sampler_static_state(struct lp_sampler_static_state *state,
54
 
                        const struct pipe_texture *texture,
 
53
                        const struct pipe_sampler_view *view,
55
54
                        const struct pipe_sampler_state *sampler)
56
55
{
 
56
   const struct pipe_resource *texture = view->texture;
 
57
 
57
58
   memset(state, 0, sizeof *state);
58
59
 
59
60
   if(!texture)
62
63
   if(!sampler)
63
64
      return;
64
65
 
65
 
   state->format            = texture->format;
 
66
   /*
 
67
    * We don't copy sampler state over unless it is actually enabled, to avoid
 
68
    * spurious recompiles, as the sampler static state is part of the shader
 
69
    * key.
 
70
    *
 
71
    * Ideally the state tracker or cso_cache module would make all state
 
72
    * canonical, but until that happens it's better to be safe than sorry here.
 
73
    *
 
74
    * XXX: Actually there's much more than can be done here, especially
 
75
    * regarding 1D/2D/3D/CUBE textures, wrap modes, etc.
 
76
    */
 
77
 
 
78
   state->format            = view->format;
 
79
   state->swizzle_r         = view->swizzle_r;
 
80
   state->swizzle_g         = view->swizzle_g;
 
81
   state->swizzle_b         = view->swizzle_b;
 
82
   state->swizzle_a         = view->swizzle_a;
 
83
 
66
84
   state->target            = texture->target;
67
 
   state->pot_width         = util_is_pot(texture->width0);
68
 
   state->pot_height        = util_is_pot(texture->height0);
69
 
   state->pot_depth         = util_is_pot(texture->depth0);
 
85
   state->pot_width         = util_is_power_of_two(texture->width0);
 
86
   state->pot_height        = util_is_power_of_two(texture->height0);
 
87
   state->pot_depth         = util_is_power_of_two(texture->depth0);
70
88
 
71
89
   state->wrap_s            = sampler->wrap_s;
72
90
   state->wrap_t            = sampler->wrap_t;
73
91
   state->wrap_r            = sampler->wrap_r;
74
92
   state->min_img_filter    = sampler->min_img_filter;
75
 
   state->min_mip_filter    = sampler->min_mip_filter;
76
93
   state->mag_img_filter    = sampler->mag_img_filter;
 
94
   if (view->last_level) {
 
95
      state->min_mip_filter = sampler->min_mip_filter;
 
96
   } else {
 
97
      state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
 
98
   }
 
99
 
77
100
   state->compare_mode      = sampler->compare_mode;
78
 
   state->compare_func      = sampler->compare_func;
 
101
   if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) {
 
102
      state->compare_func   = sampler->compare_func;
 
103
   }
 
104
 
79
105
   state->normalized_coords = sampler->normalized_coords;
80
106
   state->lod_bias          = sampler->lod_bias;
81
 
   state->min_lod           = sampler->min_lod;
82
 
   state->max_lod           = sampler->max_lod;
 
107
   if (!view->last_level &&
 
108
       sampler->min_img_filter == sampler->mag_img_filter) {
 
109
      state->min_lod        = 0.0f;
 
110
      state->max_lod        = 0.0f;
 
111
   } else {
 
112
      state->min_lod        = MAX2(sampler->min_lod, 0.0f);
 
113
      state->max_lod        = sampler->max_lod;
 
114
   }
83
115
   state->border_color[0]   = sampler->border_color[0];
84
116
   state->border_color[1]   = sampler->border_color[1];
85
117
   state->border_color[2]   = sampler->border_color[2];
86
118
   state->border_color[3]   = sampler->border_color[3];
 
119
 
 
120
   /*
 
121
    * FIXME: Handle the remainder of pipe_sampler_view.
 
122
    */
87
123
}
88
124
 
89
125
 
90
126
/**
91
 
 * Gather elements from scatter positions in memory into a single vector.
 
127
 * Compute the partial offset of a pixel block along an arbitrary axis.
92
128
 *
93
 
 * @param src_width src element width
94
 
 * @param dst_width result element width (source will be expanded to fit)
95
 
 * @param length length of the offsets,
96
 
 * @param base_ptr base pointer, should be a i8 pointer type.
97
 
 * @param offsets vector with offsets
 
129
 * @param coord   coordinate in pixels
 
130
 * @param stride  number of bytes between rows of successive pixel blocks
 
131
 * @param block_length  number of pixels in a pixels block along the coordinate
 
132
 *                      axis
 
133
 * @param out_offset    resulting relative offset of the pixel block in bytes
 
134
 * @param out_subcoord  resulting sub-block pixel coordinate
98
135
 */
99
 
LLVMValueRef
100
 
lp_build_gather(LLVMBuilderRef builder,
101
 
                unsigned length,
102
 
                unsigned src_width,
103
 
                unsigned dst_width,
104
 
                LLVMValueRef base_ptr,
105
 
                LLVMValueRef offsets)
 
136
void
 
137
lp_build_sample_partial_offset(struct lp_build_context *bld,
 
138
                               unsigned block_length,
 
139
                               LLVMValueRef coord,
 
140
                               LLVMValueRef stride,
 
141
                               LLVMValueRef *out_offset,
 
142
                               LLVMValueRef *out_subcoord)
106
143
{
107
 
   LLVMTypeRef src_type = LLVMIntType(src_width);
108
 
   LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0);
109
 
   LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
110
 
   LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length);
111
 
   LLVMValueRef res;
112
 
   unsigned i;
113
 
 
114
 
   res = LLVMGetUndef(dst_vec_type);
115
 
   for(i = 0; i < length; ++i) {
116
 
      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
117
 
      LLVMValueRef elem_offset;
118
 
      LLVMValueRef elem_ptr;
119
 
      LLVMValueRef elem;
120
 
 
121
 
      elem_offset = LLVMBuildExtractElement(builder, offsets, index, "");
122
 
      elem_ptr = LLVMBuildGEP(builder, base_ptr, &elem_offset, 1, "");
123
 
      elem_ptr = LLVMBuildBitCast(builder, elem_ptr, src_ptr_type, "");
124
 
      elem = LLVMBuildLoad(builder, elem_ptr, "");
125
 
 
126
 
      assert(src_width <= dst_width);
127
 
      if(src_width > dst_width)
128
 
         elem = LLVMBuildTrunc(builder, elem, dst_elem_type, "");
129
 
      if(src_width < dst_width)
130
 
         elem = LLVMBuildZExt(builder, elem, dst_elem_type, "");
131
 
 
132
 
      res = LLVMBuildInsertElement(builder, res, elem, index, "");
133
 
   }
134
 
 
135
 
   return res;
 
144
   LLVMValueRef offset;
 
145
   LLVMValueRef subcoord;
 
146
 
 
147
   if (block_length == 1) {
 
148
      subcoord = bld->zero;
 
149
   }
 
150
   else {
 
151
      /*
 
152
       * Pixel blocks have power of two dimensions. LLVM should convert the
 
153
       * rem/div to bit arithmetic.
 
154
       * TODO: Verify this.
 
155
       */
 
156
 
 
157
      LLVMValueRef block_width = lp_build_const_int_vec(bld->type, block_length);
 
158
      subcoord = LLVMBuildURem(bld->builder, coord, block_width, "");
 
159
      coord    = LLVMBuildUDiv(bld->builder, coord, block_width, "");
 
160
   }
 
161
 
 
162
   offset = lp_build_mul(bld, coord, stride);
 
163
 
 
164
   assert(out_offset);
 
165
   assert(out_subcoord);
 
166
 
 
167
   *out_offset = offset;
 
168
   *out_subcoord = subcoord;
136
169
}
137
170
 
138
171
 
139
172
/**
140
 
 * Compute the offset of a pixel.
141
 
 *
142
 
 * x, y, y_stride are vectors
 
173
 * Compute the offset of a pixel block.
 
174
 *
 
175
 * x, y, z, y_stride, z_stride are vectors, and they refer to pixels.
 
176
 *
 
177
 * Returns the relative offset and i,j sub-block coordinates
143
178
 */
144
 
LLVMValueRef
 
179
void
145
180
lp_build_sample_offset(struct lp_build_context *bld,
146
181
                       const struct util_format_description *format_desc,
147
182
                       LLVMValueRef x,
148
183
                       LLVMValueRef y,
 
184
                       LLVMValueRef z,
149
185
                       LLVMValueRef y_stride,
150
 
                       LLVMValueRef data_ptr)
 
186
                       LLVMValueRef z_stride,
 
187
                       LLVMValueRef *out_offset,
 
188
                       LLVMValueRef *out_i,
 
189
                       LLVMValueRef *out_j)
151
190
{
152
191
   LLVMValueRef x_stride;
153
192
   LLVMValueRef offset;
154
193
 
155
 
   x_stride = lp_build_const_scalar(bld->type, format_desc->block.bits/8);
156
 
 
157
 
   if(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
158
 
      LLVMValueRef x_lo, x_hi;
159
 
      LLVMValueRef y_lo, y_hi;
160
 
      LLVMValueRef x_stride_lo, x_stride_hi;
161
 
      LLVMValueRef y_stride_lo, y_stride_hi;
162
 
      LLVMValueRef x_offset_lo, x_offset_hi;
163
 
      LLVMValueRef y_offset_lo, y_offset_hi;
164
 
      LLVMValueRef offset_lo, offset_hi;
165
 
 
166
 
      x_lo = LLVMBuildAnd(bld->builder, x, bld->one, "");
167
 
      y_lo = LLVMBuildAnd(bld->builder, y, bld->one, "");
168
 
 
169
 
      x_hi = LLVMBuildLShr(bld->builder, x, bld->one, "");
170
 
      y_hi = LLVMBuildLShr(bld->builder, y, bld->one, "");
171
 
 
172
 
      x_stride_lo = x_stride;
173
 
      y_stride_lo = lp_build_const_scalar(bld->type, 2*format_desc->block.bits/8);
174
 
 
175
 
      x_stride_hi = lp_build_const_scalar(bld->type, 4*format_desc->block.bits/8);
176
 
      y_stride_hi = LLVMBuildShl(bld->builder, y_stride, bld->one, "");
177
 
 
178
 
      x_offset_lo = lp_build_mul(bld, x_lo, x_stride_lo);
179
 
      y_offset_lo = lp_build_mul(bld, y_lo, y_stride_lo);
180
 
      offset_lo = lp_build_add(bld, x_offset_lo, y_offset_lo);
181
 
 
182
 
      x_offset_hi = lp_build_mul(bld, x_hi, x_stride_hi);
183
 
      y_offset_hi = lp_build_mul(bld, y_hi, y_stride_hi);
184
 
      offset_hi = lp_build_add(bld, x_offset_hi, y_offset_hi);
185
 
 
186
 
      offset = lp_build_add(bld, offset_hi, offset_lo);
187
 
   }
188
 
   else {
189
 
      LLVMValueRef x_offset;
 
194
   x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8);
 
195
 
 
196
   lp_build_sample_partial_offset(bld,
 
197
                                  format_desc->block.width,
 
198
                                  x, x_stride,
 
199
                                  &offset, out_i);
 
200
 
 
201
   if (y && y_stride) {
190
202
      LLVMValueRef y_offset;
191
 
 
192
 
      x_offset = lp_build_mul(bld, x, x_stride);
193
 
      y_offset = lp_build_mul(bld, y, y_stride);
194
 
 
195
 
      offset = lp_build_add(bld, x_offset, y_offset);
196
 
   }
197
 
 
198
 
   return offset;
 
203
      lp_build_sample_partial_offset(bld,
 
204
                                     format_desc->block.height,
 
205
                                     y, y_stride,
 
206
                                     &y_offset, out_j);
 
207
      offset = lp_build_add(bld, offset, y_offset);
 
208
   }
 
209
   else {
 
210
      *out_j = bld->zero;
 
211
   }
 
212
 
 
213
   if (z && z_stride) {
 
214
      LLVMValueRef z_offset;
 
215
      LLVMValueRef k;
 
216
      lp_build_sample_partial_offset(bld,
 
217
                                     1, /* pixel blocks are always 2D */
 
218
                                     z, z_stride,
 
219
                                     &z_offset, &k);
 
220
      offset = lp_build_add(bld, offset, z_offset);
 
221
   }
 
222
 
 
223
   *out_offset = offset;
199
224
}