From 958f56704c0d82472ba7268d98e31e79cf9f322d Mon Sep 17 00:00:00 2001 From: AWoloszyn Date: Tue, 5 Mar 2019 13:53:12 -0500 Subject: [PATCH] Add VK_KHR_draw_indirect_count extensions. This also adds VK_AMD_draw_indirect_count which is the same. --- .../api/vulkan/api/command_buffer_control.api | 106 ++++++------ gapis/api/vulkan/api/draw_commands.api | 2 +- .../vulkan/api/queued_command_tracking.api | 8 + gapis/api/vulkan/command_buffer_rebuilder.go | 120 ++++++++++++++ gapis/api/vulkan/draw_call_mesh.go | 8 + .../extensions/amd_draw_indirect_count.api | 121 ++++++++++++++ .../extensions/khr_draw_indirect_count.api | 153 ++++++++++++++++++ gapis/api/vulkan/vulkan.api | 21 ++- 8 files changed, 487 insertions(+), 52 deletions(-) create mode 100644 gapis/api/vulkan/extensions/amd_draw_indirect_count.api create mode 100644 gapis/api/vulkan/extensions/khr_draw_indirect_count.api diff --git a/gapis/api/vulkan/api/command_buffer_control.api b/gapis/api/vulkan/api/command_buffer_control.api index c8fd12bbc5..c7229be51a 100644 --- a/gapis/api/vulkan/api/command_buffer_control.api +++ b/gapis/api/vulkan/api/command_buffer_control.api @@ -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 } @@ -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 { @@ -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) { diff --git a/gapis/api/vulkan/api/draw_commands.api b/gapis/api/vulkan/api/draw_commands.api index d55d51303f..44333c07c5 100644 --- a/gapis/api/vulkan/api/draw_commands.api +++ b/gapis/api/vulkan/api/draw_commands.api @@ -271,7 +271,6 @@ cmd void vkCmdDrawIndexed( u32 Stride } -@spy_disabled sub void readIndirectDrawBuffer(VkBuffer buf, VkDeviceSize offset, u32 drawCount, u32 stride) { if !(buf in Buffers) { vkErrorInvalidBuffer(buf) @@ -279,6 +278,7 @@ sub void readIndirectDrawBuffer(VkBuffer buf, VkDeviceSize offset, u32 drawCount 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]) } } diff --git a/gapis/api/vulkan/api/queued_command_tracking.api b/gapis/api/vulkan/api/queued_command_tracking.api index e9b95d3271..4fe75708a0 100644 --- a/gapis/api/vulkan/api/queued_command_tracking.api +++ b/gapis/api/vulkan/api/queued_command_tracking.api @@ -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) } diff --git a/gapis/api/vulkan/command_buffer_rebuilder.go b/gapis/api/vulkan/command_buffer_rebuilder.go index f144a3bfbd..8bd20610e8 100644 --- a/gapis/api/vulkan/command_buffer_rebuilder.go +++ b/gapis/api/vulkan/command_buffer_rebuilder.go @@ -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 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 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 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 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, @@ -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) @@ -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) @@ -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) diff --git a/gapis/api/vulkan/draw_call_mesh.go b/gapis/api/vulkan/draw_call_mesh.go index a48ad68bf4..0182186bbc 100644 --- a/gapis/api/vulkan/draw_call_mesh.go +++ b/gapis/api/vulkan/draw_call_mesh.go @@ -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()) diff --git a/gapis/api/vulkan/extensions/amd_draw_indirect_count.api b/gapis/api/vulkan/extensions/amd_draw_indirect_count.api new file mode 100644 index 0000000000..4c490c3e1e --- /dev/null +++ b/gapis/api/vulkan/extensions/amd_draw_indirect_count.api @@ -0,0 +1,121 @@ +// Copyright (C) 2019 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/////////////// +// Constants // +/////////////// + +@extension("VK_AMD_draw_indirect_count") define VK_AMD_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +@extension("VK_AMD_draw_indirect_count") define VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_AMD_draw_indirect_count" + +@internal class vkCmdDrawIndirectCountAMDArgs { + VkBuffer Buffer + VkDeviceSize Offset + VkBuffer CountBuffer + VkDeviceSize CountBufferOffset + u32 MaxDrawCount + u32 Stride +} + +sub void dovkCmdDrawIndirectCountAMD(ref!vkCmdDrawIndirectCountAMDArgs draw) { + if draw.MaxDrawCount > 0 { + dovkCmdDrawIndirectCountCOMMON!ref!vkCmdDrawIndirectCountAMDArgs(draw) + lastDrawInfo().CommandParameters.DrawIndirectCountAMD = draw + } +} + +sub void dovkCmdDrawIndexedIndirectCountAMD(ref!vkCmdDrawIndexedIndirectCountAMDArgs draw) { + if draw.MaxDrawCount > 0 { + dovkCmdDrawIndexedIndirectCountCOMMON!ref!vkCmdDrawIndexedIndirectCountAMDArgs(draw) + lastDrawInfo().CommandParameters.DrawIndexedIndirectCountAMD = draw + } +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@executed_draw +@threadsafe +cmd void vkCmdDrawIndirectCountAMD( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countOffset, + u32 maxDrawCount, + u32 stride) { + if !(commandBuffer in CommandBuffers) { + vkErrorInvalidCommandBuffer(commandBuffer) + } else { + if !(buffer in Buffers) { vkErrorInvalidBuffer(buffer) } + if !(countBuffer in Buffers) { vkErrorInvalidBuffer(buffer) } + args := new!vkCmdDrawIndirectCountAMDArgs( + buffer, + offset, + countBuffer, + countOffset, + maxDrawCount, + stride) + + cmdBuf := CommandBuffers[commandBuffer] + + mapPos := as!u32(len(cmdBuf.BufferCommands.vkCmdDrawIndirectCountAMD)) + cmdBuf.BufferCommands.vkCmdDrawIndirectCountAMD[mapPos] = args + + AddCommand(commandBuffer, cmd_vkCmdDrawIndirectCountAMD, mapPos) + } +} + + +@internal class vkCmdDrawIndexedIndirectCountAMDArgs { + VkBuffer Buffer + VkDeviceSize Offset + VkBuffer CountBuffer + VkDeviceSize CountBufferOffset + u32 MaxDrawCount + u32 Stride +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@executed_draw +@threadsafe +cmd void vkCmdDrawIndexedIndirectCountAMD( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countOffset, + u32 maxDrawCount, + u32 stride) { + if !(commandBuffer in CommandBuffers) { + vkErrorInvalidCommandBuffer(commandBuffer) + } else { + if !(buffer in Buffers) { vkErrorInvalidBuffer(buffer) } + if !(countBuffer in Buffers) { vkErrorInvalidBuffer(buffer) } + args := new!vkCmdDrawIndexedIndirectCountAMDArgs( + buffer, + offset, + countBuffer, + countOffset, + maxDrawCount, + stride) + + cmdBuf := CommandBuffers[commandBuffer] + + mapPos := as!u32(len(cmdBuf.BufferCommands.vkCmdDrawIndexedIndirectCountAMD)) + cmdBuf.BufferCommands.vkCmdDrawIndexedIndirectCountAMD[mapPos] = args + + AddCommand(commandBuffer, cmd_vkCmdDrawIndexedIndirectCountAMD, mapPos) + } +} diff --git a/gapis/api/vulkan/extensions/khr_draw_indirect_count.api b/gapis/api/vulkan/extensions/khr_draw_indirect_count.api new file mode 100644 index 0000000000..0b24e3d3ee --- /dev/null +++ b/gapis/api/vulkan/extensions/khr_draw_indirect_count.api @@ -0,0 +1,153 @@ +// Copyright (C) 2019 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/////////////// +// Constants // +/////////////// + +@extension("VK_KHR_draw_indirect_count") define VK_KHR_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +@extension("VK_KHR_draw_indirect_count") define VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_KHR_draw_indirect_count" + +@internal class vkCmdDrawIndirectCountKHRArgs { + VkBuffer Buffer + VkDeviceSize Offset + VkBuffer CountBuffer + VkDeviceSize CountBufferOffset + u32 MaxDrawCount + u32 Stride +} + +sub void dovkCmdDrawIndirectCountCOMMON!T(T draw) { + useRenderPass() + if draw.MaxDrawCount > 0 { + readWriteMemoryInBoundGraphicsDescriptorSets() + readIndirectDrawBuffer(draw.Buffer, draw.Offset, draw.MaxDrawCount, draw.Stride) + readMemoryInBuffer(Buffers[draw.CountBuffer], draw.CountBufferOffset, 4) + readCoherentMemoryInBuffer(Buffers[draw.CountBuffer]) + // Read through all the vertex buffers, as we cannot assume the buffer given to indirect draw is host + readMemoryInCurrentPipelineBoundVertexBuffers(0xFFFFFFFF, 0xFFFFFFFF, 0, 0) + clearLastDrawInfoDrawCommandParameters() + } +} + +sub void dovkCmdDrawIndirectCountKHR(ref!vkCmdDrawIndirectCountKHRArgs draw) { + if draw.MaxDrawCount > 0 { + dovkCmdDrawIndirectCountCOMMON!ref!vkCmdDrawIndirectCountKHRArgs(draw) + lastDrawInfo().CommandParameters.DrawIndirectCountKHR = draw + } +} + +sub void dovkCmdDrawIndexedIndirectCountCOMMON!T(T draw) { + useRenderPass() + if draw.MaxDrawCount > 0 { + readWriteMemoryInBoundGraphicsDescriptorSets() + readIndirectDrawBuffer(draw.Buffer, draw.Offset, draw.MaxDrawCount, draw.Stride) + readMemoryInBuffer(Buffers[draw.CountBuffer], draw.CountBufferOffset, 4) + readCoherentMemoryInBuffer(Buffers[draw.CountBuffer]) + + readCoherentMemoryInBoundIndexBuffer() + indexBuffer := lastDrawInfo().BoundIndexBuffer.BoundBuffer.Buffer + readMemoryInBuffer(indexBuffer, 0, 0xFFFFFFFF) + + // Read through all the vertex buffers, as we cannot assume the buffer given to indirect draw is host + readMemoryInCurrentPipelineBoundVertexBuffers(0xFFFFFFFF, 0xFFFFFFFF, 0, 0) + clearLastDrawInfoDrawCommandParameters() + } +} + + +@internal class vkCmdDrawIndexedIndirectCountKHRArgs { + VkBuffer Buffer + VkDeviceSize Offset + VkBuffer CountBuffer + VkDeviceSize CountBufferOffset + u32 MaxDrawCount + u32 Stride +} + +sub void dovkCmdDrawIndexedIndirectCountKHR(ref!vkCmdDrawIndexedIndirectCountKHRArgs draw) { + if draw.MaxDrawCount > 0 { + dovkCmdDrawIndexedIndirectCountCOMMON!ref!vkCmdDrawIndexedIndirectCountKHRArgs(draw) + lastDrawInfo().CommandParameters.DrawIndexedIndirectCountKHR = draw + } +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@executed_draw +@threadsafe +cmd void vkCmdDrawIndirectCountKHR( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countOffset, + u32 maxDrawCount, + u32 stride) { + if !(commandBuffer in CommandBuffers) { + vkErrorInvalidCommandBuffer(commandBuffer) + } else { + if !(buffer in Buffers) { vkErrorInvalidBuffer(buffer) } + if !(countBuffer in Buffers) { vkErrorInvalidBuffer(buffer) } + args := new!vkCmdDrawIndirectCountKHRArgs( + buffer, + offset, + countBuffer, + countOffset, + maxDrawCount, + stride) + + cmdBuf := CommandBuffers[commandBuffer] + + mapPos := as!u32(len(cmdBuf.BufferCommands.vkCmdDrawIndirectCountKHR)) + cmdBuf.BufferCommands.vkCmdDrawIndirectCountKHR[mapPos] = args + + AddCommand(commandBuffer, cmd_vkCmdDrawIndirectCountKHR, mapPos) + } +} + + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@executed_draw +@threadsafe +cmd void vkCmdDrawIndexedIndirectCountKHR( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countOffset, + u32 maxDrawCount, + u32 stride) { + if !(commandBuffer in CommandBuffers) { + vkErrorInvalidCommandBuffer(commandBuffer) + } else { + if !(buffer in Buffers) { vkErrorInvalidBuffer(buffer) } + if !(countBuffer in Buffers) { vkErrorInvalidBuffer(buffer) } + args := new!vkCmdDrawIndexedIndirectCountKHRArgs( + buffer, + offset, + countBuffer, + countOffset, + maxDrawCount, + stride) + + cmdBuf := CommandBuffers[commandBuffer] + + mapPos := as!u32(len(cmdBuf.BufferCommands.vkCmdDrawIndexedIndirectCountKHR)) + cmdBuf.BufferCommands.vkCmdDrawIndexedIndirectCountKHR[mapPos] = args + + AddCommand(commandBuffer, cmd_vkCmdDrawIndexedIndirectCountKHR, mapPos) + } +} diff --git a/gapis/api/vulkan/vulkan.api b/gapis/api/vulkan/vulkan.api index 52d2c1311e..9a71ab248b 100644 --- a/gapis/api/vulkan/vulkan.api +++ b/gapis/api/vulkan/vulkan.api @@ -87,6 +87,8 @@ import "extensions/khr_external_memory_capabilities.api" import "extensions/khr_external_semaphore_capabilities.api" import "extensions/khr_variable_pointers.api" import "extensions/khr_sampler_ycbcr_conversion.api" +import "extensions/amd_draw_indirect_count.api" +import "extensions/khr_draw_indirect_count.api" import "android/vulkan_android.api" import "linux/vulkan_linux.api" @@ -227,6 +229,9 @@ sub ref!ExtensionSet supportedDeviceExtensions() { supported.ExtensionNames["VK_KHR_maintenance1"] = true supported.ExtensionNames["VK_KHR_maintenance2"] = true supported.ExtensionNames["VK_KHR_maintenance3"] = true + supported.ExtensionNames["VK_KHR_maintenance3"] = true + supported.ExtensionNames["VK_AMD_draw_indirect_count"] = true + supported.ExtensionNames["VK_KHR_draw_indirect_count"] = true return supported } @@ -237,10 +242,14 @@ sub ref!ExtensionSet supportedDeviceExtensions() { // This contains the draw command parameters. Only one of the draw data should be // valid at a time. Others should be null. @internal class DrawParameters { - ref!vkCmdDrawArgs Draw - ref!vkCmdDrawIndexedArgs DrawIndexed - ref!vkCmdDrawIndirectArgs DrawIndirect - ref!vkCmdDrawIndexedIndirectArgs DrawIndexedIndirect + ref!vkCmdDrawArgs Draw + ref!vkCmdDrawIndexedArgs DrawIndexed + ref!vkCmdDrawIndirectArgs DrawIndirect + ref!vkCmdDrawIndexedIndirectArgs DrawIndexedIndirect + ref!vkCmdDrawIndirectCountKHRArgs DrawIndirectCountKHR + ref!vkCmdDrawIndexedIndirectCountKHRArgs DrawIndexedIndirectCountKHR + ref!vkCmdDrawIndirectCountAMDArgs DrawIndirectCountAMD + ref!vkCmdDrawIndexedIndirectCountAMDArgs DrawIndexedIndirectCountAMD } // This contains the information about a draw @@ -407,6 +416,10 @@ sub void clearLastDrawInfoDrawCommandParameters() { lastDrawInfo().CommandParameters.DrawIndexed = null lastDrawInfo().CommandParameters.DrawIndirect = null lastDrawInfo().CommandParameters.DrawIndexedIndirect = null + lastDrawInfo().CommandParameters.DrawIndirectCountKHR = null + lastDrawInfo().CommandParameters.DrawIndexedIndirectCountKHR = null + lastDrawInfo().CommandParameters.DrawIndirectCountAMD = null + lastDrawInfo().CommandParameters.DrawIndexedIndirectCountAMD = null } sub ref!ComputeInfo lastComputeInfo() {