Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan dump resources: Multiple cbs from same qs #1911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions framework/decode/vulkan_replay_dump_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,10 @@ VkResult VulkanReplayDumpResourcesBase::QueueSubmit(const std::vector<VkSubmitIn

submitted = true;
}

// In case we are dumping multiple command buffers from the same submission
modified_submit_infos[s].waitSemaphoreCount = 0;
modified_submit_infos[s].signalSemaphoreCount = 0;
}
}

Expand All @@ -1922,9 +1926,10 @@ VkResult VulkanReplayDumpResourcesBase::QueueSubmit(const std::vector<VkSubmitIn
}
else
{
auto index_it = QueueSubmit_indices_.find(index);
assert(index_it != QueueSubmit_indices_.end());
QueueSubmit_indices_.erase(index_it);
QueueSubmit_indices_.erase(std::remove_if(QueueSubmit_indices_.begin(),
QueueSubmit_indices_.end(),
[index](uint64_t i) { return i == index; }),
QueueSubmit_indices_.end());

// Once all submissions are complete release resources
if (QueueSubmit_indices_.empty())
Expand Down Expand Up @@ -1994,26 +1999,14 @@ bool VulkanReplayDumpResourcesBase::UpdateRecordingStatus(VkCommandBuffer origin
{
assert(recording_);

const DrawCallsDumpingContext* dc_context = FindDrawCallCommandBufferContext(original_command_buffer);
if (dc_context != nullptr && dc_context->IsRecording())
{
return true;
}

const DispatchTraceRaysDumpingContext* dr_context = FindDispatchRaysCommandBufferContext(original_command_buffer);
if (dr_context != nullptr && dr_context->IsRecording())
{
return true;
}
recording_ = !QueueSubmit_indices_.empty();

recording_ = false;
return false;
return recording_;
}

bool VulkanReplayDumpResourcesBase::MustDumpQueueSubmitIndex(uint64_t index) const
{
// Indices should be sorted
return QueueSubmit_indices_.find(index) != QueueSubmit_indices_.end();
return std::find(QueueSubmit_indices_.begin(), QueueSubmit_indices_.end(), index) != QueueSubmit_indices_.end();
}

bool VulkanReplayDumpResourcesBase::IsRecording(VkCommandBuffer original_command_buffer) const
Expand Down
2 changes: 1 addition & 1 deletion framework/decode/vulkan_replay_dump_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class VulkanReplayDumpResourcesBase
// Mapping between the original VkCommandBuffer handle and BeginCommandBuffer index
std::unordered_map<VkCommandBuffer, uint64_t> cmd_buf_begin_map_;

std::unordered_set<uint64_t> QueueSubmit_indices_;
std::vector<uint64_t> QueueSubmit_indices_;

// One per BeginCommandBuffer index
std::unordered_map<uint64_t, DrawCallsDumpingContext> draw_call_contexts;
Expand Down
17 changes: 6 additions & 11 deletions framework/decode/vulkan_replay_dump_resources_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
bool dump_all_subresources,
bool dump_image_raw,
bool dump_separate_alpha,
VkImageLayout layout,
const VkExtent3D* extent_p)
VkImageLayout layout)
{
assert(image_info != nullptr);
assert(device_info != nullptr);
Expand All @@ -472,10 +471,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
*instance_table,
*phys_dev_info->replay_device_info->memory_properties);

const VkExtent3D extent{ (extent_p != nullptr) ? extent_p->width : image_info->extent.width,
(extent_p != nullptr) ? extent_p->height : image_info->extent.height,
(extent_p != nullptr) ? extent_p->depth : image_info->extent.depth };

const VkFormat dst_format = ChooseDestinationImageFormat(image_info->format);

uint32_t f = 0;
Expand All @@ -492,7 +487,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
image_info->handle,
image_info->format,
image_info->type,
extent,
image_info->extent,
image_info->level_count,
image_info->layer_count,
image_info->tiling,
Expand Down Expand Up @@ -651,13 +646,13 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
VkExtent3D scaled_extent;
if (scale != 1.0f && scaled)
{
scaled_extent.width = extent.width * scale;
scaled_extent.height = extent.height * scale;
scaled_extent.depth = extent.depth;
scaled_extent.width = image_info->extent.width * scale;
scaled_extent.height = image_info->extent.height * scale;
scaled_extent.depth = image_info->extent.depth;
}
else
{
scaled_extent = extent;
scaled_extent = image_info->extent;
}

scaled_extent.width = std::max(1u, scaled_extent.width >> mip);
Expand Down
3 changes: 1 addition & 2 deletions framework/decode/vulkan_replay_dump_resources_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
bool dump_all_subresources = false,
bool dump_image_raw = false,
bool dump_separate_alpha = false,
VkImageLayout layout = VK_IMAGE_LAYOUT_MAX_ENUM,
const VkExtent3D* extent_p = nullptr);
VkImageLayout layout = VK_IMAGE_LAYOUT_MAX_ENUM);

bool CheckDescriptorCompatibility(VkDescriptorType desc_type_a, VkDescriptorType desc_type_b);

