52
52
#include "glsl_types.h"
53
53
#include "main/macros.h"
56
* Generate a comparison value for a block of indices
58
* Lowering passes for non-constant indexing of arrays, matrices, or vectors
59
* can use this to generate blocks of index comparison values.
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.
69
* An \c ir_rvalue that \b must be cloned for each use in conditional
73
compare_index_block(exec_list *instructions, ir_variable *index,
74
unsigned base, unsigned components, void *mem_ctx)
76
ir_rvalue *broadcast_index = new(mem_ctx) ir_dereference_variable(index);
78
assert(index->type->is_scalar());
79
assert(index->type->base_type == GLSL_TYPE_INT);
80
assert(components >= 1 && components <= 4);
83
const ir_swizzle_mask m = { 0, 0, 0, 0, components, false };
84
broadcast_index = new(mem_ctx) ir_swizzle(broadcast_index, m);
87
/* Compare the desired index value with the next block of four indices.
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;
96
ir_constant *const test_indices =
97
new(mem_ctx) ir_constant(broadcast_index->type,
100
ir_rvalue *const condition_val =
101
new(mem_ctx) ir_expression(ir_binop_equal,
102
&glsl_type::bool_type[components - 1],
106
ir_variable *const condition =
107
new(mem_ctx) ir_variable(condition_val->type,
108
"dereference_condition",
110
instructions->push_tail(condition);
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));
55
119
static inline bool
56
120
is_array_or_matrix(const ir_instruction *ir)
204
268
for (unsigned i = first; i < end; i += 4) {
205
269
const unsigned comps = MIN2(condition_components, end - i);
207
ir_rvalue *broadcast_index =
208
new(this->mem_ctx) ir_dereference_variable(index);
211
const ir_swizzle_mask m = { 0, 0, 0, 0, comps, false };
212
broadcast_index = new(this->mem_ctx) ir_swizzle(broadcast_index, m);
215
/* Compare the desired index value with the next block of four indices.
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,
227
ir_rvalue *const condition_val =
228
new(this->mem_ctx) ir_expression(ir_binop_equal,
229
&glsl_type::bool_type[comps - 1],
233
ir_variable *const condition =
234
new(this->mem_ctx) ir_variable(condition_val->type,
235
"dereference_array_condition",
237
list->push_tail(condition);
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,
272
compare_index_block(list, index, i, comps, this->mem_ctx);
244
274
if (comps == 1) {
245
ir_rvalue *const cond_deref =
246
new(this->mem_ctx) ir_dereference_variable(condition);
248
this->generator.generate(i, cond_deref, list);
275
this->generator.generate(i, cond_deref->clone(this->mem_ctx, NULL),
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),
256
283
this->generator.generate(i + j, cond_swiz, list);