From 6084f1c1f74676d858f20a3725984f3e21d3ee09 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 19 Mar 2020 14:07:34 +0000 Subject: [PATCH] Improve fake structured data for indirect draws on vulkan --- renderdoc/driver/vulkan/vk_core.h | 4 ++-- .../driver/vulkan/wrappers/vk_draw_funcs.cpp | 22 +++++++++++++++---- .../driver/vulkan/wrappers/vk_queue_funcs.cpp | 21 +++++++++++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_core.h b/renderdoc/driver/vulkan/vk_core.h index 71f8f432b..5978702ea 100644 --- a/renderdoc/driver/vulkan/vk_core.h +++ b/renderdoc/driver/vulkan/vk_core.h @@ -863,8 +863,8 @@ private: void AddRequiredExtensions(bool instance, rdcarray &extensionList, const std::set &supportedExtensions); - bool PatchIndirectDraw(VkIndirectPatchType type, DrawcallDescription &draw, byte *&argptr, - byte *argend); + bool PatchIndirectDraw(size_t drawIndex, uint32_t paramStride, VkIndirectPatchType type, + DrawcallDescription &draw, byte *&argptr, byte *argend); void InsertDrawsAndRefreshIDs(BakedCmdBufferInfo &cmdBufInfo); rdcarray m_DrawcallStack; diff --git a/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp index d9c373790..8402fae53 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp @@ -632,7 +632,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirect(SerialiserType &ser, VkCommandBu StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndirectCommand()); } @@ -683,7 +686,6 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirect(SerialiserType &ser, VkCommandBu for(uint32_t i = 0; i < count; i++) { DrawcallDescription multi; - multi.drawIndex = i; multi.name = name; @@ -698,7 +700,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirect(SerialiserType &ser, VkCommandBu StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndirectCommand()); } @@ -1010,7 +1015,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirect(SerialiserType &ser, StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndexedIndirectCommand()); } @@ -1063,7 +1071,6 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirect(SerialiserType &ser, for(uint32_t i = 0; i < count; i++) { DrawcallDescription multi; - multi.drawIndex = i; multi.name = name; @@ -1079,7 +1086,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirect(SerialiserType &ser, StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndexedIndirectCommand()); } @@ -2837,7 +2847,6 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirectCount(SerialiserType &ser, for(uint32_t i = 0; i < maxDrawCount; i++) { DrawcallDescription multi; - multi.drawIndex = i; multi.name = name; @@ -2852,7 +2861,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirectCount(SerialiserType &ser, StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndirectCommand()); } @@ -3150,7 +3162,6 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirectCount( for(uint32_t i = 0; i < maxDrawCount; i++) { DrawcallDescription multi; - multi.drawIndex = i; multi.name = name; @@ -3166,7 +3177,10 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirectCount( StructuredSerialiser structuriser(fakeChunk, ser.GetChunkLookup()); structuriser.Serialise("drawIndex"_lit, 0U); + ResourceId bufid = GetResourceManager()->GetOriginalID(GetResID(buffer)); + structuriser.Serialise("buffer"_lit, bufid); structuriser.Serialise("offset"_lit, offset); + structuriser.Serialise("stride"_lit, stride); structuriser.Serialise("command"_lit, VkDrawIndexedIndirectCommand()); } diff --git a/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp index 0e8f7baf6..ab8264445 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp @@ -448,11 +448,14 @@ bool WrappedVulkan::Serialise_vkQueueSubmit(SerialiserType &ser, VkQueue queue, return true; } -bool WrappedVulkan::PatchIndirectDraw(VkIndirectPatchType type, DrawcallDescription &draw, +bool WrappedVulkan::PatchIndirectDraw(size_t drawIndex, uint32_t paramStride, + VkIndirectPatchType type, DrawcallDescription &draw, byte *&argptr, byte *argend) { bool valid = false; + draw.drawIndex = (uint32_t)drawIndex; + if(type == VkIndirectPatchType::DrawIndirect || type == VkIndirectPatchType::DrawIndirectCount) { if(argptr && argptr + sizeof(VkDrawIndirectCommand) <= argend) @@ -506,6 +509,16 @@ bool WrappedVulkan::PatchIndirectDraw(VkIndirectPatchType type, DrawcallDescript if(chunk->metadata.chunkID != (uint32_t)VulkanChunk::vkCmdIndirectSubCommand) chunk = m_StructuredFile->chunks[draw.events.back().chunkIndex - 1]; + SDObject *drawIdx = chunk->FindChild("drawIndex"); + + if(drawIdx) + drawIdx->data.basic.u = drawIndex; + + SDObject *offset = chunk->FindChild("offset"); + + if(offset) + offset->data.basic.u += drawIndex * paramStride; + SDObject *command = chunk->FindChild("command"); // single draw indirect draws don't have a command child since it can't be added without @@ -661,7 +674,8 @@ void WrappedVulkan::InsertDrawsAndRefreshIDs(BakedCmdBufferInfo &cmdBufInfo) // be in-lined as a single draw, so we patch in-place if(!hasCount && indirectCount == 1) { - bool valid = PatchIndirectDraw(n.indirectPatch.type, n.draw, ptr, end); + bool valid = + PatchIndirectDraw(0, n.indirectPatch.stride, n.indirectPatch.type, n.draw, ptr, end); if(n.indirectPatch.type == VkIndirectPatchType::DrawIndirectByteCount) { @@ -697,7 +711,8 @@ void WrappedVulkan::InsertDrawsAndRefreshIDs(BakedCmdBufferInfo &cmdBufInfo) { VulkanDrawcallTreeNode &n2 = cmdBufNodes[i + j + 1]; - bool valid = PatchIndirectDraw(n.indirectPatch.type, n2.draw, ptr, end); + bool valid = + PatchIndirectDraw(j, n.indirectPatch.stride, n.indirectPatch.type, n2.draw, ptr, end); if(valid) n2.draw.name = StringFormat::Fmt("%s[%zu](<%u, %u>)", n2.draw.name.c_str(), j,