Expand Down
13 changes: 6 additions & 7 deletions framework/decode/vulkan_replay_dump_resources_draw_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,10 @@ void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo(

auto& current_block = dump_json.GetCurrentSubEntry();
auto& drawcall_json_entries = !output_json_per_command ? current_block["drawCallCommands"] : current_block;
auto& draw_call_entry = !output_json_per_command ? drawcall_json_entries[cmd_buf_index] : drawcall_json_entries;

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 auto& dc_param_entry = draw_call_params.find(dc_index);
assert(dc_param_entry != draw_call_params.end());
Expand Down Expand Up @@ -1710,7 +1713,6 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments(
}
}

const VkExtent3D extent{ render_area[rp].extent.width, render_area[rp].extent.height, 1 };
std::vector<bool> scaling_supported(filenames.size());
VkResult res = DumpImageToFile(image_info,
device_info,
Expand All @@ -1724,8 +1726,7 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments(
dump_all_image_subresources,
dump_images_raw,
dump_images_separate_alpha,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
&extent);
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);

if (res != VK_SUCCESS)
{
Expand Down Expand Up @@ -1788,7 +1789,6 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments(
}
}

const VkExtent3D extent{ render_area[rp].extent.width, render_area[rp].extent.height, 1 };
std::vector<bool> scaling_supported(filenames.size());
VkResult res = DumpImageToFile(image_info,
device_info,
Expand All @@ -1802,8 +1802,7 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments(
dump_all_image_subresources,
dump_images_raw,
dump_images_separate_alpha,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
&extent);
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);

if (res != VK_SUCCESS)
{
Expand Down
2 changes: 1 addition & 1 deletion framework/decode/vulkan_replay_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct VulkanReplayOptions : public ReplayOptions
std::vector<std::vector<std::vector<uint64_t>>> RenderPass_Indices;
std::vector<std::vector<uint64_t>> Dispatch_Indices;
std::vector<std::vector<uint64_t>> TraceRays_Indices;
std::unordered_set<uint64_t> QueueSubmit_Indices;
std::vector<uint64_t> QueueSubmit_Indices;
std::string dump_resources;
util::ScreenshotFormat dump_resources_image_format{ util::ScreenshotFormat::kBmp };

Expand Down
15 changes: 12 additions & 3 deletions framework/graphics/vulkan_resources_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,17 +1383,26 @@ VkResult VulkanResourcesUtil::SubmitCommandBuffer(VkQueue queue)
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = nullptr;

VkResult result = device_table_.QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
VkFence fence;
const VkFenceCreateInfo ci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
VkResult result = device_table_.CreateFence(device_, &ci, nullptr, &fence);
if (result != VK_SUCCESS)
{
GFXRECON_LOG_ERROR("Failed to create fence (%s)", util::ToString(result).c_str());
return result;
}

result = device_table_.QueueSubmit(queue, 1, &submit_info, fence);
if (result != VK_SUCCESS)
{
GFXRECON_LOG_ERROR("Failed to submit command buffer for execution while taking a resource memory snapshot");
return result;
}

result = device_table_.QueueWaitIdle(queue);
result = device_table_.WaitForFences(device_, 1, &fence, VK_TRUE, ~0UL);
if (result != VK_SUCCESS)
{
GFXRECON_LOG_ERROR("QueueWaitIdle returned %d while taking a resource memory snapshot", result);
GFXRECON_LOG_ERROR("WaitForFences returned %d while taking a resource memory snapshot", result);
return result;
}

Expand Down
23 changes: 2 additions & 21 deletions tools/replay/parse_dump_resources_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,7 @@ bool parse_dump_resources_arg(gfxrecon::decode::VulkanReplayOptions& vulkan_repl
for (int idx0 = 0; idx0 < jargs["QueueSubmit"].size(); idx0++)
{
uint64_t qs = static_cast<uint64_t>(jargs["QueueSubmit"][idx0]);
if (vulkan_replay_options.QueueSubmit_Indices.find(qs) !=
vulkan_replay_options.QueueSubmit_Indices.end())
{
// QueueSubmit value can't be repeated
parse_error_message =
"Bad --dump-resources parameter: QueueSubmit value of " + std::to_string(qs) + " is repeated";
parse_error = true;
}
else
{
vulkan_replay_options.QueueSubmit_Indices.insert(static_cast<uint64_t>(jargs["QueueSubmit"][idx0]));
}
vulkan_replay_options.QueueSubmit_Indices.push_back(static_cast<uint64_t>(jargs["QueueSubmit"][idx0]));
}
}
catch (...)
Expand Down Expand Up @@ -485,15 +474,7 @@ bool parse_dump_resources_arg(gfxrecon::decode::VulkanReplayOptions& vulkan_repl
vulkan_replay_options.TraceRays_Indices[i].push_back(TraceRays);
}

auto [itr, inserted] = vulkan_replay_options.QueueSubmit_Indices.insert(QueueSubmit);
if (!inserted)
{
// QueueSubmit value can't be repeated
parse_error = true;
parse_error_message = "Bad --dump-resources parameter: QueueSubmit value of " +
std::to_string(QueueSubmit) + " is repeated";
break;
}
vulkan_replay_options.QueueSubmit_Indices.push_back(QueueSubmit);
}
}

Expand Down
Loading