nir/tex_instr: Add a nir_tex_src struct and dynamically allocate the src array

This solves a number of problems.  First is the ability to change the
number of sources that a texture instruction has.  Second, it solves the
delema that may occur if a texture instruction has more than 4 sources.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
Jason Ekstrand
2015-01-09 20:01:13 -08:00
parent dcb1acdea0
commit 4aa6162f6e
7 changed files with 51 additions and 43 deletions

View File

@@ -1662,20 +1662,20 @@ nir_visitor::visit(ir_texture *ir)
if (ir->coordinate != NULL) {
instr->coord_components = ir->coordinate->type->vector_elements;
instr->src[src_number] = evaluate_rvalue(ir->coordinate);
instr->src_type[src_number] = nir_tex_src_coord;
instr->src[src_number].src = evaluate_rvalue(ir->coordinate);
instr->src[src_number].src_type = nir_tex_src_coord;
src_number++;
}
if (ir->projector != NULL) {
instr->src[src_number] = evaluate_rvalue(ir->projector);
instr->src_type[src_number] = nir_tex_src_projector;
instr->src[src_number].src = evaluate_rvalue(ir->projector);
instr->src[src_number].src_type = nir_tex_src_projector;
src_number++;
}
if (ir->shadow_comparitor != NULL) {
instr->src[src_number] = evaluate_rvalue(ir->shadow_comparitor);
instr->src_type[src_number] = nir_tex_src_comparitor;
instr->src[src_number].src = evaluate_rvalue(ir->shadow_comparitor);
instr->src[src_number].src_type = nir_tex_src_comparitor;
src_number++;
}
@@ -1688,16 +1688,16 @@ nir_visitor::visit(ir_texture *ir)
for (unsigned i = 0; i < const_offset->type->vector_elements; i++)
instr->const_offset[i] = const_offset->value.i[i];
} else {
instr->src[src_number] = evaluate_rvalue(ir->offset);
instr->src_type[src_number] = nir_tex_src_offset;
instr->src[src_number].src = evaluate_rvalue(ir->offset);
instr->src[src_number].src_type = nir_tex_src_offset;
src_number++;
}
}
switch (ir->op) {
case ir_txb:
instr->src[src_number] = evaluate_rvalue(ir->lod_info.bias);
instr->src_type[src_number] = nir_tex_src_bias;
instr->src[src_number].src = evaluate_rvalue(ir->lod_info.bias);
instr->src[src_number].src_type = nir_tex_src_bias;
src_number++;
break;
@@ -1705,24 +1705,24 @@ nir_visitor::visit(ir_texture *ir)
case ir_txf:
case ir_txs:
if (ir->lod_info.lod != NULL) {
instr->src[src_number] = evaluate_rvalue(ir->lod_info.lod);
instr->src_type[src_number] = nir_tex_src_lod;
instr->src[src_number].src = evaluate_rvalue(ir->lod_info.lod);
instr->src[src_number].src_type = nir_tex_src_lod;
src_number++;
}
break;
case ir_txd:
instr->src[src_number] = evaluate_rvalue(ir->lod_info.grad.dPdx);
instr->src_type[src_number] = nir_tex_src_ddx;
instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdx);
instr->src[src_number].src_type = nir_tex_src_ddx;
src_number++;
instr->src[src_number] = evaluate_rvalue(ir->lod_info.grad.dPdy);
instr->src_type[src_number] = nir_tex_src_ddy;
instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdy);
instr->src[src_number].src_type = nir_tex_src_ddy;
src_number++;
break;
case ir_txf_ms:
instr->src[src_number] = evaluate_rvalue(ir->lod_info.sample_index);
instr->src_type[src_number] = nir_tex_src_ms_index;
instr->src[src_number].src = evaluate_rvalue(ir->lod_info.sample_index);
instr->src[src_number].src_type = nir_tex_src_ms_index;
src_number++;
break;

View File

@@ -447,8 +447,9 @@ nir_tex_instr_create(void *mem_ctx, unsigned num_srcs)
dest_init(&instr->dest);
instr->num_srcs = num_srcs;
for (unsigned i = 0; i < 4; i++)
src_init(&instr->src[i]);
instr->src = ralloc_array(mem_ctx, nir_tex_src, num_srcs);
for (unsigned i = 0; i < num_srcs; i++)
src_init(&instr->src[i].src);
instr->sampler_index = 0;
instr->sampler_array_size = 0;

View File

