Skip to content

Commit

Permalink
Add VK_KHR_draw_indirect_count extensions.
Browse files Browse the repository at this point in the history
This also adds VK_AMD_draw_indirect_count which is the same.
  • Loading branch information
AWoloszyn committed Mar 8, 2019
1 parent 3499be7 commit d4bf475
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 52 deletions.
106 changes: 59 additions & 47 deletions gapis/api/vulkan/api/command_buffer_control.api
Original file line number Diff line number Diff line change
Expand Up @@ -136,53 +136,57 @@ enum RecordingState {
}

enum CommandType {
cmd_vkCmdBindPipeline = 0,
cmd_vkCmdSetViewport = 1,
cmd_vkCmdSetScissor = 2,
cmd_vkCmdSetLineWidth = 3,
cmd_vkCmdSetDepthBias = 4,
cmd_vkCmdSetBlendConstants = 5,
cmd_vkCmdSetDepthBounds = 6,
cmd_vkCmdSetStencilCompareMask = 7,
cmd_vkCmdSetStencilWriteMask = 8,
cmd_vkCmdSetStencilReference = 9,
cmd_vkCmdBindDescriptorSets = 10,
cmd_vkCmdBindIndexBuffer = 11,
cmd_vkCmdBindVertexBuffers = 12,
cmd_vkCmdDraw = 13,
cmd_vkCmdDrawIndexed = 14,
cmd_vkCmdDrawIndirect = 15,
cmd_vkCmdDrawIndexedIndirect = 16,
cmd_vkCmdDispatch = 17,
cmd_vkCmdDispatchIndirect = 18,
cmd_vkCmdCopyBuffer = 19,
cmd_vkCmdCopyImage = 20,
cmd_vkCmdBlitImage = 21,
cmd_vkCmdCopyBufferToImage = 22,
cmd_vkCmdCopyImageToBuffer = 23,
cmd_vkCmdUpdateBuffer = 24,
cmd_vkCmdFillBuffer = 25,
cmd_vkCmdClearColorImage = 26,
cmd_vkCmdClearDepthStencilImage = 27,
cmd_vkCmdClearAttachments = 28,
cmd_vkCmdResolveImage = 29,
cmd_vkCmdSetEvent = 30,
cmd_vkCmdResetEvent = 31,
cmd_vkCmdWaitEvents = 32,
cmd_vkCmdPipelineBarrier = 33,
cmd_vkCmdBeginQuery = 34,
cmd_vkCmdEndQuery = 35,
cmd_vkCmdResetQueryPool = 36,
cmd_vkCmdWriteTimestamp = 37,
cmd_vkCmdCopyQueryPoolResults = 38,
cmd_vkCmdPushConstants = 39,
cmd_vkCmdBeginRenderPass = 40,
cmd_vkCmdNextSubpass = 41,
cmd_vkCmdEndRenderPass = 42,
cmd_vkCmdExecuteCommands = 43,
cmd_vkCmdDebugMarkerBeginEXT = 44,
cmd_vkCmdDebugMarkerEndEXT = 45,
cmd_vkCmdDebugMarkerInsertEXT = 46,
cmd_vkCmdBindPipeline = 0,
cmd_vkCmdSetViewport = 1,
cmd_vkCmdSetScissor = 2,
cmd_vkCmdSetLineWidth = 3,
cmd_vkCmdSetDepthBias = 4,
cmd_vkCmdSetBlendConstants = 5,
cmd_vkCmdSetDepthBounds = 6,
cmd_vkCmdSetStencilCompareMask = 7,
cmd_vkCmdSetStencilWriteMask = 8,
cmd_vkCmdSetStencilReference = 9,
cmd_vkCmdBindDescriptorSets = 10,
cmd_vkCmdBindIndexBuffer = 11,
cmd_vkCmdBindVertexBuffers = 12,
cmd_vkCmdDraw = 13,
cmd_vkCmdDrawIndexed = 14,
cmd_vkCmdDrawIndirect = 15,
cmd_vkCmdDrawIndexedIndirect = 16,
cmd_vkCmdDispatch = 17,
cmd_vkCmdDispatchIndirect = 18,
cmd_vkCmdCopyBuffer = 19,
cmd_vkCmdCopyImage = 20,
cmd_vkCmdBlitImage = 21,
cmd_vkCmdCopyBufferToImage = 22,
cmd_vkCmdCopyImageToBuffer = 23,
cmd_vkCmdUpdateBuffer = 24,
cmd_vkCmdFillBuffer = 25,
cmd_vkCmdClearColorImage = 26,
cmd_vkCmdClearDepthStencilImage = 27,
cmd_vkCmdClearAttachments = 28,
cmd_vkCmdResolveImage = 29,
cmd_vkCmdSetEvent = 30,
cmd_vkCmdResetEvent = 31,
cmd_vkCmdWaitEvents = 32,
cmd_vkCmdPipelineBarrier = 33,
cmd_vkCmdBeginQuery = 34,
cmd_vkCmdEndQuery = 35,
cmd_vkCmdResetQueryPool = 36,
cmd_vkCmdWriteTimestamp = 37,
cmd_vkCmdCopyQueryPoolResults = 38,
cmd_vkCmdPushConstants = 39,
cmd_vkCmdBeginRenderPass = 40,
cmd_vkCmdNextSubpass = 41,
cmd_vkCmdEndRenderPass = 42,
cmd_vkCmdExecuteCommands = 43,
cmd_vkCmdDebugMarkerBeginEXT = 44,
cmd_vkCmdDebugMarkerEndEXT = 45,
cmd_vkCmdDebugMarkerInsertEXT = 46,
cmd_vkCmdDrawIndirectCountKHR = 47,
cmd_vkCmdDrawIndexedIndirectCountKHR = 48,
cmd_vkCmdDrawIndirectCountAMD = 49,
cmd_vkCmdDrawIndexedIndirectCountAMD = 50,
cmd_vkNoCommand = 0xFFFFFFFF
}

