@vcollab/shader-library 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -0
- package/LICENSE +8 -0
- package/README.md +111 -2
- package/dist/bind.d.ts +53 -0
- package/dist/blocks.d.ts +73 -0
- package/dist/bundled.cjs +272 -0
- package/dist/bundled.cjs.map +1 -0
- package/dist/bundled.d.ts +6 -0
- package/dist/bundled.js +22 -0
- package/dist/bundled.js.map +1 -0
- package/dist/chunk-A73KYX6T.js +298 -0
- package/dist/chunk-A73KYX6T.js.map +1 -0
- package/dist/derived/dispatch.d.ts +80 -0
- package/dist/derived/errors.d.ts +4 -0
- package/dist/derived/index.cjs +451 -0
- package/dist/derived/index.cjs.map +1 -0
- package/dist/derived/index.d.ts +62 -0
- package/dist/derived/index.js +417 -0
- package/dist/derived/index.js.map +1 -0
- package/dist/derived/kernels.d.ts +73 -0
- package/dist/encoding.d.ts +39 -0
- package/dist/index.cjs +736 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +418 -0
- package/dist/index.js.map +1 -0
- package/dist/load.d.ts +60 -0
- package/dist/manifest.d.ts +213 -0
- package/dist/pack.d.ts +69 -0
- package/dist/pick.d.ts +89 -0
- package/dist/select.d.ts +47 -0
- package/dist/version.d.ts +2 -0
- package/package.json +70 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@vcollab/shader-library` are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
6
|
+
this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] — 2026-12-06
|
|
9
|
+
|
|
10
|
+
Released with `@vcollab/shader-artifacts` 2.0.0, which carries the 9.0.0 set.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `TableBlocks`: gives each occurrence of a mesh a block of rows in a scene
|
|
15
|
+
table — its base is the `u_maskLutBase` its draws are made with — and
|
|
16
|
+
`locate` turns a picked `groupId` back into the occurrence (`owner`) and
|
|
17
|
+
the mesh-local id (`offset`). Append-only; refuses a table past
|
|
18
|
+
`maxRows`, at most 2³¹. With `BlockRow` and `TableBlockError`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- An envelope is refused unless its capabilities are exactly those of the
|
|
23
|
+
index entry that selected it. The carried `contractSha256` is compared as a
|
|
24
|
+
string, so it did not show a mismatch.
|
|
25
|
+
- An index entry is refused if it carries a tag `capabilityVocabulary` does
|
|
26
|
+
not declare.
|
|
27
|
+
- The pick texel's third channel is the group id: `PICK_CHANNELS` reads
|
|
28
|
+
`["primitiveId", "depth", "groupId", "reserved"]`, and `Pick` and
|
|
29
|
+
`decodePick` carry `groupId`, the scene atom `a_atomId + u_maskLutBase`
|
|
30
|
+
that the 9.0.0 set's pick pipelines write. It names the occurrence as well
|
|
31
|
+
as the atom when each occurrence is drawn with its own block of the scene
|
|
32
|
+
mask.
|
|
33
|
+
|
|
34
|
+
### Security
|
|
35
|
+
|
|
36
|
+
- Set paths are confined to the set. An envelope path must be a plain
|
|
37
|
+
relative POSIX path — the rule the foundry and the importer apply — and is
|
|
38
|
+
checked when the index is read and again by `fsSource` and `fetchSource`
|
|
39
|
+
before any read. `fetchSource` also refuses a request outside the base URL's
|
|
40
|
+
origin and path, which a percent-encoded `..` would otherwise reach. Before,
|
|
41
|
+
an index entry could read a file outside an `fsSource` directory, or send
|
|
42
|
+
`fetchSource`'s request headers to another origin.
|
|
43
|
+
|
|
44
|
+
## [1.0.0] — 2026-12-03
|
|
45
|
+
|
|
46
|
+
First release. The package is a consumer of the artifact set emitted by
|
|
47
|
+
`vcti-shader-foundry` (schema 3), and composes no shader text of its own.
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
|
|
51
|
+
- `ShaderSet` for reading an artifact set: the index eagerly, envelopes on
|
|
52
|
+
demand and cached, with the schema version and each envelope's
|
|
53
|
+
`contractSha256` checked against the index entry that pointed at it. A
|
|
54
|
+
document's structure is checked when it is loaded and refused with
|
|
55
|
+
`ShaderSetError`: a missing or non-array `capabilityVocabulary`, an entry
|
|
56
|
+
missing a field, a capability list that repeats a tag, a repeated pipeline
|
|
57
|
+
id, an envelope with no `languages`, a language block missing `blockSize`,
|
|
58
|
+
`layout`, `bindings` or `stages`, and a layout member whose offset is not a
|
|
59
|
+
non-negative multiple of 4, whose recorded extent leaves the block, or whose
|
|
60
|
+
encoding the packer does not write. Nothing is recomputed from std140 rules.
|
|
61
|
+
- `ArtifactSource` with `fetchSource` and `fsSource` adapters, and
|
|
62
|
+
`bundledSource` / `openBundledSet` at `@vcollab/shader-library/bundled` for
|
|
63
|
+
the set shipped in `@vcollab/shader-artifacts`. `fetchSource` resolves a
|
|
64
|
+
relative base URL against `location.href` in a browser, and asks for an
|
|
65
|
+
absolute URL where there is no location.
|
|
66
|
+
- `resolvePipeline` and the exact capability match, compared as sets, plus
|
|
67
|
+
`matchCapabilities`, `withCapabilities`, `capabilitiesInUse` and
|
|
68
|
+
`validateCapabilities` for building a chooser. Nothing is ranked.
|
|
69
|
+
- `UniformBlock`, a std140 writer driven by the layout and block size the build
|
|
70
|
+
reported. It refuses an encoding it does not write, and a non-integer or
|
|
71
|
+
out-of-range value for an `int` or `uint` member, rather than truncating or
|
|
72
|
+
wrapping it. Matrices are written so the shaders apply the caller's
|
|
73
|
+
transform: the block declares them `row_major`, but the emitted GLSL
|
|
74
|
+
multiplies row-vector-first, so a column-major input goes in untransposed.
|
|
75
|
+
`majorness` describes the input array's own order; it is not a way to ask
|
|
76
|
+
for a transpose.
|
|
77
|
+
- `ResourceBindings`, resolving a table or texture's semantic to the sampler
|
|
78
|
+
uniform the linked program carries and its texture unit.
|
|
79
|
+
- The pick module: `pickPipelineFor` pairs a color pipeline with the pick
|
|
80
|
+
pipeline whose vertex stage matches it, deform variant included, and throws
|
|
81
|
+
`PipelineSelectionError` when none does; `decodePick` reads one texel of the
|
|
82
|
+
`rgba32ui` pick readback. With `Pick`, `PICK_CAPABILITY`, `PICK_EMPTY`,
|
|
83
|
+
`PICK_RESERVED`, `PICK_CHANNELS` and `PickDecodeError`.
|
|
84
|
+
- Types mirroring the emitted documents, and `SCHEMA_VERSION`.
|
|
85
|
+
- `@vcollab/shader-library/derived`: the derived-quantity math on the CPU for
|
|
86
|
+
all four families, with the dispatch integers and `dispatchTable(family)`,
|
|
87
|
+
pinned to `vcti.derived` by tests over exported reference vectors. A datum
|
|
88
|
+
with any NaN component gives NaN for every derived type, as `vcti.derived`
|
|
89
|
+
does for a masked row; an infinite component throws `DerivedError` for the
|
|
90
|
+
principal-based types, as its eigen-solver raises; an `order` that is not a
|
|
91
|
+
permutation of the family's slots throws `DerivedError`. Lookups by name use
|
|
92
|
+
own properties only, so `"constructor"` is not a derived type.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2018-2026 Visual Collaboration Technologies Inc.
|
|
2
|
+
All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
This software is proprietary and confidential. Unauthorized copying,
|
|
5
|
+
distribution, or use of this software, via any medium, is strictly
|
|
6
|
+
prohibited. Access is granted only to authorized VCollab developers
|
|
7
|
+
and individuals explicitly authorized by Visual Collaboration
|
|
8
|
+
Technologies Inc.
|
package/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vcollab/shader-library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The runtime side of the VCollab shader system: read the artifact set, choose a
|
|
4
|
+
pipeline, pack its uniforms, bind its resources.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
VCollab's GPU shaders are not written here. They are built offline by
|
|
9
|
+
`vcti-shader-foundry` from composable shader features — mask, deform,
|
|
10
|
+
transform, derive, fringe, clip, cap, pick and material — and shipped as an
|
|
11
|
+
**artifact set** — an index, one self-contained envelope per pipeline, and the
|
|
12
|
+
emitted GLSL ES 3.00. The governing principle of that system is that
|
|
13
|
+
**generated artifacts are the runtime API**: nothing is composed, templated or
|
|
14
|
+
compiled at runtime, and this package is deliberately incapable of doing so.
|
|
15
|
+
|
|
16
|
+
What it does is the things a consumer of that set has to get right:
|
|
17
|
+
|
|
18
|
+
- **Read** the set — the index once, an envelope per pipeline drawn — and check
|
|
19
|
+
that the envelope received is the one the index pointed at.
|
|
20
|
+
- **Choose** a pipeline by matching capabilities exactly, without ranking.
|
|
21
|
+
- **Pack** the uniform block at the offsets the build reported, rather than at
|
|
22
|
+
offsets recomputed from the declared types.
|
|
23
|
+
- **Bind** tables and textures by semantic, because the names a shader declares
|
|
24
|
+
them under never reach the linked program.
|
|
25
|
+
- **Pick** with the pick pipeline whose vertex stage matches the color pass,
|
|
26
|
+
and decode the integer texel it writes.
|
|
27
|
+
- **Place** each occurrence of a mesh in rows of the scene tables of its own,
|
|
28
|
+
and turn a picked group id back into the occurrence and the atom.
|
|
29
|
+
|
|
30
|
+
It creates no GPU resources and touches no context — that is the renderer's
|
|
31
|
+
job. The derived-quantity math the shaders compute is also here, on the CPU,
|
|
32
|
+
for the value range a consumer must know before it can choose fringe bands.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @vcollab/shader-library
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`@vcollab/shader-artifacts` carries the artifact set. It is a normal dependency,
|
|
41
|
+
so it is always installed with this package. Only the `/bundled` entry point
|
|
42
|
+
imports it, so a consumer that serves its own set over HTTP and does not import
|
|
43
|
+
`/bundled` ships none of the set in its bundle.
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { ResourceBindings, ShaderSet, UniformBlock, resolvePipeline } from "@vcollab/shader-library";
|
|
49
|
+
import { openBundledSet } from "@vcollab/shader-library/bundled";
|
|
50
|
+
|
|
51
|
+
const set = await openBundledSet();
|
|
52
|
+
|
|
53
|
+
// Capabilities are matched exactly — a pipeline carrying one you did not ask
|
|
54
|
+
// for reads an attribute you did not bind.
|
|
55
|
+
const entry = resolvePipeline(set.registry, [
|
|
56
|
+
"deform3", "symtensor", "fringe-float",
|
|
57
|
+
"material", "material-table", "material-surface-finish",
|
|
58
|
+
"mask", "mask-lut-r8ui", "transform", "transform-lut-r32ui", "clip",
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const envelope = await set.envelope(entry.id);
|
|
62
|
+
const glsl = ShaderSet.language(envelope);
|
|
63
|
+
|
|
64
|
+
// The shader text, as built. Compile it; do not edit it.
|
|
65
|
+
const program = link(glsl.stages.vertex!.source, glsl.stages.fragment!.source);
|
|
66
|
+
|
|
67
|
+
// The block is larger than the contract: the compiler emits its whole global
|
|
68
|
+
// block whatever entry point was compiled. Allocate what the build reported.
|
|
69
|
+
const uniforms = new UniformBlock(glsl);
|
|
70
|
+
uniforms.set("u_mvpMatrix", mvp); // column-major in; the packer arranges the bytes
|
|
71
|
+
uniforms.set("u_colorSource", 2); // named states are in the contract
|
|
72
|
+
uniforms.set("u_clipPlaneCount", 0); // the off state of a feature that is always present
|
|
73
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Uint8Array(uniforms.buffer));
|
|
74
|
+
|
|
75
|
+
// Bind by semantic; the declared name is not what the program has.
|
|
76
|
+
const bindings = new ResourceBindings(glsl);
|
|
77
|
+
const mask = bindings.get("mask");
|
|
78
|
+
gl.activeTexture(gl.TEXTURE0 + mask.unit);
|
|
79
|
+
gl.bindTexture(gl.TEXTURE_2D, maskTable);
|
|
80
|
+
gl.uniform1i(gl.getUniformLocation(program, mask.uniform), mask.unit);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Serving the set yourself instead of bundling it:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { ShaderSet, fetchSource } from "@vcollab/shader-library";
|
|
87
|
+
|
|
88
|
+
const set = await ShaderSet.open(fetchSource("https://cdn.example.com/shaders/"));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The derived math, for the range the fringe bands span:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { computeDerivedField, fieldRange } from "@vcollab/shader-library/derived";
|
|
95
|
+
|
|
96
|
+
const range = fieldRange(computeDerivedField("symtensor", "von_mises", tensors));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Dependencies
|
|
100
|
+
|
|
101
|
+
`@vcollab/shader-artifacts` (the set) is a normal dependency. There are no peer
|
|
102
|
+
dependencies: this package does not touch a GPU context, a renderer or a
|
|
103
|
+
framework.
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
| If you want to… | Read |
|
|
108
|
+
|---|---|
|
|
109
|
+
| Understand the design and what this package does not do | [docs/design.md](docs/design.md) |
|
|
110
|
+
| Look up an export | [docs/api.md](docs/api.md) |
|
|
111
|
+
| See practical consumption patterns | [docs/patterns.md](docs/patterns.md) |
|
|
112
|
+
| Navigate and modify the source | [docs/source-guide.md](docs/source-guide.md) |
|
package/dist/bind.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binding tables and textures, by semantic.
|
|
3
|
+
*
|
|
4
|
+
* A table or texture is declared under a name in the shader source, and that
|
|
5
|
+
* name never reaches the linked program: GLSL ES 3.00 has no binding qualifier
|
|
6
|
+
* for samplers, so the cross-compiler pairs each texture with a sampler and
|
|
7
|
+
* names the combination itself — `u_maskLut` is declared, and what the program
|
|
8
|
+
* carries is `SPIRV_Cross_Combinedu_maskLutSPIRV_Cross_DummySampler`.
|
|
9
|
+
*
|
|
10
|
+
* So the declared name is not what a consumer binds by. The semantic is. Each
|
|
11
|
+
* envelope records, per emitted sampler uniform, the semantic it was built
|
|
12
|
+
* from, the uniform the program actually has, and a texture unit assigned at
|
|
13
|
+
* build. Bind the resource to that unit and set that uniform to it.
|
|
14
|
+
*/
|
|
15
|
+
import type { BindingRecord, LanguageBlock, ShaderStage } from "./manifest.js";
|
|
16
|
+
/** Raised when a resource cannot be bound as asked. */
|
|
17
|
+
export declare class BindingError extends Error {
|
|
18
|
+
readonly name = "BindingError";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One pipeline's sampler bindings, indexed by semantic.
|
|
22
|
+
*
|
|
23
|
+
* Built from the envelope's own `bindings`, which the build derived from the
|
|
24
|
+
* emitted text rather than from the contract — so it describes the program
|
|
25
|
+
* that exists, not the program that was intended.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ResourceBindings {
|
|
28
|
+
#private;
|
|
29
|
+
/** Every binding, in the order the envelope records them (units ascending). */
|
|
30
|
+
readonly all: readonly BindingRecord[];
|
|
31
|
+
constructor(block: LanguageBlock);
|
|
32
|
+
/** Every semantic this pipeline binds, sorted. */
|
|
33
|
+
get semantics(): string[];
|
|
34
|
+
/** How many texture units the pipeline spends in total. */
|
|
35
|
+
get unitCount(): number;
|
|
36
|
+
/** Whether the pipeline binds anything for `semantic`. */
|
|
37
|
+
has(semantic: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Every binding for `semantic` — more than one when the same resource is
|
|
40
|
+
* read in both stages, which the build gives separate units.
|
|
41
|
+
*/
|
|
42
|
+
forSemantic(semantic: string): readonly BindingRecord[];
|
|
43
|
+
/**
|
|
44
|
+
* The one binding for `semantic`.
|
|
45
|
+
*
|
|
46
|
+
* @throws {BindingError} if the pipeline binds nothing for it, or binds it
|
|
47
|
+
* in more than one stage — in which case use {@link forSemantic} and bind
|
|
48
|
+
* each.
|
|
49
|
+
*/
|
|
50
|
+
get(semantic: string): BindingRecord;
|
|
51
|
+
/** Every binding a given stage spends a unit on. */
|
|
52
|
+
forStage(stage: ShaderStage): readonly BindingRecord[];
|
|
53
|
+
}
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Giving each occurrence of a mesh its own rows of a scene table.
|
|
3
|
+
*
|
|
4
|
+
* A slab's atom ids are local to its mesh: `0 … n-1` in every slab. Two
|
|
5
|
+
* occurrences of one mesh drawn from one vertex buffer would read the same
|
|
6
|
+
* mask rows and pick as the same thing. The per-draw base uniforms solve that
|
|
7
|
+
* on the GPU — the shader reads row `a_atomId + u_maskLutBase` — and the pick
|
|
8
|
+
* pass writes that sum as the group id. What is left is bookkeeping on the
|
|
9
|
+
* CPU: hand each occurrence a block of rows that no other occurrence uses, set
|
|
10
|
+
* its base before its draw, and turn a picked group id back into the
|
|
11
|
+
* occurrence and the mesh-local atom. This does that bookkeeping, once.
|
|
12
|
+
*
|
|
13
|
+
* It is append-only. A scene that drops occurrences rebuilds its blocks (and
|
|
14
|
+
* its table) rather than leaving holes to be reused, which keeps a group id
|
|
15
|
+
* meaning one thing for as long as the table it indexes is the same.
|
|
16
|
+
*/
|
|
17
|
+
/** Raised for a block that cannot be given out. */
|
|
18
|
+
export declare class TableBlockError extends Error {
|
|
19
|
+
readonly name = "TableBlockError";
|
|
20
|
+
}
|
|
21
|
+
/** One row of a scene table, found by {@link TableBlocks.locate}. */
|
|
22
|
+
export interface BlockRow<T> {
|
|
23
|
+
/** Whoever the block was given to: an occurrence, as the caller names it. */
|
|
24
|
+
readonly owner: T;
|
|
25
|
+
/** The block's first row: the base its draws are made with. */
|
|
26
|
+
readonly base: number;
|
|
27
|
+
/** The row within the block: the mesh-local id, `row - base`. */
|
|
28
|
+
readonly offset: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Contiguous blocks of rows in one scene table, given out in order.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const blocks = new TableBlocks<Occurrence>();
|
|
35
|
+
* for (const occurrence of scene) occurrence.maskBase = blocks.allocate(mesh.atomCount, occurrence);
|
|
36
|
+
* // …build the scene mask, blocks.rows rows, each occurrence's at its base…
|
|
37
|
+
* const hit = pass.pick(x, y, drawScene);
|
|
38
|
+
* const found = hit && blocks.locate(hit.groupId); // { owner, base, offset }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class TableBlocks<T = unknown> {
|
|
42
|
+
#private;
|
|
43
|
+
/** The most rows the table may hold. */
|
|
44
|
+
readonly maxRows: number;
|
|
45
|
+
/**
|
|
46
|
+
* @param options.maxRows the most rows the table may hold — the capacity of
|
|
47
|
+
* the texture it will be uploaded to, say. At most, and by default, 2³¹:
|
|
48
|
+
* the shader adds the base to an `int`.
|
|
49
|
+
* @throws {TableBlockError} if `maxRows` is not a positive integer no larger
|
|
50
|
+
* than 2³¹.
|
|
51
|
+
*/
|
|
52
|
+
constructor(options?: {
|
|
53
|
+
maxRows?: number;
|
|
54
|
+
});
|
|
55
|
+
/** Rows given out so far: the size the table must be. */
|
|
56
|
+
get rows(): number;
|
|
57
|
+
/** How many blocks have been given out. */
|
|
58
|
+
get size(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Give out the next `rows` rows.
|
|
61
|
+
*
|
|
62
|
+
* @returns the block's base: the uniform to draw the owner with, and where
|
|
63
|
+
* its rows start in the table.
|
|
64
|
+
* @throws {TableBlockError} if `rows` is not a positive integer, or the
|
|
65
|
+
* table would grow past {@link maxRows}. Nothing is given out then.
|
|
66
|
+
*/
|
|
67
|
+
allocate(rows: number, owner: T): number;
|
|
68
|
+
/**
|
|
69
|
+
* The block a row falls in — a picked `groupId`, say — or `null` when no
|
|
70
|
+
* block holds it.
|
|
71
|
+
*/
|
|
72
|
+
locate(row: number): BlockRow<T> | null;
|
|
73
|
+
}
|
package/dist/bundled.cjs
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var shaderArtifacts = require('@vcollab/shader-artifacts');
|
|
4
|
+
|
|
5
|
+
// src/bundled.ts
|
|
6
|
+
|
|
7
|
+
// src/encoding.ts
|
|
8
|
+
var ELEMENTS = {
|
|
9
|
+
float: { kind: "float", width: 1 },
|
|
10
|
+
int: { kind: "int", width: 1 },
|
|
11
|
+
uint: { kind: "uint", width: 1 },
|
|
12
|
+
vec2: { kind: "float", width: 2 },
|
|
13
|
+
vec3: { kind: "float", width: 3 },
|
|
14
|
+
vec4: { kind: "float", width: 4 },
|
|
15
|
+
ivec2: { kind: "int", width: 2 },
|
|
16
|
+
ivec3: { kind: "int", width: 3 },
|
|
17
|
+
ivec4: { kind: "int", width: 4 },
|
|
18
|
+
uvec2: { kind: "uint", width: 2 },
|
|
19
|
+
uvec3: { kind: "uint", width: 3 },
|
|
20
|
+
uvec4: { kind: "uint", width: 4 },
|
|
21
|
+
mat2: { kind: "float", width: 4, order: 2 },
|
|
22
|
+
mat3: { kind: "float", width: 9, order: 3 },
|
|
23
|
+
mat4: { kind: "float", width: 16, order: 4 }
|
|
24
|
+
};
|
|
25
|
+
var ARRAY_SUFFIX = "[]";
|
|
26
|
+
var KNOWN_ENCODINGS = Object.keys(ELEMENTS);
|
|
27
|
+
function describeEncoding(encoding) {
|
|
28
|
+
const isArray = encoding.endsWith(ARRAY_SUFFIX);
|
|
29
|
+
const element = isArray ? encoding.slice(0, -ARRAY_SUFFIX.length) : encoding;
|
|
30
|
+
if (!Object.hasOwn(ELEMENTS, element)) return void 0;
|
|
31
|
+
return { ...ELEMENTS[element], isArray };
|
|
32
|
+
}
|
|
33
|
+
var isWhole = (value) => typeof value === "number" && Number.isInteger(value);
|
|
34
|
+
function layoutProblem(name, layout, blockSize) {
|
|
35
|
+
if (typeof layout !== "object" || layout === null) {
|
|
36
|
+
return `${name} has no layout record.`;
|
|
37
|
+
}
|
|
38
|
+
const { offset, size, elementStride, encoding } = layout;
|
|
39
|
+
if (!isWhole(offset) || offset < 0 || offset % 4 !== 0) {
|
|
40
|
+
return `${name} is at offset ${String(offset)}, which is not a non-negative multiple of 4.`;
|
|
41
|
+
}
|
|
42
|
+
if (!isWhole(size) || size <= 0 || offset + size > blockSize) {
|
|
43
|
+
return `${name} occupies ${String(size)} byte(s) at offset ${offset}, which does not lie within the ${blockSize}-byte block.`;
|
|
44
|
+
}
|
|
45
|
+
if (encoding === null) return void 0;
|
|
46
|
+
if (typeof encoding !== "string") {
|
|
47
|
+
return `${name} has the encoding ${String(encoding)}, which is not a name.`;
|
|
48
|
+
}
|
|
49
|
+
const described = describeEncoding(encoding);
|
|
50
|
+
if (described === void 0) {
|
|
51
|
+
return `${name} has the encoding ${encoding}, which the packer does not know; it writes ${KNOWN_ENCODINGS.join(", ")}, and arrays of them.`;
|
|
52
|
+
}
|
|
53
|
+
const reach = described.order === void 0 ? described.width * 4 : (described.order - 1) * 16 + described.order * 4;
|
|
54
|
+
if (described.isArray) {
|
|
55
|
+
if (!isWhole(elementStride) || elementStride <= 0 || elementStride % 4 !== 0) {
|
|
56
|
+
return `${name} is ${encoding}, but the build reports an element stride of ${String(elementStride)}.`;
|
|
57
|
+
}
|
|
58
|
+
if (reach > elementStride || elementStride > size) {
|
|
59
|
+
return `${name} is ${encoding} with ${size} byte(s) at a ${elementStride}-byte stride, which does not hold one element.`;
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
if (reach > size) {
|
|
64
|
+
return `${name} is ${encoding}, which writes ${reach} byte(s), but the build gives it ${size}.`;
|
|
65
|
+
}
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/manifest.ts
|
|
70
|
+
var SCHEMA_VERSION = 3;
|
|
71
|
+
|
|
72
|
+
// src/load.ts
|
|
73
|
+
var ShaderSetError = class extends Error {
|
|
74
|
+
name = "ShaderSetError";
|
|
75
|
+
};
|
|
76
|
+
function pathProblem(path) {
|
|
77
|
+
if (path.length === 0) return "is empty";
|
|
78
|
+
if (/[\u0000-\u001f\u007f-\u009f\\:]/.test(path)) {
|
|
79
|
+
return "holds a backslash, a colon or a control character";
|
|
80
|
+
}
|
|
81
|
+
if (path.startsWith("/")) return "is absolute";
|
|
82
|
+
if (path.split("/").some((part) => part === "" || part === "." || part === "..")) {
|
|
83
|
+
return 'has an empty, "." or ".." segment';
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function assertPath(path, what) {
|
|
88
|
+
const problem = pathProblem(path);
|
|
89
|
+
if (problem !== void 0) {
|
|
90
|
+
throw new ShaderSetError(
|
|
91
|
+
`${what} ${JSON.stringify(path)} ${problem}; a path inside the set is plain and relative.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function assertSchema(document, what) {
|
|
96
|
+
if (document.schemaVersion !== SCHEMA_VERSION) {
|
|
97
|
+
throw new ShaderSetError(
|
|
98
|
+
`${what} is schema version ${String(document.schemaVersion)}, and this package reads ${SCHEMA_VERSION}. A document whose shape is not the one expected is refused rather than read with its fields misinterpreted.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
103
|
+
function assertTags(tags, what) {
|
|
104
|
+
if (!Array.isArray(tags) || !tags.every((tag) => typeof tag === "string")) {
|
|
105
|
+
throw new ShaderSetError(`${what} is not an array of capability tags.`);
|
|
106
|
+
}
|
|
107
|
+
const repeated = tags.filter((tag, index) => tags.indexOf(tag) !== index);
|
|
108
|
+
if (repeated.length > 0) {
|
|
109
|
+
throw new ShaderSetError(`${what} repeats the tag(s) ${[...new Set(repeated)].join(", ")}.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function assertEntry(entry, index) {
|
|
113
|
+
if (!isObject(entry) || typeof entry.id !== "string") {
|
|
114
|
+
throw new ShaderSetError(`registry.json pipeline ${index} has no id.`);
|
|
115
|
+
}
|
|
116
|
+
for (const field of ["contractSha256", "envelope"]) {
|
|
117
|
+
if (typeof entry[field] !== "string") {
|
|
118
|
+
throw new ShaderSetError(`registry.json entry ${entry.id} has no ${field}.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
assertPath(entry.envelope, `registry.json entry ${entry.id} has the envelope path`);
|
|
122
|
+
assertTags(entry.capabilities, `the capabilities of registry.json entry ${entry.id}`);
|
|
123
|
+
}
|
|
124
|
+
function asRegistry(document) {
|
|
125
|
+
if (!isObject(document)) {
|
|
126
|
+
throw new ShaderSetError("registry.json is not an object.");
|
|
127
|
+
}
|
|
128
|
+
assertSchema(document, "registry.json");
|
|
129
|
+
if (!Array.isArray(document.pipelines)) {
|
|
130
|
+
throw new ShaderSetError("registry.json carries no pipelines array.");
|
|
131
|
+
}
|
|
132
|
+
assertTags(document.capabilityVocabulary, "the capabilityVocabulary of registry.json");
|
|
133
|
+
document.pipelines.forEach(assertEntry);
|
|
134
|
+
const vocabulary = new Set(document.capabilityVocabulary);
|
|
135
|
+
for (const entry of document.pipelines) {
|
|
136
|
+
const unknown = entry.capabilities.filter((tag) => !vocabulary.has(tag));
|
|
137
|
+
if (unknown.length > 0) {
|
|
138
|
+
throw new ShaderSetError(
|
|
139
|
+
`registry.json entry ${entry.id} carries ${unknown.join(", ")}, which capabilityVocabulary does not declare.`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const ids = document.pipelines.map((entry) => entry.id);
|
|
144
|
+
const repeated = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
145
|
+
if (repeated.length > 0) {
|
|
146
|
+
throw new ShaderSetError(`registry.json lists ${repeated.join(", ")} more than once.`);
|
|
147
|
+
}
|
|
148
|
+
return document;
|
|
149
|
+
}
|
|
150
|
+
function assertLanguage(id, language, block) {
|
|
151
|
+
const where = `the ${language} block of the envelope for ${id}`;
|
|
152
|
+
if (!isObject(block)) throw new ShaderSetError(`${where} is not an object.`);
|
|
153
|
+
const { blockSize, layout, bindings, stages } = block;
|
|
154
|
+
if (typeof blockSize !== "number" || !Number.isInteger(blockSize) || blockSize <= 0) {
|
|
155
|
+
throw new ShaderSetError(`${where} reports a block size of ${String(blockSize)}.`);
|
|
156
|
+
}
|
|
157
|
+
if (!isObject(layout)) throw new ShaderSetError(`${where} carries no layout.`);
|
|
158
|
+
for (const [name, member] of Object.entries(layout)) {
|
|
159
|
+
const problem = layoutProblem(name, member, blockSize);
|
|
160
|
+
if (problem !== void 0) throw new ShaderSetError(`in ${where}, ${problem}`);
|
|
161
|
+
}
|
|
162
|
+
if (!Array.isArray(bindings)) throw new ShaderSetError(`${where} carries no bindings.`);
|
|
163
|
+
if (!isObject(stages)) throw new ShaderSetError(`${where} carries no stages.`);
|
|
164
|
+
}
|
|
165
|
+
function asEnvelope(document, entry) {
|
|
166
|
+
if (typeof document !== "object" || document === null) {
|
|
167
|
+
throw new ShaderSetError(`the envelope for ${entry.id} is not an object.`);
|
|
168
|
+
}
|
|
169
|
+
const envelope = document;
|
|
170
|
+
assertSchema(envelope, `the envelope for ${entry.id}`);
|
|
171
|
+
if (envelope.pipeline?.id !== entry.id) {
|
|
172
|
+
throw new ShaderSetError(
|
|
173
|
+
`${entry.envelope} describes pipeline ${String(envelope.pipeline?.id)}, but the index points at it for ${entry.id}.`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (envelope.contractSha256 !== entry.contractSha256) {
|
|
177
|
+
throw new ShaderSetError(
|
|
178
|
+
`the envelope for ${entry.id} carries contract ${envelope.contractSha256}, but the index entry that pointed at it records ${entry.contractSha256}. The set is mixed: the index and this envelope are from different builds.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
assertTags(envelope.pipeline.capabilities, `the capabilities in the envelope for ${entry.id}`);
|
|
182
|
+
const selected = new Set(entry.capabilities);
|
|
183
|
+
const carried = new Set(envelope.pipeline.capabilities);
|
|
184
|
+
if (selected.size !== carried.size || [...carried].some((tag) => !selected.has(tag))) {
|
|
185
|
+
throw new ShaderSetError(
|
|
186
|
+
`the envelope for ${entry.id} declares the capabilities [${[...carried].sort().join(", ")}], but the index entry that selected it records [${[...selected].sort().join(", ")}].`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (!isObject(envelope.languages)) {
|
|
190
|
+
throw new ShaderSetError(`the envelope for ${entry.id} carries no languages.`);
|
|
191
|
+
}
|
|
192
|
+
for (const [language, block] of Object.entries(envelope.languages)) {
|
|
193
|
+
assertLanguage(entry.id, language, block);
|
|
194
|
+
}
|
|
195
|
+
return envelope;
|
|
196
|
+
}
|
|
197
|
+
var ShaderSet = class _ShaderSet {
|
|
198
|
+
#source;
|
|
199
|
+
#entries;
|
|
200
|
+
#envelopes = /* @__PURE__ */ new Map();
|
|
201
|
+
/** The index, as read. */
|
|
202
|
+
registry;
|
|
203
|
+
constructor(source, registry) {
|
|
204
|
+
this.#source = source;
|
|
205
|
+
this.registry = registry;
|
|
206
|
+
this.#entries = new Map(registry.pipelines.map((entry) => [entry.id, entry]));
|
|
207
|
+
}
|
|
208
|
+
/** Read the index and open the set. */
|
|
209
|
+
static async open(source) {
|
|
210
|
+
return new _ShaderSet(source, asRegistry(await source.readRegistry()));
|
|
211
|
+
}
|
|
212
|
+
/** Every pipeline the set holds, in the order the index lists them. */
|
|
213
|
+
get pipelines() {
|
|
214
|
+
return this.registry.pipelines;
|
|
215
|
+
}
|
|
216
|
+
/** The closed set of capability tags any pipeline here may declare. */
|
|
217
|
+
get capabilityVocabulary() {
|
|
218
|
+
return this.registry.capabilityVocabulary;
|
|
219
|
+
}
|
|
220
|
+
/** The index entry for `id`. */
|
|
221
|
+
entry(id) {
|
|
222
|
+
const entry = this.#entries.get(id);
|
|
223
|
+
if (entry === void 0) {
|
|
224
|
+
throw new ShaderSetError(`no pipeline ${id} in this set; it holds ${this.#entries.size}.`);
|
|
225
|
+
}
|
|
226
|
+
return entry;
|
|
227
|
+
}
|
|
228
|
+
/** The envelope for `id`, fetched once and cached. */
|
|
229
|
+
async envelope(id) {
|
|
230
|
+
const entry = this.entry(id);
|
|
231
|
+
let pending = this.#envelopes.get(id);
|
|
232
|
+
if (pending === void 0) {
|
|
233
|
+
pending = this.#source.readEnvelope(entry).then((document) => asEnvelope(document, entry));
|
|
234
|
+
pending.catch(() => this.#envelopes.delete(id));
|
|
235
|
+
this.#envelopes.set(id, pending);
|
|
236
|
+
}
|
|
237
|
+
return pending;
|
|
238
|
+
}
|
|
239
|
+
/** The envelope's block for one language; `glsl` unless asked otherwise. */
|
|
240
|
+
static language(envelope, language = "glsl") {
|
|
241
|
+
const block = Object.hasOwn(envelope.languages, language) ? envelope.languages[language] : void 0;
|
|
242
|
+
if (block === void 0) {
|
|
243
|
+
const carried = Object.keys(envelope.languages).join(", ") || "none";
|
|
244
|
+
throw new ShaderSetError(
|
|
245
|
+
`the envelope for ${envelope.pipeline.id} carries no ${language}; it carries ${carried}.`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return block;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/bundled.ts
|
|
253
|
+
function bundledSource() {
|
|
254
|
+
return {
|
|
255
|
+
readRegistry: async () => shaderArtifacts.REGISTRY,
|
|
256
|
+
readEnvelope: async (entry) => {
|
|
257
|
+
const load = Object.hasOwn(shaderArtifacts.ENVELOPE_LOADERS, entry.id) ? shaderArtifacts.ENVELOPE_LOADERS[entry.id] : void 0;
|
|
258
|
+
if (load === void 0) {
|
|
259
|
+
throw new ShaderSetError(`the bundled set carries no envelope for ${entry.id}.`);
|
|
260
|
+
}
|
|
261
|
+
return load();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function openBundledSet() {
|
|
266
|
+
return ShaderSet.open(bundledSource());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
exports.bundledSource = bundledSource;
|
|
270
|
+
exports.openBundledSet = openBundledSet;
|
|
271
|
+
//# sourceMappingURL=bundled.cjs.map
|
|
272
|
+
//# sourceMappingURL=bundled.cjs.map
|