@@ -822,8 +822,13 @@ typedef enum {
nir_tex_src_ddx,
nir_tex_src_ddy,
nir_tex_src_sampler_offset, /* < dynamically uniform indirect offset */
nir_num_texinput_types
} nir_texinput_type;
nir_num_tex_src_types
} nir_tex_src_type;
typedef struct {
nir_src src;
nir_tex_src_type src_type;
} nir_tex_src;
typedef enum {
nir_texop_tex, /**< Regular texture look-up */
@@ -846,8 +851,7 @@ typedef struct {
nir_texop op;
nir_dest dest;
nir_src src[4];
nir_texinput_type src_type[4];
nir_tex_src *src;
unsigned num_srcs, coord_components;
bool is_array, is_shadow;
@@ -917,13 +921,13 @@ nir_tex_instr_dest_size(nir_tex_instr *instr)
static inline unsigned
nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
{
if (instr->src_type[src] == nir_tex_src_coord)
if (instr->src[src].src_type == nir_tex_src_coord)
return instr->coord_components;
if (instr->src_type[src] == nir_tex_src_offset ||
instr->src_type[src] == nir_tex_src_ddx ||
instr->src_type[src] == nir_tex_src_ddy) {
if (instr->src[src].src_type == nir_tex_src_offset ||
instr->src[src].src_type == nir_tex_src_ddx ||
instr->src[src].src_type == nir_tex_src_ddy) {
if (instr->is_array)
return instr->coord_components - 1;
else
@@ -934,10 +938,10 @@ nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
}
static inline int
nir_tex_instr_src_index(nir_tex_instr *instr, nir_texinput_type type)
nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)
{
for (unsigned i = 0; i < instr->num_srcs; i++)
if (instr->src_type[i] == type)
if (instr->src[i].src_type == type)
return (int) i;
return -1;

View File

@@ -94,13 +94,16 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
case nir_deref_array_type_indirect: {
assert(!has_indirect);
assert(instr->num_srcs < 4);
nir_instr_rewrite_src(&instr->instr, &instr->src[instr->num_srcs],
nir_src_copy(deref_array->indirect, mem_ctx));
instr->src_type[instr->num_srcs] = nir_tex_src_sampler_offset;
instr->src = reralloc(mem_ctx, instr->src, nir_tex_src,
instr->num_srcs + 1);
memset(&instr->src[instr->num_srcs], 0, sizeof *instr->src);
instr->src[instr->num_srcs].src_type = nir_tex_src_sampler_offset;
instr->num_srcs++;
nir_instr_rewrite_src(&instr->instr,
&instr->src[instr->num_srcs - 1].src,
nir_src_copy(deref_array->indirect, mem_ctx));
instr->sampler_array_size = glsl_get_length(deref->type);
nir_src empty;

View File

@@ -402,11 +402,11 @@ print_tex_instr(nir_tex_instr *instr, print_var_state *state, FILE *fp)
}
for (unsigned i = 0; i < instr->num_srcs; i++) {
print_src(&instr->src[i], fp);
print_src(&instr->src[i].src, fp);
fprintf(fp, " ");
switch(instr->src_type[i]) {
switch(instr->src[i].src_type) {
case nir_tex_src_coord:
fprintf(fp, "(coord)");
break;

View File

@@ -381,13 +381,13 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)
{
validate_dest(&instr->dest, state);
bool src_type_seen[nir_num_texinput_types];
for (unsigned i = 0; i < nir_num_texinput_types; i++)
bool src_type_seen[nir_num_tex_src_types];
for (unsigned i = 0; i < nir_num_tex_src_types; i++)
src_type_seen[i] = false;
for (unsigned i = 0; i < instr->num_srcs; i++) {
assert(!src_type_seen[instr->src_type[i]]);
src_type_seen[instr->src_type[i]] = true;
assert(!src_type_seen[instr->src[i].src_type]);
src_type_seen[instr->src[i].src_type] = true;
validate_src(&instr->src[i], state);
}

View File

@@ -1625,8 +1625,8 @@ fs_visitor::nir_emit_texture(nir_tex_instr *instr)
fs_reg coordinate, shadow_comparitor, lod, lod2, sample_index, mcs, offset;
for (unsigned i = 0; i < instr->num_srcs; i++) {
fs_reg src = get_nir_src(instr->src[i]);
switch (instr->src_type[i]) {
fs_reg src = get_nir_src(instr->src[i].src);
switch (instr->src[i].src_type) {
case nir_tex_src_bias:
lod = retype(src, BRW_REGISTER_TYPE_F);
break;