From 3684d424fb78c0ab1d8de99cd885a109eea391fa Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Thu, 22 Aug 2024 13:20:07 +0300 Subject: [PATCH] Dump all subresources of render target images --- .../vulkan_replay_dump_resources_common.cpp | 2 - ...lay_dump_resources_compute_ray_tracing.cpp | 820 ++++++++++++------ ...eplay_dump_resources_compute_ray_tracing.h | 35 +- ...ulkan_replay_dump_resources_draw_calls.cpp | 615 ++++++++----- .../vulkan_replay_dump_resources_draw_calls.h | 29 +- .../vulkan_replay_dump_resources_json.cpp | 42 +- .../vulkan_replay_dump_resources_json.h | 19 +- 7 files changed, 1028 insertions(+), 534 deletions(-) diff --git a/framework/decode/vulkan_replay_dump_resources_common.cpp b/framework/decode/vulkan_replay_dump_resources_common.cpp index b38bb245f0..a1d322e88b 100644 --- a/framework/decode/vulkan_replay_dump_resources_common.cpp +++ b/framework/decode/vulkan_replay_dump_resources_common.cpp @@ -546,7 +546,6 @@ VkResult DumpImageToFile(const ImageInfo* image_info, const uint32_t texel_size = vkuFormatElementSizeWithAspect(image_info->format, aspects[i]); const uint32_t stride = texel_size * scaled_extent.width; - filename += ImageFileExtension(image_info->format, image_file_format); if (output_image_format == util::imagewriter::DataFormats::kFormat_ASTC) { VKU_FORMAT_INFO format_info = vkuGetFormatInfo(image_info->format); @@ -628,7 +627,6 @@ VkResult DumpImageToFile(const ImageInfo* image_info, const uint32_t texel_size = vkuFormatElementSizeWithAspect(image_info->format, aspect); const uint32_t stride = texel_size * scaled_extent.width; - filename += ImageFileExtension(image_info->format, image_file_format); if (output_image_format == util::imagewriter::DataFormats::kFormat_ASTC) { VKU_FORMAT_INFO format_info = vkuGetFormatInfo(image_info->format); diff --git a/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.cpp b/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.cpp index 3692da7a3f..62ecaa6645 100644 --- a/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.cpp +++ b/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.cpp @@ -918,79 +918,60 @@ VkResult DispatchTraceRaysDumpingContext::DumpDispatchTraceRays( return VK_SUCCESS; } -std::vector -DispatchTraceRaysDumpingContext::GenerateDispatchTraceRaysImageFilename(VkFormat format, - uint32_t levels, - uint32_t layers, - bool is_dispatch, - uint64_t qs_index, - uint64_t bcb_index, - uint64_t cmd_index, - uint32_t desc_set, - uint32_t desc_binding, - uint32_t array_index, - VkShaderStageFlagBits stage, - bool before_cmd, - bool dump_all_subresources) const +std::string DispatchTraceRaysDumpingContext::GenerateDispatchTraceRaysImageFilename(VkFormat format, + uint32_t mip, + uint32_t layer, + VkImageAspectFlagBits aspect, + bool is_dispatch, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t cmd_index, + uint32_t desc_set, + uint32_t desc_binding, + uint32_t array_index, + VkShaderStageFlagBits stage, + bool before_cmd) const { const util::imagewriter::DataFormats output_image_format = VkFormatToImageWriterDataFormat(format); + const std::string shader_stage_name = ShaderStageToStr(stage); + const std::string aspect_str = ImageAspectToStr(aspect); - const std::string shader_stage_name = ShaderStageToStr(stage); - std::vector aspects; - graphics::GetFormatAspects(format, &aspects); - - const uint32_t total_files = dump_all_subresources ? (levels * layers * aspects.size()) : (aspects.size()); - - std::vector filenames(total_files); + std::stringstream filename; + filename << capture_filename << '_'; - uint32_t f = 0; - for (size_t a = 0; a < aspects.size(); ++a) + if (before_cmd) { - std::string aspect_str = ImageAspectToStr(aspects[a]); - std::stringstream filename; - - filename << capture_filename << '_'; - - if (before_cmd) + filename << (is_dispatch ? "dispatch_" : "traceRays_") << cmd_index << "_qs_" << qs_index << "_bcb_" + << bcb_index << "_before_stage_" << shader_stage_name << "_set_" << desc_set << "_binding_" + << desc_binding << "_index_" << array_index; + if (output_image_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) { - filename << (is_dispatch ? "dispatch_" : "traceRays_") << cmd_index << "_qs_" << qs_index << "_bcb_" - << bcb_index << "_before_stage_" << shader_stage_name << "_set_" << desc_set << "_binding_" - << desc_binding << "_index_" << array_index; - if (output_image_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) - { - filename << "_" << util::ToString(format).c_str(); - } - filename << "_aspect_" << aspect_str; + filename << "_" << util::ToString(format).c_str(); } - else - { - filename << (is_dispatch ? "dispatch_" : "traceRays_") << cmd_index << "_qs_" << qs_index << "_bcb_" - << bcb_index << "_" << (dump_resources_before ? "after_" : "") << "stage_" << shader_stage_name - << "_set_" << desc_set << "_binding_" << desc_binding << "_index_" << array_index; - if (output_image_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) - { - filename << "_" << util::ToString(format).c_str(); - } - filename << "_aspect_" << aspect_str; - } - - if (dump_all_subresources) + filename << "_aspect_" << aspect_str; + } + else + { + filename << (is_dispatch ? "dispatch_" : "traceRays_") << cmd_index << "_qs_" << qs_index << "_bcb_" + << bcb_index << "_" << (dump_resources_before ? "after_" : "") << "stage_" << shader_stage_name + << "_set_" << desc_set << "_binding_" << desc_binding << "_index_" << array_index; + if (output_image_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) { - for (uint32_t level = 0; level < levels; ++level) - { - for (uint32_t layer = 0; layer < layers; ++layer) - { - filename << "_mip_" << level << "_layer_" << layer; - } - } + filename << "_" << util::ToString(format).c_str(); } + filename << "_aspect_" << aspect_str; + } - std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(filename.str()); - filenames[f++] = (filedirname / filebasename).string(); + if (dump_all_image_subresources) + { + filename << "_mip_" << mip << "_layer_" << layer; } - return filenames; + filename << ImageFileExtension(format, image_file_format); + + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(filename.str()); + return (filedirname / filebasename).string(); } std::string DispatchTraceRaysDumpingContext::GenerateDispatchTraceRaysBufferFilename(bool is_dispatch, @@ -1089,19 +1070,54 @@ VkResult DispatchTraceRaysDumpingContext::DumpMutableResources(uint64_t bcb_inde const uint32_t array_index = mutable_resources_clones_before.images[i].array_index; const VkShaderStageFlagBits stage = mutable_resources_clones_before.images[i].stage; - std::vector filenames = GenerateDispatchTraceRaysImageFilename(modified_image_info.format, - modified_image_info.level_count, - modified_image_info.layer_count, - is_dispatch, - qs_index, - bcb_index, - cmd_index, - desc_set, - binding, - array_index, - stage, - true, - dump_all_image_subresources); + std::vector aspects; + graphics::GetFormatAspects(modified_image_info.format, &aspects); + + const size_t total_files = + dump_all_image_subresources + ? (aspects.size() * modified_image_info.layer_count * modified_image_info.level_count) + : aspects.size(); + + std::vector filenames(total_files); + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < modified_image_info.level_count; ++mip) + { + for (uint32_t layer = 0; layer < modified_image_info.layer_count; ++layer) + { + filenames[f++] = GenerateDispatchTraceRaysImageFilename(modified_image_info.format, + mip, + layer, + aspect, + is_dispatch, + qs_index, + bcb_index, + cmd_index, + desc_set, + binding, + array_index, + stage, + true); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } std::vector scaling_supported(filenames.size()); VkResult res = DumpImageToFile(&modified_image_info, @@ -1175,19 +1191,54 @@ VkResult DispatchTraceRaysDumpingContext::DumpMutableResources(uint64_t bcb_inde const uint32_t array_index = mutable_resources_clones.images[i].array_index; const VkShaderStageFlagBits stage = mutable_resources_clones.images[i].stage; - std::vector filenames = GenerateDispatchTraceRaysImageFilename(modified_image_info.format, - modified_image_info.level_count, - modified_image_info.layer_count, - is_dispatch, - qs_index, - bcb_index, - cmd_index, - desc_set, - binding, - array_index, - stage, - false, - dump_all_image_subresources); + std::vector aspects; + graphics::GetFormatAspects(modified_image_info.format, &aspects); + + const size_t total_files = + dump_all_image_subresources + ? (aspects.size() * modified_image_info.layer_count * modified_image_info.level_count) + : aspects.size(); + + std::vector filenames(total_files); + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < modified_image_info.level_count; ++mip) + { + for (uint32_t layer = 0; layer < modified_image_info.layer_count; ++layer) + { + filenames[f++] = GenerateDispatchTraceRaysImageFilename(modified_image_info.format, + mip, + layer, + aspect, + is_dispatch, + qs_index, + bcb_index, + cmd_index, + desc_set, + binding, + array_index, + stage, + false); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } std::vector scaling_supported(filenames.size()); VkResult res = DumpImageToFile(&modified_image_info, @@ -1351,63 +1402,47 @@ void DispatchTraceRaysDumpingContext::SnapshotBoundDescriptors(TraceRaysParamete } } -std::vector DispatchTraceRaysDumpingContext::GenerateImageDescriptorFilename( - uint64_t qs_index, uint64_t bcb_index, const ImageInfo* img_info) const +std::string DispatchTraceRaysDumpingContext::GenerateImageDescriptorFilename(VkFormat format, + uint32_t mip, + uint32_t layer, + format::HandleId image_id, + VkImageAspectFlagBits aspect, + uint64_t qs_index, + uint64_t bcb_index) const { - assert(img_info != nullptr); - - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); + std::string aspect_str = ImageAspectToStr(aspect); + std::stringstream base_filename; - const uint32_t total_files = - dump_all_image_subresources ? (aspects.size() * img_info->level_count * img_info->layer_count) : aspects.size(); - std::vector filenames(total_files); + base_filename << capture_filename << '_'; - uint32_t f = 0; - for (size_t i = 0; i < aspects.size(); ++i) + if (VkFormatToImageWriterDataFormat(format) != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) { - std::string aspect_str = ImageAspectToStr(aspects[i]); - std::stringstream base_filename; - - base_filename << capture_filename << '_'; - - if (VkFormatToImageWriterDataFormat(img_info->format) != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) - { - base_filename << "image_" << img_info->capture_id << "_qs_" << qs_index << "_bcb_" << bcb_index - << "_aspect_" << aspect_str; - } - else - { - std::string format_name = FormatToStr(img_info->format); - base_filename << "image_" << img_info->capture_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_" - << format_name << "_aspect_" << aspect_str; - } - - if (dump_all_image_subresources && (img_info->level_count > 1 || img_info->layer_count > 1)) - { - for (uint32_t level = 0; level < img_info->level_count; ++level) - { - for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) - { - std::stringstream sub_resources_str; - sub_resources_str << base_filename.str() << "_mip_" << level << "_layer_" << layer; - std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(sub_resources_str.str()); - filenames[f++] = (filedirname / filebasename).string(); - } - } - } - else - { - std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(base_filename.str()); - filenames[f++] = (filedirname / filebasename).string(); - } + base_filename << "image_" << image_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_aspect_" << aspect_str; + } + else + { + std::string format_name = FormatToStr(format); + base_filename << "image_" << image_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_" << format_name + << "_aspect_" << aspect_str; } - assert(f == total_files); + if (dump_all_image_subresources) + { - return std::move(filenames); + std::stringstream sub_resources_str; + sub_resources_str << base_filename.str() << "_mip_" << mip << "_layer_" << layer; + sub_resources_str << ImageFileExtension(format, image_file_format); + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(sub_resources_str.str()); + return (filedirname / filebasename).string(); + } + else + { + base_filename << ImageFileExtension(format, image_file_format); + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(base_filename.str()); + return (filedirname / filebasename).string(); + } } std::string DispatchTraceRaysDumpingContext::GenerateBufferDescriptorFilename(uint64_t qs_index, @@ -1652,7 +1687,43 @@ VkResult DispatchTraceRaysDumpingContext::DumpImmutableDescriptors(uint64_t qs_i for (const auto& img_info : image_descriptors) { - const std::vector filenames = GenerateImageDescriptorFilename(qs_index, bcb_index, img_info); + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + const size_t total_files = dump_all_image_subresources + ? (aspects.size() * img_info->layer_count * img_info->level_count) + : aspects.size(); + + std::vector filenames(total_files); + + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + filenames[f++] = GenerateImageDescriptorFilename( + img_info->format, mip, layer, img_info->capture_id, aspect, qs_index, bcb_index); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } std::vector scaling_supported(filenames.size()); VkResult res = DumpImageToFile(img_info, @@ -2065,24 +2136,6 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs const ImageInfo* img_info = image.original_image; assert(img_info != nullptr); - std::vector filenames = - GenerateDispatchTraceRaysImageFilename(img_info->format, - img_info->level_count, - img_info->layer_count, - true, - qs_index, - bcb_index, - disp_index, - desc_set, - binding, - array_index, - stage, - true, - dump_all_image_subresources); - - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); - auto& image_json_entry = before_command_output_image_entries[output_image_index++]; image_json_entry["type"] = util::ToString(image.desc_type); image_json_entry["set"] = desc_set; @@ -2090,12 +2143,62 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs image_json_entry["arrayIndex"] = array_index; auto& image_json_entry_desc = image_json_entry["images"]; - for (size_t f = 0; f < filenames.size(); ++f) + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - filenames[f] += ImageFileExtension(img_info->format, image_file_format); - dump_json.InsertImageInfo( - image_json_entry_desc[f], img_info, { filenames[f] }, aspects[f], scaling_failed); + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateDispatchTraceRaysImageFilename(img_info->format, + mip, + layer, + aspect, + true, + qs_index, + bcb_index, + disp_index, + desc_set, + binding, + array_index, + stage, + true); + + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + dump_json.InsertImageInfo(image_json_entry_desc[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } } } } @@ -2143,23 +2246,6 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs const ImageInfo* img_info = image.original_image; assert(img_info != nullptr); - std::vector filenames = GenerateDispatchTraceRaysImageFilename(img_info->format, - img_info->level_count, - img_info->layer_count, - true, - qs_index, - bcb_index, - disp_index, - desc_set, - binding, - array_index, - stage, - false, - dump_all_image_subresources); - - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); - auto& image_json_entry = image_outputs_json_entries[mutable_images_count++]; image_json_entry["type"] = util::ToString(image.desc_type); image_json_entry["set"] = desc_set; @@ -2167,13 +2253,62 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs image_json_entry["arrayIndex"] = array_index; auto& image_json_entry_desc = image_json_entry["images"]; - for (size_t f = 0; f < filenames.size(); ++f) + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - const std::vector full_filename{ filenames[f] + - ImageFileExtension(img_info->format, image_file_format) }; - dump_json.InsertImageInfo( - image_json_entry_desc[f], img_info, full_filename, aspects[f], scaling_failed); + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateDispatchTraceRaysImageFilename(img_info->format, + mip, + layer, + aspect, + true, + qs_index, + bcb_index, + disp_index, + desc_set, + binding, + array_index, + stage, + false); + + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + dump_json.InsertImageInfo(image_json_entry_desc[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } } } } @@ -2223,36 +2358,72 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonDispatchInfo(uint64_t qs { for (size_t i = 0; i < desc_binding.second.image_info.size(); ++i) { - if (desc_binding.second.image_info[i].image_view_info != nullptr) + if (desc_binding.second.image_info[i].image_view_info == nullptr) { - auto& entry = dispatch_json_entry["descriptors"][descriptor_entries_count++]; + continue; + } - entry["type"] = util::ToString(desc_binding.second.desc_type); - entry["set"] = desc_set_index; - entry["binding"] = desc_binding_index; - entry["arrayIndex"] = i; + auto& entry = dispatch_json_entry["descriptors"][descriptor_entries_count++]; - const ImageInfo* img_info = object_info_table.GetImageInfo( - desc_binding.second.image_info[i].image_view_info->image_id); - assert(img_info); + entry["type"] = util::ToString(desc_binding.second.desc_type); + entry["set"] = desc_set_index; + entry["binding"] = desc_binding_index; + entry["arrayIndex"] = i; - std::vector filenames = GenerateImageDescriptorFilename(qs_index, bcb_index, img_info); + const ImageInfo* img_info = object_info_table.GetImageInfo( + desc_binding.second.image_info[i].image_view_info->image_id); + assert(img_info); - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } - for (size_t f = 0; f < filenames.size(); ++f) + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) { - auto& image_descriptor_json_entry = entry["descriptor"]; - const bool scaling_failed = ImageFailedScaling(filenames[f]); - const std::vector full_filename{ - filenames[f] + ImageFileExtension(img_info->format, image_file_format) - }; - dump_json.InsertImageInfo(image_descriptor_json_entry, - img_info, - full_filename, - aspects[f], - scaling_failed); + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateImageDescriptorFilename(img_info->format, + mip, + layer, + img_info->capture_id, + aspect, + qs_index, + bcb_index); + + auto& image_descriptor_json_entry = entry["descriptor"]; + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + dump_json.InsertImageInfo(image_descriptor_json_entry[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } } } } @@ -2416,21 +2587,6 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t const ImageInfo* img_info = image.original_image; assert(img_info != nullptr); - std::vector filenames = - GenerateDispatchTraceRaysImageFilename(img_info->format, - img_info->level_count, - img_info->layer_count, - false, - qs_index, - bcb_index, - tr_index, - desc_set, - binding, - array_index, - stage, - true, - dump_all_image_subresources); - std::vector aspects; graphics::GetFormatAspects(img_info->format, &aspects); @@ -2441,12 +2597,59 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t image_json_entry["arrayIndex"] = array_index; auto& image_json_entry_desc = image_json_entry["images"]; - for (size_t f = 0; f < filenames.size(); ++f) + size_t f = 0; + for (auto aspect : aspects) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - filenames[f] += ImageFileExtension(img_info->format, image_file_format); - dump_json.InsertImageInfo( - image_json_entry_desc[f], img_info, { filenames[f] }, aspects[f], scaling_failed); + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateDispatchTraceRaysImageFilename(img_info->format, + mip, + layer, + aspect, + false, + qs_index, + bcb_index, + tr_index, + desc_set, + binding, + array_index, + stage, + true); + + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + dump_json.InsertImageInfo(image_json_entry_desc[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } } } } @@ -2493,23 +2696,6 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t const ImageInfo* img_info = image.original_image; assert(img_info != nullptr); - std::vector filenames = GenerateDispatchTraceRaysImageFilename(img_info->format, - img_info->level_count, - img_info->layer_count, - false, - qs_index, - bcb_index, - tr_index, - desc_set, - binding, - array_index, - stage, - false, - dump_all_image_subresources); - - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); - auto& image_json_entry = outputs_json_entries_after["images"][mutable_images_count++]; image_json_entry["type"] = util::ToString(image.desc_type); image_json_entry["set"] = desc_set; @@ -2517,13 +2703,62 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t image_json_entry["arrayIndex"] = array_index; auto& image_json_entry_desc = image_json_entry["image"]; - for (size_t f = 0; f < filenames.size(); ++f) + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - const std::vector full_filename{ filenames[f] + - ImageFileExtension(img_info->format, image_file_format) }; - dump_json.InsertImageInfo( - image_json_entry_desc[f], img_info, full_filename, aspects[f], scaling_failed); + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateDispatchTraceRaysImageFilename(img_info->format, + mip, + layer, + aspect, + false, + qs_index, + bcb_index, + tr_index, + desc_set, + binding, + array_index, + stage, + false); + + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + dump_json.InsertImageInfo(image_json_entry_desc[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } } } } @@ -2575,36 +2810,73 @@ void DispatchTraceRaysDumpingContext::GenerateOutputJsonTraceRaysIndex(uint64_t { for (size_t img = 0; img < desc_binding.second.image_info.size(); ++img) { - if (desc_binding.second.image_info[img].image_view_info != nullptr) + if (desc_binding.second.image_info[img].image_view_info == nullptr) { - auto& entry = tr_entry["descriptors"][shader_stage_name][stage_entry_index++]; + continue; + } - const ImageInfo* img_info = object_info_table.GetImageInfo( - desc_binding.second.image_info[img].image_view_info->image_id); - assert(img_info); + auto& entry = tr_entry["descriptors"][shader_stage_name][stage_entry_index++]; - entry["type"] = util::ToString(desc_binding.second.desc_type); - entry["set"] = desc_set_index; - entry["binding"] = desc_binding_index; - entry["arrayIndex"] = img; + const ImageInfo* img_info = object_info_table.GetImageInfo( + desc_binding.second.image_info[img].image_view_info->image_id); + assert(img_info); - std::vector filenames = - GenerateImageDescriptorFilename(qs_index, bcb_index, img_info); - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); + entry["type"] = util::ToString(desc_binding.second.desc_type); + entry["set"] = desc_set_index; + entry["binding"] = desc_binding_index; + entry["arrayIndex"] = img; + + std::vector aspects; + graphics::GetFormatAspects(img_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } - for (size_t f = 0; f < filenames.size(); ++f) + for (uint32_t mip = 0; mip < img_info->level_count; ++mip) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - const std::vector full_filename{ - filenames[f] + ImageFileExtension(img_info->format, image_file_format) - }; - auto& image_descriptor_json_entry = entry["descriptor"]; - dump_json.InsertImageInfo(image_descriptor_json_entry[f], - img_info, - full_filename, - aspects[f], - scaling_failed); + for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) + { + std::string filename = GenerateImageDescriptorFilename(img_info->format, + mip, + layer, + img_info->capture_id, + aspect, + qs_index, + bcb_index); + + const VkExtent3D extent = { std::max(1u, img_info->extent.width >> mip), + std::max(1u, img_info->extent.height >> mip), + img_info->extent.depth }; + + auto& image_descriptor_json_entry = entry["descriptor"]; + + dump_json.InsertImageInfo(image_descriptor_json_entry[f++], + img_info->format, + img_info->type, + img_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } } } } diff --git a/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.h b/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.h index 8c822ceda6..2db6cd9770 100644 --- a/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.h +++ b/framework/decode/vulkan_replay_dump_resources_compute_ray_tracing.h @@ -119,19 +119,19 @@ class DispatchTraceRaysDumpingContext void Release(); private: - std::vector GenerateDispatchTraceRaysImageFilename(VkFormat format, - uint32_t levels, - uint32_t layers, - bool is_dispatch, - uint64_t qs_index, - uint64_t bcb_index, - uint64_t cmd_index, - uint32_t desc_set, - uint32_t desc_binding, - uint32_t array_index, - VkShaderStageFlagBits stage, - bool before_cmd, - bool dump_all_subresources) const; + std::string GenerateDispatchTraceRaysImageFilename(VkFormat format, + uint32_t mip, + uint32_t layer, + VkImageAspectFlagBits aspect, + bool is_dispatch, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t cmd_index, + uint32_t desc_set, + uint32_t desc_binding, + uint32_t array_index, + VkShaderStageFlagBits stage, + bool before_cmd) const; std::string GenerateDispatchTraceRaysBufferFilename(bool is_dispatch, uint64_t qs_index, @@ -143,8 +143,13 @@ class DispatchTraceRaysDumpingContext VkShaderStageFlagBits stage, bool before_cmd) const; - std::vector - GenerateImageDescriptorFilename(uint64_t bcb_index, uint64_t cmd_index, const ImageInfo* img_info) const; + std::string GenerateImageDescriptorFilename(VkFormat format, + uint32_t mip, + uint32_t layer, + format::HandleId image_id, + VkImageAspectFlagBits aspect, + uint64_t bcb_index, + uint64_t cmd_index) const; std::string GenerateBufferDescriptorFilename(uint64_t bcb_index, uint64_t cmd_index, format::HandleId buffer_id) const; diff --git a/framework/decode/vulkan_replay_dump_resources_draw_calls.cpp b/framework/decode/vulkan_replay_dump_resources_draw_calls.cpp index 56a88a2f89..4ffd4ca6c4 100644 --- a/framework/decode/vulkan_replay_dump_resources_draw_calls.cpp +++ b/framework/decode/vulkan_replay_dump_resources_draw_calls.cpp @@ -33,6 +33,7 @@ #include "util/logging.h" #include "util/platform.h" +#include #include #include #include @@ -693,7 +694,7 @@ void DrawCallsDumpingContext::FinalizeCommandBuffer() barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; barrier.image = cat->handle; barrier.subresourceRange = { - VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS + VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS }; device_table->CmdPipelineBarrier(current_command_buffer, @@ -896,60 +897,68 @@ VkResult DrawCallsDumpingContext::DumpDrawCalls( #define DEPTH_ATTACHMENT ~0 -std::vector DrawCallsDumpingContext::GenerateRenderTargetImageFilename(VkFormat format, - uint64_t cmd_buf_index, - uint64_t qs_index, - uint64_t bcb_index, - uint64_t dc_index, - int attachment_index) const +std::string DrawCallsDumpingContext::GenerateRenderTargetImageFilename(VkFormat format, + VkImageAspectFlagBits aspect, + uint32_t mip_level, + uint32_t layer, + uint64_t cmd_buf_index, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t dc_index, + int attachment_index) const { - std::vector aspects; - graphics::GetFormatAspects(format, &aspects); + std::string aspect_str = ImageAspectToStr(aspect); + std::string attachment_str = + attachment_index != DEPTH_ATTACHMENT ? "_att_" + std::to_string(attachment_index) : "_depth_att"; - std::vector filenames(aspects.size()); - - for (size_t i = 0; i < aspects.size(); ++i) + std::stringstream filename; + filename << capture_filename << "_"; + if (VkFormatToImageWriterDataFormat(format) != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) { - std::string aspect_str = ImageAspectToStr(aspects[i]); - std::string attachment_str = - attachment_index != DEPTH_ATTACHMENT ? "_att_" + std::to_string(attachment_index) : "_depth_att"; - - std::stringstream filename; - filename << capture_filename << "_"; - if (VkFormatToImageWriterDataFormat(format) != util::imagewriter::DataFormats::kFormat_UNSPECIFIED) + if (dump_resources_before) { - if (dump_resources_before) - { - filename << "draw_" << ((cmd_buf_index % 2) ? "after_" : "before_") << dc_index << "_qs_" << qs_index - << "_bcb_" << bcb_index << attachment_str << "_aspect_" << aspect_str; - } - else - { - filename << "draw_" << dc_index << "_qs_" << qs_index << "_bcb_" << bcb_index << attachment_str - << "_aspect_" << aspect_str; - } + filename << "draw_" << ((cmd_buf_index % 2) ? "after_" : "before_") << dc_index << "_qs_" << qs_index + << "_bcb_" << bcb_index << attachment_str << "_aspect_" << aspect_str; } else { - if (dump_resources_before) - { - filename << "draw_" << ((cmd_buf_index % 2) ? "after_" : "before_") << dc_index << "_qs_" << qs_index - << "_bcb_" << bcb_index << "_" << qs_index << "_" << bcb_index << "_" << attachment_str - << util::ToString(format) << "_aspect_" << aspect_str; - } - else - { - filename << "draw_" << dc_index << "_qs_" << qs_index << "_bcb_" << bcb_index << "_dc_" - << attachment_str << util::ToString(format) << "_aspect_" << aspect_str; - } + filename << "draw_" << dc_index << "_qs_" << qs_index << "_bcb_" << bcb_index << attachment_str + << "_aspect_" << aspect_str; + } + } + else + { + if (dump_resources_before) + { + filename << "draw_" << ((cmd_buf_index % 2) ? "after_" : "before_") << dc_index << "_qs_" << qs_index + << "_bcb_" << bcb_index << "_" << qs_index << "_" << bcb_index << "_" << attachment_str + << util::ToString(format) << "_aspect_" << aspect_str; + } + else + { + filename << "draw_" << dc_index << "_qs_" << qs_index << "_bcb_" << bcb_index << "_dc_" << attachment_str + << util::ToString(format) << "_aspect_" << aspect_str; } + } + + if (dump_all_image_subresources) + { + std::stringstream subresource_sting; + subresource_sting << "_mip_" << mip_level << "_layer_" << layer; + subresource_sting << ImageFileExtension(format, image_file_format); std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(filename.str()); - filenames[i] = (filedirname / filebasename).string(); + std::filesystem::path filebasename(filename.str() + subresource_sting.str()); + return (filedirname / filebasename).string(); } + else + { + filename << ImageFileExtension(format, image_file_format); - return filenames; + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(filename.str()); + return (filedirname / filebasename).string(); + } } void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo( @@ -1106,32 +1115,80 @@ void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo( continue; } - const ImageInfo* image_info = render_targets[rp][sp].color_att_imgs[i]; - std::vector filenamesBefore, filenamesAfter; - std::vector filenamesBeforeAfter; - bool scaling_failed; - if (dump_resources_before) - { - filenamesBefore = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, i); - filenamesAfter = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index + 1, qs_index, bcb_index, dc_index, i); - scaling_failed = ImageFailedScaling(filenamesBefore[0]); - filenamesBeforeAfter.resize(2); - filenamesBeforeAfter[0] = - filenamesBefore[0] + ImageFileExtension(image_info->format, image_file_format); - filenamesBeforeAfter[1] = filenamesAfter[0] + ImageFileExtension(image_info->format, image_file_format); - } - else + const ImageInfo* image_info = render_targets[rp][sp].color_att_imgs[i]; + assert(image_info != nullptr); + + std::vector aspects; + graphics::GetFormatAspects(image_info->format, &aspects); + + size_t f = 0; + for (auto aspect : aspects) { - filenamesAfter = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, i); - scaling_failed = ImageFailedScaling(filenamesAfter[0]); - filenamesBeforeAfter.resize(1); - filenamesBeforeAfter[0] = filenamesAfter[0] + ImageFileExtension(image_info->format, image_file_format); + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + std::string filenameBefore; + if (dump_resources_before) + { + filenameBefore = GenerateRenderTargetImageFilename(image_info->format, + aspect, + mip, + layer, + cmd_buf_index, + qs_index, + bcb_index, + dc_index, + i); + } + + std::string filenameAfter = + GenerateRenderTargetImageFilename(image_info->format, + aspect, + mip, + layer, + cmd_buf_index + dump_resources_before, + qs_index, + bcb_index, + dc_index, + i); + + const VkExtent3D extent = { std::max(1u, image_info->extent.width >> mip), + std::max(1u, image_info->extent.height >> mip), + image_info->extent.depth }; + + dump_json.InsertImageInfo(rt_entries[f++], + image_info->format, + image_info->type, + image_info->capture_id, + extent, + filenameAfter, + aspect, + ImageFailedScaling(filenameAfter), + mip, + layer, + dump_resources_before ? &filenameBefore : nullptr); + + // Skip rest of layers + if (!dump_all_image_subresources) + { + break; + } + } + + // Skip rest of mip map levels + if (!dump_all_image_subresources) + { + break; + } + } } - dump_json.InsertImageInfo( - rt_entries[i], image_info, filenamesBeforeAfter, VK_IMAGE_ASPECT_COLOR_BIT, scaling_failed); } } @@ -1140,48 +1197,77 @@ void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo( { auto& depth_entries = draw_call_entry["depthAttachments"]; - const ImageInfo* image_info = render_targets[rp][sp].depth_att_img; - std::vector filenamesBefore, filenamesAfter; - if (dump_resources_before) - { - filenamesBefore = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, DEPTH_ATTACHMENT); - filenamesAfter = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index + 1, qs_index, bcb_index, dc_index, DEPTH_ATTACHMENT); - } - else - { - filenamesAfter = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, DEPTH_ATTACHMENT); - } + const ImageInfo* image_info = render_targets[rp][sp].depth_att_img; std::vector aspects; graphics::GetFormatAspects(image_info->format, &aspects); - for (size_t i = 0; i < filenamesAfter.size(); ++i) + size_t f = 0; + for (auto aspect : aspects) { - std::vector filenamesBeforeAfter; - bool scaling_failed; - - // We don't support stencil output yet - if (filenamesAfter[i].find("stencil") != std::string::npos) - continue; - - if (dump_resources_before) + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { - filenamesBeforeAfter.resize(2); - scaling_failed = ImageFailedScaling(filenamesBefore[i]); - filenamesBeforeAfter[0] = - filenamesBefore[i] + ImageFileExtension(image_info->format, image_file_format); - filenamesBeforeAfter[1] = filenamesAfter[i] + ImageFileExtension(image_info->format, image_file_format); + continue; } - else + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) { - filenamesBeforeAfter.resize(1); - scaling_failed = ImageFailedScaling(filenamesAfter[i]); - filenamesBeforeAfter[0] = filenamesAfter[i] + ImageFileExtension(image_info->format, image_file_format); + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + std::string filenameBefore; + if (dump_resources_before) + { + filenameBefore = GenerateRenderTargetImageFilename(image_info->format, + aspect, + mip, + layer, + cmd_buf_index, + qs_index, + bcb_index, + dc_index, + DEPTH_ATTACHMENT); + } + + std::string filenameAfter = GenerateRenderTargetImageFilename(image_info->format, + aspect, + mip, + layer, + cmd_buf_index + dump_resources_before, + qs_index, + bcb_index, + dc_index, + DEPTH_ATTACHMENT); + + const VkExtent3D extent = { std::max(1u, image_info->extent.width >> mip), + std::max(1u, image_info->extent.height >> mip), + image_info->extent.depth }; + + dump_json.InsertImageInfo(depth_entries[f++], + image_info->format, + image_info->type, + image_info->capture_id, + extent, + filenameAfter, + aspect, + ImageFailedScaling(filenameAfter), + mip, + layer, + dump_resources_before ? &filenameBefore : nullptr); + + // Skip rest of layers + if (!dump_all_image_subresources) + { + break; + } + } + + // Skip rest of mip map levels + if (!dump_all_image_subresources) + { + break; + } } - dump_json.InsertImageInfo(depth_entries[i], image_info, filenamesBeforeAfter, aspects[i], scaling_failed); } } @@ -1257,40 +1343,80 @@ void DrawCallsDumpingContext::GenerateOutputJsonDrawCallInfo( { for (size_t img = 0; img < desc_binding.second.image_info.size(); ++img) { - if (desc_binding.second.image_info[img].image_view_info != nullptr) + if (desc_binding.second.image_info[img].image_view_info == nullptr) { - auto& desc_shader_stage_json_entry = - draw_call_entry["descriptors"][ShaderStageToStr(shader_stage.first)]; - auto& desc_shader_binding_json_entry = - desc_shader_stage_json_entry[stage_entry_index++]; + continue; + } - desc_shader_binding_json_entry["type"] = - util::ToString(desc_binding.second.desc_type); - desc_shader_binding_json_entry["set"] = desc_set_index; - desc_shader_binding_json_entry["binding"] = desc_set_binding_index; - desc_shader_binding_json_entry["arrayIndex"] = img; + auto& desc_shader_stage_json_entry = + draw_call_entry["descriptors"][ShaderStageToStr(shader_stage.first)]; + auto& desc_shader_binding_json_entry = + desc_shader_stage_json_entry[stage_entry_index++]; - const ImageInfo* img_info = object_info_table.GetImageInfo( - desc_binding.second.image_info[img].image_view_info->image_id); - assert(img_info != nullptr); + desc_shader_binding_json_entry["type"] = + util::ToString(desc_binding.second.desc_type); + desc_shader_binding_json_entry["set"] = desc_set_index; + desc_shader_binding_json_entry["binding"] = desc_set_binding_index; + desc_shader_binding_json_entry["arrayIndex"] = img; - std::vector filenames = - GenerateImageDescriptorFilename(qs_index, bcb_index, rp, img_info); + const ImageInfo* image_info = object_info_table.GetImageInfo( + desc_binding.second.image_info[img].image_view_info->image_id); + assert(image_info != nullptr); - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); + std::vector aspects; + graphics::GetFormatAspects(image_info->format, &aspects); - auto& image_descriptor_json_entry = - desc_shader_binding_json_entry["descriptor"]; - for (size_t f = 0; f < filenames.size(); ++f) + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) { - const bool scaling_failed = ImageFailedScaling(filenames[f]); - filenames[f] += ImageFileExtension(img_info->format, image_file_format); - dump_json.InsertImageInfo(image_descriptor_json_entry[f], - img_info, - { filenames[f] }, - aspects[f], - scaling_failed); + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + std::string filename = + GenerateImageDescriptorFilename(image_info->format, + aspect, + image_info->capture_id, + mip, + layer, + qs_index, + bcb_index, + rp); + const VkExtent3D extent = { + std::max(1u, image_info->extent.width >> mip), + std::max(1u, image_info->extent.height >> mip), + image_info->extent.depth + }; + + auto& image_descriptor_json_entry = + desc_shader_binding_json_entry["descriptor"]; + dump_json.InsertImageInfo(image_descriptor_json_entry[f++], + image_info->format, + image_info->type, + image_info->capture_id, + extent, + filename, + aspect, + ImageFailedScaling(filename), + mip, + layer); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } } } } @@ -1403,7 +1529,7 @@ VkResult DrawCallsDumpingContext::RevertRenderTargetImageLayouts(VkQueue queue, img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; img_barrier.subresourceRange = { - VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS + VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS }; for (size_t i = 0; i < render_targets[rp][sp].color_att_imgs.size(); ++i) @@ -1517,15 +1643,6 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments( const DeviceInfo* device_info = object_info_table.GetDeviceInfo(original_command_buffer_info->parent_id); assert(device_info); - const PhysicalDeviceInfo* phys_dev_info = object_info_table.GetPhysicalDeviceInfo(device_info->parent_id); - assert(phys_dev_info); - - graphics::VulkanResourcesUtil resource_util(device_info->handle, - device_info->parent, - *device_table, - *instance_table, - *phys_dev_info->replay_device_info->memory_properties); - // Dump color attachments for (size_t i = 0; i < render_targets[rp][sp].color_att_imgs.size(); ++i) { @@ -1537,8 +1654,42 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments( const ImageInfo* image_info = render_targets[rp][sp].color_att_imgs[i]; - const std::vector filenames = - GenerateRenderTargetImageFilename(image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, i); + std::vector aspects; + graphics::GetFormatAspects(image_info->format, &aspects); + + const size_t total_files = dump_all_image_subresources + ? (aspects.size() * image_info->layer_count * image_info->level_count) + : aspects.size(); + + std::vector filenames(total_files); + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + filenames[f++] = GenerateRenderTargetImageFilename( + image_info->format, aspect, mip, layer, cmd_buf_index, qs_index, bcb_index, dc_index, i); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } const VkExtent3D extent{ render_area[rp].extent.width, render_area[rp].extent.height, 1 }; std::vector scaling_supported(filenames.size()); @@ -1576,12 +1727,49 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments( { const ImageInfo* image_info = render_targets[rp][sp].depth_att_img; - std::vector data; - std::vector subresource_offsets; - std::vector subresource_sizes; + std::vector aspects; + graphics::GetFormatAspects(image_info->format, &aspects); - const std::vector filenames = GenerateRenderTargetImageFilename( - image_info->format, cmd_buf_index, qs_index, bcb_index, dc_index, DEPTH_ATTACHMENT); + const size_t total_files = dump_all_image_subresources + ? (aspects.size() * image_info->layer_count * image_info->level_count) + : aspects.size(); + + std::vector filenames(total_files); + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + filenames[f++] = GenerateRenderTargetImageFilename(image_info->format, + aspect, + mip, + layer, + cmd_buf_index, + qs_index, + bcb_index, + dc_index, + DEPTH_ATTACHMENT); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } const VkExtent3D extent{ render_area[rp].extent.width, render_area[rp].extent.height, 1 }; std::vector scaling_supported(filenames.size()); @@ -1617,68 +1805,52 @@ VkResult DrawCallsDumpingContext::DumpRenderTargetAttachments( return VK_SUCCESS; } -std::vector DrawCallsDumpingContext::GenerateImageDescriptorFilename(uint64_t qs_index, - uint64_t bcb_index, - uint64_t rp, - const ImageInfo* img_info) const +std::string DrawCallsDumpingContext::GenerateImageDescriptorFilename(VkFormat format, + VkImageAspectFlagBits aspect, + format::HandleId image_id, + uint32_t level, + uint32_t layer, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t rp) const { - assert(img_info != nullptr); + std::string aspect_str = ImageAspectToStr(aspect); + std::stringstream base_filename; + base_filename << capture_filename << "_"; - std::vector aspects; - graphics::GetFormatAspects(img_info->format, &aspects); - - const uint32_t total_files = - dump_all_image_subresources ? (aspects.size() * img_info->level_count * img_info->layer_count) : aspects.size(); - std::vector filenames(total_files); - - uint32_t f = 0; - for (size_t i = 0; i < aspects.size(); ++i) + const util::imagewriter::DataFormats output_format = VkFormatToImageWriterDataFormat(format); + if (output_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED && + output_format != util::imagewriter::DataFormats::kFormat_ASTC) { - std::string aspect_str = ImageAspectToStr(aspects[i]); - std::stringstream base_filename; - base_filename << capture_filename << "_"; - - const util::imagewriter::DataFormats output_format = VkFormatToImageWriterDataFormat(img_info->format); - if (output_format != util::imagewriter::DataFormats::kFormat_UNSPECIFIED && - output_format != util::imagewriter::DataFormats::kFormat_ASTC) - { - base_filename << "image_" << img_info->capture_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_rp_" - << rp << "_aspect_" << aspect_str; - } - else - { - std::string whole_format_name = util::ToString(img_info->format); - std::string format_name(whole_format_name.begin() + 10, whole_format_name.end()); - - base_filename << "image_" << img_info->capture_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_rp_" - << rp << "_" << format_name << "_aspect_" << aspect_str; - } + base_filename << "image_" << image_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_rp_" << rp + << "_aspect_" << aspect_str; + } + else + { + std::string whole_format_name = util::ToString(format); + std::string format_name(whole_format_name.begin() + 10, whole_format_name.end()); - if (dump_all_image_subresources && (img_info->level_count > 1 || img_info->layer_count > 1)) - { - for (uint32_t level = 0; level < img_info->level_count; ++level) - { - for (uint32_t layer = 0; layer < img_info->layer_count; ++layer) - { - std::stringstream sub_resources_str; - sub_resources_str << base_filename.str() << "_mip_" << level << "_layer_" << layer; - std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(sub_resources_str.str()); - filenames[f++] = (filedirname / filebasename).string(); - } - } - } - else - { - std::filesystem::path filedirname(dump_resource_path); - std::filesystem::path filebasename(base_filename.str()); - filenames[f++] = (filedirname / filebasename).string(); - } + base_filename << "image_" << image_id << "_qs_" << qs_index << "_bcb_" << bcb_index << "_rp_" << rp << "_" + << format_name << "_aspect_" << aspect_str; } - assert(f == total_files); + if (dump_all_image_subresources) + { + std::stringstream sub_resources_str; + sub_resources_str << base_filename.str() << "_mip_" << level << "_layer_" << layer; + sub_resources_str << ImageFileExtension(format, image_file_format); - return filenames; + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(sub_resources_str.str()); + return (filedirname / filebasename).string(); + } + else + { + base_filename << ImageFileExtension(format, image_file_format); + std::filesystem::path filedirname(dump_resource_path); + std::filesystem::path filebasename(base_filename.str()); + return (filedirname / filebasename).string(); + } } std::string DrawCallsDumpingContext::GenerateBufferDescriptorFilename(uint64_t qs_index, @@ -1833,11 +2005,48 @@ DrawCallsDumpingContext::DumpImmutableDescriptors(uint64_t qs_index, uint64_t bc const DeviceInfo* device_info = object_info_table.GetDeviceInfo(original_command_buffer_info->parent_id); assert(device_info); - for (const auto& img_info : image_descriptors) + for (const auto& image_info : image_descriptors) { - const std::vector filenames = GenerateImageDescriptorFilename(qs_index, bcb_index, rp, img_info); - std::vector scaling_supported(filenames.size()); - VkResult res = DumpImageToFile(img_info, + std::vector aspects; + graphics::GetFormatAspects(image_info->format, &aspects); + + const size_t total_files = dump_all_image_subresources + ? (aspects.size() * image_info->layer_count * image_info->level_count) + : aspects.size(); + + std::vector filenames(total_files); + + size_t f = 0; + for (auto aspect : aspects) + { + // Dumping stencil is not supported at the moment + if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) + { + continue; + } + + for (uint32_t mip = 0; mip < image_info->level_count; ++mip) + { + for (uint32_t layer = 0; layer < image_info->layer_count; ++layer) + { + filenames[f++] = GenerateImageDescriptorFilename( + image_info->format, aspect, image_info->capture_id, mip, layer, qs_index, bcb_index, rp); + + if (!dump_all_image_subresources) + { + break; + } + } + + if (!dump_all_image_subresources) + { + break; + } + } + } + + std::vector scaling_supported(total_files); + VkResult res = DumpImageToFile(image_info, device_info, device_table, instance_table, diff --git a/framework/decode/vulkan_replay_dump_resources_draw_calls.h b/framework/decode/vulkan_replay_dump_resources_draw_calls.h index 02f18cb5e5..55bee07d22 100644 --- a/framework/decode/vulkan_replay_dump_resources_draw_calls.h +++ b/framework/decode/vulkan_replay_dump_resources_draw_calls.h @@ -190,17 +190,24 @@ class DrawCallsDumpingContext void SetRenderArea(const VkRect2D& new_render_area); - std::vector GenerateRenderTargetImageFilename(VkFormat format, - uint64_t cmd_buf_index, - uint64_t qs_index, - uint64_t bcb_index, - uint64_t dc_index, - int attachment_index) const; - - std::vector GenerateImageDescriptorFilename(uint64_t qs_index, - uint64_t bcb_index, - uint64_t rp, - const ImageInfo* img_info) const; + std::string GenerateRenderTargetImageFilename(VkFormat format, + VkImageAspectFlagBits aspect, + uint32_t mip_level, + uint32_t layer, + uint64_t cmd_buf_index, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t dc_index, + int attachment_index) const; + + std::string GenerateImageDescriptorFilename(VkFormat format, + VkImageAspectFlagBits aspect, + format::HandleId image_id, + uint32_t level, + uint32_t layer, + uint64_t qs_index, + uint64_t bcb_index, + uint64_t rp) const; std::string GenerateBufferDescriptorFilename(uint64_t qs_index, uint64_t bcb_index, diff --git a/framework/decode/vulkan_replay_dump_resources_json.cpp b/framework/decode/vulkan_replay_dump_resources_json.cpp index fcecd76eca..302aeaf92f 100644 --- a/framework/decode/vulkan_replay_dump_resources_json.cpp +++ b/framework/decode/vulkan_replay_dump_resources_json.cpp @@ -150,28 +150,29 @@ nlohmann::ordered_json& VulkanReplayDumpResourcesJson::GetCurrentSubEntry() return current_entry != nullptr ? *current_entry : json_data_; } -void VulkanReplayDumpResourcesJson::InsertImageInfo(nlohmann::ordered_json& json_entry, - const ImageInfo* image_info, - const std::vector& filenames, - VkImageAspectFlagBits aspect, - bool scale_failed, - uint32_t mip_level, - uint32_t array_layer, - const VkExtent3D* extent) +void VulkanReplayDumpResourcesJson::InsertImageInfo(nlohmann::ordered_json& json_entry, + VkFormat image_format, + VkImageType image_type, + format::HandleId image_id, + const VkExtent3D& extent, + const std::string& filename, + VkImageAspectFlagBits aspect, + bool scale_failed, + uint32_t mip_level, + uint32_t array_layer, + const std::string* filename_before) { - assert(image_info != nullptr); - - json_entry["imageId"] = image_info->capture_id; - json_entry["format"] = util::ToString(image_info->format); - json_entry["type"] = util::ToString(image_info->type); + json_entry["imageId"] = image_id; + json_entry["format"] = util::ToString(image_format); + json_entry["type"] = util::ToString(image_type); const std::string aspect_str_whole(util::ToString(aspect)); const std::string aspect_str(aspect_str_whole.begin() + 16, aspect_str_whole.end() - 4); json_entry["aspect"] = aspect_str; - json_entry["dimensions"][0] = extent != nullptr ? extent->width : image_info->extent.width; - json_entry["dimensions"][1] = extent != nullptr ? extent->height : image_info->extent.height; - json_entry["dimensions"][2] = extent != nullptr ? extent->depth : image_info->extent.depth; + json_entry["dimensions"][0] = extent.width; + json_entry["dimensions"][1] = extent.height; + json_entry["dimensions"][2] = extent.depth; json_entry["mipLevel"] = mip_level; json_entry["arrayLayer"] = array_layer; @@ -181,15 +182,14 @@ void VulkanReplayDumpResourcesJson::InsertImageInfo(nlohmann::ordered_json& json_entry["scaleFailed"] = true; } - assert(filenames.size() == 1 || filenames.size() == 2); - if (filenames.size() == 2) + if (filename_before != nullptr) { - json_entry["beforeFile"] = filenames[0]; - json_entry["afterFile"] = filenames[1]; + json_entry["beforeFile"] = *filename_before; + json_entry["afterFile"] = filename; } else { - json_entry["file"] = filenames[0]; + json_entry["file"] = filename; } } diff --git a/framework/decode/vulkan_replay_dump_resources_json.h b/framework/decode/vulkan_replay_dump_resources_json.h index 0c20b4ad46..f17fc03f23 100644 --- a/framework/decode/vulkan_replay_dump_resources_json.h +++ b/framework/decode/vulkan_replay_dump_resources_json.h @@ -59,14 +59,17 @@ class VulkanReplayDumpResourcesJson nlohmann::ordered_json& GetCurrentSubEntry(); - void InsertImageInfo(nlohmann::ordered_json& json_entry, - const ImageInfo* image_info, - const std::vector& filenames, - VkImageAspectFlagBits aspect, - bool scale_failed = false, - uint32_t mip_level = 0, - uint32_t array_layer = 0, - const VkExtent3D* extent = nullptr); + void InsertImageInfo(nlohmann::ordered_json& json_entry, + VkFormat image_format, + VkImageType image_type, + format::HandleId image_id, + const VkExtent3D& extent, + const std::string& filename, + VkImageAspectFlagBits aspect, + bool scale_failed, + uint32_t mip_level = 0, + uint32_t array_layer = 0, + const std::string* filename_before = nullptr); void InsertBufferInfo(nlohmann::ordered_json& json_entry, const BufferInfo* buffer_info, const std::string& filename);