Symbols in this topic
ResolvedShader and ShaderSource
Data shapes returned or consumed by the WGSL helpers. Use ResolvedShader for compile() output and ShaderSource for loader-emitted .wgsl modules.
Import
TypeScript
1
import type { ResolvedShader, ShaderSource, SourceMap, WGSLAst, WGSLSource } from "@vgpu/wgsl";Signature
TypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
interface ShaderSource {
readonly version: 1;
readonly wgsl: string;
}
interface WGSLSource {
readonly text: string;
readonly path?: string;
readonly imports?: readonly { readonly path: string; readonly from: string }[];
}
interface SourceMap {
readonly version: 1;
readonly mappings: readonly [];
}
interface WGSLAst {
readonly version: 1;
readonly modules: readonly [{ readonly path: string; readonly text: string }];
readonly diagnostics: readonly [];
readonly sourceMap: SourceMap;
readonly cacheKey: Record<string, string>;
}
interface ResolvedShader {
readonly kind: "wgsl";
readonly wgsl: string;
readonly source: WGSLSource;
readonly ast: WGSLAst;
readonly sourceMap: SourceMap;
readonly diagnostics: readonly [];
readonly cacheKey: Record<string, string>;
readonly entryPoints: readonly string[];
readonly stats: { readonly lines: number; readonly bytes: number; readonly bindGroups: number };
}Parameters
ResolvedShader fields:
| Param | Type | Required | Default | Notes |
|---|---|---|---|---|
| kind | "wgsl" | ✔ | — | Discriminant for WGSL shader data returned by compile(). |
| wgsl | string | ✔ | — | Original source string passed to compile(). |
| source | WGSLSource | ✔ | — | Runtime source metadata. compile() sets text to the input, path to "<runtime>", and imports to []. |
| ast | WGSLAst | ✔ | — | Lightweight passthrough AST metadata with one runtime module and no diagnostics. |
| sourceMap | SourceMap | ✔ | — | Passthrough v1 source map with empty mappings. |
| diagnostics | readonly [] | ✔ | — | Always empty for compile() output. |
| cacheKey | Record<string, string> | ✔ | — | Deterministic FNV-style key in the form vgpu-wgsl-1:<hash> under default. |
| entryPoints | readonly string[] | ✔ | — | Names matched by `@(vertex |
| stats | { lines: number; bytes: number; bindGroups: number } | ✔ | — | Line count, UTF-8 byte length, and bindGroups: 0. |
ShaderSource fields:
| Param | Type | Required | Default | Notes |
|---|---|---|---|---|
| version | 1 | ✔ | — | Loader artifact version. |
| wgsl | string | ✔ | — | Plain WGSL emitted by a loader or resolver. |
Returns: These are TypeScript interfaces, not callables. They return nothing.
Throws: These type declarations throw nothing. compile() throws before constructing ResolvedShader when runtime WGSL contains a top-level import.
Examples
TypeScript
1
2
3
4
5
6
7
8
9
10
11
import { compile, type ResolvedShader, type ShaderSource } from "@vgpu/wgsl";
const resolved: ResolvedShader = compile(`
@fragment
fn fs_main() -> @location(0) vec4f {
return vec4f(1.0, 0.0, 0.0, 1.0);
}
`);
const source: ShaderSource = { version: 1, wgsl: resolved.wgsl };
console.log(source.version, resolved.entryPoints[0]);TypeScript
1
2
3
4
5
6
7
8
9
10
import type { ShaderSource } from "@vgpu/wgsl";
function acceptsLoaderOutput(shader: ShaderSource): string {
return shader.wgsl;
}
acceptsLoaderOutput({
version: 1,
wgsl: "@compute @workgroup_size(1) fn main() {}",
});Notes
ShaderSourcev1 is exactly{ version: 1, wgsl: string }. It has nobindings, reflection, layouts, or cache metadata;bindingsis reserved for a future version bump.- Treat
ResolvedShaderfields as read-only data. Do not patch placeholder AST internals to represent imports; useresolveShader()for import graphs. compile()output does not prove WGSL validity. It only packages the string and rejects top-levelimport.- Pure-module contract for resolver graphs: imported modules may export structs/functions/constants/aliases, but no imported module may declare
@group/@binding; declare resources only in the entry module. - See also:
compile,resolveShader,wgslVitePlugin,wgslWebpackLoader.