@pmndrs/vdb 0.0.0-stage → 0.2.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.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,762 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0), through the TSL sparse source
2
+ // (`three/sparse-source.ts`, K3.2): frameShaderChunks.js L729–763 (createVolumeUniforms, the source half) and
3
+ // L834–1028 (createVolumeNodes).
4
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
5
+ // Changes: engine-free; one source per pool serving every volume through a uniform table indexed by `v`; the
6
+ // coarse pyramids of all volumes packed in one r16float texture. Divergences: DIVERGES.md (K3.2 rows, K6.7 row).
7
+ /**
8
+ * `vdbSparseSource(pool, options)` (K6.7, design K6-core-renderer.md §2.1): the sparse volume source of the core
9
+ * renderer, on raw WebGPU. One source serves every volume of one `VDBGridPool`:
10
+ *
11
+ * const source = vdbSparseSource(pool, { followImage: true });
12
+ * const slot = source.volume({ density: id }); // a VDBVolumeSlot; slot.v indexes the source's table
13
+ * // per frame, in the host's encoder:
14
+ * pool.update(encoder);
15
+ * source.update(encoder); // pyramids, layouts, the table (after the pool's update)
16
+ * // bind group 2: source.layoutEntries(slot2) / source.bindEntries(slot2) (rebuild when source.version moves)
17
+ * // WGSL: source.moduleWgsl(slot2) (or the renderer's one module with source.module's helpers) + source.wgsl(...)
18
+ *
19
+ * Group 2 at `slot` = { group, firstBinding: b }: b the pool (the VDB module's storage buffer, D10), b + 1 the volume
20
+ * table (`array<VdbSrcVolume, maxVolumes>`, uniform), and with `lod: 'coarse-pyramid'` b + 2 the packed pyramid
21
+ * atlas (r16float `texture_3d<f32>`) and b + 3 its sampler (linear, clamp to edge).
22
+ *
23
+ * The WGSL depends only on the options (LOD strategy, channels, `maxVolumes`, sampling options): boxes, pool ids,
24
+ * LOD ranges and pyramid placements are values in the table, so adding volumes, a sequence frame (`pool.replace`)
25
+ * or a coarse-first swap (`followImage`) never changes it, and with `types` fixed (the default
26
+ * `VDB_ALL_SCALAR_TYPES`; the pyramid kernels of every type are compiled at creation when following images) a
27
+ * swap creates no pipeline and no shader module (G16a).
28
+ *
29
+ * Per volume (see {@link VDBSparseVolume}): `texels`, `lodLevels`, `stats`, `boxToSource`, `bbox` and `version`
30
+ * describe that volume; the source's own copies of the {@link VDBVolumeSourceInfo} fields are aggregates.
31
+ */
32
+ import { VDBError } from "../errors.js";
33
+ import { VDBRetireQueue } from "../frame/resources.js";
34
+ import { VDB_ALL_SCALAR_TYPES } from "../types.js";
35
+ import { vdbModuleEntries, vdbModuleWgsl } from "../wgsl/generate.js";
36
+ import { vdbCreateBoxPyramid, warmBoxPyramidPipelines } from "../compute/pyramid.js";
37
+ import { vdbBoxPyramidLayout, vdbPackPyramidBlocks } from "../../tools/frame/pyramid-layout.js";
38
+ import { vdbSparseDensityStats } from "../../tools/frame/sparse.js";
39
+ import { packSparseRecord, sparseBindings, sparseSourceWgsl, SPARSE_FLAG, VDB_SPARSE_RECORD_BYTES } from "./sparse-wgsl.js";
40
+ import { VDBSparseBrickCache } from "./brick-cache.js";
41
+ import { VDB_BRICK_KERNELS, vdbBrickKernelUse } from "../../tools/frame/brick-cache.js";
42
+ /** WebGPU flag values (the globals do not exist in Node). */
43
+ const BUFFER = { MAP_READ: 0x1, COPY_DST: 0x8, UNIFORM: 0x40 };
44
+ const TEXTURE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4 };
45
+ const STAGE_FRAGMENT_COMPUTE = 0x2 | 0x4;
46
+ /** Updates a replaced GPU object outlives (the core's retire rule: destroyed two updates later). */
47
+ const RETIRE_UPDATES = 2;
48
+ const bad = (message) => new VDBError("VDB_BAD_OPTION", `vdbSparseSource: ${message}`);
49
+ function checkSlot(slot, where) {
50
+ if (!slot || !Number.isInteger(slot.group) || slot.group < 0 || !Number.isInteger(slot.firstBinding) || slot.firstBinding < 0) {
51
+ throw bad(`${where}: slot must be { group, firstBinding } with non-negative integers, got ${JSON.stringify(slot)}.`);
52
+ }
53
+ return slot;
54
+ }
55
+ const copyBox = (b) => ({ min: [b.min[0], b.min[1], b.min[2]], max: [b.max[0], b.max[1], b.max[2]] });
56
+ const sizeOf = (b) => [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];
57
+ const sameBox = (a, b) => a.min.every((v, i) => v === b.min[i]) && a.max.every((v, i) => v === b.max[i]);
58
+ /** World AABB of an index cell box through a 3x4 row-major affine (the TSL source's `worldBox`). */
59
+ function worldBox(box, m) {
60
+ const lo = [Infinity, Infinity, Infinity];
61
+ const hi = [-Infinity, -Infinity, -Infinity];
62
+ for (let c = 0; c < 8; c++) {
63
+ const p = [c & 1 ? box.max[0] + 0.5 : box.min[0] - 0.5, c & 2 ? box.max[1] + 0.5 : box.min[1] - 0.5, c & 4 ? box.max[2] + 0.5 : box.min[2] - 0.5];
64
+ for (let r = 0; r < 3; r++) {
65
+ const v = m[r * 4] * p[0] + m[r * 4 + 1] * p[1] + m[r * 4 + 2] * p[2] + m[r * 4 + 3];
66
+ lo[r] = Math.min(lo[r], v);
67
+ hi[r] = Math.max(hi[r], v);
68
+ }
69
+ }
70
+ return [lo, hi];
71
+ }
72
+ /** Local unit box → sample index space: p = min − ½ + (local + ½)·size (column-major; the TSL source's). */
73
+ function boxToIndex(b) {
74
+ const [sx, sy, sz] = sizeOf(b);
75
+ return new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);
76
+ }
77
+ class SparseVolume {
78
+ kind = "sparse";
79
+ source;
80
+ v;
81
+ ids;
82
+ channels;
83
+ indexBox;
84
+ auxBoxes;
85
+ texels;
86
+ lodLevels = 0;
87
+ stats;
88
+ boxToSource;
89
+ bbox;
90
+ statsUpdates = 0;
91
+ layoutUpdates = 0;
92
+ removed = false;
93
+ entry = null;
94
+ /** The channel grids' newest imageRevision the layout describes (followImage) and the pool revision last checked. */
95
+ layoutRevision = 0;
96
+ layoutPoolRevision = -1;
97
+ /** The density imageRevision the stats describe; -1 = none yet (read back once resident). */
98
+ statsRevision;
99
+ readback = null;
100
+ poolIds;
101
+ #versionSeen = { poolRevision: -1, value: 0 };
102
+ constructor(source, v, ids, o) {
103
+ this.source = source;
104
+ this.v = v;
105
+ const albedo = Array.isArray(ids.albedo) ? [...ids.albedo] : ids.albedo;
106
+ this.ids = Object.freeze({ ...ids, ...(albedo !== undefined ? { albedo } : {}) });
107
+ this.channels = { mask: ids.mask !== undefined, albedo: ids.albedo !== undefined, emission: ids.emission !== undefined };
108
+ this.poolIds = [...new Set([ids.density, ids.mask, ids.emission, ...(Array.isArray(albedo) ? albedo : [albedo])].filter((x) => x !== undefined))];
109
+ const pool = source.pool;
110
+ const density = pool.info(ids.density);
111
+ this.indexBox = copyBox(o.indexBox ?? density.indexBBox);
112
+ this.texels = sizeOf(this.indexBox);
113
+ if (this.texels.some((t) => !(t > 0)))
114
+ throw bad("the density index box is empty.");
115
+ const aux = o.auxIndexBoxes ?? {};
116
+ const box = (id, given) => (id === undefined ? null : copyBox(given ?? pool.info(id).indexBBox));
117
+ this.auxBoxes = { mask: box(ids.mask, aux.mask), albedo: box(this.albedoId, aux.albedo), emission: box(ids.emission, aux.emission) };
118
+ this.boxToSource = boxToIndex(this.indexBox);
119
+ this.bbox = o.bbox ? [[...o.bbox[0]], [...o.bbox[1]]] : worldBox(this.indexBox, density.indexToWorld);
120
+ const clamp01 = source.normalize === "clamp01";
121
+ this.stats = o.stats ? { ...o.stats } : o.image ? vdbSparseDensityStats(o.image, clamp01) : { meanNonZero: 0, max: 0, activeVoxels: 0 };
122
+ this.statsRevision = o.stats || o.image ? density.imageRevision : -1;
123
+ this.layoutRevision = this.poolIds.reduce((r, id) => Math.max(r, pool.info(id).imageRevision), 0);
124
+ }
125
+ get albedoId() {
126
+ const a = this.ids.albedo;
127
+ return Array.isArray(a) ? a[0] : a;
128
+ }
129
+ /** Content version: the image revision the layout describes (following), else the newest channel imageRevision. */
130
+ get version() {
131
+ if (this.source.followImage)
132
+ return this.layoutRevision;
133
+ const pool = this.source.pool;
134
+ if (pool.revision !== this.#versionSeen.poolRevision) {
135
+ let value = 0;
136
+ for (const id of this.poolIds) {
137
+ try {
138
+ value = Math.max(value, pool.info(id).imageRevision);
139
+ }
140
+ catch {
141
+ // A removed grid: keep the others' revision.
142
+ }
143
+ }
144
+ this.#versionSeen = { poolRevision: pool.revision, value };
145
+ }
146
+ return this.#versionSeen.value;
147
+ }
148
+ get pyramid() {
149
+ const e = this.entry;
150
+ return e ? { layout: e.layout, base: e.base, atlas: e.atlas } : null;
151
+ }
152
+ /** Re-reads every box from the pool (followImage). */
153
+ relayout() {
154
+ const pool = this.source.pool;
155
+ const density = pool.info(this.ids.density);
156
+ this.indexBox = copyBox(density.indexBBox);
157
+ this.texels = sizeOf(this.indexBox);
158
+ this.boxToSource = boxToIndex(this.indexBox);
159
+ this.bbox = worldBox(this.indexBox, density.indexToWorld);
160
+ const aux = (id) => (id === undefined ? null : copyBox(pool.info(id).indexBBox));
161
+ this.auxBoxes = { mask: aux(this.ids.mask), albedo: aux(this.albedoId), emission: aux(this.ids.emission) };
162
+ this.layoutUpdates++;
163
+ }
164
+ /** The table record. */
165
+ record() {
166
+ const ids = this.ids;
167
+ const albedo = ids.albedo === undefined ? [0, 0, 0] : Array.isArray(ids.albedo) ? ids.albedo : [ids.albedo, ids.albedo, ids.albedo];
168
+ const flags = (this.channels.mask ? SPARSE_FLAG.mask : 0) |
169
+ (this.channels.albedo ? SPARSE_FLAG.albedo : 0) |
170
+ (Array.isArray(ids.albedo) ? SPARSE_FLAG.albedoRgb : 0) |
171
+ (this.channels.emission ? SPARSE_FLAG.emission : 0);
172
+ const minOf = (b) => (b ? b.min : [0, 0, 0]);
173
+ const sizeOfBox = (b) => (b ? sizeOf(b) : [1, 1, 1]);
174
+ const e = this.entry;
175
+ const layout = e?.layout;
176
+ return {
177
+ ids: [ids.density, ids.mask ?? 0, ids.emission ?? 0, flags],
178
+ albedo: [albedo[0], albedo[1], albedo[2], 0],
179
+ lod: [this.lodLevels, layout?.level ?? 0, layout?.atlas?.levels.length ?? 0, this.stats.max],
180
+ densityMin: this.indexBox.min,
181
+ densitySize: this.texels,
182
+ maskMin: minOf(this.auxBoxes.mask),
183
+ maskSize: sizeOfBox(this.auxBoxes.mask),
184
+ albedoMin: minOf(this.auxBoxes.albedo),
185
+ albedoSize: sizeOfBox(this.auxBoxes.albedo),
186
+ emissionMin: minOf(this.auxBoxes.emission),
187
+ emissionSize: sizeOfBox(this.auxBoxes.emission),
188
+ pyrBase: e?.base ?? [0, 0, 0],
189
+ pyrSize: layout?.dimensions ?? [1, 1, 1],
190
+ pyrMip: [...(e?.atlas ?? [0, 0, 0]), layout?.atlas?.dimensions[0] ?? 1],
191
+ };
192
+ }
193
+ remove() {
194
+ this.source.removeVolume(this);
195
+ }
196
+ }
197
+ class SparseSource {
198
+ kind = "sparse";
199
+ pool;
200
+ lod;
201
+ normalize;
202
+ followImage;
203
+ maxVolumes;
204
+ module;
205
+ boxToSource = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
206
+ pyramidBuilds = 0;
207
+ #device;
208
+ #label;
209
+ #types;
210
+ #pyramidMax;
211
+ #fixedChannels;
212
+ #channels = { mask: false, albedo: false, emission: false };
213
+ #wgslBase;
214
+ #slots = [];
215
+ #pyramids = new Map();
216
+ #table;
217
+ #sampler;
218
+ #atlas = null;
219
+ #ownVersion = 0;
220
+ #lastVersion = -1;
221
+ #packDirty = false;
222
+ #tableDirty = true;
223
+ #updates = 0;
224
+ #retired = [];
225
+ /** K6.10a: due objects are destroyed in a later task (several updates may share one encoder and one submit). */
226
+ #later = new VDBRetireQueue();
227
+ #mappings = new Set();
228
+ #disposed = false;
229
+ /** K3.2f: the brick cache (null when off) and whether its page layout must be redone. */
230
+ #bricks;
231
+ /** K3.2f-e: which kernels read and mark the cache, and whether each marks its own section (counts per kernel). */
232
+ #brickKernels;
233
+ #brickMarkStats;
234
+ #bricksLayout = true;
235
+ constructor(pool, o) {
236
+ if (!pool || typeof pool.info !== "function" || !pool.device)
237
+ throw bad("pass a VDBGridPool.");
238
+ this.pool = pool;
239
+ this.#device = pool.device;
240
+ this.#label = o.label ?? "vdb sparse source";
241
+ const lod = o.lod ?? "coarse-pyramid";
242
+ if (lod !== "none" && lod !== "coarse-pyramid" && lod !== "node-average")
243
+ throw bad(`unknown lod ${JSON.stringify(lod)}; use 'none', 'coarse-pyramid' or 'node-average'.`);
244
+ this.lod = lod;
245
+ const normalize = o.normalize ?? "none";
246
+ if (normalize !== "none" && normalize !== "clamp01")
247
+ throw bad(`unknown normalize ${JSON.stringify(normalize)}; use 'none' or 'clamp01'.`);
248
+ this.normalize = normalize;
249
+ if (o.followImage !== undefined && typeof o.followImage !== "boolean")
250
+ throw bad("followImage must be a boolean.");
251
+ this.followImage = o.followImage ?? false;
252
+ const types = o.types ?? VDB_ALL_SCALAR_TYPES;
253
+ if (!Array.isArray(types) || types.length === 0 || types.some((t) => !VDB_ALL_SCALAR_TYPES.includes(t)))
254
+ throw bad(`types must list grid types (${VDB_ALL_SCALAR_TYPES.join(", ")}), got ${JSON.stringify(types)}.`);
255
+ this.#types = Object.freeze([...types]);
256
+ this.#pyramidMax = o.pyramidMax ?? 128;
257
+ if (!Number.isInteger(this.#pyramidMax) || this.#pyramidMax < 1)
258
+ throw bad(`pyramidMax must be a positive integer, got ${o.pyramidMax}.`);
259
+ const skipEmpty = o.skipEmpty ?? true;
260
+ const fastTrilinear = o.fastTrilinear ?? true;
261
+ const cacheAccessor = o.cacheAccessor ?? true;
262
+ const uniformLimit = this.#device.limits?.maxUniformBufferBindingSize ?? 65536;
263
+ const maxVolumes = o.maxVolumes ?? 64;
264
+ const cap = Math.floor(uniformLimit / VDB_SPARSE_RECORD_BYTES);
265
+ if (!Number.isInteger(maxVolumes) || maxVolumes < 1 || maxVolumes > cap)
266
+ throw bad(`maxVolumes must be an integer in [1, ${cap}] (${VDB_SPARSE_RECORD_BYTES} B each in one uniform binding), got ${o.maxVolumes}.`);
267
+ this.maxVolumes = maxVolumes;
268
+ this.#fixedChannels = o.channels ? { ...o.channels } : null;
269
+ if (this.#fixedChannels)
270
+ Object.assign(this.#channels, { mask: !!o.channels.mask, albedo: !!o.channels.albedo, emission: !!o.channels.emission });
271
+ const brick = o.brickCache ?? "off";
272
+ if (brick !== "off" && brick !== "f32" && brick !== "f16")
273
+ throw bad(`brickCache must be 'off', 'f32' or 'f16', got ${JSON.stringify(o.brickCache)}.`);
274
+ this.#wgslBase = { lod, fastTrilinear, cacheAccessor, clamp01: normalize === "clamp01", skipEmpty, maxVolumes, ...(brick !== "off" ? { brick } : {}) };
275
+ const brickKernels = o.brickKernels ?? "all";
276
+ if (brickKernels !== "all" && brickKernels !== "gather-marks" && brickKernels !== "gather-only")
277
+ throw bad(`brickKernels must be 'all', 'gather-marks' or 'gather-only', got ${JSON.stringify(o.brickKernels)}.`);
278
+ if (o.brickMarkStats !== undefined && typeof o.brickMarkStats !== "boolean")
279
+ throw bad("brickMarkStats must be a boolean.");
280
+ this.#brickKernels = brickKernels;
281
+ this.#brickMarkStats = o.brickMarkStats ?? false;
282
+ const helpers = [];
283
+ if (skipEmpty)
284
+ helpers.push("cellBoundTrilinear", "hddaCellEnd");
285
+ if (lod === "node-average")
286
+ helpers.push("nodeAverage");
287
+ if (fastTrilinear)
288
+ helpers.push("fastTrilinear");
289
+ this.module = Object.freeze({ profile: skipEmpty || lod === "node-average" ? "march" : "sample", helpers: Object.freeze(helpers), types: this.#types });
290
+ this.#table = this.#device.createBuffer({ label: `${this.#label} volumes`, size: maxVolumes * VDB_SPARSE_RECORD_BYTES, usage: BUFFER.UNIFORM | BUFFER.COPY_DST });
291
+ if (lod === "coarse-pyramid") {
292
+ this.#sampler = this.#device.createSampler({
293
+ label: `${this.#label} pyramid sampler`,
294
+ magFilter: "linear",
295
+ minFilter: "linear",
296
+ mipmapFilter: "nearest",
297
+ addressModeU: "clamp-to-edge",
298
+ addressModeV: "clamp-to-edge",
299
+ addressModeW: "clamp-to-edge",
300
+ });
301
+ this.#atlas = this.#newAtlas([1, 1, 1]);
302
+ // G16a: a following source compiles the pyramid kernels of every type now, so a swap creates no pipeline.
303
+ if (this.followImage)
304
+ warmBoxPyramidPipelines(this.#device, this.#types);
305
+ }
306
+ else {
307
+ this.#sampler = null;
308
+ }
309
+ this.#bricks =
310
+ brick === "off"
311
+ ? null
312
+ : new VDBSparseBrickCache(this.#device, pool, {
313
+ mode: brick,
314
+ types: this.#types,
315
+ maxVolumes,
316
+ label: this.#label,
317
+ ...(o.brickCapacity !== undefined ? { capacity: o.brickCapacity } : {}),
318
+ ...(o.brickBudget !== undefined ? { budget: o.brickBudget } : {}),
319
+ ...(o.brickPagesMax !== undefined ? { pagesMax: o.brickPagesMax } : {}),
320
+ kernels: brickKernels,
321
+ markStats: this.#brickMarkStats,
322
+ }, { retire: (destroy) => this.#retire(destroy), rebind: () => this.#ownVersion++ });
323
+ }
324
+ /** K3.2f: the brick cache (null when off), for counters, tests and probes. */
325
+ get brickCache() {
326
+ return this.#bricks;
327
+ }
328
+ // ---- VDBVolumeSourceInfo (aggregates over the live volumes; per volume, read the slot) ----
329
+ get channels() {
330
+ return { ...this.#channels };
331
+ }
332
+ get texels() {
333
+ const t = [1, 1, 1];
334
+ for (const s of this.volumes)
335
+ for (let a = 0; a < 3; a++)
336
+ t[a] = Math.max(t[a], s.texels[a]);
337
+ return t;
338
+ }
339
+ get lodLevels() {
340
+ return this.volumes.reduce((m, s) => Math.max(m, s.lodLevels), 0);
341
+ }
342
+ get stats() {
343
+ let sum = 0;
344
+ let count = 0;
345
+ let max = 0;
346
+ for (const s of this.volumes) {
347
+ sum += s.stats.meanNonZero * s.stats.activeVoxels;
348
+ count += s.stats.activeVoxels;
349
+ max = Math.max(max, s.stats.max);
350
+ }
351
+ return { meanNonZero: count > 0 ? sum / count : 0, max, activeVoxels: count };
352
+ }
353
+ /** Bumps when bind group 2 must be rebuilt: a new atlas texture, or the pool's buffer replaced (`pool.version`). */
354
+ get version() {
355
+ return this.#ownVersion + this.pool.version;
356
+ }
357
+ get volumes() {
358
+ return this.#slots.filter((s) => s !== null);
359
+ }
360
+ get atlas() {
361
+ return this.#atlas;
362
+ }
363
+ get gpuBytes() {
364
+ const a = this.#atlas;
365
+ let scratch = 0;
366
+ for (const e of this.#pyramids.values())
367
+ scratch += e.gpu?.gpuBytes.scratch ?? 0;
368
+ return { table: this.#table.size, atlas: a ? 2 * a.width * a.height * a.depthOrArrayLayers : 0, pyramidScratch: scratch };
369
+ }
370
+ // ---- volumes ----
371
+ #check() {
372
+ if (this.#disposed)
373
+ throw new VDBError("VDB_DISPOSED", "vdbSparseSource: the source was disposed; create a new one.");
374
+ }
375
+ #checkTypes(infos, what) {
376
+ const missing = infos.filter((i) => !this.#types.includes(i.type));
377
+ if (missing.length === 0)
378
+ return;
379
+ throw new VDBError("VDB_TYPE_NOT_COMPILED", `vdbSparseSource: ${what} is ${missing.map((m) => `grid ${m.id}: ${m.type}`).join(", ")}, but the source compiles only ${this.#types.join(", ")}; ` +
380
+ `it would read 0. Make the source with types that include every type the images will have (a coarse-first stream lists them in VDBCoarseFirstEvent.types).`);
381
+ }
382
+ volume(grids, o = {}) {
383
+ this.#check();
384
+ if (!grids || !Number.isInteger(grids.density))
385
+ throw bad("volume(): grids.density must be a pool grid id.");
386
+ if (Array.isArray(grids.albedo) && grids.albedo.length !== 3)
387
+ throw bad("volume(): albedo must be one id or three (RGB).");
388
+ if (this.followImage) {
389
+ const fixed = ["indexBox", "auxIndexBoxes", "bbox"].filter((k) => o[k] !== undefined);
390
+ if (fixed.length)
391
+ throw bad(`followImage re-reads every box from the pool; drop ${fixed.join(", ")} (fixed boxes).`);
392
+ }
393
+ const ids = [grids.density, grids.mask, grids.emission, ...(Array.isArray(grids.albedo) ? grids.albedo : [grids.albedo])].filter((x) => x !== undefined);
394
+ const infos = ids.map((id) => this.pool.info(id));
395
+ this.#checkTypes(infos, "a channel grid");
396
+ if (this.lod === "node-average" && !infos[0].hasStats)
397
+ throw bad("lod 'node-average' reads node statistics; this grid has none (rebuild it with stats).");
398
+ const channels = { mask: grids.mask !== undefined, albedo: grids.albedo !== undefined, emission: grids.emission !== undefined };
399
+ if (this.#fixedChannels) {
400
+ const off = Object.keys(channels).filter((k) => channels[k] && !this.#channels[k]);
401
+ if (off.length)
402
+ throw bad(`volume(): the source compiles channels ${JSON.stringify(this.#channels)}; this volume has ${off.join(", ")} (make the source with channels that include it).`);
403
+ }
404
+ let v = this.#slots.indexOf(null);
405
+ if (v < 0)
406
+ v = this.#slots.length;
407
+ if (v >= this.maxVolumes)
408
+ throw new VDBError("VDB_POOL_FULL", `vdbSparseSource: all ${this.maxVolumes} volume slots are used (maxVolumes).`);
409
+ const volume = new SparseVolume(this, v, grids, o);
410
+ this.#slots[v] = volume;
411
+ for (const k of Object.keys(channels))
412
+ if (channels[k])
413
+ this.#channels[k] = true;
414
+ this.#attachPyramid(volume);
415
+ this.#tableDirty = true;
416
+ this.#bricksLayout = true;
417
+ return volume;
418
+ }
419
+ removeVolume(volume) {
420
+ if (volume.removed || this.#slots[volume.v] !== volume)
421
+ return;
422
+ volume.removed = true;
423
+ this.#slots[volume.v] = null;
424
+ while (this.#slots.length && this.#slots[this.#slots.length - 1] === null)
425
+ this.#slots.pop();
426
+ this.#detachPyramid(volume);
427
+ const r = volume.readback;
428
+ // Not mapping yet: its copy may sit in an encoder that is not submitted (mapping ones free themselves).
429
+ if (r && !r.mapping)
430
+ this.#retire(() => r.buffer.destroy());
431
+ this.#tableDirty = true;
432
+ this.#bricksLayout = true;
433
+ }
434
+ #attachPyramid(volume) {
435
+ if (this.lod !== "coarse-pyramid") {
436
+ volume.lodLevels = this.lod === "node-average" ? 7 : 0;
437
+ return;
438
+ }
439
+ const box = volume.indexBox;
440
+ const key = `${volume.ids.density}:${box.min.join(",")}:${box.max.join(",")}`;
441
+ let entry = this.#pyramids.get(key);
442
+ if (!entry) {
443
+ entry = { key, gridId: volume.ids.density, box: copyBox(box), layout: vdbBoxPyramidLayout(sizeOf(box), { pyramidMax: this.#pyramidMax }), refs: 0, gpu: null, base: null, atlas: null, dirty: true };
444
+ this.#pyramids.set(key, entry);
445
+ this.#packDirty = true;
446
+ }
447
+ entry.refs++;
448
+ volume.entry = entry;
449
+ volume.lodLevels = entry.layout.lodLevels;
450
+ }
451
+ #detachPyramid(volume) {
452
+ const entry = volume.entry;
453
+ volume.entry = null;
454
+ if (!entry || --entry.refs > 0)
455
+ return;
456
+ this.#pyramids.delete(entry.key);
457
+ const gpu = entry.gpu;
458
+ if (gpu)
459
+ this.#retire(() => gpu.destroy());
460
+ this.#packDirty = true;
461
+ }
462
+ #retire(destroy) {
463
+ this.#retired.push({ at: this.#updates, destroy });
464
+ }
465
+ #newAtlas(size) {
466
+ return this.#device.createTexture({
467
+ label: `${this.#label} pyramid atlas`,
468
+ size,
469
+ dimension: "3d",
470
+ format: "r16float",
471
+ usage: TEXTURE.TEXTURE_BINDING | TEXTURE.COPY_DST | TEXTURE.COPY_SRC,
472
+ });
473
+ }
474
+ /** Packs every pyramid's blocks; grows the atlas when they no longer fit; moved or new blocks rebuild. */
475
+ #pack() {
476
+ this.#packDirty = false;
477
+ const entries = [...this.#pyramids.values()];
478
+ const blocks = [];
479
+ for (const e of entries) {
480
+ blocks.push(e.layout.dimensions);
481
+ if (e.layout.atlas)
482
+ blocks.push(e.layout.atlas.dimensions);
483
+ }
484
+ const max = this.#device.limits?.maxTextureDimension3D ?? 2048;
485
+ const packing = vdbPackPyramidBlocks(blocks, [max, max, max]);
486
+ const old = this.#atlas;
487
+ const grow = packing.size.some((s, a) => s > [old.width, old.height, old.depthOrArrayLayers][a]);
488
+ if (grow) {
489
+ const size = [Math.max(old.width, packing.size[0]), Math.max(old.height, packing.size[1]), Math.max(old.depthOrArrayLayers, packing.size[2])];
490
+ this.#atlas = this.#newAtlas(size);
491
+ this.#retire(() => old.destroy());
492
+ this.#ownVersion++;
493
+ }
494
+ let i = 0;
495
+ for (const e of entries) {
496
+ const base = packing.origins[i++];
497
+ const atlas = e.layout.atlas ? packing.origins[i++] : null;
498
+ const moved = !e.base || e.base.some((v, a) => v !== base[a]) || (atlas !== null && (!e.atlas || e.atlas.some((v, a) => v !== atlas[a])));
499
+ if (!moved && !grow && e.gpu)
500
+ continue;
501
+ e.base = [...base];
502
+ e.atlas = atlas ? [...atlas] : null;
503
+ const previous = e.gpu;
504
+ if (previous)
505
+ this.#retire(() => previous.destroy());
506
+ const target = this.#atlas;
507
+ e.gpu = vdbCreateBoxPyramid(this.#device, this.pool, e.gridId, {
508
+ indexBox: e.box,
509
+ level: e.layout.level,
510
+ targets: { base: target, atlas: e.layout.atlas ? target : null, baseOrigin: e.base, ...(e.atlas ? { atlasOrigin: e.atlas } : {}) },
511
+ label: `${this.#label} pyramid grid ${e.gridId}`,
512
+ });
513
+ e.dirty = true;
514
+ }
515
+ this.#tableDirty = true;
516
+ }
517
+ /** G16a: re-reads a following volume's layout once every channel grid's new image is resident. */
518
+ #syncLayout(volume) {
519
+ const pool = this.pool;
520
+ if (pool.revision === volume.layoutPoolRevision)
521
+ return false;
522
+ let revision = 0;
523
+ let resident = true;
524
+ const infos = [];
525
+ for (const id of volume.poolIds) {
526
+ let i;
527
+ try {
528
+ i = pool.info(id);
529
+ }
530
+ catch {
531
+ return false; // a removed grid: keep the last layout
532
+ }
533
+ revision = Math.max(revision, i.imageRevision);
534
+ if (!i.resident)
535
+ resident = false;
536
+ infos.push({ id, type: i.type });
537
+ }
538
+ if (revision === volume.layoutRevision) {
539
+ volume.layoutPoolRevision = pool.revision;
540
+ return false;
541
+ }
542
+ if (!resident)
543
+ return false; // look again once the update has written it
544
+ this.#checkTypes(infos, "a channel grid's new image");
545
+ const before = copyBox(volume.indexBox);
546
+ volume.relayout();
547
+ if (this.lod === "coarse-pyramid" && !sameBox(before, volume.indexBox)) {
548
+ this.#detachPyramid(volume);
549
+ this.#attachPyramid(volume);
550
+ }
551
+ volume.layoutRevision = revision;
552
+ volume.layoutPoolRevision = pool.revision;
553
+ this.#tableDirty = true;
554
+ this.#bricksLayout = true;
555
+ return true;
556
+ }
557
+ update(encoder) {
558
+ this.#check();
559
+ this.#updates++;
560
+ // Retire: destroyed two updates after they were replaced (an encoder recorded before may still name them), in a
561
+ // later task (K6.10a: updates recorded into one encoder before its submit in this task)
562
+ const keep = [];
563
+ for (const r of this.#retired) {
564
+ if (this.#updates - r.at > RETIRE_UPDATES)
565
+ this.#later.retireAfterTask(r);
566
+ else
567
+ keep.push(r);
568
+ }
569
+ this.#retired = keep;
570
+ let relayouts = 0;
571
+ if (this.followImage)
572
+ for (const s of this.volumes)
573
+ if (this.#syncLayout(s))
574
+ relayouts++;
575
+ if (this.#packDirty)
576
+ this.#pack();
577
+ let builds = 0;
578
+ for (const e of this.#pyramids.values()) {
579
+ const gpu = e.gpu;
580
+ if (!gpu)
581
+ continue;
582
+ let info;
583
+ try {
584
+ info = this.pool.info(e.gridId);
585
+ }
586
+ catch {
587
+ continue; // removed from the pool: keep the last pyramid
588
+ }
589
+ if (!info.resident)
590
+ continue; // the update that writes it is still to come
591
+ if (e.dirty) {
592
+ gpu.record(encoder);
593
+ e.dirty = false;
594
+ builds++;
595
+ }
596
+ else if (gpu.update(encoder)) {
597
+ builds++;
598
+ }
599
+ }
600
+ this.pyramidBuilds += builds;
601
+ this.#stats(encoder);
602
+ // K3.2f: the brick cache after the pool's update (its fills read the resident images) and before the frame's passes.
603
+ if (this.#bricks) {
604
+ if (this.#bricksLayout) {
605
+ this.#bricksLayout = false;
606
+ this.#bricks.layout(this.volumes);
607
+ }
608
+ this.#bricks.update(encoder);
609
+ }
610
+ if (this.#tableDirty) {
611
+ this.#tableDirty = false;
612
+ const bytes = new ArrayBuffer(Math.max(1, this.#slots.length) * VDB_SPARSE_RECORD_BYTES);
613
+ for (const s of this.volumes)
614
+ packSparseRecord(bytes, s.v * VDB_SPARSE_RECORD_BYTES, s.record());
615
+ this.#device.queue.writeBuffer(this.#table, 0, new Uint8Array(bytes));
616
+ }
617
+ const version = this.version;
618
+ const rebind = version !== this.#lastVersion;
619
+ this.#lastVersion = version;
620
+ return { pyramidBuilds: builds, relayouts, rebind };
621
+ }
622
+ /** K3.2e: a changed density image's stats, read back from the pool: copied in this encoder, mapped next update. */
623
+ #stats(encoder) {
624
+ const clamp01 = this.normalize === "clamp01";
625
+ for (const s of this.volumes) {
626
+ const r = s.readback;
627
+ if (r && !r.mapping && r.recordedAt < this.#updates) {
628
+ // The encoder that holds the copy was submitted (one update per submitted encoder).
629
+ const mapping = r.buffer
630
+ .mapAsync(0x1)
631
+ .then(() => {
632
+ if (s.removed)
633
+ return;
634
+ s.stats = vdbSparseDensityStats(new Uint32Array(r.buffer.getMappedRange().slice(0)), clamp01);
635
+ s.statsRevision = r.revision;
636
+ s.statsUpdates++;
637
+ this.#tableDirty = true;
638
+ })
639
+ .catch(() => { })
640
+ .finally(() => {
641
+ r.buffer.destroy();
642
+ if (s.readback === r)
643
+ s.readback = null;
644
+ this.#mappings.delete(mapping);
645
+ });
646
+ r.mapping = mapping;
647
+ this.#mappings.add(mapping);
648
+ continue;
649
+ }
650
+ if (r)
651
+ continue;
652
+ let info;
653
+ try {
654
+ info = this.pool.info(s.ids.density);
655
+ }
656
+ catch {
657
+ continue;
658
+ }
659
+ if (info.imageRevision === s.statsRevision || !info.resident || info.imageOffset === null)
660
+ continue;
661
+ const bytes = Math.ceil(info.imageBytes / 4) * 4;
662
+ const buffer = this.#device.createBuffer({ label: `${this.#label} stats readback`, size: bytes, usage: BUFFER.MAP_READ | BUFFER.COPY_DST });
663
+ encoder.copyBufferToBuffer(this.pool.buffer, info.imageOffset, buffer, 0, bytes);
664
+ s.readback = { buffer, revision: info.imageRevision, recordedAt: this.#updates, mapping: null };
665
+ }
666
+ }
667
+ async settled() {
668
+ while (this.#mappings.size)
669
+ await Promise.all([...this.#mappings]);
670
+ await this.#bricks?.settled();
671
+ }
672
+ // ---- group-2 contract ----
673
+ #config(o) {
674
+ const slot = checkSlot(o.slot, "wgsl");
675
+ if (o.profile !== "sample" && o.profile !== "march")
676
+ throw bad(`wgsl: profile must be 'sample' or 'march', got ${JSON.stringify(o.profile)}.`);
677
+ const on = (k) => this.#channels[k] && o.channels?.[k] !== false;
678
+ // K3.2f-e: the kernel's use of the brick cache (absent for the K3.2f defaults: the WGSL is the K3.2f text)
679
+ const kernel = o.brickKernel ?? "gather";
680
+ if (!VDB_BRICK_KERNELS.includes(kernel))
681
+ throw bad(`wgsl: brickKernel must be one of ${VDB_BRICK_KERNELS.join(", ")}, got ${JSON.stringify(kernel)}.`);
682
+ const brickUse = this.#wgslBase.brick && (this.#brickKernels !== "all" || this.#brickMarkStats) ? { brickUse: vdbBrickKernelUse(this.#brickKernels, kernel, this.#brickMarkStats) } : {};
683
+ return { ...this.#wgslBase, ...brickUse, slot, profile: o.profile, channels: { mask: on("mask"), albedo: on("albedo"), emission: on("emission") }, stochastic: o.stochastic === true };
684
+ }
685
+ wgsl(o) {
686
+ this.#check();
687
+ return sparseSourceWgsl(this.#config(o));
688
+ }
689
+ moduleWgsl(slot, helpers = []) {
690
+ this.#check();
691
+ return vdbModuleWgsl({ slot: checkSlot(slot, "moduleWgsl"), types: this.#types, profile: this.module.profile, helpers: new Set([...this.module.helpers, ...helpers]) });
692
+ }
693
+ layoutEntries(slot, visibility = STAGE_FRAGMENT_COMPUTE) {
694
+ this.#check();
695
+ const b = sparseBindings(checkSlot(slot, "layoutEntries"), this.lod, this.#wgslBase.brick);
696
+ const entries = [
697
+ ...vdbModuleEntries({ slot, visibility }),
698
+ { binding: b.table, visibility, buffer: { type: "uniform", minBindingSize: this.maxVolumes * VDB_SPARSE_RECORD_BYTES } },
699
+ ];
700
+ if (b.pyramid !== null) {
701
+ entries.push({ binding: b.pyramid, visibility, texture: { sampleType: "float", viewDimension: "3d" } });
702
+ entries.push({ binding: b.sampler, visibility, sampler: { type: "filtering" } });
703
+ }
704
+ if (b.brick)
705
+ entries.push(...this.#bricks.layoutEntries(b.brick, visibility));
706
+ return entries;
707
+ }
708
+ bindEntries(slot) {
709
+ this.#check();
710
+ const b = sparseBindings(checkSlot(slot, "bindEntries"), this.lod, this.#wgslBase.brick);
711
+ const entries = [this.pool.bindGroupEntry(slot), { binding: b.table, resource: { buffer: this.#table } }];
712
+ if (b.pyramid !== null) {
713
+ entries.push({ binding: b.pyramid, resource: this.#atlas.createView({ dimension: "3d" }) });
714
+ entries.push({ binding: b.sampler, resource: this.#sampler });
715
+ }
716
+ if (b.brick)
717
+ entries.push(...this.#bricks.bindEntries(b.brick));
718
+ return entries;
719
+ }
720
+ dispose() {
721
+ if (this.#disposed)
722
+ return;
723
+ this.#disposed = true;
724
+ for (const r of this.#retired)
725
+ r.destroy();
726
+ this.#retired = [];
727
+ this.#later.drain();
728
+ for (const e of this.#pyramids.values())
729
+ e.gpu?.destroy();
730
+ this.#pyramids.clear();
731
+ for (const s of this.volumes) {
732
+ s.removed = true;
733
+ if (s.readback && !s.readback.mapping)
734
+ s.readback.buffer.destroy();
735
+ }
736
+ this.#slots.length = 0;
737
+ this.#atlas?.destroy();
738
+ this.#atlas = null;
739
+ this.#bricks?.dispose();
740
+ this.#table.destroy();
741
+ }
742
+ }
743
+ /**
744
+ * A sparse volume source over the volumes of one `VDBGridPool` (see the file comment). The source owns its volume
745
+ * table, the packed pyramid atlas and the pyramids' scratch buffers; it never touches the pool's buffer or the
746
+ * device. `dispose()` frees what it allocated.
747
+ *
748
+ * @param pool The pool whose grids the volumes read (the source creates its objects on `pool.device`).
749
+ * @param options LOD, normalization, types, `followImage`, `skipEmpty`, sampling and size options.
750
+ */
751
+ export function vdbSparseSource(pool, options = {}) {
752
+ return new SparseSource(pool, options);
753
+ }
754
+ /** K3.2f (internal): the brick cache's counters of a source made with `brickCache` (null when off). */
755
+ export function vdbSparseBrickCacheInfo(source) {
756
+ return source.brickCache?.counters ?? null;
757
+ }
758
+ /** K3.2f (internal): the brick cache of a source (null when off), for tests and probes. */
759
+ export function vdbSparseBrickCache(source) {
760
+ return source.brickCache ?? null;
761
+ }
762
+ //# sourceMappingURL=sparse.js.map