<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 5, 2017 at 12:38 AM, Alejandro Piñeiro <span dir="ltr"><<a href="mailto:apinheiro@igalia.com" target="_blank">apinheiro@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 05/05/17 04:11, Jason Ekstrand wrote:<br>
> We have to pass inputs_read through from prog_data because we may add an<br>
> edge flag on old platforms.<br>
<br>
</span>Well, the previous code was using nir->info->inputs_read. So perhaps<br>
this explanation should explicitly point that prog_data->inputs_read and<br>
nir->info->inputs_read they are not the same at that point (perhaps2,<br>
and why?)<br></blockquote><div><br></div><div>Sure. How about:<br><br></div><div>We also change nir_lower_vs_inputs to take an explicit inputs_read bitmask and pass in the inputs_read from prog_data instead from pulling it out of NIR. This is because the version in prog_data may get EDGEFLAG added to it on some old platforms.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another nitpick and one question below.<br>
<div><div class="h5"><br>
> ---<br>
> src/intel/compiler/brw_nir.c | 12 +++----<br>
> src/intel/compiler/brw_nir.h | 2 +-<br>
> src/intel/compiler/brw_vec4.<wbr>cpp | 54 +++++++++++-------------------<br>
> src/intel/compiler/brw_vec4_<wbr>nir.cpp | 49 ++-------------------------<br>
> src/intel/compiler/brw_vec4_<wbr>visitor.cpp | 7 ++--<br>
> src/intel/compiler/brw_vec4_<wbr>vs_visitor.cpp | 31 ++---------------<br>
> 6 files changed, 33 insertions(+), 122 deletions(-)<br>
><br>
> diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c<br>
> index 556782e..5ca532f 100644<br>
> --- a/src/intel/compiler/brw_nir.c<br>
> +++ b/src/intel/compiler/brw_nir.c<br>
> @@ -230,7 +230,7 @@ remap_patch_urb_offsets(nir_<wbr>block *block, nir_builder *b,<br>
><br>
> void<br>
> brw_nir_lower_vs_inputs(nir_<wbr>shader *nir,<br>
> - bool is_scalar,<br>
> + uint64_t inputs_read,<br>
> bool use_legacy_snorm_formula,<br>
> const uint8_t *vs_attrib_wa_flags)<br>
> {<br>
> @@ -253,11 +253,7 @@ brw_nir_lower_vs_inputs(nir_<wbr>shader *nir,<br>
> brw_nir_apply_attribute_<wbr>workarounds(nir, use_legacy_snorm_formula,<br>
> vs_attrib_wa_flags);<br>
><br>
> - /* The last step is to remap VERT_ATTRIB_* to actual registers and we only<br>
> - * do that for scalar shaders at the moment.<br>
> - */<br>
> - if (!is_scalar)<br>
> - return;<br>
> + /* The last step is to remap VERT_ATTRIB_* to actual registers */<br>
><br>
> const bool has_svgs =<br>
> nir->info->system_values_read &<br>
> @@ -266,7 +262,7 @@ brw_nir_lower_vs_inputs(nir_<wbr>shader *nir,<br>
> BITFIELD64_BIT(SYSTEM_VALUE_<wbr>VERTEX_ID_ZERO_BASE) |<br>
> BITFIELD64_BIT(SYSTEM_VALUE_<wbr>INSTANCE_ID));<br>
><br>
> - const unsigned num_inputs = _mesa_bitcount_64(nir->info-><wbr>inputs_read);<br>
> + const unsigned num_inputs = _mesa_bitcount_64(inputs_read)<wbr>;<br>
><br>
> nir_foreach_function(function, nir) {<br>
> if (!function->impl)<br>
> @@ -340,7 +336,7 @@ brw_nir_lower_vs_inputs(nir_<wbr>shader *nir,<br>
> * before it and counting the bits.<br>
> */<br>
> int attr = nir_intrinsic_base(intrin);<br>
> - int slot = _mesa_bitcount_64(nir->info-><wbr>inputs_read &<br>
> + int slot = _mesa_bitcount_64(inputs_read &<br>
> BITFIELD64_MASK(attr));<br>
> nir_intrinsic_set_base(intrin, slot);<br>
> break;<br>
> diff --git a/src/intel/compiler/brw_nir.h b/src/intel/compiler/brw_nir.h<br>
> index b96072c..3bba68d 100644<br>
> --- a/src/intel/compiler/brw_nir.h<br>
> +++ b/src/intel/compiler/brw_nir.h<br>
> @@ -98,7 +98,7 @@ nir_shader *brw_preprocess_nir(const struct brw_compiler *compiler,<br>
> bool brw_nir_lower_intrinsics(nir_<wbr>shader *nir,<br>
> struct brw_stage_prog_data *prog_data);<br>
> void brw_nir_lower_vs_inputs(nir_<wbr>shader *nir,<br>
> - bool is_scalar,<br>
> + uint64_t inputs_read,<br>
> bool use_legacy_snorm_formula,<br>
> const uint8_t *vs_attrib_wa_flags);<br>
> void brw_nir_lower_vue_inputs(nir_<wbr>shader *nir, bool is_scalar,<br>
> diff --git a/src/intel/compiler/brw_vec4.<wbr>cpp b/src/intel/compiler/brw_vec4.<wbr>cpp<br>
> index 21f34bc..b387321 100644<br>
> --- a/src/intel/compiler/brw_vec4.<wbr>cpp<br>
> +++ b/src/intel/compiler/brw_vec4.<wbr>cpp<br>
> @@ -1740,40 +1740,23 @@ vec4_visitor::lower_<wbr>attributes_to_hw_regs(const int *attribute_map,<br>
> int<br>
> vec4_vs_visitor::setup_<wbr>attributes(int payload_reg)<br>
> {<br>
> - int nr_attributes;<br>
> - int attribute_map[VERT_ATTRIB_MAX + 2];<br>
> - memset(attribute_map, 0, sizeof(attribute_map));<br>
> -<br>
> - nr_attributes = 0;<br>
> - GLbitfield64 vs_inputs = vs_prog_data->inputs_read;<br>
> - while (vs_inputs) {<br>
> - GLuint first = ffsll(vs_inputs) - 1;<br>
> - int needed_slots =<br>
> - (vs_prog_data->double_inputs_<wbr>read & BITFIELD64_BIT(first)) ? 2 : 1;<br>
> - for (int c = 0; c < needed_slots; c++) {<br>
> - attribute_map[first + c] = payload_reg + nr_attributes;<br>
> - nr_attributes++;<br>
> - vs_inputs &= ~BITFIELD64_BIT(first + c);<br>
> + foreach_block_and_inst(block, vec4_instruction, inst, cfg) {<br>
> + for (int i = 0; i < 3; i++) {<br>
> + if (inst->src[i].file == ATTR) {<br>
> + assert(inst->src[i].offset % REG_SIZE == 0);<br>
> + int grf = payload_reg + inst->src[i].nr +<br>
> + inst->src[i].offset / REG_SIZE;<br>
> +<br>
> + struct brw_reg reg = brw_vec8_grf(grf, 0);<br>
> + reg.swizzle = inst->src[i].swizzle;<br>
> + reg.type = inst->src[i].type;<br>
> + reg.abs = inst->src[i].abs;<br>
> + reg.negate = inst->src[i].negate;<br>
> + inst->src[i] = reg;<br>
> + }<br>
> }<br>
> }<br>
><br>
> - /* VertexID is stored by the VF as the last vertex element, but we<br>
> - * don't represent it with a flag in inputs_read, so we call it<br>
> - * VERT_ATTRIB_MAX.<br>
> - */<br>
> - if (vs_prog_data->uses_vertexid || vs_prog_data->uses_instanceid ||<br>
> - vs_prog_data->uses_basevertex || vs_prog_data->uses_<wbr>baseinstance) {<br>
> - attribute_map[VERT_ATTRIB_MAX] = payload_reg + nr_attributes;<br>
> - nr_attributes++;<br>
> - }<br>
> -<br>
> - if (vs_prog_data->uses_drawid) {<br>
> - attribute_map[VERT_ATTRIB_MAX + 1] = payload_reg + nr_attributes;<br>
> - nr_attributes++;<br>
> - }<br>
> -<br>
> - lower_attributes_to_hw_regs(<wbr>attribute_map, false /* interleaved */);<br>
> -<br>
> return payload_reg + vs_prog_data->nr_attribute_<wbr>slots;<br>
> }<br>
><br>
> @@ -2771,10 +2754,6 @@ brw_compile_vs(const struct brw_compiler *compiler, void *log_data,<br>
> const bool is_scalar = compiler->scalar_stage[MESA_<wbr>SHADER_VERTEX];<br>
> nir_shader *shader = nir_shader_clone(mem_ctx, src_shader);<br>
> shader = brw_nir_apply_sampler_key(<wbr>shader, compiler, &key->tex, is_scalar);<br>
> - brw_nir_lower_vs_inputs(<wbr>shader, is_scalar,<br>
> - use_legacy_snorm_formula, key->gl_attrib_wa_flags);<br>
> - brw_nir_lower_vue_outputs(<wbr>shader, is_scalar);<br>
> - shader = brw_postprocess_nir(shader, compiler, is_scalar);<br>
><br>
> const unsigned *assembly = NULL;<br>
><br>
> @@ -2791,6 +2770,11 @@ brw_compile_vs(const struct brw_compiler *compiler, void *log_data,<br>
> prog_data->inputs_read |= VERT_BIT_EDGEFLAG;<br>
> }<br>
><br>
> + brw_nir_lower_vs_inputs(<wbr>shader, prog_data->inputs_read,<br>
> + use_legacy_snorm_formula, key->gl_attrib_wa_flags);<br>
> + brw_nir_lower_vue_outputs(<wbr>shader, is_scalar);<br>
> + shader = brw_postprocess_nir(shader, compiler, is_scalar);<br>
> +<br>
> unsigned nr_attribute_slots = _mesa_bitcount_64(prog_data-><wbr>inputs_read);<br>
><br>
> /* gl_VertexID and gl_InstanceID are system values, but arrive via an<br>
> diff --git a/src/intel/compiler/brw_vec4_<wbr>nir.cpp b/src/intel/compiler/brw_vec4_<wbr>nir.cpp<br>
> index a82d520..2a98932 100644<br>
> --- a/src/intel/compiler/brw_vec4_<wbr>nir.cpp<br>
> +++ b/src/intel/compiler/brw_vec4_<wbr>nir.cpp<br>
> @@ -50,45 +50,6 @@ vec4_visitor::emit_nir_code()<br>
> void<br>
> vec4_visitor::nir_setup_<wbr>system_value_intrinsic(nir_<wbr>intrinsic_instr *instr)<br>
> {<br>
<br>
</div></div>Perhaps it would be good to include on the commit message that the<br>
remapping include the system values vs attributes.<br><div><div class="h5"></div></div></blockquote><div><br></div><div>Sure. How about:<br><br></div><div>The NIR pass already handles remapping system values to attributes for us so we can delete the system value code as well.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> - dst_reg *reg;<br>
> -<br>
> - switch (instr->intrinsic) {<br>
> - case nir_intrinsic_load_vertex_id:<br>
> - unreachable("should be lowered by lower_vertex_id().");<br>
> -<br>
> - case nir_intrinsic_load_vertex_id_<wbr>zero_base:<br>
> - reg = &nir_system_values[SYSTEM_<wbr>VALUE_VERTEX_ID_ZERO_BASE];<br>
> - if (reg->file == BAD_FILE)<br>
> - *reg = *make_reg_for_system_value(<wbr>SYSTEM_VALUE_VERTEX_ID_ZERO_<wbr>BASE);<br>
> - break;<br>
> -<br>
> - case nir_intrinsic_load_base_<wbr>vertex:<br>
> - reg = &nir_system_values[SYSTEM_<wbr>VALUE_BASE_VERTEX];<br>
> - if (reg->file == BAD_FILE)<br>
> - *reg = *make_reg_for_system_value(<wbr>SYSTEM_VALUE_BASE_VERTEX);<br>
> - break;<br>
> -<br>
> - case nir_intrinsic_load_instance_<wbr>id:<br>
> - reg = &nir_system_values[SYSTEM_<wbr>VALUE_INSTANCE_ID];<br>
> - if (reg->file == BAD_FILE)<br>
> - *reg = *make_reg_for_system_value(<wbr>SYSTEM_VALUE_INSTANCE_ID);<br>
> - break;<br>
> -<br>
> - case nir_intrinsic_load_base_<wbr>instance:<br>
> - reg = &nir_system_values[SYSTEM_<wbr>VALUE_BASE_INSTANCE];<br>
> - if (reg->file == BAD_FILE)<br>
> - *reg = *make_reg_for_system_value(<wbr>SYSTEM_VALUE_BASE_INSTANCE);<br>
> - break;<br>
> -<br>
> - case nir_intrinsic_load_draw_id:<br>
> - reg = &nir_system_values[SYSTEM_<wbr>VALUE_DRAW_ID];<br>
> - if (reg->file == BAD_FILE)<br>
> - *reg = *make_reg_for_system_value(<wbr>SYSTEM_VALUE_DRAW_ID);<br>
> - break;<br>
> -<br>
> - default:<br>
> - break;<br>
> - }<br>
> }<br>
><br>
> static bool<br>
> @@ -826,14 +787,8 @@ vec4_visitor::nir_emit_<wbr>intrinsic(nir_intrinsic_instr *instr)<br>
> case nir_intrinsic_load_instance_<wbr>id:<br>
> case nir_intrinsic_load_base_<wbr>instance:<br>
> case nir_intrinsic_load_draw_id:<br>
> - case nir_intrinsic_load_invocation_<wbr>id: {<br>
> - gl_system_value sv = nir_system_value_from_<wbr>intrinsic(instr->intrinsic);<br>
> - src_reg val = src_reg(nir_system_values[sv])<wbr>;<br>
> - assert(val.file != BAD_FILE);<br>
> - dest = get_nir_dest(instr->dest, val.type);<br>
> - emit(MOV(dest, val));<br>
> - break;<br>
> - }<br>
> + case nir_intrinsic_load_invocation_<wbr>id:<br>
> + unreachable("should be lowered by brw_nir_lower_vs_inputs()");<br>
><br>
> case nir_intrinsic_load_uniform: {<br>
> /* Offsets are in bytes but they should always be multiples of 4 */<br>
> diff --git a/src/intel/compiler/brw_vec4_<wbr>visitor.cpp b/src/intel/compiler/brw_vec4_<wbr>visitor.cpp<br>
> index 262a084..0753bd6 100644<br>
> --- a/src/intel/compiler/brw_vec4_<wbr>visitor.cpp<br>
> +++ b/src/intel/compiler/brw_vec4_<wbr>visitor.cpp<br>
> @@ -1315,7 +1315,7 @@ vec4_visitor::emit_urb_slot(<wbr>dst_reg reg, int varying)<br>
> if (output_reg[VARYING_SLOT_POS][<wbr>0].file != BAD_FILE)<br>
> emit(MOV(reg, src_reg(output_reg[VARYING_<wbr>SLOT_POS][0])));<br>
> break;<br>
> - case VARYING_SLOT_EDGE:<br>
> + case VARYING_SLOT_EDGE: {<br>
> /* This is present when doing unfilled polygons. We're supposed to copy<br>
> * the edge flag from the user-provided vertex array<br>
> * (glEdgeFlagPointer), or otherwise we'll copy from the current value<br>
> @@ -1323,9 +1323,12 @@ vec4_visitor::emit_urb_slot(<wbr>dst_reg reg, int varying)<br>
> * determine which edges should be drawn as wireframe.<br>
> */<br>
> current_annotation = "edge flag";<br>
> - emit(MOV(reg, src_reg(dst_reg(ATTR, VERT_ATTRIB_EDGEFLAG,<br>
> + int edge_attr = _mesa_bitcount_64(nir->info-><wbr>inputs_read &<br>
> + BITFIELD64_MASK(VERT_ATTRIB_<wbr>EDGEFLAG));<br>
> + emit(MOV(reg, src_reg(dst_reg(ATTR, edge_attr,<br>
> glsl_type::float_type, WRITEMASK_XYZW))));<br>
> break;<br>
> + }<br>
> case BRW_VARYING_SLOT_PAD:<br>
> /* No need to write to this slot */<br>
> break;<br>
> diff --git a/src/intel/compiler/brw_vec4_<wbr>vs_visitor.cpp b/src/intel/compiler/brw_vec4_<wbr>vs_visitor.cpp<br>
> index 2a19788..7edf6ba 100644<br>
> --- a/src/intel/compiler/brw_vec4_<wbr>vs_visitor.cpp<br>
> +++ b/src/intel/compiler/brw_vec4_<wbr>vs_visitor.cpp<br>
> @@ -36,35 +36,8 @@ vec4_vs_visitor::emit_prolog()<br>
> dst_reg *<br>
> vec4_vs_visitor::make_reg_for_<wbr>system_value(int location)<br>
> {<br>
> - /* VertexID is stored by the VF as the last vertex element, but<br>
> - * we don't represent it with a flag in inputs_read, so we call<br>
> - * it VERT_ATTRIB_MAX, which setup_attributes() picks up on.<br>
> - */<br>
> - dst_reg *reg = new(mem_ctx) dst_reg(ATTR, VERT_ATTRIB_MAX);<br>
> -<br>
> - switch (location) {<br>
> - case SYSTEM_VALUE_BASE_VERTEX:<br>
> - reg->writemask = WRITEMASK_X;<br>
> - break;<br>
> - case SYSTEM_VALUE_BASE_INSTANCE:<br>
> - reg->writemask = WRITEMASK_Y;<br>
> - break;<br>
> - case SYSTEM_VALUE_VERTEX_ID:<br>
> - case SYSTEM_VALUE_VERTEX_ID_ZERO_<wbr>BASE:<br>
> - reg->writemask = WRITEMASK_Z;<br>
> - break;<br>
> - case SYSTEM_VALUE_INSTANCE_ID:<br>
> - reg->writemask = WRITEMASK_W;<br>
> - break;<br>
> - case SYSTEM_VALUE_DRAW_ID:<br>
> - reg = new(mem_ctx) dst_reg(ATTR, VERT_ATTRIB_MAX + 1);<br>
> - reg->writemask = WRITEMASK_X;<br>
> - break;<br>
> - default:<br>
> - unreachable("not reached");<br>
> - }<br>
> -<br>
> - return reg;<br>
> + unreachable("not reached");<br>
> + return NULL;<br>
<br>
</div></div>So I understand that the only reason to not just remove<br>
make_reg_for_system_value is the custom make_reg_for_system_value at<br>
brw_vec4_gs_visitor (that deals with invocation ID), right?<br></blockquote><div><br></div></div>I believe that's correct. That said, I should be able to fairly easily just special-case that and delete even more stuff. I'll give it a go as a follow-on patch.<br><br></div><div class="gmail_extra">--Jason<br></div></div>