@pmndrs/vdb 0.1.0 → 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 (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -0,0 +1,627 @@
1
+ /**
2
+ * K3.2f: the brick cache of the core sparse source (`vdbSparseSource`, internal option `brickCache`; design in
3
+ * docs/archive/handoffs/K3-2d.md, built and measured in K3-2f.md). CPU side and twins: `tools/frame/brick-cache.ts`.
4
+ *
5
+ * The level-0 density samples of a sparse source read the tree: 8 lower-node lookups and value decodes per sample
6
+ * (K3.2d). The cache decodes the 8³ blocks the frames touch into a dense atlas of 9³ bricks (the block plus a
7
+ * +x/+y/+z apron, so the 8 taps of every sample based in the block sit in one brick) and keeps a page table:
8
+ *
9
+ * - **Pages buffer** (storage, read): a header of 4 words per volume slot (first page, pages per axis; first page
10
+ * `0xffffffff` = no pages, the volume reads the tree), then one word per page: 0 = not resident, else brick slot + 1.
11
+ * - **Marks buffer** (storage, read_write): one bit per page, set by the sampler on every page it reads (resident or
12
+ * not). `update()` copies it into a readback buffer and clears it; once mapped, {@link VDBBrickResidency} gives the
13
+ * marked pages without a brick a slot (least recently marked out first) and the next `update()` records the fills.
14
+ * - **Atlas**: `'f32'`: r32float, filled through a storage texture, sampled with 8 `textureLoad`s and the vendored
15
+ * lerp order: bit-identical to the tree sampler. `'f16'`: r16float (core WebGPU has no r16float storage texture:
16
+ * f16 words in a staging buffer, then one `copyBufferToTexture` per brick), sampled with ONE hardware-filtered fetch;
17
+ * not identical (f16 values, quantized filter weights on some GPUs): the bound is `vdbBrickHalfBound`.
18
+ *
19
+ * A page that is not resident is a miss: the sampler reads the tree, so the f32 cache is exact from the first frame
20
+ * and only gets faster; a page marked in frame k is resident from about frame k + 2 (the marks' readback latency).
21
+ * An image change (`imageRevision`) drops the volume's bricks; a layout change (volumes added, removed or re-laid
22
+ * out) keeps the bricks of volumes whose page range is unchanged.
23
+ */
24
+ var _a;
25
+ import { VDBError } from "../errors.js";
26
+ import { vdbModuleEntries, vdbModuleWgsl } from "../wgsl/generate.js";
27
+ import { COMPUTE_SLOT } from "../compute/shared.js";
28
+ import { VDBBrickResidency, VDB_BRICK_KERNELS, VDB_BRICK_NO_PAGES, VDB_BRICK_SIDE, vdbBrickMarkSections, vdbBrickOrigin, vdbBrickPageLayout, vdbBrickPolicyPages, } from "../../tools/frame/brick-cache.js";
29
+ const BUFFER = { MAP_READ: 0x1, COPY_SRC: 0x4, COPY_DST: 0x8, STORAGE: 0x80 };
30
+ const TEXTURE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4, STORAGE_BINDING: 0x8 };
31
+ const STAGE_COMPUTE = 0x4;
32
+ /** Bricks per atlas row and column (the atlas grows along z, one layer of 16 × 16 bricks at a time). */
33
+ const ATLAS_BRICKS_XY = 16;
34
+ const LAYER = ATLAS_BRICKS_XY * ATLAS_BRICKS_XY;
35
+ /** f16 staging: one brick is 81 rows of 256 bytes (64 words): 9 texels of 2 bytes per row, padded. */
36
+ const STAGING_ROW_WORDS = 64;
37
+ const STAGING_BRICK_BYTES = VDB_BRICK_SIDE * VDB_BRICK_SIDE * STAGING_ROW_WORDS * 4;
38
+ const DEFAULT_ATLAS_BYTES = 64 * 1024 * 1024;
39
+ const DEFAULT_PAGES_MAX = 1 << 22;
40
+ const align = (n, a) => Math.ceil(n / a) * a;
41
+ const bad = (message) => new VDBError("VDB_BAD_OPTION", `vdbSparseSource: ${message}`);
42
+ /** Bytes of the zero-filled atlas (Dawn clears a new texture through one buffer, rows padded to 256 bytes; Traps). */
43
+ function atlasClearBytes(mode, layers) {
44
+ const row = align(ATLAS_BRICKS_XY * VDB_BRICK_SIDE * (mode === "f32" ? 4 : 2), 256);
45
+ return row * ATLAS_BRICKS_XY * VDB_BRICK_SIDE * layers * VDB_BRICK_SIDE;
46
+ }
47
+ /** The fill kernels: one workgroup per brick, the 9³ tree values through `vdbReadValue` (twin `vdbBrickFillCpu`). */
48
+ export function vdbBrickFillWgsl(mode, types) {
49
+ const out = mode === "f32"
50
+ ? `@group(1) @binding(1) var brickOut: texture_storage_3d<r32float, write>;`
51
+ : `@group(1) @binding(1) var<storage, read_write> brickOut: array<u32>;`;
52
+ const body = mode === "f32"
53
+ ? ` let n = textureDimensions(brickOut) / 9u;
54
+ let o = vec3u(slot % n.x, (slot / n.x) % n.y, slot / (n.x * n.y)) * 9u;
55
+ for (var i = lid.x; i < 729u; i += 64u) {
56
+ let l = vec3u(i % 9u, (i / 9u) % 9u, i / 81u);
57
+ textureStore(brickOut, o + l, vec4f(vdbReadValue(&acc, origin + vec3i(l)), 0.0, 0.0, 0.0));
58
+ }`
59
+ : ` // 81 rows of 5 words (texels 2w, 2w + 1; texel 9 is padding) at 64 words a row.
60
+ for (var i = lid.x; i < 405u; i += 64u) {
61
+ let w = i % 5u;
62
+ let row = i / 5u;
63
+ let ijk = origin + vec3i(vec3u(2u * w, row % 9u, row / 9u));
64
+ let lo = brickHalf(vdbReadValue(&acc, ijk));
65
+ var hi = 0u;
66
+ if w < 4u {
67
+ hi = brickHalf(vdbReadValue(&acc, ijk + vec3i(1, 0, 0)));
68
+ }
69
+ brickOut[wid.x * ${VDB_BRICK_SIDE * VDB_BRICK_SIDE * STAGING_ROW_WORDS}u + row * ${STAGING_ROW_WORDS}u + w] = lo | (hi << 16u);
70
+ }`;
71
+ const half = mode === "f16"
72
+ ? `
73
+ // f32 -> f16 bits, round to nearest even (tools vdbFloatToHalf, after NanoVDB HalfLite; as K7.3's msHalf).
74
+ fn brickHalf(v: f32) -> u32 {
75
+ let bits = bitcast<u32>(v);
76
+ let ui = bits & 0x7fffffffu;
77
+ var h = (bits >> 16u) & 0x8000u;
78
+ if ui >= 0x38800000u {
79
+ if ui >= 0x7f800000u {
80
+ h = h | 0x7c00u;
81
+ if ui == 0x7f800000u {
82
+ return h;
83
+ }
84
+ let m = (ui & 0x7fffffu) >> 13u;
85
+ return h | m | select(0u, 1u, m == 0u);
86
+ }
87
+ if ui > 0x477fefffu {
88
+ return h | 0x7c00u;
89
+ }
90
+ let r = ui - 0x38000000u;
91
+ return h | ((r + 0x00000fffu + ((r >> 13u) & 1u)) >> 13u);
92
+ }
93
+ if ui < 0x33000001u {
94
+ return h;
95
+ }
96
+ let shift = 0x7eu - (ui >> 23u);
97
+ let m = 0x800000u | (ui & 0x7fffffu);
98
+ let r = m << (32u - shift);
99
+ h = h | (m >> shift);
100
+ if r > 0x80000000u || (r == 0x80000000u && (h & 1u) != 0u) {
101
+ h = h + 1u;
102
+ }
103
+ return h;
104
+ }`
105
+ : "";
106
+ return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types, profile: "read" })}
107
+ // K3.2f brick fill (${mode}): job = (brick origin xyz, slot), then (grid id, 0, 0, 0).
108
+ @group(1) @binding(0) var<storage, read> brickJobs: array<vec4i>;
109
+ ${out}
110
+ ${half}
111
+ @compute @workgroup_size(64)
112
+ fn vdbBrickFillCs(@builtin(workgroup_id) wid: vec3u, @builtin(local_invocation_id) lid: vec3u) {
113
+ let a = brickJobs[2u * wid.x];
114
+ let origin = a.xyz;
115
+ let slot = u32(a.w);
116
+ var acc = vdbAccessorInit(u32(brickJobs[2u * wid.x + 1u].x));
117
+ ${body}
118
+ }
119
+ `;
120
+ }
121
+ const fillPipelines = new WeakMap();
122
+ function fillPipeline(device, mode, types) {
123
+ let byKey = fillPipelines.get(device);
124
+ if (!byKey)
125
+ fillPipelines.set(device, (byKey = new Map()));
126
+ const key = `${mode}:${types.join(",")}`;
127
+ const hit = byKey.get(key);
128
+ if (hit)
129
+ return hit;
130
+ const group0 = device.createBindGroupLayout({ label: `vdb brick fill ${mode} group 0`, entries: vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }) });
131
+ const group1 = device.createBindGroupLayout({
132
+ label: `vdb brick fill ${mode} group 1`,
133
+ entries: [
134
+ { binding: 0, visibility: STAGE_COMPUTE, buffer: { type: "read-only-storage" } },
135
+ mode === "f32"
136
+ ? { binding: 1, visibility: STAGE_COMPUTE, storageTexture: { access: "write-only", format: "r32float", viewDimension: "3d" } }
137
+ : { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: "storage" } },
138
+ ],
139
+ });
140
+ const module = device.createShaderModule({ label: `vdb brick fill ${mode}`, code: vdbBrickFillWgsl(mode, types) });
141
+ const pipeline = device.createComputePipeline({
142
+ label: `vdb brick fill ${mode}`,
143
+ layout: device.createPipelineLayout({ bindGroupLayouts: [group0, group1] }),
144
+ compute: { module, entryPoint: "vdbBrickFillCs" },
145
+ });
146
+ const p = { pipeline, group0, group1 };
147
+ byKey.set(key, p);
148
+ return p;
149
+ }
150
+ /** The cache of one sparse source (owned by it; see the file comment). */
151
+ export class VDBSparseBrickCache {
152
+ mode;
153
+ #device;
154
+ #pool;
155
+ #types;
156
+ #label;
157
+ #maxVolumes;
158
+ #budget;
159
+ #pagesMax;
160
+ #capacityMax;
161
+ #retire;
162
+ #rebind;
163
+ #residency;
164
+ /** K3.2f-e: the residency policy and the marks sections (1, or one per kernel with `markStats`). */
165
+ #kernels;
166
+ #sections;
167
+ #kernelMarks = null;
168
+ #regions = [];
169
+ #pages = 0;
170
+ /** CPU mirror of the pages buffer (header, then entries) and its dirty word range. */
171
+ #table;
172
+ #dirty = [0, 0];
173
+ #pagesBuffer;
174
+ #marks;
175
+ #atlas;
176
+ #layers = 1;
177
+ #sampler;
178
+ #staging = null;
179
+ #jobs = null;
180
+ #readback = null;
181
+ #spare = null;
182
+ #observation = null;
183
+ #epoch = 0;
184
+ #updates = 0;
185
+ /** The update at which the marks buffer was last cleared or made (its marks start after it). */
186
+ #marksFrom = 1;
187
+ #mappings = new Set();
188
+ #counters = { marked: 0, misses: 0, overflow: 0, fills: 0, fillsLast: 0, evictions: 0, observations: 0, dropped: 0 };
189
+ constructor(device, pool, o, hooks) {
190
+ if (o.mode !== "f32" && o.mode !== "f16")
191
+ throw bad(`brickCache must be 'off', 'f32' or 'f16', got ${JSON.stringify(o.mode)}.`);
192
+ this.mode = o.mode;
193
+ this.#device = device;
194
+ this.#pool = pool;
195
+ this.#types = o.types;
196
+ this.#label = `${o.label} bricks`;
197
+ this.#maxVolumes = o.maxVolumes;
198
+ this.#retire = hooks.retire;
199
+ this.#rebind = hooks.rebind;
200
+ const limits = (device.limits ?? {});
201
+ const maxLayers = Math.max(1, Math.floor((limits.maxTextureDimension3D ?? 2048) / VDB_BRICK_SIDE));
202
+ // Dawn's zero-fill of a new texture goes through one buffer of its padded size: stay under half maxBufferSize.
203
+ const clearCap = Math.max(1, Math.floor(Math.min(DEFAULT_ATLAS_BYTES, (limits.maxBufferSize ?? 268435456) / 2) / atlasClearBytes(o.mode, 1)));
204
+ const layersMax = Math.min(maxLayers, clearCap);
205
+ const capacity = o.capacity ?? layersMax * LAYER;
206
+ if (!Number.isInteger(capacity) || capacity < 1)
207
+ throw bad(`brickCapacity must be a positive integer, got ${o.capacity}.`);
208
+ this.#capacityMax = Math.min(capacity, maxLayers * LAYER);
209
+ this.#budget = o.budget ?? (o.mode === "f32" ? 1024 : 256);
210
+ if (!Number.isInteger(this.#budget) || this.#budget < 1 || this.#budget > 65535)
211
+ throw bad(`brickBudget must be an integer in [1, 65535], got ${o.budget}.`);
212
+ this.#kernels = o.kernels ?? "all";
213
+ if (this.#kernels !== "all" && this.#kernels !== "gather-marks" && this.#kernels !== "gather-only")
214
+ throw bad(`brickKernels must be 'all', 'gather-marks' or 'gather-only', got ${JSON.stringify(o.kernels)}.`);
215
+ this.#sections = o.markStats ? VDB_BRICK_KERNELS.length : 1;
216
+ if (o.markStats)
217
+ this.#kernelMarks = { union: 0, unionPeak: 0, byKernel: VDB_BRICK_KERNELS.map(() => ({ marked: 0, markedPeak: 0, misses: 0, only: 0, fillsLast: 0, fills: 0 })) };
218
+ this.#pagesMax = o.pagesMax ?? DEFAULT_PAGES_MAX;
219
+ if (!Number.isInteger(this.#pagesMax) || this.#pagesMax < 0)
220
+ throw bad(`brickPagesMax must be a non-negative integer, got ${o.pagesMax}.`);
221
+ this.#residency = new VDBBrickResidency(Math.min(LAYER, this.#capacityMax));
222
+ this.#table = new Uint32Array(4 * this.#maxVolumes).fill(VDB_BRICK_NO_PAGES);
223
+ this.#pagesBuffer = this.#newPages(this.#table.length);
224
+ this.#dirty = [0, this.#table.length];
225
+ this.#marks = this.#newMarks(0);
226
+ this.#atlas = this.#newAtlas(1);
227
+ this.#sampler =
228
+ o.mode === "f16"
229
+ ? device.createSampler({
230
+ label: `${this.#label} sampler`,
231
+ magFilter: "linear",
232
+ minFilter: "linear",
233
+ mipmapFilter: "nearest",
234
+ addressModeU: "clamp-to-edge",
235
+ addressModeV: "clamp-to-edge",
236
+ addressModeW: "clamp-to-edge",
237
+ })
238
+ : null;
239
+ }
240
+ #newPages(words) {
241
+ return this.#device.createBuffer({ label: `${this.#label} pages`, size: align(words * 4, 16), usage: BUFFER.STORAGE | BUFFER.COPY_DST });
242
+ }
243
+ /** Bytes of one marks section for `pages` (K3.2f-e: the buffer holds `#sections` of them; the WGSL splits it by `arrayLength`). */
244
+ static #sectionBytes(pages) {
245
+ return Math.max(16, align(Math.ceil(pages / 32) * 4, 16));
246
+ }
247
+ #newMarks(pages) {
248
+ return this.#device.createBuffer({ label: `${this.#label} marks`, size: this.#sections * _a.#sectionBytes(pages), usage: BUFFER.STORAGE | BUFFER.COPY_SRC | BUFFER.COPY_DST });
249
+ }
250
+ #newAtlas(layers) {
251
+ const n = ATLAS_BRICKS_XY * VDB_BRICK_SIDE;
252
+ return this.#device.createTexture({
253
+ label: `${this.#label} atlas`,
254
+ size: [n, n, layers * VDB_BRICK_SIDE],
255
+ dimension: "3d",
256
+ format: this.mode === "f32" ? "r32float" : "r16float",
257
+ usage: TEXTURE.TEXTURE_BINDING | TEXTURE.COPY_SRC | TEXTURE.COPY_DST | (this.mode === "f32" ? TEXTURE.STORAGE_BINDING : 0),
258
+ });
259
+ }
260
+ /** The atlas (for probes and readbacks). */
261
+ get atlas() {
262
+ return this.#atlas;
263
+ }
264
+ /** Pages buffer words before the first page entry (the per-volume header). */
265
+ get headerWords() {
266
+ return 4 * this.#maxVolumes;
267
+ }
268
+ /** The CPU mirror of the pages buffer (header, then entries), for tests. */
269
+ get table() {
270
+ return this.#table;
271
+ }
272
+ /** The page layout of a volume slot and its first page (-1: no pages), for tests and probes. */
273
+ region(v) {
274
+ const r = this.#regions.find((x) => x.volume.v === v);
275
+ return r ? { base: r.base, layout: r.layout, gridId: r.gridId } : null;
276
+ }
277
+ get counters() {
278
+ const t = this.#atlas;
279
+ const c = this.#counters;
280
+ const km = this.#kernelMarks;
281
+ const kernelMarks = km
282
+ ? { union: km.union, unionPeak: km.unionPeak, ...Object.fromEntries(VDB_BRICK_KERNELS.map((k, i) => [k, { ...km.byKernel[i] }])) }
283
+ : null;
284
+ return {
285
+ mode: this.mode,
286
+ capacity: this.#residency.capacity,
287
+ capacityMax: this.#capacityMax,
288
+ pages: this.#pages,
289
+ volumesWithoutPages: this.#regions.filter((r) => r.base < 0).length,
290
+ resident: this.#residency.resident,
291
+ marked: c.marked,
292
+ misses: c.misses,
293
+ overflow: c.overflow,
294
+ fills: c.fills,
295
+ fillsLast: c.fillsLast,
296
+ evictions: c.evictions,
297
+ observations: c.observations,
298
+ dropped: c.dropped,
299
+ bytes: {
300
+ atlas: t.width * t.height * t.depthOrArrayLayers * (this.mode === "f32" ? 4 : 2),
301
+ pages: this.#pagesBuffer.size,
302
+ marks: this.#marks.size,
303
+ staging: this.#staging?.size ?? 0,
304
+ readback: (this.#readback?.buffer.size ?? 0) + (this.#spare?.size ?? 0),
305
+ jobs: this.#jobs?.size ?? 0,
306
+ },
307
+ kernels: this.#kernels,
308
+ kernelMarks,
309
+ };
310
+ }
311
+ // ---- layout ----
312
+ /** Re-lays the page ranges out over `volumes` (slot order); keeps the bricks of unchanged ranges. */
313
+ layout(volumes) {
314
+ const old = this.#regions;
315
+ const next = [];
316
+ let pages = 0;
317
+ for (const volume of [...volumes].sort((a, b) => a.v - b.v)) {
318
+ const layout = vdbBrickPageLayout(volume.indexBox);
319
+ const fits = pages + layout.count <= this.#pagesMax;
320
+ const prev = old.find((r) => r.volume === volume);
321
+ const same = prev && prev.base >= 0 && fits && prev.gridId === volume.ids.density && prev.layout.blockMin.every((x, a) => x === layout.blockMin[a]) && prev.layout.dims.every((x, a) => x === layout.dims[a]);
322
+ next.push({ volume, gridId: volume.ids.density, layout, base: fits ? pages : -1, revision: same ? prev.revision : -1, ready: same ? prev.ready : false });
323
+ if (fits)
324
+ pages += layout.count;
325
+ }
326
+ // Pages of kept regions move to their new base; every other brick is freed.
327
+ const to = (page) => {
328
+ const r = old.find((x) => x.base >= 0 && page >= x.base && page < x.base + x.layout.count);
329
+ const n = r ? next.find((x) => x.volume === r.volume && x.revision >= 0 && x.base >= 0) : undefined;
330
+ return r && n ? page - r.base + n.base : -1;
331
+ };
332
+ this.#counters.dropped += this.#residency.drop((page) => to(page) >= 0).length;
333
+ this.#residency.remap(to);
334
+ this.#regions = next;
335
+ const sectionBytes = this.#marks.size / this.#sections;
336
+ const grewMarks = Math.ceil(pages / 32) * 4 > sectionBytes;
337
+ this.#pages = pages;
338
+ this.#epoch++;
339
+ this.#observation = null;
340
+ // The whole table again: the header, then each resident page's slot.
341
+ const table = new Uint32Array(this.headerWords + pages).fill(0);
342
+ table.fill(VDB_BRICK_NO_PAGES, 0, this.headerWords);
343
+ for (const r of next) {
344
+ if (r.base < 0)
345
+ continue;
346
+ table.set([r.base, ...r.layout.dims], 4 * r.volume.v);
347
+ }
348
+ for (const [page, slot] of this.#residency.entries())
349
+ table[this.headerWords + page] = slot + 1;
350
+ this.#table = table;
351
+ this.#dirty = [0, table.length];
352
+ if (table.length * 4 > this.#pagesBuffer.size) {
353
+ const old = this.#pagesBuffer;
354
+ this.#retire(() => old.destroy());
355
+ this.#pagesBuffer = this.#newPages(table.length + (table.length >> 1));
356
+ this.#rebind();
357
+ }
358
+ // New page numbers: the marks of the old layout mean nothing now, start from a clear buffer.
359
+ const oldMarks = this.#marks;
360
+ this.#retire(() => oldMarks.destroy());
361
+ this.#marks = this.#newMarks(grewMarks ? pages + (pages >> 1) : Math.max(pages, (sectionBytes / 4) * 32));
362
+ // layout() runs in the source's update just before this cache's: that update's frame is the first to mark it.
363
+ this.#marksFrom = this.#updates + 1;
364
+ this.#rebind();
365
+ }
366
+ // ---- per update ----
367
+ #setEntry(page, value) {
368
+ const w = this.headerWords + page;
369
+ this.#table[w] = value;
370
+ this.#dirty = this.#dirty[0] === this.#dirty[1] ? [w, w + 1] : [Math.min(this.#dirty[0], w), Math.max(this.#dirty[1], w + 1)];
371
+ }
372
+ /** Drops a region's bricks (its image changed). */
373
+ #dropRegion(r) {
374
+ if (r.base < 0)
375
+ return;
376
+ const dropped = this.#residency.drop((page) => page < r.base || page >= r.base + r.layout.count);
377
+ for (const page of dropped)
378
+ this.#setEntry(page, 0);
379
+ this.#counters.dropped += dropped.length;
380
+ }
381
+ /** Grows the atlas by layers (copying the old one) so `slots` fit, up to the capacity; returns the new capacity. */
382
+ #grow(encoder, slots) {
383
+ const want = Math.min(this.#capacityMax, slots);
384
+ if (want <= this.#residency.capacity)
385
+ return;
386
+ let layers = this.#layers;
387
+ while (layers * LAYER < want)
388
+ layers *= 2;
389
+ layers = Math.min(layers, Math.ceil(this.#capacityMax / LAYER));
390
+ const old = this.#atlas;
391
+ const next = this.#newAtlas(layers);
392
+ encoder.copyTextureToTexture({ texture: old }, { texture: next }, [old.width, old.height, old.depthOrArrayLayers]);
393
+ this.#retire(() => old.destroy());
394
+ this.#atlas = next;
395
+ this.#layers = layers;
396
+ this.#residency.grow(Math.min(this.#capacityMax, layers * LAYER));
397
+ this.#rebind();
398
+ }
399
+ /**
400
+ * One update (after the pool's, in the same encoder): drops the bricks of changed images, applies the last marks
401
+ * (allocations, evictions, fills recorded into `encoder`), writes the page table, and copies this window's marks out.
402
+ */
403
+ update(encoder) {
404
+ this.#updates++;
405
+ for (const r of this.#regions) {
406
+ let info;
407
+ try {
408
+ info = this.#pool.info(r.gridId);
409
+ }
410
+ catch {
411
+ r.ready = false;
412
+ continue;
413
+ }
414
+ if (info.imageRevision !== r.revision) {
415
+ if (r.revision >= 0)
416
+ this.#dropRegion(r);
417
+ r.ready = false;
418
+ if (info.resident) {
419
+ r.revision = info.imageRevision;
420
+ r.ready = true;
421
+ }
422
+ }
423
+ else if (!info.resident) {
424
+ r.ready = false;
425
+ }
426
+ else {
427
+ r.ready = true;
428
+ }
429
+ }
430
+ const obs = this.#observation;
431
+ if (obs && obs.epoch === this.#epoch) {
432
+ this.#observation = null;
433
+ this.#apply(encoder, obs.bits);
434
+ }
435
+ if (this.#dirty[1] > this.#dirty[0]) {
436
+ const [lo, hi] = this.#dirty;
437
+ this.#device.queue.writeBuffer(this.#pagesBuffer, lo * 4, new Uint8Array(this.#table.buffer, lo * 4, (hi - lo) * 4));
438
+ this.#dirty = [0, 0];
439
+ }
440
+ this.#marksOut(encoder);
441
+ }
442
+ #apply(encoder, bits) {
443
+ const ready = this.#regions.filter((r) => r.ready && r.base >= 0);
444
+ // Only pages of resident images take a brick (the others keep reading the tree).
445
+ const isReady = (page) => ready.some((r) => page >= r.base && page < r.base + r.layout.count);
446
+ // K3.2f-e: the marks of each section (one per kernel with markStats), then the pages the policy gives bricks to.
447
+ const sections = vdbBrickMarkSections(bits, this.#sections, this.#pages).map((list) => list.filter(isReady));
448
+ const marked = vdbBrickPolicyPages(this.#kernels, sections);
449
+ let missing = 0;
450
+ for (const page of marked)
451
+ if (this.#residency.slotOf(page) < 0)
452
+ missing++;
453
+ const kernelMisses = this.#kernelMarks ? sections.map((list) => list.reduce((n, page) => n + (this.#residency.slotOf(page) < 0 ? 1 : 0), 0)) : null;
454
+ if (this.#residency.resident + Math.min(missing, this.#budget) > this.#residency.capacity)
455
+ this.#grow(encoder, this.#residency.resident + Math.min(missing, this.#budget));
456
+ const o = this.#residency.observe(marked, this.#updates, this.#budget);
457
+ if (this.#kernelMarks && kernelMisses)
458
+ this.#countKernels(sections, kernelMisses, o.allocated);
459
+ const c = this.#counters;
460
+ c.observations++;
461
+ c.marked = marked.length;
462
+ c.misses = o.misses;
463
+ c.overflow = o.overflow;
464
+ c.evictions += o.evicted.length;
465
+ c.fillsLast = o.allocated.length;
466
+ for (const page of o.evicted)
467
+ this.#setEntry(page, 0);
468
+ if (o.allocated.length === 0)
469
+ return;
470
+ const jobs = new Int32Array(o.allocated.length * 8);
471
+ o.allocated.forEach(([page, slot], j) => {
472
+ const r = ready.find((x) => page >= x.base && page < x.base + x.layout.count);
473
+ const origin = vdbBrickOrigin(r.layout, page - r.base);
474
+ jobs.set([origin[0], origin[1], origin[2], slot, r.gridId, 0, 0, 0], j * 8);
475
+ this.#setEntry(page, slot + 1);
476
+ });
477
+ this.#fill(encoder, jobs, o.allocated.map(([, slot]) => slot));
478
+ c.fills += o.allocated.length;
479
+ }
480
+ /** K3.2f-e: the per-kernel counters of one observation (`markStats`). */
481
+ #countKernels(sections, misses, allocated) {
482
+ const km = this.#kernelMarks;
483
+ // A bit per kernel for each page any kernel marked.
484
+ const who = new Uint8Array(this.#pages);
485
+ sections.forEach((list, k) => {
486
+ for (const page of list)
487
+ who[page] |= 1 << k;
488
+ });
489
+ let union = 0;
490
+ for (let page = 0; page < who.length; page++)
491
+ if (who[page] !== 0)
492
+ union++;
493
+ km.union = union;
494
+ km.unionPeak = Math.max(km.unionPeak, union);
495
+ const filled = new Set(allocated.map(([page]) => page));
496
+ sections.forEach((list, k) => {
497
+ const c = km.byKernel[k];
498
+ c.marked = list.length;
499
+ c.markedPeak = Math.max(c.markedPeak, list.length);
500
+ c.misses = misses[k];
501
+ c.only = list.reduce((n, page) => n + (who[page] === 1 << k ? 1 : 0), 0);
502
+ c.fillsLast = list.reduce((n, page) => n + (filled.has(page) ? 1 : 0), 0);
503
+ c.fills += c.fillsLast;
504
+ });
505
+ }
506
+ #fill(encoder, jobs, slots) {
507
+ const device = this.#device;
508
+ const count = slots.length;
509
+ if (!this.#jobs || this.#jobs.size < jobs.byteLength) {
510
+ const old = this.#jobs;
511
+ if (old)
512
+ this.#retire(() => old.destroy());
513
+ this.#jobs = device.createBuffer({ label: `${this.#label} jobs`, size: align(Math.max(jobs.byteLength, this.#budget * 32), 16), usage: BUFFER.STORAGE | BUFFER.COPY_DST });
514
+ }
515
+ device.queue.writeBuffer(this.#jobs, 0, new Uint8Array(jobs.buffer));
516
+ if (this.mode === "f16" && (!this.#staging || this.#staging.size < count * STAGING_BRICK_BYTES)) {
517
+ const old = this.#staging;
518
+ if (old)
519
+ this.#retire(() => old.destroy());
520
+ this.#staging = device.createBuffer({ label: `${this.#label} staging`, size: Math.max(count, Math.min(this.#budget, 64)) * STAGING_BRICK_BYTES, usage: BUFFER.STORAGE | BUFFER.COPY_SRC });
521
+ }
522
+ const p = fillPipeline(device, this.mode, this.#types);
523
+ const group0 = device.createBindGroup({ label: `${this.#label} fill group 0`, layout: p.group0, entries: [this.#pool.bindGroupEntry(COMPUTE_SLOT)] });
524
+ const group1 = device.createBindGroup({
525
+ label: `${this.#label} fill group 1`,
526
+ layout: p.group1,
527
+ entries: [
528
+ { binding: 0, resource: { buffer: this.#jobs, size: align(jobs.byteLength, 16) } },
529
+ { binding: 1, resource: this.mode === "f32" ? this.#atlas.createView({ dimension: "3d" }) : { buffer: this.#staging } },
530
+ ],
531
+ });
532
+ const pass = encoder.beginComputePass({ label: `${this.#label} fill` });
533
+ pass.setPipeline(p.pipeline);
534
+ pass.setBindGroup(0, group0);
535
+ pass.setBindGroup(1, group1);
536
+ pass.dispatchWorkgroups(count);
537
+ pass.end();
538
+ if (this.mode === "f16") {
539
+ slots.forEach((slot, j) => {
540
+ const origin = [slot % ATLAS_BRICKS_XY, Math.floor(slot / ATLAS_BRICKS_XY) % ATLAS_BRICKS_XY, Math.floor(slot / LAYER)].map((c) => c * VDB_BRICK_SIDE);
541
+ encoder.copyBufferToTexture({ buffer: this.#staging, offset: j * STAGING_BRICK_BYTES, bytesPerRow: STAGING_ROW_WORDS * 4, rowsPerImage: VDB_BRICK_SIDE }, { texture: this.#atlas, origin: { x: origin[0], y: origin[1], z: origin[2] } }, [VDB_BRICK_SIDE, VDB_BRICK_SIDE, VDB_BRICK_SIDE]);
542
+ });
543
+ }
544
+ }
545
+ /** The marks readback: map one copied in an earlier (submitted) update, or copy this window's marks and clear them. */
546
+ #marksOut(encoder) {
547
+ const r = this.#readback;
548
+ if (r) {
549
+ if (!r.mapping && r.recordedAt < this.#updates) {
550
+ const mapping = r.buffer
551
+ .mapAsync(0x1)
552
+ .then(() => {
553
+ const bits = new Uint32Array(r.buffer.getMappedRange().slice(0));
554
+ r.buffer.unmap();
555
+ if (r.epoch === this.#epoch)
556
+ this.#observation = { bits, epoch: r.epoch };
557
+ })
558
+ .catch(() => { })
559
+ .finally(() => {
560
+ this.#mappings.delete(mapping);
561
+ if (this.#readback === r)
562
+ this.#readback = null;
563
+ if (r.buffer.size === this.#marks.size && !this.#spare)
564
+ this.#spare = r.buffer;
565
+ else
566
+ this.#retire(() => r.buffer.destroy());
567
+ });
568
+ r.mapping = mapping;
569
+ this.#mappings.add(mapping);
570
+ }
571
+ return;
572
+ }
573
+ // An observation not applied yet: its marks are still the newest; copy again after it is applied.
574
+ // Nor before a frame has sampled since the marks were cleared (the copy would be empty).
575
+ if (this.#observation || this.#pages === 0 || this.#updates <= this.#marksFrom)
576
+ return;
577
+ const size = this.#marks.size;
578
+ let buffer = this.#spare;
579
+ this.#spare = null;
580
+ if (!buffer || buffer.size !== size) {
581
+ if (buffer) {
582
+ const b = buffer;
583
+ this.#retire(() => b.destroy());
584
+ }
585
+ buffer = this.#device.createBuffer({ label: `${this.#label} marks readback`, size, usage: BUFFER.MAP_READ | BUFFER.COPY_DST });
586
+ }
587
+ encoder.copyBufferToBuffer(this.#marks, 0, buffer, 0, size);
588
+ encoder.clearBuffer(this.#marks, 0, size);
589
+ this.#marksFrom = this.#updates;
590
+ this.#readback = { buffer, epoch: this.#epoch, recordedAt: this.#updates, mapping: null };
591
+ }
592
+ /** Resolves when the marks readback in flight has landed. */
593
+ async settled() {
594
+ while (this.#mappings.size)
595
+ await Promise.all([...this.#mappings]);
596
+ }
597
+ // ---- group 2 ----
598
+ layoutEntries(b, visibility) {
599
+ const out = [
600
+ { binding: b.pages, visibility, buffer: { type: "read-only-storage" } },
601
+ { binding: b.marks, visibility, buffer: { type: "storage" } },
602
+ { binding: b.atlas, visibility, texture: { sampleType: this.mode === "f32" ? "unfilterable-float" : "float", viewDimension: "3d" } },
603
+ ];
604
+ if (b.sampler !== null)
605
+ out.push({ binding: b.sampler, visibility, sampler: { type: "filtering" } });
606
+ return out;
607
+ }
608
+ bindEntries(b) {
609
+ const out = [
610
+ { binding: b.pages, resource: { buffer: this.#pagesBuffer } },
611
+ { binding: b.marks, resource: { buffer: this.#marks } },
612
+ { binding: b.atlas, resource: this.#atlas.createView({ dimension: "3d" }) },
613
+ ];
614
+ if (b.sampler !== null)
615
+ out.push({ binding: b.sampler, resource: this.#sampler });
616
+ return out;
617
+ }
618
+ dispose() {
619
+ for (const b of [this.#pagesBuffer, this.#marks, this.#staging, this.#jobs, this.#spare])
620
+ b?.destroy();
621
+ if (this.#readback && !this.#readback.mapping)
622
+ this.#readback.buffer.destroy();
623
+ this.#atlas.destroy();
624
+ }
625
+ }
626
+ _a = VDBSparseBrickCache;
627
+ //# sourceMappingURL=brick-cache.js.map