nir/lower_idiv: add new llvm-based path
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_compiler_nir.c
index 4f854954922104737b2a503abc54e2802900989d..4cf48b46e785b548d5a63aa00af38556d776ae75 100644 (file)
@@ -56,16 +56,13 @@ struct etna_compile {
    int inst_ptr; /* current instruction pointer */
    struct etna_inst code[ETNA_MAX_INSTRUCTIONS * ETNA_INST_SIZE];
 
+   /* constants */
+   uint64_t consts[ETNA_MAX_IMM];
+
    /* There was an error during compilation */
    bool error;
 };
 
-#define compile_error(ctx, args...) ({ \
-   printf(args); \
-   ctx->error = true; \
-   assert(0); \
-})
-
 /* io related lowering
  * run after lower_int_to_float because it adds i2f/f2i ops
  */
@@ -149,6 +146,8 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v)
                   lod_bias = &tex->src[i].src;
                   lod_bias_idx = i;
                   break;
+               case nir_tex_src_comparator:
+                  break;
                default:
                   assert(0);
                   break;
@@ -490,7 +489,7 @@ etna_emit_alu(struct etna_compile *c, nir_op op, struct etna_inst_dst dst,
 static void
 etna_emit_tex(struct etna_compile *c, nir_texop op, unsigned texid, unsigned dst_swiz,
               struct etna_inst_dst dst, struct etna_inst_src coord,
-              struct etna_inst_src lod_bias)
+              struct etna_inst_src lod_bias, struct etna_inst_src compare)
 {
    struct etna_inst inst = {
       .dst = dst,
@@ -502,6 +501,9 @@ etna_emit_tex(struct etna_compile *c, nir_texop op, unsigned texid, unsigned dst
    if (lod_bias.use)
       inst.src[1] = lod_bias;
 
+   if (compare.use)
+      inst.src[2] = compare;
+
    switch (op) {
    case nir_texop_tex: inst.opcode = INST_OPCODE_TEXLD; break;
    case nir_texop_txb: inst.opcode = INST_OPCODE_TEXLDB; break;
@@ -760,7 +762,7 @@ etna_compile_shader_nir(struct etna_shader_variant *v)
       OPT_V(s, nir_opt_algebraic);
       OPT_V(s, nir_lower_bool_to_float);
    } else {
-      OPT_V(s, nir_lower_idiv);
+      OPT_V(s, nir_lower_idiv, nir_lower_idiv_fast);
       OPT_V(s, nir_lower_bool_to_int32);
    }
 
@@ -790,23 +792,11 @@ etna_compile_shader_nir(struct etna_shader_variant *v)
    if (DBG_ENABLED(ETNA_DBG_DUMP_SHADERS))
       nir_print_shader(s, stdout);
 
-   uint64_t consts[ETNA_MAX_IMM] = {};
-
    unsigned block_ptr[nir_shader_get_entrypoint(s)->num_blocks];
    c->block_ptr = block_ptr;
-   struct emit_options options = {
-      .max_temps = ETNA_MAX_TEMPS,
-      .max_consts = ETNA_MAX_IMM / 4,
-      .id_reg = sf->num_reg,
-      .single_const_src = c->specs->halti < 5,
-      .etna_new_transcendentals = c->specs->has_new_transcendentals,
-      .no_integers = c->specs->halti < 2,
-      .user = c,
-      .consts = consts,
-   };
 
    unsigned num_consts;
-   ASSERTED bool ok = emit_shader(c->nir, &options, &v->num_temps, &num_consts);
+   ASSERTED bool ok = emit_shader(c, &v->num_temps, &num_consts);
    assert(ok);
 
    /* empty shader, emit NOP */
@@ -814,7 +804,7 @@ etna_compile_shader_nir(struct etna_shader_variant *v)
       emit_inst(c, &(struct etna_inst) { .opcode = INST_OPCODE_NOP });
 
    /* assemble instructions, fixing up labels */
-   uint32_t *code = MALLOC(c->inst_ptr * 16 + 1024);
+   uint32_t *code = MALLOC(c->inst_ptr * 16);
    for (unsigned i = 0; i < c->inst_ptr; i++) {
       struct etna_inst *inst = &c->code[i];
       if (inst->opcode == INST_OPCODE_BRANCH)
@@ -828,7 +818,7 @@ etna_compile_shader_nir(struct etna_shader_variant *v)
    v->code = code;
    v->needs_icache = c->inst_ptr > specs->max_instructions;
 
-   copy_uniform_state_to_shader(v, consts, num_consts);
+   copy_uniform_state_to_shader(v, c->consts, num_consts);
 
    if (s->info.stage == MESA_SHADER_FRAGMENT) {
       v->input_count_unk8 = 31; /* XXX what is this */