Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use LF everywhere
* text=auto eol=lf
22 changes: 2 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,2 @@
# dependency packages
node_modules

# bundled release
dist

# macOS
.DS_Store

# vi temp files
*.swp

# typescript build info cache files
*.tsbuildinfo

# output file for esbuild meta.data for bundle size analysis
meta.json

# output file for rollup-plugin-visualizer
stats.html
dist/
node_modules/
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"deno.lint": true,
"[typescript]": { "editor.defaultFormatter": "denoland.vscode-deno" }
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ The linker will rename one of them, and all the calls to the renamed function.
You get only that function and its references, not the whole file.

**wgsl-linker** is currently being revised to follow the upcoming community [WESL standard](https://github.com/wgsl-tooling-wg/wesl-spec).

## Development

Deno is used for almost everything.
- `deno install` for setup
- `deno lint` for linting
- `deno fmt` for formatting
- `deno test --allow-read` to run the unit tests
- To update the snapshots, run `deno test --allow-all -- --update`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all deno! 🦕

I guess that unified tooling aspect is reasonably nice. Hopefully the Node.js ecosystem will catch up and also get more unified tooling.

4 changes: 2 additions & 2 deletions packages/bench/README.md → bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Launch with:

```sh
pnpm tsx --inspect-brk bin/bench.ts --profile
deno --allow-read --allow-env --inspect-brk bench.ts --profile
```

And then launch the chrome debugger and press the green node button, and press play
Expand All @@ -15,5 +15,5 @@ See instructions [here](https://developer.chrome.com/docs/devtools/performance/n
## Benchmark

```sh
pnpm tsx bin/bench.ts --bench
deno --allow-read --allow-env bench.ts --bench
```
29 changes: 15 additions & 14 deletions packages/bench/bin/bench.ts → bench/bench.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env -S deno run --allow-read --allow-env

import { WGSLLinker } from "@use-gpu/shader";
import fs from "fs/promises";
import path from "path";
import { ModuleRegistry } from "wgsl-linker";
import * as path from "@std/path";
import { ModuleRegistry } from "@wesl/linker";
import { WgslReflect } from "wgsl_reflect";
import yargs from "yargs";

import { hideBin } from "yargs/helpers";
import { profile, profileEnd } from "node:console";

type ParserVariant =
| "wgsl-linker"
Expand All @@ -16,8 +16,9 @@ type ParserVariant =

type CliArgs = ReturnType<typeof parseArgs>;

const rawArgs = hideBin(process.argv);
main(rawArgs);
if (import.meta.main) {
await main(Deno.args);
}

async function main(args: string[]): Promise<void> {
const argv = parseArgs(args);
Expand Down Expand Up @@ -52,17 +53,17 @@ async function bench(argv: CliArgs): Promise<void> {
if (argv.bench) {
const ms = runBench(variant, texts);
const codeLines = texts
.map(t => t.text.split("\n").length)
.map((t) => t.text.split("\n").length)
.reduce((a, b) => a + b, 0);
const locSec = codeLines / ms;
const locSecStr = new Intl.NumberFormat().format(Math.round(locSec));
console.log(`${variant} LOC/sec: ${locSecStr}`);
}

if (argv.profile) {
console.profile();
profile();
runOnAllFiles(variant, texts);
console.profileEnd();
profileEnd();
}
}

Expand Down Expand Up @@ -121,24 +122,24 @@ async function loadAllFiles(): Promise<LoadedFile[]> {
// return [...boat];
const reduceBuffer = await loadFile(
"reduceBuffer",
"./src/examples/reduceBuffer.wgsl",
"./examples/reduceBuffer.wgsl",
);
const particle = await loadFile(
"reduceBuffer",
"../../../community-wgsl/webgpu-samples/sample/particles/particle.wgsl",
"../../community-wgsl/webgpu-samples/sample/particles/particle.wgsl",
);
return [reduceBuffer, particle];
}

async function loadFile(name: string, path: string): Promise<LoadedFile> {
const text = await fs.readFile(path, { encoding: "utf8" });
const text = await Deno.readTextFile(path);

return { name, text };
}

async function loadBoatFiles(): Promise<LoadedFile[]> {
const boatAttackDir =
"../../../community-wgsl/unity_web_research/webgpu/wgsl/boat_attack";
"../../community-wgsl/unity_web_research/webgpu/wgsl/boat_attack";

const boatName = "unity_webgpu_0000026E5689B260.fs.wgsl";
const boatPath = path.join(boatAttackDir, boatName);
Expand Down
14 changes: 14 additions & 0 deletions bench/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.1.0",
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@std/fs": "jsr:@std/fs",
"@std/path": "jsr:@std/path",
"yargs": "https://deno.land/x/yargs@v17.7.2-deno/deno.ts",
"diff": "npm:diff",
"wgsl_reflect": "npm:wgsl_reflect@1.0.16",
"@use-gpu/shader": "npm:@use-gpu/shader@0.12.0"
}
}
2 changes: 1 addition & 1 deletion packages/bulk-test/README.md → bulk-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Test the parser/linker on community projects.

```sh
pnpm bulk-test
deno test --allow-read
```
11 changes: 11 additions & 0 deletions bulk-test/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.1.0",
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@std/fs": "jsr:@std/fs",
"@std/path": "jsr:@std/path",
"diff": "npm:diff"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { glob } from "glob";
import path from "node:path";
import { BulkTest, bulkTests } from "wesl-testsuite";
import { NamedPath } from "./parallelTest.ts";
import * as path from "@std/path";
import { expandGlob } from "@std/fs";

/* Vitest parallelizes per .test.ts file.
*
Expand All @@ -12,7 +12,7 @@ import { NamedPath } from "./parallelTest.ts";
* 16 parts, which we'll later use in 16 .test.ts runners.
*/

const communityRoot = path.join("..", "..", "..", "community-wgsl");
const communityRoot = path.join("..", "..", "community-wgsl");
const numParts = 16;
const allPaths = await loadTests();

Expand All @@ -37,7 +37,7 @@ async function loadBulkSet(bulk: BulkTest): Promise<NamedPath[]> {
bulk.exclude,
);
const relativePaths: string[] = [...includeFiles, ...globFiles];
const namePaths: NamedPath[] = relativePaths.map(f => ({
const namePaths: NamedPath[] = relativePaths.map((f) => ({
name: f,
filePath: path.join(baseDir, f),
}));
Expand All @@ -49,19 +49,19 @@ async function findGlobFiles(
globs: string[] | undefined,
exclude: string[] | undefined,
): Promise<string[]> {
const fullBaseDir = path.resolve(baseDir);
const cwd = process.cwd();
const skip = exclude ?? [];
try {
process.chdir(fullBaseDir);
const futurePaths =
globs?.map(g => glob(g, { ignore: ["node_modules/**"] })) ?? [];
const pathSets = await Promise.all(futurePaths);
const filePaths = pathSets.flat();
return filePaths.filter(p => !skip.some(s => p.includes(s)));
} finally {
process.chdir(cwd);
}
const futurePaths = (globs ?? []).map((g) =>
Array.fromAsync(expandGlob(g, {
root: baseDir,
exclude: ["node_modules/**"],
}))
);

const pathSets = await Promise.all(futurePaths);
const filePaths = pathSets.flat().filter((f) => f.isFile).map((f) =>
path.relative(baseDir, f.path)
);
return filePaths.filter((p) => !skip.some((s) => p.includes(s)));
}

/** split an array into n partitions */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "node:fs/promises";
import { test } from "vitest";
import { ModuleRegistry } from "wgsl-linker";
import { ModuleRegistry } from "@wesl/linker";

export interface NamedPath {
name: string; // test name
Expand All @@ -16,7 +15,7 @@ export function testWgslFiles(namedPaths: NamedPath[]) {
namedPaths.forEach(({ name, filePath }) => {
const shortPath = "./" + name;
test(name, async () => {
const text = await fs.readFile(filePath, { encoding: "utf8" });
const text = await Deno.readTextFile(filePath);
const registry = new ModuleRegistry({ wgsl: { [shortPath]: text } });
registry.parsed();
// registry.link(shortPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { dlogOpt } from "berry-pretty";
import { uniquishFiles } from "../src/util/uniqueDocs.js";
import { uniquishFiles } from "./util/uniqueDocs.ts";

/* The boat_attack sample shaders have significantly internal duplication
* This script tries to find the relatively unique shaders for testing.
Expand All @@ -21,8 +20,8 @@ const uniqueHlsl = await uniquishFiles({
// limitSearch: 100,
// limitCheck: 5
});
const wgsl = uniqueHlsl.map(p => p.replace(/hlsl$/, "wgsl"));
dlogOpt({ maxArray: 500 }, { wgsl });
const wgsl = uniqueHlsl.map((p) => p.replace(/hlsl$/, "wgsl"));
console.log({ maxArray: 500 }, { wgsl });

function removeDirectiveLines(text: string): string {
return text.replace(/^#.*$/gm, "");
Expand Down
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-0.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[0]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[1]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-10.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[10]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-11.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[11]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-12.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[12]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-13.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[13]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-14.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[14]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-15.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[15]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[2]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[3]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[4]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-5.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[5]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-6.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[6]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-7.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[7]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-8.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[8]);
4 changes: 4 additions & 0 deletions bulk-test/test/parallel-9.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathSets } from "../parallelDriver.ts";
import { testWgslFiles } from "../parallelTest.ts";

testWgslFiles(pathSets[9]);
Loading