@woosh/meep-engine 3.60.6 → 3.60.8

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 (328) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/package.json +1 -1
  3. package/src/core/binary/BitSet.d.ts.map +1 -1
  4. package/src/core/binary/BitSet.js +2 -1
  5. package/src/{format/image/avif/av1/util → core/binary/operations}/ceil_log2.d.ts +2 -2
  6. package/src/core/binary/operations/ceil_log2.d.ts.map +1 -0
  7. package/src/{format/image/avif/av1/util → core/binary/operations}/ceil_log2.js +18 -18
  8. package/src/core/binary/zstd/ZstdReverseBitReader.d.ts.map +1 -1
  9. package/src/core/binary/zstd/ZstdReverseBitReader.js +225 -223
  10. package/src/core/binary/zstd/zstd_fse.d.ts.map +1 -1
  11. package/src/core/binary/zstd/zstd_fse.js +267 -265
  12. package/src/core/binary/zstd/zstd_huffman.d.ts.map +1 -1
  13. package/src/core/binary/zstd/zstd_huffman.js +246 -244
  14. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  15. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +8 -2
  16. package/src/core/bvh2/bvh3/ebvh_optimize_treelet.d.ts.map +1 -1
  17. package/src/core/bvh2/bvh3/ebvh_optimize_treelet.js +8 -7
  18. package/src/core/collection/PairUint32Map.d.ts.map +1 -1
  19. package/src/core/collection/PairUint32Map.js +2 -2
  20. package/src/core/collection/Uint32Map.d.ts.map +1 -1
  21. package/src/core/collection/Uint32Map.js +2 -4
  22. package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -1
  23. package/src/core/collection/heap/FibonacciHeap.js +2 -1
  24. package/src/core/geom/2d/r-tree/StaticR2Tree.d.ts.map +1 -1
  25. package/src/core/geom/2d/r-tree/StaticR2Tree.js +8 -2
  26. package/src/core/geom/3d/shape/util/mesh_compute_triangle_edge_flags.d.ts.map +1 -1
  27. package/src/core/geom/3d/shape/util/mesh_compute_triangle_edge_flags.js +2 -3
  28. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  29. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -14
  30. package/src/engine/graphics/texture/atlas/sprite_atlas_border.d.ts.map +1 -1
  31. package/src/engine/graphics/texture/atlas/sprite_atlas_border.js +70 -69
  32. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.d.ts.map +1 -1
  33. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.js +2 -1
  34. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts.map +1 -1
  35. package/src/engine/graphics3/GPUParticleEmitterSystem.js +2 -1
  36. package/src/engine/graphics3/decal/GPUDecalRenderer.d.ts.map +1 -1
  37. package/src/engine/graphics3/decal/GPUDecalRenderer.js +2 -1
  38. package/src/engine/graphics3/decal/chunk_decal_record.d.ts +14 -0
  39. package/src/engine/graphics3/decal/chunk_decal_record.d.ts.map +1 -0
  40. package/src/engine/graphics3/decal/chunk_decal_record.js +44 -0
  41. package/src/engine/graphics3/decal/shader_cluster_assign_decals.d.ts.map +1 -1
  42. package/src/engine/graphics3/decal/shader_cluster_assign_decals.js +2 -15
  43. package/src/engine/graphics3/decal/shader_cull_decals_frustum.d.ts.map +1 -1
  44. package/src/engine/graphics3/decal/shader_cull_decals_frustum.js +3 -16
  45. package/src/engine/graphics3/decal/shader_decal_composite.d.ts.map +1 -1
  46. package/src/engine/graphics3/decal/shader_decal_composite.js +3 -23
  47. package/src/engine/graphics3/terrain/TERRAIN_MATERIAL_TEMPLATE.d.ts.map +1 -1
  48. package/src/engine/graphics3/terrain/TERRAIN_MATERIAL_TEMPLATE.js +2 -1
  49. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  50. package/src/engine/physics/queries/shape_cast.js +2 -2
  51. package/src/format/image/avif/av1/decode/decode_palette.js +442 -442
  52. package/src/format/image/avif/av1/entropy/SymbolWriter.d.ts.map +1 -1
  53. package/src/format/image/avif/av1/entropy/SymbolWriter.js +2 -1
  54. package/src/generation/foliage/material/foliage_tile.d.ts.map +1 -1
  55. package/src/generation/foliage/material/foliage_tile.js +2 -1
  56. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  57. package/src/generation/markers/GridActionRuleSet.js +12 -3
  58. package/src/shade/device/mock/SoftwareGPUDevice.d.ts.map +1 -1
  59. package/src/shade/device/mock/SoftwareGPUDevice.js +6 -13
  60. package/src/shade/playground/caldera/main.js +3 -2
  61. package/src/shade/playground/probe_clipmap/README.md +2 -1
  62. package/src/shade/playground/probe_clipmap/index.html +7 -2
  63. package/src/shade/playground/probe_clipmap/main.d.ts.map +1 -1
  64. package/src/shade/playground/probe_clipmap/main.js +17 -7
  65. package/src/shade/playground/sh_exponential/sh_exp_playground_shaders.d.ts.map +1 -1
  66. package/src/shade/playground/sh_exponential/sh_exp_playground_shaders.js +7 -13
  67. package/src/shade/playground/vgeo_scene/main.js +2 -1
  68. package/src/shade/playground/vsm/VSMDebugOverlay.d.ts.map +1 -1
  69. package/src/shade/playground/vsm/VSMDebugOverlay.js +3 -1
  70. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  71. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  72. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +6 -6
  73. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  74. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_coarsest.d.ts.map +1 -1
  75. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_coarsest.js +5 -4
  76. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_residual_restrict.d.ts.map +1 -1
  77. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_residual_restrict.js +168 -166
  78. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_smooth.d.ts.map +1 -1
  79. package/src/shade/renderer/fluid/pressure/shader_fluid_mg_smooth.js +221 -219
  80. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  81. package/src/shade/renderer/fow/shader_fog_of_war.d.ts.map +1 -1
  82. package/src/shade/renderer/fow/shader_fog_of_war.js +8 -19
  83. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts.map +1 -1
  84. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.js +6 -6
  85. package/src/shade/renderer/geometry/sdf/MeshSDFLayout.d.ts.map +1 -1
  86. package/src/shade/renderer/geometry/sdf/MeshSDFLayout.js +2 -1
  87. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts.map +1 -1
  88. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.js +2 -1
  89. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.d.ts.map +1 -1
  90. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.js +2 -1
  91. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_decode_from_storage.d.ts.map +1 -1
  92. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_decode_from_storage.js +10 -31
  93. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_encode_to_storage.d.ts.map +1 -1
  94. package/src/shade/renderer/global_illumination/brick4/gpu/encoding/v1/chunk_brick4_sh3_color_encode_to_storage.js +9 -15
  95. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.d.ts +2 -1
  96. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.d.ts.map +1 -1
  97. package/src/shade/renderer/global_illumination/clipmap/shader_debug_clipmap.js +6 -5
  98. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.d.ts.map +1 -1
  99. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.js +2 -1
  100. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +15 -3
  101. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts.map +1 -1
  102. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.js +168 -18
  103. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts +98 -57
  104. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts.map +1 -1
  105. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.js +168 -77
  106. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts +4 -2
  107. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts.map +1 -1
  108. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.js +27 -12
  109. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap.d.ts.map +1 -1
  110. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap.js +12 -7
  111. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  112. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +8 -2
  113. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.d.ts.map +1 -1
  114. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.js +5 -2
  115. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_batch.js +1 -1
  116. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.d.ts.map +1 -1
  117. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.js +5 -3
  118. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_resolve.js +1 -1
  119. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_free.d.ts.map +1 -1
  120. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_free.js +1 -1
  121. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_movers_command.d.ts.map +1 -1
  122. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_movers_command.js +4 -2
  123. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_scroll.d.ts.map +1 -1
  124. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_scroll.js +1 -1
  125. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_store.d.ts.map +1 -1
  126. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_store.js +1 -1
  127. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_take.d.ts.map +1 -1
  128. package/src/shade/renderer/global_illumination/probe_clipmap/brick/shader_brick_clipmap_take.js +3 -1
  129. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_mesh_cards.js +2 -2
  130. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts +114 -41
  131. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts.map +1 -1
  132. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.js +424 -207
  133. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts +34 -25
  134. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts.map +1 -1
  135. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.js +41 -31
  136. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.d.ts +7 -5
  137. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.d.ts.map +1 -1
  138. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP_RESAMPLING.js +7 -5
  139. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.d.ts +47 -0
  140. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.d.ts.map +1 -0
  141. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapHitWants.js +84 -0
  142. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts +48 -0
  143. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts.map +1 -0
  144. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.js +101 -0
  145. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts +58 -4
  146. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts.map +1 -1
  147. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.js +127 -30
  148. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.d.ts +18 -7
  149. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.d.ts.map +1 -1
  150. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_cage.js +39 -13
  151. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.d.ts +29 -8
  152. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.d.ts.map +1 -1
  153. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_pick.js +112 -56
  154. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.d.ts +19 -0
  155. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.d.ts.map +1 -0
  156. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_resample.js +35 -0
  157. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts.map +1 -1
  158. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.js +9 -3
  159. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts +3 -3
  160. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.js +5 -5
  161. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.d.ts +8 -12
  162. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.d.ts.map +1 -1
  163. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_accumulate.js +23 -56
  164. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.d.ts +0 -3
  165. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.d.ts.map +1 -1
  166. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_admit.js +11 -15
  167. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.d.ts +26 -0
  168. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.d.ts.map +1 -0
  169. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_bounce.js +173 -0
  170. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.d.ts +32 -0
  171. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.d.ts.map +1 -0
  172. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_candidate.js +166 -0
  173. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts +3 -4
  174. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts.map +1 -1
  175. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.js +3 -4
  176. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_guide.d.ts.map +1 -1
  177. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_guide.js +3 -1
  178. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts +6 -12
  179. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.d.ts.map +1 -1
  180. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.js +15 -65
  181. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_order.d.ts.map +1 -1
  182. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_order.js +7 -2
  183. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.d.ts +4 -4
  184. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.d.ts.map +1 -1
  185. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_project.js +24 -17
  186. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.d.ts +7 -5
  187. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.d.ts.map +1 -1
  188. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_publish.js +18 -10
  189. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.d.ts +2 -2
  190. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.d.ts.map +1 -1
  191. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_ray_layout.js +9 -5
  192. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts +3 -0
  193. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts.map +1 -1
  194. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.js +9 -6
  195. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.d.ts +1 -1
  196. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.d.ts.map +1 -1
  197. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample.js +16 -16
  198. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.d.ts +36 -0
  199. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.d.ts.map +1 -0
  200. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_resample_rays.js +233 -0
  201. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts.map +1 -1
  202. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.js +7 -5
  203. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.d.ts.map +1 -1
  204. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.js +5 -3
  205. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts.map +1 -1
  206. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.js +10 -4
  207. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.d.ts +2 -1
  208. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.d.ts.map +1 -1
  209. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace_command.js +12 -6
  210. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts +1 -2
  211. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts.map +1 -1
  212. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.js +5 -6
  213. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.d.ts +14 -18
  214. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.d.ts.map +1 -1
  215. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_hits.js +25 -35
  216. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.d.ts +13 -0
  217. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.d.ts.map +1 -0
  218. package/src/shade/renderer/gpu_primitive/WEBGPU_GUARANTEED_MAX_UNIFORM_BUFFER_BINDING_SIZE.js +12 -0
  219. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.d.ts +27 -2
  220. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.d.ts.map +1 -1
  221. package/src/shade/renderer/gpu_primitive/hash_table/cpu_build_hash_table.js +62 -6
  222. package/src/shade/renderer/gpu_primitive/indirect/IndirectComputeCommandBuildPass.d.ts.map +1 -1
  223. package/src/shade/renderer/gpu_primitive/indirect/IndirectComputeCommandBuildPass.js +10 -19
  224. package/src/shade/renderer/gpu_primitive/indirect/chunk_folded_dispatch.d.ts.map +1 -1
  225. package/src/shade/renderer/gpu_primitive/indirect/chunk_folded_dispatch.js +6 -3
  226. package/src/shade/renderer/hiz/hzb_pick_alignment.d.ts.map +1 -1
  227. package/src/shade/renderer/hiz/hzb_pick_alignment.js +149 -148
  228. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_environment_cells.d.ts.map +1 -1
  229. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_environment_cells.js +4 -2
  230. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_log_floor.d.ts.map +1 -1
  231. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_log_floor.js +6 -5
  232. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_project.d.ts.map +1 -1
  233. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_project.js +3 -1
  234. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_reference_reflectance.d.ts.map +1 -1
  235. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_reference_reflectance.js +3 -1
  236. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_solve.d.ts.map +1 -1
  237. package/src/shade/renderer/light/environment/sh_exponential/shader_sh_exp_solve.js +3 -1
  238. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.d.ts +0 -5
  239. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.d.ts.map +1 -1
  240. package/src/shade/renderer/light/world_cluster/WORLD_LIGHT_CLUSTER.js +0 -7
  241. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.d.ts +15 -2
  242. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.d.ts.map +1 -1
  243. package/src/shade/renderer/light/world_cluster/graph_build_world_light_clusters.js +51 -16
  244. package/src/shade/renderer/light/world_cluster/shader_world_cluster_assign_lights.d.ts.map +1 -1
  245. package/src/shade/renderer/light/world_cluster/shader_world_cluster_assign_lights.js +3 -2
  246. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  247. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.d.ts +17 -0
  248. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.d.ts.map +1 -0
  249. package/src/shade/renderer/postprocess/dof/raymarch/chunk_dof_lds_coc_cache.js +81 -0
  250. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.d.ts.map +1 -1
  251. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.js +5 -48
  252. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.d.ts.map +1 -1
  253. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js +4 -44
  254. package/src/shade/renderer/postprocess/gtao/chunk_integrate_lighting_sample.d.ts.map +1 -1
  255. package/src/shade/renderer/postprocess/gtao/chunk_integrate_lighting_sample.js +4 -1
  256. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.d.ts.map +1 -1
  257. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.js +8 -7
  258. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  259. package/src/shade/renderer/postprocess/nss/chunk_nss_luma_derivative.d.ts.map +1 -1
  260. package/src/shade/renderer/postprocess/nss/chunk_nss_luma_derivative.js +5 -7
  261. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.d.ts +17 -0
  262. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.d.ts.map +1 -0
  263. package/src/shade/renderer/postprocess/nss/chunk_nss_tonemap.js +56 -0
  264. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.d.ts.map +1 -1
  265. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.js +2 -22
  266. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.d.ts.map +1 -1
  267. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.js +2 -13
  268. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  269. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +10 -13
  270. package/src/shade/renderer/rasterize/expand/bucket/RASTERIZATION_BUCKET_LIMIT.d.ts.map +1 -1
  271. package/src/shade/renderer/rasterize/expand/bucket/RASTERIZATION_BUCKET_LIMIT.js +39 -38
  272. package/src/shade/renderer/rasterize/expand/mesh/shader_prefix_sum_to_command.d.ts.map +1 -1
  273. package/src/shade/renderer/rasterize/expand/mesh/shader_prefix_sum_to_command.js +7 -12
  274. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.d.ts +8 -6
  275. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.d.ts.map +1 -1
  276. package/src/shade/renderer/shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.js +10 -7
  277. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.d.ts +16 -0
  278. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.d.ts.map +1 -0
  279. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_key.js +35 -0
  280. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.d.ts +5 -2
  281. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.d.ts.map +1 -1
  282. package/src/shade/renderer/shader/chunk/clipmap/chunk_clipmap_select_finest.js +27 -18
  283. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh2_color_get_irradiance_at.d.ts.map +1 -1
  284. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh2_color_get_irradiance_at.js +5 -15
  285. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh3_convolve_with_cosine_kernel.d.ts.map +1 -1
  286. package/src/shade/renderer/shader/chunk/spherical_harmonics/chunk_sh3_convolve_with_cosine_kernel.js +5 -19
  287. package/src/shade/renderer/shader/chunk/spherical_harmonics/dering/chunk_sh3_windowing.d.ts.map +1 -1
  288. package/src/shade/renderer/shader/chunk/spherical_harmonics/dering/chunk_sh3_windowing.js +3 -22
  289. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.d.ts.map +1 -1
  290. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.js +2 -1
  291. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_shadow_group_list.d.ts.map +1 -1
  292. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_shadow_group_list.js +154 -152
  293. package/src/shade/renderer/volumetrics/irradiance_clipmap/GPUIrradianceClipmap.d.ts.map +1 -1
  294. package/src/shade/renderer/volumetrics/irradiance_clipmap/GPUIrradianceClipmap.js +2 -1
  295. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.d.ts +3 -1
  296. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.d.ts.map +1 -1
  297. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP.js +4 -3
  298. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.d.ts +7 -1
  299. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.d.ts.map +1 -1
  300. package/src/shade/renderer/volumetrics/irradiance_clipmap/IRRADIANCE_CLIPMAP_STRUCT.js +54 -47
  301. package/src/shade/renderer/volumetrics/irradiance_clipmap/chunk_irradiance_clipmap_sample.d.ts.map +1 -1
  302. package/src/shade/renderer/volumetrics/irradiance_clipmap/chunk_irradiance_clipmap_sample.js +371 -370
  303. package/src/shade/renderer/water/GPUWaterRenderer.d.ts.map +1 -1
  304. package/src/shade/renderer/water/GPUWaterRenderer.js +2 -1
  305. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
  306. package/src/shade/renderer/water/surface/lod/shader_water_lod.d.ts.map +1 -1
  307. package/src/shade/renderer/water/surface/lod/shader_water_lod.js +12 -14
  308. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.d.ts.map +1 -1
  309. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.js +2 -9
  310. package/src/shade/renderer/water/surface/particles/chunk_water_particle.d.ts.map +1 -1
  311. package/src/shade/renderer/water/surface/particles/chunk_water_particle.js +2 -1
  312. package/src/shade/renderer/wind/WIND_FIELD.d.ts +3 -1
  313. package/src/shade/renderer/wind/WIND_FIELD.d.ts.map +1 -1
  314. package/src/shade/renderer/wind/WIND_FIELD.js +4 -3
  315. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts +8 -2
  316. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts.map +1 -1
  317. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.js +11 -4
  318. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts +2 -2
  319. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts.map +1 -1
  320. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.js +13 -4
  321. package/src/shade/util/texture_mip_extent.d.ts.map +1 -1
  322. package/src/shade/util/texture_mip_extent.js +88 -87
  323. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  324. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +9 -7
  325. package/src/format/image/avif/av1/util/ceil_log2.d.ts.map +0 -1
  326. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.d.ts +0 -1
  327. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.d.ts.map +0 -1
  328. package/src/shade/renderer/shader/chunk/color/chunk_hash_squirrel3.js +0 -0
