From b4904b2db34bf2a94f4ce7e57ff5409108243d9f Mon Sep 17 00:00:00 2001 From: beau-lunarg Date: Thu, 10 Oct 2024 16:11:18 -0400 Subject: [PATCH] Add transformer annotation (#1566) Co-authored-by: bradgrantham-lunarg <50641407+bradgrantham-lunarg@users.noreply.github.com> --- framework/decode/file_transformer.cpp | 32 +++++++++++++++++++++++- framework/decode/file_transformer.h | 5 +++- framework/format/format.h | 1 + tools/compress/compression_converter.cpp | 2 +- tools/optimize/dx12_optimize_util.cpp | 4 +-- tools/optimize/main.cpp | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/framework/decode/file_transformer.cpp b/framework/decode/file_transformer.cpp index 4d4aefd372..8befc8bfb8 100644 --- a/framework/decode/file_transformer.cpp +++ b/framework/decode/file_transformer.cpp @@ -49,8 +49,14 @@ FileTransformer::~FileTransformer() } } -bool FileTransformer::Initialize(const std::string& input_filename, const std::string& output_filename) +bool FileTransformer::Initialize(const std::string& input_filename, + const std::string& output_filename, + const std::string& tool) { + input_filename_ = input_filename; + output_filename_ = output_filename; + tool_ = tool; + bool success = false; int32_t result = util::platform::FileOpen(&input_file_, input_filename.c_str(), "rb"); @@ -102,6 +108,30 @@ bool FileTransformer::Process() { bool success = true; + const char* label = format::kAnnotationLabelTransformer; + const size_t label_length = util::platform::StringLength(label); + + std::string data = ""; + data += "{\n"; + data += " \"input\": " + input_filename_ + ",\n"; + data += " \"output\": " + output_filename_ + ",\n"; + data += " \"tool\": " + tool_ + "\n"; + data += "}"; + const size_t data_length = data.size(); + + format::AnnotationHeader annotation; + annotation.block_header.size = format::GetAnnotationBlockBaseSize() + label_length + data_length; + annotation.block_header.type = format::BlockType::kAnnotation; + annotation.annotation_type = format::kJson; + annotation.label_length = label_length; + annotation.data_length = data_length; + if (!WriteBytes(&annotation, sizeof(annotation)) || !WriteBytes(label, label_length) || + !WriteBytes(data.c_str(), data_length)) + { + HandleBlockWriteError(kErrorWritingBlockHeader, "Failed to write transformer annotation"); + return false; + } + block_index_ = 0; while (success) { diff --git a/framework/decode/file_transformer.h b/framework/decode/file_transformer.h index da8c91be48..f24f3243ce 100644 --- a/framework/decode/file_transformer.h +++ b/framework/decode/file_transformer.h @@ -67,7 +67,7 @@ class FileTransformer virtual ~FileTransformer(); - bool Initialize(const std::string& input_filename, const std::string& output_filename); + bool Initialize(const std::string& input_filename, const std::string& output_filename, const std::string& tool); // Returns false if processing failed. Use GetErrorState() to determine error condition for failure case. bool Process(); @@ -146,6 +146,9 @@ class FileTransformer bool ReadBlockHeader(format::BlockHeader* block_header); private: + std::string input_filename_; + std::string output_filename_; + std::string tool_; FILE* input_file_; FILE* output_file_; format::FileHeader file_header_; diff --git a/framework/format/format.h b/framework/format/format.h index 1ae1533feb..00791ffad0 100644 --- a/framework/format/format.h +++ b/framework/format/format.h @@ -70,6 +70,7 @@ const int8_t kNoneIndex = -1; const char* const kAnnotationLabelOperation = "operation"; const char* const kAnnotationLabelReplayOptions = "replayopts"; const char* const kAnnotationLabelRemovedResource = "removed-resource"; +const char* const kAnnotationLabelTransformer = "transformer"; const char* const kAnnotationPipelineCreationAttempt = "pipelinecreationattempt"; const char* const kOperationAnnotationGfxreconstructVersion = "gfxrecon-version"; diff --git a/tools/compress/compression_converter.cpp b/tools/compress/compression_converter.cpp index e75e1ce51a..a1d0a23625 100644 --- a/tools/compress/compression_converter.cpp +++ b/tools/compress/compression_converter.cpp @@ -50,7 +50,7 @@ bool CompressionConverter::Initialize(const std::string& input_filename, // WriteFileHeader, which depends on a valid target compression type. target_compression_type_ = target_compression_type; decompressing_ = (target_compression_type == format::CompressionType::kNone); - success = FileTransformer::Initialize(input_filename, output_filename); + success = FileTransformer::Initialize(input_filename, output_filename, "compress"); } return success; diff --git a/tools/optimize/dx12_optimize_util.cpp b/tools/optimize/dx12_optimize_util.cpp index 1c52cf1a5e..c39d283d70 100644 --- a/tools/optimize/dx12_optimize_util.cpp +++ b/tools/optimize/dx12_optimize_util.cpp @@ -73,7 +73,7 @@ void CreateResourceValueTrackingConsumer( // Use default replay options, except gpu index. decode::DxReplayOptions dx_replay_options; - dx_replay_options.override_gpu_index = options.override_gpu_index; + dx_replay_options.override_gpu_index = options.override_gpu_index; // Create the replay consumer. dx12_replay_consumer = std::make_unique( @@ -389,7 +389,7 @@ bool ApplyDx12OptimizationInfo(const std::string& input_file GFXRECON_WRITE_CONSOLE("Writing optimized file."); gfxrecon::Dx12FileOptimizer file_optimizer; - if (file_optimizer.Initialize(input_filename, output_filename)) + if (file_optimizer.Initialize(input_filename, output_filename, "optimize")) { file_optimizer.SetUnreferencedBlocks(info.unreferenced_blocks); file_optimizer.SetFillCommandResourceValues(&info.fill_command_resource_values, diff --git a/tools/optimize/main.cpp b/tools/optimize/main.cpp index ec2e226dbd..bd23825bb6 100644 --- a/tools/optimize/main.cpp +++ b/tools/optimize/main.cpp @@ -161,7 +161,7 @@ void FilterUnreferencedResources(const std::string& std::unordered_set&& unreferenced_ids) { gfxrecon::FileOptimizer file_processor(std::move(unreferenced_ids)); - if (file_processor.Initialize(input_filename, output_filename)) + if (file_processor.Initialize(input_filename, output_filename, "optimize")) { file_processor.Process();