<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 9, 2015 at 8:24 PM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jan 9, 2015 at 11:04 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> This solves a number of problems. First is the ability to change the<br>
> number of sources that a texture instruction has. Second, it solves the<br>
> delema that may occur if a texture instruction has more than 4 sources.<br>
> ---<br>
> src/glsl/nir/glsl_to_nir.cpp | 36 ++++++++++++++++----------------<br>
> src/glsl/nir/nir.c | 5 +++--<br>
> src/glsl/nir/nir.h | 22 +++++++++++--------<br>
> src/glsl/nir/nir_lower_samplers.cpp | 11 +++++++---<br>
> src/glsl/nir/nir_print.c | 4 ++--<br>
> src/glsl/nir/nir_validate.c | 4 ++--<br>
> src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 4 ++--<br>
> 7 files changed, 48 insertions(+), 38 deletions(-)<br>
><br>
> diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp<br>
> index a84a06f..744c404 100644<br>
> --- a/src/glsl/nir/glsl_to_nir.cpp<br>
> +++ b/src/glsl/nir/glsl_to_nir.cpp<br>
> @@ -1667,20 +1667,20 @@ nir_visitor::visit(ir_texture *ir)<br>
><br>
> if (ir->coordinate != NULL) {<br>
> instr->coord_components = ir->coordinate->type->vector_elements;<br>
> - instr->src[src_number] = evaluate_rvalue(ir->coordinate);<br>
> - instr->src_type[src_number] = nir_tex_src_coord;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->coordinate);<br>
> + instr->src[src_number].src_type = nir_tex_src_coord;<br>
> src_number++;<br>
> }<br>
><br>
> if (ir->projector != NULL) {<br>
> - instr->src[src_number] = evaluate_rvalue(ir->projector);<br>
> - instr->src_type[src_number] = nir_tex_src_projector;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->projector);<br>
> + instr->src[src_number].src_type = nir_tex_src_projector;<br>
> src_number++;<br>
> }<br>
><br>
> if (ir->shadow_comparitor != NULL) {<br>
> - instr->src[src_number] = evaluate_rvalue(ir->shadow_comparitor);<br>
> - instr->src_type[src_number] = nir_tex_src_comparitor;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->shadow_comparitor);<br>
> + instr->src[src_number].src_type = nir_tex_src_comparitor;<br>
> src_number++;<br>
> }<br>
><br>
> @@ -1693,16 +1693,16 @@ nir_visitor::visit(ir_texture *ir)<br>
> for (unsigned i = 0; i < const_offset->type->vector_elements; i++)<br>
> instr->const_offset[i] = const_offset->value.i[i];<br>
> } else {<br>
> - instr->src[src_number] = evaluate_rvalue(ir->offset);<br>
> - instr->src_type[src_number] = nir_tex_src_offset;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->offset);<br>
> + instr->src[src_number].src_type = nir_tex_src_offset;<br>
> src_number++;<br>
> }<br>
> }<br>
><br>
> switch (ir->op) {<br>
> case ir_txb:<br>
> - instr->src[src_number] = evaluate_rvalue(ir->lod_info.bias);<br>
> - instr->src_type[src_number] = nir_tex_src_bias;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->lod_info.bias);<br>
> + instr->src[src_number].src_type = nir_tex_src_bias;<br>
> src_number++;<br>
> break;<br>
><br>
> @@ -1710,24 +1710,24 @@ nir_visitor::visit(ir_texture *ir)<br>
> case ir_txf:<br>
> case ir_txs:<br>
> if (ir->lod_info.lod != NULL) {<br>
> - instr->src[src_number] = evaluate_rvalue(ir->lod_info.lod);<br>
> - instr->src_type[src_number] = nir_tex_src_lod;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->lod_info.lod);<br>
> + instr->src[src_number].src_type = nir_tex_src_lod;<br>
> src_number++;<br>
> }<br>
> break;<br>
><br>
> case ir_txd:<br>
> - instr->src[src_number] = evaluate_rvalue(ir->lod_info.grad.dPdx);<br>
> - instr->src_type[src_number] = nir_tex_src_ddx;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdx);<br>
> + instr->src[src_number].src_type = nir_tex_src_ddx;<br>
> src_number++;<br>
> - instr->src[src_number] = evaluate_rvalue(ir->lod_info.grad.dPdy);<br>
> - instr->src_type[src_number] = nir_tex_src_ddy;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdy);<br>
> + instr->src[src_number].src_type = nir_tex_src_ddy;<br>
> src_number++;<br>
> break;<br>
><br>
> case ir_txf_ms:<br>
> - instr->src[src_number] = evaluate_rvalue(ir->lod_info.sample_index);<br>
> - instr->src_type[src_number] = nir_tex_src_ms_index;<br>
> + instr->src[src_number].src = evaluate_rvalue(ir->lod_info.sample_index);<br>
> + instr->src[src_number].src_type = nir_tex_src_ms_index;<br>
> src_number++;<br>
> break;<br>
><br>
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c<br>
> index d8560c2..6239365 100644<br>
> --- a/src/glsl/nir/nir.c<br>
> +++ b/src/glsl/nir/nir.c<br>
> @@ -444,8 +444,9 @@ nir_tex_instr_create(void *mem_ctx, unsigned num_srcs)<br>
> dest_init(&instr->dest);<br>
><br>
> instr->num_srcs = num_srcs;<br>
> - for (unsigned i = 0; i < 4; i++)<br>
> - src_init(&instr->src[i]);<br>
> + instr->src = ralloc_array(mem_ctx, nir_tex_src, num_srcs);<br>
> + for (unsigned i = 0; i < num_srcs; i++)<br>
> + src_init(&instr->src[i].src);<br>
><br>
> instr->sampler_index = 0;<br>
> instr->sampler_array_size = 0;<br>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
> index 93023d3..26d99ee 100644<br>
> --- a/src/glsl/nir/nir.h<br>
> +++ b/src/glsl/nir/nir.h<br>
> @@ -823,7 +823,12 @@ typedef enum {<br>
> nir_tex_src_ddy,<br>
> nir_tex_src_sampler_offset, /* < dynamically uniform indirect offset */<br>
> nir_num_texinput_types<br>
<br>
</div></div>Whoops, seems like I spoke too fast again... this needs to be changed<br>
to nir_num_tex_src_types. To be honest, I'm not even sure if anything<br>
even uses this though so we might be able to just delete it.<br></blockquote><div><br></div><div>Good catch. Fixed.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> -} nir_texinput_type;<br>
> +} nir_tex_src_type;<br>
> +<br>
> +typedef struct {<br>
> + nir_src src;<br>
> + nir_tex_src_type src_type;<br>
> +} nir_tex_src;<br>
><br>
> typedef enum {<br>
> nir_texop_tex, /**< Regular texture look-up */<br>
> @@ -846,8 +851,7 @@ typedef struct {<br>
><br>
> nir_texop op;<br>
> nir_dest dest;<br>
> - nir_src src[4];<br>
> - nir_texinput_type src_type[4];<br>
> + nir_tex_src *src;<br>
> unsigned num_srcs, coord_components;<br>
> bool is_array, is_shadow;<br>
><br>
> @@ -917,13 +921,13 @@ nir_tex_instr_dest_size(nir_tex_instr *instr)<br>
> static inline unsigned<br>
> nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)<br>
> {<br>
> - if (instr->src_type[src] == nir_tex_src_coord)<br>
> + if (instr->src[src].src_type == nir_tex_src_coord)<br>
> return instr->coord_components;<br>
><br>
><br>
> - if (instr->src_type[src] == nir_tex_src_offset ||<br>
> - instr->src_type[src] == nir_tex_src_ddx ||<br>
> - instr->src_type[src] == nir_tex_src_ddy) {<br>
> + if (instr->src[src].src_type == nir_tex_src_offset ||<br>
> + instr->src[src].src_type == nir_tex_src_ddx ||<br>
> + instr->src[src].src_type == nir_tex_src_ddy) {<br>
> if (instr->is_array)<br>
> return instr->coord_components - 1;<br>
> else<br>
> @@ -934,10 +938,10 @@ nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)<br>
> }<br>
><br>
> static inline int<br>
> -nir_tex_instr_src_index(nir_tex_instr *instr, nir_texinput_type type)<br>
> +nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)<br>
> {<br>
> for (unsigned i = 0; i < instr->num_srcs; i++)<br>
> - if (instr->src_type[i] == type)<br>
> + if (instr->src[i].src_type == type)<br>
> return (int) i;<br>
><br>
> return -1;<br>
> diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp<br>
> index 5e90a4c..34b1a2d 100644<br>
> --- a/src/glsl/nir/nir_lower_samplers.cpp<br>
> +++ b/src/glsl/nir/nir_lower_samplers.cpp<br>
> @@ -96,11 +96,16 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,<br>
><br>
> assert(instr->num_srcs < 4);<br>
><br>
> - nir_instr_rewrite_src(&instr->instr, &instr->src[instr->num_srcs],<br>
> - nir_src_copy(deref_array->indirect, mem_ctx));<br>
> - instr->src_type[instr->num_srcs] = nir_tex_src_sampler_offset;<br>
> + instr->src = reralloc(mem_ctx, instr->src, nir_tex_src,<br>
> + instr->num_srcs + 1);<br>
> + memset(&instr->src[instr->num_srcs], 0, sizeof *instr->src);<br>
> + instr->src[instr->num_srcs].src_type = nir_tex_src_sampler_offset;<br>
> instr->num_srcs++;<br>
><br>
> + nir_instr_rewrite_src(&instr->instr,<br>
> + &instr->src[instr->num_srcs].src,<br>
> + nir_src_copy(deref_array->indirect, mem_ctx));<br>
> +<br>
> instr->sampler_array_size = glsl_get_length(deref->type);<br>
><br>
> nir_src empty;<br>
> diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c<br>
> index 502da38..ac1bb92 100644<br>
> --- a/src/glsl/nir/nir_print.c<br>
> +++ b/src/glsl/nir/nir_print.c<br>
> @@ -403,11 +403,11 @@ print_tex_instr(nir_tex_instr *instr, print_var_state *state, FILE *fp)<br>
> }<br>
><br>
> for (unsigned i = 0; i < instr->num_srcs; i++) {<br>
> - print_src(&instr->src[i], fp);<br>
> + print_src(&instr->src[i].src, fp);<br>
><br>
> fprintf(fp, " ");<br>
><br>
> - switch(instr->src_type[i]) {<br>
> + switch(instr->src[i].src_type) {<br>
> case nir_tex_src_coord:<br>
> fprintf(fp, "(coord)");<br>
> break;<br>
> diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c<br>
> index 5b5a7fc..a5ca3bd 100644<br>
> --- a/src/glsl/nir/nir_validate.c<br>
> +++ b/src/glsl/nir/nir_validate.c<br>
> @@ -393,8 +393,8 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)<br>
> src_type_seen[i] = false;<br>
><br>
> for (unsigned i = 0; i < instr->num_srcs; i++) {<br>
> - assert(!src_type_seen[instr->src_type[i]]);<br>
> - src_type_seen[instr->src_type[i]] = true;<br>
> + assert(!src_type_seen[instr->src[i].src_type]);<br>
> + src_type_seen[instr->src[i].src_type] = true;<br>
> validate_src(&instr->src[i], state);<br>
> }<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> index 845e47f..a520a58 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> @@ -1607,8 +1607,8 @@ fs_visitor::nir_emit_texture(nir_tex_instr *instr)<br>
> fs_reg coordinate, shadow_comparitor, lod, lod2, sample_index, mcs, offset;<br>
><br>
> for (unsigned i = 0; i < instr->num_srcs; i++) {<br>
> - fs_reg src = get_nir_src(instr->src[i]);<br>
> - switch (instr->src_type[i]) {<br>
> + fs_reg src = get_nir_src(instr->src[i].src);<br>
> + switch (instr->src[i].src_type) {<br>
> case nir_tex_src_bias:<br>
> lod = retype(src, BRW_REGISTER_TYPE_F);<br>
> break;<br>
> --<br>
> 2.2.0<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>