transform: Add a debug flag to dump WGSL

Before and after each transform of a transform::Manager.

This change makes the transforms use the Castable system so we can get the transform name.

Change-Id: I2cf9335960f1aca56f1d32c5ba0d104db4cc46c1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54581
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-07-15 20:24:38 +00:00
committed by Tint LUCI CQ
parent aa5686acc3
commit 4511a2ebb6
5 changed files with 73 additions and 5 deletions

View File

@@ -14,6 +14,16 @@
#include "src/transform/manager.h"
/// If set to 1 then the transform::Manager will dump the WGSL of the program
/// before and after each transform. Helpful for debugging bad output.
#define PRINT_PROGRAM_FOR_EACH_TRANSFORM 0
#if PRINT_PROGRAM_FOR_EACH_TRANSFORM
#define IF_PRINT_PROGRAM(x) x
#else // PRINT_PROGRAM_FOR_EACH_TRANSFORM
#define IF_PRINT_PROGRAM(x)
#endif // PRINT_PROGRAM_FOR_EACH_TRANSFORM
TINT_INSTANTIATE_TYPEINFO(tint::transform::Manager);
namespace tint {
@@ -23,16 +33,39 @@ Manager::Manager() = default;
Manager::~Manager() = default;
Output Manager::Run(const Program* program, const DataMap& data) {
#if PRINT_PROGRAM_FOR_EACH_TRANSFORM
auto print_program = [&](const char* msg, const Transform* transform) {
auto wgsl = Program::printer(program);
std::cout << "---------------------------------------------------------"
<< std::endl;
std::cout << "-- " << msg << " " << transform->TypeInfo().name << ":"
<< std::endl;
std::cout << "---------------------------------------------------------"
<< std::endl;
std::cout << wgsl << std::endl;
std::cout << "---------------------------------------------------------"
<< std::endl
<< std::endl;
};
#endif
Output out;
if (!transforms_.empty()) {
for (auto& transform : transforms_) {
for (const auto& transform : transforms_) {
IF_PRINT_PROGRAM(print_program("Input to", transform.get()));
auto res = transform->Run(program, data);
out.program = std::move(res.program);
out.data.Add(std::move(res.data));
if (!out.program.IsValid()) {
program = &out.program;
if (!program->IsValid()) {
IF_PRINT_PROGRAM(print_program("Invalid output of", transform.get()));
return out;
}
program = &out.program;
if (transform == transforms_.back()) {
IF_PRINT_PROGRAM(print_program("Output of", transform.get()));
}
}
} else {
out.program = program->Clone();