bug-14715: DrawIndirect fix
authorCourtney Goeltzenleuchter <courtney@LunarG.com>
Wed, 23 Sep 2015 18:31:50 +0000 (12:31 -0600)
committerCourtney Goeltzenleuchter <courtney@LunarG.com>
Thu, 24 Sep 2015 00:15:15 +0000 (18:15 -0600)
This patch contains fixes to structure layout for draws.
These structures are accessed by HW and must be in a specific order.
This change also includes reordering of the parameters for
vkCmdDraw and vkCmdDrawIndexed.

demos/cube.c
demos/tri.c
icd/nulldrv/nulldrv.c
include/vulkan.h
layers/draw_state.cpp
layers/param_checker.cpp
loader/trampoline.c
vulkan.py

index aba534881b7d1f9e13d3b73d2ee13f345c108ee3..35a28655ad3d5ae58d384cf58d45e049eac62591 100644 (file)
@@ -572,7 +572,7 @@ static void demo_draw_build_cmd(struct demo *demo, VkCmdBuffer cmd_buf)
     vkCmdSetStencilWriteMask(cmd_buf, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0xff);
     vkCmdSetStencilReference(cmd_buf, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0);
 
-    vkCmdDraw(cmd_buf, 0, 12 * 3, 0, 1);
+    vkCmdDraw(cmd_buf, 12 * 3, 1, 0, 0);
     vkCmdEndRenderPass(cmd_buf);
 
     err = vkEndCommandBuffer(cmd_buf);
index f64c82422d028b6f1e05fe0ac2ffeb324e5abf6b..f3749cbb5bf20eb678b674d6d7fc49aad11c5ce0 100644 (file)
@@ -418,7 +418,7 @@ static void demo_draw_build_cmd(struct demo *demo)
     VkDeviceSize offsets[1] = {0};
     vkCmdBindVertexBuffers(demo->draw_cmd, VERTEX_BUFFER_BIND_ID, 1, &demo->vertices.buf, offsets);
 
-    vkCmdDraw(demo->draw_cmd, 0, 3, 0, 1);
+    vkCmdDraw(demo->draw_cmd, 3, 1, 0, 0);
     vkCmdEndRenderPass(demo->draw_cmd);
 
     err = vkEndCommandBuffer(demo->draw_cmd);
index 828c42726d198e22b6112ba09a27cadf04dc5d71..5b71cfa9eddfa538b32590dbec5f814a8011b956 100644 (file)
@@ -1155,22 +1155,22 @@ ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
 }
 
 ICD_EXPORT void VKAPI vkCmdDraw(
-    VkCmdBuffer                              cmdBuffer,
-    uint32_t                                    firstVertex,
+    VkCmdBuffer                                 cmdBuffer,
     uint32_t                                    vertexCount,
-    uint32_t                                    firstInstance,
-    uint32_t                                    instanceCount)
+    uint32_t                                    instanceCount,
+    uint32_t                                    firstVertex,
+    uint32_t                                    firstInstance)
 {
     NULLDRV_LOG_FUNC;
 }
 
 ICD_EXPORT void VKAPI vkCmdDrawIndexed(
     VkCmdBuffer                              cmdBuffer,
-    uint32_t                                    firstIndex,
     uint32_t                                    indexCount,
+    uint32_t                                    instanceCount,
+    uint32_t                                    firstIndex,
     int32_t                                     vertexOffset,
-    uint32_t                                    firstInstance,
-    uint32_t                                    instanceCount)
+    uint32_t                                    firstInstance)
 {
     NULLDRV_LOG_FUNC;
 }
index 8be2b4f3194cce351cd5f37b5f1af5c07dbdd7bd..03bcefea50a69ab1f6394d87d73a97c66d09fd35 100644 (file)
@@ -2013,11 +2013,6 @@ typedef struct {
     uint32_t                                    stencil;
 } VkClearDepthStencilValue;
 
