vk/vulkan.h: Remove the explicit primitive restart index
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 7 Jul 2015 22:11:56 +0000 (15:11 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 7 Jul 2015 22:33:00 +0000 (15:33 -0700)
Unfortunately, this requires some non-trivial changes to the driver.  Now
that the primitive restart index isn't given explicitly by the client, we
always use ~0 for everything like D3D does.  Unfortunately, our hardware is
awesome and a 32-bit version of ~0 doesn't match any 16-bit values.  This
means, we have to set it to either UINT16_MAX or UINT32_MAX depending on
the size of the index type.  Since we get the index type from
CmdBindIndexBuffer and the rest of the VF packet from the pipeline, we need
to lazy-emit the VF packet.

include/vulkan/vulkan.h
src/vulkan/device.c
src/vulkan/meta.c
src/vulkan/pipeline.c
src/vulkan/private.h

index 7a11f96a9b32f73d10de1c07004d21828e212575..4e2d8dfc7cc22ea01cc35bc8b0fe9ae16f12c245 100644 (file)
@@ -1452,7 +1452,6 @@ typedef struct {
     VkPrimitiveTopology                         topology;
     bool32_t                                    disableVertexReuse;
     bool32_t                                    primitiveRestartEnable;
-    uint32_t                                    primitiveRestartIndex;
 } VkPipelineIaStateCreateInfo;
 
 typedef struct {
index 60d6910577e3b3685eb0f46820b8ef3186b4b689..11b820dc2cebe7a495f41f1131be4cf11a2af579 100644 (file)
@@ -2227,6 +2227,7 @@ VkResult anv_CreateCommandBuffer(
    cmd_buffer->vp_state = NULL;
    cmd_buffer->cb_state = NULL;
    cmd_buffer->ds_state = NULL;
+   memset(&cmd_buffer->state_vf, 0, sizeof(cmd_buffer->state_vf));
    memset(&cmd_buffer->descriptors, 0, sizeof(cmd_buffer->descriptors));
 
    result = anv_batch_bo_create(device, &cmd_buffer->last_batch_bo);
@@ -2716,6 +2717,14 @@ void anv_CmdBindIndexBuffer(
       [VK_INDEX_TYPE_UINT32]                    = INDEX_DWORD,
    };
 
+   struct GEN8_3DSTATE_VF vf = {
+      GEN8_3DSTATE_VF_header,
+      .CutIndex = (indexType == VK_INDEX_TYPE_UINT16) ? UINT16_MAX : UINT32_MAX,
+   };
+   GEN8_3DSTATE_VF_pack(NULL, cmd_buffer->state_vf, &vf);
+
+   cmd_buffer->dirty |= ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY;
+
    anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_INDEX_BUFFER,
                   .IndexFormat = vk_to_gen_index_type[indexType],
                   .MemoryObjectControlState = GEN8_MOCS,
@@ -3181,6 +3190,11 @@ anv_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
                      .ColorCalcStatePointerValid = true);
    }
 
+   if (cmd_buffer->dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY | ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY)) {
+      anv_batch_emit_merge(&cmd_buffer->batch,
+                           cmd_buffer->state_vf, pipeline->state_vf);
+   }
+
    cmd_buffer->vb_dirty &= ~vb_emit;
    cmd_buffer->dirty = 0;
 }
index b782279e7b96cca5ac23161874b093ac54ee2237..6c1f57a6956dbf05ab871ed4fdda8b9879f73fdf 100644 (file)
@@ -38,7 +38,6 @@ anv_device_init_meta_clear_state(struct anv_device *device)
       .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
       .disableVertexReuse = false,
       .primitiveRestartEnable = false,
-      .primitiveRestartIndex = 0
    };
 
    /* We don't use a vertex shader for clearing, but instead build and pass
@@ -314,7 +313,6 @@ anv_device_init_meta_blit_state(struct anv_device *device)
       .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
       .disableVertexReuse = false,
       .primitiveRestartEnable = false,
-      .primitiveRestartIndex = 0
    };
 
    /* We don't use a vertex shader for clearing, but instead build and pass
index 5003156e914c53b20d0f37ef1c61b3b547f7474e..f0f578706e9bed38db6213618b45fdb2742ea81a 100644 (file)
@@ -146,9 +146,12 @@ emit_ia_state(struct anv_pipeline *pipeline,
    if (extra && extra->use_rectlist)
       topology = _3DPRIM_RECTLIST;
 
-   anv_batch_emit(&pipeline->batch, GEN8_3DSTATE_VF,
-                  .IndexedDrawCutIndexEnable = info->primitiveRestartEnable,
-                  .CutIndex = info->primitiveRestartIndex);
+   struct GEN8_3DSTATE_VF vf = {
+      GEN8_3DSTATE_VF_header,
+      .IndexedDrawCutIndexEnable = info->primitiveRestartEnable,
+   };
+   GEN8_3DSTATE_VF_pack(NULL, pipeline->state_vf, &vf);
+
    anv_batch_emit(&pipeline->batch, GEN8_3DSTATE_VF_TOPOLOGY,
                   .PrimitiveTopologyType = topology);
 }
index cb290ffea994b9c05a60b210854420e31005b423..e0b18eaeddf03cd156cb2a09291a23ff7245422f 100644 (file)
@@ -642,6 +642,7 @@ struct anv_buffer {
 #define ANV_CMD_BUFFER_DS_DIRTY                 (1 << 3)
 #define ANV_CMD_BUFFER_CB_DIRTY                 (1 << 4)
 #define ANV_CMD_BUFFER_VP_DIRTY                 (1 << 5)
+#define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY       (1 << 6)
 
 struct anv_vertex_binding {
    struct anv_buffer *                          buffer;
@@ -687,6 +688,7 @@ struct anv_cmd_buffer {
    struct anv_dynamic_ds_state *                ds_state;
    struct anv_dynamic_vp_state *                vp_state;
    struct anv_dynamic_cb_state *                cb_state;
+   uint32_t                                     state_vf[GEN8_3DSTATE_VF_length];
    struct anv_vertex_binding                    vertex_bindings[MAX_VBS];
    struct anv_descriptor_set_binding            descriptors[MAX_SETS];
 };
@@ -746,6 +748,7 @@ struct anv_pipeline {
    uint32_t                                     binding_stride[MAX_VBS];
 
    uint32_t                                     state_sf[GEN8_3DSTATE_SF_length];
+   uint32_t                                     state_vf[GEN8_3DSTATE_VF_length];
    uint32_t                                     state_raster[GEN8_3DSTATE_RASTER_length];
    uint32_t                                     state_wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];