spirv: Lower BaseVertex to FIRST_VERTEX instead of BASE_VERTEX
authorNeil Roberts <nroberts@igalia.com>
Thu, 25 Jan 2018 18:15:41 +0000 (19:15 +0100)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 19 Apr 2018 22:57:45 +0000 (15:57 -0700)
The base vertex in Vulkan is different from GL in that for non-indexed
primitives the value is taken from the firstVertex parameter instead
of being set to zero. This coincides with the new SYSTEM_VALUE_FIRST_VERTEX
instead of BASE_VERTEX.

v2 (idr): Add comment describing why SYSTEM_VALUE_FIRST_VERTEX is used
for SpvBuiltInBaseVertex.  Suggested by Jason.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> [v1]
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/spirv/vtn_variables.c
src/intel/vulkan/genX_cmd_buffer.c
src/intel/vulkan/genX_pipeline.c

index 0673fe80675a5f436f39e346c83c8928b4232699..9679ff6526cede567ac8111f268252681f76ce8c 100644 (file)
@@ -1296,7 +1296,10 @@ vtn_get_builtin_location(struct vtn_builder *b,
       set_mode_system_value(b, mode);
       break;
    case SpvBuiltInBaseVertex:
-      *location = SYSTEM_VALUE_BASE_VERTEX;
+      /* OpenGL gl_BaseVertex (SYSTEM_VALUE_BASE_VERTEX) is not the same
+       * semantic as SPIR-V BaseVertex (SYSTEM_VALUE_FIRST_VERTEX).
+       */
+      *location = SYSTEM_VALUE_FIRST_VERTEX;
       set_mode_system_value(b, mode);
       break;
    case SpvBuiltInBaseInstance:
index cbe623802e9381e9b3be42896335eb1c3379e345..be4e9a694262959eebe2454dae386990d83c959c 100644 (file)
@@ -2673,7 +2673,9 @@ void genX(CmdDraw)(
 
    genX(cmd_buffer_flush_state)(cmd_buffer);
 
-   if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
+   if (vs_prog_data->uses_firstvertex ||
+       vs_prog_data->uses_basevertex ||
+       vs_prog_data->uses_baseinstance)
       emit_base_vertex_instance(cmd_buffer, firstVertex, firstInstance);
    if (vs_prog_data->uses_drawid)
       emit_draw_index(cmd_buffer, 0);
@@ -2711,7 +2713,9 @@ void genX(CmdDrawIndexed)(
 
    genX(cmd_buffer_flush_state)(cmd_buffer);
 
-   if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
+   if (vs_prog_data->uses_firstvertex ||
+       vs_prog_data->uses_basevertex ||
+       vs_prog_data->uses_baseinstance)
       emit_base_vertex_instance(cmd_buffer, vertexOffset, firstInstance);
    if (vs_prog_data->uses_drawid)
       emit_draw_index(cmd_buffer, 0);
@@ -2850,7 +2854,9 @@ void genX(CmdDrawIndirect)(
       struct anv_bo *bo = buffer->bo;
       uint32_t bo_offset = buffer->offset + offset;
 
-      if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
+      if (vs_prog_data->uses_firstvertex ||
+          vs_prog_data->uses_basevertex ||
+          vs_prog_data->uses_baseinstance)
          emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 8);
       if (vs_prog_data->uses_drawid)
          emit_draw_index(cmd_buffer, i);
@@ -2889,7 +2895,9 @@ void genX(CmdDrawIndexedIndirect)(
       uint32_t bo_offset = buffer->offset + offset;
 
       /* TODO: We need to stomp base vertex to 0 somehow */
-      if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
+      if (vs_prog_data->uses_firstvertex ||
+          vs_prog_data->uses_basevertex ||
+          vs_prog_data->uses_baseinstance)
          emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 12);
       if (vs_prog_data->uses_drawid)
          emit_draw_index(cmd_buffer, i);
index eb2d414735708cdcb86834f8153df7c36df3482f..a473f42c7e1161c45ca912dfa21fdff965744bc9 100644 (file)
@@ -98,6 +98,7 @@ emit_vertex_input(struct anv_pipeline *pipeline,
    const bool needs_svgs_elem = vs_prog_data->uses_vertexid ||
                                 vs_prog_data->uses_instanceid ||
                                 vs_prog_data->uses_basevertex ||
+                                vs_prog_data->uses_firstvertex ||
                                 vs_prog_data->uses_baseinstance;
 
    uint32_t elem_count = __builtin_popcount(elements) -
@@ -178,6 +179,7 @@ emit_vertex_input(struct anv_pipeline *pipeline,
        * well.  Just do all or nothing.
        */
       uint32_t base_ctrl = (vs_prog_data->uses_basevertex ||
+                            vs_prog_data->uses_firstvertex ||
                             vs_prog_data->uses_baseinstance) ?
                            VFCOMP_STORE_SRC : VFCOMP_STORE_0;