anv/pipeline: Add a per-VB instance divisor
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 2 Jul 2018 19:49:06 +0000 (12:49 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 9 Jul 2018 22:37:51 +0000 (15:37 -0700)
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c
src/intel/vulkan/genX_pipeline.c

index f0bf80a1cf072303b6054665b52591b056d0919c..e8489e72394464a50f634b92ae2ed260fe45ebcb 100644 (file)
@@ -1421,6 +1421,22 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
          pipeline->vb[desc->binding].instanced = true;
          break;
       }
+
+      pipeline->vb[desc->binding].instance_divisor = 1;
+   }
+
+
+   /* Our implementation of VK_KHR_multiview uses instancing to draw the
+    * different views.  If the client asks for instancing, we need to multiply
+    * the instance divisor by the number of views ensure that we repeat the
+    * client's per-instance data once for each view.
+    */
+   if (pipeline->subpass->view_mask) {
+      const uint32_t view_count = anv_subpass_view_count(pipeline->subpass);
+      for (uint32_t vb = 0; vb < MAX_VBS; vb++) {
+         if (pipeline->vb[vb].instanced)
+            pipeline->vb[vb].instance_divisor *= view_count;
+      }
    }
 
    const VkPipelineInputAssemblyStateCreateInfo *ia_info =
index ae763e4e2eb05b13ec78010de5607c2235dd14ee..cec2842792322991138e91be7504e4f77cfc085d 100644 (file)
@@ -2386,6 +2386,7 @@ struct anv_pipeline {
    struct anv_pipeline_vertex_binding {
       uint32_t                                  stride;
       bool                                      instanced;
+      uint32_t                                  instance_divisor;
    } vb[MAX_VBS];
 
    bool                                         primitive_restart;
index 7033e978144502d2d6b718ba2f7685a96b565a6c..b7ed817d3a08642fd8476e7899cf1393cbaa3213 100644 (file)
@@ -2518,12 +2518,7 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
             .MemoryObjectControlState = GENX(MOCS),
 #else
             .BufferAccessType = pipeline->vb[vb].instanced ? INSTANCEDATA : VERTEXDATA,
-            /* Our implementation of VK_KHR_multiview uses instancing to draw
-             * the different views.  If the client asks for instancing, we
-             * need to use the Instance Data Step Rate to ensure that we
-             * repeat the client's per-instance data once for each view.
-             */
-            .InstanceDataStepRate = anv_subpass_view_count(pipeline->subpass),
+            .InstanceDataStepRate = pipeline->vb[vb].instance_divisor,
             .VertexBufferMemoryObjectControlState = GENX(MOCS),
 #endif
 
index f4a455cce6762fd7b66073cd3c7e7e1f1eba76db..0821d71c9f8e8d2f1a24ea3b2b2f3f2843ab6713 100644 (file)
@@ -156,12 +156,8 @@ emit_vertex_input(struct anv_pipeline *pipeline,
       anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VF_INSTANCING), vfi) {
          vfi.InstancingEnable = pipeline->vb[desc->binding].instanced;
          vfi.VertexElementIndex = slot;
-         /* Our implementation of VK_KHR_multiview uses instancing to draw
-          * the different views.  If the client asks for instancing, we
-          * need to use the Instance Data Step Rate to ensure that we
-          * repeat the client's per-instance data once for each view.
-          */
-         vfi.InstanceDataStepRate = anv_subpass_view_count(pipeline->subpass);
+         vfi.InstanceDataStepRate =
+            pipeline->vb[desc->binding].instance_divisor;
       }
 #endif
    }