@forgeax/engine-codec 0.1.2
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/LICENSE +202 -0
- package/README.md +268 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/basis-encode-fast-preset.unit.test.d.ts +2 -0
- package/dist/__tests__/basis-encode-fast-preset.unit.test.d.ts.map +1 -0
- package/dist/__tests__/basis-encode-lifecycle.unit.test.d.ts +2 -0
- package/dist/__tests__/basis-encode-lifecycle.unit.test.d.ts.map +1 -0
- package/dist/__tests__/basis-encode-mode-owner.test-d.d.ts +2 -0
- package/dist/__tests__/basis-encode-mode-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/basis-transcoder.unit.test.d.ts +2 -0
- package/dist/__tests__/basis-transcoder.unit.test.d.ts.map +1 -0
- package/dist/__tests__/block-format.unit.test.d.ts +2 -0
- package/dist/__tests__/block-format.unit.test.d.ts.map +1 -0
- package/dist/__tests__/byte-identical-falsification.test.d.ts +2 -0
- package/dist/__tests__/byte-identical-falsification.test.d.ts.map +1 -0
- package/dist/__tests__/codec-errors.test-d.d.ts +2 -0
- package/dist/__tests__/codec-errors.test-d.d.ts.map +1 -0
- package/dist/__tests__/codec-errors.unit.test.d.ts +2 -0
- package/dist/__tests__/codec-errors.unit.test.d.ts.map +1 -0
- package/dist/__tests__/compression-field.unit.test.d.ts +19 -0
- package/dist/__tests__/compression-field.unit.test.d.ts.map +1 -0
- package/dist/__tests__/encode-pixel-limit.unit.test.d.ts +2 -0
- package/dist/__tests__/encode-pixel-limit.unit.test.d.ts.map +1 -0
- package/dist/__tests__/encode-roundtrip.unit.test.d.ts +2 -0
- package/dist/__tests__/encode-roundtrip.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-basis-capability-matrix.unit.test.d.ts +2 -0
- package/dist/__tests__/ktx2-basis-capability-matrix.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-errors.test.d.ts +2 -0
- package/dist/__tests__/ktx2-errors.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-parse-scheme0.test.d.ts +2 -0
- package/dist/__tests__/ktx2-parse-scheme0.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-parse-scheme2.test.d.ts +2 -0
- package/dist/__tests__/ktx2-parse-scheme2.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-scheme1-and-transcode-errors.unit.test.d.ts +2 -0
- package/dist/__tests__/ktx2-scheme1-and-transcode-errors.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-to-texture.integration.test.d.ts +2 -0
- package/dist/__tests__/ktx2-to-texture.integration.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-validation.unit.test.d.ts +2 -0
- package/dist/__tests__/runtime-validation.unit.test.d.ts.map +1 -0
- package/dist/__tests__/transcode-select-target.unit.test.d.ts +2 -0
- package/dist/__tests__/transcode-select-target.unit.test.d.ts.map +1 -0
- package/dist/__tests__/wasm-init-smoke.test.d.ts +2 -0
- package/dist/__tests__/wasm-init-smoke.test.d.ts.map +1 -0
- package/dist/__tests__/zstd-deterministic.unit.test.d.ts +2 -0
- package/dist/__tests__/zstd-deterministic.unit.test.d.ts.map +1 -0
- package/dist/__tests__/zstd-encode-singleton.unit.test.d.ts +2 -0
- package/dist/__tests__/zstd-encode-singleton.unit.test.d.ts.map +1 -0
- package/dist/__tests__/zstd-roundtrip.unit.test.d.ts +2 -0
- package/dist/__tests__/zstd-roundtrip.unit.test.d.ts.map +1 -0
- package/dist/__tests__/zstd-singleton.unit.test.d.ts +2 -0
- package/dist/__tests__/zstd-singleton.unit.test.d.ts.map +1 -0
- package/dist/basis-transcoder.d.ts +86 -0
- package/dist/basis-transcoder.d.ts.map +1 -0
- package/dist/block-format.d.ts +41 -0
- package/dist/block-format.d.ts.map +1 -0
- package/dist/encode/basis-encode.d.ts +68 -0
- package/dist/encode/basis-encode.d.ts.map +1 -0
- package/dist/encode/index.d.ts +10 -0
- package/dist/encode/index.d.ts.map +1 -0
- package/dist/encode/index.mjs +207 -0
- package/dist/encode/index.mjs.map +1 -0
- package/dist/encode-impl.d.ts +30 -0
- package/dist/encode-impl.d.ts.map +1 -0
- package/dist/errors.d.ts +61 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +672 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ktx2.d.ts +111 -0
- package/dist/ktx2.d.ts.map +1 -0
- package/dist/transcode.d.ts +55 -0
- package/dist/transcode.d.ts.map +1 -0
- package/dist/wasm/basis-types.d.ts +179 -0
- package/dist/wasm/basis-types.d.ts.map +1 -0
- package/dist/zstd.d.ts +28 -0
- package/dist/zstd.d.ts.map +1 -0
- package/package.json +71 -0
- package/pkg/basis_transcoder.mjs +2 -0
- package/pkg/basis_transcoder.wasm +0 -0
- package/pkg/encode/basis_encoder.mjs +2 -0
- package/pkg/encode/basis_encoder.wasm +0 -0
- package/scripts/build-wasm.mjs +370 -0
- package/scripts/content-key.mjs +85 -0
- package/scripts/ensure-wasm.mjs +38 -0
- package/scripts/fetch-basis.mjs +150 -0
- package/scripts/fetch-wasm.mjs +97 -0
- package/src/__tests__/basis-encode-fast-preset.unit.test.ts +204 -0
- package/src/__tests__/basis-encode-lifecycle.unit.test.ts +249 -0
- package/src/__tests__/basis-encode-mode-owner.test-d.ts +39 -0
- package/src/__tests__/basis-transcoder.unit.test.ts +502 -0
- package/src/__tests__/block-format.unit.test.ts +215 -0
- package/src/__tests__/byte-identical-falsification.test.ts +164 -0
- package/src/__tests__/codec-errors.test-d.ts +67 -0
- package/src/__tests__/codec-errors.unit.test.ts +128 -0
- package/src/__tests__/compression-field.unit.test.ts +245 -0
- package/src/__tests__/encode-pixel-limit.unit.test.ts +117 -0
- package/src/__tests__/encode-roundtrip.unit.test.ts +239 -0
- package/src/__tests__/ktx2-basis-capability-matrix.unit.test.ts +241 -0
- package/src/__tests__/ktx2-errors.test.ts +239 -0
- package/src/__tests__/ktx2-parse-scheme0.test.ts +263 -0
- package/src/__tests__/ktx2-parse-scheme2.test.ts +220 -0
- package/src/__tests__/ktx2-scheme1-and-transcode-errors.unit.test.ts +178 -0
- package/src/__tests__/ktx2-to-texture.integration.test.ts +384 -0
- package/src/__tests__/runtime-validation.unit.test.ts +19 -0
- package/src/__tests__/transcode-select-target.unit.test.ts +167 -0
- package/src/__tests__/wasm-init-smoke.test.ts +102 -0
- package/src/__tests__/zstd-deterministic.unit.test.ts +49 -0
- package/src/__tests__/zstd-encode-singleton.unit.test.ts +63 -0
- package/src/__tests__/zstd-roundtrip.unit.test.ts +87 -0
- package/src/__tests__/zstd-singleton.unit.test.ts +105 -0
- package/src/basis-transcoder.ts +380 -0
- package/src/block-format.ts +128 -0
- package/src/encode/basis-encode.ts +264 -0
- package/src/encode/index.ts +19 -0
- package/src/encode-impl.ts +103 -0
- package/src/errors.ts +79 -0
- package/src/index.ts +38 -0
- package/src/ktx2.ts +469 -0
- package/src/transcode.ts +99 -0
- package/src/wasm/basis-types.ts +220 -0
- package/src/zstd.ts +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# @forgeax/engine-codec
|
|
2
|
+
|
|
3
|
+
> `@forgeax/engine-codec` provides zstd decode/encode, KTX2 container parse,
|
|
4
|
+
> Basis transcode, block-format lookup, and build-time Basis encode --
|
|
5
|
+
> a single package covering the full runtime codec surface for the forgeax
|
|
6
|
+
> asset pipeline.
|
|
7
|
+
|
|
8
|
+
> [!IMPORTANT]
|
|
9
|
+
> This package uses **subpath-level encode/decode separation** (D-1). The main entry
|
|
10
|
+
(`@forgeax/engine-codec`) exports runtime-safe decode + transcode + block-format
|
|
11
|
+
functions. The `/encode` subpath (`@forgeax/engine-codec/encode`) exports
|
|
12
|
+
build-time encode (zstd + Basis). Runtime code must never import from `/encode` --
|
|
13
|
+
this is enforced by `check-image-pipeline-isolation.mjs` path d (AC-09).
|
|
14
|
+
|
|
15
|
+
## WASM provisioning
|
|
16
|
+
|
|
17
|
+
> [!IMPORTANT]
|
|
18
|
+
> In a contributor checkout, `pkg/` is an Emscripten build artifact and is
|
|
19
|
+
> **not committed to git**. It contains the runtime transcoder and build-time
|
|
20
|
+
> encoder bundles, so a fresh checkout must hydrate it before using Basis KTX2
|
|
21
|
+
> paths.
|
|
22
|
+
|
|
23
|
+
> [!NOTE]
|
|
24
|
+
> A source tree containing `.forgeax-public-distribution` is the public SDK
|
|
25
|
+
> source mode. It already carries the checked `pkg/` closure, so ordinary SDK
|
|
26
|
+
> install/build work must not fetch WASM or require Emscripten. Run `build:wasm`
|
|
27
|
+
> only when the codec WASM source or its toolchain changes.
|
|
28
|
+
|
|
29
|
+
| Path | Command | Use |
|
|
30
|
+
|:--|:--|:--|
|
|
31
|
+
| Pre-built release | `pnpm -F @forgeax/engine-codec fetch-wasm` | Fast setup without Emscripten |
|
|
32
|
+
| Local build | `pnpm -F @forgeax/engine-codec build:wasm` | Rebuild with the Emscripten toolchain |
|
|
33
|
+
| Opt out | `FORGEAX_SKIP_CODEC_WASM_FETCH=1 pnpm install` | Toolchain owners provisioning separately |
|
|
34
|
+
|
|
35
|
+
<details>
|
|
36
|
+
<summary>Release selection, fallback, and recovery</summary>
|
|
37
|
+
|
|
38
|
+
The pre-built bundle is published under the `wasm-artifacts` GitHub Release tag
|
|
39
|
+
as `basis-wasm-pkg-{sha8}.tar.gz`. The content key is the first eight characters
|
|
40
|
+
of `SHA256(fetch-basis.mjs + build-wasm.mjs)`, shared by the consumer and the CI
|
|
41
|
+
publisher. The tarball contains the whole `pkg/` tree:
|
|
42
|
+
|
|
43
|
+
- `basis_transcoder.mjs` + `basis_transcoder.wasm` for runtime transcode;
|
|
44
|
+
- `encode/basis_encoder.mjs` + `encode/basis_encoder.wasm` for build-time encode.
|
|
45
|
+
|
|
46
|
+
The shared downloader tries Node `fetch` first, then authenticated `gh` and
|
|
47
|
+
platform-native `curl` (`curl.exe` on Windows) when the Node TLS/network
|
|
48
|
+
handshake fails. All paths remain pinned to the current repository, the
|
|
49
|
+
`wasm-artifacts` tag, and the exact content-keyed asset. Authentication uses
|
|
50
|
+
`GITHUB_TOKEN`/`GH_TOKEN` or `gh auth login`.
|
|
51
|
+
|
|
52
|
+
`postinstall` uses the same fetch path on a best-effort basis: an unavailable
|
|
53
|
+
release does not fail a bare install, while a later build or typecheck reports
|
|
54
|
+
that `pkg/` still needs provisioning. Use `build:wasm` when no matching release
|
|
55
|
+
exists; it runs `fetch-basis.mjs` and `build-wasm.mjs` and requires `emcc`.
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
### Runtime-safe decode (main entry)
|
|
62
|
+
|
|
63
|
+
| Export | Signature | Description |
|
|
64
|
+
|:--|:--|:--|
|
|
65
|
+
| `decompressZstd` | `(bytes: Uint8Array) => Promise<CodecResult<Uint8Array>>` | Decompress a zstd-compressed byte buffer. Lazy-init singleton (fzstd pure JS, zero WASM); concurrent first calls share the same init promise (AC-12). Returns `CodecOk<Uint8Array>` on success, `CodecError` on failure. |
|
|
66
|
+
| `parseKtx2` | `(bytes: Uint8Array) => Promise<CodecResult<Ktx2Parsed>>` | Parse a KTX2 2.0 container (12B magic validation). Returns header, index, level index, DFD, KV metadata, and SGD descriptor -- all five parts per AC-03. Does **not** interpret block-compressed payload content (OOS-6, Loop 2). Async -- `await` the result. |
|
|
67
|
+
| `ktx2LevelsToRGBA` | `(parsed: Ktx2Parsed, level?: number) => Promise<CodecResult<Uint8Array>>` | Extract RGBA bytes from a parsed KTX2 container. Handles scheme=0 (uncompressed, pass-through) and scheme=2 (zstd supercompression, reuses `decompressZstd` per AC-04). The optional `level` parameter selects a mip level (default: 0). Returns the level's RGBA bytes as a flat `Uint8Array`. |
|
|
68
|
+
| `selectTranscodeTarget` | `(dfdModel: number, srgb: boolean, channels: number, caps: TranscodeCaps) => GPUTextureFormat \| null` | Pure-function priority chain (node-safe, zero DOM): given a DFD color model, srgb flag, channel count, and device caps, returns the best native block format. The chain is LDR RGBA: `ASTC4x4 -> BC7 -> ETC2 -> RGBA8` (with srgb variants); single-channel R: `BC4 -> EAC-R11 -> R8`; two-channel RG: `BC5 -> EAC-RG11 -> RG8`; HDR: `BC6H -> rgba16float`. BC-first rule: when BC and ETC2/ASTC coexist, the chain selects BC (D-4 Mesa guard). Input `TranscodeCaps { bc, etc2, astc }` is a local struct -- codec never imports from rhi. Returns non-null (no-cap fallback to rgba8unorm/rgba16float). |
|
|
69
|
+
| `initBasisTranscoder` | `() => Promise<BasisTranscoderModule>` | Lazy-init singleton (main-thread, D-10). First call dynamic-imports + initializes the basis_transcoder WASM; subsequent calls return the cached instance. |
|
|
70
|
+
| `transcodeKtx2` | `(parsed: Ktx2Parsed, targetFormat: GPUTextureFormat) => Promise<CodecResult<TranscodedMips>>` | Transcode a scheme=1 (BasisLZ) KTX2 payload to a native block format. Iterates every mip level through the transcoder, returning `TranscodedMips { format, mips: { data, width, height }[] }`. Calls init on first use. |
|
|
71
|
+
| `bytesPerRow` | `(width: number, format: GPUTextureFormat) => number` | Block-aligned bytes-per-row: `ceil(width / blockW) * bytesPerBlock`. Returns `width * 4` for non-compressed formats. SSOT with `blockFormatInfo`. |
|
|
72
|
+
| `rowsPerImage` | `(height: number, format: GPUTextureFormat) => number` | Block-aligned rows-per-image: `ceil(height / blockH)`. Returns `height` for non-compressed formats. |
|
|
73
|
+
| `blockFormatInfo` | `(format: GPUTextureFormat) => { blockW: number, blockH: number, bytesPerBlock: number } \| undefined` | Block dimension lookup table covering BC1-BC7, ETC2, ASTC4x4, EAC, BC6H. Returns undefined for non-compressed formats. |
|
|
74
|
+
| `isCompressedFormat` | `(format: GPUTextureFormat) => boolean` | Type guard returning true for all block-compressed formats in `blockFormatInfo`. |
|
|
75
|
+
|
|
76
|
+
**Priority chain rules** (D-4 BC-first, D-8 local TranscodeCaps):
|
|
77
|
+
|
|
78
|
+
| Source (channels, color, srgb) | BC cap | ETC2 cap | ASTC cap | Target format |
|
|
79
|
+
|:--|:--|:--|:--|:--|
|
|
80
|
+
| RGBA, LDR, srgb | yes | yes | yes | `bc7-rgba-unorm-srgb` |
|
|
81
|
+
| RGBA, LDR, srgb | no | yes | -- | `etc2-rgba8unorm-srgb` |
|
|
82
|
+
| RGBA, LDR, srgb | no | no | yes | `astc-4x4-unorm-srgb` |
|
|
83
|
+
| RGBA, LDR, srgb | no | no | no | `rgba8unorm-srgb` |
|
|
84
|
+
| R, LDR | yes | -- | -- | `bc4-r-unorm` |
|
|
85
|
+
| R, LDR | no | yes | -- | `eac-r11unorm` |
|
|
86
|
+
| R, LDR | no | no | -- | `r8unorm` |
|
|
87
|
+
| RG, LDR | yes | -- | -- | `bc5-rg-unorm` |
|
|
88
|
+
| RG, LDR | no | yes | -- | `eac-rg11unorm` |
|
|
89
|
+
| RG, LDR | no | no | -- | `rg8unorm` |
|
|
90
|
+
| HDR | yes | -- | -- | `bc6h-rgb-ufloat` |
|
|
91
|
+
| HDR | no | -- | -- | `rgba16float` |
|
|
92
|
+
|
|
93
|
+
**Scheme support** (extended in Loop 2):
|
|
94
|
+
|
|
95
|
+
| Scheme | Name | Supported | Path |
|
|
96
|
+
|:--|:--|:--|:--|
|
|
97
|
+
| 0 | None (uncompressed) | yes | `ktx2LevelsToRGBA` pass-through |
|
|
98
|
+
| 1 | BasisLZ | yes | `parseKtx2` -> `transcodeKtx2` |
|
|
99
|
+
| 2 | Zstandard | yes | `ktx2LevelsToRGBA` + `decompressZstd` |
|
|
100
|
+
| 3 | ZLIB / DEFLATE | no | returns `ktx2-unsupported-scheme` |
|
|
101
|
+
|
|
102
|
+
Usage example:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { decompressZstd, parseKtx2, ktx2LevelsToRGBA, codecError }
|
|
106
|
+
from '@forgeax/engine-codec';
|
|
107
|
+
|
|
108
|
+
// Decompress zstd bytes
|
|
109
|
+
const res = await decompressZstd(compressedBytes);
|
|
110
|
+
if (res.ok) {
|
|
111
|
+
const original = res.value; // Uint8Array
|
|
112
|
+
} else {
|
|
113
|
+
switch (res.error.code) {
|
|
114
|
+
case 'decompression-failed': // res.error.detail: { reason }
|
|
115
|
+
case 'codec-init-failed': // res.error.detail: { stage }
|
|
116
|
+
case 'ktx2-parse-failed': // res.error.detail: { reason }
|
|
117
|
+
case 'ktx2-unsupported-scheme': // res.error.detail: { scheme }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Parse KTX2 container and extract RGBA
|
|
122
|
+
const k = await parseKtx2(ktx2Bytes);
|
|
123
|
+
if (k.ok) {
|
|
124
|
+
const rgba = await ktx2LevelsToRGBA(k.value, 0);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Build-time encode (`/encode` subpath)
|
|
129
|
+
|
|
130
|
+
| Export | Signature | Description |
|
|
131
|
+
|:--|:--|:--|
|
|
132
|
+
| `compressZstd` | `(bytes: Uint8Array) => Promise<CodecResult<Uint8Array>>` | Compress bytes with zstd (pinned WASM, fixed level, no dictionary, no timestamp -- deterministic per AC-07). Build-time only; gated from runtime import by `check-image-pipeline-isolation.mjs` path d. |
|
|
133
|
+
|
|
134
|
+
Import path:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { compressZstd } from '@forgeax/engine-codec/encode';
|
|
138
|
+
// ^^^^^^^^^^^^^^^
|
|
139
|
+
// build-time only, blocked from runtime
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Type exports
|
|
143
|
+
|
|
144
|
+
| Export | Description |
|
|
145
|
+
|:--|:--|
|
|
146
|
+
| `CodecErrorCode` | Closed union: `'decompression-failed' \| 'codec-init-failed' \| 'ktx2-parse-failed' \| 'ktx2-unsupported-scheme' \| 'transcode-failed' \| 'ktx2-encode-failed'` (order-locked, add-only-minor) |
|
|
147
|
+
| `CodecError` | Structured error: `{ ok: false, error: { code, expected, hint, detail } }` with per-code narrowed `detail` |
|
|
148
|
+
| `CodecOk<T>` | Success branch: `{ ok: true, value: T }` |
|
|
149
|
+
| `CodecResult<T>` | Discriminated union: `CodecOk<T> \| CodecError` |
|
|
150
|
+
| `Ktx2Header` | Parsed KTX2 header (9 u32 fields + supercompressionScheme) |
|
|
151
|
+
| `Ktx2Index` | Parsed KTX2 index (dfd/kvd/sgd byte offsets and lengths) |
|
|
152
|
+
| `Ktx2LevelEntry` | Per-level byte offset, byte length, uncompressed byte length |
|
|
153
|
+
| `Ktx2Dfd` / `Ktx2DfdSample` | Parsed DFD (data format descriptor) block |
|
|
154
|
+
| `Ktx2KvEntry` | Key-value metadata entry (key string + raw value bytes) |
|
|
155
|
+
| `Ktx2Parsed` | Fully parsed KTX2 container: `{ header, index, levelIndex, dfd, kvEntries, sgd }` |
|
|
156
|
+
|
|
157
|
+
## Error codes
|
|
158
|
+
|
|
159
|
+
All codec errors use the `CodecErrorCode` closed union. Consume with exhaustive
|
|
160
|
+
`switch (err.code)` -- no `default` branch, TypeScript guards completeness.
|
|
161
|
+
|
|
162
|
+
| Code | Trigger condition | `.hint` (executable recovery) | `.detail` payload |
|
|
163
|
+
|:--|:--|:--|:--|
|
|
164
|
+
| `decompression-failed` | Corrupted/malformed zstd input, or encode failure surfaced as decompression error | "Check catalog row compression field and asset binary consistency; re-run asset import." | `{ reason: string }` -- failure cause |
|
|
165
|
+
| `codec-init-failed` | Dynamic import of fzstd decode module failed (network / bundling) | "Uncompressed assets are still loadable. Verify the codec module is installed correctly." | `{ stage: string }` -- failed initialization stage |
|
|
166
|
+
| `ktx2-parse-failed` | KTX2 magic mismatch, header truncation, level index out of bounds (E5) | "Check that the KTX2 file is valid and not truncated. Re-import the texture asset." | `{ reason: string }` -- parse failure location |
|
|
167
|
+
| `ktx2-unsupported-scheme` | KTX2 supercompression scheme is ZLIB (=3) or other unsupported scheme. Scheme 1 (BasisLZ) and 2 (Zstd) are accepted. | "This supercompression scheme requires a future codec upgrade. Check the codec README Loop 2 extension points." | `{ scheme: number }` -- the unsupported scheme value |
|
|
168
|
+
| `transcode-failed` | Basis transcoder returned 0 bytes or threw an error during transcode. The payload may be corrupt or the target format incompatible with the DFD model. | "Verify the KTX2/Basis asset payload is valid. Check that selectTranscodeTarget returned a compatible format." | `{ sourceFormat: GPUTextureFormat, targetFormat: GPUTextureFormat }` -- the source + requested target |
|
|
169
|
+
| `ktx2-encode-failed` | Basis encoder returned 0 bytes or threw. May indicate invalid dimensions, incompatible pixel format, or encoder-side memory exhaustion. | "Check input texture dimensions and pixel format. Verify the Basis encoder WASM was built correctly (pnpm --filter @forgeax/engine-codec build:wasm)." | `{ mode: string, reason: string }` -- the encode mode + failure reason |
|
|
170
|
+
|
|
171
|
+
### Error propagation
|
|
172
|
+
|
|
173
|
+
Codec errors are consumed in two contexts:
|
|
174
|
+
|
|
175
|
+
1. **Direct consumption** -- AI users calling `decompressZstd` / `parseKtx2` directly
|
|
176
|
+
get the full `CodecError` with per-code narrowed `detail`.
|
|
177
|
+
|
|
178
|
+
2. **Runtime transparent pass-through** -- in the runtime's `fetchBinary` gate,
|
|
179
|
+
codec errors are nested in the existing `asset-fetch-failed` error's `.detail`
|
|
180
|
+
field. The types-shared `ErrorCode` union is NOT extended (D-8). AI users
|
|
181
|
+
doing a typed `AssetRegistry.load(guid, kind)` never see `CodecErrorCode` directly; they see the standard
|
|
182
|
+
asset error surface.
|
|
183
|
+
|
|
184
|
+
## Loop 2 extension points
|
|
185
|
+
|
|
186
|
+
> [!NOTE]
|
|
187
|
+
> This section documents the 3 frozen contract seams that Loop 2
|
|
188
|
+
> ("texture block-compression") consumes without re-designing (AC-13).
|
|
189
|
+
> Do not delete or rearrange these sections -- they are the hand-off interface.
|
|
190
|
+
|
|
191
|
+
### Contract seam 1: `compression` sidecar field
|
|
192
|
+
|
|
193
|
+
The `AssetCompression` union (`packages/types/src/index.ts`) currently has:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
type AssetCompression = 'none' | 'zstd';
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Loop 2 extension**: May add combination literal members such as `'zstd+bc7'`,
|
|
200
|
+
`'zstd+astc'`, or `'basis-uastc'` to represent block-compressed payloads wrapped
|
|
201
|
+
in zstd supercompression. The field is consumed in `PackIndexEntry.compression?`,
|
|
202
|
+
`ImageMetadata.compression?`, `LoaderEntry.compression?`, `listCatalog()` return
|
|
203
|
+
rows, and `importSettings`. Loop 2 adds members here; runtime `fetchBinary`
|
|
204
|
+
gate branches on the string value.
|
|
205
|
+
|
|
206
|
+
### Contract seam 2: runtime single decompression gate
|
|
207
|
+
|
|
208
|
+
The runtime decompression happens in exactly one place:
|
|
209
|
+
`fetchBinary(url, { compression })` in `asset-registry.ts`. The gate currently
|
|
210
|
+
branches on `compression === 'zstd'` to call `decompressZstd`. Raw bytes are
|
|
211
|
+
returned to loaders unchanged in all other cases.
|
|
212
|
+
|
|
213
|
+
**Loop 2 extension**: After zstd decompression returns raw bytes, Loop 2 adds a
|
|
214
|
+
second gate for block-compressed payloads: `basis_transcoder.wasm` transcode from
|
|
215
|
+
the universal intermediate format to the platform's native block format.
|
|
216
|
+
The transcoder hangs **after** the zstd gate -- same `fetchBinary` entry point,
|
|
217
|
+
no second decompression point (contract seam 2 constraint).
|
|
218
|
+
|
|
219
|
+
### Contract seam 3: KTX2 container parser
|
|
220
|
+
|
|
221
|
+
`parseKtx2(bytes)` returns `Ktx2Parsed` with `header.supercompressionScheme`,
|
|
222
|
+
`levelIndex` (per-level `byteOffset` / `byteLength` / `uncompressedByteLength`),
|
|
223
|
+
`dfd.colorModel`, and `sgd`. `ktx2LevelsToRGBA` handles scheme=0 (uncompressed)
|
|
224
|
+
and scheme=2 (zstd) only.
|
|
225
|
+
|
|
226
|
+
**Loop 2 extension**: For scheme=1 (BasisLZ), `parseKtx2` already provides:
|
|
227
|
+
- `levelIndex[].byteOffset` and `levelIndex[].byteLength` -- the block payload
|
|
228
|
+
bytes to feed into `basis_transcoder.wasm`
|
|
229
|
+
- `dfd.colorModel` and `dfd.colorPrimaries` -- color space metadata for upload
|
|
230
|
+
- `sgd` (supercompression global data) -- the BasisLZ codebook
|
|
231
|
+
|
|
232
|
+
Loop 2 adds a third arm to `ktx2LevelsToRGBA` for scheme=1 that calls the
|
|
233
|
+
transcoder instead of `decompressZstd`. The container parser itself does NOT
|
|
234
|
+
change -- Loop 2 reuses the same `parseKtx2` export (contract seam 3 constraint).
|
|
235
|
+
|
|
236
|
+
### Compression ratio baseline (AC-05)
|
|
237
|
+
|
|
238
|
+
zstd compression on representative mesh `.bin` data achieves approximately 30-60%
|
|
239
|
+
size reduction (f32 vertex data). The AC-05 assertion floor is `>= 30%` on the
|
|
240
|
+
compression ratio (compressed / original <= 0.70). Loop 2 may establish separate
|
|
241
|
+
ratios for block-compressed textures.
|
|
242
|
+
|
|
243
|
+
## Package metrics (AC-11)
|
|
244
|
+
|
|
245
|
+
The codec package declares all 5 `MetricKind` entries in
|
|
246
|
+
`package.json#forgeax.metrics`:
|
|
247
|
+
|
|
248
|
+
| Metric | Status | Reason |
|
|
249
|
+
|:--|:--|:--|
|
|
250
|
+
| `bundle-size` | enabled | Measures decode entry dist bundle (`dist/index.mjs` gzip). fzstd is pure JS (no WASM), so this captures the full decode cost. |
|
|
251
|
+
| `fps` | disabled | Pure-function library, no render-loop impact |
|
|
252
|
+
| `bench` | disabled | No performance-sensitive hot paths to benchmark in isolation |
|
|
253
|
+
| `gate` | disabled | No codec-specific gates beyond metric declaration itself |
|
|
254
|
+
| `spike-report` | disabled | No spiking concerns for a deterministic pure-function library |
|
|
255
|
+
|
|
256
|
+
## Build-time encode subpath
|
|
257
|
+
|
|
258
|
+
The `/encode` subpath (`@forgeax/engine-codec/encode`) exports `compressZstd`
|
|
259
|
+
for build-time use only. It is consumed by `vite-plugin-pack`'s
|
|
260
|
+
`compress-artifact.ts` SSOT function. Runtime code must never import from this
|
|
261
|
+
subpath -- enforced by `check-image-pipeline-isolation.mjs` path d (AC-09).
|
|
262
|
+
|
|
263
|
+
## Related documentation
|
|
264
|
+
|
|
265
|
+
- `packages/runtime/README.md` -- `fetchBinary` automatic decompression gate
|
|
266
|
+
- `packages/pack/README.md` -- `compression` field in pack-index row schema
|
|
267
|
+
- `skills/forgeax-engine-assets/SKILL.md` -- AI user-facing asset pipeline
|
|
268
|
+
- `docs/superpowers/specs/2026-07-06-asset-compression-pipeline-roadmap-design.md` -- two-loop roadmap
|