27#include <unordered_map>
28#include <unordered_set>
36 auto debugTrace = sk_make_sp<SkSL::DebugTracePriv>();
42 std::unique_ptr<SkSL::Program> program =
55 *program, *
main->definition(), debugTrace.get(),
true);
60 static constexpr float kCoordinates[4] = {0.5f, 0.5f, 0.0f, 1.0f};
62 rasterProg->appendStages(&pipeline,
66 pipeline.
run(0, 0, 1, 1);
78 const char* separator =
"";
79 for (
int frame : callStack) {
95 const std::vector<SkSL::SkSLDebugTracePlayer::VariableData>&
vars) {
101 if (var.fSlotIndex < 0 || (
size_t)var.fSlotIndex >= trace.
fSlotInfo.size()) {
107 text += var.fDirty ?
"##" :
"";
130 player.
reset(
nullptr);
144half4 main(float2 xy) { // Line 2
145 return half4(2 + 2); // Line 3
178 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
179 "4, ##[main].result.w = 4");
185half4 main(float2 xy) { // Line 2
186 return half4(2 + 2); // Line 3
218DEF_TEST(SkSLTracePlayerFunctions, r) {
222 return 2 + 2; // Line 3
225 return fnB(); // Line 6
227half4 main(float2 xy) { // Line 8
228 return half4(fnA()); // Line 9
259 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
260 "4, ##[main].result.w = 4");
281 make_stack_string(*trace, player) ==
"half4 main(float2 xy) -> int fnA() -> int fnB()");
304 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
305 "4, ##[main].result.w = 4");
308DEF_TEST(SkSLTracePlayerVariables, r) {
311float func() { // Line 2
312 float x = 4, y = 5, z = 6; // Line 3
315half4 main(float2 xy) { // Line 6
316 int a = 123; // Line 7
317 bool b = true; // Line 8
319 float4 c = float4(0, 0.5, 1, -1); // Line 10
320 float3x3 d = float3x3(2); // Line 11
321 return half4(a); // Line 12
331 {{3, 1}, {4, 1}, {7, 1}, {8, 1}, {9, 1}, {10, 1}, {11, 1}, {12, 1}}));
349 "##b = true, a = 123, xy.x = 0.5, xy.y = 0.5");
368 "##[func].result = 6, b = true, a = 123, xy.x = 0.5, xy.y = 0.5");
382 "##c.x = 0, ##c.y = 0.5, ##c.z = 1, ##c.w = -1, b = true, a = 123, "
383 "xy.x = 0.5, xy.y = 0.5");
390 "##d[0][0] = 2, ##d[0][1] = 0, ##d[0][2] = 0, "
391 "##d[1][0] = 0, ##d[1][1] = 2, ##d[1][2] = 0, "
392 "##d[2][0] = 0, ##d[2][1] = 0, ##d[2][2] = 2, "
393 "c.x = 0, c.y = 0.5, c.z = 1, c.w = -1, b = true, a = 123, "
394 "xy.x = 0.5, xy.y = 0.5");
401 "##[main].result.x = 123, ##[main].result.y = 123, "
402 "##[main].result.z = 123, ##[main].result.w = 123");
405DEF_TEST(SkSLTracePlayerVariableGroups, r) {
408struct S { int x, y, z; }; // Line 2
409half4 main(float2 xy) { // Line 3
411 int arr[3]; // Line 5
413 arr[1] = 2; // Line 7
415 arr[2] = 4; // Line 9
416 return half4(0); // Line 10
431 "##s.x = 0, ##s.y = 0, ##s.z = 0, xy.x = 0.5, xy.y = 0.5");
437 "##arr[0] = 0, ##arr[1] = 0, ##arr[2] = 0, s.x = 0, s.y = 0, s.z = "
438 "0, xy.x = 0.5, xy.y = 0.5");
444 "s.x = 0, ##s.y = 1, s.z = 0, arr[0] = 0, arr[1] = 0, arr[2] = 0, "
445 "xy.x = 0.5, xy.y = 0.5");
451 "arr[0] = 0, ##arr[1] = 2, arr[2] = 0, s.x = 0, s.y = 1, s.z = 0, "
452 "xy.x = 0.5, xy.y = 0.5");
458 "##s.x = 3, s.y = 1, s.z = 0, arr[0] = 0, arr[1] = 2, arr[2] = 0, "
459 "xy.x = 0.5, xy.y = 0.5");
465 "arr[0] = 0, arr[1] = 2, ##arr[2] = 4, s.x = 3, s.y = 1, s.z = 0, "
466 "xy.x = 0.5, xy.y = 0.5");
469DEF_TEST(SkSLTracePlayerIfStatement, r) {
472half4 main(float2 xy) { // Line 2
474 if (true) { // Line 4
475 int temp = 1; // Line 5
476 val = temp; // Line 6
480 if (false) { // Line 10
481 int temp = 3; // Line 11
482 val = temp; // Line 12
486 return half4(val); // Line 16
495 LineNumberMap({{3, 1}, {4, 1}, {5, 1}, {6, 1}, {10, 1}, {14, 1}, {16, 1}}));
514 "##temp = 1, val = 0, xy.x = 0.5, xy.y = 0.5");
536 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
537 "4, ##[main].result.w = 4");
540DEF_TEST(SkSLTracePlayerForLoop, r) {
543half4 main(float2 xy) { // Line 2
544 int val = 0; // Line 3
545 for (int x = 1; x < 3; ++x) { // Line 4
548 return half4(val); // Line 7
612 "##[main].result.x = 2, ##[main].result.y = 2, ##[main].result.z = "
613 "2, ##[main].result.w = 2");
616DEF_TEST(SkSLTracePlayerStepOut, r) {
620 int a = 11; // Line 3
621 int b = 22; // Line 4
622 int c = 33; // Line 5
623 int d = 44; // Line 6
626half4 main(float2 xy) { // Line 9
627 return half4(fn()); // Line 10
634 LineNumberMap({{3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {10, 1}}));
669 "##[main].result.x = 44, ##[main].result.y = 44, ##[main].result.z "
670 "= 44, ##[main].result.w = 44");
673DEF_TEST(SkSLTracePlayerVariableScope, r) {
676half4 main(float2 xy) { // Line 2
685 int e = 5; // Line 11
687 int f = 6; // Line 13
689 int g = 7; // Line 15
691 int h = 8; // Line 17
693 int i = 9; // Line 19
694 return half4(0); // Line 20
743 "##f = 6, e = 5, a = 1, xy.x = 0.5, xy.y = 0.5");
749 "f = 6, e = 5, a = 1, xy.x = 0.5, xy.y = 0.5");
760 "##i = 9, e = 5, a = 1, xy.x = 0.5, xy.y = 0.5");
766DEF_TEST(SkSLTracePlayerNestedBlocks, r) {
769half4 main(float2 xy) { // Line 2
773 return half4(0); // Line 6
789DEF_TEST(SkSLTracePlayerSwitchStatement, r) {
792half4 main(float2 xy) { // Line 2
794 switch (x) { // Line 4
803 return half4(x); // Line 13
828DEF_TEST(SkSLTracePlayerBreakpoint, r) {
831int counter = 0; // Line 2
832void func() { // Line 3
833 --counter; // Line 4 BREAKPOINT 4 5
835half4 main(float2 xy) { // Line 6
836 for (int x = 1; x <= 3; ++x) { // Line 7
837 ++counter; // Line 8 BREAKPOINT 1 2 3
841 ++counter; // Line 12 BREAKPOINT 6
842 return half4(counter); // Line 13
882DEF_TEST(SkSLTracePlayerStepOverWithBreakpoint, r) {
885int counter = 0; // Line 2
886void func() { // Line 3
887 ++counter; // Line 4 BREAKPOINT
889half4 main(float2 xy) { // Line 6
891 return half4(counter); // Line 8
913DEF_TEST(SkSLTracePlayerStepOutWithBreakpoint, r) {
916int counter = 0; // Line 2
917void func() { // Line 3
920 ++counter; // Line 6 BREAKPOINT
922half4 main(float2 xy) { // Line 8
924 return half4(counter); // Line 10
static std::string make_stack_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
static std::string make_vars_string(const SkSL::DebugTracePriv &trace, const std::vector< SkSL::SkSLDebugTracePlayer::VariableData > &vars)
SkSL::SkSLDebugTracePlayer::LineNumberMap LineNumberMap
static std::string make_global_vars_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
DEF_TEST(SkSLTracePlayerCanResetToNull, r)
static std::string make_local_vars_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
static sk_sp< SkSL::DebugTracePriv > make_trace(skiatest::Reporter *r, std::string src)
#define REPORTER_ASSERT(r, cond,...)
void run(size_t x, size_t y, size_t w, size_t h) const
void appendConstantColor(SkArenaAlloc *, const float rgba[4])
std::vector< FunctionDebugInfo > fFuncInfo
std::vector< SlotDebugInfo > fSlotInfo
std::string slotValueToString(int slotIndex, double value) const
std::string getSlotComponentSuffix(int slotIndex) const
int getStackDepth() const
const LineNumberMap & getLineNumbersReached() const
void reset(sk_sp< DebugTracePriv > trace)
std::vector< VariableData > getGlobalVariables() const
std::vector< VariableData > getLocalVariables(int stackFrameIndex) const
int32_t getCurrentLineInStackFrame(int stackFrameIndex) const
std::unordered_map< int, int > LineNumberMap
void setBreakpoints(std::unordered_set< int > breakpointLines)
bool traceHasCompleted() const
int32_t getCurrentLine() const
std::vector< int > getCallStack() const
std::string void void auto Separator()
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)