Skip to content

Commit

Permalink
VDR: Fix indexing error in output json files (#1958)
Browse files Browse the repository at this point in the history
  • Loading branch information
panos-lunarg authored Jan 15, 2025
1 parent dd4ba5c commit 6512f0b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ VkResult DispatchTraceRaysDumpingContext::DumpDispatchTraceRays(
}
}

GenerateOutputJsonDispatchInfo(qs_index, bcb_index, disp_index, i);
GenerateOutputJsonDispatchInfo(qs_index, bcb_index, disp_index);
}

for (size_t i = 0; i < trace_rays_indices.size(); ++i)
Expand All @@ -900,7 +900,7 @@ VkResult DispatchTraceRaysDumpingContext::DumpDispatchTraceRays(
}
}

GenerateOutputJsonTraceRaysIndex(qs_index, bcb_index, tr_index, i);
GenerateOutputJsonTraceRaysIndex(qs_index, bcb_index, tr_index);
}

// Clean up references to dumped descriptors in case this command buffer is submitted again
Expand Down Expand Up @@ -2058,8 +2058,7 @@ VkResult DispatchTraceRaysDumpingContext::FetchIndirectParams()

void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs_index,
uint64_t bcb_index,
uint64_t disp_index,
uint64_t cmd_index) const
uint64_t disp_index) const
{
if (dispatch_params.empty())
{
Expand All @@ -2080,7 +2079,10 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs

auto& current_block = dump_json.GetCurrentSubEntry();
auto& dispatch_json_entries = !output_json_per_command ? current_block["dispatchCommands"] : dump_json.GetData();
auto& dispatch_json_entry = !output_json_per_command ? dispatch_json_entries[cmd_index] : dump_json.GetData();

const uint32_t dispatch_json_entry_index = dump_json.FetchAndAddDispatchEntryIndex();
auto& dispatch_json_entry =
!output_json_per_command ? dispatch_json_entries[dispatch_json_entry_index] : dump_json.GetData();

const auto& disp_params = dispatch_params.find(disp_index);

Expand Down Expand Up @@ -2506,8 +2508,7 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs

void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t qs_index,
uint64_t bcb_index,
uint64_t tr_index,
uint64_t cmd_index) const
uint64_t tr_index) const
{
auto& current_block = dump_json.GetCurrentSubEntry();

Expand All @@ -2528,7 +2529,8 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t
}
const auto& tr_params = trace_rays_params.find(tr_index);

auto& tr_entry = !output_json_per_command ? tr_json_entries[cmd_index] : dump_json.GetData();
const uint32_t trace_rays_json_entry_index = dump_json.FetchAndAddTraceRaysEntryIndex();
auto& tr_entry = !output_json_per_command ? tr_json_entries[trace_rays_json_entry_index] : dump_json.GetData();

tr_entry["traceRaysIndex"] = tr_index;
tr_entry["beginCommandBufferIndex"] = bcb_index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,9 @@ class DispatchTraceRaysDumpingContext

VkResult DumpImmutableDescriptors(uint64_t qs_index, uint64_t bcb_index, uint64_t cmd_index, bool is_dispatch);

void GenerateOutputJsonDispatchInfo(uint64_t qs_index,
uint64_t bcb_index,
uint64_t disp_index,
uint64_t cmd_index) const;

void GenerateOutputJsonTraceRaysIndex(uint64_t qs_index,
uint64_t bcb_index,
uint64_t tr_index,
uint64_t cmd_index) const;
void GenerateOutputJsonDispatchInfo(uint64_t qs_index, uint64_t bcb_index, uint64_t disp_index) const;

void GenerateOutputJsonTraceRaysIndex(uint64_t qs_index, uint64_t bcb_index, uint64_t tr_index) const;

const VulkanCommandBufferInfo* original_command_buffer_info;
VkCommandBuffer DR_command_buffer;
Expand Down
6 changes: 3 additions & 3 deletions framework/decode/vulkan_replay_dump_resources_draw_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,9 @@ void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo(
auto& current_block = dump_json.GetCurrentSubEntry();
auto& drawcall_json_entries = !output_json_per_command ? current_block["drawCallCommands"] : current_block;

static uint64_t unique_json_entry = 0;
auto& draw_call_entry =
!output_json_per_command ? drawcall_json_entries[unique_json_entry++] : drawcall_json_entries;
const uint32_t draw_call_json_entry = dump_json.FetchAndAddDrawCallsEntryIndex();
auto& draw_call_entry =
!output_json_per_command ? drawcall_json_entries[draw_call_json_entry] : drawcall_json_entries;

const auto& dc_param_entry = draw_call_params.find(dc_index);
assert(dc_param_entry != draw_call_params.end());
Expand Down
8 changes: 7 additions & 1 deletion framework/decode/vulkan_replay_dump_resources_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)

VulkanReplayDumpResourcesJson::VulkanReplayDumpResourcesJson(const VulkanReplayOptions& options) :
file_(nullptr), current_entry(nullptr), first_block_(true)
file_(nullptr), current_entry(nullptr), first_block_(true), draw_calls_entry_index(0), dispatch_entry_index(0),
trace_rays_entry_index(0)
{
header_["vulkanVersion"] = std::to_string(VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE)) + "." +
std::to_string(VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE)) + "." +
Expand Down Expand Up @@ -126,6 +127,11 @@ nlohmann::ordered_json& VulkanReplayDumpResourcesJson::BlockStart()
{
json_data_.clear();
current_entry = nullptr;

draw_calls_entry_index = 0;
dispatch_entry_index = 0;
trace_rays_entry_index = 0;

return json_data_;
}

Expand Down
10 changes: 10 additions & 0 deletions framework/decode/vulkan_replay_dump_resources_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class VulkanReplayDumpResourcesJson
const VulkanBufferInfo* buffer_info,
const std::string& filename);

uint32_t FetchAndAddDrawCallsEntryIndex() { return draw_calls_entry_index++; }

uint32_t FetchAndAddDispatchEntryIndex() { return dispatch_entry_index++; }

uint32_t FetchAndAddTraceRaysEntryIndex() { return trace_rays_entry_index++; }

private:
bool InitializeFile(const std::string& filename);

Expand All @@ -84,6 +90,10 @@ class VulkanReplayDumpResourcesJson
nlohmann::ordered_json json_data_;
nlohmann::ordered_json* current_entry;
bool first_block_;

uint32_t draw_calls_entry_index;
uint32_t dispatch_entry_index;
uint32_t trace_rays_entry_index;
};

GFXRECON_END_NAMESPACE(gfxrecon)
Expand Down

0 comments on commit 6512f0b

Please sign in to comment.