~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/glsl/lower_variable_index_to_cond_assign.cpp

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include "glsl_types.h"
53
53
#include "main/macros.h"
54
54
 
 
55
/**
 
56
 * Generate a comparison value for a block of indices
 
57
 *
 
58
 * Lowering passes for non-constant indexing of arrays, matrices, or vectors
 
59
 * can use this to generate blocks of index comparison values.
 
60
 *
 
61
 * \param instructions  List where new instructions will be appended
 
62
 * \param index         \c ir_variable containing the desired index
 
63
 * \param base          Base value for this block of comparisons
 
64
 * \param components    Number of unique index values to compare.  This must
 
65
 *                      be on the range [1, 4].
 
66
 * \param mem_ctx       ralloc memory context to be used for all allocations.
 
67
 *
 
68
 * \returns
 
69
 * An \c ir_rvalue that \b must be cloned for each use in conditional
 
70
 * assignments, etc.
 
71
 */
 
72
ir_rvalue *
 
73
compare_index_block(exec_list *instructions, ir_variable *index,
 
74
                    unsigned base, unsigned components, void *mem_ctx)
 
75
{
 
76
   ir_rvalue *broadcast_index = new(mem_ctx) ir_dereference_variable(index);
 
77
 
 
78
   assert(index->type->is_scalar());
 
79
   assert(index->type->base_type == GLSL_TYPE_INT);
 
80
   assert(components >= 1 && components <= 4);
 
81
 
 
82
   if (components > 1) {
 
83
      const ir_swizzle_mask m = { 0, 0, 0, 0, components, false };
 
84
      broadcast_index = new(mem_ctx) ir_swizzle(broadcast_index, m);
 
85
   }
 
86
 
 
87
   /* Compare the desired index value with the next block of four indices.
 
88
    */
 
89
   ir_constant_data test_indices_data;
 
90
   memset(&test_indices_data, 0, sizeof(test_indices_data));
 
91
   test_indices_data.i[0] = base;
 
92
   test_indices_data.i[1] = base + 1;
 
93
   test_indices_data.i[2] = base + 2;
 
94
   test_indices_data.i[3] = base + 3;
 
95
 
 
96
   ir_constant *const test_indices =
 
97
      new(mem_ctx) ir_constant(broadcast_index->type,
 
98
                               &test_indices_data);
 
99
 
 
100
   ir_rvalue *const condition_val =
 
101
      new(mem_ctx) ir_expression(ir_binop_equal,
 
102
                                 &glsl_type::bool_type[components - 1],
 
103
                                 broadcast_index,
 
104
                                 test_indices);
 
105
 
 
106
   ir_variable *const condition =
 
107
      new(mem_ctx) ir_variable(condition_val->type,
 
108
                               "dereference_condition",
 
109
                               ir_var_temporary);
 
110
   instructions->push_tail(condition);
 
111
 
 
112
   ir_rvalue *const cond_deref =
 
113
      new(mem_ctx) ir_dereference_variable(condition);
 
114
   instructions->push_tail(new(mem_ctx) ir_assignment(cond_deref, condition_val, 0));
 
115
 
 
116
   return cond_deref;
 
117
}
 
118
 
55
119
static inline bool
56
120
is_array_or_matrix(const ir_instruction *ir)
57
121
{
204
268
      for (unsigned i = first; i < end; i += 4) {
205
269
         const unsigned comps = MIN2(condition_components, end - i);
206
270
 
207
 
         ir_rvalue *broadcast_index =
208
 
            new(this->mem_ctx) ir_dereference_variable(index);
209
 
 
210
 
         if (comps) {
211
 
            const ir_swizzle_mask m = { 0, 0, 0, 0, comps, false };
212
 
            broadcast_index = new(this->mem_ctx) ir_swizzle(broadcast_index, m);
213
 
         }
214
 
 
215
 
         /* Compare the desired index value with the next block of four indices.
216
 
          */
217
 
         ir_constant_data test_indices_data;
218
 
         memset(&test_indices_data, 0, sizeof(test_indices_data));
219
 
         test_indices_data.i[0] = i;
220
 
         test_indices_data.i[1] = i + 1;
221
 
         test_indices_data.i[2] = i + 2;
222
 
         test_indices_data.i[3] = i + 3;
223
 
         ir_constant *const test_indices =
224
 
            new(this->mem_ctx) ir_constant(broadcast_index->type,
225
 
                                           &test_indices_data);
226
 
 
227
 
         ir_rvalue *const condition_val =
228
 
            new(this->mem_ctx) ir_expression(ir_binop_equal,
229
 
                                             &glsl_type::bool_type[comps - 1],
230
 
                                             broadcast_index,
231
 
                                             test_indices);
232
 
 
233
 
         ir_variable *const condition =
234
 
            new(this->mem_ctx) ir_variable(condition_val->type,
235
 
                                           "dereference_array_condition",
236
 
                                           ir_var_temporary);
237
 
         list->push_tail(condition);
238
 
 
239
271
         ir_rvalue *const cond_deref =
240
 
            new(this->mem_ctx) ir_dereference_variable(condition);
241
 
         list->push_tail(new(this->mem_ctx) ir_assignment(cond_deref,
242
 
                                                          condition_val, 0));
 
272
            compare_index_block(list, index, i, comps, this->mem_ctx);
243
273
 
244
274
         if (comps == 1) {
245
 
            ir_rvalue *const cond_deref =
246
 
               new(this->mem_ctx) ir_dereference_variable(condition);
247
 
 
248
 
            this->generator.generate(i, cond_deref, list);
 
275
            this->generator.generate(i, cond_deref->clone(this->mem_ctx, NULL),
 
276
                                     list);
249
277
         } else {
250
278
            for (unsigned j = 0; j < comps; j++) {
251
 
               ir_rvalue *const cond_deref =
252
 
                  new(this->mem_ctx) ir_dereference_variable(condition);
253
279
               ir_rvalue *const cond_swiz =
254
 
                  new(this->mem_ctx) ir_swizzle(cond_deref, j, 0, 0, 0, 1);
 
280
                  new(this->mem_ctx) ir_swizzle(cond_deref->clone(this->mem_ctx, NULL),
 
281
                                                j, 0, 0, 0, 1);
255
282
 
256
283
               this->generator.generate(i + j, cond_swiz, list);
257
284
            }