v3dv: emit instanced draw calls when requested

This requires that we emit a specific draw command and that we emit
the base instance if not zero right before the instanced draw call.
Notice that we were already doing this for instanced indexed draw
calls, so here we are only adding this for non-indexed draw calls.

We also need to flag whether the vertex shader reads the base instance
in the shader record (which it will if it reads uses gl_InstanceIndex,
as that is lowered in Vulkan to base_instance + instance_id).

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c
index 69c791e..f26cc6a 100644
--- a/src/broadcom/vulkan/v3dv_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c
@@ -2849,16 +2849,28 @@
 
    assert(pipeline);
 
-   uint32_t prim_tf_enable = 0;
    uint32_t hw_prim_type = v3d_hw_prim_type(pipeline->vs->topology);
 
-   /* FIXME: using VERTEX_ARRAY_PRIMS always as it fits our test caselist
-    * right now. Need to be choosen based on the current case.
-    */
-   cl_emit(&job->bcl, VERTEX_ARRAY_PRIMS, prim) {
-      prim.mode = hw_prim_type | prim_tf_enable;
-      prim.length = info->vertex_count;
-      prim.index_of_first_vertex = info->first_vertex;
+   if (info->first_instance > 0) {
+      cl_emit(&job->bcl, BASE_VERTEX_BASE_INSTANCE, base) {
+         base.base_instance = info->first_instance;
+         base.base_vertex = 0;
+      }
+   }
+
+   if (info->instance_count > 1) {
+      cl_emit(&job->bcl, VERTEX_ARRAY_INSTANCED_PRIMS, prim) {
+         prim.mode = hw_prim_type;
+         prim.index_of_first_vertex = info->first_vertex;
+         prim.number_of_instances = info->instance_count;
+         prim.instance_length = info->vertex_count;
+      }
+   } else {
+      cl_emit(&job->bcl, VERTEX_ARRAY_PRIMS, prim) {
+         prim.mode = hw_prim_type;
+         prim.length = info->vertex_count;
+         prim.index_of_first_vertex = info->first_vertex;
+      }
    }
 }
 
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c
index 21f9235..b9b0403 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -2019,10 +2019,14 @@
 
       shader.vertex_id_read_by_coordinate_shader =
          prog_data_vs_bin->uses_vid;
+      shader.base_instance_id_read_by_coordinate_shader =
+         prog_data_vs_bin->uses_biid;
       shader.instance_id_read_by_coordinate_shader =
          prog_data_vs_bin->uses_iid;
       shader.vertex_id_read_by_vertex_shader =
          prog_data_vs->uses_vid;
+      shader.base_instance_id_read_by_vertex_shader =
+         prog_data_vs->uses_biid;
       shader.instance_id_read_by_vertex_shader =
          prog_data_vs->uses_iid;