diff --git a/apps/resolution-time/README.md b/apps/resolution-time/README.md new file mode 100644 index 0000000000..3a1ba58c28 --- /dev/null +++ b/apps/resolution-time/README.md @@ -0,0 +1,62 @@ +# Procedural TypeGPU function generator for benchmarking resolution time + +## Adding a new instruction + +Each instruction is a `tgpu.comptime` that returns a `tgpu.fn(() => void)`. There are two kinds: **leaf** (no function calls) and **recursive** (branches into other instructions). + +### Leaf instruction + +```ts +const myLeafFn = tgpu.comptime(() => { + return tgpu.fn(() => { + 'use gpu'; + // ... + popDepth(); // REQUIRED — always call at the end + }).$name('myLeafFn'); +}); +``` + +### Recursive instruction + +Use `tgpu.unroll` over `arrayForUnroll(BRANCHING)` and call `instructions[choice()]()()` to branch into other instructions. The `choice()` function handles depth tracking and picks a leaf when at max depth. + +```ts +const myRecursiveFn = tgpu.comptime(() => { + return tgpu.fn(() => { + 'use gpu'; + // ... + for (const _i of tgpu.unroll(arrayForUnroll(BRANCHING))) { + instructions[choice()]()(); + } + popDepth(); // REQUIRED — always call at the end, after the unroll + }).$name('myRecursiveFn'); +}); +``` + +## Generating Mermaid charts + +`generateChart.ts` reads benchmark result JSON files and outputs a Mermaid xychart comparing up to 3 datasets. + +### Usage + +```sh +node generateChart.ts \ + --input "PR:pr-branch/results-max-depth.json" \ + --input "main:main-branch/results-max-depth.json" \ + --title "Resolution Time vs Max Depth" \ + --xAxisTitle "max depth" \ + --yAxisTitle "time (ms)" \ + --output chart.md +``` + +### Arguments + +| Argument | Required | Description | +|---|---|---| +| `--input