Expand Down Expand Up @@ -257,6 +261,10 @@ enum SemaphoreUpdate {
@untrackedMap dense_map!(u32, ref!vkCmdDebugMarkerBeginEXTArgs) vkCmdDebugMarkerBeginEXT
@untrackedMap dense_map!(u32, ref!vkCmdDebugMarkerEndEXTArgs) vkCmdDebugMarkerEndEXT
@untrackedMap dense_map!(u32, ref!vkCmdDebugMarkerInsertEXTArgs) vkCmdDebugMarkerInsertEXT
@untrackedMap dense_map!(u32, ref!vkCmdDrawIndirectCountKHRArgs) vkCmdDrawIndirectCountKHR
@untrackedMap dense_map!(u32, ref!vkCmdDrawIndexedIndirectCountKHRArgs) vkCmdDrawIndexedIndirectCountKHR
@untrackedMap dense_map!(u32, ref!vkCmdDrawIndirectCountAMDArgs) vkCmdDrawIndirectCountAMD
@untrackedMap dense_map!(u32, ref!vkCmdDrawIndexedIndirectCountAMDArgs) vkCmdDrawIndexedIndirectCountAMD
}

@internal class CommandBufferObject {
Expand Down Expand Up @@ -505,6 +513,10 @@ sub void resetBufferCommands(ref!CommandBufferObject obj) {
clear(obj.BufferCommands.vkCmdDebugMarkerBeginEXT)
clear(obj.BufferCommands.vkCmdDebugMarkerEndEXT)
clear(obj.BufferCommands.vkCmdDebugMarkerInsertEXT)
clear(obj.BufferCommands.vkCmdDrawIndirectCountKHR)
clear(obj.BufferCommands.vkCmdDrawIndexedIndirectCountKHR)
clear(obj.BufferCommands.vkCmdDrawIndirectCountAMD)
clear(obj.BufferCommands.vkCmdDrawIndexedIndirectCountAMD)
}

sub void resetCommandBuffer(ref!CommandBufferObject obj) {
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/api/draw_commands.api
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ cmd void vkCmdDrawIndexed(
u32 Stride
}

@spy_disabled
sub void readIndirectDrawBuffer(VkBuffer buf, VkDeviceSize offset, u32 drawCount, u32 stride) {
if !(buf in Buffers) {
vkErrorInvalidBuffer(buf)
} else {
command_size := as!VkDeviceSize(16)
indirect_buffer_read_size := as!VkDeviceSize((drawCount - 1) * stride) + command_size
readMemoryInBuffer(Buffers[buf], offset, indirect_buffer_read_size)
readCoherentMemoryInBuffer(Buffers[buf])
}
}

Expand Down
8 changes: 8 additions & 0 deletions gapis/api/vulkan/api/queued_command_tracking.api
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ sub void callCommand(ref!CommandReference reference) {
dovkCmdDebugMarkerEndEXT(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDebugMarkerEndEXT[reference.MapIndex])
case cmd_vkCmdDebugMarkerInsertEXT:
dovkCmdDebugMarkerInsertEXT(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDebugMarkerInsertEXT[reference.MapIndex])
case cmd_vkCmdDrawIndirectCountKHR:
dovkCmdDrawIndirectCountKHR(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDrawIndirectCountKHR[reference.MapIndex])
case cmd_vkCmdDrawIndexedIndirectCountKHR:
dovkCmdDrawIndexedIndirectCountKHR(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDrawIndexedIndirectCountKHR[reference.MapIndex])
case cmd_vkCmdDrawIndirectCountAMD:
dovkCmdDrawIndirectCountAMD(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDrawIndirectCountAMD[reference.MapIndex])
case cmd_vkCmdDrawIndexedIndirectCountAMD:
dovkCmdDrawIndexedIndirectCountAMD(CommandBuffers[reference.Buffer].BufferCommands.vkCmdDrawIndexedIndirectCountAMD[reference.MapIndex])
default:
vkErrorInvalidCommandBuffer(reference.Buffer)
}
Expand Down
120 changes: 120 additions & 0 deletions gapis/api/vulkan/command_buffer_rebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,102 @@ func rebuildVkCmdDrawIndexedIndirect(
), nil
}

func rebuildVkCmdDrawIndirectCountKHR(
ctx context.Context,
cb CommandBuilder,
commandBuffer VkCommandBuffer,
r *api.GlobalState,
s *api.GlobalState,
d VkCmdDrawIndirectCountKHRArgsʳ) (func(), api.Cmd, error) {
if !GetState(s).Buffers().Contains(d.Buffer()) {
return nil, nil, fmt.Errorf("Cannot find Buffer %v", d.Buffer())
}
if !GetState(s).Buffers().Contains(d.CountBuffer()) {
return nil, nil, fmt.Errorf("Cannot find Count Buffer %v", d.Buffer())
}

return func() {}, cb.VkCmdDrawIndirectCountKHR(commandBuffer,
d.Buffer(),
d.Offset(),
d.CountBuffer(),
d.CountBufferOffset(),
d.MaxDrawCount(),
d.Stride(),
), nil
}

func rebuildVkCmdDrawIndexedIndirectCountKHR(
ctx context.Context,
cb CommandBuilder,
commandBuffer VkCommandBuffer,
r *api.GlobalState,
s *api.GlobalState,
d VkCmdDrawIndexedIndirectCountKHRArgsʳ) (func(), api.Cmd, error) {
if !GetState(s).Buffers().Contains(d.Buffer()) {
return nil, nil, fmt.Errorf("Cannot find Buffer %v", d.Buffer())
}
if !GetState(s).Buffers().Contains(d.CountBuffer()) {
return nil, nil, fmt.Errorf("Cannot find Count Buffer %v", d.Buffer())
}

return func() {}, cb.VkCmdDrawIndexedIndirectCountKHR(commandBuffer,
d.Buffer(),
d.Offset(),
d.CountBuffer(),
d.CountBufferOffset(),
d.MaxDrawCount(),
d.Stride(),
), nil
}

func rebuildVkCmdDrawIndirectCountAMD(
ctx context.Context,
cb CommandBuilder,
commandBuffer VkCommandBuffer,
r *api.GlobalState,
s *api.GlobalState,
d VkCmdDrawIndirectCountAMDArgsʳ) (func(), api.Cmd, error) {
if !GetState(s).Buffers().Contains(d.Buffer()) {
return nil, nil, fmt.Errorf("Cannot find Buffer %v", d.Buffer())
}
if !GetState(s).Buffers().Contains(d.CountBuffer()) {
return nil, nil, fmt.Errorf("Cannot find Count Buffer %v", d.Buffer())
}

return func() {}, cb.VkCmdDrawIndirectCountAMD(commandBuffer,
d.Buffer(),
d.Offset(),
d.CountBuffer(),
d.CountBufferOffset(),
d.MaxDrawCount(),
d.Stride(),
), nil
}

func rebuildVkCmdDrawIndexedIndirectCountAMD(
ctx context.Context,
cb CommandBuilder,
commandBuffer VkCommandBuffer,
r *api.GlobalState,
s *api.GlobalState,
d VkCmdDrawIndexedIndirectCountAMDArgsʳ) (func(), api.Cmd, error) {
if !GetState(s).Buffers().Contains(d.Buffer()) {
return nil, nil, fmt.Errorf("Cannot find Buffer %v", d.Buffer())
}
if !GetState(s).Buffers().Contains(d.CountBuffer()) {
return nil, nil, fmt.Errorf("Cannot find Count Buffer %v", d.Buffer())
}

return func() {}, cb.VkCmdDrawIndexedIndirectCountAMD(commandBuffer,
d.Buffer(),
d.Offset(),
d.CountBuffer(),
d.CountBufferOffset(),
d.MaxDrawCount(),
d.Stride(),
), nil
}

func rebuildVkCmdDrawIndirect(
ctx context.Context,
cb CommandBuilder,
Expand Down Expand Up @@ -1244,6 +1340,14 @@ func GetCommandArgs(ctx context.Context,
return cmds.VkCmdDebugMarkerEndEXT().Get(cr.MapIndex())
case CommandType_cmd_vkCmdDebugMarkerInsertEXT:
return cmds.VkCmdDebugMarkerInsertEXT().Get(cr.MapIndex())
case CommandType_cmd_vkCmdDrawIndirectCountKHR:
return cmds.VkCmdDrawIndirectCountKHR().Get(cr.MapIndex())
case CommandType_cmd_vkCmdDrawIndexedIndirectCountKHR:
return cmds.VkCmdDrawIndexedIndirectCountKHR().Get(cr.MapIndex())
case CommandType_cmd_vkCmdDrawIndirectCountAMD:
return cmds.VkCmdDrawIndirectCountAMD().Get(cr.MapIndex())
case CommandType_cmd_vkCmdDrawIndexedIndirectCountAMD:
return cmds.VkCmdDrawIndexedIndirectCountAMD().Get(cr.MapIndex())
default:
x := fmt.Sprintf("Should not reach here: %T", cr)
panic(x)
Expand Down Expand Up @@ -1349,6 +1453,14 @@ func GetCommandFunction(cr *CommandReference) interface{} {
return subDovkCmdDebugMarkerEndEXT
case CommandType_cmd_vkCmdDebugMarkerInsertEXT:
return subDovkCmdDebugMarkerInsertEXT
case CommandType_cmd_vkCmdDrawIndirectCountKHR:
return subDovkCmdDrawIndirectCountKHR
case CommandType_cmd_vkCmdDrawIndexedIndirectCountKHR:
return subDovkCmdDrawIndexedIndirectCountKHR
case CommandType_cmd_vkCmdDrawIndirectCountAMD:
return subDovkCmdDrawIndirectCountAMD
case CommandType_cmd_vkCmdDrawIndexedIndirectCountAMD:
return subDovkCmdDrawIndexedIndirectCountAMD
default:
x := fmt.Sprintf("Should not reach here: %T", cr)
panic(x)
Expand Down Expand Up @@ -1461,6 +1573,14 @@ func AddCommand(ctx context.Context,
return rebuildVkCmdDebugMarkerEndEXT(ctx, cb, commandBuffer, r, s, t)
case VkCmdDebugMarkerInsertEXTArgsʳ:
return rebuildVkCmdDebugMarkerInsertEXT(ctx, cb, commandBuffer, r, s, t)
case VkCmdDrawIndirectCountKHRArgsʳ:
return rebuildVkCmdDrawIndirectCountKHR(ctx, cb, commandBuffer, r, s, t)
case VkCmdDrawIndexedIndirectCountKHRArgsʳ:
return rebuildVkCmdDrawIndexedIndirectCountKHR(ctx, cb, commandBuffer, r, s, t)
case VkCmdDrawIndirectCountAMDArgsʳ:
return rebuildVkCmdDrawIndirectCountAMD(ctx, cb, commandBuffer, r, s, t)
case VkCmdDrawIndexedIndirectCountAMDArgsʳ:
return rebuildVkCmdDrawIndexedIndirectCountAMD(ctx, cb, commandBuffer, r, s, t)
default:
x := fmt.Sprintf("Should not reach here: %T", t)
panic(x)
Expand Down
8 changes: 8 additions & 0 deletions gapis/api/vulkan/draw_call_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func drawCallMesh(ctx context.Context, dc *VkQueueSubmit, p *path.Mesh, r *path.
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndirect not implemented")
} else if p := lastDrawInfo.CommandParameters().DrawIndexedIndirect(); !p.IsNil() {
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndexedIndirect not implemented")
} else if p := lastDrawInfo.CommandParameters().DrawIndirectCountKHR(); !p.IsNil() {
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndirectCountKHR not implemented")
} else if p := lastDrawInfo.CommandParameters().DrawIndexedIndirectCountKHR(); !p.IsNil() {
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndexedIndirectCountKHR not implemented")
} else if p := lastDrawInfo.CommandParameters().DrawIndirectCountAMD(); !p.IsNil() {
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndirectCountAMD not implemented")
} else if p := lastDrawInfo.CommandParameters().DrawIndexedIndirectCountAMD(); !p.IsNil() {
return nil, fmt.Errorf("Draw mesh for vkCmdDrawIndexedIndirectCountAMD not implemented")
}

guessSemantics(vb, p.Options.Hints())
Expand Down
Loading

0 comments on commit d4bf475

Please sign in to comment.