etnaviv: implement gl_VertexID/gl_InstanceID
authorJonathan Marek <jonathan@marek.ca>
Mon, 6 Jan 2020 02:40:18 +0000 (21:40 -0500)
committerJonathan Marek <jonathan@marek.ca>
Wed, 8 Jan 2020 17:27:35 +0000 (12:27 -0500)
Fixes:
dEQP-GLES3.functional.instanced.*

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
src/gallium/drivers/etnaviv/etnaviv_emit.c
src/gallium/drivers/etnaviv/etnaviv_internal.h
src/gallium/drivers/etnaviv/etnaviv_shader.c

index 7934eb0490e6fd371ca39f6a097a898fcb3a8919..3aa2b00c822f984464e869f8bb09928d11a88281 100644 (file)
@@ -120,6 +120,11 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v)
                   nir_ssa_def *ssa = nir_imul(&b, intr->src[0].ssa, nir_imm_int(&b, 16));
                   nir_instr_rewrite_src(instr, &intr->src[0], nir_src_for_ssa(ssa));
                } break;
+               case nir_intrinsic_load_vertex_id:
+               case nir_intrinsic_load_instance_id:
+                  /* detect use of vertex_id/instance_id */
+                  v->vs_id_in_reg = v->infile.num_reg;
+                  break;
                default:
                   break;
                }
index 977f156958aa18d50ecf5090a73705176feecea1..e60437d8ec926dc0e27b1a1d5443b9aba1a72e07 100644 (file)
@@ -132,6 +132,7 @@ emit_halti5_only_state(struct etna_context *ctx, int vs_output_count)
    etna_coalesce_start(stream, &coalesce);
    if (unlikely(dirty & (ETNA_DIRTY_SHADER))) {
       /* Magic states (load balancing, inter-unit sync, buffers) */
+      /*007C4*/ EMIT_STATE(FE_HALTI5_ID_CONFIG, ctx->shader_state.FE_HALTI5_ID_CONFIG);
       /*00870*/ EMIT_STATE(VS_HALTI5_OUTPUT_COUNT, vs_output_count | ((vs_output_count * 0x10) << 8));
       /*008A0*/ EMIT_STATE(VS_HALTI5_UNK008A0, 0x0001000e | ((0x110/vs_output_count) << 20));
       for (int x = 0; x < 4; ++x) {
index b226526410dba13901b668a5785a90bcf8dda9ec..c868cafab8d18b4fe1d212c79ea075499331e370 100644 (file)
@@ -265,6 +265,7 @@ struct compiled_shader_state {
    uint32_t GL_VARYING_NUM_COMPONENTS;
    uint32_t GL_VARYING_COMPONENT_USE[2];
    uint32_t GL_HALTI5_SH_SPECIALS;
+   uint32_t FE_HALTI5_ID_CONFIG;
    unsigned vs_inst_mem_size;
    unsigned ps_inst_mem_size;
    uint32_t *VS_INST_MEM;
index 937a83c89798f5863417db6c8ed7397d6cb4d522..6f6f8d2b9f4ad71eb9e9009f347253215047d307 100644 (file)
@@ -284,6 +284,20 @@ etna_shader_update_vs_inputs(struct compiled_shader_state *cs,
          etna_bitarray_set(vs_input, 8, idx, cur_temp++);
    }
 
+   if (vs->vs_id_in_reg >= 0) {
+      cs->VS_INPUT_COUNT = VIVS_VS_INPUT_COUNT_COUNT(num_vs_inputs + 1) |
+                           VIVS_VS_INPUT_COUNT_UNK8(vs->input_count_unk8) |
+                           VIVS_VS_INPUT_COUNT_ID_ENABLE;
+
+      etna_bitarray_set(vs_input, 8, num_vs_inputs, vs->vs_id_in_reg);
+
+      cs->FE_HALTI5_ID_CONFIG =
+         VIVS_FE_HALTI5_ID_CONFIG_VERTEX_ID_ENABLE |
+         VIVS_FE_HALTI5_ID_CONFIG_INSTANCE_ID_ENABLE |
+         VIVS_FE_HALTI5_ID_CONFIG_VERTEX_ID_REG(vs->vs_id_in_reg * 4) |
+         VIVS_FE_HALTI5_ID_CONFIG_INSTANCE_ID_REG(vs->vs_id_in_reg * 4 + 1);
+   }
+
    for (int idx = 0; idx < ARRAY_SIZE(cs->VS_INPUT); ++idx)
       cs->VS_INPUT[idx] = vs_input[idx];