v3dv/cmd_buffer: start to emit draw packets
authorAlejandro Piñeiro <apinheiro@igalia.com>
Thu, 2 Jan 2020 11:34:43 +0000 (12:34 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 13 Oct 2020 21:21:26 +0000 (21:21 +0000)
Starting using only the packet VERTEX_ARRAY_PRIMS

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

src/broadcom/vulkan/v3dv_cmd_buffer.c
src/broadcom/vulkan/v3dv_pipeline.c
src/broadcom/vulkan/v3dv_private.h

index 2f5d39e..377314e 100644 (file)
@@ -1417,9 +1417,63 @@ cmd_buffer_emit_graphics_pipeline(struct v3dv_cmd_buffer *cmd_buffer)
 
 }
 
+/* FIXME: C&P from v3dx_draw. Refactor to common place? */
+static uint32_t
+v3d_hw_prim_type(enum pipe_prim_type prim_type)
+{
+   switch (prim_type) {
+   case PIPE_PRIM_POINTS:
+   case PIPE_PRIM_LINES:
+   case PIPE_PRIM_LINE_LOOP:
+   case PIPE_PRIM_LINE_STRIP:
+   case PIPE_PRIM_TRIANGLES:
+   case PIPE_PRIM_TRIANGLE_STRIP:
+   case PIPE_PRIM_TRIANGLE_FAN:
+      return prim_type;
+
+   case PIPE_PRIM_LINES_ADJACENCY:
+   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
+   case PIPE_PRIM_TRIANGLES_ADJACENCY:
+   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
+      return 8 + (prim_type - PIPE_PRIM_LINES_ADJACENCY);
+
+   default:
+      unreachable("Unsupported primitive type");
+   }
+}
+
+struct v3dv_draw_info {
+   uint32_t vertex_count;
+   uint32_t instance_count;
+   uint32_t first_vertex;
+   uint32_t first_instance;
+};
 
 static void
-cmd_buffer_emit_state(struct v3dv_cmd_buffer *cmd_buffer)
+cmd_buffer_emit_draw_packets(struct v3dv_cmd_buffer *cmd_buffer,
+                             struct v3dv_draw_info *info)
+{
+   struct v3dv_cmd_buffer_state *state = &cmd_buffer->state;
+   struct v3dv_pipeline *pipeline = state->pipeline;
+
+   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(&cmd_buffer->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;
+   }
+}
+
+static void
+cmd_buffer_draw(struct v3dv_cmd_buffer *cmd_buffer,
+                struct v3dv_draw_info *info)
 {
    /* FIXME: likely to be filtered by really needed states */
    uint32_t states = cmd_buffer->state.dirty;
@@ -1439,6 +1493,9 @@ cmd_buffer_emit_state(struct v3dv_cmd_buffer *cmd_buffer)
       emit_viewport(cmd_buffer);
    }
 
+   /* FIXME: any dirty flag to filter ? */
+   cmd_buffer_emit_draw_packets(cmd_buffer, info);
+
    cmd_buffer->state.dirty &= ~states;
 }
 
@@ -1450,6 +1507,12 @@ v3dv_CmdDraw(VkCommandBuffer commandBuffer,
              uint32_t firstInstance)
 {
    V3DV_FROM_HANDLE(v3dv_cmd_buffer, cmd_buffer, commandBuffer);
+   struct v3dv_draw_info info = {};
+
+   info.vertex_count = vertexCount;
+   info.instance_count = instanceCount;
+   info.first_instance = firstInstance;
+   info.first_vertex = firstVertex;
 
-   cmd_buffer_emit_state(cmd_buffer);
+   cmd_buffer_draw(cmd_buffer, &info);
 }
index a5643c5..cd593dc 100644 (file)
@@ -646,6 +646,13 @@ pipeline_compile_graphics(struct v3dv_pipeline *pipeline,
 
          pipeline->vs_bin = pipeline_stage_create_vs_bin(pipeline->vs, alloc);
 
+         /* FIXME: likely this to be moved to a gather info method to a full
+          * struct inside pipeline_stage
+          */
+         const VkPipelineInputAssemblyStateCreateInfo *ia_info =
+            pCreateInfo->pInputAssemblyState;
+         pipeline->vs->topology = vk_to_pipe_prim_type[ia_info->topology];
+
          /* Note that at this point we would compile twice, one for vs and
           * other for vs_bin. For now we are maintaining two pipeline_stage
           * and two keys. Eventually we could reuse the key.
index f202fba..8c6869b 100644 (file)
@@ -543,6 +543,11 @@ struct v3dv_pipeline_stage {
       struct v3d_fs_prog_data *fs;
    } prog_data;
 
+   /* FIXME: only make sense on vs, so perhaps a v3dv key like radv? or a kind
+    * of pipe_draw_info
+    */
+   enum pipe_prim_type topology;
+
    /* FIXME: using one bo per shader. Eventually we would be interested on
     * reusing the same bo for all the shaders, like a bo per v3dv_pipeline for
     * shaders.