From 7941f45451a004d4bf9d7320bd3ba43fa75c7b6b Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Tue, 4 Feb 2025 12:13:00 +0200 Subject: [PATCH 1/4] VDR: Fix dumping image subresources --- .../decode/vulkan_replay_dump_resources_common.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/decode/vulkan_replay_dump_resources_common.cpp b/framework/decode/vulkan_replay_dump_resources_common.cpp index c7c3cd64ad..ba91e4e498 100644 --- a/framework/decode/vulkan_replay_dump_resources_common.cpp +++ b/framework/decode/vulkan_replay_dump_resources_common.cpp @@ -583,7 +583,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WriteBmpImageSeparateAlpha(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[0], + subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format); @@ -593,7 +593,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WriteBmpImage(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[0], + subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format, @@ -607,7 +607,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WritePngImageSeparateAlpha(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[0], + subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format); @@ -617,7 +617,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WritePngImage(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[0], + subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format, @@ -631,7 +631,7 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, "%s format is not handled. Images with that format will be dump as a plain binary file.", util::ToString(image_info->format).c_str()); - util::bufferwriter::WriteBuffer(filename, data.data(), data.size()); + util::bufferwriter::WriteBuffer(filename, offsetted_data, subresource_sizes[sub_res_idx]); } if (!dump_all_subresources) From f42bf63509109acf8461cec6f978de857bf8753f Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Thu, 6 Feb 2025 14:02:18 +0200 Subject: [PATCH 2/4] Image writer does not need to know the data size --- framework/decode/dx12_dump_resources.cpp | 1 - framework/decode/screenshot_handler.cpp | 6 ++--- .../vulkan_replay_dump_resources_common.cpp | 4 --- framework/graphics/dx12_util.cpp | 3 --- framework/util/image_writer.cpp | 27 ++++++------------- framework/util/image_writer.h | 4 --- 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/framework/decode/dx12_dump_resources.cpp b/framework/decode/dx12_dump_resources.cpp index df75608936..cacdda48fc 100644 --- a/framework/decode/dx12_dump_resources.cpp +++ b/framework/decode/dx12_dump_resources.cpp @@ -2684,7 +2684,6 @@ void DefaultDx12DumpResourcesDelegate::TestWriteImageResource(const std::string& if (!util::imagewriter::WriteBmpImage(file_path, resource_data->footprints[sub_index].Footprint.Width, resource_data->footprints[sub_index].Footprint.Height, - size, resource_data->datas[sub_index].data() + offset, resource_data->footprints[sub_index].Footprint.RowPitch)) { diff --git a/framework/decode/screenshot_handler.cpp b/framework/decode/screenshot_handler.cpp index e0dbb35893..3074298852 100644 --- a/framework/decode/screenshot_handler.cpp +++ b/framework/decode/screenshot_handler.cpp @@ -42,7 +42,6 @@ inline void WriteImageFile(const std::string& filename, util::ScreenshotFormat file_format, uint32_t width, uint32_t height, - uint64_t size, void* data) { switch (file_format) @@ -51,14 +50,14 @@ inline void WriteImageFile(const std::string& filename, GFXRECON_LOG_ERROR("Screenshot format invalid! Expected BMP or PNG, falling back to BMP."); // Intentional fall-through case util::ScreenshotFormat::kBmp: - if (!util::imagewriter::WriteBmpImage(filename + ".bmp", width, height, size, data)) + if (!util::imagewriter::WriteBmpImage(filename + ".bmp", width, height, data)) { GFXRECON_LOG_ERROR("Screenshot could not be created: failed to write BMP file %s", filename.c_str()); } break; #ifdef GFXRECON_ENABLE_PNG_SCREENSHOT case util::ScreenshotFormat::kPng: - if (!util::imagewriter::WritePngImage(filename + ".png", width, height, size, data)) + if (!util::imagewriter::WritePngImage(filename + ".png", width, height, data)) { GFXRECON_LOG_ERROR("Screenshot could not be created: failed to write PNG file %s", filename.c_str()); } @@ -409,7 +408,6 @@ void ScreenshotHandler::WriteImage(const std::string& filen screenshot_format_, copy_width, copy_height, - copy_resource.buffer_size, data); allocator->UnmapResourceMemoryDirect(copy_resource.buffer_data); diff --git a/framework/decode/vulkan_replay_dump_resources_common.cpp b/framework/decode/vulkan_replay_dump_resources_common.cpp index ba91e4e498..eff2b016ea 100644 --- a/framework/decode/vulkan_replay_dump_resources_common.cpp +++ b/framework/decode/vulkan_replay_dump_resources_common.cpp @@ -583,7 +583,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WriteBmpImageSeparateAlpha(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format); @@ -593,7 +592,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WriteBmpImage(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format, @@ -607,7 +605,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WritePngImageSeparateAlpha(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format); @@ -617,7 +614,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info, util::imagewriter::WritePngImage(filename, scaled_extent.width, scaled_extent.height, - subresource_sizes[sub_res_idx], offsetted_data, stride, image_writer_format, diff --git a/framework/graphics/dx12_util.cpp b/framework/graphics/dx12_util.cpp index 408c76a0a6..977c007d57 100644 --- a/framework/graphics/dx12_util.cpp +++ b/framework/graphics/dx12_util.cpp @@ -261,7 +261,6 @@ void TakeScreenshot(std::unique_ptr& image_renderer if (capture_result == S_OK) { - auto datasize = static_cast(buffer_byte_size); std::string filename = filename_prefix; filename += "_frame_"; @@ -277,7 +276,6 @@ void TakeScreenshot(std::unique_ptr& image_renderer if (!util::imagewriter::WriteBmpImage(filename + ".bmp", static_cast(fb_desc.Width), static_cast(fb_desc.Height), - datasize, std::data(captured_image.data), static_cast(pitch))) { @@ -290,7 +288,6 @@ void TakeScreenshot(std::unique_ptr& image_renderer if (!util::imagewriter::WritePngImage(filename + ".png", static_cast(fb_desc.Width), static_cast(fb_desc.Height), - datasize, std::data(captured_image.data), static_cast(pitch), util::imagewriter::kFormat_RGBA)) diff --git a/framework/util/image_writer.cpp b/framework/util/image_writer.cpp index c312c9c390..1e97d4f7c3 100644 --- a/framework/util/image_writer.cpp +++ b/framework/util/image_writer.cpp @@ -405,7 +405,6 @@ static bool WriteBmpHeader(FILE* file, uint32_t width, uint32_t height, bool wri bool WriteBmpImage(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t data_pitch, DataFormats format, @@ -480,28 +479,20 @@ bool WriteBmpImage(const std::string& filename, bool WriteBmpImageSeparateAlpha(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t data_pitch, DataFormats data_format) { - bool success = WriteBmpImage(filename, width, height, data_size, data, data_pitch, data_format, false); + bool success = WriteBmpImage(filename, width, height, data, data_pitch, data_format, false); if (success && DataFormatHasAlpha(data_format)) { - const uint8_t* alpha_channel = ExtractAlphaChannel(width, height, data, data_pitch, true); - const std::string alpha_filename = util::filepath::InsertFilenamePostfix(filename, "_alpha"); - const size_t alpha_pitch = width * kImageBppNoAlpha; - const size_t alpha_image_size = alpha_pitch * height; - const DataFormats alpha_format = data_format == kFormat_BGRA ? kFormat_BGR : kFormat_RGB; - success = WriteBmpImage(alpha_filename, - width, - height, - alpha_image_size, - alpha_channel, - static_cast(alpha_pitch), - alpha_format, - false); + const uint8_t* alpha_channel = ExtractAlphaChannel(width, height, data, data_pitch, true); + const std::string alpha_filename = util::filepath::InsertFilenamePostfix(filename, "_alpha"); + const size_t alpha_pitch = width * kImageBppNoAlpha; + const DataFormats alpha_format = data_format == kFormat_BGRA ? kFormat_BGR : kFormat_RGB; + success = WriteBmpImage( + alpha_filename, width, height, alpha_channel, static_cast(alpha_pitch), alpha_format, false); } return success; @@ -510,7 +501,6 @@ bool WriteBmpImageSeparateAlpha(const std::string& filename, bool WritePngImage(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t data_pitch, DataFormats format, @@ -557,12 +547,11 @@ bool WritePngImage(const std::string& filename, bool WritePngImageSeparateAlpha(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t data_pitch, DataFormats format) { - bool success = WritePngImage(filename, width, height, data_size, data, data_pitch, format, false); + bool success = WritePngImage(filename, width, height, data, data_pitch, format, false); if (success && DataFormatHasAlpha(format)) { const std::string alpha_filename = util::filepath::InsertFilenamePostfix(filename, "_alpha"); diff --git a/framework/util/image_writer.h b/framework/util/image_writer.h index c8da614dd9..6fa1ac9e8b 100644 --- a/framework/util/image_writer.h +++ b/framework/util/image_writer.h @@ -125,7 +125,6 @@ constexpr size_t DataFormatsSizes(DataFormats format) bool WriteBmpImage(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t pitch = 0, DataFormats data_format = kFormat_BGRA, @@ -134,7 +133,6 @@ bool WriteBmpImage(const std::string& filename, bool WriteBmpImageSeparateAlpha(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t pitch, DataFormats data_format); @@ -142,7 +140,6 @@ bool WriteBmpImageSeparateAlpha(const std::string& filename, bool WritePngImage(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t pitch = 0, DataFormats format = kFormat_BGRA, @@ -151,7 +148,6 @@ bool WritePngImage(const std::string& filename, bool WritePngImageSeparateAlpha(const std::string& filename, uint32_t width, uint32_t height, - uint64_t data_size, const void* data, uint32_t pitch, DataFormats format); From d5911a4962a57da914be66455ba805c551edded9 Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Thu, 6 Feb 2025 14:03:08 +0200 Subject: [PATCH 3/4] ProcessInitImageCommand should update image info layout --- framework/decode/vulkan_replay_consumer_base.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/decode/vulkan_replay_consumer_base.cpp b/framework/decode/vulkan_replay_consumer_base.cpp index 59a118c0cb..d7b4d47278 100644 --- a/framework/decode/vulkan_replay_consumer_base.cpp +++ b/framework/decode/vulkan_replay_consumer_base.cpp @@ -939,8 +939,8 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId const std::vector& level_sizes, const uint8_t* data) { - VulkanDeviceInfo* device_info = object_info_table_->GetVkDeviceInfo(device_id); - const VulkanImageInfo* image_info = object_info_table_->GetVkImageInfo(image_id); + VulkanDeviceInfo* device_info = object_info_table_->GetVkDeviceInfo(device_id); + VulkanImageInfo* image_info = object_info_table_->GetVkImageInfo(image_id); if ((device_info != nullptr) && (image_info != nullptr)) { @@ -1033,6 +1033,9 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId image_info->level_count); } + image_info->intermediate_layout = static_cast(layout); + image_info->current_layout = static_cast(layout); + if (result != VK_SUCCESS) { GFXRECON_LOG_WARNING( From eb5ad043f881cbd42c6457aa86ce792c971c31ec Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Thu, 6 Feb 2025 14:03:51 +0200 Subject: [PATCH 4/4] VDR: DumpImageDescriptor should use the correct image layout --- framework/decode/vulkan_replay_dump_resources_delegate.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/decode/vulkan_replay_dump_resources_delegate.cpp b/framework/decode/vulkan_replay_dump_resources_delegate.cpp index 5af929755c..ef42d5779a 100644 --- a/framework/decode/vulkan_replay_dump_resources_delegate.cpp +++ b/framework/decode/vulkan_replay_dump_resources_delegate.cpp @@ -275,7 +275,8 @@ VkResult DefaultVulkanDumpResourcesDelegate::DumpImageDescriptor(const VulkanDum options_.dump_resources_image_format, options_.dump_resources_dump_all_image_subresources, options_.dump_resources_dump_raw_images, - options_.dump_resources_dump_separate_alpha); + options_.dump_resources_dump_separate_alpha, + image_info->intermediate_layout); if (res != VK_SUCCESS) { GFXRECON_LOG_ERROR("Dumping image failed (%s)", util::ToString(res).c_str())