From 7fbed521bb0fba037a6f4b0f7a8adad77cda0736 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 7 Jul 2015 15:11:56 -0700 Subject: [PATCH] vk/vulkan.h: Remove the explicit primitive restart index 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 | 1 - src/vulkan/device.c | 14 ++++++++++++++ src/vulkan/meta.c | 2 -- src/vulkan/pipeline.c | 9 ++++++--- src/vulkan/private.h | 3 +++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 7a11f96a9b3..4e2d8dfc7cc 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -1452,7 +1452,6 @@ typedef struct { VkPrimitiveTopology topology; bool32_t disableVertexReuse; bool32_t primitiveRestartEnable; - uint32_t primitiveRestartIndex; } VkPipelineIaStateCreateInfo; typedef struct { diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 60d6910577e..11b820dc2ce 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -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; } diff --git a/src/vulkan/meta.c b/src/vulkan/meta.c index b782279e7b9..6c1f57a6956 100644 --- a/src/vulkan/meta.c +++ b/src/vulkan/meta.c @@ -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 diff --git a/src/vulkan/pipeline.c b/src/vulkan/pipeline.c index 5003156e914..f0f578706e9 100644 --- a/src/vulkan/pipeline.c +++ b/src/vulkan/pipeline.c @@ -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); } diff --git a/src/vulkan/private.h b/src/vulkan/private.h index cb290ffea99..e0b18eaeddf 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -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]; -- 2.30.2