-typedef union {
-    VkClearColorValue                           color;
-    VkClearDepthStencilValue                    depthStencil;
-} VkClearValue;
-
 typedef struct {
     VkOffset3D                                  offset;
     VkExtent3D                                  extent;
@@ -2031,6 +2026,11 @@ typedef struct {
     VkExtent3D                                  extent;
 } VkImageResolve;
 
+typedef union {
+    VkClearColorValue                           color;
+    VkClearDepthStencilValue                    depthStencil;
+} VkClearValue;
+
 typedef struct {
     VkStructureType                             sType;
     const void*                                 pNext;
@@ -2060,18 +2060,18 @@ typedef struct {
 } VkDispatchIndirectCmd;
 
 typedef struct {
-    uint32_t                                    firstIndex;
     uint32_t                                    indexCount;
+    uint32_t                                    instanceCount;
+    uint32_t                                    firstIndex;
     int32_t                                     vertexOffset;
     uint32_t                                    firstInstance;
-    uint32_t                                    instanceCount;
 } VkDrawIndexedIndirectCmd;
 
 typedef struct {
-    uint32_t                                    firstVertex;
     uint32_t                                    vertexCount;
-    uint32_t                                    firstInstance;
     uint32_t                                    instanceCount;
+    uint32_t                                    firstVertex;
+    uint32_t                                    firstInstance;
 } VkDrawIndirectCmd;
 
 typedef struct {
@@ -2208,8 +2208,8 @@ typedef void (VKAPI *PFN_vkCmdSetStencilReference)(VkCmdBuffer cmdBuffer, VkSten
 typedef void (VKAPI *PFN_vkCmdBindDescriptorSets)(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets);
 typedef void (VKAPI *PFN_vkCmdBindIndexBuffer)(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
 typedef void (VKAPI *PFN_vkCmdBindVertexBuffers)(VkCmdBuffer cmdBuffer, uint32_t startBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets);
-typedef void (VKAPI *PFN_vkCmdDraw)(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount);
-typedef void (VKAPI *PFN_vkCmdDrawIndexed)(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount);
+typedef void (VKAPI *PFN_vkCmdDraw)(VkCmdBuffer cmdBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
+typedef void (VKAPI *PFN_vkCmdDrawIndexed)(VkCmdBuffer cmdBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
 typedef void (VKAPI *PFN_vkCmdDrawIndirect)(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride);
 typedef void (VKAPI *PFN_vkCmdDrawIndexedIndirect)(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride);
 typedef void (VKAPI *PFN_vkCmdDispatch)(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z);
@@ -2806,18 +2806,18 @@ void VKAPI vkCmdBindVertexBuffers(
 
 void VKAPI vkCmdDraw(
     VkCmdBuffer                                 cmdBuffer,
-    uint32_t                                    firstVertex,
     uint32_t                                    vertexCount,
-    uint32_t                                    firstInstance,
-    uint32_t                                    instanceCount);
+    uint32_t                                    instanceCount,
+    uint32_t                                    firstVertex,
+    uint32_t                                    firstInstance);
 
 void VKAPI vkCmdDrawIndexed(
     VkCmdBuffer                                 cmdBuffer,
-    uint32_t                                    firstIndex,
     uint32_t                                    indexCount,
+    uint32_t                                    instanceCount,
+    uint32_t                                    firstIndex,
     int32_t                                     vertexOffset,
-    uint32_t                                    firstInstance,
-    uint32_t                                    instanceCount);
+    uint32_t                                    firstInstance);
 
 void VKAPI vkCmdDrawIndirect(
     VkCmdBuffer                                 cmdBuffer,
index 10fa70cd91e66220fd9099a3252a9632bd38a93f..35f60357e9473716659c036e3d306768a2cfa630 100644 (file)
@@ -2325,7 +2325,7 @@ VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
         get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
 }
 
-VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
+VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
 {
     VkBool32 skipCall = VK_FALSE;
     GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
@@ -2352,10 +2352,10 @@ VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex
         }
     }
     if (VK_FALSE == skipCall)
-        get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
+        get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
 }
 
-VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
+VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
 {
     GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
     VkBool32 skipCall = VK_FALSE;
@@ -2376,7 +2376,7 @@ VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firs
         }
     }
     if (VK_FALSE == skipCall)
-        get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
+        get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
 }
 
 VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
index 2ffeefa6775ffeea35f24831a2c8c74523bef797..0b6909ddb915682ea4d7235d5af47102d5943fb9 100644 (file)
@@ -5688,12 +5688,12 @@ bool PostCmdDraw(
 
 VK_LAYER_EXPORT void VKAPI vkCmdDraw(
     VkCmdBuffer cmdBuffer,
-    uint32_t firstVertex,
     uint32_t vertexCount,
-    uint32_t firstInstance,
-    uint32_t instanceCount)
+    uint32_t instanceCount,
+    uint32_t firstVertex,
+    uint32_t firstInstance)
 {
-    get_dispatch_table(pc_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
+    get_dispatch_table(pc_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
 
     PostCmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
 }
@@ -5717,13 +5717,13 @@ bool PostCmdDrawIndexed(
 
 VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(
     VkCmdBuffer cmdBuffer,
-    uint32_t firstIndex,
     uint32_t indexCount,
+    uint32_t instanceCount,
+    uint32_t firstIndex,
     int32_t vertexOffset,
-    uint32_t firstInstance,
-    uint32_t instanceCount)
+    uint32_t firstInstance)
 {
-    get_dispatch_table(pc_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
+    get_dispatch_table(pc_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
 
     PostCmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
 }
index 5074f3b21ba9737594f933269765050c8de1b8d7..8ae81355bc0e6586ac36e2663914b26174aa6f7c 100644 (file)
@@ -1220,22 +1220,22 @@ LOADER_EXPORT void VKAPI vkCmdBindVertexBuffers(VkCmdBuffer cmdBuffer, uint32_t
     disp->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
 }
 
-LOADER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
+LOADER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
 {
     const VkLayerDispatchTable *disp;
 
     disp = loader_get_dispatch(cmdBuffer);
 
-    disp->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
+    disp->CmdDraw(cmdBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
 }
 
-LOADER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
+LOADER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
 {
     const VkLayerDispatchTable *disp;
 
     disp = loader_get_dispatch(cmdBuffer);
 
-    disp->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
+    disp->CmdDrawIndexed(cmdBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
 }
 
 LOADER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
index 880a1079bdfe82c9aa106598d659e6815ef97ce5..5323a6a523f6f7539951e1388585934e146e72c9 100755 (executable)
--- a/vulkan.py
+++ b/vulkan.py
@@ -708,18 +708,18 @@ core = Extension(
 
         Proto("void", "CmdDraw",
             [Param("VkCmdBuffer", "cmdBuffer"),
-             Param("uint32_t", "firstVertex"),
              Param("uint32_t", "vertexCount"),
-             Param("uint32_t", "firstInstance"),
-             Param("uint32_t", "instanceCount")]),
+             Param("uint32_t", "instanceCount"),
+             Param("uint32_t", "firstVertex"),
+             Param("uint32_t", "firstInstance")]),
 
         Proto("void", "CmdDrawIndexed",
             [Param("VkCmdBuffer", "cmdBuffer"),
-             Param("uint32_t", "firstIndex"),
              Param("uint32_t", "indexCount"),
+             Param("uint32_t", "instanceCount"),
+             Param("uint32_t", "firstIndex"),
              Param("int32_t", "vertexOffset"),
-             Param("uint32_t", "firstInstance"),
-             Param("uint32_t", "instanceCount")]),
+             Param("uint32_t", "firstInstance")]),
 
         Proto("void", "CmdDrawIndirect",
             [Param("VkCmdBuffer", "cmdBuffer"),