@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,116 @@
1
+ import type { VDBGridInfo, VDBGridPool } from "../pool/pool.js";
2
+ import type { VDBGridTypeName, VDBSlot } from "../types.js";
3
+ /** Where the compute kernels bind the pool. */
4
+ export declare const COMPUTE_SLOT: VDBSlot;
5
+ /** Threads per workgroup per axis (4 x 4 x 4 = 64). */
6
+ export declare const WORKGROUP_AXIS = 4;
7
+ /** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */
8
+ export declare const USAGE: {
9
+ readonly MAP_READ: 1;
10
+ readonly COPY_SRC: 4;
11
+ readonly COPY_DST: 8;
12
+ readonly UNIFORM: 64;
13
+ readonly STORAGE: 128;
14
+ };
15
+ declare const MAP_MODE_READ = 1;
16
+ /** Bytes of `CsParams` below. */
17
+ export declare const PARAMS_BYTES = 80;
18
+ /**
19
+ * Uniform parameters shared by every kernel (`CsParams`, 80 B):
20
+ * `grid, bins, filter, _` u32 at 0..15; `regionMin` vec3i at 16; `regionSize`
21
+ * vec3u at 32; `dims` vec3u at 48; `range` vec2f at 64.
22
+ */
23
+ export interface KernelParams {
24
+ grid: number;
25
+ bins?: number;
26
+ filter?: number;
27
+ regionMin: readonly [number, number, number];
28
+ regionSize: readonly [number, number, number];
29
+ dims?: readonly [number, number, number];
30
+ range?: {
31
+ min: number;
32
+ max: number;
33
+ };
34
+ }
35
+ /** A kernel: its footer WGSL (after the module and `CsParams`) and its group-1 output bindings. */
36
+ export interface KernelSource {
37
+ readonly entryPoint: string;
38
+ readonly footer: string;
39
+ readonly outputs: number;
40
+ }
41
+ interface CachedPipeline {
42
+ pipeline: GPUComputePipeline;
43
+ group0: GPUBindGroupLayout;
44
+ group1: GPUBindGroupLayout;
45
+ /** Validation result of the module + pipeline creation (null = valid). */
46
+ error: Promise<GPUError | null>;
47
+ }
48
+ /** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */
49
+ export declare function kernelWgsl(kernel: KernelSource, type: VDBGridTypeName): string;
50
+ /** The compute pipeline of `kernel` for `type` on `device`, created once per device. */
51
+ export declare function kernelPipeline(device: GPUDevice, kernel: KernelSource, type: VDBGridTypeName): CachedPipeline;
52
+ /** Checks `device` / `pool` / `gridId` and returns the grid's info. */
53
+ export declare function checkTarget(where: string, device: GPUDevice, pool: VDBGridPool, gridId: number): VDBGridInfo;
54
+ /** Checks a positive integer option. */
55
+ export declare function checkPositiveInt(where: string, name: string, value: number): void;
56
+ /** Creates a buffer with initial contents (mapped at creation, no queue write). */
57
+ export declare function createInitialized(device: GPUDevice, label: string, usage: number, data: ArrayBufferView, size?: number): GPUBuffer;
58
+ export declare function align4(n: number): number;
59
+ /** The packed `CsParams` bytes. */
60
+ export declare function packParams(p: KernelParams): ArrayBuffer;
61
+ /** Workgroup counts covering `size` threads per axis. */
62
+ export declare function workgroups(size: readonly [number, number, number]): [number, number, number];
63
+ /**
64
+ * Pending GPU work with a CPU result. Created by `gridStats` / `decodeToAtlas`
65
+ * after their passes are recorded.
66
+ *
67
+ * Order of calls:
68
+ * - **No `encoder` option** (the tool created and submitted its own): call
69
+ * {@link read} at any time.
70
+ * - **Host `encoder`**: the work sits in the host's encoder until the host
71
+ * submits it. Submit, then call {@link submitted}, then {@link read}:
72
+ *
73
+ * const job = gridStats(device, pool, id, { encoder });
74
+ * device.queue.submit([encoder.finish()]);
75
+ * const stats = await job.submitted().read();
76
+ *
77
+ * `read()` before `submitted()` rejects with `VDB_BAD_OPTION` and touches
78
+ * nothing: mapping (or freeing) the tool's buffers before the submit would
79
+ * make that submit fail validation ("used in submit while destroyed" /
80
+ * "mapped").
81
+ *
82
+ * `read()` maps the readback, frees every buffer the tool allocated and
83
+ * resolves with the result; keep it outside timed regions. Call
84
+ * {@link dispose} instead to drop the work without reading it (after its
85
+ * submit, or with the encoder discarded).
86
+ */
87
+ export interface VDBReadback<T> {
88
+ /**
89
+ * Tells the job the host submitted the encoder it recorded into; returns
90
+ * the job (`job.submitted().read()`). A no-op for work the tool submitted
91
+ * itself.
92
+ */
93
+ submitted(): this;
94
+ /**
95
+ * Maps the result and frees the tool's buffers. With a host `encoder`,
96
+ * call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).
97
+ */
98
+ read(): Promise<T>;
99
+ /** Drops the work without reading it and frees the tool's buffers. */
100
+ dispose(): void;
101
+ }
102
+ /** Owns the buffers of one tool call; frees exactly those. */
103
+ export declare class ComputeJob<T> implements VDBReadback<T> {
104
+ #private;
105
+ constructor(where: string, owned: GPUBuffer[], staging: GPUBuffer | null, error: Promise<GPUError | null>, finish: (bytes: ArrayBuffer) => T, selfSubmitted?: boolean);
106
+ submitted(): this;
107
+ read(): Promise<T>;
108
+ dispose(): void;
109
+ }
110
+ /** Creates an encoder when the host gave none; `submit` submits it only then. */
111
+ export declare function hostEncoder(device: GPUDevice, given: GPUCommandEncoder | undefined, label: string): {
112
+ encoder: GPUCommandEncoder;
113
+ submit(): void;
114
+ readonly selfSubmitted: boolean;
115
+ };
116
+ export { MAP_MODE_READ };
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Shared plumbing of the core compute tools (K2.3): kernel assembly on a
3
+ * slot-mode VDB module, per-device pipeline caching, and the readback handle.
4
+ *
5
+ * Each kernel is one shader: `vdbModuleWgsl({ slot: COMPUTE_SLOT, types:
6
+ * [type], profile: 'sample' })` plus a host footer that calls only the public
7
+ * `vdb*` API. Group 0 holds the pool (binding 0, `vdbModuleEntries`) and the
8
+ * kernel's uniform parameters (binding 1); group 1 holds the kernel's
9
+ * outputs. Default module options, so the WGSL size snapshot is unchanged.
10
+ */
11
+ import { VDBError } from "../errors.js";
12
+ import { vdbModuleEntries, vdbModuleWgsl } from "../wgsl/generate.js";
13
+ /** Where the compute kernels bind the pool. */
14
+ export const COMPUTE_SLOT = { group: 0, firstBinding: 0 };
15
+ /** Threads per workgroup per axis (4 x 4 x 4 = 64). */
16
+ export const WORKGROUP_AXIS = 4;
17
+ /** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */
18
+ export const USAGE = { MAP_READ: 0x1, COPY_SRC: 0x4, COPY_DST: 0x8, UNIFORM: 0x40, STORAGE: 0x80 };
19
+ const STAGE_COMPUTE = 0x4;
20
+ const MAP_MODE_READ = 0x1;
21
+ /** Bytes of `CsParams` below. */
22
+ export const PARAMS_BYTES = 80;
23
+ const PARAMS_WGSL = /* wgsl */ `
24
+ struct CsParams {
25
+ grid: u32,
26
+ bins: u32,
27
+ filterMode: u32,
28
+ pad0: u32,
29
+ regionMin: vec3i,
30
+ pad1: u32,
31
+ regionSize: vec3u,
32
+ pad2: u32,
33
+ dims: vec3u,
34
+ pad3: u32,
35
+ range: vec2f,
36
+ pad4: vec2f,
37
+ };
38
+ @group(0) @binding(1) var<uniform> csParams: CsParams;
39
+ `;
40
+ const pipelines = new WeakMap();
41
+ /** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */
42
+ export function kernelWgsl(kernel, type) {
43
+ return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: "sample" })}\n${PARAMS_WGSL}\n${kernel.footer}`;
44
+ }
45
+ /** The compute pipeline of `kernel` for `type` on `device`, created once per device. */
46
+ export function kernelPipeline(device, kernel, type) {
47
+ let byKey = pipelines.get(device);
48
+ if (!byKey)
49
+ pipelines.set(device, (byKey = new Map()));
50
+ const key = `${kernel.entryPoint}:${type}`;
51
+ let cached = byKey.get(key);
52
+ if (cached)
53
+ return cached;
54
+ device.pushErrorScope("validation");
55
+ const group0 = device.createBindGroupLayout({
56
+ label: `vdb compute ${key} group 0`,
57
+ entries: [
58
+ ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),
59
+ { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: "uniform" } },
60
+ ],
61
+ });
62
+ const group1 = device.createBindGroupLayout({
63
+ label: `vdb compute ${key} group 1`,
64
+ entries: Array.from({ length: kernel.outputs }, (_, binding) => ({
65
+ binding,
66
+ visibility: STAGE_COMPUTE,
67
+ buffer: { type: "storage" },
68
+ })),
69
+ });
70
+ const module = device.createShaderModule({ label: `vdb compute ${key}`, code: kernelWgsl(kernel, type) });
71
+ const pipeline = device.createComputePipeline({
72
+ label: `vdb compute ${key}`,
73
+ layout: device.createPipelineLayout({ bindGroupLayouts: [group0, group1] }),
74
+ compute: { module, entryPoint: kernel.entryPoint },
75
+ });
76
+ cached = { pipeline, group0, group1, error: device.popErrorScope() };
77
+ byKey.set(key, cached);
78
+ return cached;
79
+ }
80
+ function badOption(message) {
81
+ throw new VDBError("VDB_BAD_OPTION", message);
82
+ }
83
+ /** Checks `device` / `pool` / `gridId` and returns the grid's info. */
84
+ export function checkTarget(where, device, pool, gridId) {
85
+ if (!device || typeof device.createBuffer !== "function") {
86
+ badOption(`${where}: expected a GPUDevice as the first argument (the device the pool lives on).`);
87
+ }
88
+ if (!pool || typeof pool.info !== "function") {
89
+ badOption(`${where}: expected a VDBGridPool as the second argument.`);
90
+ }
91
+ if (pool.device !== device) {
92
+ badOption(`${where}: the pool lives on a different GPUDevice. Pass pool.device (or create the pool on this device).`);
93
+ }
94
+ const info = pool.info(gridId);
95
+ if (!info.resident) {
96
+ badOption(`${where}: grid ${gridId} is not on the GPU yet. Call pool.update(encoder) (or pool.flush()) before recording compute work on it.`);
97
+ }
98
+ const { min, max } = info.indexBBox;
99
+ if (min.some((v, a) => v > max[a])) {
100
+ badOption(`${where}: grid ${gridId} has an empty index bbox (${JSON.stringify(info.indexBBox)}); there are no voxels to process.`);
101
+ }
102
+ return info;
103
+ }
104
+ /** Checks a positive integer option. */
105
+ export function checkPositiveInt(where, name, value) {
106
+ if (!Number.isInteger(value) || value < 1)
107
+ badOption(`${where}: ${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);
108
+ }
109
+ /** Creates a buffer with initial contents (mapped at creation, no queue write). */
110
+ export function createInitialized(device, label, usage, data, size = data.byteLength) {
111
+ const buffer = device.createBuffer({ label, size: align4(Math.max(4, size)), usage, mappedAtCreation: true });
112
+ new Uint8Array(buffer.getMappedRange()).set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
113
+ buffer.unmap();
114
+ return buffer;
115
+ }
116
+ export function align4(n) {
117
+ return Math.ceil(n / 4) * 4;
118
+ }
119
+ /** The packed `CsParams` bytes. */
120
+ export function packParams(p) {
121
+ const bytes = new ArrayBuffer(PARAMS_BYTES);
122
+ const u = new Uint32Array(bytes);
123
+ const i = new Int32Array(bytes);
124
+ const f = new Float32Array(bytes);
125
+ u[0] = p.grid;
126
+ u[1] = p.bins ?? 0;
127
+ u[2] = p.filter ?? 0;
128
+ for (let a = 0; a < 3; a++) {
129
+ i[4 + a] = p.regionMin[a];
130
+ u[8 + a] = p.regionSize[a];
131
+ u[12 + a] = p.dims?.[a] ?? 0;
132
+ }
133
+ f[16] = p.range?.min ?? 0;
134
+ f[17] = p.range?.max ?? 0;
135
+ return bytes;
136
+ }
137
+ /** Workgroup counts covering `size` threads per axis. */
138
+ export function workgroups(size) {
139
+ return [Math.ceil(size[0] / WORKGROUP_AXIS), Math.ceil(size[1] / WORKGROUP_AXIS), Math.ceil(size[2] / WORKGROUP_AXIS)];
140
+ }
141
+ /** Owns the buffers of one tool call; frees exactly those. */
142
+ export class ComputeJob {
143
+ #owned;
144
+ #staging;
145
+ #finish;
146
+ #error;
147
+ #where;
148
+ #result = null;
149
+ #disposed = false;
150
+ /** False until the host says it submitted its encoder; true when the tool submitted its own. */
151
+ #submitted;
152
+ constructor(where, owned, staging, error, finish, selfSubmitted = true) {
153
+ this.#where = where;
154
+ this.#owned = owned;
155
+ this.#staging = staging;
156
+ this.#error = error;
157
+ this.#finish = finish;
158
+ this.#submitted = selfSubmitted;
159
+ }
160
+ submitted() {
161
+ this.#submitted = true;
162
+ return this;
163
+ }
164
+ read() {
165
+ if (this.#result)
166
+ return this.#result;
167
+ if (this.#disposed)
168
+ return Promise.reject(new VDBError("VDB_DISPOSED", `${this.#where}: this result was disposed before read().`));
169
+ if (!this.#submitted) {
170
+ return Promise.reject(new VDBError("VDB_BAD_OPTION", `${this.#where}: read() before the host submitted its encoder. The work was recorded into your encoder: ` +
171
+ "device.queue.submit([encoder.finish()]), then job.submitted().read(). (Nothing was mapped or freed.)"));
172
+ }
173
+ this.#result = this.#read();
174
+ return this.#result;
175
+ }
176
+ async #read() {
177
+ const staging = this.#staging;
178
+ // Keeps the GPU output alive: the host frees it with dispose().
179
+ if (!staging)
180
+ throw new VDBError("VDB_BAD_OPTION", `${this.#where}: created with readback: false; nothing to read. Use the buffer, then dispose().`);
181
+ try {
182
+ const error = await this.#error;
183
+ if (error)
184
+ throw new VDBError("VDB_UNSUPPORTED_DEVICE", `${this.#where}: the compute pipeline failed validation: ${error.message}`);
185
+ await staging.mapAsync(MAP_MODE_READ);
186
+ const bytes = staging.getMappedRange().slice(0);
187
+ staging.unmap();
188
+ return this.#finish(bytes);
189
+ }
190
+ finally {
191
+ this.dispose();
192
+ }
193
+ }
194
+ dispose() {
195
+ if (this.#disposed)
196
+ return;
197
+ this.#disposed = true;
198
+ for (const b of this.#owned)
199
+ b.destroy();
200
+ this.#staging?.destroy();
201
+ }
202
+ }
203
+ /** Creates an encoder when the host gave none; `submit` submits it only then. */
204
+ export function hostEncoder(device, given, label) {
205
+ if (given)
206
+ return { encoder: given, submit() { }, selfSubmitted: false };
207
+ const encoder = device.createCommandEncoder({ label });
208
+ return { encoder, submit: () => device.queue.submit([encoder.finish()]), selfSubmitted: true };
209
+ }
210
+ export { MAP_MODE_READ };
211
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/core/compute/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAY,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AAEnE,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,2FAA2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,EAAE,IAAI,EAAE,CAAC;AACjG,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["/**\n * Shared plumbing of the core compute tools (K2.3): kernel assembly on a\n * slot-mode VDB module, per-device pipeline caching, and the readback handle.\n *\n * Each kernel is one shader: `vdbModuleWgsl({ slot: COMPUTE_SLOT, types:\n * [type], profile: 'sample' })` plus a host footer that calls only the public\n * `vdb*` API. Group 0 holds the pool (binding 0, `vdbModuleEntries`) and the\n * kernel's uniform parameters (binding 1); group 1 holds the kernel's\n * outputs. Default module options, so the WGSL size snapshot is unchanged.\n */\nimport { VDBError } from \"../errors.js\";\nimport type { VDBGridInfo, VDBGridPool } from \"../pool/pool.js\";\nimport type { VDBGridTypeName, VDBSlot } from \"../types.js\";\nimport { vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\n\n/** Where the compute kernels bind the pool. */\nexport const COMPUTE_SLOT: VDBSlot = { group: 0, firstBinding: 0 };\n\n/** Threads per workgroup per axis (4 x 4 x 4 = 64). */\nexport const WORKGROUP_AXIS = 4;\n\n/** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */\nexport const USAGE = { MAP_READ: 0x1, COPY_SRC: 0x4, COPY_DST: 0x8, UNIFORM: 0x40, STORAGE: 0x80 } as const;\nconst STAGE_COMPUTE = 0x4;\nconst MAP_MODE_READ = 0x1;\n\n/** Bytes of `CsParams` below. */\nexport const PARAMS_BYTES = 80;\n\n/**\n * Uniform parameters shared by every kernel (`CsParams`, 80 B):\n * `grid, bins, filter, _` u32 at 0..15; `regionMin` vec3i at 16; `regionSize`\n * vec3u at 32; `dims` vec3u at 48; `range` vec2f at 64.\n */\nexport interface KernelParams {\n grid: number;\n bins?: number;\n filter?: number;\n regionMin: readonly [number, number, number];\n regionSize: readonly [number, number, number];\n dims?: readonly [number, number, number];\n range?: { min: number; max: number };\n}\n\nconst PARAMS_WGSL = /* wgsl */ `\nstruct CsParams {\n grid: u32,\n bins: u32,\n filterMode: u32,\n pad0: u32,\n regionMin: vec3i,\n pad1: u32,\n regionSize: vec3u,\n pad2: u32,\n dims: vec3u,\n pad3: u32,\n range: vec2f,\n pad4: vec2f,\n};\n@group(0) @binding(1) var<uniform> csParams: CsParams;\n`;\n\n/** A kernel: its footer WGSL (after the module and `CsParams`) and its group-1 output bindings. */\nexport interface KernelSource {\n readonly entryPoint: string;\n readonly footer: string;\n readonly outputs: number;\n}\n\ninterface CachedPipeline {\n pipeline: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n group1: GPUBindGroupLayout;\n /** Validation result of the module + pipeline creation (null = valid). */\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<string, CachedPipeline>>();\n\n/** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */\nexport function kernelWgsl(kernel: KernelSource, type: VDBGridTypeName): string {\n return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: \"sample\" })}\\n${PARAMS_WGSL}\\n${kernel.footer}`;\n}\n\n/** The compute pipeline of `kernel` for `type` on `device`, created once per device. */\nexport function kernelPipeline(device: GPUDevice, kernel: KernelSource, type: VDBGridTypeName): CachedPipeline {\n let byKey = pipelines.get(device);\n if (!byKey) pipelines.set(device, (byKey = new Map()));\n const key = `${kernel.entryPoint}:${type}`;\n let cached = byKey.get(key);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 0`,\n entries: [\n ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),\n { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\" } },\n ],\n });\n const group1 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 1`,\n entries: Array.from({ length: kernel.outputs }, (_, binding) => ({\n binding,\n visibility: STAGE_COMPUTE,\n buffer: { type: \"storage\" as const },\n })),\n });\n const module = device.createShaderModule({ label: `vdb compute ${key}`, code: kernelWgsl(kernel, type) });\n const pipeline = device.createComputePipeline({\n label: `vdb compute ${key}`,\n layout: device.createPipelineLayout({ bindGroupLayouts: [group0, group1] }),\n compute: { module, entryPoint: kernel.entryPoint },\n });\n cached = { pipeline, group0, group1, error: device.popErrorScope() };\n byKey.set(key, cached);\n return cached;\n}\n\nfunction badOption(message: string): never {\n throw new VDBError(\"VDB_BAD_OPTION\", message);\n}\n\n/** Checks `device` / `pool` / `gridId` and returns the grid's info. */\nexport function checkTarget(where: string, device: GPUDevice, pool: VDBGridPool, gridId: number): VDBGridInfo {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") {\n badOption(`${where}: expected a GPUDevice as the first argument (the device the pool lives on).`);\n }\n if (!pool || typeof (pool as { info?: unknown }).info !== \"function\") {\n badOption(`${where}: expected a VDBGridPool as the second argument.`);\n }\n if (pool.device !== device) {\n badOption(`${where}: the pool lives on a different GPUDevice. Pass pool.device (or create the pool on this device).`);\n }\n const info = pool.info(gridId);\n if (!info.resident) {\n badOption(\n `${where}: grid ${gridId} is not on the GPU yet. Call pool.update(encoder) (or pool.flush()) before recording compute work on it.`,\n );\n }\n const { min, max } = info.indexBBox;\n if (min.some((v, a) => v > max[a]!)) {\n badOption(`${where}: grid ${gridId} has an empty index bbox (${JSON.stringify(info.indexBBox)}); there are no voxels to process.`);\n }\n return info;\n}\n\n/** Checks a positive integer option. */\nexport function checkPositiveInt(where: string, name: string, value: number): void {\n if (!Number.isInteger(value) || value < 1) badOption(`${where}: ${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n}\n\n/** Creates a buffer with initial contents (mapped at creation, no queue write). */\nexport function createInitialized(device: GPUDevice, label: string, usage: number, data: ArrayBufferView, size = data.byteLength): GPUBuffer {\n const buffer = device.createBuffer({ label, size: align4(Math.max(4, size)), usage, mappedAtCreation: true });\n new Uint8Array(buffer.getMappedRange()).set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\n buffer.unmap();\n return buffer;\n}\n\nexport function align4(n: number): number {\n return Math.ceil(n / 4) * 4;\n}\n\n/** The packed `CsParams` bytes. */\nexport function packParams(p: KernelParams): ArrayBuffer {\n const bytes = new ArrayBuffer(PARAMS_BYTES);\n const u = new Uint32Array(bytes);\n const i = new Int32Array(bytes);\n const f = new Float32Array(bytes);\n u[0] = p.grid;\n u[1] = p.bins ?? 0;\n u[2] = p.filter ?? 0;\n for (let a = 0; a < 3; a++) {\n i[4 + a] = p.regionMin[a]!;\n u[8 + a] = p.regionSize[a]!;\n u[12 + a] = p.dims?.[a] ?? 0;\n }\n f[16] = p.range?.min ?? 0;\n f[17] = p.range?.max ?? 0;\n return bytes;\n}\n\n/** Workgroup counts covering `size` threads per axis. */\nexport function workgroups(size: readonly [number, number, number]): [number, number, number] {\n return [Math.ceil(size[0] / WORKGROUP_AXIS), Math.ceil(size[1] / WORKGROUP_AXIS), Math.ceil(size[2] / WORKGROUP_AXIS)];\n}\n\n/**\n * Pending GPU work with a CPU result. Created by `gridStats` / `decodeToAtlas`\n * after their passes are recorded.\n *\n * Order of calls:\n * - **No `encoder` option** (the tool created and submitted its own): call\n * {@link read} at any time.\n * - **Host `encoder`**: the work sits in the host's encoder until the host\n * submits it. Submit, then call {@link submitted}, then {@link read}:\n *\n * const job = gridStats(device, pool, id, { encoder });\n * device.queue.submit([encoder.finish()]);\n * const stats = await job.submitted().read();\n *\n * `read()` before `submitted()` rejects with `VDB_BAD_OPTION` and touches\n * nothing: mapping (or freeing) the tool's buffers before the submit would\n * make that submit fail validation (\"used in submit while destroyed\" /\n * \"mapped\").\n *\n * `read()` maps the readback, frees every buffer the tool allocated and\n * resolves with the result; keep it outside timed regions. Call\n * {@link dispose} instead to drop the work without reading it (after its\n * submit, or with the encoder discarded).\n */\nexport interface VDBReadback<T> {\n /**\n * Tells the job the host submitted the encoder it recorded into; returns\n * the job (`job.submitted().read()`). A no-op for work the tool submitted\n * itself.\n */\n submitted(): this;\n /**\n * Maps the result and frees the tool's buffers. With a host `encoder`,\n * call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).\n */\n read(): Promise<T>;\n /** Drops the work without reading it and frees the tool's buffers. */\n dispose(): void;\n}\n\n/** Owns the buffers of one tool call; frees exactly those. */\nexport class ComputeJob<T> implements VDBReadback<T> {\n readonly #owned: GPUBuffer[];\n readonly #staging: GPUBuffer | null;\n readonly #finish: (bytes: ArrayBuffer) => T;\n readonly #error: Promise<GPUError | null>;\n readonly #where: string;\n #result: Promise<T> | null = null;\n #disposed = false;\n /** False until the host says it submitted its encoder; true when the tool submitted its own. */\n #submitted: boolean;\n\n constructor(\n where: string,\n owned: GPUBuffer[],\n staging: GPUBuffer | null,\n error: Promise<GPUError | null>,\n finish: (bytes: ArrayBuffer) => T,\n selfSubmitted = true,\n ) {\n this.#where = where;\n this.#owned = owned;\n this.#staging = staging;\n this.#error = error;\n this.#finish = finish;\n this.#submitted = selfSubmitted;\n }\n\n submitted(): this {\n this.#submitted = true;\n return this;\n }\n\n read(): Promise<T> {\n if (this.#result) return this.#result;\n if (this.#disposed) return Promise.reject(new VDBError(\"VDB_DISPOSED\", `${this.#where}: this result was disposed before read().`));\n if (!this.#submitted) {\n return Promise.reject(\n new VDBError(\n \"VDB_BAD_OPTION\",\n `${this.#where}: read() before the host submitted its encoder. The work was recorded into your encoder: ` +\n \"device.queue.submit([encoder.finish()]), then job.submitted().read(). (Nothing was mapped or freed.)\",\n ),\n );\n }\n this.#result = this.#read();\n return this.#result;\n }\n\n async #read(): Promise<T> {\n const staging = this.#staging;\n // Keeps the GPU output alive: the host frees it with dispose().\n if (!staging) throw new VDBError(\"VDB_BAD_OPTION\", `${this.#where}: created with readback: false; nothing to read. Use the buffer, then dispose().`);\n try {\n const error = await this.#error;\n if (error) throw new VDBError(\"VDB_UNSUPPORTED_DEVICE\", `${this.#where}: the compute pipeline failed validation: ${error.message}`);\n await staging.mapAsync(MAP_MODE_READ);\n const bytes = staging.getMappedRange().slice(0);\n staging.unmap();\n return this.#finish(bytes);\n } finally {\n this.dispose();\n }\n }\n\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n for (const b of this.#owned) b.destroy();\n this.#staging?.destroy();\n }\n}\n\n/** Creates an encoder when the host gave none; `submit` submits it only then. */\nexport function hostEncoder(\n device: GPUDevice,\n given: GPUCommandEncoder | undefined,\n label: string,\n): { encoder: GPUCommandEncoder; submit(): void; readonly selfSubmitted: boolean } {\n if (given) return { encoder: given, submit() {}, selfSubmitted: false };\n const encoder = device.createCommandEncoder({ label });\n return { encoder, submit: () => device.queue.submit([encoder.finish()]), selfSubmitted: true };\n}\n\nexport { MAP_MODE_READ };\n"]}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * `gridStats`: min, max, mean, active-voxel count and a histogram of one pool
3
+ * grid, as compute passes recorded into the host's encoder (K2.3, ported from
4
+ * v1 `three/compute.ts`). CPU twin: `vdbGridStatsCpu` in `@pmndrs/vdb/tools`.
5
+ *
6
+ * One thread per voxel of the grid's dense index bbox reads `vdbIsActive` and
7
+ * `vdbReadValue`; inactive voxels are skipped. The histogram spans the root
8
+ * statistics `[rootMin, rootMax]` from `pool.info(id)` (v1 read the same f32s
9
+ * on the GPU in a separate pass first).
10
+ *
11
+ * Two paths, as in v1:
12
+ * - root min ≥ 0 (fog volumes): one pass of atomics. `atomicMin/Max` on the
13
+ * value's bit pattern as i32 (order-preserving for non-negative floats),
14
+ * a count, a 64-bit fixed-point sum of `u32(norm * 2^20)` (no f32 atomics
15
+ * in WGSL) and histogram bins. Readback: 3 + bins words + 2.
16
+ * - root min < 0: every voxel's (value, active) is written out and reduced on
17
+ * the CPU after readback (8 B per bbox voxel).
18
+ *
19
+ * Limitations kept from v1: dense bbox dispatch (a sparse grid with a large
20
+ * bbox wastes threads); the range comes from the image's stats, so a grid
21
+ * without stats (or with stale stats after a value transform) bins against
22
+ * whatever they hold; and a negative value in a grid whose root min is ≥ 0
23
+ * (stale stats) breaks the atomics path's min/max.
24
+ */
25
+ import type { VDBGridPool } from "../pool/pool.js";
26
+ import { type VDBReadback } from "./shared.js";
27
+ /** Options of {@link vdbGridStats}. */
28
+ export interface VDBGridStatsOptions {
29
+ /** Histogram bins over `[rootMin, rootMax]`. Default 256. */
30
+ histogramBins?: number;
31
+ /**
32
+ * Record into this encoder. The host submits it, then calls
33
+ * `job.submitted().read()`; `read()` before `submitted()` rejects
34
+ * (`VDB_BAD_OPTION`). Omitted: the tool creates and submits its own encoder.
35
+ */
36
+ encoder?: GPUCommandEncoder;
37
+ }
38
+ /** What {@link vdbGridStats} reads back (v1's `GridStatsResult` plus the range). */
39
+ export interface VDBGridStats {
40
+ /** Exact extremes over the active voxels (0 when there are none). */
41
+ min: number;
42
+ /** Exact maximum over the active voxels. */
43
+ max: number;
44
+ /** Mean over the active voxels: fixed-point (2^-20 of the range) on the atomics path, f64 on the dump path. */
45
+ mean: number;
46
+ /** `histogramBins` counts over `range`, clamped to the end bins. */
47
+ histogram: Uint32Array;
48
+ /** Number of active voxels counted. */
49
+ activeVoxelCount: number;
50
+ /** True when the atomics path ran (root min ≥ 0). */
51
+ usedAtomicFastPath: boolean;
52
+ /** The histogram range: the grid's root min/max statistics. */
53
+ range: {
54
+ min: number;
55
+ max: number;
56
+ };
57
+ }
58
+ /**
59
+ * Records the statistics passes for grid `gridId` of `pool` and returns a
60
+ * {@link VDBReadback}: `await gridStats(device, pool, id).read()`, or with a
61
+ * host encoder `submit`, then `await job.submitted().read()`.
62
+ *
63
+ * The grid must be resident (`pool.update(encoder)` / `pool.flush()` ran
64
+ * after its `add`), and the pool must live on `device`. The tool allocates
65
+ * its own parameter, output and readback buffers and frees them in `read()`
66
+ * or `dispose()`; it never touches the pool's buffer beyond binding it.
67
+ *
68
+ * @param device The host's `GPUDevice`; the pool must live on it.
69
+ * @param pool The pool that holds the grid.
70
+ * @param gridId The grid's pool id; it must be resident.
71
+ * @param options Histogram bins and an optional host encoder ({@link VDBGridStatsOptions}).
72
+ *
73
+ * @throws VDBError `VDB_BAD_OPTION` for bad options, a pool on another
74
+ * device, a non-resident grid, or (root min < 0, the dump path) a bbox whose
75
+ * per-voxel outputs (`voxels * 4` bytes each, `voxels * 8` to read back)
76
+ * exceed `device.limits.maxStorageBufferBindingSize` / `maxBufferSize`.
77
+ */
78
+ export declare function vdbGridStats(device: GPUDevice, pool: VDBGridPool, gridId: number, options?: VDBGridStatsOptions): VDBReadback<VDBGridStats>;
@@ -0,0 +1,193 @@
1
+ import { VDBError } from "../errors.js";
2
+ import { checkPositiveInt, checkTarget, ComputeJob, createInitialized, hostEncoder, kernelPipeline, packParams, USAGE, workgroups, WORKGROUP_AXIS, } from "./shared.js";
3
+ import { bboxSize, GRID_STATS_SUM_SCALE } from "../../tools/cpu/compute.js";
4
+ const W = WORKGROUP_AXIS;
5
+ const STATS_FAST = {
6
+ entryPoint: "csStatsFast",
7
+ outputs: 2,
8
+ footer: /* wgsl */ `
9
+ @group(1) @binding(0) var<storage, read_write> csStatsI32: array<atomic<i32>>; // [0] min bits, [1] max bits
10
+ @group(1) @binding(1) var<storage, read_write> csStatsU32: array<atomic<u32>>; // [0] count, [1] sum lo, [2] sum hi, [3..] bins
11
+
12
+ const CS_SUM_SCALE: f32 = ${GRID_STATS_SUM_SCALE}.0;
13
+
14
+ @compute @workgroup_size(${W}, ${W}, ${W})
15
+ fn csStatsFast(@builtin(global_invocation_id) gid: vec3u) {
16
+ if any(gid >= csParams.regionSize) {
17
+ return;
18
+ }
19
+ let ijk = csParams.regionMin + vec3i(gid);
20
+ var acc = vdbAccessorInit(csParams.grid);
21
+ if !vdbIsActive(&acc, ijk) {
22
+ return;
23
+ }
24
+ let value = vdbReadValue(&acc, ijk);
25
+ // Non-negative floats keep their order as i32 bit patterns (root min >= 0 was checked on the CPU).
26
+ let bits = bitcast<i32>(value);
27
+ atomicMin(&csStatsI32[0], bits);
28
+ atomicMax(&csStatsI32[1], bits);
29
+ atomicAdd(&csStatsU32[0], 1u);
30
+ let span = max(csParams.range.y - csParams.range.x, 1.0e-20);
31
+ let norm = clamp((value - csParams.range.x) / span, 0.0, 1.0);
32
+ // 64-bit sum: atomicAdd returns the old low word; carry when it wraps.
33
+ let scaled = u32(norm * CS_SUM_SCALE);
34
+ let oldLo = atomicAdd(&csStatsU32[1], scaled);
35
+ if oldLo > (0xFFFFFFFFu - scaled) {
36
+ atomicAdd(&csStatsU32[2], 1u);
37
+ }
38
+ let bins = csParams.bins;
39
+ let bin = min(u32(norm * f32(bins)), bins - 1u);
40
+ atomicAdd(&csStatsU32[3u + bin], 1u);
41
+ }
42
+ `,
43
+ };
44
+ const STATS_DUMP = {
45
+ entryPoint: "csStatsDump",
46
+ outputs: 2,
47
+ footer: /* wgsl */ `
48
+ @group(1) @binding(0) var<storage, read_write> csDumpValue: array<f32>;
49
+ @group(1) @binding(1) var<storage, read_write> csDumpIsOn: array<u32>;
50
+
51
+ @compute @workgroup_size(${W}, ${W}, ${W})
52
+ fn csStatsDump(@builtin(global_invocation_id) gid: vec3u) {
53
+ let size = csParams.regionSize;
54
+ if any(gid >= size) {
55
+ return;
56
+ }
57
+ let idx = gid.x + gid.y * size.x + gid.z * size.x * size.y;
58
+ let ijk = csParams.regionMin + vec3i(gid);
59
+ var acc = vdbAccessorInit(csParams.grid);
60
+ let on = vdbIsActive(&acc, ijk);
61
+ csDumpValue[idx] = vdbReadValue(&acc, ijk);
62
+ csDumpIsOn[idx] = select(0u, 1u, on);
63
+ }
64
+ `,
65
+ };
66
+ const DEFAULT_BINS = 256;
67
+ const WHERE = "gridStats";
68
+ /**
69
+ * Records the statistics passes for grid `gridId` of `pool` and returns a
70
+ * {@link VDBReadback}: `await gridStats(device, pool, id).read()`, or with a
71
+ * host encoder `submit`, then `await job.submitted().read()`.
72
+ *
73
+ * The grid must be resident (`pool.update(encoder)` / `pool.flush()` ran
74
+ * after its `add`), and the pool must live on `device`. The tool allocates
75
+ * its own parameter, output and readback buffers and frees them in `read()`
76
+ * or `dispose()`; it never touches the pool's buffer beyond binding it.
77
+ *
78
+ * @param device The host's `GPUDevice`; the pool must live on it.
79
+ * @param pool The pool that holds the grid.
80
+ * @param gridId The grid's pool id; it must be resident.
81
+ * @param options Histogram bins and an optional host encoder ({@link VDBGridStatsOptions}).
82
+ *
83
+ * @throws VDBError `VDB_BAD_OPTION` for bad options, a pool on another
84
+ * device, a non-resident grid, or (root min < 0, the dump path) a bbox whose
85
+ * per-voxel outputs (`voxels * 4` bytes each, `voxels * 8` to read back)
86
+ * exceed `device.limits.maxStorageBufferBindingSize` / `maxBufferSize`.
87
+ */
88
+ export function vdbGridStats(device, pool, gridId, options = {}) {
89
+ const bins = options.histogramBins ?? DEFAULT_BINS;
90
+ checkPositiveInt(WHERE, "histogramBins", bins);
91
+ const info = checkTarget(WHERE, device, pool, gridId);
92
+ const range = { min: info.rootMin, max: info.rootMax };
93
+ const regionMin = info.indexBBox.min;
94
+ const size = bboxSize(info.indexBBox);
95
+ const fast = range.min >= 0;
96
+ if (!fast)
97
+ checkDumpSize(device, gridId, size);
98
+ const kernel = fast ? STATS_FAST : STATS_DUMP;
99
+ const cached = kernelPipeline(device, kernel, info.type);
100
+ const params = createInitialized(device, "vdb gridStats params", USAGE.UNIFORM, new Uint8Array(packParams({ grid: gridId, bins, regionMin, regionSize: size, range })));
101
+ let outA;
102
+ let outB;
103
+ const outUsage = USAGE.STORAGE | USAGE.COPY_SRC;
104
+ if (fast) {
105
+ // min starts at i32 max (above every non-negative float's bits), max at +0.0.
106
+ outA = createInitialized(device, "vdb gridStats min/max", outUsage, new Int32Array([0x7fffffff, 0]));
107
+ outB = createInitialized(device, "vdb gridStats sums", outUsage, new Uint32Array(3 + bins));
108
+ }
109
+ else {
110
+ const voxels = size[0] * size[1] * size[2];
111
+ outA = device.createBuffer({ label: "vdb gridStats values", size: voxels * 4, usage: outUsage });
112
+ outB = device.createBuffer({ label: "vdb gridStats active", size: voxels * 4, usage: outUsage });
113
+ }
114
+ const staging = device.createBuffer({ label: "vdb gridStats readback", size: outA.size + outB.size, usage: USAGE.MAP_READ | USAGE.COPY_DST });
115
+ const group0 = device.createBindGroup({ layout: cached.group0, entries: [pool.bindGroupEntry({ group: 0, firstBinding: 0 }), { binding: 1, resource: { buffer: params } }] });
116
+ const group1 = device.createBindGroup({ layout: cached.group1, entries: [{ binding: 0, resource: { buffer: outA } }, { binding: 1, resource: { buffer: outB } }] });
117
+ const host = hostEncoder(device, options.encoder, "vdb gridStats");
118
+ const pass = host.encoder.beginComputePass({ label: `vdb gridStats (${fast ? "atomics" : "dump"})` });
119
+ pass.setPipeline(cached.pipeline);
120
+ pass.setBindGroup(0, group0);
121
+ pass.setBindGroup(1, group1);
122
+ pass.dispatchWorkgroups(...workgroups(size));
123
+ pass.end();
124
+ host.encoder.copyBufferToBuffer(outA, 0, staging, 0, outA.size);
125
+ host.encoder.copyBufferToBuffer(outB, 0, staging, outA.size, outB.size);
126
+ host.submit();
127
+ const splitAt = outA.size;
128
+ return new ComputeJob(WHERE, [params, outA, outB], staging, cached.error, (bytes) => (fast ? reduceFast(bytes, bins, range) : reduceDump(bytes, splitAt, bins, range)), host.selfSubmitted);
129
+ }
130
+ /**
131
+ * The dump path writes 4 B of value and 4 B of active flag per bbox voxel and
132
+ * reads both back (8 B per voxel); refuse a bbox the device can't hold before
133
+ * any buffer is made.
134
+ */
135
+ function checkDumpSize(device, gridId, size) {
136
+ const voxels = size[0] * size[1] * size[2];
137
+ const each = voxels * 4;
138
+ const limits = device.limits;
139
+ const binding = limits?.maxStorageBufferBindingSize ?? Infinity;
140
+ const total = limits?.maxBufferSize ?? Infinity;
141
+ if (each > binding || each * 2 > total) {
142
+ throw new VDBError("VDB_BAD_OPTION", `${WHERE}: grid ${gridId} has a negative root min, so its stats take the dump path (8 B per bbox voxel): ` +
143
+ `${size.join(" x ")} = ${voxels} voxels needs ${each} B per output binding and ${each * 2} B of readback, over this device's ` +
144
+ `maxStorageBufferBindingSize ${binding} / maxBufferSize ${total}. Raise the limits (VDBGridPool.requiredLimits(adapter)) ` +
145
+ "or compute the stats on the CPU (vdbGridStatsCpu in @pmndrs/vdb/tools).");
146
+ }
147
+ }
148
+ function reduceFast(bytes, bins, range) {
149
+ const u32 = new Uint32Array(bytes, 8, 3 + bins);
150
+ const count = u32[0];
151
+ const histogram = u32.slice(3, 3 + bins);
152
+ if (count === 0)
153
+ return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: true, range };
154
+ const minMax = new Float32Array(bytes, 0, 2);
155
+ const total = BigInt(u32[2]) * 4294967296n + BigInt(u32[1]);
156
+ const meanNorm = Number(total) / (GRID_STATS_SUM_SCALE * count);
157
+ return {
158
+ min: minMax[0],
159
+ max: minMax[1],
160
+ mean: range.min + meanNorm * (range.max - range.min),
161
+ histogram,
162
+ activeVoxelCount: count,
163
+ usedAtomicFastPath: true,
164
+ range,
165
+ };
166
+ }
167
+ function reduceDump(bytes, splitAt, bins, range) {
168
+ const values = new Float32Array(bytes, 0, splitAt / 4);
169
+ const on = new Uint32Array(bytes, splitAt, splitAt / 4);
170
+ const histogram = new Uint32Array(bins);
171
+ let min = Infinity;
172
+ let max = -Infinity;
173
+ let sum = 0;
174
+ let count = 0;
175
+ const span = Math.max(range.max - range.min, 1e-20);
176
+ for (let i = 0; i < values.length; i++) {
177
+ if (!on[i])
178
+ continue;
179
+ const v = values[i];
180
+ count++;
181
+ sum += v;
182
+ if (v < min)
183
+ min = v;
184
+ if (v > max)
185
+ max = v;
186
+ const norm = Math.min(Math.max((v - range.min) / span, 0), 1);
187
+ histogram[Math.min(Math.floor(norm * bins), bins - 1)]++;
188
+ }
189
+ if (count === 0)
190
+ return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: false, range };
191
+ return { min, max, mean: sum / count, histogram, activeVoxelCount: count, usedAtomicFastPath: false, range };
192
+ }
193
+ //# sourceMappingURL=stats.js.map