Skip to content

Commit

Permalink
Add transformer annotation (#1566)
Browse files Browse the repository at this point in the history
Co-authored-by: bradgrantham-lunarg <[email protected]>
  • Loading branch information
beau-lunarg and bradgrantham-lunarg authored Oct 10, 2024
1 parent 7819bea commit b4904b2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
32 changes: 31 additions & 1 deletion framework/decode/file_transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion framework/decode/file_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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_;
Expand Down
1 change: 1 addition & 0 deletions framework/format/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tools/compress/compression_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tools/optimize/dx12_optimize_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decode::Dx12ResourceValueTrackingConsumer>(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tools/optimize/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void FilterUnreferencedResources(const std::string&
std::unordered_set<gfxrecon::format::HandleId>&& 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();

Expand Down

0 comments on commit b4904b2

Please sign in to comment.