@vcollab/shader-library 0.0.0-stage → 1.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 +56 -0
- package/LICENSE +8 -0
- package/README.md +109 -2
- package/dist/bind.d.ts +53 -0
- package/dist/bundled.cjs +236 -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-ELLNQZJX.js +257 -0
- package/dist/chunk-ELLNQZJX.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 +617 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +342 -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 +78 -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,56 @@
|
|
|
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
|
+
## [1.0.0] — 2026-12-03
|
|
9
|
+
|
|
10
|
+
First release. The package is a consumer of the artifact set emitted by
|
|
11
|
+
`vcti-shader-foundry` (schema 3), and composes no shader text of its own.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `ShaderSet` for reading an artifact set: the index eagerly, envelopes on
|
|
16
|
+
demand and cached, with the schema version and each envelope's
|
|
17
|
+
`contractSha256` checked against the index entry that pointed at it. A
|
|
18
|
+
document's structure is checked when it is loaded and refused with
|
|
19
|
+
`ShaderSetError`: a missing or non-array `capabilityVocabulary`, an entry
|
|
20
|
+
missing a field, a capability list that repeats a tag, a repeated pipeline
|
|
21
|
+
id, an envelope with no `languages`, a language block missing `blockSize`,
|
|
22
|
+
`layout`, `bindings` or `stages`, and a layout member whose offset is not a
|
|
23
|
+
non-negative multiple of 4, whose recorded extent leaves the block, or whose
|
|
24
|
+
encoding the packer does not write. Nothing is recomputed from std140 rules.
|
|
25
|
+
- `ArtifactSource` with `fetchSource` and `fsSource` adapters, and
|
|
26
|
+
`bundledSource` / `openBundledSet` at `@vcollab/shader-library/bundled` for
|
|
27
|
+
the set shipped in `@vcollab/shader-artifacts`. `fetchSource` resolves a
|
|
28
|
+
relative base URL against `location.href` in a browser, and asks for an
|
|
29
|
+
absolute URL where there is no location.
|
|
30
|
+
- `resolvePipeline` and the exact capability match, compared as sets, plus
|
|
31
|
+
`matchCapabilities`, `withCapabilities`, `capabilitiesInUse` and
|
|
32
|
+
`validateCapabilities` for building a chooser. Nothing is ranked.
|
|
33
|
+
- `UniformBlock`, a std140 writer driven by the layout and block size the build
|
|
34
|
+
reported. It refuses an encoding it does not write, and a non-integer or
|
|
35
|
+
out-of-range value for an `int` or `uint` member, rather than truncating or
|
|
36
|
+
wrapping it. Matrices are written so the shaders apply the caller's
|
|
37
|
+
transform: the block declares them `row_major`, but the emitted GLSL
|
|
38
|
+
multiplies row-vector-first, so a column-major input goes in untransposed.
|
|
39
|
+
`majorness` describes the input array's own order; it is not a way to ask
|
|
40
|
+
for a transpose.
|
|
41
|
+
- `ResourceBindings`, resolving a table or texture's semantic to the sampler
|
|
42
|
+
uniform the linked program carries and its texture unit.
|
|
43
|
+
- The pick module: `pickPipelineFor` pairs a color pipeline with the pick
|
|
44
|
+
pipeline whose vertex stage matches it, deform variant included, and throws
|
|
45
|
+
`PipelineSelectionError` when none does; `decodePick` reads one texel of the
|
|
46
|
+
`rgba32ui` pick readback. With `Pick`, `PICK_CAPABILITY`, `PICK_EMPTY`,
|
|
47
|
+
`PICK_RESERVED`, `PICK_CHANNELS` and `PickDecodeError`.
|
|
48
|
+
- Types mirroring the emitted documents, and `SCHEMA_VERSION`.
|
|
49
|
+
- `@vcollab/shader-library/derived`: the derived-quantity math on the CPU for
|
|
50
|
+
all four families, with the dispatch integers and `dispatchTable(family)`,
|
|
51
|
+
pinned to `vcti.derived` by tests over exported reference vectors. A datum
|
|
52
|
+
with any NaN component gives NaN for every derived type, as `vcti.derived`
|
|
53
|
+
does for a masked row; an infinite component throws `DerivedError` for the
|
|
54
|
+
principal-based types, as its eigen-solver raises; an `order` that is not a
|
|
55
|
+
permutation of the family's slots throws `DerivedError`. Lookups by name use
|
|
56
|
+
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,110 @@
|
|
|
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 five 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
|
+
|
|
28
|
+
It creates no GPU resources and touches no context — that is the renderer's
|
|
29
|
+
job. The derived-quantity math the shaders compute is also here, on the CPU,
|
|
30
|
+
for the value range a consumer must know before it can choose fringe bands.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add @vcollab/shader-library
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`@vcollab/shader-artifacts` carries the artifact set. It is a normal dependency,
|
|
39
|
+
so it is always installed with this package. Only the `/bundled` entry point
|
|
40
|
+
imports it, so a consumer that serves its own set over HTTP and does not import
|
|
41
|
+
`/bundled` ships none of the set in its bundle.
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { ResourceBindings, ShaderSet, UniformBlock, resolvePipeline } from "@vcollab/shader-library";
|
|
47
|
+
import { openBundledSet } from "@vcollab/shader-library/bundled";
|
|
48
|
+
|
|
49
|
+
const set = await openBundledSet();
|
|
50
|
+
|
|
51
|
+
// Capabilities are matched exactly — a pipeline carrying one you did not ask
|
|
52
|
+
// for reads an attribute you did not bind.
|
|
53
|
+
const entry = resolvePipeline(set.registry, [
|
|
54
|
+
"deform3", "symtensor", "fringe-float",
|
|
55
|
+
"material", "material-table", "material-surface-finish",
|
|
56
|
+
"mask", "mask-lut-r8ui", "transform", "transform-lut-r32ui", "clip",
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
const envelope = await set.envelope(entry.id);
|
|
60
|
+
const glsl = ShaderSet.language(envelope);
|
|
61
|
+
|
|
62
|
+
// The shader text, as built. Compile it; do not edit it.
|
|
63
|
+
const program = link(glsl.stages.vertex!.source, glsl.stages.fragment!.source);
|
|
64
|
+
|
|
65
|
+
// The block is larger than the contract: the compiler emits its whole global
|
|
66
|
+
// block whatever entry point was compiled. Allocate what the build reported.
|
|
67
|
+
const uniforms = new UniformBlock(glsl);
|
|
68
|
+
uniforms.set("u_mvpMatrix", mvp); // column-major in; the packer arranges the bytes
|
|
69
|
+
uniforms.set("u_colorSource", 2); // named states are in the contract
|
|
70
|
+
uniforms.set("u_clipPlaneCount", 0); // the off state of a feature that is always present
|
|
71
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Uint8Array(uniforms.buffer));
|
|
72
|
+
|
|
73
|
+
// Bind by semantic; the declared name is not what the program has.
|
|
74
|
+
const bindings = new ResourceBindings(glsl);
|
|
75
|
+
const mask = bindings.get("mask");
|
|
76
|
+
gl.activeTexture(gl.TEXTURE0 + mask.unit);
|
|
77
|
+
gl.bindTexture(gl.TEXTURE_2D, maskTable);
|
|
78
|
+
gl.uniform1i(gl.getUniformLocation(program, mask.uniform), mask.unit);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Serving the set yourself instead of bundling it:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { ShaderSet, fetchSource } from "@vcollab/shader-library";
|
|
85
|
+
|
|
86
|
+
const set = await ShaderSet.open(fetchSource("https://cdn.example.com/shaders/"));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The derived math, for the range the fringe bands span:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { computeDerivedField, fieldRange } from "@vcollab/shader-library/derived";
|
|
93
|
+
|
|
94
|
+
const range = fieldRange(computeDerivedField("symtensor", "von_mises", tensors));
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Dependencies
|
|
98
|
+
|
|
99
|
+
`@vcollab/shader-artifacts` (the set) is a normal dependency. There are no peer
|
|
100
|
+
dependencies: this package does not touch a GPU context, a renderer or a
|
|
101
|
+
framework.
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
| If you want to… | Read |
|
|
106
|
+
|---|---|
|
|
107
|
+
| Understand the design and what this package does not do | [docs/design.md](docs/design.md) |
|
|
108
|
+
| Look up an export | [docs/api.md](docs/api.md) |
|
|
109
|
+
| See practical consumption patterns | [docs/patterns.md](docs/patterns.md) |
|
|
110
|
+
| 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/bundled.cjs
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
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 assertSchema(document, what) {
|
|
77
|
+
if (document.schemaVersion !== SCHEMA_VERSION) {
|
|
78
|
+
throw new ShaderSetError(
|
|
79
|
+
`${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.`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
|
+
function assertTags(tags, what) {
|
|
85
|
+
if (!Array.isArray(tags) || !tags.every((tag) => typeof tag === "string")) {
|
|
86
|
+
throw new ShaderSetError(`${what} is not an array of capability tags.`);
|
|
87
|
+
}
|
|
88
|
+
const repeated = tags.filter((tag, index) => tags.indexOf(tag) !== index);
|
|
89
|
+
if (repeated.length > 0) {
|
|
90
|
+
throw new ShaderSetError(`${what} repeats the tag(s) ${[...new Set(repeated)].join(", ")}.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function assertEntry(entry, index) {
|
|
94
|
+
if (!isObject(entry) || typeof entry.id !== "string") {
|
|
95
|
+
throw new ShaderSetError(`registry.json pipeline ${index} has no id.`);
|
|
96
|
+
}
|
|
97
|
+
for (const field of ["contractSha256", "envelope"]) {
|
|
98
|
+
if (typeof entry[field] !== "string") {
|
|
99
|
+
throw new ShaderSetError(`registry.json entry ${entry.id} has no ${field}.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
assertTags(entry.capabilities, `the capabilities of registry.json entry ${entry.id}`);
|
|
103
|
+
}
|
|
104
|
+
function asRegistry(document) {
|
|
105
|
+
if (!isObject(document)) {
|
|
106
|
+
throw new ShaderSetError("registry.json is not an object.");
|
|
107
|
+
}
|
|
108
|
+
assertSchema(document, "registry.json");
|
|
109
|
+
if (!Array.isArray(document.pipelines)) {
|
|
110
|
+
throw new ShaderSetError("registry.json carries no pipelines array.");
|
|
111
|
+
}
|
|
112
|
+
assertTags(document.capabilityVocabulary, "the capabilityVocabulary of registry.json");
|
|
113
|
+
document.pipelines.forEach(assertEntry);
|
|
114
|
+
const ids = document.pipelines.map((entry) => entry.id);
|
|
115
|
+
const repeated = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
116
|
+
if (repeated.length > 0) {
|
|
117
|
+
throw new ShaderSetError(`registry.json lists ${repeated.join(", ")} more than once.`);
|
|
118
|
+
}
|
|
119
|
+
return document;
|
|
120
|
+
}
|
|
121
|
+
function assertLanguage(id, language, block) {
|
|
122
|
+
const where = `the ${language} block of the envelope for ${id}`;
|
|
123
|
+
if (!isObject(block)) throw new ShaderSetError(`${where} is not an object.`);
|
|
124
|
+
const { blockSize, layout, bindings, stages } = block;
|
|
125
|
+
if (typeof blockSize !== "number" || !Number.isInteger(blockSize) || blockSize <= 0) {
|
|
126
|
+
throw new ShaderSetError(`${where} reports a block size of ${String(blockSize)}.`);
|
|
127
|
+
}
|
|
128
|
+
if (!isObject(layout)) throw new ShaderSetError(`${where} carries no layout.`);
|
|
129
|
+
for (const [name, member] of Object.entries(layout)) {
|
|
130
|
+
const problem = layoutProblem(name, member, blockSize);
|
|
131
|
+
if (problem !== void 0) throw new ShaderSetError(`in ${where}, ${problem}`);
|
|
132
|
+
}
|
|
133
|
+
if (!Array.isArray(bindings)) throw new ShaderSetError(`${where} carries no bindings.`);
|
|
134
|
+
if (!isObject(stages)) throw new ShaderSetError(`${where} carries no stages.`);
|
|
135
|
+
}
|
|
136
|
+
function asEnvelope(document, entry) {
|
|
137
|
+
if (typeof document !== "object" || document === null) {
|
|
138
|
+
throw new ShaderSetError(`the envelope for ${entry.id} is not an object.`);
|
|
139
|
+
}
|
|
140
|
+
const envelope = document;
|
|
141
|
+
assertSchema(envelope, `the envelope for ${entry.id}`);
|
|
142
|
+
if (envelope.pipeline?.id !== entry.id) {
|
|
143
|
+
throw new ShaderSetError(
|
|
144
|
+
`${entry.envelope} describes pipeline ${String(envelope.pipeline?.id)}, but the index points at it for ${entry.id}.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (envelope.contractSha256 !== entry.contractSha256) {
|
|
148
|
+
throw new ShaderSetError(
|
|
149
|
+
`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.`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
assertTags(envelope.pipeline.capabilities, `the capabilities in the envelope for ${entry.id}`);
|
|
153
|
+
if (!isObject(envelope.languages)) {
|
|
154
|
+
throw new ShaderSetError(`the envelope for ${entry.id} carries no languages.`);
|
|
155
|
+
}
|
|
156
|
+
for (const [language, block] of Object.entries(envelope.languages)) {
|
|
157
|
+
assertLanguage(entry.id, language, block);
|
|
158
|
+
}
|
|
159
|
+
return envelope;
|
|
160
|
+
}
|
|
161
|
+
var ShaderSet = class _ShaderSet {
|
|
162
|
+
#source;
|
|
163
|
+
#entries;
|
|
164
|
+
#envelopes = /* @__PURE__ */ new Map();
|
|
165
|
+
/** The index, as read. */
|
|
166
|
+
registry;
|
|
167
|
+
constructor(source, registry) {
|
|
168
|
+
this.#source = source;
|
|
169
|
+
this.registry = registry;
|
|
170
|
+
this.#entries = new Map(registry.pipelines.map((entry) => [entry.id, entry]));
|
|
171
|
+
}
|
|
172
|
+
/** Read the index and open the set. */
|
|
173
|
+
static async open(source) {
|
|
174
|
+
return new _ShaderSet(source, asRegistry(await source.readRegistry()));
|
|
175
|
+
}
|
|
176
|
+
/** Every pipeline the set holds, in the order the index lists them. */
|
|
177
|
+
get pipelines() {
|
|
178
|
+
return this.registry.pipelines;
|
|
179
|
+
}
|
|
180
|
+
/** The closed set of capability tags any pipeline here may declare. */
|
|
181
|
+
get capabilityVocabulary() {
|
|
182
|
+
return this.registry.capabilityVocabulary;
|
|
183
|
+
}
|
|
184
|
+
/** The index entry for `id`. */
|
|
185
|
+
entry(id) {
|
|
186
|
+
const entry = this.#entries.get(id);
|
|
187
|
+
if (entry === void 0) {
|
|
188
|
+
throw new ShaderSetError(`no pipeline ${id} in this set; it holds ${this.#entries.size}.`);
|
|
189
|
+
}
|
|
190
|
+
return entry;
|
|
191
|
+
}
|
|
192
|
+
/** The envelope for `id`, fetched once and cached. */
|
|
193
|
+
async envelope(id) {
|
|
194
|
+
const entry = this.entry(id);
|
|
195
|
+
let pending = this.#envelopes.get(id);
|
|
196
|
+
if (pending === void 0) {
|
|
197
|
+
pending = this.#source.readEnvelope(entry).then((document) => asEnvelope(document, entry));
|
|
198
|
+
pending.catch(() => this.#envelopes.delete(id));
|
|
199
|
+
this.#envelopes.set(id, pending);
|
|
200
|
+
}
|
|
201
|
+
return pending;
|
|
202
|
+
}
|
|
203
|
+
/** The envelope's block for one language; `glsl` unless asked otherwise. */
|
|
204
|
+
static language(envelope, language = "glsl") {
|
|
205
|
+
const block = Object.hasOwn(envelope.languages, language) ? envelope.languages[language] : void 0;
|
|
206
|
+
if (block === void 0) {
|
|
207
|
+
const carried = Object.keys(envelope.languages).join(", ") || "none";
|
|
208
|
+
throw new ShaderSetError(
|
|
209
|
+
`the envelope for ${envelope.pipeline.id} carries no ${language}; it carries ${carried}.`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return block;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/bundled.ts
|
|
217
|
+
function bundledSource() {
|
|
218
|
+
return {
|
|
219
|
+
readRegistry: async () => shaderArtifacts.REGISTRY,
|
|
220
|
+
readEnvelope: async (entry) => {
|
|
221
|
+
const load = Object.hasOwn(shaderArtifacts.ENVELOPE_LOADERS, entry.id) ? shaderArtifacts.ENVELOPE_LOADERS[entry.id] : void 0;
|
|
222
|
+
if (load === void 0) {
|
|
223
|
+
throw new ShaderSetError(`the bundled set carries no envelope for ${entry.id}.`);
|
|
224
|
+
}
|
|
225
|
+
return load();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function openBundledSet() {
|
|
230
|
+
return ShaderSet.open(bundledSource());
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
exports.bundledSource = bundledSource;
|
|
234
|
+
exports.openBundledSet = openBundledSet;
|
|
235
|
+
//# sourceMappingURL=bundled.cjs.map
|
|
236
|
+
//# sourceMappingURL=bundled.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/encoding.ts","../src/manifest.ts","../src/load.ts","../src/bundled.ts"],"names":["REGISTRY","ENVELOPE_LOADERS"],"mappings":";;;;;;;AAkCA,IAAM,QAAA,GAAgE;AAAA,EACpE,KAAA,EAAO,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA,EAAE;AAAA,EACjC,GAAA,EAAK,EAAE,IAAA,EAAM,KAAA,EAAO,OAAO,CAAA,EAAE;AAAA,EAC7B,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAE;AAAA,EAC/B,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA,EAAE;AAAA,EAChC,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA,EAAE;AAAA,EAChC,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA,EAAE;AAAA,EAChC,KAAA,EAAO,EAAE,IAAA,EAAM,KAAA,EAAO,OAAO,CAAA,EAAE;AAAA,EAC/B,KAAA,EAAO,EAAE,IAAA,EAAM,KAAA,EAAO,OAAO,CAAA,EAAE;AAAA,EAC/B,KAAA,EAAO,EAAE,IAAA,EAAM,KAAA,EAAO,OAAO,CAAA,EAAE;AAAA,EAC/B,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAE;AAAA,EAChC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAE;AAAA,EAChC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAE;AAAA,EAChC,MAAM,EAAE,IAAA,EAAM,SAAS,KAA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AA,CAAS,QAAA,EAAoB,QAAA,GAA2B,MAAA,EAAuB;AACpF,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,MAAA,CAAO,QAAA,CAAS,SAAA,EAAW,QAAQ,CAAA,GACpD,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,GAC3B,MAAA;AACJ,IAAA,IAAI,UAAU,MAAA,EAAW;AACvB,MAAA,MAAM,OAAA,GAAU,OAAO,IAAA,CAAK,QAAA,CAAS,SAAS,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA,IAAK,MAAA;AAC9D,MAAA,MAAM,IAAI,cAAA;AAAA,QACR,oBAAoB,QAAA,CAAS,QAAA,CAAS,EAAE,CAAA,YAAA,EAAe,QAAQ,gBAAgB,OAAO,CAAA,CAAA;AAAA,OACxF;AAAA,IACF;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF,CAAA;;;ACrSO,SAAS,aAAA,GAAgC;AAC9C,EAAA,OAAO;AAAA,IACL,cAAc,YAAYA,wBAAA;AAAA,IAC1B,YAAA,EAAc,OAAO,KAAA,KAAU;AAC7B,MAAA,MAAM,IAAA,GAAO,MAAA,CAAO,MAAA,CAAOC,gCAAA,EAAkB,KAAA,CAAM,EAAE,CAAA,GACjDA,gCAAA,CAAiB,KAAA,CAAM,EAAE,CAAA,GACzB,MAAA;AACJ,MAAA,IAAI,SAAS,MAAA,EAAW;AACtB,QAAA,MAAM,IAAI,cAAA,CAAe,CAAA,wCAAA,EAA2C,KAAA,CAAM,EAAE,CAAA,CAAA,CAAG,CAAA;AAAA,MACjF;AACA,MAAA,OAAO,IAAA,EAAK;AAAA,IACd;AAAA,GACF;AACF;AAGO,SAAS,cAAA,GAAqC;AACnD,EAAA,OAAO,SAAA,CAAU,IAAA,CAAK,aAAA,EAAe,CAAA;AACvC","file":"bundled.cjs","sourcesContent":["// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The uniform encodings the packer can write, and the check that a reflected\n * layout fits them.\n *\n * Internal: {@link UniformBlock} and {@link ShaderSet} share it, so an envelope\n * the set accepts is one the packer can write, and the two cannot disagree\n * about what an encoding is.\n *\n * Nothing here computes a std140 offset or size. The layout is the build's;\n * what is checked is only that the packer's own writes — `width` four-byte\n * components at the member's offset, or `order` sixteen-byte rows for a matrix,\n * or one element per `elementStride` for an array — land inside the extent the\n * build recorded for that member, and inside the block.\n */\n\nimport type { UniformLayout } from \"./manifest.js\";\n\n/** How a scalar component is stored. */\nexport type Kind = \"float\" | \"int\" | \"uint\";\n\n/** What one encoding means to the packer. */\nexport interface Encoding {\n readonly kind: Kind;\n /** Components per element: 1 for a scalar, 2–4 for a vector, order² for a matrix. */\n readonly width: number;\n /** The matrix order, for a matrix. */\n readonly order?: number;\n /** Whether the member is an array of these. */\n readonly isArray: boolean;\n}\n\nconst ELEMENTS: Readonly<Record<string, Omit<Encoding, \"isArray\">>> = {\n float: { kind: \"float\", width: 1 },\n int: { kind: \"int\", width: 1 },\n uint: { kind: \"uint\", width: 1 },\n vec2: { kind: \"float\", width: 2 },\n vec3: { kind: \"float\", width: 3 },\n vec4: { kind: \"float\", width: 4 },\n ivec2: { kind: \"int\", width: 2 },\n ivec3: { kind: \"int\", width: 3 },\n ivec4: { kind: \"int\", width: 4 },\n uvec2: { kind: \"uint\", width: 2 },\n uvec3: { kind: \"uint\", width: 3 },\n uvec4: { kind: \"uint\", width: 4 },\n mat2: { kind: \"float\", width: 4, order: 2 },\n mat3: { kind: \"float\", width: 9, order: 3 },\n mat4: { kind: \"float\", width: 16, order: 4 },\n};\n\nconst ARRAY_SUFFIX = \"[]\";\n\n/** The encodings the packer writes, each also as an array. */\nexport const KNOWN_ENCODINGS: readonly string[] = Object.keys(ELEMENTS);\n\n/** What `encoding` means, or `undefined` if the packer does not know it. */\nexport function describeEncoding(encoding: string): Encoding | undefined {\n const isArray = encoding.endsWith(ARRAY_SUFFIX);\n const element = isArray ? encoding.slice(0, -ARRAY_SUFFIX.length) : encoding;\n // An own-property lookup: `in` would accept `toString` as an encoding.\n if (!Object.hasOwn(ELEMENTS, element)) return undefined;\n return { ...(ELEMENTS[element] as Omit<Encoding, \"isArray\">), isArray };\n}\n\nconst isWhole = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isInteger(value);\n\n/**\n * Why `layout` cannot be written into a block of `blockSize` bytes, or\n * `undefined` if it can.\n *\n * A member with a `null` encoding passes: it is part of the block and counts\n * towards its size, and the packer refuses only a write to it.\n */\nexport function layoutProblem(\n name: string,\n layout: UniformLayout,\n blockSize: number,\n): string | undefined {\n if (typeof layout !== \"object\" || layout === null) {\n return `${name} has no layout record.`;\n }\n const { offset, size, elementStride, encoding } = layout;\n if (!isWhole(offset) || offset < 0 || offset % 4 !== 0) {\n return `${name} is at offset ${String(offset)}, which is not a non-negative multiple of 4.`;\n }\n if (!isWhole(size) || size <= 0 || offset + size > blockSize) {\n return (\n `${name} occupies ${String(size)} byte(s) at offset ${offset}, which does not lie ` +\n `within the ${blockSize}-byte block.`\n );\n }\n if (encoding === null) return undefined;\n if (typeof encoding !== \"string\") {\n return `${name} has the encoding ${String(encoding)}, which is not a name.`;\n }\n const described = describeEncoding(encoding);\n if (described === undefined) {\n return (\n `${name} has the encoding ${encoding}, which the packer does not know; it writes ` +\n `${KNOWN_ENCODINGS.join(\", \")}, and arrays of them.`\n );\n }\n // How far the packer's writes reach for one element, from the element's\n // start: a matrix is `order` rows, each at a sixteen-byte slot.\n const reach =\n described.order === undefined\n ? described.width * 4\n : (described.order - 1) * 16 + described.order * 4;\n if (described.isArray) {\n if (!isWhole(elementStride) || elementStride <= 0 || elementStride % 4 !== 0) {\n return (\n `${name} is ${encoding}, but the build reports an element stride of ` +\n `${String(elementStride)}.`\n );\n }\n if (reach > elementStride || elementStride > size) {\n return `${name} is ${encoding} with ${size} byte(s) at a ${elementStride}-byte stride, which does not hold one element.`;\n }\n return undefined;\n }\n if (reach > size) {\n return `${name} is ${encoding}, which writes ${reach} byte(s), but the build gives it ${size}.`;\n }\n return undefined;\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The artifact set's documents, as types.\n *\n * These mirror what `vcti-shader-foundry` emits — `registry.json` and one\n * envelope per pipeline — field for field. The foundry is the only thing that\n * produces them; nothing here re-declares a contract or invents a field. When\n * the emitted shape changes, {@link SCHEMA_VERSION} changes with it and a set\n * carrying an unknown version is refused rather than misread.\n */\n\n/** The emitted document shape this package understands. */\nexport const SCHEMA_VERSION = 3;\n\n/** A shader language an artifact set can carry. Only `glsl` is emitted today. */\nexport type ShaderLanguage = \"glsl\" | \"wgsl\";\n\n/** A stage of a pipeline. */\nexport type ShaderStage = \"vertex\" | \"fragment\";\n\n/** One vertex attribute the pipeline reads. */\nexport interface AttributeSpec {\n /** The name the attribute is declared under. */\n readonly name: string;\n /** Its GL type, e.g. `vec3`, `int`. */\n readonly type: string;\n /** What the attribute means — how a consumer matches its own buffer to it. */\n readonly semantic: string;\n}\n\n/** One uniform block member the pipeline reads. */\nexport interface UniformSpec {\n readonly name: string;\n /** Its GL type, e.g. `vec3`, `mat4`, `int`. */\n readonly type: string;\n /**\n * Named states for an integer selector, e.g. `u_colorSource`. The numbers\n * are append-only across releases (see the foundry's stability rules).\n */\n readonly namedValues?: Readonly<Record<string, number>>;\n}\n\n/** One fragment output. Its index in `outputs` is its location. */\nexport interface OutputSpec {\n readonly name: string;\n readonly type: string;\n /**\n * The attachment format the output requires, or `null` for no exact\n * requirement. `null` is a claim, not an omission.\n */\n readonly format: string | null;\n}\n\n/** A texture read at exact integer coordinates — a lookup table, not an image. */\nexport interface TableSpec {\n readonly name: string;\n readonly type: string;\n readonly format: string;\n readonly semantic: string;\n}\n\n/** An image sampled between texels. */\nexport interface TextureSpec {\n readonly name: string;\n readonly semantic: string;\n readonly kind: string;\n readonly component: string;\n readonly format: string;\n readonly requiresMipChain: boolean;\n /** The name of a sampler this contract declares. */\n readonly sampler: string;\n /** The semantic of a uv attribute this contract carries. */\n readonly uv: string;\n readonly selection: string;\n readonly neutral: readonly number[] | null;\n}\n\n/** Sampler state a texture is read through. */\nexport interface SamplerSpec {\n readonly name: string;\n readonly magFilter: string;\n readonly minFilter: string;\n readonly mipmapFilter: string;\n readonly wrapS: string;\n readonly wrapT: string;\n}\n\n/**\n * A pipeline's binding surface: everything a caller must match.\n *\n * Order is significant. A uniform block's member order determines its byte\n * offsets, which is why {@link RegistryEntry.contractSha256} is computed over\n * this document with its sequences left unsorted.\n */\nexport interface PipelineContract {\n readonly id: string;\n readonly capabilities: readonly string[];\n readonly inputs: readonly AttributeSpec[];\n readonly uniforms: readonly UniformSpec[];\n readonly outputs: readonly OutputSpec[];\n readonly tables: readonly TableSpec[];\n readonly textures: readonly TextureSpec[];\n readonly samplers: readonly SamplerSpec[];\n}\n\n/** Versions of the three executables that compiled a set. `null` where unread. */\nexport interface ToolchainInfo {\n readonly slangc: string | null;\n readonly spirvCross: string | null;\n readonly glslang: string | null;\n}\n\n/** What produced a set, and with what. */\nexport interface GeneratorInfo {\n readonly name: string;\n readonly version: string;\n readonly toolchain: ToolchainInfo | null;\n}\n\n/**\n * One index entry: enough to choose this pipeline, and where to go next.\n *\n * Not the contract. `contractSha256` names the envelope's content without\n * repeating it, so a fetched envelope can be checked against the entry that\n * pointed at it.\n */\nexport interface RegistryEntry {\n readonly id: string;\n readonly description: string;\n readonly capabilities: readonly string[];\n readonly contractSha256: string;\n /** The envelope's path within the set, relative and POSIX. */\n readonly envelope: string;\n}\n\n/** `registry.json`: the index a consumer selects from. */\nexport interface Registry {\n readonly schemaVersion: number;\n readonly generator: GeneratorInfo;\n /** The closed set of tags any pipeline in this set may declare. */\n readonly capabilityVocabulary: readonly string[];\n readonly pipelines: readonly RegistryEntry[];\n}\n\n/**\n * Where std140 placed one uniform block member.\n *\n * Read rather than recomputed: a second implementation of the padding rules is\n * a second thing to be wrong, and it would diverge silently — on one pipeline,\n * in one case, such as the sixteen-byte stride std140 gives the eight-byte\n * elements of a `vec2[72]`.\n */\nexport interface UniformLayout {\n /** Byte offset from the start of the block. */\n readonly offset: number;\n /** Total byte size, including any array padding. */\n readonly size: number;\n /**\n * Bytes between array elements. For a member that is not an array it is\n * what the reflection reports for its components: `4` for a vector, `0` for\n * a scalar or a matrix. The packer reads it only for an array.\n */\n readonly elementStride: number;\n /** The element type — `float`, `vec3`, `mat4`, `ivec2`. */\n readonly encoding: string | null;\n /** `row` or `column`, present only for a matrix. */\n readonly majorness?: \"row\" | \"column\";\n}\n\n/**\n * One emitted sampler uniform, and the resource it was built from.\n *\n * The seam the declared names do not cross: GLSL ES 3.00 has no binding\n * qualifier for samplers, so the cross-compiler pairs each texture with a\n * sampler and names the combination itself. A consumer binds by\n * {@link semantic}, then uses {@link uniform} and {@link unit}.\n */\nexport interface BindingRecord {\n /** The semantic of the table or texture this was built from. */\n readonly semantic: string;\n /** The declared name of that resource. It does not reach the program. */\n readonly texture: string;\n /**\n * The declared name of the sampler it was paired with, or `null` where the\n * contract declares none — a table read at exact texel coordinates is paired\n * with the cross-compiler's dummy sampler, which the contract never names.\n */\n readonly sampler: string | null;\n /** The uniform the emitted program actually declares. */\n readonly uniform: string;\n readonly component: string;\n readonly stage: ShaderStage;\n /** The texture unit to bind to, assigned deterministically at build. */\n readonly unit: number;\n}\n\n/** One stage's emitted source and its hash. */\nexport interface StageSource {\n readonly source: string;\n readonly sha256: string;\n}\n\n/** Everything about one pipeline in one language. */\nexport interface LanguageBlock {\n /**\n * The reflected size of the whole uniform block, which is larger than the\n * contract: the compiler emits its entire global block whatever entry point\n * is compiled, so an undeformed pipeline's GLSL still carries deform members\n * its contract does not list. Allocate this many bytes.\n */\n readonly blockSize: number;\n /** Placement of every member the block holds, by name. */\n readonly layout: Readonly<Record<string, UniformLayout>>;\n readonly bindings: readonly BindingRecord[];\n readonly stages: Readonly<Partial<Record<ShaderStage, StageSource>>>;\n}\n\n/**\n * One pipeline as a self-contained document: contract plus its shaders.\n *\n * The second projection of the manifest, for consumption rather than\n * selection. Fetching one is a single request that cannot arrive half-stale.\n */\nexport interface Envelope {\n readonly schemaVersion: number;\n readonly generator: GeneratorInfo;\n /** The contract, with the pipeline's description alongside it. */\n readonly pipeline: PipelineContract & { readonly description: string };\n readonly contractSha256: string;\n readonly languages: Readonly<Partial<Record<ShaderLanguage, LanguageBlock>>>;\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * Reading an artifact set: where the documents come from, and what is checked.\n *\n * The set is two projections of one build. The index is fetched once, to list\n * what can be drawn; an envelope is fetched to draw one pipeline. {@link\n * ShaderSet} keeps that shape — the index eagerly, envelopes on demand and\n * cached — and makes the one check the split exists to enable: the envelope it\n * received carries the `contractSha256` the index entry that pointed at it\n * recorded.\n *\n * Where the bytes come from is a {@link ArtifactSource}, so the same set works\n * bundled, served over HTTP, or read from a directory on disk.\n */\n\nimport { layoutProblem } from \"./encoding.js\";\nimport type {\n Envelope,\n LanguageBlock,\n Registry,\n RegistryEntry,\n ShaderLanguage,\n} from \"./manifest.js\";\nimport { SCHEMA_VERSION } from \"./manifest.js\";\n\n/** Raised for any artifact set this package will not read. */\nexport class ShaderSetError extends Error {\n override readonly name = \"ShaderSetError\";\n}\n\n/**\n * Where an artifact set's documents come from.\n *\n * Two methods, because there are two documents. `readEnvelope` receives the\n * whole index entry rather than an id: the entry carries the envelope's path\n * within the set, which is the set's business and not the caller's to\n * reconstruct.\n */\nexport interface ArtifactSource {\n /** The parsed `registry.json`. */\n readRegistry(): Promise<unknown>;\n /** The parsed envelope the entry points at. */\n readEnvelope(entry: RegistryEntry): Promise<unknown>;\n}\n\n/**\n * The base URL as an absolute URL.\n *\n * A relative base such as `/shaders/` is what a page naturally writes, and\n * `new URL` alone refuses it. In a browser it is resolved against the page's\n * own location, as a link would be; where there is no location there is\n * nothing to resolve it against, and guessing one would fetch from somewhere\n * the caller did not name.\n */\nfunction absoluteBase(baseUrl: string | URL): URL {\n if (baseUrl instanceof URL) return new URL(baseUrl.href);\n if (URL.canParse(baseUrl)) return new URL(baseUrl);\n const here = (globalThis as { location?: { href?: unknown } }).location?.href;\n if (typeof here === \"string\" && URL.canParse(baseUrl, here)) return new URL(baseUrl, here);\n throw new ShaderSetError(\n `${JSON.stringify(baseUrl)} is not an absolute URL, and there is no page location to ` +\n \"resolve it against. Outside a browser, pass an absolute URL such as \" +\n \"https://host/shaders/.\",\n );\n}\n\n/**\n * Reads a set served over HTTP under one base URL.\n *\n * A relative `baseUrl` is resolved against `location.href` where there is one\n * — in a browser — and refused elsewhere.\n *\n * @throws {ShaderSetError} for a relative `baseUrl` with no page location.\n */\nexport function fetchSource(baseUrl: string | URL, init?: RequestInit): ArtifactSource {\n const base = absoluteBase(baseUrl);\n // A base URL naming a directory must end in a slash or the last segment is\n // replaced rather than appended to.\n if (!base.pathname.endsWith(\"/\")) base.pathname += \"/\";\n\n const read = async (path: string): Promise<unknown> => {\n const url = new URL(path, base);\n const response = await fetch(url, init);\n if (!response.ok) {\n throw new ShaderSetError(\n `fetching ${url.href} failed: ${response.status} ${response.statusText}`,\n );\n }\n return response.json();\n };\n\n return {\n readRegistry: () => read(\"registry.json\"),\n readEnvelope: (entry) => read(entry.envelope),\n };\n}\n\n/**\n * Reads a set unpacked into a directory on disk.\n *\n * `node:fs` is imported when the source is first read rather than when this\n * module is loaded, so importing this package in a browser does not pull a\n * Node built-in into the bundle.\n */\nexport function fsSource(directory: string): ArtifactSource {\n const read = async (path: string): Promise<unknown> => {\n const [{ readFile }, { join }] = await Promise.all([\n import(\"node:fs/promises\"),\n import(\"node:path\"),\n ]);\n const full = join(directory, ...path.split(\"/\"));\n try {\n return JSON.parse(await readFile(full, \"utf8\"));\n } catch (cause) {\n throw new ShaderSetError(`reading ${full} failed: ${(cause as Error).message}`, { cause });\n }\n };\n\n return {\n readRegistry: () => read(\"registry.json\"),\n readEnvelope: (entry) => read(entry.envelope),\n };\n}\n\nfunction assertSchema(document: { schemaVersion?: unknown }, what: string): void {\n if (document.schemaVersion !== SCHEMA_VERSION) {\n throw new ShaderSetError(\n `${what} is schema version ${String(document.schemaVersion)}, and this package reads ` +\n `${SCHEMA_VERSION}. A document whose shape is not the one expected is refused rather ` +\n \"than read with its fields misinterpreted.\",\n );\n }\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/**\n * Check a capability list is an array of distinct strings.\n *\n * A repeated tag is not harmless: the exact match compares sizes, and a list\n * of `a, a` has the length of `{a, b}`.\n */\nfunction assertTags(tags: unknown, what: string): void {\n if (!Array.isArray(tags) || !tags.every((tag) => typeof tag === \"string\")) {\n throw new ShaderSetError(`${what} is not an array of capability tags.`);\n }\n const repeated = tags.filter((tag, index) => tags.indexOf(tag) !== index);\n if (repeated.length > 0) {\n throw new ShaderSetError(`${what} repeats the tag(s) ${[...new Set(repeated)].join(\", \")}.`);\n }\n}\n\nfunction assertEntry(entry: unknown, index: number): void {\n if (!isObject(entry) || typeof entry.id !== \"string\") {\n throw new ShaderSetError(`registry.json pipeline ${index} has no id.`);\n }\n for (const field of [\"contractSha256\", \"envelope\"] as const) {\n if (typeof entry[field] !== \"string\") {\n throw new ShaderSetError(`registry.json entry ${entry.id} has no ${field}.`);\n }\n }\n assertTags(entry.capabilities, `the capabilities of registry.json entry ${entry.id}`);\n}\n\nfunction asRegistry(document: unknown): Registry {\n if (!isObject(document)) {\n throw new ShaderSetError(\"registry.json is not an object.\");\n }\n assertSchema(document, \"registry.json\");\n if (!Array.isArray(document.pipelines)) {\n throw new ShaderSetError(\"registry.json carries no pipelines array.\");\n }\n assertTags(document.capabilityVocabulary, \"the capabilityVocabulary of registry.json\");\n document.pipelines.forEach(assertEntry);\n const ids = (document.pipelines as RegistryEntry[]).map((entry) => entry.id);\n const repeated = ids.filter((id, index) => ids.indexOf(id) !== index);\n if (repeated.length > 0) {\n throw new ShaderSetError(`registry.json lists ${repeated.join(\", \")} more than once.`);\n }\n return document as unknown as Registry;\n}\n\n/**\n * Check one language block is something the packer and binder can use.\n *\n * The layout is checked against itself, not recomputed: each member must sit\n * at a four-byte-aligned offset, its recorded extent must lie inside the\n * recorded block size, and its encoding must be one the packer writes.\n */\nfunction assertLanguage(id: string, language: string, block: unknown): void {\n const where = `the ${language} block of the envelope for ${id}`;\n if (!isObject(block)) throw new ShaderSetError(`${where} is not an object.`);\n const { blockSize, layout, bindings, stages } = block;\n if (typeof blockSize !== \"number\" || !Number.isInteger(blockSize) || blockSize <= 0) {\n throw new ShaderSetError(`${where} reports a block size of ${String(blockSize)}.`);\n }\n if (!isObject(layout)) throw new ShaderSetError(`${where} carries no layout.`);\n for (const [name, member] of Object.entries(layout)) {\n const problem = layoutProblem(name, member as never, blockSize);\n if (problem !== undefined) throw new ShaderSetError(`in ${where}, ${problem}`);\n }\n if (!Array.isArray(bindings)) throw new ShaderSetError(`${where} carries no bindings.`);\n if (!isObject(stages)) throw new ShaderSetError(`${where} carries no stages.`);\n}\n\nfunction asEnvelope(document: unknown, entry: RegistryEntry): Envelope {\n if (typeof document !== \"object\" || document === null) {\n throw new ShaderSetError(`the envelope for ${entry.id} is not an object.`);\n }\n const envelope = document as Envelope;\n assertSchema(envelope, `the envelope for ${entry.id}`);\n if (envelope.pipeline?.id !== entry.id) {\n throw new ShaderSetError(\n `${entry.envelope} describes pipeline ${String(envelope.pipeline?.id)}, but the index ` +\n `points at it for ${entry.id}.`,\n );\n }\n // The whole reason the index carries a hash instead of the contract: an\n // envelope that is not the one the index sent us to would bind at the wrong\n // offsets and draw a wrong picture with no error anywhere.\n if (envelope.contractSha256 !== entry.contractSha256) {\n throw new ShaderSetError(\n `the envelope for ${entry.id} carries contract ${envelope.contractSha256}, but the index ` +\n `entry that pointed at it records ${entry.contractSha256}. The set is mixed: the index ` +\n \"and this envelope are from different builds.\",\n );\n }\n assertTags(envelope.pipeline.capabilities, `the capabilities in the envelope for ${entry.id}`);\n if (!isObject(envelope.languages)) {\n throw new ShaderSetError(`the envelope for ${entry.id} carries no languages.`);\n }\n for (const [language, block] of Object.entries(envelope.languages)) {\n assertLanguage(entry.id, language, block);\n }\n return envelope;\n}\n\n/**\n * One artifact set, opened.\n *\n * Holds the index and caches each envelope it has been asked for. Every\n * envelope it hands out has been checked against the entry that pointed at it.\n */\nexport class ShaderSet {\n readonly #source: ArtifactSource;\n readonly #entries: ReadonlyMap<string, RegistryEntry>;\n readonly #envelopes = new Map<string, Promise<Envelope>>();\n\n /** The index, as read. */\n readonly registry: Registry;\n\n private constructor(source: ArtifactSource, registry: Registry) {\n this.#source = source;\n this.registry = registry;\n this.#entries = new Map(registry.pipelines.map((entry) => [entry.id, entry]));\n }\n\n /** Read the index and open the set. */\n static async open(source: ArtifactSource): Promise<ShaderSet> {\n return new ShaderSet(source, asRegistry(await source.readRegistry()));\n }\n\n /** Every pipeline the set holds, in the order the index lists them. */\n get pipelines(): readonly RegistryEntry[] {\n return this.registry.pipelines;\n }\n\n /** The closed set of capability tags any pipeline here may declare. */\n get capabilityVocabulary(): readonly string[] {\n return this.registry.capabilityVocabulary;\n }\n\n /** The index entry for `id`. */\n entry(id: string): RegistryEntry {\n const entry = this.#entries.get(id);\n if (entry === undefined) {\n throw new ShaderSetError(`no pipeline ${id} in this set; it holds ${this.#entries.size}.`);\n }\n return entry;\n }\n\n /** The envelope for `id`, fetched once and cached. */\n async envelope(id: string): Promise<Envelope> {\n const entry = this.entry(id);\n let pending = this.#envelopes.get(id);\n if (pending === undefined) {\n pending = this.#source.readEnvelope(entry).then((document) => asEnvelope(document, entry));\n // A failed read must not be cached, or one network blip poisons the id\n // for the lifetime of the set.\n pending.catch(() => this.#envelopes.delete(id));\n this.#envelopes.set(id, pending);\n }\n return pending;\n }\n\n /** The envelope's block for one language; `glsl` unless asked otherwise. */\n static language(envelope: Envelope, language: ShaderLanguage = \"glsl\"): LanguageBlock {\n const block = Object.hasOwn(envelope.languages, language)\n ? envelope.languages[language]\n : undefined;\n if (block === undefined) {\n const carried = Object.keys(envelope.languages).join(\", \") || \"none\";\n throw new ShaderSetError(\n `the envelope for ${envelope.pipeline.id} carries no ${language}; it carries ${carried}.`,\n );\n }\n return block;\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The artifact set that ships with this library.\n *\n * A separate entry point (`@vcollab/shader-library/bundled`) on purpose: it is\n * the only module that reaches `@vcollab/shader-artifacts`, so a consumer\n * serving its own set over HTTP imports the root entry and carries none of the\n * set's 1.7 MB. Envelopes are loaded one at a time, through the per-id dynamic\n * imports the artifacts package generates, so a bundler can split them.\n */\n\nimport { ENVELOPE_LOADERS, REGISTRY } from \"@vcollab/shader-artifacts\";\nimport type { ArtifactSource } from \"./load.js\";\nimport { ShaderSet, ShaderSetError } from \"./load.js\";\n\n/** An {@link ArtifactSource} over the set bundled with this library. */\nexport function bundledSource(): ArtifactSource {\n return {\n readRegistry: async () => REGISTRY,\n readEnvelope: async (entry) => {\n const load = Object.hasOwn(ENVELOPE_LOADERS, entry.id)\n ? ENVELOPE_LOADERS[entry.id]\n : undefined;\n if (load === undefined) {\n throw new ShaderSetError(`the bundled set carries no envelope for ${entry.id}.`);\n }\n return load();\n },\n };\n}\n\n/** Open the set bundled with this library. */\nexport function openBundledSet(): Promise<ShaderSet> {\n return ShaderSet.open(bundledSource());\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArtifactSource } from "./load.js";
|
|
2
|
+
import { ShaderSet } from "./load.js";
|
|
3
|
+
/** An {@link ArtifactSource} over the set bundled with this library. */
|
|
4
|
+
export declare function bundledSource(): ArtifactSource;
|
|
5
|
+
/** Open the set bundled with this library. */
|
|
6
|
+
export declare function openBundledSet(): Promise<ShaderSet>;
|
package/dist/bundled.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ShaderSetError, ShaderSet } from './chunk-ELLNQZJX.js';
|
|
2
|
+
import { REGISTRY, ENVELOPE_LOADERS } from '@vcollab/shader-artifacts';
|
|
3
|
+
|
|
4
|
+
function bundledSource() {
|
|
5
|
+
return {
|
|
6
|
+
readRegistry: async () => REGISTRY,
|
|
7
|
+
readEnvelope: async (entry) => {
|
|
8
|
+
const load = Object.hasOwn(ENVELOPE_LOADERS, entry.id) ? ENVELOPE_LOADERS[entry.id] : void 0;
|
|
9
|
+
if (load === void 0) {
|
|
10
|
+
throw new ShaderSetError(`the bundled set carries no envelope for ${entry.id}.`);
|
|
11
|
+
}
|
|
12
|
+
return load();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function openBundledSet() {
|
|
17
|
+
return ShaderSet.open(bundledSource());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { bundledSource, openBundledSet };
|
|
21
|
+
//# sourceMappingURL=bundled.js.map
|
|
22
|
+
//# sourceMappingURL=bundled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bundled.ts"],"names":[],"mappings":";;;AAkBO,SAAS,aAAA,GAAgC;AAC9C,EAAA,OAAO;AAAA,IACL,cAAc,YAAY,QAAA;AAAA,IAC1B,YAAA,EAAc,OAAO,KAAA,KAAU;AAC7B,MAAA,MAAM,IAAA,GAAO,MAAA,CAAO,MAAA,CAAO,gBAAA,EAAkB,KAAA,CAAM,EAAE,CAAA,GACjD,gBAAA,CAAiB,KAAA,CAAM,EAAE,CAAA,GACzB,MAAA;AACJ,MAAA,IAAI,SAAS,MAAA,EAAW;AACtB,QAAA,MAAM,IAAI,cAAA,CAAe,CAAA,wCAAA,EAA2C,KAAA,CAAM,EAAE,CAAA,CAAA,CAAG,CAAA;AAAA,MACjF;AACA,MAAA,OAAO,IAAA,EAAK;AAAA,IACd;AAAA,GACF;AACF;AAGO,SAAS,cAAA,GAAqC;AACnD,EAAA,OAAO,SAAA,CAAU,IAAA,CAAK,aAAA,EAAe,CAAA;AACvC","file":"bundled.js","sourcesContent":["// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The artifact set that ships with this library.\n *\n * A separate entry point (`@vcollab/shader-library/bundled`) on purpose: it is\n * the only module that reaches `@vcollab/shader-artifacts`, so a consumer\n * serving its own set over HTTP imports the root entry and carries none of the\n * set's 1.7 MB. Envelopes are loaded one at a time, through the per-id dynamic\n * imports the artifacts package generates, so a bundler can split them.\n */\n\nimport { ENVELOPE_LOADERS, REGISTRY } from \"@vcollab/shader-artifacts\";\nimport type { ArtifactSource } from \"./load.js\";\nimport { ShaderSet, ShaderSetError } from \"./load.js\";\n\n/** An {@link ArtifactSource} over the set bundled with this library. */\nexport function bundledSource(): ArtifactSource {\n return {\n readRegistry: async () => REGISTRY,\n readEnvelope: async (entry) => {\n const load = Object.hasOwn(ENVELOPE_LOADERS, entry.id)\n ? ENVELOPE_LOADERS[entry.id]\n : undefined;\n if (load === undefined) {\n throw new ShaderSetError(`the bundled set carries no envelope for ${entry.id}.`);\n }\n return load();\n },\n };\n}\n\n/** Open the set bundled with this library. */\nexport function openBundledSet(): Promise<ShaderSet> {\n return ShaderSet.open(bundledSource());\n}\n"]}
|