@@ -1,265 +1,267 @@
1
- /**
2
- * One Finite State Entropy decoding table.
3
- *
4
- * Three parallel arrays rather than an array of objects: a table has up to 512 entries and every
5
- * symbol decoded reads all three, so the shape that avoids an object per state is worth the noise.
6
- *
7
- * @typedef {object} ZstdFseTable
8
- * @property {number} accuracy_log base-2 logarithm of the table size, and the width of an initial
9
- * state read
10
- * @property {Uint8Array} symbol what each state decodes to
11
- * @property {Uint8Array} bits how many to read to reach the next state
12
- * @property {Uint16Array} baseline what to add them to
13
- */
14
-
15
- /**
16
- * Build a decoding table from a normalised distribution.
17
- *
18
- * **The allocation order is the format, not a choice.** States are handed out by stepping a position
19
- * through the table with a stride that visits every slot exactly once, so a symbol's states are
20
- * spread rather than contiguous. Symbols with the "less than one" probability are placed first, from
21
- * the end of the table backwards, and skipped over by the stepping. Getting either wrong builds a
22
- * table that decodes plausible garbage rather than failing.
23
- *
24
- * @param {Int16Array|number[]} counts normalised probability per symbol, `-1` meaning "less than one"
25
- * @param {number} symbol_count how many of `counts` are present
26
- * @param {number} accuracy_log
27
- * @returns {ZstdFseTable}
28
- *
29
- * @see RFC 8878, section 4.1.1
30
- * @author Alex Goldring
31
- * @copyright Company Named Limited (c) 2026
32
- */
33
- export function zstd_build_fse_table(counts, symbol_count, accuracy_log) {
34
- const size = 1 << accuracy_log;
35
-
36
- const symbol = new Uint8Array(size);
37
- const bits = new Uint8Array(size);
38
- const baseline = new Uint16Array(size);
39
-
40
- /*
41
- A "less than one" symbol gets a single state, taken from the end of the table backwards, and
42
- that state resets the decoder to a full read of `accuracy_log` bits.
43
- */
44
- let low_slot = size;
45
-
46
- for (let s = 0; s < symbol_count; s++) {
47
- if (counts[s] === -1) {
48
- low_slot--;
49
-
50
- symbol[low_slot] = s;
51
- bits[low_slot] = accuracy_log;
52
- baseline[low_slot] = 0;
53
- }
54
- }
55
-
56
- /*
57
- The stride visits every slot of a power-of-two table exactly once — it is odd relative to the
58
- table size — which is what spreads a symbol's states instead of clustering them.
59
- */
60
- const step = (size >> 1) + (size >> 3) + 3;
61
- const mask = size - 1;
62
-
63
- let position = 0;
64
-
65
- for (let s = 0; s < symbol_count; s++) {
66
- const count = counts[s];
67
-
68
- for (let i = 0; i < count; i++) {
69
- symbol[position] = s;
70
-
71
- do {
72
- position = (position + step) & mask;
73
- } while (position >= low_slot);
74
- }
75
- }
76
-
77
- if (position !== 0) {
78
- throw new Error(
79
- "zstd: an FSE distribution did not fill its table exactly, so its probabilities do not"
80
- + " sum to the accuracy log's scale"
81
- );
82
- }
83
-
84
- /*
85
- Now that each state knows its symbol, the states of one symbol are numbered in their natural
86
- order and given widths: the lower ones take an extra bit so the widths sum to the table size.
87
- */
88
- const next = new Uint16Array(symbol_count);
89
-
90
- for (let s = 0; s < symbol_count; s++) {
91
- next[s] = counts[s] === -1 ? 1 : counts[s];
92
- }
93
-
94
- /*
95
- The "less than one" states need no special case here: their counter starts at one, which makes
96
- the width below the full accuracy log and the baseline zero — exactly the reset they were placed
97
- for. Writing that as a branch would be a second statement of the same arithmetic.
98
- */
99
- for (let state = 0; state < size; state++) {
100
- const value = next[symbol[state]]++;
101
-
102
- bits[state] = accuracy_log - (31 - Math.clz32(value));
103
- baseline[state] = ((value << bits[state]) - size) & 0xFFFF;
104
- }
105
-
106
- return { accuracy_log, symbol, bits, baseline };
107
- }
108
-
109
- /**
110
- * Read a normalised distribution and build its table.
111
- *
112
- * The distribution is read *forward* in little-endian order, unlike the streams the table then
113
- * decodes — it is a header rather than an entropy-coded body.
114
- *
115
- * @param {Uint8Array} data
116
- * @param {number} offset
117
- * @param {number} end one past the last readable byte
118
- * @param {number} max_symbol the largest symbol the context allows
119
- * @param {number} max_accuracy_log the largest the context allows
120
- * @returns {{table: ZstdFseTable, byte_length: number}}
121
- * @throws {Error} for a distribution that overruns its scale or its symbol range
122
- */
123
- export function zstd_read_fse_table(data, offset, end, max_symbol, max_accuracy_log) {
124
- let bit = 0;
125
-
126
- /**
127
- * @param {number} count
128
- * @returns {number}
129
- */
130
- const peek = count => {
131
- let value = 0;
132
-
133
- for (let i = 0; i < count; i++) {
134
- const at = offset + ((bit + i) >> 3);
135
-
136
- if (at >= end) {
137
- continue;
138
- }
139
-
140
- value |= ((data[at] >> ((bit + i) & 7)) & 1) << i;
141
- }
142
-
143
- return value;
144
- };
145
-
146
- const accuracy_log = (peek(4) & 15) + 5;
147
-
148
- bit += 4;
149
-
150
- if (accuracy_log > max_accuracy_log) {
151
- throw new Error(
152
- `zstd: an FSE distribution declares an accuracy log of ${accuracy_log}, and this table`
153
- + ` allows at most ${max_accuracy_log}`
154
- );
155
- }
156
-
157
- const size = 1 << accuracy_log;
158
-
159
- const counts = new Int16Array(max_symbol + 1);
160
-
161
- /*
162
- **The field width is not recomputed per symbol; it shrinks with a running threshold.** As the
163
- unallocated probability falls, so does the number of values a count could take, and the format
164
- tracks that with a threshold that halves — spending one bit fewer each time it does. Deriving
165
- the width from `remaining` afresh looks equivalent and is not, because the halving lags: it
166
- happens only once `remaining` has fallen below the current threshold, so a distribution reads
167
- correctly only if the decoder shrinks in the same steps the encoder grew.
168
- */
169
- let remaining = size + 1;
170
- let threshold = size;
171
- let width = accuracy_log + 1;
172
-
173
- let symbol = 0;
174
- let previous_zero = false;
175
-
176
- while (remaining > 1 && symbol <= max_symbol) {
177
- if (previous_zero) {
178
- /*
179
- A zero count is followed by a two-bit run of further zeroes, and a run of three means
180
- another such field follows — so a long stretch of unused symbols costs two bits per
181
- three rather than a field each.
182
- */
183
- let run = 0;
184
-
185
- for (; ;) {
186
- const chunk = peek(2);
187
-
188
- bit += 2;
189
-
190
- run += chunk;
191
-
192
- if (chunk !== 3) {
193
- break;
194
- }
195
- }
196
-
197
- for (let i = 0; i < run && symbol <= max_symbol; i++) {
198
- counts[symbol++] = 0;
199
- }
200
-
201
- previous_zero = false;
202
-
203
- continue;
204
- }
205
-
206
- const max = (2 * threshold - 1) - remaining;
207
-
208
- const value = peek(width);
209
-
210
- let count;
211
-
212
- if ((value & (threshold - 1)) < max) {
213
- count = value & (threshold - 1);
214
- bit += width - 1;
215
- } else {
216
- count = value & (2 * threshold - 1);
217
-
218
- if (count >= threshold) {
219
- count -= max;
220
- }
221
-
222
- bit += width;
223
- }
224
-
225
- // one is subtracted so that zero can mean the "less than one" probability
226
- count--;
227
-
228
- remaining -= count < 0 ? -count : count;
229
-
230
- counts[symbol++] = count;
231
-
232
- previous_zero = count === 0;
233
-
234
- while (remaining < threshold) {
235
- width--;
236
- threshold >>= 1;
237
- }
238
- }
239
-
240
- if (remaining !== 1) {
241
- throw new Error(
242
- "zstd: an FSE distribution's probabilities do not sum to its declared scale"
243
- );
244
- }
245
-
246
- return {
247
- table: zstd_build_fse_table(counts, symbol, accuracy_log),
248
- byte_length: (bit + 7) >> 3,
249
- };
250
- }
251
-
252
- /**
253
- * A table for a stream that carries one symbol over and over.
254
- *
255
- * @param {number} value
256
- * @returns {ZstdFseTable}
257
- */
258
- export function zstd_rle_fse_table(value) {
259
- return {
260
- accuracy_log: 0,
261
- symbol: Uint8Array.from([value]),
262
- bits: Uint8Array.from([0]),
263
- baseline: Uint16Array.from([0]),
264
- };
265
- }
1
+ import { msb_32 } from "../msb_32.js";
2
+
3
+ /**
4
+ * One Finite State Entropy decoding table.
5
+ *
6
+ * Three parallel arrays rather than an array of objects: a table has up to 512 entries and every
7
+ * symbol decoded reads all three, so the shape that avoids an object per state is worth the noise.
8
+ *
9
+ * @typedef {object} ZstdFseTable
10
+ * @property {number} accuracy_log base-2 logarithm of the table size, and the width of an initial
11
+ * state read
12
+ * @property {Uint8Array} symbol what each state decodes to
13
+ * @property {Uint8Array} bits how many to read to reach the next state
14
+ * @property {Uint16Array} baseline what to add them to
15
+ */
16
+
17
+ /**
18
+ * Build a decoding table from a normalised distribution.
19
+ *
20
+ * **The allocation order is the format, not a choice.** States are handed out by stepping a position
21
+ * through the table with a stride that visits every slot exactly once, so a symbol's states are
22
+ * spread rather than contiguous. Symbols with the "less than one" probability are placed first, from
23
+ * the end of the table backwards, and skipped over by the stepping. Getting either wrong builds a
24
+ * table that decodes plausible garbage rather than failing.
25
+ *
26
+ * @param {Int16Array|number[]} counts normalised probability per symbol, `-1` meaning "less than one"
27
+ * @param {number} symbol_count how many of `counts` are present
28
+ * @param {number} accuracy_log
29
+ * @returns {ZstdFseTable}
30
+ *
31
+ * @see RFC 8878, section 4.1.1
32
+ * @author Alex Goldring
33
+ * @copyright Company Named Limited (c) 2026
34
+ */
35
+ export function zstd_build_fse_table(counts, symbol_count, accuracy_log) {
36
+ const size = 1 << accuracy_log;
37
+
38
+ const symbol = new Uint8Array(size);
39
+ const bits = new Uint8Array(size);
40
+ const baseline = new Uint16Array(size);
41
+
42
+ /*
43
+ A "less than one" symbol gets a single state, taken from the end of the table backwards, and
44
+ that state resets the decoder to a full read of `accuracy_log` bits.
45
+ */
46
+ let low_slot = size;
47
+
48
+ for (let s = 0; s < symbol_count; s++) {
49
+ if (counts[s] === -1) {
50
+ low_slot--;
51
+
52
+ symbol[low_slot] = s;
53
+ bits[low_slot] = accuracy_log;
54
+ baseline[low_slot] = 0;
55
+ }
56
+ }
57
+
58
+ /*
59
+ The stride visits every slot of a power-of-two table exactly once — it is odd relative to the
60
+ table size — which is what spreads a symbol's states instead of clustering them.
61
+ */
62
+ const step = (size >> 1) + (size >> 3) + 3;
63
+ const mask = size - 1;
64
+
65
+ let position = 0;
66
+
67
+ for (let s = 0; s < symbol_count; s++) {
68
+ const count = counts[s];
69
+
70
+ for (let i = 0; i < count; i++) {
71
+ symbol[position] = s;
72
+
73
+ do {
74
+ position = (position + step) & mask;
75
+ } while (position >= low_slot);
76
+ }
77
+ }
78
+
79
+ if (position !== 0) {
80
+ throw new Error(
81
+ "zstd: an FSE distribution did not fill its table exactly, so its probabilities do not"
82
+ + " sum to the accuracy log's scale"
83
+ );
84
+ }
85
+
86
+ /*
87
+ Now that each state knows its symbol, the states of one symbol are numbered in their natural
88
+ order and given widths: the lower ones take an extra bit so the widths sum to the table size.
89
+ */
90
+ const next = new Uint16Array(symbol_count);
91
+
92
+ for (let s = 0; s < symbol_count; s++) {
93
+ next[s] = counts[s] === -1 ? 1 : counts[s];
94
+ }
95
+
96
+ /*
97
+ The "less than one" states need no special case here: their counter starts at one, which makes
98
+ the width below the full accuracy log and the baseline zero — exactly the reset they were placed
99
+ for. Writing that as a branch would be a second statement of the same arithmetic.
100
+ */
101
+ for (let state = 0; state < size; state++) {
102
+ const value = next[symbol[state]]++;
103
+
104
+ bits[state] = accuracy_log - msb_32(value);
105
+ baseline[state] = ((value << bits[state]) - size) & 0xFFFF;
106
+ }
107
+
108
+ return { accuracy_log, symbol, bits, baseline };
109
+ }
110
+
111
+ /**
112
+ * Read a normalised distribution and build its table.
113
+ *
114
+ * The distribution is read *forward* in little-endian order, unlike the streams the table then
115
+ * decodes — it is a header rather than an entropy-coded body.
116
+ *
117
+ * @param {Uint8Array} data
118
+ * @param {number} offset
119
+ * @param {number} end one past the last readable byte
120
+ * @param {number} max_symbol the largest symbol the context allows
121
+ * @param {number} max_accuracy_log the largest the context allows
122
+ * @returns {{table: ZstdFseTable, byte_length: number}}
123
+ * @throws {Error} for a distribution that overruns its scale or its symbol range
124
+ */
125
+ export function zstd_read_fse_table(data, offset, end, max_symbol, max_accuracy_log) {
126
+ let bit = 0;
127
+
128
+ /**
129
+ * @param {number} count
130
+ * @returns {number}
131
+ */
132
+ const peek = count => {
133
+ let value = 0;
134
+
135
+ for (let i = 0; i < count; i++) {
136
+ const at = offset + ((bit + i) >> 3);
137
+
138
+ if (at >= end) {
139
+ continue;
140
+ }
141
+
142
+ value |= ((data[at] >> ((bit + i) & 7)) & 1) << i;
143
+ }
144
+
145
+ return value;
146
+ };
147
+
148
+ const accuracy_log = (peek(4) & 15) + 5;
149
+
150
+ bit += 4;
151
+
152
+ if (accuracy_log > max_accuracy_log) {
153
+ throw new Error(
154
+ `zstd: an FSE distribution declares an accuracy log of ${accuracy_log}, and this table`
155
+ + ` allows at most ${max_accuracy_log}`
156
+ );
157
+ }
158
+
159
+ const size = 1 << accuracy_log;
160
+
161
+ const counts = new Int16Array(max_symbol + 1);
162
+
163
+ /*
164
+ **The field width is not recomputed per symbol; it shrinks with a running threshold.** As the
165
+ unallocated probability falls, so does the number of values a count could take, and the format
166
+ tracks that with a threshold that halves — spending one bit fewer each time it does. Deriving
167
+ the width from `remaining` afresh looks equivalent and is not, because the halving lags: it
168
+ happens only once `remaining` has fallen below the current threshold, so a distribution reads
169
+ correctly only if the decoder shrinks in the same steps the encoder grew.
170
+ */
171
+ let remaining = size + 1;
172
+ let threshold = size;
173
+ let width = accuracy_log + 1;
174
+
175
+ let symbol = 0;
176
+ let previous_zero = false;
177
+
178
+ while (remaining > 1 && symbol <= max_symbol) {
179
+ if (previous_zero) {
180
+ /*
181
+ A zero count is followed by a two-bit run of further zeroes, and a run of three means
182
+ another such field follows — so a long stretch of unused symbols costs two bits per
183
+ three rather than a field each.
184
+ */
185
+ let run = 0;
186
+
187
+ for (; ;) {
188
+ const chunk = peek(2);
189
+
190
+ bit += 2;
191
+
192
+ run += chunk;
193
+
194
+ if (chunk !== 3) {
195
+ break;
196
+ }
197
+ }
198
+
199
+ for (let i = 0; i < run && symbol <= max_symbol; i++) {
200
+ counts[symbol++] = 0;
201
+ }
202
+
203
+ previous_zero = false;
204
+
205
+ continue;
206
+ }
207
+
208
+ const max = (2 * threshold - 1) - remaining;
209
+
210
+ const value = peek(width);
211
+
212
+ let count;
213
+
214
+ if ((value & (threshold - 1)) < max) {
215
+ count = value & (threshold - 1);
216
+ bit += width - 1;
217
+ } else {
218
+ count = value & (2 * threshold - 1);
219
+
220
+ if (count >= threshold) {
221
+ count -= max;
222
+ }
223
+
224
+ bit += width;
225
+ }
226
+
227
+ // one is subtracted so that zero can mean the "less than one" probability
228
+ count--;
229
+
230
+ remaining -= count < 0 ? -count : count;
231
+
232
+ counts[symbol++] = count;
233
+
234
+ previous_zero = count === 0;
235
+
236
+ while (remaining < threshold) {
237
+ width--;
238
+ threshold >>= 1;
239
+ }
240
+ }
241
+
242
+ if (remaining !== 1) {
243
+ throw new Error(
244
+ "zstd: an FSE distribution's probabilities do not sum to its declared scale"
245
+ );
246
+ }
247
+
248
+ return {
249
+ table: zstd_build_fse_table(counts, symbol, accuracy_log),
250
+ byte_length: (bit + 7) >> 3,
251
+ };
252
+ }
253
+
254
+ /**
255
+ * A table for a stream that carries one symbol over and over.
256
+ *
257
+ * @param {number} value
258
+ * @returns {ZstdFseTable}
259
+ */
260
+ export function zstd_rle_fse_table(value) {
261
+ return {
262
+ accuracy_log: 0,
263
+ symbol: Uint8Array.from([value]),
264
+ bits: Uint8Array.from([0]),
265
+ baseline: Uint16Array.from([0]),
266
+ };
267
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"zstd_huffman.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/zstd/zstd_huffman.js"],"names":[],"mappings":"AAoHA;;;;;;;;;;;;;;;;GAgBG;AACH,8CAVW,UAAU,UACV,MAAM,OACN,MAAM,GACJ;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAuF1D;AAED;;;;;;;;;;;GAWG;AACH,kDATW,gBAAgB,QAChB,UAAU,UACV,MAAM,eACN,MAAM,OACN,UAAU,cACV,MAAM,SACN,MAAM,QAmBhB;;;;;;;;;;;;cAxNa,MAAM;;;;YACN,UAAU;;;;UACV,UAAU"}
1
+ {"version":3,"file":"zstd_huffman.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/zstd/zstd_huffman.js"],"names":[],"mappings":"AAsHA;;;;;;;;;;;;;;;;GAgBG;AACH,8CAVW,UAAU,UACV,MAAM,OACN,MAAM,GACJ;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAuF1D;AAED;;;;;;;;;;;GAWG;AACH,kDATW,gBAAgB,QAChB,UAAU,UACV,MAAM,eACN,MAAM,OACN,UAAU,cACV,MAAM,SACN,MAAM,QAmBhB;;;;;;;;;;;;cAxNa,MAAM;;;;YACN,UAAU;;;;UACV,UAAU"}