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

VDR: Fix dumping image subresources #2005

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
1 change: 0 additions & 1 deletion framework/decode/dx12_dump_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
6 changes: 2 additions & 4 deletions framework/decode/screenshot_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId
const std::vector<uint64_t>& 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))
{
Expand Down Expand Up @@ -1033,6 +1033,9 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId
image_info->level_count);
}

image_info->intermediate_layout = static_cast<VkImageLayout>(layout);
image_info->current_layout = static_cast<VkImageLayout>(layout);

if (result != VK_SUCCESS)
{
GFXRECON_LOG_WARNING(
Expand Down
6 changes: 1 addition & 5 deletions framework/decode/vulkan_replay_dump_resources_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
util::imagewriter::WriteBmpImageSeparateAlpha(filename,
scaled_extent.width,
scaled_extent.height,
subresource_sizes[0],
offsetted_data,
stride,
image_writer_format);
Expand All @@ -593,7 +592,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
util::imagewriter::WriteBmpImage(filename,
scaled_extent.width,
scaled_extent.height,
subresource_sizes[0],
offsetted_data,
stride,
image_writer_format,
Expand All @@ -607,7 +605,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
util::imagewriter::WritePngImageSeparateAlpha(filename,
scaled_extent.width,
scaled_extent.height,
subresource_sizes[0],
offsetted_data,
stride,
image_writer_format);
Expand All @@ -617,7 +614,6 @@ VkResult DumpImageToFile(const VulkanImageInfo* image_info,
util::imagewriter::WritePngImage(filename,
scaled_extent.width,
scaled_extent.height,
subresource_sizes[0],
offsetted_data,
stride,
image_writer_format,
Expand All @@ -631,7 +627,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<VkFormat>(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)
Expand Down
3 changes: 2 additions & 1 deletion framework/decode/vulkan_replay_dump_resources_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkResult>(res).c_str())
Expand Down
3 changes: 0 additions & 3 deletions framework/graphics/dx12_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ void TakeScreenshot(std::unique_ptr<graphics::DX12ImageRenderer>& image_renderer

if (capture_result == S_OK)
{
auto datasize = static_cast<int>(buffer_byte_size);
std::string filename = filename_prefix;

filename += "_frame_";
Expand All @@ -277,7 +276,6 @@ void TakeScreenshot(std::unique_ptr<graphics::DX12ImageRenderer>& image_renderer
if (!util::imagewriter::WriteBmpImage(filename + ".bmp",
static_cast<unsigned int>(fb_desc.Width),
static_cast<unsigned int>(fb_desc.Height),
datasize,
std::data(captured_image.data),
static_cast<unsigned int>(pitch)))
{
Expand All @@ -290,7 +288,6 @@ void TakeScreenshot(std::unique_ptr<graphics::DX12ImageRenderer>& image_renderer
if (!util::imagewriter::WritePngImage(filename + ".png",
static_cast<unsigned int>(fb_desc.Width),
static_cast<unsigned int>(fb_desc.Height),
datasize,
std::data(captured_image.data),
static_cast<unsigned int>(pitch),
util::imagewriter::kFormat_RGBA))
Expand Down
27 changes: 8 additions & 19 deletions framework/util/image_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<uint32_t>(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<uint32_t>(alpha_pitch), alpha_format, false);
}

return success;
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 0 additions & 4 deletions framework/util/image_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -134,15 +133,13 @@ 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);

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,
Expand All @@ -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);
Expand Down