Add "Write Debug Trace/Dump" buttons to SkSL slide in Viewer.

Click these buttons to trace execution of the current SkSL program.
This demonstrates end-to-end debug trace functionality in
SkRuntimeEffect.

Change-Id: I684099e337d1d275e444eb33dfa3a9e99343bb17
Bug: skia:12708
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/481336
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-12-08 10:34:52 -05:00 committed by SkCQ
parent 44f8636b30
commit 97119e5b3c
2 changed files with 28 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include "include/core/SkFont.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkPerlinNoiseShader.h"
#include "include/sksl/SkSLDebugTrace.h"
#include "src/core/SkEnumerate.h"
#include "tools/Resources.h"
#include "tools/viewer/Viewer.h"
@ -140,6 +141,14 @@ void SkSLSlide::draw(SkCanvas* canvas) {
return;
}
bool writeTrace = false;
bool writeDump = false;
if (!canvas->recordingContext()) {
ImGui::InputInt2("Trace Coordinate (X/Y)", fTraceCoord);
writeTrace = ImGui::Button("Write Debug Trace (JSON)");
writeDump = ImGui::Button("Write Debug Dump (Human-Readable)");
}
// Update fMousePos
ImVec2 mousePos = ImGui::GetMousePos();
if (ImGui::IsMouseDown(0)) {
@ -246,9 +255,17 @@ void SkSLSlide::draw(SkCanvas* canvas) {
ImGui::End();
auto inputs = SkData::MakeWithoutCopy(fInputs.get(), fEffect->uniformSize());
sk_sp<SkSL::DebugTrace> debugTrace;
auto shader = fEffect->makeShader(std::move(inputs), fChildren.data(), fChildren.count(),
nullptr, false);
if (writeTrace || writeDump) {
SkIPoint traceCoord = {fTraceCoord[0], fTraceCoord[1]};
SkRuntimeEffect::TracedShader traced = SkRuntimeEffect::MakeTraced(std::move(shader),
traceCoord);
shader = std::move(traced.shader);
debugTrace = std::move(traced.debugTrace);
}
SkPaint p;
p.setColor4f(gPaintColor);
p.setShader(std::move(shader));
@ -274,6 +291,15 @@ void SkSLSlide::draw(SkCanvas* canvas) {
} break;
default: break;
}
if (debugTrace && writeTrace) {
SkFILEWStream traceFile("SkVMDebugTrace.json");
debugTrace->writeTrace(&traceFile);
}
if (debugTrace && writeDump) {
SkFILEWStream dumpFile("SkVMDebugTrace.dump.txt");
debugTrace->dump(&dumpFile);
}
}
bool SkSLSlide::animate(double nanos) {

View File

@ -51,6 +51,7 @@ private:
int fGeometry = kFill;
SkV3 fResolution = { 1, 1, 1 };
SkV4 fMousePos;
int fTraceCoord[2] = {64, 64};
// Named shaders that can be selected as inputs
SkTArray<std::pair<const char*, sk_sp<SkShader>>> fShaders;