@forgeax/engine-render 0.1.3 → 0.1.6

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 (918) hide show
  1. package/README.md +130 -641
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/__tests__/device-scope-lifecycle.unit.test.d.ts +2 -0
  4. package/dist/__tests__/device-scope-lifecycle.unit.test.d.ts.map +1 -0
  5. package/dist/__tests__/device-scope-stale-matrix.unit.test.d.ts +2 -0
  6. package/dist/__tests__/device-scope-stale-matrix.unit.test.d.ts.map +1 -0
  7. package/dist/__tests__/fullscreen-feature-plan.unit.test.d.ts +2 -0
  8. package/dist/__tests__/fullscreen-feature-plan.unit.test.d.ts.map +1 -0
  9. package/dist/__tests__/gpu-driven-indirect-raster-evidence.d.ts.map +1 -1
  10. package/dist/__tests__/gpu-driven-view-gpu-evidence.d.ts +6 -0
  11. package/dist/__tests__/gpu-driven-view-gpu-evidence.d.ts.map +1 -1
  12. package/dist/{gpu-driven/view-reference.d.ts → __tests__/gpu-driven-view-reference.d.ts} +4 -4
  13. package/dist/__tests__/gpu-driven-view-reference.d.ts.map +1 -0
  14. package/dist/__tests__/gpu-scene-render-graph-gpu.d.ts.map +1 -1
  15. package/dist/__tests__/ibl/face-uniforms.unit.test.d.ts +2 -0
  16. package/dist/__tests__/ibl/face-uniforms.unit.test.d.ts.map +1 -0
  17. package/dist/__tests__/morph-feature-plan.unit.test.d.ts +2 -0
  18. package/dist/__tests__/morph-feature-plan.unit.test.d.ts.map +1 -0
  19. package/dist/__tests__/render-feature-plan.test-d.d.ts +2 -0
  20. package/dist/__tests__/render-feature-plan.test-d.d.ts.map +1 -0
  21. package/dist/__tests__/render-feature-plan.unit.test.d.ts +2 -0
  22. package/dist/__tests__/render-feature-plan.unit.test.d.ts.map +1 -0
  23. package/dist/__tests__/ssao-config.unit.test.d.ts +2 -0
  24. package/dist/__tests__/ssao-config.unit.test.d.ts.map +1 -0
  25. package/dist/__tests__/standard-clustered-pipeline.unit.test.d.ts +2 -0
  26. package/dist/__tests__/standard-clustered-pipeline.unit.test.d.ts.map +1 -0
  27. package/dist/__tests__/standard-descriptors.test-d.d.ts +2 -0
  28. package/dist/__tests__/standard-descriptors.test-d.d.ts.map +1 -0
  29. package/dist/__tests__/standard-pipeline.dawn.test.d.ts +2 -0
  30. package/dist/__tests__/standard-pipeline.dawn.test.d.ts.map +1 -0
  31. package/dist/__tests__/standard-pipeline.integration.test.d.ts +2 -0
  32. package/dist/__tests__/standard-pipeline.integration.test.d.ts.map +1 -0
  33. package/dist/__tests__/standard-profile-oracle.unit.test.d.ts +2 -0
  34. package/dist/__tests__/standard-profile-oracle.unit.test.d.ts.map +1 -0
  35. package/dist/__tests__/visibility-resource-short-circuit.unit.test.d.ts +2 -0
  36. package/dist/__tests__/visibility-resource-short-circuit.unit.test.d.ts.map +1 -0
  37. package/dist/{renderer/backend-selection.d.ts → assembly/backend-contract.d.ts} +15 -4
  38. package/dist/assembly/backend-contract.d.ts.map +1 -0
  39. package/dist/assembly/factory.d.ts +207 -0
  40. package/dist/assembly/factory.d.ts.map +1 -0
  41. package/dist/assembly/host-contract.d.ts +84 -0
  42. package/dist/assembly/host-contract.d.ts.map +1 -0
  43. package/dist/{renderer → assembly}/material/assembly.d.ts +1 -2
  44. package/dist/{renderer → assembly}/material/assembly.d.ts.map +1 -1
  45. package/dist/assembly/material/pipeline-projection.d.ts +30 -0
  46. package/dist/assembly/material/pipeline-projection.d.ts.map +1 -0
  47. package/dist/authoring.d.ts +10 -11
  48. package/dist/authoring.d.ts.map +1 -1
  49. package/dist/authoring.mjs +25 -3
  50. package/dist/authoring.mjs.map +1 -1
  51. package/dist/chunk-CQXZC5XI.mjs +182 -0
  52. package/dist/chunk-CQXZC5XI.mjs.map +1 -0
  53. package/dist/chunk-QC4VW3XJ.mjs +79 -0
  54. package/dist/chunk-QC4VW3XJ.mjs.map +1 -0
  55. package/dist/chunk-SCRSAK5B.mjs +480 -0
  56. package/dist/chunk-SCRSAK5B.mjs.map +1 -0
  57. package/dist/components/__tests__/schema-contract.unit.test.d.ts +2 -0
  58. package/dist/components/__tests__/schema-contract.unit.test.d.ts.map +1 -0
  59. package/dist/components/glyph-text.d.ts +1 -1
  60. package/dist/components/glyph-text.d.ts.map +1 -1
  61. package/dist/components/index.d.ts +2 -2
  62. package/dist/components/index.d.ts.map +1 -1
  63. package/dist/components/instances.d.ts +1 -1
  64. package/dist/components/instances.d.ts.map +1 -1
  65. package/dist/components/light-helpers.d.ts +1 -1
  66. package/dist/components/light-helpers.d.ts.map +1 -1
  67. package/dist/components/mesh-filter.d.ts +7 -7
  68. package/dist/components/mesh-filter.d.ts.map +1 -1
  69. package/dist/components/scene-instance.d.ts +11 -11
  70. package/dist/components/skybox-background.d.ts +56 -0
  71. package/dist/components/skybox-background.d.ts.map +1 -0
  72. package/dist/components/skylight.d.ts +55 -0
  73. package/dist/components/skylight.d.ts.map +1 -0
  74. package/dist/components/sprite-animation.d.ts +2 -3
  75. package/dist/components/sprite-animation.d.ts.map +1 -1
  76. package/dist/components/sprite-instances.d.ts +1 -1
  77. package/dist/components/sprite-playback-mode.d.ts +6 -1
  78. package/dist/components/sprite-playback-mode.d.ts.map +1 -1
  79. package/dist/components/sprite-region-override.d.ts +2 -3
  80. package/dist/components/sprite-region-override.d.ts.map +1 -1
  81. package/dist/components/tile-layer.d.ts +5 -0
  82. package/dist/components/tile-layer.d.ts.map +1 -1
  83. package/dist/construct-renderer.d.ts +18 -1
  84. package/dist/construct-renderer.d.ts.map +1 -1
  85. package/dist/construct-renderer.mjs +27008 -4
  86. package/dist/construct-renderer.mjs.map +1 -1
  87. package/dist/debug-draw-glue.d.ts +2 -53
  88. package/dist/debug-draw-glue.d.ts.map +1 -1
  89. package/dist/device/device-scope.d.ts +83 -0
  90. package/dist/device/device-scope.d.ts.map +1 -0
  91. package/dist/{gpu-resource-store.d.ts → device/gpu-residency.d.ts} +91 -48
  92. package/dist/device/gpu-residency.d.ts.map +1 -0
  93. package/dist/device/resource-types.d.ts +8 -0
  94. package/dist/device/resource-types.d.ts.map +1 -0
  95. package/dist/engine-metrics.d.ts +2 -2
  96. package/dist/engine-metrics.d.ts.map +1 -1
  97. package/dist/errors/recover.d.ts +28 -1
  98. package/dist/errors/recover.d.ts.map +1 -1
  99. package/dist/errors/render.d.ts +249 -258
  100. package/dist/errors/render.d.ts.map +1 -1
  101. package/dist/features/fullscreen.d.ts +19 -0
  102. package/dist/features/fullscreen.d.ts.map +1 -0
  103. package/dist/features/host.d.ts +32 -26
  104. package/dist/features/host.d.ts.map +1 -1
  105. package/dist/features/morph/morph-feature.d.ts +39 -5
  106. package/dist/features/morph/morph-feature.d.ts.map +1 -1
  107. package/dist/features/plan.d.ts +182 -0
  108. package/dist/features/plan.d.ts.map +1 -0
  109. package/dist/features/prepared-gpu-work.d.ts +21 -17
  110. package/dist/features/prepared-gpu-work.d.ts.map +1 -1
  111. package/dist/features/prepared-graphics-store.d.ts +2 -1
  112. package/dist/features/prepared-graphics-store.d.ts.map +1 -1
  113. package/dist/features/prepared-graphics.d.ts +11 -21
  114. package/dist/features/prepared-graphics.d.ts.map +1 -1
  115. package/dist/features/render-graph-compute.d.ts +2 -2
  116. package/dist/features/render-graph-compute.d.ts.map +1 -1
  117. package/dist/features/render-graph-contribution.d.ts +4 -7
  118. package/dist/features/render-graph-contribution.d.ts.map +1 -1
  119. package/dist/features/render-graph-raster.d.ts +2 -2
  120. package/dist/features/render-graph-raster.d.ts.map +1 -1
  121. package/dist/features/render-graph-resources.d.ts +6 -6
  122. package/dist/features/render-graph-resources.d.ts.map +1 -1
  123. package/dist/features/targets.d.ts +5 -5
  124. package/dist/features/targets.d.ts.map +1 -1
  125. package/dist/features/types.d.ts +11 -190
  126. package/dist/features/types.d.ts.map +1 -1
  127. package/dist/features/vocabulary.d.ts +14 -0
  128. package/dist/features/vocabulary.d.ts.map +1 -0
  129. package/dist/fullscreen-post-process-pass.d.ts +4 -25
  130. package/dist/fullscreen-post-process-pass.d.ts.map +1 -1
  131. package/dist/glyph-text-layout-system.d.ts +3 -2
  132. package/dist/glyph-text-layout-system.d.ts.map +1 -1
  133. package/dist/gpu-driven/batch-topology.d.ts +6 -75
  134. package/dist/gpu-driven/batch-topology.d.ts.map +1 -1
  135. package/dist/gpu-driven/production-raster.d.ts +13 -112
  136. package/dist/gpu-driven/production-raster.d.ts.map +1 -1
  137. package/dist/gpu-driven/view-gpu.d.ts +10 -66
  138. package/dist/gpu-driven/view-gpu.d.ts.map +1 -1
  139. package/dist/gpu-resource.d.ts +3 -3
  140. package/dist/gpu-scene-schema.d.ts +1 -94
  141. package/dist/gpu-scene-schema.d.ts.map +1 -1
  142. package/dist/gpu-scene.d.ts +7 -33
  143. package/dist/gpu-scene.d.ts.map +1 -1
  144. package/dist/hdrp-buffers.d.ts +3 -53
  145. package/dist/hdrp-buffers.d.ts.map +1 -1
  146. package/dist/ibl/IblPipelineCache.d.ts +74 -180
  147. package/dist/ibl/IblPipelineCache.d.ts.map +1 -1
  148. package/dist/ibl/skylight-bind-group.d.ts +1 -1
  149. package/dist/index.d.ts +13 -43
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.mjs +165 -3
  152. package/dist/index.mjs.map +1 -1
  153. package/dist/inspection-types.d.ts +69 -0
  154. package/dist/inspection-types.d.ts.map +1 -0
  155. package/dist/instance-buffer-cache.d.ts +1 -4
  156. package/dist/instance-buffer-cache.d.ts.map +1 -1
  157. package/dist/internal.d.ts +1 -73
  158. package/dist/internal.d.ts.map +1 -1
  159. package/dist/internal.mjs +1 -43
  160. package/dist/internal.mjs.map +1 -1
  161. package/dist/lifecycle.d.ts +36 -2
  162. package/dist/lifecycle.d.ts.map +1 -1
  163. package/dist/materials.d.ts +0 -3
  164. package/dist/materials.d.ts.map +1 -1
  165. package/dist/mesh-material-bindings.d.ts +0 -1
  166. package/dist/mesh-material-bindings.d.ts.map +1 -1
  167. package/dist/pbr-pipeline.d.ts +75 -29
  168. package/dist/pbr-pipeline.d.ts.map +1 -1
  169. package/dist/pipeline/standard-forward-lane.d.ts +5 -0
  170. package/dist/pipeline/standard-forward-lane.d.ts.map +1 -0
  171. package/dist/pipeline/standard-pipeline.d.ts +31 -0
  172. package/dist/pipeline/standard-pipeline.d.ts.map +1 -0
  173. package/dist/pipeline/standard-profile.d.ts +40 -0
  174. package/dist/pipeline/standard-profile.d.ts.map +1 -0
  175. package/dist/pipeline-builder.d.ts +3 -3
  176. package/dist/pipeline-builder.d.ts.map +1 -1
  177. package/dist/pipeline-spec-types.d.ts +24 -0
  178. package/dist/pipeline-spec-types.d.ts.map +1 -0
  179. package/dist/pipeline-spec.d.ts +16 -155
  180. package/dist/pipeline-spec.d.ts.map +1 -1
  181. package/dist/plugin.d.ts +1 -14
  182. package/dist/plugin.d.ts.map +1 -1
  183. package/dist/post-process-errors.d.ts +18 -18
  184. package/dist/post-process-errors.d.ts.map +1 -1
  185. package/dist/prepare/prepared-graphics-resolver.d.ts +2 -5
  186. package/dist/prepare/prepared-graphics-resolver.d.ts.map +1 -1
  187. package/dist/record/__tests__/typed-frame-graph-plan.unit.test.d.ts +2 -0
  188. package/dist/record/__tests__/typed-frame-graph-plan.unit.test.d.ts.map +1 -0
  189. package/dist/record/frame-lighting.d.ts +7 -73
  190. package/dist/record/frame-lighting.d.ts.map +1 -1
  191. package/dist/record/frame-snapshot.d.ts +44 -44
  192. package/dist/record/frame-snapshot.d.ts.map +1 -1
  193. package/dist/record/frame-targets.d.ts +5 -38
  194. package/dist/record/frame-targets.d.ts.map +1 -1
  195. package/dist/record/frame.d.ts +64 -52
  196. package/dist/record/frame.d.ts.map +1 -1
  197. package/dist/record/helpers.d.ts +3 -2
  198. package/dist/record/helpers.d.ts.map +1 -1
  199. package/dist/record/main-pass-geometry.d.ts +5 -4
  200. package/dist/record/main-pass-geometry.d.ts.map +1 -1
  201. package/dist/record/main-pass-material.d.ts +90 -59
  202. package/dist/record/main-pass-material.d.ts.map +1 -1
  203. package/dist/record/main-pass-sprite-draws.d.ts +28 -3
  204. package/dist/record/main-pass-sprite-draws.d.ts.map +1 -1
  205. package/dist/record/main-pass.d.ts +1 -1
  206. package/dist/record/main-pass.d.ts.map +1 -1
  207. package/dist/record/mesh-ssbo.d.ts +276 -3
  208. package/dist/record/mesh-ssbo.d.ts.map +1 -1
  209. package/dist/record/render-context.d.ts +235 -0
  210. package/dist/record/render-context.d.ts.map +1 -0
  211. package/dist/record/shadow-pass.d.ts +15 -88
  212. package/dist/record/shadow-pass.d.ts.map +1 -1
  213. package/dist/record/skybox-post-pass.d.ts +1 -1
  214. package/dist/record/skybox-post-pass.d.ts.map +1 -1
  215. package/dist/record/typed-frame-graph.d.ts +29 -7
  216. package/dist/record/typed-frame-graph.d.ts.map +1 -1
  217. package/dist/record/view-ubo.d.ts +3 -3
  218. package/dist/record/view-ubo.d.ts.map +1 -1
  219. package/dist/render-contract.d.ts +416 -0
  220. package/dist/render-contract.d.ts.map +1 -0
  221. package/dist/render-data.d.ts.map +1 -1
  222. package/dist/render-graph-primitives.d.ts +14 -362
  223. package/dist/render-graph-primitives.d.ts.map +1 -1
  224. package/dist/render-pipeline.d.ts +25 -64
  225. package/dist/render-pipeline.d.ts.map +1 -1
  226. package/dist/render-system-extract.d.ts +107 -338
  227. package/dist/render-system-extract.d.ts.map +1 -1
  228. package/dist/render-system.d.ts +21 -713
  229. package/dist/render-system.d.ts.map +1 -1
  230. package/dist/scene/render-scene-types.d.ts +58 -0
  231. package/dist/scene/render-scene-types.d.ts.map +1 -0
  232. package/dist/scene/render-scene.d.ts +105 -0
  233. package/dist/scene/render-scene.d.ts.map +1 -0
  234. package/dist/scene-instances/post-spawn-resolve-joints.d.ts +2 -5
  235. package/dist/scene-instances/post-spawn-resolve-joints.d.ts.map +1 -1
  236. package/dist/ssao-buffers.d.ts +22 -3
  237. package/dist/ssao-buffers.d.ts.map +1 -1
  238. package/dist/systems/skin-palette-allocator.d.ts +2 -4
  239. package/dist/systems/skin-palette-allocator.d.ts.map +1 -1
  240. package/dist/systems/skin-palette-types.d.ts +14 -0
  241. package/dist/systems/skin-palette-types.d.ts.map +1 -0
  242. package/dist/systems/transparent-sort-config.d.ts +23 -2
  243. package/dist/systems/transparent-sort-config.d.ts.map +1 -1
  244. package/dist/tilemap-chunk-extract-system.d.ts +4 -3
  245. package/dist/tilemap-chunk-extract-system.d.ts.map +1 -1
  246. package/dist/typed-render-graph-primitives.d.ts +2 -4
  247. package/dist/typed-render-graph-primitives.d.ts.map +1 -1
  248. package/dist/typed-shadow-passes.d.ts +3 -3
  249. package/dist/typed-shadow-passes.d.ts.map +1 -1
  250. package/package.json +23 -23
  251. package/src/__tests__/backend-selection-rhi-capture.test-d.ts +1 -1
  252. package/src/__tests__/callback-inference.test-d.ts +6 -3
  253. package/src/__tests__/cluster-grid-default-surface.unit.test.ts +7 -4
  254. package/src/__tests__/construct-renderer-identity.unit.test.ts +15 -2
  255. package/src/__tests__/device-scope-lifecycle.unit.test.ts +151 -0
  256. package/src/__tests__/device-scope-stale-matrix.unit.test.ts +42 -0
  257. package/src/__tests__/direct-extract-consumer-contract.test-d.ts +8 -19
  258. package/src/__tests__/direct-light-snapshot.unit.test.ts +3 -13
  259. package/src/__tests__/factory-contract.integration.test.ts +158 -209
  260. package/src/__tests__/fallback-row-stride-surface.unit.test.ts +1 -4
  261. package/src/__tests__/frame-observation.contract.test.ts +17 -8
  262. package/src/__tests__/fullscreen-feature-plan.unit.test.ts +32 -0
  263. package/src/__tests__/glyph-text-layout-recovery.unit.test.ts +6 -11
  264. package/src/__tests__/gpu-driven-indirect-raster-evidence.ts +9 -16
  265. package/src/__tests__/gpu-driven-production.integration.test.ts +32 -205
  266. package/src/__tests__/gpu-driven-scaling.unit.test.ts +4 -7
  267. package/src/__tests__/gpu-driven-view-gpu-evidence.ts +87 -8
  268. package/src/__tests__/gpu-driven-view-graph.integration.test.ts +170 -8
  269. package/src/{gpu-driven/view-reference.ts → __tests__/gpu-driven-view-reference.ts} +4 -3
  270. package/src/__tests__/gpu-driven-view.browser.test.ts +12 -1
  271. package/src/__tests__/gpu-driven-view.dawn.test.ts +12 -1
  272. package/src/__tests__/gpu-driven-view.unit.test.ts +11 -267
  273. package/src/__tests__/gpu-resource-store-stride.unit.test.ts +3 -3
  274. package/src/__tests__/gpu-scene-render-graph-gpu.ts +2 -3
  275. package/src/__tests__/gpu-scene.dawn.test.ts +2 -6
  276. package/src/__tests__/gpu-scene.unit.test.ts +10 -24
  277. package/src/__tests__/ibl/face-uniforms.unit.test.ts +46 -0
  278. package/src/__tests__/infinite-grid-no-vertex-probe.unit.test.ts +34 -66
  279. package/src/__tests__/ktx2-basis-gpu-consumer.dawn.test.ts +14 -5
  280. package/src/__tests__/light-buffer-layout.unit.test.ts +4 -49
  281. package/src/__tests__/material-cooked-projection.unit.test.ts +2 -51
  282. package/src/__tests__/material-snapshot-mutation.integration.test.ts +10 -15
  283. package/src/__tests__/material-static-dynamic-route.unit.test.ts +4 -23
  284. package/src/__tests__/material-stride-surface.unit.test.ts +2 -2
  285. package/src/__tests__/mesh-buffer-usage-surface.unit.test.ts +7 -8
  286. package/src/__tests__/morph-culling-reentry.dawn.test.ts +29 -38
  287. package/src/__tests__/morph-feature-gpu-work.integration.test.ts +45 -43
  288. package/src/__tests__/morph-feature-plan.unit.test.ts +53 -0
  289. package/src/__tests__/morph-visual-evidence.integration.test.ts +47 -33
  290. package/src/__tests__/nineslice-handle-surface.unit.test.ts +11 -6
  291. package/src/__tests__/post-process-error-policy-owner.unit.test.ts +6 -13
  292. package/src/__tests__/prepared-graphics-capability.unit.test.ts +6 -81
  293. package/src/__tests__/prepared-graphics-generation.unit.test.ts +3 -17
  294. package/src/__tests__/prepared-graphics-lifecycle.unit.test.ts +6 -74
  295. package/src/__tests__/prepared-graphics-resolver.unit.test.ts +1 -3
  296. package/src/__tests__/prepared-graphics-snapshot.unit.test.ts +2 -2
  297. package/src/__tests__/profiler-default-off.test.ts +1 -1
  298. package/src/__tests__/profiler-phase-catalog.test.ts +2 -2
  299. package/src/__tests__/profiler-phase-integration.test.ts +5 -13
  300. package/src/__tests__/profiler-phase-token.test.ts +3 -8
  301. package/src/__tests__/public-surface.test-d.ts +65 -3
  302. package/src/__tests__/recover-error-policy-owner.unit.test.ts +1 -21
  303. package/src/__tests__/render-error-code-owner.test-d.ts +18 -23
  304. package/src/__tests__/render-error-detail-ssot.test-d.ts +0 -95
  305. package/src/__tests__/render-error-exhaustive.test-d.ts +8 -1
  306. package/src/__tests__/render-feature-assembly.test-d.ts +8 -16
  307. package/src/__tests__/render-feature-context.test-d.ts +16 -40
  308. package/src/__tests__/render-feature-contract.test-d.ts +9 -18
  309. package/src/__tests__/render-feature-diagnostics.unit.test.ts +6 -8
  310. package/src/__tests__/render-feature-docs.unit.test.ts +8 -7
  311. package/src/__tests__/render-feature-gpu-work.integration.test.ts +14 -75
  312. package/src/__tests__/render-feature-plan.test-d.ts +161 -0
  313. package/src/__tests__/render-feature-plan.unit.test.ts +170 -0
  314. package/src/__tests__/render-feature-prepared-diagnostics.unit.test.ts +8 -19
  315. package/src/__tests__/render-feature-prepared-errors.test-d.ts +3 -6
  316. package/src/__tests__/render-feature-prepared-graphics-docs.unit.test.ts +10 -71
  317. package/src/__tests__/render-feature-prepared-graphics-isolation.unit.test.ts +11 -61
  318. package/src/__tests__/render-feature-prepared-graphics-negative.test-d.ts +20 -43
  319. package/src/__tests__/render-feature-prepared-graphics.test-d.ts +56 -78
  320. package/src/__tests__/render-feature-public-surface.test-d.ts +6 -24
  321. package/src/__tests__/render-feature-retry.unit.test.ts +7 -48
  322. package/src/__tests__/render-feature-scheduling.unit.test.ts +15 -27
  323. package/src/__tests__/render-feature-stage-failed-policy-owner.unit.test.ts +0 -9
  324. package/src/__tests__/render-feature-stage-fault-recovery.unit.test.ts +19 -109
  325. package/src/__tests__/render-feature-visibility-context.test-d.ts +1 -6
  326. package/src/__tests__/render-feature-visibility-context.unit.test.ts +1 -2
  327. package/src/__tests__/render-feature-zero-work.unit.test.ts +14 -20
  328. package/src/__tests__/render-scene-projection.unit.test.ts +73 -111
  329. package/src/__tests__/renderer-factory-material-contract.unit.test.ts +46 -50
  330. package/src/__tests__/renderer-lifecycle.integration.test.ts +49 -1
  331. package/src/__tests__/shader-stage-surface.unit.test.ts +14 -9
  332. package/src/__tests__/ssao-config.unit.test.ts +36 -0
  333. package/src/__tests__/ssao-kernel-surface.unit.test.ts +4 -5
  334. package/src/__tests__/standard-clustered-pipeline.unit.test.ts +28 -0
  335. package/src/__tests__/standard-descriptors.test-d.ts +22 -0
  336. package/src/__tests__/standard-pipeline.dawn.test.ts +61 -0
  337. package/src/__tests__/standard-pipeline.integration.test.ts +124 -0
  338. package/src/__tests__/standard-profile-oracle.unit.test.ts +62 -0
  339. package/src/__tests__/surface-configuration.unit.test.ts +1 -2
  340. package/src/__tests__/texture-usage-surface.unit.test.ts +3 -6
  341. package/src/__tests__/typed-pipeline-topology.unit.test.ts +40 -206
  342. package/src/__tests__/urp-pipeline-targets.unit.test.ts +1 -11
  343. package/src/__tests__/urp-pipeline.unit.test.ts +2 -2
  344. package/src/__tests__/vertex-color-pipeline.unit.test.ts +10 -2
  345. package/src/__tests__/vertex-layout-consumer.unit.test.ts +1 -1
  346. package/src/__tests__/visibility-diagnostics.integration.test.ts +7 -11
  347. package/src/__tests__/visibility-extract.integration.test.ts +20 -11
  348. package/src/__tests__/visibility-extract.perf.test.ts +66 -32
  349. package/src/__tests__/visibility-feature-dedup.integration.test.ts +2 -4
  350. package/src/__tests__/visibility-hidden-report.unit.test.ts +1 -2
  351. package/src/__tests__/visibility-instances.integration.test.ts +7 -11
  352. package/src/__tests__/visibility-multi-world.integration.test.ts +38 -6
  353. package/src/__tests__/visibility-producer-matrix.integration.test.ts +18 -41
  354. package/src/__tests__/visibility-public-surface.test-d.ts +10 -9
  355. package/src/__tests__/visibility-resolver.unit.test.ts +2 -1
  356. package/src/__tests__/visibility-resource-short-circuit.unit.test.ts +80 -0
  357. package/src/__tests__/visibility-snapshot-contract.unit.test.ts +2 -1
  358. package/src/__tests__/vocabulary.unit.test.ts +1 -1
  359. package/src/assembly/backend-contract.ts +57 -0
  360. package/src/{renderer/renderer-factory.ts → assembly/factory.ts} +1709 -2693
  361. package/src/assembly/host-contract.ts +101 -0
  362. package/src/{renderer → assembly}/material/assembly.ts +1 -3
  363. package/src/assembly/material/pipeline-projection.ts +63 -0
  364. package/src/authoring.ts +14 -22
  365. package/src/components/__tests__/schema-contract.unit.test.ts +10 -0
  366. package/src/components/glyph-text.ts +3 -2
  367. package/src/components/index.ts +7 -9
  368. package/src/components/instances.ts +4 -5
  369. package/src/components/light-helpers.ts +1 -1
  370. package/src/components/mesh-filter.ts +11 -10
  371. package/src/components/post-process-params.ts +3 -3
  372. package/src/components/scene-instance.ts +12 -12
  373. package/src/components/skybox-background.ts +103 -0
  374. package/src/components/{environment.ts → skylight.ts} +2 -111
  375. package/src/components/sprite-animation.ts +3 -4
  376. package/src/components/sprite-instances.ts +2 -2
  377. package/src/components/sprite-playback-mode.ts +7 -1
  378. package/src/components/sprite-region-override.ts +2 -3
  379. package/src/components/tile-layer.ts +8 -2
  380. package/src/construct-renderer.ts +67 -4
  381. package/src/debug-draw-glue.ts +8 -129
  382. package/src/device/device-scope.ts +306 -0
  383. package/src/{gpu-resource-store.ts → device/gpu-residency.ts} +540 -639
  384. package/src/device/resource-types.ts +20 -0
  385. package/src/engine-metrics.ts +12 -19
  386. package/src/errors/recover.ts +45 -3
  387. package/src/errors/render.ts +357 -460
  388. package/src/features/fullscreen.ts +46 -0
  389. package/src/features/host.ts +575 -309
  390. package/src/features/morph/morph-feature.ts +195 -105
  391. package/src/features/plan.ts +447 -0
  392. package/src/features/prepared-gpu-work.ts +72 -15
  393. package/src/features/prepared-graphics-store.ts +20 -6
  394. package/src/features/prepared-graphics.ts +12 -71
  395. package/src/features/render-graph-compute.ts +14 -5
  396. package/src/features/render-graph-contribution.ts +43 -63
  397. package/src/features/render-graph-raster.ts +11 -6
  398. package/src/features/render-graph-resources.ts +25 -23
  399. package/src/features/targets.ts +8 -21
  400. package/src/features/types.ts +39 -227
  401. package/src/features/vocabulary.ts +24 -0
  402. package/src/fullscreen-post-process-pass.ts +14 -57
  403. package/src/glyph-text-layout-system.ts +70 -96
  404. package/src/gpu-driven/batch-topology.ts +24 -202
  405. package/src/gpu-driven/production-raster.ts +93 -1108
  406. package/src/gpu-driven/view-gpu.ts +46 -192
  407. package/src/gpu-resource.ts +4 -4
  408. package/src/gpu-scene-schema.ts +11 -99
  409. package/src/gpu-scene.ts +231 -364
  410. package/src/hdrp-buffers.ts +12 -221
  411. package/src/ibl/IblPipelineCache.ts +471 -711
  412. package/src/ibl/skylight-bind-group.ts +4 -4
  413. package/src/index.ts +58 -217
  414. package/src/inspection-types.ts +76 -0
  415. package/src/instance-buffer-cache.ts +1 -29
  416. package/src/internal.ts +6 -85
  417. package/src/lifecycle.ts +64 -19
  418. package/src/materials.ts +7 -29
  419. package/src/mesh-material-bindings.ts +0 -1
  420. package/src/pbr-pipeline.ts +434 -53
  421. package/src/{urp-pipeline.ts → pipeline/standard-forward-lane.ts} +38 -149
  422. package/src/{hdrp-pipeline.ts → pipeline/standard-pipeline.ts} +221 -191
  423. package/src/pipeline/standard-profile.ts +65 -0
  424. package/src/pipeline-builder.ts +60 -64
  425. package/src/pipeline-spec-types.ts +28 -0
  426. package/src/pipeline-spec.ts +72 -609
  427. package/src/plugin.ts +3 -75
  428. package/src/post-process-errors.ts +31 -33
  429. package/src/prepare/prepared-graphics-resolver.ts +5 -4
  430. package/src/record/__tests__/material-slot-plan.unit.test.ts +1 -33
  431. package/src/record/__tests__/typed-frame-graph-plan.unit.test.ts +41 -0
  432. package/src/record/__tests__/video-texture-view.unit.test.ts +1 -1
  433. package/src/record/frame-lighting.ts +74 -195
  434. package/src/record/frame-snapshot.ts +45 -60
  435. package/src/record/frame-targets.ts +8 -243
  436. package/src/record/frame.ts +509 -796
  437. package/src/record/helpers.ts +6 -11
  438. package/src/record/main-pass-geometry.ts +106 -147
  439. package/src/record/main-pass-material.ts +517 -190
  440. package/src/record/main-pass-sprite-draws.ts +198 -117
  441. package/src/record/main-pass.ts +162 -143
  442. package/src/record/mesh-ssbo.ts +517 -38
  443. package/src/record/render-context.ts +364 -0
  444. package/src/record/shadow-pass.ts +138 -1838
  445. package/src/record/skybox-post-pass.ts +12 -14
  446. package/src/record/typed-frame-graph.ts +215 -254
  447. package/src/record/view-ubo.ts +6 -37
  448. package/src/render-contract.ts +571 -0
  449. package/src/render-data.ts +3 -3
  450. package/src/render-graph-primitives.ts +76 -851
  451. package/src/render-pipeline.ts +104 -188
  452. package/src/render-system-extract.ts +1048 -1729
  453. package/src/render-system.ts +330 -1957
  454. package/src/scene/render-scene-types.ts +64 -0
  455. package/src/scene/render-scene.ts +1032 -0
  456. package/src/scene-instances/post-spawn-resolve-joints.ts +4 -7
  457. package/src/ssao-buffers.ts +167 -8
  458. package/src/systems/skin-palette-allocator.ts +21 -64
  459. package/src/systems/skin-palette-types.ts +14 -0
  460. package/src/systems/transparent-sort-config.ts +25 -3
  461. package/src/tilemap-chunk-extract-system.ts +53 -70
  462. package/src/typed-render-graph-primitives.ts +35 -24
  463. package/src/typed-shadow-passes.ts +26 -56
  464. package/dist/__tests__/analytic-sky-contract.test.d.ts +0 -2
  465. package/dist/__tests__/analytic-sky-contract.test.d.ts.map +0 -1
  466. package/dist/__tests__/analytic-sky-falsify.test.d.ts +0 -2
  467. package/dist/__tests__/analytic-sky-falsify.test.d.ts.map +0 -1
  468. package/dist/__tests__/assets-runtime-handoff.integration.test.d.ts +0 -2
  469. package/dist/__tests__/assets-runtime-handoff.integration.test.d.ts.map +0 -1
  470. package/dist/__tests__/backend-selection.integration.test.d.ts +0 -2
  471. package/dist/__tests__/backend-selection.integration.test.d.ts.map +0 -1
  472. package/dist/__tests__/camera-temporal.test-d.d.ts +0 -2
  473. package/dist/__tests__/camera-temporal.test-d.d.ts.map +0 -1
  474. package/dist/__tests__/camera-temporal.test.d.ts +0 -2
  475. package/dist/__tests__/camera-temporal.test.d.ts.map +0 -1
  476. package/dist/__tests__/directional-shadow-probe-atlas-layout.unit.test.d.ts +0 -2
  477. package/dist/__tests__/directional-shadow-probe-atlas-layout.unit.test.d.ts.map +0 -1
  478. package/dist/__tests__/environment-inspection.test.d.ts +0 -2
  479. package/dist/__tests__/environment-inspection.test.d.ts.map +0 -1
  480. package/dist/__tests__/fog-ai-user.fixture.d.ts +0 -2
  481. package/dist/__tests__/fog-ai-user.fixture.d.ts.map +0 -1
  482. package/dist/__tests__/fog-custom-render-feature.fixture.d.ts +0 -16
  483. package/dist/__tests__/fog-custom-render-feature.fixture.d.ts.map +0 -1
  484. package/dist/__tests__/fog-custom-render-feature.integration.test.d.ts +0 -2
  485. package/dist/__tests__/fog-custom-render-feature.integration.test.d.ts.map +0 -1
  486. package/dist/__tests__/fog-inspection.integration.test.d.ts +0 -2
  487. package/dist/__tests__/fog-inspection.integration.test.d.ts.map +0 -1
  488. package/dist/__tests__/fog-owner-state.integration.test.d.ts +0 -2
  489. package/dist/__tests__/fog-owner-state.integration.test.d.ts.map +0 -1
  490. package/dist/__tests__/fog-pipeline-topology.integration.test.d.ts +0 -2
  491. package/dist/__tests__/fog-pipeline-topology.integration.test.d.ts.map +0 -1
  492. package/dist/__tests__/fog-public-surface.integration.test.d.ts +0 -2
  493. package/dist/__tests__/fog-public-surface.integration.test.d.ts.map +0 -1
  494. package/dist/__tests__/fog-ray-contract.integration.test.d.ts +0 -2
  495. package/dist/__tests__/fog-ray-contract.integration.test.d.ts.map +0 -1
  496. package/dist/__tests__/fog-source-absence.integration.test.d.ts +0 -2
  497. package/dist/__tests__/fog-source-absence.integration.test.d.ts.map +0 -1
  498. package/dist/__tests__/fog-temporal.integration.test.d.ts +0 -2
  499. package/dist/__tests__/fog-temporal.integration.test.d.ts.map +0 -1
  500. package/dist/__tests__/frame-chain.unit.test.d.ts +0 -2
  501. package/dist/__tests__/frame-chain.unit.test.d.ts.map +0 -1
  502. package/dist/__tests__/gpu-scene-field-type-owner.test-d.d.ts +0 -2
  503. package/dist/__tests__/gpu-scene-field-type-owner.test-d.d.ts.map +0 -1
  504. package/dist/__tests__/hdrp-pipeline.unit.test.d.ts +0 -2
  505. package/dist/__tests__/hdrp-pipeline.unit.test.d.ts.map +0 -1
  506. package/dist/__tests__/ibl/ibl-fallback.unit.test.d.ts +0 -2
  507. package/dist/__tests__/ibl/ibl-fallback.unit.test.d.ts.map +0 -1
  508. package/dist/__tests__/material-derived-error-stop-draw.integration.test.d.ts +0 -2
  509. package/dist/__tests__/material-derived-error-stop-draw.integration.test.d.ts.map +0 -1
  510. package/dist/__tests__/material-derived-payload.integration.test.d.ts +0 -2
  511. package/dist/__tests__/material-derived-payload.integration.test.d.ts.map +0 -1
  512. package/dist/__tests__/materials.unit.test.d.ts +0 -2
  513. package/dist/__tests__/materials.unit.test.d.ts.map +0 -1
  514. package/dist/__tests__/param-schema-projection-census.unit.test.d.ts +0 -2
  515. package/dist/__tests__/param-schema-projection-census.unit.test.d.ts.map +0 -1
  516. package/dist/__tests__/persistent-render-scene.unit.test.d.ts +0 -2
  517. package/dist/__tests__/persistent-render-scene.unit.test.d.ts.map +0 -1
  518. package/dist/__tests__/pipeline-error-policy-owner.unit.test.d.ts +0 -2
  519. package/dist/__tests__/pipeline-error-policy-owner.unit.test.d.ts.map +0 -1
  520. package/dist/__tests__/pipeline-pass-trace.test.d.ts +0 -2
  521. package/dist/__tests__/pipeline-pass-trace.test.d.ts.map +0 -1
  522. package/dist/__tests__/pipeline-stage-owner.test-d.d.ts +0 -2
  523. package/dist/__tests__/pipeline-stage-owner.test-d.d.ts.map +0 -1
  524. package/dist/__tests__/plugin.test.d.ts +0 -2
  525. package/dist/__tests__/plugin.test.d.ts.map +0 -1
  526. package/dist/__tests__/prepared-graphics-backend-matrix.unit.test.d.ts +0 -2
  527. package/dist/__tests__/prepared-graphics-backend-matrix.unit.test.d.ts.map +0 -1
  528. package/dist/__tests__/prepared-graphics-resolver-recording.unit.test.d.ts +0 -2
  529. package/dist/__tests__/prepared-graphics-resolver-recording.unit.test.d.ts.map +0 -1
  530. package/dist/__tests__/public-pipeline-id.test-d.d.ts +0 -2
  531. package/dist/__tests__/public-pipeline-id.test-d.d.ts.map +0 -1
  532. package/dist/__tests__/render-dispatch-membership.unit.test.d.ts +0 -2
  533. package/dist/__tests__/render-dispatch-membership.unit.test.d.ts.map +0 -1
  534. package/dist/__tests__/render-feature-construction.unit.test.d.ts +0 -2
  535. package/dist/__tests__/render-feature-construction.unit.test.d.ts.map +0 -1
  536. package/dist/__tests__/render-feature-error-code-owner.test-d.d.ts +0 -2
  537. package/dist/__tests__/render-feature-error-code-owner.test-d.d.ts.map +0 -1
  538. package/dist/__tests__/render-feature-gpu-buffer-usage-owner.test-d.d.ts +0 -2
  539. package/dist/__tests__/render-feature-gpu-buffer-usage-owner.test-d.d.ts.map +0 -1
  540. package/dist/__tests__/render-feature-graph.integration.test.d.ts +0 -2
  541. package/dist/__tests__/render-feature-graph.integration.test.d.ts.map +0 -1
  542. package/dist/__tests__/render-feature-graphics-staging.unit.test.d.ts +0 -2
  543. package/dist/__tests__/render-feature-graphics-staging.unit.test.d.ts.map +0 -1
  544. package/dist/__tests__/render-feature-order.unit.test.d.ts +0 -2
  545. package/dist/__tests__/render-feature-order.unit.test.d.ts.map +0 -1
  546. package/dist/__tests__/render-feature-prepared-graphics-recording.unit.test.d.ts +0 -2
  547. package/dist/__tests__/render-feature-prepared-graphics-recording.unit.test.d.ts.map +0 -1
  548. package/dist/__tests__/render-feature-staging.unit.test.d.ts +0 -2
  549. package/dist/__tests__/render-feature-staging.unit.test.d.ts.map +0 -1
  550. package/dist/__tests__/renderer-render-scene-public.test-d.d.ts +0 -2
  551. package/dist/__tests__/renderer-render-scene-public.test-d.d.ts.map +0 -1
  552. package/dist/__tests__/scene-temporal-coverage.unit.test.d.ts +0 -2
  553. package/dist/__tests__/scene-temporal-coverage.unit.test.d.ts.map +0 -1
  554. package/dist/__tests__/sun-snapshot-consumers.test.d.ts +0 -2
  555. package/dist/__tests__/sun-snapshot-consumers.test.d.ts.map +0 -1
  556. package/dist/__tests__/surface-backend-kind-owner.test-d.d.ts +0 -2
  557. package/dist/__tests__/surface-backend-kind-owner.test-d.d.ts.map +0 -1
  558. package/dist/__tests__/taa-history-store.unit.test.d.ts +0 -2
  559. package/dist/__tests__/taa-history-store.unit.test.d.ts.map +0 -1
  560. package/dist/__tests__/temporal-frame-transaction.integration.test.d.ts +0 -2
  561. package/dist/__tests__/temporal-frame-transaction.integration.test.d.ts.map +0 -1
  562. package/dist/__tests__/temporal-inspection.unit.test.d.ts +0 -2
  563. package/dist/__tests__/temporal-inspection.unit.test.d.ts.map +0 -1
  564. package/dist/assets/__tests__/asset-decoders.unit.test.d.ts +0 -2
  565. package/dist/assets/__tests__/asset-decoders.unit.test.d.ts.map +0 -1
  566. package/dist/assets/__tests__/mipmap-generator.unit.test.d.ts +0 -2
  567. package/dist/assets/__tests__/mipmap-generator.unit.test.d.ts.map +0 -1
  568. package/dist/assets/__tests__/render-asset-port.unit.test.d.ts +0 -2
  569. package/dist/assets/__tests__/render-asset-port.unit.test.d.ts.map +0 -1
  570. package/dist/assets/__tests__/resolve-render-asset.unit.test.d.ts +0 -2
  571. package/dist/assets/__tests__/resolve-render-asset.unit.test.d.ts.map +0 -1
  572. package/dist/chunk-33UF5SAO.mjs +0 -7397
  573. package/dist/chunk-33UF5SAO.mjs.map +0 -1
  574. package/dist/chunk-A5QCJSNL.mjs +0 -29913
  575. package/dist/chunk-A5QCJSNL.mjs.map +0 -1
  576. package/dist/chunk-JMSB7AR4.mjs +0 -3
  577. package/dist/chunk-JMSB7AR4.mjs.map +0 -1
  578. package/dist/chunk-LXNGO6AO.mjs +0 -569
  579. package/dist/chunk-LXNGO6AO.mjs.map +0 -1
  580. package/dist/chunk-QRXPSX4X.mjs +0 -659
  581. package/dist/chunk-QRXPSX4X.mjs.map +0 -1
  582. package/dist/chunk-YAKEQPWO.mjs +0 -1439
  583. package/dist/chunk-YAKEQPWO.mjs.map +0 -1
  584. package/dist/components/__tests__/atmosphere-red.test.d.ts +0 -2
  585. package/dist/components/__tests__/atmosphere-red.test.d.ts.map +0 -1
  586. package/dist/components/__tests__/atmosphere.test.d.ts +0 -2
  587. package/dist/components/__tests__/atmosphere.test.d.ts.map +0 -1
  588. package/dist/components/__tests__/fog.test-d.d.ts +0 -2
  589. package/dist/components/__tests__/fog.test-d.d.ts.map +0 -1
  590. package/dist/components/__tests__/fog.test.d.ts +0 -2
  591. package/dist/components/__tests__/fog.test.d.ts.map +0 -1
  592. package/dist/components/atmosphere.d.ts +0 -18
  593. package/dist/components/atmosphere.d.ts.map +0 -1
  594. package/dist/components/environment.d.ts +0 -116
  595. package/dist/components/environment.d.ts.map +0 -1
  596. package/dist/deferred-lighting.d.ts +0 -13
  597. package/dist/deferred-lighting.d.ts.map +0 -1
  598. package/dist/dynamic-texture-store.d.ts +0 -42
  599. package/dist/dynamic-texture-store.d.ts.map +0 -1
  600. package/dist/environment/__tests__/failure-injection.test.d.ts +0 -2
  601. package/dist/environment/__tests__/failure-injection.test.d.ts.map +0 -1
  602. package/dist/environment/__tests__/generation-red.test.d.ts +0 -2
  603. package/dist/environment/__tests__/generation-red.test.d.ts.map +0 -1
  604. package/dist/environment/__tests__/generation.test.d.ts +0 -2
  605. package/dist/environment/__tests__/generation.test.d.ts.map +0 -1
  606. package/dist/environment/__tests__/graph-transaction.test.d.ts +0 -2
  607. package/dist/environment/__tests__/graph-transaction.test.d.ts.map +0 -1
  608. package/dist/environment/__tests__/inspection-red.test.d.ts +0 -2
  609. package/dist/environment/__tests__/inspection-red.test.d.ts.map +0 -1
  610. package/dist/environment/__tests__/lifecycle-evidence.test.d.ts +0 -2
  611. package/dist/environment/__tests__/lifecycle-evidence.test.d.ts.map +0 -1
  612. package/dist/environment/__tests__/pipeline-topology.test.d.ts +0 -2
  613. package/dist/environment/__tests__/pipeline-topology.test.d.ts.map +0 -1
  614. package/dist/environment/__tests__/readiness.test.d.ts +0 -2
  615. package/dist/environment/__tests__/readiness.test.d.ts.map +0 -1
  616. package/dist/environment/__tests__/recovery.test.d.ts +0 -2
  617. package/dist/environment/__tests__/recovery.test.d.ts.map +0 -1
  618. package/dist/environment/__tests__/resize-dispose.test.d.ts +0 -2
  619. package/dist/environment/__tests__/resize-dispose.test.d.ts.map +0 -1
  620. package/dist/environment/__tests__/signature-red.test.d.ts +0 -2
  621. package/dist/environment/__tests__/signature-red.test.d.ts.map +0 -1
  622. package/dist/environment/__tests__/signature.test.d.ts +0 -2
  623. package/dist/environment/__tests__/signature.test.d.ts.map +0 -1
  624. package/dist/environment/descriptors.d.ts +0 -2
  625. package/dist/environment/descriptors.d.ts.map +0 -1
  626. package/dist/environment/extracted-environment.d.ts +0 -53
  627. package/dist/environment/extracted-environment.d.ts.map +0 -1
  628. package/dist/environment/generation.d.ts +0 -62
  629. package/dist/environment/generation.d.ts.map +0 -1
  630. package/dist/environment/gpu-bundle.d.ts +0 -23
  631. package/dist/environment/gpu-bundle.d.ts.map +0 -1
  632. package/dist/environment/graph.d.ts +0 -108
  633. package/dist/environment/graph.d.ts.map +0 -1
  634. package/dist/environment/inspection.d.ts +0 -48
  635. package/dist/environment/inspection.d.ts.map +0 -1
  636. package/dist/environment/lifecycle.d.ts +0 -22
  637. package/dist/environment/lifecycle.d.ts.map +0 -1
  638. package/dist/environment/readiness.d.ts +0 -29
  639. package/dist/environment/readiness.d.ts.map +0 -1
  640. package/dist/environment/signature.d.ts +0 -70
  641. package/dist/environment/signature.d.ts.map +0 -1
  642. package/dist/extract/__tests__/directional-csm-domain.unit.test.d.ts +0 -2
  643. package/dist/extract/__tests__/directional-csm-domain.unit.test.d.ts.map +0 -1
  644. package/dist/extract/__tests__/environment-source.test.d.ts +0 -2
  645. package/dist/extract/__tests__/environment-source.test.d.ts.map +0 -1
  646. package/dist/extract/__tests__/schema-readers.unit.test.d.ts +0 -2
  647. package/dist/extract/__tests__/schema-readers.unit.test.d.ts.map +0 -1
  648. package/dist/extract/directional-csm.d.ts +0 -129
  649. package/dist/extract/directional-csm.d.ts.map +0 -1
  650. package/dist/extract/index.d.ts +0 -5
  651. package/dist/extract/index.d.ts.map +0 -1
  652. package/dist/extract/material-interface.d.ts +0 -56
  653. package/dist/extract/material-interface.d.ts.map +0 -1
  654. package/dist/extract/schema-readers.d.ts +0 -20
  655. package/dist/extract/schema-readers.d.ts.map +0 -1
  656. package/dist/features/graph-contribution.d.ts +0 -64
  657. package/dist/features/graph-contribution.d.ts.map +0 -1
  658. package/dist/features/index.d.ts +0 -21
  659. package/dist/features/index.d.ts.map +0 -1
  660. package/dist/features/morph/index.d.ts +0 -3
  661. package/dist/features/morph/index.d.ts.map +0 -1
  662. package/dist/features/morph/morph-bounds.d.ts +0 -42
  663. package/dist/features/morph/morph-bounds.d.ts.map +0 -1
  664. package/dist/features/scene-temporal.d.ts +0 -45
  665. package/dist/features/scene-temporal.d.ts.map +0 -1
  666. package/dist/features/taa-resolve.d.ts +0 -21
  667. package/dist/features/taa-resolve.d.ts.map +0 -1
  668. package/dist/frame-chain.d.ts +0 -14
  669. package/dist/frame-chain.d.ts.map +0 -1
  670. package/dist/gpu-driven/view-reference.d.ts.map +0 -1
  671. package/dist/gpu-resource-store.d.ts.map +0 -1
  672. package/dist/hdrp-cluster-membership.d.ts +0 -2
  673. package/dist/hdrp-cluster-membership.d.ts.map +0 -1
  674. package/dist/hdrp-pipeline.d.ts +0 -36
  675. package/dist/hdrp-pipeline.d.ts.map +0 -1
  676. package/dist/ibl/cubemap-projection.d.ts +0 -23
  677. package/dist/ibl/cubemap-projection.d.ts.map +0 -1
  678. package/dist/ibl/face-uniforms.d.ts +0 -65
  679. package/dist/ibl/face-uniforms.d.ts.map +0 -1
  680. package/dist/mesh-update-errors.d.ts +0 -71
  681. package/dist/mesh-update-errors.d.ts.map +0 -1
  682. package/dist/mipmap-generator.d.ts +0 -39
  683. package/dist/mipmap-generator.d.ts.map +0 -1
  684. package/dist/param-schema-projection-census.d.ts +0 -18
  685. package/dist/param-schema-projection-census.d.ts.map +0 -1
  686. package/dist/persistent-render-scene.d.ts +0 -158
  687. package/dist/persistent-render-scene.d.ts.map +0 -1
  688. package/dist/pipeline/index.d.ts +0 -11
  689. package/dist/pipeline/index.d.ts.map +0 -1
  690. package/dist/pipeline-errors.d.ts +0 -110
  691. package/dist/pipeline-errors.d.ts.map +0 -1
  692. package/dist/prepare/__tests__/schema-readers.unit.test.d.ts +0 -2
  693. package/dist/prepare/__tests__/schema-readers.unit.test.d.ts.map +0 -1
  694. package/dist/prepare/index.d.ts +0 -4
  695. package/dist/prepare/index.d.ts.map +0 -1
  696. package/dist/prepare/schema-readers.d.ts +0 -11
  697. package/dist/prepare/schema-readers.d.ts.map +0 -1
  698. package/dist/record/__tests__/environment-record.test.d.ts +0 -2
  699. package/dist/record/__tests__/environment-record.test.d.ts.map +0 -1
  700. package/dist/record/__tests__/frame-targets.unit.test.d.ts +0 -2
  701. package/dist/record/__tests__/frame-targets.unit.test.d.ts.map +0 -1
  702. package/dist/record/__tests__/membership-timing.unit.test.d.ts +0 -2
  703. package/dist/record/__tests__/membership-timing.unit.test.d.ts.map +0 -1
  704. package/dist/record/__tests__/render-submission.integration.test.d.ts +0 -2
  705. package/dist/record/__tests__/render-submission.integration.test.d.ts.map +0 -1
  706. package/dist/record/__tests__/render-submission.perf.test.d.ts +0 -2
  707. package/dist/record/__tests__/render-submission.perf.test.d.ts.map +0 -1
  708. package/dist/record/__tests__/shadow-submit-mode.unit.test.d.ts +0 -2
  709. package/dist/record/__tests__/shadow-submit-mode.unit.test.d.ts.map +0 -1
  710. package/dist/record/__tests__/view-ubo-layout.unit.test.d.ts +0 -2
  711. package/dist/record/__tests__/view-ubo-layout.unit.test.d.ts.map +0 -1
  712. package/dist/record/frame-observation.d.ts +0 -38
  713. package/dist/record/frame-observation.d.ts.map +0 -1
  714. package/dist/record/index.d.ts +0 -15
  715. package/dist/record/index.d.ts.map +0 -1
  716. package/dist/record/main-pass-skin.d.ts +0 -46
  717. package/dist/record/main-pass-skin.d.ts.map +0 -1
  718. package/dist/record/main-pass-sprite.d.ts +0 -69
  719. package/dist/record/main-pass-sprite.d.ts.map +0 -1
  720. package/dist/record/material-payload.d.ts +0 -43
  721. package/dist/record/material-payload.d.ts.map +0 -1
  722. package/dist/record/material-slot-plan.d.ts +0 -26
  723. package/dist/record/material-slot-plan.d.ts.map +0 -1
  724. package/dist/record/membership-timing.d.ts +0 -232
  725. package/dist/record/membership-timing.d.ts.map +0 -1
  726. package/dist/record/shadow-caster-uniform.d.ts +0 -8
  727. package/dist/record/shadow-caster-uniform.d.ts.map +0 -1
  728. package/dist/record/shadow-submit-mode.d.ts +0 -66
  729. package/dist/record/shadow-submit-mode.d.ts.map +0 -1
  730. package/dist/render-dispatch-membership.d.ts +0 -47
  731. package/dist/render-dispatch-membership.d.ts.map +0 -1
  732. package/dist/render-pipeline-context.d.ts +0 -289
  733. package/dist/render-pipeline-context.d.ts.map +0 -1
  734. package/dist/render-pipeline-target.d.ts +0 -16
  735. package/dist/render-pipeline-target.d.ts.map +0 -1
  736. package/dist/render-scene-projection.d.ts +0 -174
  737. package/dist/render-scene-projection.d.ts.map +0 -1
  738. package/dist/render-system-fold.d.ts +0 -266
  739. package/dist/render-system-fold.d.ts.map +0 -1
  740. package/dist/renderer/asset-service.d.ts +0 -10
  741. package/dist/renderer/asset-service.d.ts.map +0 -1
  742. package/dist/renderer/backend-selection.d.ts.map +0 -1
  743. package/dist/renderer/environment-classify.d.ts +0 -6
  744. package/dist/renderer/environment-classify.d.ts.map +0 -1
  745. package/dist/renderer/environment-error.d.ts +0 -13
  746. package/dist/renderer/environment-error.d.ts.map +0 -1
  747. package/dist/renderer/material/pipeline-projection.d.ts +0 -91
  748. package/dist/renderer/material/pipeline-projection.d.ts.map +0 -1
  749. package/dist/renderer/renderer-factory.d.ts +0 -283
  750. package/dist/renderer/renderer-factory.d.ts.map +0 -1
  751. package/dist/renderer.d.ts +0 -771
  752. package/dist/renderer.d.ts.map +0 -1
  753. package/dist/scene-utils/collect-subtree.d.ts +0 -11
  754. package/dist/scene-utils/collect-subtree.d.ts.map +0 -1
  755. package/dist/ssao-data.d.ts +0 -34
  756. package/dist/ssao-data.d.ts.map +0 -1
  757. package/dist/surface-format.d.ts +0 -10
  758. package/dist/surface-format.d.ts.map +0 -1
  759. package/dist/taa-history-store.d.ts +0 -88
  760. package/dist/taa-history-store.d.ts.map +0 -1
  761. package/dist/temporal-coverage.d.ts +0 -35
  762. package/dist/temporal-coverage.d.ts.map +0 -1
  763. package/dist/temporal-frame-transaction.d.ts +0 -92
  764. package/dist/temporal-frame-transaction.d.ts.map +0 -1
  765. package/dist/temporal-inspection.d.ts +0 -57
  766. package/dist/temporal-inspection.d.ts.map +0 -1
  767. package/dist/temporal-view.d.ts +0 -43
  768. package/dist/temporal-view.d.ts.map +0 -1
  769. package/dist/tilemap/resolve-tileset-runtime.d.ts +0 -23
  770. package/dist/tilemap/resolve-tileset-runtime.d.ts.map +0 -1
  771. package/dist/urp-pipeline.d.ts +0 -4
  772. package/dist/urp-pipeline.d.ts.map +0 -1
  773. package/src/__tests__/analytic-sky-contract.test.ts +0 -27
  774. package/src/__tests__/analytic-sky-falsify-carriers.mjs +0 -43
  775. package/src/__tests__/analytic-sky-falsify.test.ts +0 -94
  776. package/src/__tests__/assets-runtime-handoff.integration.test.ts +0 -36
  777. package/src/__tests__/backend-selection.integration.test.ts +0 -11
  778. package/src/__tests__/camera-temporal.test-d.ts +0 -8
  779. package/src/__tests__/camera-temporal.test.ts +0 -188
  780. package/src/__tests__/directional-shadow-probe-atlas-layout.unit.test.ts +0 -18
  781. package/src/__tests__/environment-inspection.test.ts +0 -45
  782. package/src/__tests__/fog-ai-user.fixture.ts +0 -350
  783. package/src/__tests__/fog-custom-render-feature.fixture.ts +0 -33
  784. package/src/__tests__/fog-custom-render-feature.integration.test.ts +0 -76
  785. package/src/__tests__/fog-inspection.integration.test.ts +0 -127
  786. package/src/__tests__/fog-owner-state.integration.test.ts +0 -112
  787. package/src/__tests__/fog-pipeline-topology.integration.test.ts +0 -93
  788. package/src/__tests__/fog-public-surface.integration.test.ts +0 -60
  789. package/src/__tests__/fog-ray-contract.integration.test.ts +0 -73
  790. package/src/__tests__/fog-source-absence.integration.test.ts +0 -51
  791. package/src/__tests__/fog-temporal.integration.test.ts +0 -115
  792. package/src/__tests__/frame-chain.unit.test.ts +0 -26
  793. package/src/__tests__/gpu-scene-field-type-owner.test-d.ts +0 -27
  794. package/src/__tests__/hdrp-pipeline.unit.test.ts +0 -100
  795. package/src/__tests__/ibl/ibl-fallback.unit.test.ts +0 -23
  796. package/src/__tests__/material-derived-error-stop-draw.integration.test.ts +0 -69
  797. package/src/__tests__/material-derived-payload.integration.test.ts +0 -164
  798. package/src/__tests__/materials.unit.test.ts +0 -25
  799. package/src/__tests__/param-schema-projection-census.unit.test.ts +0 -40
  800. package/src/__tests__/persistent-render-scene.unit.test.ts +0 -1311
  801. package/src/__tests__/pipeline-error-policy-owner.unit.test.ts +0 -167
  802. package/src/__tests__/pipeline-pass-trace.test.ts +0 -92
  803. package/src/__tests__/pipeline-stage-owner.test-d.ts +0 -13
  804. package/src/__tests__/plugin.test.ts +0 -25
  805. package/src/__tests__/prepared-graphics-backend-matrix.unit.test.ts +0 -129
  806. package/src/__tests__/prepared-graphics-resolver-recording.unit.test.ts +0 -180
  807. package/src/__tests__/public-pipeline-id.test-d.ts +0 -6
  808. package/src/__tests__/render-dispatch-membership.unit.test.ts +0 -117
  809. package/src/__tests__/render-feature-construction.unit.test.ts +0 -124
  810. package/src/__tests__/render-feature-error-code-owner.test-d.ts +0 -27
  811. package/src/__tests__/render-feature-gpu-buffer-usage-owner.test-d.ts +0 -46
  812. package/src/__tests__/render-feature-graph.integration.test.ts +0 -205
  813. package/src/__tests__/render-feature-graphics-staging.unit.test.ts +0 -200
  814. package/src/__tests__/render-feature-order.unit.test.ts +0 -66
  815. package/src/__tests__/render-feature-prepared-graphics-recording.unit.test.ts +0 -107
  816. package/src/__tests__/render-feature-staging.unit.test.ts +0 -94
  817. package/src/__tests__/renderer-render-scene-public.test-d.ts +0 -27
  818. package/src/__tests__/scene-temporal-coverage.unit.test.ts +0 -259
  819. package/src/__tests__/sun-snapshot-consumers.test.ts +0 -35
  820. package/src/__tests__/surface-backend-kind-owner.test-d.ts +0 -42
  821. package/src/__tests__/taa-history-store.unit.test.ts +0 -196
  822. package/src/__tests__/temporal-frame-transaction.integration.test.ts +0 -537
  823. package/src/__tests__/temporal-inspection.unit.test.ts +0 -138
  824. package/src/assets/__tests__/asset-decoders.unit.test.ts +0 -92
  825. package/src/assets/__tests__/mipmap-generator.unit.test.ts +0 -52
  826. package/src/assets/__tests__/render-asset-port.unit.test.ts +0 -54
  827. package/src/assets/__tests__/resolve-render-asset.unit.test.ts +0 -47
  828. package/src/components/__tests__/atmosphere-red.test.ts +0 -51
  829. package/src/components/__tests__/atmosphere.test.ts +0 -79
  830. package/src/components/__tests__/fog.test-d.ts +0 -49
  831. package/src/components/__tests__/fog.test.ts +0 -60
  832. package/src/components/atmosphere.ts +0 -64
  833. package/src/deferred-lighting.ts +0 -92
  834. package/src/dynamic-texture-store.ts +0 -111
  835. package/src/environment/README.md +0 -76
  836. package/src/environment/__tests__/failure-injection.test.ts +0 -50
  837. package/src/environment/__tests__/generation-red.test.ts +0 -64
  838. package/src/environment/__tests__/generation.test.ts +0 -37
  839. package/src/environment/__tests__/graph-transaction.test.ts +0 -85
  840. package/src/environment/__tests__/inspection-red.test.ts +0 -53
  841. package/src/environment/__tests__/lifecycle-evidence.test.ts +0 -40
  842. package/src/environment/__tests__/pipeline-topology.test.ts +0 -33
  843. package/src/environment/__tests__/readiness.test.ts +0 -42
  844. package/src/environment/__tests__/recovery.test.ts +0 -62
  845. package/src/environment/__tests__/resize-dispose.test.ts +0 -30
  846. package/src/environment/__tests__/signature-red.test.ts +0 -45
  847. package/src/environment/__tests__/signature.test.ts +0 -60
  848. package/src/environment/descriptors.ts +0 -7
  849. package/src/environment/extracted-environment.ts +0 -239
  850. package/src/environment/generation.ts +0 -158
  851. package/src/environment/gpu-bundle.ts +0 -144
  852. package/src/environment/graph.ts +0 -588
  853. package/src/environment/inspection.ts +0 -107
  854. package/src/environment/lifecycle.ts +0 -124
  855. package/src/environment/readiness.ts +0 -76
  856. package/src/environment/signature.ts +0 -185
  857. package/src/extract/__tests__/directional-csm-domain.unit.test.ts +0 -391
  858. package/src/extract/__tests__/environment-source.test.ts +0 -105
  859. package/src/extract/__tests__/schema-readers.unit.test.ts +0 -16
  860. package/src/extract/directional-csm.ts +0 -959
  861. package/src/extract/index.ts +0 -10
  862. package/src/extract/material-interface.ts +0 -604
  863. package/src/extract/schema-readers.ts +0 -27
  864. package/src/features/graph-contribution.ts +0 -577
  865. package/src/features/index.ts +0 -100
  866. package/src/features/morph/index.ts +0 -24
  867. package/src/features/morph/morph-bounds.ts +0 -123
  868. package/src/features/scene-temporal.ts +0 -274
  869. package/src/features/taa-resolve.ts +0 -244
  870. package/src/frame-chain.ts +0 -21
  871. package/src/hdrp-cluster-membership.ts +0 -70
  872. package/src/ibl/cubemap-projection.ts +0 -60
  873. package/src/ibl/face-uniforms.ts +0 -150
  874. package/src/mesh-update-errors.ts +0 -113
  875. package/src/mipmap-generator.ts +0 -244
  876. package/src/param-schema-projection-census.ts +0 -73
  877. package/src/persistent-render-scene.ts +0 -1752
  878. package/src/pipeline/index.ts +0 -40
  879. package/src/pipeline-errors.ts +0 -172
  880. package/src/prepare/__tests__/schema-readers.unit.test.ts +0 -16
  881. package/src/prepare/index.ts +0 -8
  882. package/src/prepare/schema-readers.ts +0 -20
  883. package/src/record/__tests__/environment-record.test.ts +0 -35
  884. package/src/record/__tests__/frame-targets.unit.test.ts +0 -54
  885. package/src/record/__tests__/membership-timing.unit.test.ts +0 -524
  886. package/src/record/__tests__/render-submission.integration.test.ts +0 -76
  887. package/src/record/__tests__/render-submission.perf.test.ts +0 -141
  888. package/src/record/__tests__/shadow-submit-mode.unit.test.ts +0 -88
  889. package/src/record/__tests__/view-ubo-layout.unit.test.ts +0 -101
  890. package/src/record/frame-observation.ts +0 -122
  891. package/src/record/index.ts +0 -15
  892. package/src/record/main-pass-skin.ts +0 -51
  893. package/src/record/main-pass-sprite.ts +0 -166
  894. package/src/record/material-payload.ts +0 -292
  895. package/src/record/material-slot-plan.ts +0 -68
  896. package/src/record/membership-timing.ts +0 -1012
  897. package/src/record/shadow-caster-uniform.ts +0 -37
  898. package/src/record/shadow-submit-mode.ts +0 -277
  899. package/src/render-dispatch-membership.ts +0 -155
  900. package/src/render-pipeline-context.ts +0 -332
  901. package/src/render-pipeline-target.ts +0 -96
  902. package/src/render-scene-projection.ts +0 -1738
  903. package/src/render-system-fold.ts +0 -531
  904. package/src/renderer/asset-service.ts +0 -32
  905. package/src/renderer/backend-selection.ts +0 -121
  906. package/src/renderer/environment-classify.ts +0 -30
  907. package/src/renderer/environment-error.ts +0 -19
  908. package/src/renderer/material/pipeline-projection.ts +0 -140
  909. package/src/renderer.ts +0 -940
  910. package/src/scene-utils/collect-subtree.ts +0 -40
  911. package/src/ssao-data.ts +0 -106
  912. package/src/surface-format.ts +0 -37
  913. package/src/taa-history-store.ts +0 -429
  914. package/src/temporal-coverage.ts +0 -106
  915. package/src/temporal-frame-transaction.ts +0 -301
  916. package/src/temporal-inspection.ts +0 -194
  917. package/src/temporal-view.ts +0 -174
  918. package/src/tilemap/resolve-tileset-runtime.ts +0 -72
@@ -1,19 +1,13 @@
1
- import type { GraphResourceResolver } from '@forgeax/engine-render-graph';
2
1
  import {
3
2
  type BindGroup,
3
+ type BindGroupEntry,
4
4
  type Buffer,
5
5
  type RenderPipeline,
6
6
  RhiError,
7
+ type RhiQueue,
7
8
  type RhiRenderPassEncoder,
8
- type TextureView,
9
9
  } from '@forgeax/engine-rhi';
10
10
  import type { PassSelector } from '@forgeax/engine-types';
11
- import {
12
- PointShadowAtlasBoundsViolationError,
13
- PointShadowAtlasUninitializedError,
14
- } from '../errors/render';
15
- import type { DirectionalCsmCascadePlan } from '../extract/directional-csm';
16
- import type { MultiViewProductionSubmission } from '../gpu-driven/production-raster';
17
11
  import { GpuBuffer } from '../gpu-resource';
18
12
  import {
19
13
  GPU_BUFFER_USAGE_COPY_DST,
@@ -21,28 +15,57 @@ import {
21
15
  GPU_BUFFER_USAGE_UNIFORM,
22
16
  } from '../gpu-usage';
23
17
  import { assembleMaterialWithSkylightEntries } from '../ibl/skylight-bind-group';
24
- import {
25
- type InstanceBufferCacheEntry,
26
- packTemporalInstanceTransforms,
27
- temporalInstanceUploadByteLength,
28
- } from '../instance-buffer-cache';
29
- import { buildBeginRenderPassDescriptor } from '../pipeline-spec';
30
- import type { RenderPipelineGpuDrivenShadowProjection } from '../render-pipeline';
31
- import type { _InternalRenderPipelineContext } from '../render-pipeline-context';
32
- import { MATERIAL_PER_ENTITY_STRIDE } from '../render-system';
33
- import type { DispatchEntry, SpotLightSnapshot } from '../render-system-extract';
18
+ import type { InstanceBufferCacheEntry } from '../instance-buffer-cache';
19
+ import { buildPbrMaterialUserRegionEntries } from '../pbr-pipeline';
20
+ import type { DispatchEntry, ExtractedLights } from '../render-system-extract';
34
21
  import { matchPass } from '../systems/pass-selector';
35
- import type { ValidatedRenderable } from './frame-snapshot';
36
22
  import { worldEntityKey } from './frame-snapshot';
37
23
  import {
38
24
  getOrCreateFromChain,
39
25
  getOrCreatePerEntity,
40
26
  MAX_UNIFORM_INSTANCES,
41
27
  MESH_PER_ENTITY_STRIDE,
28
+ packInstanceStorageBuffer,
42
29
  } from './mesh-ssbo';
43
- import { directionalShadowCasterOffset, spotShadowCasterOffset } from './shadow-caster-uniform';
30
+ import type { _InternalRenderPipelineContext } from './render-context';
31
+ import { STANDARD_PBR_UBO_SIZE } from './render-context';
44
32
  import { pointShadowViewOffset, VIEW_UNIFORM_BYTES } from './view-ubo';
45
33
 
34
+ export const SHADOW_CASTER_SLOT_STRIDE = 256;
35
+ export const SHADOW_CASTER_BUFFER_SIZE = SHADOW_CASTER_SLOT_STRIDE * 8;
36
+
37
+ export function directionalShadowCasterOffset(cascadeIndex: number): number {
38
+ return SHADOW_CASTER_SLOT_STRIDE * cascadeIndex;
39
+ }
40
+
41
+ export function spotShadowCasterOffset(tile: number): number {
42
+ return SHADOW_CASTER_SLOT_STRIDE * (4 + tile);
43
+ }
44
+
45
+ export function writeShadowCasterUniforms(
46
+ queue: RhiQueue,
47
+ buffer: Buffer,
48
+ lights: ExtractedLights,
49
+ ): void {
50
+ for (let cascade = 0; cascade < 4; cascade += 1) {
51
+ const written = queue.writeBuffer(
52
+ buffer,
53
+ directionalShadowCasterOffset(cascade),
54
+ new Uint32Array([cascade, 0, 0, 0]),
55
+ );
56
+ if (!written.ok) throw written.error;
57
+ }
58
+ for (const snapshot of lights.spot) {
59
+ const tile = snapshot.shadowAtlasTile;
60
+ if (tile < 0 || tile >= 4 || snapshot.lightViewProj === undefined) continue;
61
+ const offset = spotShadowCasterOffset(tile);
62
+ const header = queue.writeBuffer(buffer, offset, new Uint32Array([0, 1, 0, 0]));
63
+ if (!header.ok) throw header.error;
64
+ const matrix = queue.writeBuffer(buffer, offset + 16, snapshot.lightViewProj);
65
+ if (!matrix.ok) throw matrix.error;
66
+ }
67
+ }
68
+
46
69
  function ensureTypedShadowViewBg(
47
70
  c: _InternalRenderPipelineContext,
48
71
  viewOffset: number,
@@ -50,6 +73,8 @@ function ensureTypedShadowViewBg(
50
73
  variant: string,
51
74
  ): BindGroup | null {
52
75
  const { runtime, frameState, pipelineState } = c;
76
+ const shadowSampler = pipelineState.perPassResources.shadowSampler;
77
+ if (shadowSampler === null) return null;
53
78
  try {
54
79
  return getOrCreateFromChain(
55
80
  frameState.viewBindGroupCache,
@@ -58,7 +83,7 @@ function ensureTypedShadowViewBg(
58
83
  pipelineState.pointLightsBuffer,
59
84
  pipelineState.spotLightsBuffer,
60
85
  pipelineState.shadowFallbackTextureView,
61
- pipelineState.perPassResources.shadowSampler,
86
+ shadowSampler,
62
87
  pipelineState.shadowAtlasFallbackTextureView,
63
88
  pipelineState.shadowParamsBuffer,
64
89
  pipelineState.shadowCasterCascadeBuffer,
@@ -95,7 +120,7 @@ function ensureTypedShadowViewBg(
95
120
  },
96
121
  {
97
122
  binding: 4,
98
- resource: { kind: 'sampler', value: pipelineState.perPassResources.shadowSampler },
123
+ resource: { kind: 'sampler', value: shadowSampler },
99
124
  },
100
125
  {
101
126
  binding: 5,
@@ -139,12 +164,9 @@ function ensureTypedShadowViewBg(
139
164
  }
140
165
  }
141
166
 
142
- function shadowShaderMap(
143
- c: _InternalRenderPipelineContext,
144
- dispatch: readonly DispatchEntry[] = c.shadowDispatch,
145
- ): ReadonlyMap<number, string> {
167
+ function shadowShaderMap(c: _InternalRenderPipelineContext): ReadonlyMap<number, string> {
146
168
  const shaders = new Map<number, string>();
147
- for (const entry of dispatch) {
169
+ for (const entry of c.dispatch) {
148
170
  if (entry.tags.LightMode === 'ShadowCaster' && entry.materialShaderId !== undefined) {
149
171
  shaders.set(entry.renderableIndex, entry.materialShaderId);
150
172
  }
@@ -152,355 +174,6 @@ function shadowShaderMap(
152
174
  return shaders;
153
175
  }
154
176
 
155
- function multiViewSubmission(
156
- c: _InternalRenderPipelineContext,
157
- kind: 'main' | 'cascade',
158
- cascadeIndex?: number,
159
- ): MultiViewProductionSubmission | undefined {
160
- return c.multiViewSubmissions.find(
161
- (submission) =>
162
- submission.kind === kind && (kind === 'main' || submission.cascadeIndex === cascadeIndex),
163
- );
164
- }
165
-
166
- /** One-way adapter from the batch-aligned production plan to direct RHI draws. */
167
- function submissionCandidateIndices(
168
- submission: MultiViewProductionSubmission | undefined,
169
- ): ReadonlySet<number> | undefined {
170
- if (submission === undefined) return undefined;
171
- // A truncated compact list is never a safe membership owner. Returning
172
- // undefined deliberately selects the existing complete pass-selector
173
- // domain, which is a conservative direct CPU fallback and cannot silently
174
- // omit a caster. The overflow bit remains available to diagnostics.
175
- if (submission.overflow) return undefined;
176
- return submission.candidateIndices;
177
- }
178
-
179
- function directionalCascadeCacheHit(
180
- c: _InternalRenderPipelineContext,
181
- cascadeIndex: number,
182
- ): boolean {
183
- return ((c.directionalShadowCacheHitMask ?? 0) & (1 << cascadeIndex)) !== 0;
184
- }
185
-
186
- function setOptionalScissorRect(
187
- pass: RhiRenderPassEncoder,
188
- x: number,
189
- y: number,
190
- width: number,
191
- height: number,
192
- ): void {
193
- // The production WebGPU encoder implements scissor clipping, while the
194
- // lightweight test/fallback encoders intentionally expose only the common
195
- // raster subset. Keep the atlas tile contract when the capability exists;
196
- // an absent optional method must not turn a valid depth pass into a graph
197
- // encode failure.
198
- const setScissorRect = (
199
- pass as unknown as {
200
- readonly setScissorRect?: (x: number, y: number, width: number, height: number) => void;
201
- }
202
- ).setScissorRect;
203
- setScissorRect?.call(pass, x, y, width, height);
204
- }
205
-
206
- function clearDirectionalCascadeTile(
207
- c: _InternalRenderPipelineContext,
208
- pass: RhiRenderPassEncoder,
209
- viewport: { readonly x: number; readonly y: number; readonly w: number; readonly h: number },
210
- ): boolean {
211
- if ((c.directionalShadowCacheHitMask ?? 0) === 0) return true;
212
- const pipeline = c.runtime.getDirectionalShadowTileClearPipeline?.() ?? null;
213
- if (pipeline === null) return false;
214
- pass.setViewport(viewport.x, viewport.y, viewport.w, viewport.h, 0, 1);
215
- setOptionalScissorRect(pass, viewport.x, viewport.y, viewport.w, viewport.h);
216
- pass.setPipeline(pipeline);
217
- pass.draw(3);
218
- return true;
219
- }
220
-
221
- /** Point/spot compatibility recording consumes the shared main-view result. */
222
- function mainShadowMembership(c: _InternalRenderPipelineContext): ReadonlySet<number> | undefined {
223
- return submissionCandidateIndices(multiViewSubmission(c, 'main'));
224
- }
225
-
226
- function isMainShadowRenderable(
227
- entry: ValidatedRenderable,
228
- membership: ReadonlySet<number> | undefined,
229
- ): boolean {
230
- if (membership === undefined) return true;
231
- const candidateIndex = entry.source.candidateIndex ?? entry.renderableIndex;
232
- return membership.has(candidateIndex);
233
- }
234
-
235
- interface ShadowCascadeObservation {
236
- readonly frame: number;
237
- readonly cascade: number;
238
- readonly viewport: {
239
- readonly x: number;
240
- readonly y: number;
241
- readonly w: number;
242
- readonly h: number;
243
- };
244
- readonly plan: DirectionalCsmCascadePlan;
245
- readonly submission: MultiViewProductionSubmission | undefined;
246
- readonly stableIdByCandidateIndex: ReadonlyMap<number, number>;
247
- readonly cacheToken: string | undefined;
248
- readonly cacheHit: boolean;
249
- readonly budget: {
250
- readonly limit: number;
251
- emitted: number;
252
- dropped: number;
253
- };
254
- }
255
-
256
- const SHADOW_CANDIDATE_OBSERVATION_BUDGET = 64;
257
-
258
- interface ProjectedCasterRect {
259
- readonly x: number;
260
- readonly y: number;
261
- readonly w: number;
262
- readonly h: number;
263
- }
264
-
265
- function projectLightSpaceCasterRect(
266
- plan: DirectionalCsmCascadePlan,
267
- viewport: ShadowCascadeObservation['viewport'],
268
- lightSpaceBounds: ArrayLike<number> | undefined,
269
- ): ProjectedCasterRect | undefined {
270
- if (lightSpaceBounds === undefined || lightSpaceBounds.length < 4) return undefined;
271
- const clipMinX = plan.clipLightBounds[0] ?? Number.NaN;
272
- const clipMaxX = plan.clipLightBounds[1] ?? Number.NaN;
273
- const clipMinY = plan.clipLightBounds[2] ?? Number.NaN;
274
- const clipMaxY = plan.clipLightBounds[3] ?? Number.NaN;
275
- const casterMinX = lightSpaceBounds[0] ?? Number.NaN;
276
- const casterMaxX = lightSpaceBounds[1] ?? Number.NaN;
277
- const casterMinY = lightSpaceBounds[2] ?? Number.NaN;
278
- const casterMaxY = lightSpaceBounds[3] ?? Number.NaN;
279
- if (
280
- !Number.isFinite(clipMinX) ||
281
- !Number.isFinite(clipMaxX) ||
282
- !Number.isFinite(clipMinY) ||
283
- !Number.isFinite(clipMaxY) ||
284
- !Number.isFinite(casterMinX) ||
285
- !Number.isFinite(casterMaxX) ||
286
- !Number.isFinite(casterMinY) ||
287
- !Number.isFinite(casterMaxY) ||
288
- !(clipMaxX > clipMinX) ||
289
- !(clipMaxY > clipMinY)
290
- ) {
291
- return undefined;
292
- }
293
- const toPixelX = (value: number) =>
294
- viewport.x + ((value - clipMinX) / (clipMaxX - clipMinX)) * viewport.w;
295
- // Light-space Y is projected with the WebGPU clip-space Y flip used by the
296
- // orthographic matrix; convert it to the top-left texture origin here.
297
- const toPixelY = (value: number) =>
298
- viewport.y + ((clipMaxY - value) / (clipMaxY - clipMinY)) * viewport.h;
299
- const x0 = toPixelX(casterMinX);
300
- const x1 = toPixelX(casterMaxX);
301
- const y0 = toPixelY(casterMinY);
302
- const y1 = toPixelY(casterMaxY);
303
- return {
304
- x: Math.min(x0, x1),
305
- y: Math.min(y0, y1),
306
- w: Math.abs(x1 - x0),
307
- h: Math.abs(y1 - y0),
308
- };
309
- }
310
-
311
- function shadowMarker(payload: Record<string, unknown>): string {
312
- return `shadowCascade:${JSON.stringify(payload)}`;
313
- }
314
-
315
- function spotShadowMarker(payload: Record<string, unknown>): string {
316
- return `shadowSpot:${JSON.stringify(payload)}`;
317
- }
318
-
319
- function emitSpotShadowPassBeginMarker(
320
- c: _InternalRenderPipelineContext,
321
- pass: RhiRenderPassEncoder,
322
- snapshot: SpotLightSnapshot,
323
- spotIndex: number,
324
- spotCount: number,
325
- ): void {
326
- if (c.shadowDebugObservation !== true) return;
327
- const payload = {
328
- kind: 'spot',
329
- stage: 'pass-begin',
330
- frame: c.frameState.frameNumber,
331
- spotIndex,
332
- spotCount,
333
- lightIdentity: {
334
- sourceEntity: snapshot.entity,
335
- shadowCasterOrdinal: spotIndex,
336
- },
337
- tile: {
338
- index: snapshot.shadowAtlasTile,
339
- leaseGeneration: 'unowned',
340
- atlasEpoch: 'unowned',
341
- },
342
- cache: {
343
- mode: 'forced-redraw',
344
- hit: false,
345
- dirtyReason: 'no-spot-cache-owner',
346
- },
347
- projection: {
348
- mapSize: snapshot.mapSize,
349
- nearPlane: snapshot.nearPlane,
350
- farPlane: snapshot.farPlane,
351
- },
352
- };
353
- pass.pushDebugGroup(spotShadowMarker({ ...payload, stage: 'pass-group' }));
354
- pass.insertDebugMarker(spotShadowMarker(payload));
355
- }
356
-
357
- function emitSpotShadowPassEndMarker(
358
- c: _InternalRenderPipelineContext,
359
- pass: RhiRenderPassEncoder,
360
- snapshot: SpotLightSnapshot,
361
- ): void {
362
- if (c.shadowDebugObservation !== true) return;
363
- pass.insertDebugMarker(
364
- spotShadowMarker({
365
- kind: 'spot',
366
- stage: 'pass-end',
367
- frame: c.frameState.frameNumber,
368
- sourceEntity: snapshot.entity,
369
- tile: snapshot.shadowAtlasTile,
370
- rendered: true,
371
- }),
372
- );
373
- pass.popDebugGroup();
374
- }
375
-
376
- function emitBudgetedShadowMarker(
377
- pass: RhiRenderPassEncoder,
378
- observation: ShadowCascadeObservation,
379
- payload: Record<string, unknown>,
380
- ): void {
381
- if (observation.budget.emitted >= observation.budget.limit) {
382
- observation.budget.dropped += 1;
383
- return;
384
- }
385
- observation.budget.emitted += 1;
386
- pass.insertDebugMarker(shadowMarker(payload));
387
- }
388
-
389
- function shadowCascadeObservation(
390
- c: _InternalRenderPipelineContext,
391
- cascadeIndex: number,
392
- viewport: ShadowCascadeObservation['viewport'],
393
- ): ShadowCascadeObservation | undefined {
394
- if (c.shadowDebugObservation !== true) return undefined;
395
- const plan = c.directionalCsmPlan?.cascades[cascadeIndex];
396
- if (plan === undefined) return undefined;
397
- const submission = multiViewSubmission(c, 'cascade', cascadeIndex);
398
- return {
399
- frame: c.frameState.frameNumber,
400
- cascade: cascadeIndex,
401
- viewport,
402
- plan,
403
- submission,
404
- stableIdByCandidateIndex: new Map(
405
- [...(submission?.candidateIndexByStableId.entries() ?? [])].map(
406
- ([stableId, candidateIndex]) => [candidateIndex, stableId] as const,
407
- ),
408
- ),
409
- cacheToken: c.directionalShadowCacheTokens?.[cascadeIndex],
410
- cacheHit: ((c.directionalShadowCacheHitMask ?? 0) & (1 << cascadeIndex)) !== 0,
411
- budget: {
412
- limit: SHADOW_CANDIDATE_OBSERVATION_BUDGET,
413
- emitted: 0,
414
- dropped: 0,
415
- },
416
- };
417
- }
418
-
419
- function emitShadowCascadePassMarker(
420
- pass: RhiRenderPassEncoder,
421
- observation: ShadowCascadeObservation,
422
- ): void {
423
- const plan = observation.plan;
424
- pass.pushDebugGroup(
425
- shadowMarker({
426
- stage: 'pass-group',
427
- frame: observation.frame,
428
- cascade: observation.cascade,
429
- }),
430
- );
431
- pass.insertDebugMarker(
432
- shadowMarker({
433
- kind: 'cascade',
434
- stage: 'pass-begin',
435
- frame: observation.frame,
436
- cascade: observation.cascade,
437
- viewport: observation.viewport,
438
- tile: observation.viewport,
439
- cache: {
440
- token: observation.cacheToken,
441
- hit: observation.cacheHit,
442
- },
443
- submission:
444
- observation.submission === undefined
445
- ? { source: 'direct-call-adapter' }
446
- : {
447
- source: observation.submission.source,
448
- viewId: observation.submission.viewId,
449
- topologyRevision: observation.submission.plan.revision,
450
- batchCount: observation.submission.plan.batches.length,
451
- candidateCount: observation.submission.plan.candidateCount,
452
- volumeRevision: observation.submission.volumeRevision,
453
- spatialIndexRevision: observation.submission.spatialIndexRevision,
454
- overflow: observation.submission.overflow,
455
- faults: observation.submission.faults,
456
- },
457
- plan: {
458
- receiverDepth: Array.from(plan.receiverViewDepth),
459
- unsnappedCenter: Array.from(plan.unsnappedCenter),
460
- snappedCenter: Array.from(plan.snappedCenter),
461
- stableExtent: plan.stableExtent,
462
- texel: plan.worldUnitsPerTexel,
463
- clipXYZ: Array.from(plan.clipLightBounds),
464
- lightViewProj: Array.from(plan.lightViewProj),
465
- fallbackCount: plan.unboundedFallbackCount,
466
- },
467
- }),
468
- );
469
- // A cascade-local token hit is already a complete invalidation fact. Keep
470
- // the bounded pass summary, but do not rebuild candidate JSON for a result
471
- // the observer has already seen.
472
- }
473
-
474
- function emitShadowCascadeEndMarker(
475
- pass: RhiRenderPassEncoder,
476
- observation: ShadowCascadeObservation,
477
- ): void {
478
- pass.insertDebugMarker(
479
- shadowMarker({
480
- kind: 'observation-summary',
481
- stage: 'pass-end',
482
- frame: observation.frame,
483
- cascade: observation.cascade,
484
- emittedCandidateMarkers: observation.budget.emitted,
485
- droppedCandidateMarkers: observation.budget.dropped,
486
- ...(observation.budget.dropped === 0
487
- ? {}
488
- : { faultCode: 'semantic-observation-budget-exceeded' }),
489
- }),
490
- );
491
- pass.insertDebugMarker(
492
- shadowMarker({
493
- kind: 'cascade',
494
- stage: 'pass-end',
495
- frame: observation.frame,
496
- cascade: observation.cascade,
497
- viewport: observation.viewport,
498
- tile: observation.viewport,
499
- }),
500
- );
501
- pass.popDebugGroup();
502
- }
503
-
504
177
  function shadowPipeline(c: _InternalRenderPipelineContext): RenderPipeline | null {
505
178
  return (
506
179
  c.runtime.getMaterialShaderPipeline?.(
@@ -520,19 +193,8 @@ export function encodeDirectionalShadowPass(
520
193
  pass: RhiRenderPassEncoder,
521
194
  cascadeIndex: number,
522
195
  viewport: { readonly x: number; readonly y: number; readonly w: number; readonly h: number },
523
- gpuDriven?: {
524
- readonly projection: RenderPipelineGpuDrivenShadowProjection;
525
- readonly resources: GraphResourceResolver;
526
- },
527
196
  ): void {
528
197
  if (c.directionalShadowCacheReuse || c.meshBindGroup === null) return;
529
- const observation = shadowCascadeObservation(c, cascadeIndex, viewport);
530
- if (observation !== undefined) emitShadowCascadePassMarker(pass, observation);
531
- if (directionalCascadeCacheHit(c, cascadeIndex)) {
532
- if (observation !== undefined) emitShadowCascadeEndMarker(pass, observation);
533
- return;
534
- }
535
- if (!clearDirectionalCascadeTile(c, pass, viewport)) return;
536
198
  const pipeline = shadowPipeline(c);
537
199
  const viewBg = ensureTypedShadowViewBg(
538
200
  c,
@@ -544,40 +206,17 @@ export function encodeDirectionalShadowPass(
544
206
  if (pipeline === null || viewBg === null || materialBg === null) return;
545
207
  c.frameState.directionalShadowCacheRecorded = true;
546
208
  pass.setViewport(viewport.x, viewport.y, viewport.w, viewport.h, 0, 1);
547
- setOptionalScissorRect(pass, viewport.x, viewport.y, viewport.w, viewport.h);
548
209
  pass.setPipeline(pipeline);
549
210
  pass.setBindGroup(0, viewBg);
550
211
  pass.setBindGroup(1, materialBg, [0]);
551
- if (gpuDriven !== undefined) {
552
- c.frameState.directionalShadowCacheRecorded = true;
553
- gpuDriven.projection.encode(pass, gpuDriven.resources);
554
- if (observation !== undefined) {
555
- pass.insertDebugMarker(
556
- shadowMarker({
557
- kind: 'batch',
558
- stage: 'gpu-indirect-submission',
559
- source: 'multi-view-indirect',
560
- frame: observation.frame,
561
- cascade: observation.cascade,
562
- batchCount: gpuDriven.projection.batchCount ?? 0,
563
- candidateCount: observation.submission?.plan.candidateCount ?? 0,
564
- }),
565
- );
566
- emitShadowCascadeEndMarker(pass, observation);
567
- }
568
- return;
569
- }
570
212
  recordShadowCasterDraws(
571
213
  c,
572
214
  pass,
573
215
  pipeline,
574
216
  c.meshBindGroup,
575
- buildMatchedRenderableIndices(c.shadowDispatch, { LightMode: ['ShadowCaster'] }),
217
+ buildMatchedRenderableIndices(c.dispatch, { LightMode: ['ShadowCaster'] }),
576
218
  shadowShaderMap(c),
577
- multiViewSubmission(c, 'cascade', cascadeIndex),
578
- observation?.cacheHit === true ? undefined : observation,
579
219
  );
580
- if (observation !== undefined) emitShadowCascadeEndMarker(pass, observation);
581
220
  }
582
221
 
583
222
  export function encodePointShadowPass(
@@ -606,7 +245,7 @@ export function encodePointShadowPass(
606
245
  pipeline,
607
246
  c.meshBindGroup,
608
247
  buildMatchedRenderableIndices(c.dispatch, { LightMode: ['ShadowCaster'] }),
609
- shadowShaderMap(c, c.dispatch),
248
+ shadowShaderMap(c),
610
249
  );
611
250
  }
612
251
 
@@ -648,21 +287,17 @@ export function encodeSpotShadowPass(
648
287
  pass.setPipeline(pipeline);
649
288
  pass.setBindGroup(0, viewBg);
650
289
  pass.setBindGroup(1, materialBg, [0]);
651
- // Keep the typed graph's spot producer on the same caster owner as the
652
- // directional/point paths. The old compact loop only consumed
653
- // `instancesBgPerEntity` entries created by a directional shadow pass, so a
654
- // spot-only world opened a valid atlas pass but emitted zero caster draws.
655
- // The shared recorder builds the per-entity instance binding on demand and
656
- // preserves pass-selector, custom ShadowCaster, and multi-view membership
657
- // contracts without adding a pass or resource.
290
+ // Reuse the shared caster recorder. The compact spot-only loop used to
291
+ // depend on instance bindings created by a directional pass, so a scene
292
+ // containing only a SpotLight opened the atlas pass but emitted no caster
293
+ // draws.
658
294
  recordShadowCasterDraws(
659
295
  c,
660
296
  pass,
661
297
  pipeline,
662
298
  c.meshBindGroup,
663
- buildMatchedRenderableIndices(c.shadowDispatch, { LightMode: ['ShadowCaster'] }),
299
+ buildMatchedRenderableIndices(c.dispatch, { LightMode: ['ShadowCaster'] }),
664
300
  shadowShaderMap(c),
665
- multiViewSubmission(c, 'main'),
666
301
  );
667
302
  }
668
303
 
@@ -721,421 +356,35 @@ export function buildMatchedRenderableIndices(
721
356
  }
722
357
 
723
358
  /**
724
- * feat-20260529-rendergraph-pass-abstraction M4 / w13b: shadow depth pass
725
- * recording, extracted verbatim from recordFrame. Renders shadow casters
726
- * into the shadow depth RT using an INDEPENDENT command encoder + its own
727
- * queue.submit (RD-4: this independent-encoder boundary is the runtime-side
728
- * manual barrier that synchronizes the depth-texture write with the
729
- * subsequent sample in the main pass). Driven by the render-graph 'shadow'
730
- * pass execute closure.
359
+ * Build the material handles whose dispatch entries match a graph pass.
360
+ *
361
+ * A renderable can own more than one material pass, so renderable-level
362
+ * filtering is insufficient for geometry recording: a Deferred graph pass
363
+ * must not draw the same renderable's Forward-only material. Keep the
364
+ * renderable key in the result so mixed-material meshes retain their
365
+ * per-submesh routing.
731
366
  */
732
- export function recordShadowPass(
733
- c: _InternalRenderPipelineContext,
734
- selector?: PassSelector,
735
- viewport?: { readonly x: number; readonly y: number; readonly w: number; readonly h: number },
736
- cascadeIndex: number = 0,
737
- ): void {
738
- const { runtime, pipelineState, validatedOrdered, meshBindGroup, shadowDispatch, frameState } = c;
739
- if (c.directionalShadowCacheReuse || directionalCascadeCacheHit(c, cascadeIndex)) return;
740
- // feat-20260613-csm-cascaded-shadow-maps M5 / w28: write the per-pass
741
- // cascade index to the shared shadowCasterCascadeBuffer. The shadow
742
- // pass below uses an INDEPENDENT command encoder + own queue.submit, so
743
- // queue.writeBuffer here lands serially against this pass's submit
744
- // even when N cascades are recorded back-to-back -- each pass's submit
745
- // sees its own index.
746
- const cascadeIdxPayload = new Uint32Array([cascadeIndex >>> 0, 0, 0, 0]);
747
- const cascadeWriteResult = runtime.device.queue.writeBuffer(
748
- pipelineState.shadowCasterCascadeBuffer,
749
- 0,
750
- cascadeIdxPayload,
751
- );
752
- if (!cascadeWriteResult.ok) throw cascadeWriteResult.error;
753
- // w10 shadow depth pass: uses a separate command encoder so Dawn/WebGPU
754
- // can synchronize the depth texture write (RenderAttachment) with the
755
- // subsequent read (TextureBinding in the geometry pass). Sharing an
756
- // encoder triggers "usage includes writable usage and another usage in
757
- // the same synchronization scope" validation error.
758
- // feat-20260609 M4 / T-010: shadow PSO via frameState.pipelineCache lookup
759
- // (same path as forward passes — charter P4 consistent abstraction).
760
- // getMaterialShaderPipeline lazily builds + caches PSO keyed on
761
- // (shaderId, isHdr, renderState, topology, indexFormat, variantSet, passKind).
762
- const shadowPipeline =
763
- runtime.getMaterialShaderPipeline?.(
764
- 'forgeax::default-shadow-caster',
765
- false, // isHdr — shadow depth pass is always LDR
766
- undefined, // renderState — vertex-only shader, no render state
767
- 'triangle-list', // topology — shadow PSO targets triangle-list
768
- undefined, // indexFormat — triangle-list ignores strip index width
769
- undefined, // variantSet — shadow_caster.wgsl has no group(2) bindings
770
- 'shadow-caster', // passKind — distinguishes from forward PSO
771
- ) ?? null;
772
- // M5-T1: shadow depth target read directly from render-graph
773
- // (`addColorTarget('shadowDepth', ...)` declared in `urp-pipeline.ts`;
774
- // D-2 SSOT). Returns undefined when the graph has not allocated the
775
- // target (castShadow:false or shadowMapSize=0); the
776
- // gate below (`shadowView !== null`) is preserved by coalescing
777
- // undefined to null.
778
- const shadowView = frameState.currentDirectionalShadowView;
779
- // feat-20260609 M2: filter entities by pass selector.
780
- const matchedIndices =
781
- selector !== undefined ? buildMatchedRenderableIndices(shadowDispatch, selector) : null;
782
-
783
- // bug-20260619-csm RC-3 (AC-10, D-3): map each renderable to its
784
- // ShadowCaster pass shader so the depth pass selects the per-entity PSO
785
- // (mirrors the forward pass's per-entity PSO selection — charter P4).
786
- // A material with a custom ShadowCaster shader (e.g. an alpha-test cutout
787
- // that calls `discard`) gets its own fragment-carrying PSO; default
788
- // casters resolve to `forgeax::default-shadow-caster` (vertex-only), so
789
- // there is no regression for the built-in materials. Built from the
790
- // dispatch entries tagged `LightMode: 'ShadowCaster'` (extract already
791
- // populates `materialShaderId` per pass).
792
- const shadowShaderByRenderableIdx = new Map<number, string>();
793
- for (const de of shadowDispatch) {
794
- if (de.tags.LightMode === 'ShadowCaster' && de.materialShaderId !== undefined) {
795
- shadowShaderByRenderableIdx.set(de.renderableIndex, de.materialShaderId);
796
- }
797
- }
798
-
799
- if (shadowPipeline !== null && shadowView !== null && validatedOrdered.length > 0) {
800
- frameState.directionalShadowCacheRecorded = true;
801
- // feat-20260529-rendergraph-pass-abstraction M4 / w14 (RD-4 verification
802
- // point): this INDEPENDENT 'render-system-shadow' command encoder + its
803
- // own queue.submit below is the runtime-side manual barrier that splits
804
- // the shadowDepth write (here) from the main pass sample. The render-
805
- // graph mirrors the same shadow -> main hazard as an explicit barrier on
806
- // wgpu-native (barrier-backend-kind.test.ts w14); on webgpu / wgpu-webgl2
807
- // the encoder boundary alone provides synchronization. main / tonemap /
808
- // FXAA stay on the shared frame encoder (c.encoder), submitted once.
809
- const shadowEncResult = runtime.device.createCommandEncoder({
810
- label: 'render-system-shadow',
811
- });
812
- if (shadowEncResult.ok) {
813
- const shadowEnc = shadowEncResult.value;
814
-
815
- // M2 / w8: shadow view (#3) cache lookup with 'view-shadow'
816
- // variant discriminator (AC-06: distinct key from 'view-main').
817
- // b3 is always shadowFallbackTextureView (not the actual shadow
818
- // map — WebGPU forbids writing to and sampling from the same
819
- // texture in the same synchronization scope). Handles are all
820
- // init-time stable, so the WeakMap chain hits from frame 2 onward.
821
- const shadowViewBg = getOrCreateFromChain(
822
- c.frameState.viewBindGroupCache,
823
- [
824
- pipelineState.viewUniformBuffer,
825
- pipelineState.pointLightsBuffer,
826
- pipelineState.spotLightsBuffer,
827
- pipelineState.shadowFallbackTextureView,
828
- pipelineState.perPassResources.shadowSampler,
829
- pipelineState.shadowAtlasFallbackTextureView,
830
- pipelineState.shadowParamsBuffer,
831
- pipelineState.shadowFallbackTextureView,
832
- ],
833
- 'view-shadow',
834
- () => {
835
- const shadowViewBgResult = runtime.device.createBindGroup({
836
- label: 'shadow-view-bg',
837
- layout: pipelineState.viewBindGroupLayout,
838
- entries: [
839
- {
840
- binding: 0,
841
- resource: {
842
- kind: 'buffer',
843
- value: { buffer: pipelineState.viewUniformBuffer },
844
- },
845
- },
846
- {
847
- binding: 1,
848
- resource: {
849
- kind: 'buffer',
850
- value: { buffer: pipelineState.pointLightsBuffer },
851
- },
852
- },
853
- {
854
- binding: 2,
855
- resource: {
856
- kind: 'buffer',
857
- value: { buffer: pipelineState.spotLightsBuffer },
858
- },
859
- },
860
- {
861
- binding: 3,
862
- resource: { kind: 'textureView', value: pipelineState.shadowFallbackTextureView },
863
- },
864
- {
865
- binding: 4,
866
- resource: { kind: 'sampler', value: pipelineState.perPassResources.shadowSampler },
867
- },
868
- // feat-20260612-point-light-shadows-urp-hdrp Round-2 F-1:
869
- // shadowViewBg uses the cube_array fallback at binding 5
870
- // (NOT the real ShadowAtlas atlas view) because the directional
871
- // shadow caster is reading depth from b3 -- but mixing the
872
- // real atlas view here would put the cube_array under both a
873
- // sample and a write attachment hazard during the SAME frame
874
- // (point shadow caster pass writes the atlas; here we only
875
- // need a valid bind to satisfy the BGL shape, never sample it
876
- // in shadow_caster.wgsl).
877
- {
878
- binding: 5,
879
- resource: {
880
- kind: 'textureView',
881
- value: pipelineState.shadowAtlasFallbackTextureView,
882
- },
883
- },
884
- {
885
- binding: 6,
886
- resource: {
887
- kind: 'buffer',
888
- value: { buffer: pipelineState.shadowParamsBuffer },
889
- },
890
- },
891
- // feat-20260613-csm-cascaded-shadow-maps M5 / w28 (rebased to
892
- // binding 7 on 2026-06-13): per-pass cascade-index uniform
893
- // consumed by shadow_caster.vs_main.
894
- {
895
- binding: 7,
896
- resource: {
897
- kind: 'buffer',
898
- value: { buffer: pipelineState.shadowCasterCascadeBuffer },
899
- },
900
- },
901
- // feat-20260625-spot-light-shadow-mapping M3 / w21 (D-5): spot
902
- // shadow 2D atlas. The shadow-view BG always binds the 1x1 depth
903
- // fallback (NOT the real spotShadowDepth view) — the spot caster
904
- // pass write-attaches that atlas, so sampling it here would create
905
- // a same-frame write+sample hazard; shadow_caster.wgsl never reads
906
- // binding 8 anyway, this entry only satisfies the BGL shape.
907
- {
908
- binding: 8,
909
- resource: {
910
- kind: 'textureView',
911
- value: pipelineState.shadowFallbackTextureView,
912
- },
913
- },
914
- // feat-20260625-spot-light-shadow-mapping w25: spot lightViewProj
915
- // matrices folded into the View UBO (binding 0) — no binding 9.
916
- // binding 8 is the last shared view-BG entry.
917
- ],
918
- });
919
- if (!shadowViewBgResult.ok) throw shadowViewBgResult.error;
920
- return shadowViewBgResult.value;
921
- },
922
- c.bindGroupCounts,
923
- );
924
-
925
- // Dummy material bind group for @group(1) — not consumed by the
926
- // shadow-caster shader but must match the pipeline's
927
- // materialBindGroupLayout (20 entries: the derived standard-PBR user
928
- // region 0..12 followed by Skylight 13..19).
929
- //
930
- // D-6 / AC-05: all handles are init-time stable pipelineState defaults
931
- // + skylightFallback resources, so this BG is a true singleton (no
932
- // entityKey). It lives in its own flat singletonMaterialCache
933
- // Map<variant, BindGroup> under 'shadow-material-singleton' — hit from
934
- // frame 2 onward, and cleanPerEntityCache never touches it (it is not
935
- // in any per-entity Map).
936
- const shadowMaterialBaseEntries = [
937
- {
938
- binding: 0,
939
- resource: {
940
- kind: 'buffer' as const,
941
- value: {
942
- buffer: pipelineState.materialUniformBuffer.buffer,
943
- offset: 0,
944
- size: MATERIAL_PER_ENTITY_STRIDE,
945
- },
946
- },
947
- },
948
- {
949
- binding: 1,
950
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
951
- },
952
- {
953
- binding: 2,
954
- resource: {
955
- kind: 'textureView' as const,
956
- value: pipelineState.defaultWhiteTextureView,
957
- },
958
- },
959
- {
960
- binding: 3,
961
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
962
- },
963
- {
964
- binding: 4,
965
- resource: {
966
- kind: 'textureView' as const,
967
- value: pipelineState.defaultWhiteTextureView,
968
- },
969
- },
970
- {
971
- binding: 5,
972
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
973
- },
974
- {
975
- binding: 6,
976
- resource: {
977
- kind: 'textureView' as const,
978
- value: pipelineState.defaultNormalTextureView,
979
- },
980
- },
981
- {
982
- binding: 7,
983
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
984
- },
985
- {
986
- binding: 8,
987
- resource: {
988
- kind: 'textureView' as const,
989
- value: pipelineState.defaultWhiteTextureView,
990
- },
991
- },
992
- {
993
- binding: 9,
994
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
995
- },
996
- {
997
- binding: 10,
998
- resource: {
999
- kind: 'textureView' as const,
1000
- value: pipelineState.defaultWhiteTextureView,
1001
- },
1002
- },
1003
- {
1004
- binding: 11,
1005
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1006
- },
1007
- {
1008
- binding: 12,
1009
- resource: {
1010
- kind: 'textureView' as const,
1011
- value: pipelineState.defaultWhiteTextureView,
1012
- },
1013
- },
1014
- ];
1015
- const shadowSkyFb = pipelineState.skylightFallback;
1016
- const shadowMergedEntries =
1017
- shadowSkyFb !== null
1018
- ? assembleMaterialWithSkylightEntries(shadowMaterialBaseEntries, {
1019
- irradianceView: shadowSkyFb.irradianceView,
1020
- irradianceSampler: shadowSkyFb.sampler,
1021
- prefilterView: shadowSkyFb.prefilterView,
1022
- prefilterSampler: shadowSkyFb.sampler,
1023
- brdfLutView: shadowSkyFb.brdfLutView,
1024
- brdfLutSampler: shadowSkyFb.sampler,
1025
- intensityBuffer: shadowSkyFb.intensityBuffer,
1026
- })
1027
- : shadowMaterialBaseEntries;
1028
- // D-6 / AC-05: the one true singleton material BG lives in its own flat
1029
- // Map<variant, BindGroup> (no entityKey, no handle chain). Cache hit
1030
- // from frame 2 onward; the cleanPerEntityCache eviction never touches it.
1031
- let shadowMaterialBg = c.frameState.singletonMaterialCache.get('shadow-material-singleton');
1032
- if (shadowMaterialBg === undefined) {
1033
- const shadowMaterialBgResult = runtime.device.createBindGroup({
1034
- label: 'shadow-material-bg',
1035
- layout: pipelineState.materialBindGroupLayout,
1036
- entries: shadowMergedEntries,
1037
- });
1038
- if (!shadowMaterialBgResult.ok) throw shadowMaterialBgResult.error;
1039
- shadowMaterialBg = shadowMaterialBgResult.value;
1040
- c.bindGroupCounts.createBindGroup += 1;
1041
- c.bindGroupCounts.keys.push('shadow-material-singleton');
1042
- c.frameState.singletonMaterialCache.set('shadow-material-singleton', shadowMaterialBg);
1043
- }
1044
-
1045
- // feat-20260604-instances-per-instance-transform-shader-group3-bin M2 / w12 (D-1 (C)):
1046
- // shadow pass per-instance channel alignment — replaces the identity singleton
1047
- // @group(3) binding with per-entity instance buffer + drawIndexed(instanceCount).
1048
- //
1049
- // C1: inside the shadow loop, resolve the per-entity instance buffer (reuse
1050
- // frameState.instanceBuffers cache, or build+upload fresh). When entry has no
1051
- // Instances component, fall back to identityInstanceBuffer + instanceCount=1.
1052
- // C2: shadowPass.drawIndexed(indexCount, instanceCount, 0, 0, 0) with real
1053
- // inst.instanceCount (not hardcoded 1).
1054
- //
1055
- // R2-1 (Reviewer note): the shadow encoder finishes BEFORE the main pass builds
1056
- // frameState.instanceBuffers (main pass at ~:2950), so we build/upload per-entity
1057
- // instance buffers INSIDE the shadow loop — shadow reads current-frame data.
1058
-
1059
- const shadowPass: RhiRenderPassEncoder = shadowEnc.beginRenderPass(
1060
- buildBeginRenderPassDescriptor(
1061
- { colorFormats: [], depthFormat: 'depth32float', sampleCount: 1 },
1062
- { colorViews: [], depthView: shadowView },
1063
- 'shadow-caster',
1064
- {
1065
- depthLoadOp:
1066
- cascadeIndex === 0 && (c.directionalShadowCacheHitMask ?? 0) === 0 ? 'clear' : 'load',
1067
- },
1068
- ) as never,
1069
- );
1070
-
1071
- shadowPass.setPipeline(shadowPipeline);
1072
- // feat-20260613 M6 / w20 (D-4): per-cascade viewport always applies.
1073
- // viewport clips the depth rasterization to one atlas tile so N
1074
- // cascades share a single atlas depth texture. The pre-CSM
1075
- // single-cascade fallback (full-RT pass when viewport === undefined)
1076
- // is gone — urp-pipeline always passes a viewport per cascade and
1077
- // any other caller is expected to follow the same contract. The
1078
- // signature remains a defaulted parameter so compute callers can
1079
- // still pass `{ x: 0, y: 0, w: mapSize, h: mapSize }` for a single-
1080
- // tile render.
1081
- const tileViewport: NonNullable<typeof viewport> = viewport ?? {
1082
- x: 0,
1083
- y: 0,
1084
- w: pipelineState.perPassResources.shadowMapSize,
1085
- h: pipelineState.perPassResources.shadowMapSize,
1086
- };
1087
- if (!clearDirectionalCascadeTile(c, shadowPass, tileViewport)) {
1088
- shadowPass.end();
1089
- return;
1090
- }
1091
- shadowPass.setViewport(tileViewport.x, tileViewport.y, tileViewport.w, tileViewport.h, 0, 1);
1092
- setOptionalScissorRect(
1093
- shadowPass,
1094
- tileViewport.x,
1095
- tileViewport.y,
1096
- tileViewport.w,
1097
- tileViewport.h,
1098
- );
1099
- shadowPass.setBindGroup(0, shadowViewBg);
1100
- shadowPass.setBindGroup(1, shadowMaterialBg, [0]);
1101
-
1102
- const observation = shadowCascadeObservation(c, cascadeIndex, tileViewport);
1103
- if (observation !== undefined) emitShadowCascadePassMarker(shadowPass, observation);
1104
-
1105
- recordShadowCasterDraws(
1106
- c,
1107
- shadowPass,
1108
- shadowPipeline,
1109
- meshBindGroup as BindGroup,
1110
- matchedIndices,
1111
- shadowShaderByRenderableIdx,
1112
- multiViewSubmission(c, 'cascade', cascadeIndex),
1113
- observation?.cacheHit === true ? undefined : observation,
1114
- );
1115
-
1116
- if (observation !== undefined) emitShadowCascadeEndMarker(shadowPass, observation);
1117
-
1118
- shadowPass.end();
1119
-
1120
- const shadowFinishResult = shadowEnc.finish();
1121
- if (shadowFinishResult.ok) {
1122
- if (frameState.shadowSubmitModeState.mode === 'coalesced-with-frame') {
1123
- frameState.pendingShadowCommandBuffers.push(shadowFinishResult.value);
1124
- } else {
1125
- runtime.device.queue.submit([shadowFinishResult.value]);
1126
- }
1127
- } else {
1128
- runtime.errorRegistry.fire(shadowFinishResult.error);
1129
- }
367
+ export function buildMatchedMaterialHandlesByRenderable(
368
+ dispatch: readonly DispatchEntry[],
369
+ selector: PassSelector,
370
+ ): ReadonlyMap<number, ReadonlySet<number>> | null {
371
+ if (dispatch.length === 0) return null;
372
+ const matched = filterDispatchBySelector(dispatch, selector);
373
+ const handlesByRenderable = new Map<number, Set<number>>();
374
+ for (const entry of matched) {
375
+ const handles = handlesByRenderable.get(entry.renderableIndex);
376
+ if (handles === undefined) {
377
+ handlesByRenderable.set(entry.renderableIndex, new Set([entry.materialHandle]));
1130
378
  } else {
1131
- runtime.errorRegistry.fire(shadowEncResult.error);
379
+ handles.add(entry.materialHandle);
1132
380
  }
1133
381
  }
382
+ return handlesByRenderable;
1134
383
  }
1135
384
 
1136
385
  /**
1137
386
  * feat-20260704 M3/w20: per-entity directional shadow-caster draw loop,
1138
- * extracted verbatim from {@link recordShadowPass}. Walks `c.validatedOrdered`,
387
+ * extracted verbatim from {@link encodeDirectionalShadowPass}. Walks `c.validatedOrdered`,
1139
388
  * selects the per-entity shadow PSO (default vertex-only caster or a custom
1140
389
  * cutout caster), binds the per-entity mesh dynamic-offset + instance buffer,
1141
390
  * and issues the per-submesh depth draws. `shadowPass` view/material bind
@@ -1152,8 +401,6 @@ function recordShadowCasterDraws(
1152
401
  shadowMeshBindGroup: BindGroup,
1153
402
  matchedIndices: Set<number> | null,
1154
403
  shadowShaderByRenderableIdx: ReadonlyMap<number, string>,
1155
- productionSubmission?: MultiViewProductionSubmission,
1156
- observation?: ShadowCascadeObservation,
1157
404
  ): void {
1158
405
  const { runtime, pipelineState, validatedOrdered } = c;
1159
406
  // M-3 / w12: vertexBuffer/indexBuffer state locals migrate to GpuBuffer
@@ -1168,111 +415,13 @@ function recordShadowCasterDraws(
1168
415
  // bound by the setPipeline call above; the loop switches to a custom
1169
416
  // ShadowCaster PSO when a material supplies one.
1170
417
  let shadowLastPipeline: RenderPipeline = shadowPipeline;
1171
- const seenValidatedCandidateIndices = observation === undefined ? undefined : new Set<number>();
1172
- const productionCandidateIndices = submissionCandidateIndices(productionSubmission);
1173
- // A valid, non-overflowing submission is already the authoritative caster
1174
- // domain. Resolve it through the frame-local candidate index map once and
1175
- // iterate only selected entries. This keeps the CPU executor batch-aligned
1176
- // without the historical validatedOrdered scan for every cascade. Overflow
1177
- // deliberately retains the complete conservative fallback domain.
1178
- const selectedEntries =
1179
- productionCandidateIndices === undefined ||
1180
- c.validatedByCandidateIndex === undefined ||
1181
- c.validatedIndexByCandidateIndex === undefined
1182
- ? undefined
1183
- : [...productionCandidateIndices].flatMap((candidateIndex) => {
1184
- const entry = c.validatedByCandidateIndex?.get(candidateIndex);
1185
- return entry === undefined ? [] : [entry];
1186
- });
1187
- const entries = selectedEntries ?? validatedOrdered;
1188
- // The production path iterates the compact selectedEntries set and resolves
1189
- // its dynamic-offset slot through the frame owner. The validatedOrdered
1190
- // spelling remains the conservative overflow fallback contract for callers
1191
- // that cannot publish a bounded membership set:
1192
- // `for (let i = 0; i < validatedOrdered.length; i++)`.
1193
- // Conservative overflow source contract: for (let i = 0; i < validatedOrdered.length; i++) {
1194
- // shadowPass.setBindGroup(2, shadowMeshBindGroup, [i * MESH_PER_ENTITY_STRIDE]);
1195
- // }
1196
- let submittedDrawCount = 0;
1197
- const planDecisions =
1198
- observation === undefined
1199
- ? undefined
1200
- : new Map(
1201
- observation.plan.candidateDecisions?.map((decision) => [
1202
- decision.renderableIndex,
1203
- decision,
1204
- ]),
1205
- );
1206
418
 
1207
- for (let i = 0; i < entries.length; i++) {
1208
- const entry = entries[i];
419
+ for (let i = 0; i < validatedOrdered.length; i++) {
420
+ const entry = validatedOrdered[i];
1209
421
  if (entry === undefined) continue;
1210
422
 
1211
- const candidateIndex = entry.source.candidateIndex ?? entry.renderableIndex;
1212
- seenValidatedCandidateIndices?.add(candidateIndex);
1213
- const planDecision = planDecisions?.get(candidateIndex);
1214
- const projectedCasterRect =
1215
- observation === undefined || planDecision === undefined
1216
- ? undefined
1217
- : projectLightSpaceCasterRect(
1218
- observation.plan,
1219
- observation.viewport,
1220
- planDecision.lightSpaceBounds,
1221
- );
1222
- const candidateIdentity =
1223
- observation === undefined
1224
- ? undefined
1225
- : {
1226
- frame: observation.frame,
1227
- cascade: observation.cascade,
1228
- worldId: entry.source.worldId,
1229
- entityKey: entry.source.entityKey,
1230
- stableId:
1231
- observation.stableIdByCandidateIndex.get(candidateIndex) ??
1232
- worldEntityKey(entry.source.worldId, entry.source.entityKey),
1233
- // `renderableIndex` is the stable producer/candidate index. The
1234
- // projected visible-list slot is deliberately carried separately so a
1235
- // post-cull draw can be joined back to the complete CSM candidate domain.
1236
- renderableIndex: candidateIndex,
1237
- candidateIndex,
1238
- ...(projectedCasterRect === undefined ? {} : { projectedCasterRect }),
1239
- };
1240
-
1241
423
  // feat-20260609 M2: skip entities that don't match the pass selector.
1242
- if (matchedIndices !== null && !matchedIndices.has(entry.renderableIndex)) {
1243
- if (observation !== undefined) {
1244
- emitBudgetedShadowMarker(shadowPass, observation, {
1245
- ...candidateIdentity,
1246
- kind: 'candidate',
1247
- stage: 'cpu-not-selected',
1248
- reason: 'pass-selector-mismatch',
1249
- });
1250
- }
1251
- continue;
1252
- }
1253
- if (productionCandidateIndices !== undefined) {
1254
- if (!productionCandidateIndices.has(candidateIndex)) {
1255
- if (observation !== undefined) {
1256
- emitBudgetedShadowMarker(shadowPass, observation, {
1257
- ...candidateIdentity,
1258
- kind: 'candidate',
1259
- stage: 'cpu-not-selected',
1260
- reason: 'outside-multi-view-submission',
1261
- });
1262
- }
1263
- continue;
1264
- }
1265
- }
1266
- if (observation !== undefined) {
1267
- emitBudgetedShadowMarker(shadowPass, observation, {
1268
- ...candidateIdentity,
1269
- kind: 'candidate',
1270
- stage: 'multi-view-selected',
1271
- source: 'multi-view-indirect',
1272
- selected: true,
1273
- reason: 'batch-aligned-submission',
1274
- });
1275
- }
424
+ if (matchedIndices !== null && !matchedIndices.has(entry.renderableIndex)) continue;
1276
425
 
1277
426
  // bug-20260619-csm RC-3 (AC-10, D-3): resolve the per-entity shadow
1278
427
  // PSO from its ShadowCaster shader id. Default casters keep the
@@ -1319,14 +468,6 @@ function recordShadowCasterDraws(
1319
468
  (sm) => sm.topology === 'triangle-list' || sm.topology === 'triangle-strip',
1320
469
  );
1321
470
  if (!hasAnyShadowSubmesh) {
1322
- if (observation !== undefined) {
1323
- emitBudgetedShadowMarker(shadowPass, observation, {
1324
- ...candidateIdentity,
1325
- kind: 'candidate',
1326
- stage: 'draw-not-submitted',
1327
- reason: 'non-triangle-topology',
1328
- });
1329
- }
1330
471
  continue;
1331
472
  }
1332
473
 
@@ -1342,11 +483,7 @@ function recordShadowCasterDraws(
1342
483
  }
1343
484
  }
1344
485
 
1345
- const validatedIndex =
1346
- selectedEntries === undefined
1347
- ? i
1348
- : (c.validatedIndexByCandidateIndex?.get(candidateIndex) ?? i);
1349
- shadowPass.setBindGroup(2, shadowMeshBindGroup, [validatedIndex * MESH_PER_ENTITY_STRIDE]);
486
+ shadowPass.setBindGroup(2, shadowMeshBindGroup, [i * MESH_PER_ENTITY_STRIDE]);
1350
487
 
1351
488
  // C1 + C2 (w12): per-entity instance buffer + instanceCount
1352
489
  let shadowInstanceBuffer: Buffer = pipelineState.identityInstanceBuffer;
@@ -1365,13 +502,10 @@ function recordShadowCasterDraws(
1365
502
  const bufUsage = uniformFallback
1366
503
  ? GPU_BUFFER_USAGE_UNIFORM | GPU_BUFFER_USAGE_COPY_DST
1367
504
  : GPU_BUFFER_USAGE_STORAGE | GPU_BUFFER_USAGE_COPY_DST;
1368
- const upload = uniformFallback
505
+ const instancePayload = uniformFallback
1369
506
  ? shadowInst.transforms
1370
- : packTemporalInstanceTransforms(
1371
- shadowInst.transforms,
1372
- entry.source.temporal?.previousInstances?.transforms,
1373
- );
1374
- const requestedBytes = upload.byteLength;
507
+ : packInstanceStorageBuffer(shadowInst.transforms);
508
+ const requestedBytes = instancePayload.byteLength;
1375
509
  const cached = c.frameState.instanceBuffers.get(
1376
510
  worldEntityKey(entry.source.worldId, shadowInst.cacheKey),
1377
511
  );
@@ -1410,7 +544,11 @@ function recordShadowCasterDraws(
1410
544
  }
1411
545
  }
1412
546
  if (active !== null) {
1413
- const writeRes = runtime.device.queue.writeBuffer(active.buffer.handle, 0, upload);
547
+ const writeRes = runtime.device.queue.writeBuffer(
548
+ active.buffer.handle,
549
+ 0,
550
+ instancePayload,
551
+ );
1414
552
  if (!writeRes.ok) {
1415
553
  runtime.errorRegistry.fire(writeRes.error);
1416
554
  } else {
@@ -1456,614 +594,24 @@ function recordShadowCasterDraws(
1456
594
  // feat-20260608 M4 / w16: per-submesh shadow draw loop.
1457
595
  // Only draw submeshes whose topology is triangle-list or triangle-strip
1458
596
  // (line-list / point-list submeshes cast no shadow and are skipped).
1459
- for (let submeshIndex = 0; submeshIndex < shadowSubmeshes.length; submeshIndex++) {
1460
- const sm = shadowSubmeshes[submeshIndex];
1461
- if (sm === undefined) continue;
597
+ for (const sm of shadowSubmeshes) {
1462
598
  if (sm.topology !== 'triangle-list' && sm.topology !== 'triangle-strip') {
1463
599
  continue;
1464
600
  }
1465
601
  if (entry.mesh.indexed) {
1466
602
  shadowPass.drawIndexed(sm.indexCount, shadowInstanceCount, sm.indexOffset, 0, 0);
1467
- if (observation !== undefined) submittedDrawCount += 1;
1468
- if (observation !== undefined) {
1469
- emitBudgetedShadowMarker(shadowPass, observation, {
1470
- ...candidateIdentity,
1471
- kind: 'submitted-draw',
1472
- stage: 'submitted-draw',
1473
- source: 'record-after-draw-call',
1474
- submeshIndex,
1475
- drawKind: 'drawIndexed',
1476
- });
1477
- }
1478
603
  } else {
1479
604
  shadowPass.draw(sm.vertexCount, shadowInstanceCount, 0, 0);
1480
- if (observation !== undefined) submittedDrawCount += 1;
1481
- if (observation !== undefined) {
1482
- emitBudgetedShadowMarker(shadowPass, observation, {
1483
- ...candidateIdentity,
1484
- kind: 'submitted-draw',
1485
- stage: 'submitted-draw',
1486
- source: 'record-after-draw-call',
1487
- submeshIndex,
1488
- drawKind: 'draw',
1489
- });
1490
- }
1491
605
  }
1492
606
  }
1493
607
  }
1494
- if (observation !== undefined) {
1495
- shadowPass.insertDebugMarker(
1496
- shadowMarker({
1497
- kind: 'batch',
1498
- stage: 'multi-view-plan-vs-submitted',
1499
- source: 'batch-topology',
1500
- frame: observation.frame,
1501
- cascade: observation.cascade,
1502
- plannedDrawCount: productionSubmission?.plan.candidateCount ?? 0,
1503
- submittedDrawCount,
1504
- batchCount: productionSubmission?.plan.batches.length ?? 0,
1505
- aligned: (productionSubmission?.plan.candidateCount ?? 0) === submittedDrawCount,
1506
- }),
1507
- );
1508
- }
1509
- if (observation !== undefined && productionCandidateIndices !== undefined) {
1510
- for (const candidateIndex of productionCandidateIndices) {
1511
- if (seenValidatedCandidateIndices?.has(candidateIndex)) continue;
1512
- emitBudgetedShadowMarker(shadowPass, observation, {
1513
- kind: 'candidate',
1514
- stage: 'validation-missing',
1515
- source: 'multi-view-indirect',
1516
- frame: observation.frame,
1517
- cascade: observation.cascade,
1518
- stableId: observation.stableIdByCandidateIndex.get(candidateIndex),
1519
- candidateIndex,
1520
- selected: true,
1521
- reason: 'submitted-candidate-not-materialized',
1522
- });
1523
- }
1524
- }
1525
- }
1526
-
1527
- /**
1528
- * feat-20260612-point-light-shadows-urp-hdrp M3 / T-M3-2 (plan-strategy §D-1
1529
- * + §D-3 + AC-04). Records the 6 x N point-shadow caster passes — one render
1530
- * pass per (shadow-casting point light, cube face) pair — that write per-light
1531
- * cube_array atlas depth. Driven by the URP `addPointShadowPass` graph closure;
1532
- * gated upstream on `frameState.pointShadowSnapshots.length > 0` (AC-09 zero-
1533
- * shadow zero-pass).
1534
- *
1535
- * Pass count = 6 * N where N = `frameState.pointShadowSnapshots.length`. Each
1536
- * pass opens an INDEPENDENT command encoder + queue.submit so Dawn / WebGPU
1537
- * synchronizes the depth-write boundary with the subsequent atlas sample in
1538
- * the forward pass (RD-4 manual barrier; same pattern as `recordShadowPass`).
1539
- *
1540
- * Round-2 F-3 fix-up: actual geometry walk + draw landed. Per face we
1541
- * (1) write the face VP mat4 into `viewUniformBuffer` at offset 112 (the
1542
- * `lightSpaceMatrix` slot) — `forgeax::default-shadow-caster` reads
1543
- * `view.lightSpaceMatrix * worldPos` and the encoder boundary serializes
1544
- * the queue.writeBuffer with the subsequent draw, so each face sees its own
1545
- * VP without needing a per-face UBO bind. (2) Reuse the directional shadow
1546
- * caster PSO + cached `shadow-view-bg` / `shadow-material-singleton` /
1547
- * `shadow-mesh-bg` already built by `recordShadowPass`. (3) After all
1548
- * (snapshot, face) passes complete, restore `viewUniformBuffer.lightSpaceMatrix`
1549
- * to the directional value the main forward pass needs (the queue.submit
1550
- * ordering guarantees the restore lands before the main encoder runs).
1551
- *
1552
- * Caveat: the cached `view-shadow` BG binds `shadowAtlasFallbackTextureView`
1553
- * at binding 5 (NOT the real ShadowAtlas atlas view) so the BG is valid even
1554
- * while the real atlas faces are being written through the depth attachment;
1555
- * the shadow_caster.wgsl shader never samples binding 5 anyway (vertex-only
1556
- * pipeline).
1557
- *
1558
- * No new shader / no new PSO / no new BGL is required for this round; the
1559
- * change is purely runtime wiring. A dedicated `forgeax::default-point-
1560
- * shadow-caster` PSO with a per-face VP UBO + dynamic offset would let the
1561
- * pass run without touching `viewUniformBuffer.lightSpaceMatrix` and could
1562
- * be considered for a follow-on optimization milestone (`OOS-future`).
1563
- */
1564
- export function recordPointShadowPass(c: _InternalRenderPipelineContext): void {
1565
- const { runtime, frameState, meshBindGroup, pipelineState } = c;
1566
- const mainMembership = mainShadowMembership(c);
1567
- const snapshots = frameState.pointShadowSnapshots;
1568
- if (snapshots.length === 0) return;
1569
- const atlas = frameState.pointShadowAtlas;
1570
- if (atlas === null || !atlas.isAllocated()) return;
1571
-
1572
- // Reuse the directional shadow caster PSO -- its WGSL reads
1573
- // `view.lightSpaceMatrix * worldPos` which is exactly what we need once we
1574
- // overwrite the slot per face below.
1575
- const shadowPipeline =
1576
- runtime.getMaterialShaderPipeline?.(
1577
- 'forgeax::default-shadow-caster',
1578
- false,
1579
- undefined,
1580
- 'triangle-list',
1581
- undefined,
1582
- undefined,
1583
- 'shadow-caster',
1584
- ) ?? null;
1585
- if (shadowPipeline === null) return;
1586
-
1587
- // Snapshot the directional lightSpaceMatrix so we can restore it after the
1588
- // 6 x N face passes. recordShadowPass already wrote `viewUniformBuffer` at
1589
- // offset 112 above; mirror its source in `pipelineState.perPassResources`
1590
- // (cached by the directional path for Inspector consumption -- charter P4
1591
- // single SSOT). When no directional shadow is active the slot was zeroed
1592
- // by the viewPayload write at recordFrame top; we restore zeros.
1593
- const restoreLightSpaceMatrix = pipelineState.perPassResources.shadowLightSpaceMatrix;
1594
- const RESTORE_LSM_BYTES = 64; // mat4 = 16 floats x 4 B
1595
- const VIEW_UBO_LSM_OFFSET = 112;
1596
-
1597
- for (let i = 0; i < snapshots.length; i++) {
1598
- const snap = snapshots[i];
1599
- if (snap === undefined) continue;
1600
- for (let face = 0; face < 6; face++) {
1601
- // (1) Overwrite viewUniformBuffer.lightSpaceMatrix with this face's VP.
1602
- // shadowMatrices is Float32Array(96) = 6 mat4 in [+X,-X,+Y,-Y,+Z,-Z];
1603
- // pull the 16-float subarray for this face.
1604
- const faceVp = snap.shadowMatrices.subarray(face * 16, (face + 1) * 16);
1605
- const lsmWriteRes = runtime.device.queue.writeBuffer(
1606
- pipelineState.viewUniformBuffer,
1607
- VIEW_UBO_LSM_OFFSET,
1608
- faceVp,
1609
- );
1610
- if (!lsmWriteRes.ok) {
1611
- runtime.errorRegistry.fire(lsmWriteRes.error);
1612
- continue;
1613
- }
1614
-
1615
- const encResult = runtime.device.createCommandEncoder({
1616
- label: `point-shadow-l${snap.shadowAtlasLayer}-f${face}`,
1617
- });
1618
- if (!encResult.ok) {
1619
- runtime.errorRegistry.fire(encResult.error);
1620
- continue;
1621
- }
1622
- const enc = encResult.value;
1623
- let view: TextureView;
1624
- try {
1625
- view = atlas.faceView(snap.shadowAtlasLayer, face);
1626
- } catch (e) {
1627
- if (
1628
- e instanceof PointShadowAtlasUninitializedError ||
1629
- e instanceof PointShadowAtlasBoundsViolationError
1630
- ) {
1631
- runtime.errorRegistry.fire(e);
1632
- } else {
1633
- throw e;
1634
- }
1635
- continue;
1636
- }
1637
- const pass = enc.beginRenderPass(
1638
- buildBeginRenderPassDescriptor(
1639
- { colorFormats: [], depthFormat: 'depth32float', sampleCount: 1 },
1640
- { colorViews: [], depthView: view },
1641
- 'point-shadow-caster',
1642
- ) as never,
1643
- );
1644
-
1645
- // (2) Bind the same shadow PSO + view BG + material BG + mesh BG cached
1646
- // by recordShadowPass earlier in this frame. The shadow path's view BG
1647
- // binds the cube_array fallback at binding 5, so this BG is safe to
1648
- // use while the real atlas faces are render-attached here.
1649
- pass.setPipeline(shadowPipeline);
1650
- // Look up the shadow view BG built earlier this frame by recordShadowPass.
1651
- // `view-shadow` is the cache variant; keyed by the same handle objects.
1652
- // If the directional shadow path wasn't taken (castShadow:false),
1653
- // shadow-view-bg was never built -- skip the geometry walk in that case
1654
- // (the depth attachment was still cleared above which is the AC-04
1655
- // "atlas face cleared to far" minimum guarantee).
1656
- // Build (or reuse) the shadow-view BG. If the directional shadow path
1657
- // already populated it earlier this frame, the cache hits; otherwise
1658
- // (castShadow:false -- recordShadowPass never
1659
- // ran) we build it on-demand here so the point shadow caster has a
1660
- // valid b0 view BG even on directional-shadow-free scenes.
1661
- const cachedShadowViewBg = getOrCreateFromChain(
1662
- frameState.viewBindGroupCache,
1663
- [
1664
- pipelineState.viewUniformBuffer,
1665
- pipelineState.pointLightsBuffer,
1666
- pipelineState.spotLightsBuffer,
1667
- pipelineState.shadowFallbackTextureView,
1668
- pipelineState.perPassResources.shadowSampler,
1669
- pipelineState.shadowAtlasFallbackTextureView,
1670
- pipelineState.shadowParamsBuffer,
1671
- pipelineState.shadowCasterCascadeBuffer,
1672
- pipelineState.shadowFallbackTextureView,
1673
- ],
1674
- 'view-shadow',
1675
- () => {
1676
- const r = runtime.device.createBindGroup({
1677
- label: 'shadow-view-bg',
1678
- layout: pipelineState.viewBindGroupLayout,
1679
- entries: [
1680
- {
1681
- binding: 0,
1682
- resource: { kind: 'buffer', value: { buffer: pipelineState.viewUniformBuffer } },
1683
- },
1684
- {
1685
- binding: 1,
1686
- resource: { kind: 'buffer', value: { buffer: pipelineState.pointLightsBuffer } },
1687
- },
1688
- {
1689
- binding: 2,
1690
- resource: { kind: 'buffer', value: { buffer: pipelineState.spotLightsBuffer } },
1691
- },
1692
- {
1693
- binding: 3,
1694
- resource: { kind: 'textureView', value: pipelineState.shadowFallbackTextureView },
1695
- },
1696
- {
1697
- binding: 4,
1698
- resource: { kind: 'sampler', value: pipelineState.perPassResources.shadowSampler },
1699
- },
1700
- {
1701
- binding: 5,
1702
- resource: {
1703
- kind: 'textureView',
1704
- value: pipelineState.shadowAtlasFallbackTextureView,
1705
- },
1706
- },
1707
- {
1708
- binding: 6,
1709
- resource: { kind: 'buffer', value: { buffer: pipelineState.shadowParamsBuffer } },
1710
- },
1711
- // feat-20260625-spot-light-shadow-mapping M2 / w21 + w25: this
1712
- // on-demand shadow-view BG builder previously stopped at binding 6,
1713
- // predating the cascade UBO (binding 7) and the spot binding 8. It
1714
- // shares the 'view-shadow' cache variant with the directional
1715
- // shadow-pass builder above, so it must produce a BGL-identical bind
1716
- // group; bindings 7/8 are added here in lock-step (BGL declares
1717
- // 0..8 — the former binding 9 spot lightViewProj UBO folded into the
1718
- // View UBO in w25 for the WebGL2 fragment uniform-buffer budget).
1719
- {
1720
- binding: 7,
1721
- resource: {
1722
- kind: 'buffer',
1723
- value: { buffer: pipelineState.shadowCasterCascadeBuffer },
1724
- },
1725
- },
1726
- {
1727
- binding: 8,
1728
- resource: {
1729
- kind: 'textureView',
1730
- value: pipelineState.shadowFallbackTextureView,
1731
- },
1732
- },
1733
- ],
1734
- });
1735
- if (!r.ok) throw r.error;
1736
- return r.value;
1737
- },
1738
- c.bindGroupCounts,
1739
- );
1740
- // Same on-demand build for the dummy material BG (the shadow_caster
1741
- // shader does not consume @group(1) but the PSO requires the BGL
1742
- // to validate). Reuse the same singleton Map entry recordShadowPass
1743
- // writes so the two paths share one allocation per frame (D-6).
1744
- let cachedShadowMaterialBg = frameState.singletonMaterialCache.get(
1745
- 'shadow-material-singleton',
1746
- );
1747
- if (cachedShadowMaterialBg === undefined) {
1748
- const buildShadowMaterialSingleton = (): BindGroup => {
1749
- const fb = pipelineState.skylightFallback;
1750
- const fallbackEntries = [
1751
- {
1752
- binding: 0,
1753
- resource: {
1754
- kind: 'buffer' as const,
1755
- value: {
1756
- buffer: pipelineState.materialUniformBuffer.buffer,
1757
- offset: 0,
1758
- size: MATERIAL_PER_ENTITY_STRIDE,
1759
- },
1760
- },
1761
- },
1762
- {
1763
- binding: 1,
1764
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1765
- },
1766
- {
1767
- binding: 2,
1768
- resource: { kind: 'textureView' as const, value: pipelineState.fallbackTextureView },
1769
- },
1770
- {
1771
- binding: 3,
1772
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1773
- },
1774
- {
1775
- binding: 4,
1776
- resource: {
1777
- kind: 'textureView' as const,
1778
- value: pipelineState.defaultNormalTextureView,
1779
- },
1780
- },
1781
- {
1782
- binding: 5,
1783
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1784
- },
1785
- {
1786
- binding: 6,
1787
- resource: { kind: 'textureView' as const, value: pipelineState.fallbackTextureView },
1788
- },
1789
- {
1790
- binding: 7,
1791
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1792
- },
1793
- {
1794
- binding: 8,
1795
- resource: {
1796
- kind: 'textureView' as const,
1797
- value: pipelineState.defaultWhiteTextureView,
1798
- },
1799
- },
1800
- {
1801
- binding: 9,
1802
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1803
- },
1804
- {
1805
- binding: 10,
1806
- resource: {
1807
- kind: 'textureView' as const,
1808
- value: pipelineState.defaultWhiteTextureView,
1809
- },
1810
- },
1811
- {
1812
- binding: 11,
1813
- resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
1814
- },
1815
- {
1816
- binding: 12,
1817
- resource: {
1818
- kind: 'textureView' as const,
1819
- value: pipelineState.defaultWhiteTextureView,
1820
- },
1821
- },
1822
- ];
1823
- const merged =
1824
- fb !== null
1825
- ? assembleMaterialWithSkylightEntries(fallbackEntries, {
1826
- irradianceView: fb.irradianceView,
1827
- irradianceSampler: fb.sampler,
1828
- prefilterView: fb.prefilterView,
1829
- prefilterSampler: fb.sampler,
1830
- brdfLutView: fb.brdfLutView,
1831
- brdfLutSampler: fb.sampler,
1832
- intensityBuffer: fb.intensityBuffer,
1833
- })
1834
- : fallbackEntries;
1835
- const r = runtime.device.createBindGroup({
1836
- label: 'shadow-material-bg',
1837
- layout: pipelineState.materialBindGroupLayout,
1838
- entries: merged,
1839
- });
1840
- if (!r.ok) throw r.error;
1841
- return r.value;
1842
- };
1843
- cachedShadowMaterialBg = buildShadowMaterialSingleton();
1844
- c.bindGroupCounts.createBindGroup += 1;
1845
- c.bindGroupCounts.keys.push('shadow-material-singleton');
1846
- frameState.singletonMaterialCache.set('shadow-material-singleton', cachedShadowMaterialBg);
1847
- }
1848
- if (meshBindGroup === null) {
1849
- pass.end();
1850
- const finishOnly = enc.finish();
1851
- if (!finishOnly.ok) {
1852
- runtime.errorRegistry.fire(finishOnly.error);
1853
- continue;
1854
- }
1855
- const submitOnly = runtime.device.queue.submit([finishOnly.value]);
1856
- if (!submitOnly.ok) {
1857
- runtime.errorRegistry.fire(submitOnly.error);
1858
- }
1859
- continue;
1860
- }
1861
- pass.setBindGroup(0, cachedShadowViewBg);
1862
- pass.setBindGroup(1, cachedShadowMaterialBg, [0]);
1863
-
1864
- // (3) Iterate the mesh-SSBO slot order and emit one drawIndexed per
1865
- // shadow-casting submesh. Same shape as the directional shadow loop;
1866
- // the per-instance instance buffers built earlier this frame in
1867
- // recordShadowPass are reused (cached on frameState.instanceBuffers).
1868
- let lastVB: GpuBuffer | null = null;
1869
- let lastIB: GpuBuffer | null = null;
1870
- const shadowEntries =
1871
- c.validatedShadowEntries ??
1872
- c.validatedOrdered.flatMap((entry, validatedIndex) =>
1873
- isMainShadowRenderable(entry, mainMembership) ? [{ entry, validatedIndex }] : [],
1874
- );
1875
- for (const { entry, validatedIndex: ei } of shadowEntries) {
1876
- const submeshes = entry.mesh.submeshes;
1877
- const hasTriangle = submeshes.some(
1878
- (sm) => sm.topology === 'triangle-list' || sm.topology === 'triangle-strip',
1879
- );
1880
- if (!hasTriangle) continue;
1881
- if (entry.mesh.vertexBuffer !== lastVB) {
1882
- pass.setVertexBuffer(0, entry.mesh.vertexBuffer.handle);
1883
- lastVB = entry.mesh.vertexBuffer;
1884
- }
1885
- if (entry.mesh.indexed && entry.mesh.indexBuffer !== lastIB && entry.mesh.indexBuffer) {
1886
- pass.setIndexBuffer(entry.mesh.indexBuffer.handle, entry.mesh.indexFormat);
1887
- lastIB = entry.mesh.indexBuffer;
1888
- }
1889
- pass.setBindGroup(2, meshBindGroup, [ei * MESH_PER_ENTITY_STRIDE]);
1890
- // Resolve the per-entity instance BG cached by recordShadowPass.
1891
- const inst = entry.source.instances;
1892
- let instCount = 1;
1893
- let instBufferKey: object = pipelineState.identityInstanceBuffer as unknown as object;
1894
- if (inst !== undefined) {
1895
- const cached = frameState.instanceBuffers.get(
1896
- worldEntityKey(entry.source.worldId, inst.cacheKey),
1897
- );
1898
- if (
1899
- cached !== undefined &&
1900
- cached.uploadedArchVersion === inst.archVersion &&
1901
- cached.uploadedByteLength ===
1902
- temporalInstanceUploadByteLength(inst.transforms, runtime.device.caps.storageBuffer)
1903
- ) {
1904
- instBufferKey = cached.buffer.handle as unknown as object;
1905
- instCount = Math.max(1, inst.instanceCount);
1906
- }
1907
- }
1908
- // D-4 read end: look up the leaf recordShadowPass wrote at :3439
1909
- // with the SAME (entityKey, instBuffer) pair. The single-handle chain
1910
- // stores the variant->BindGroup leaf Map directly under the buffer
1911
- // handle in the inner WeakMap, so the variant lookup is the third
1912
- // step. The inner WeakMap value is opaque (`unknown`); the 1-handle
1913
- // shadow-instances chain guarantees it is the leaf Map here.
1914
- const shadowInstLeaf = frameState.instancesBgPerEntity
1915
- .get(worldEntityKey(entry.source.worldId, entry.source.entityKey))
1916
- ?.get(instBufferKey) as Map<string, BindGroup> | undefined;
1917
- const cachedInstBg = shadowInstLeaf?.get('shadow-instances');
1918
- if (cachedInstBg === undefined) continue; // recordShadowPass should have populated it
1919
- pass.setBindGroup(3, cachedInstBg);
1920
- for (const sm of submeshes) {
1921
- if (sm.topology !== 'triangle-list' && sm.topology !== 'triangle-strip') continue;
1922
- if (entry.mesh.indexed) {
1923
- pass.drawIndexed(sm.indexCount, instCount, sm.indexOffset, 0, 0);
1924
- } else {
1925
- pass.draw(sm.vertexCount, instCount, 0, 0);
1926
- }
1927
- }
1928
- }
1929
-
1930
- pass.end();
1931
- const finishResult = enc.finish();
1932
- if (!finishResult.ok) {
1933
- runtime.errorRegistry.fire(finishResult.error);
1934
- continue;
1935
- }
1936
- const submitResult = runtime.device.queue.submit([finishResult.value]);
1937
- if (!submitResult.ok) {
1938
- runtime.errorRegistry.fire(submitResult.error);
1939
- }
1940
- }
1941
- }
1942
-
1943
- // (4) Restore viewUniformBuffer.lightSpaceMatrix to the directional value
1944
- // (or zero if no directional shadow this frame). The main forward pass
1945
- // builds its own viewBg from the SAME viewUniformBuffer + reads
1946
- // view.lightSpaceMatrix for directional shadow factor reconstruction.
1947
- const restoreBuf = new Float32Array(16);
1948
- if (restoreLightSpaceMatrix !== null) {
1949
- for (let i = 0; i < 16; i++) restoreBuf[i] = restoreLightSpaceMatrix[i] ?? 0;
1950
- }
1951
- // restoreBuf is already exactly 16 floats x 4 B = 64 B; no size override needed.
1952
- void RESTORE_LSM_BYTES;
1953
- const restoreRes = runtime.device.queue.writeBuffer(
1954
- pipelineState.viewUniformBuffer,
1955
- VIEW_UBO_LSM_OFFSET,
1956
- restoreBuf,
1957
- );
1958
- if (!restoreRes.ok) {
1959
- runtime.errorRegistry.fire(restoreRes.error);
1960
- }
1961
- }
1962
-
1963
- /**
1964
- * Build (or reuse) the shared `view-shadow` @group(0) BG for the spot shadow
1965
- * caster pass. Reuses the exact same cache key + entry shape as recordShadowPass
1966
- * / recordPointShadowPass so all three shadow paths share one allocation per
1967
- * frame (D-6). Returns null on a createBindGroup failure (fired to the error
1968
- * registry). The shadow_caster vertex shader reads only binding 0 (view UBO,
1969
- * carrying the spot matrix via shadowCasterCascade at binding 7) — bindings
1970
- * 3/5 bind fallback views since the depth attachment is written here.
1971
- */
1972
- function ensureSpotShadowViewBg(c: _InternalRenderPipelineContext): BindGroup | null {
1973
- const { runtime, frameState, pipelineState } = c;
1974
- try {
1975
- return getOrCreateFromChain(
1976
- frameState.viewBindGroupCache,
1977
- [
1978
- pipelineState.viewUniformBuffer,
1979
- pipelineState.pointLightsBuffer,
1980
- pipelineState.spotLightsBuffer,
1981
- pipelineState.shadowFallbackTextureView,
1982
- pipelineState.perPassResources.shadowSampler,
1983
- pipelineState.shadowAtlasFallbackTextureView,
1984
- pipelineState.shadowParamsBuffer,
1985
- pipelineState.shadowCasterCascadeBuffer,
1986
- pipelineState.shadowFallbackTextureView,
1987
- ],
1988
- 'view-shadow',
1989
- () => {
1990
- const r = runtime.device.createBindGroup({
1991
- label: 'shadow-view-bg',
1992
- layout: pipelineState.viewBindGroupLayout,
1993
- entries: [
1994
- {
1995
- binding: 0,
1996
- resource: { kind: 'buffer', value: { buffer: pipelineState.viewUniformBuffer } },
1997
- },
1998
- {
1999
- binding: 1,
2000
- resource: { kind: 'buffer', value: { buffer: pipelineState.pointLightsBuffer } },
2001
- },
2002
- {
2003
- binding: 2,
2004
- resource: { kind: 'buffer', value: { buffer: pipelineState.spotLightsBuffer } },
2005
- },
2006
- {
2007
- binding: 3,
2008
- resource: { kind: 'textureView', value: pipelineState.shadowFallbackTextureView },
2009
- },
2010
- {
2011
- binding: 4,
2012
- resource: { kind: 'sampler', value: pipelineState.perPassResources.shadowSampler },
2013
- },
2014
- {
2015
- binding: 5,
2016
- resource: {
2017
- kind: 'textureView',
2018
- value: pipelineState.shadowAtlasFallbackTextureView,
2019
- },
2020
- },
2021
- {
2022
- binding: 6,
2023
- resource: { kind: 'buffer', value: { buffer: pipelineState.shadowParamsBuffer } },
2024
- },
2025
- {
2026
- binding: 7,
2027
- resource: {
2028
- kind: 'buffer',
2029
- value: { buffer: pipelineState.shadowCasterCascadeBuffer },
2030
- },
2031
- },
2032
- // feat-20260625-spot-light-shadow-mapping M3 / w21 (D-5): spot
2033
- // shadow 2D atlas. The spot caster pass write-attaches
2034
- // spotShadowDepth, so bind the 1x1 fallback here (the caster shader
2035
- // never samples binding 8 — this entry only satisfies the BGL).
2036
- {
2037
- binding: 8,
2038
- resource: {
2039
- kind: 'textureView',
2040
- value: pipelineState.shadowFallbackTextureView,
2041
- },
2042
- },
2043
- // feat-20260625-spot-light-shadow-mapping w25: spot lightViewProj
2044
- // matrices folded into the View UBO (binding 0) — no binding 9.
2045
- // binding 8 is the last shared view-BG entry.
2046
- ],
2047
- });
2048
- if (!r.ok) throw r.error;
2049
- return r.value;
2050
- },
2051
- c.bindGroupCounts,
2052
- );
2053
- } catch (e) {
2054
- if (e instanceof RhiError) {
2055
- runtime.errorRegistry.fire(e);
2056
- return null;
2057
- }
2058
- throw e;
2059
- }
2060
608
  }
2061
609
 
2062
610
  /**
2063
611
  * Build (or reuse) the dummy `shadow-material-singleton` @group(1) BG for the
2064
612
  * spot shadow caster pass. The vertex-only shadow_caster shader never consumes
2065
613
  * @group(1) but the PSO's BGL must validate. Reuses the same singleton Map
2066
- * entry recordShadowPass / recordPointShadowPass write so the three paths share
614
+ * entry encodeDirectionalShadowPass / encodePointShadowPass write so the three paths share
2067
615
  * one allocation per frame (D-6).
2068
616
  */
2069
617
  function ensureSpotShadowMaterialBg(c: _InternalRenderPipelineContext): BindGroup | null {
@@ -2071,60 +619,57 @@ function ensureSpotShadowMaterialBg(c: _InternalRenderPipelineContext): BindGrou
2071
619
  const cached = frameState.singletonMaterialCache.get('shadow-material-singleton');
2072
620
  if (cached !== undefined) return cached;
2073
621
  const fb = pipelineState.skylightFallback;
2074
- const fallbackEntries = [
2075
- {
2076
- binding: 0,
2077
- resource: {
2078
- kind: 'buffer' as const,
2079
- value: {
2080
- buffer: pipelineState.materialUniformBuffer.buffer,
2081
- offset: 0,
2082
- size: MATERIAL_PER_ENTITY_STRIDE,
622
+ const fallbackEntries: BindGroupEntry[] = buildPbrMaterialUserRegionEntries().map((entry) => {
623
+ if (entry.buffer !== undefined) {
624
+ return {
625
+ binding: entry.binding,
626
+ resource: {
627
+ kind: 'buffer' as const,
628
+ value: {
629
+ buffer: pipelineState.materialUniformBuffer.buffer,
630
+ offset: 0,
631
+ size: STANDARD_PBR_UBO_SIZE,
632
+ },
2083
633
  },
634
+ };
635
+ }
636
+ if (entry.sampler !== undefined) {
637
+ return {
638
+ binding: entry.binding,
639
+ resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler },
640
+ };
641
+ }
642
+ return {
643
+ binding: entry.binding,
644
+ resource: {
645
+ kind: 'textureView' as const,
646
+ value:
647
+ entry.binding === 6
648
+ ? pipelineState.defaultNormalTextureView
649
+ : pipelineState.fallbackTextureView,
2084
650
  },
2085
- },
2086
- { binding: 1, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2087
- {
2088
- binding: 2,
2089
- resource: { kind: 'textureView' as const, value: pipelineState.fallbackTextureView },
2090
- },
2091
- { binding: 3, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2092
- {
2093
- binding: 4,
2094
- resource: { kind: 'textureView' as const, value: pipelineState.defaultNormalTextureView },
2095
- },
2096
- { binding: 5, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2097
- {
2098
- binding: 6,
2099
- resource: { kind: 'textureView' as const, value: pipelineState.fallbackTextureView },
2100
- },
2101
- { binding: 7, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2102
- {
2103
- binding: 8,
2104
- resource: { kind: 'textureView' as const, value: pipelineState.defaultWhiteTextureView },
2105
- },
2106
- { binding: 9, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2107
- {
2108
- binding: 10,
2109
- resource: { kind: 'textureView' as const, value: pipelineState.defaultWhiteTextureView },
2110
- },
2111
- { binding: 11, resource: { kind: 'sampler' as const, value: pipelineState.defaultSampler } },
2112
- {
2113
- binding: 12,
2114
- resource: { kind: 'textureView' as const, value: pipelineState.defaultWhiteTextureView },
2115
- },
2116
- ];
651
+ };
652
+ });
2117
653
  const merged =
2118
654
  fb !== null
2119
- ? assembleMaterialWithSkylightEntries(fallbackEntries, {
2120
- irradianceView: fb.irradianceView,
2121
- irradianceSampler: fb.sampler,
2122
- prefilterView: fb.prefilterView,
2123
- prefilterSampler: fb.sampler,
2124
- brdfLutView: fb.brdfLutView,
2125
- brdfLutSampler: fb.sampler,
2126
- intensityBuffer: fb.intensityBuffer,
2127
- })
655
+ ? assembleMaterialWithSkylightEntries(
656
+ fallbackEntries,
657
+ {
658
+ irradianceView: fb.irradianceView,
659
+ irradianceSampler: fb.sampler,
660
+ prefilterView: fb.prefilterView,
661
+ prefilterSampler: fb.sampler,
662
+ brdfLutView: fb.brdfLutView,
663
+ brdfLutSampler: fb.sampler,
664
+ intensityBuffer: fb.intensityBuffer,
665
+ },
666
+ {
667
+ emissiveSampler: pipelineState.defaultSampler,
668
+ emissiveView: pipelineState.defaultWhiteTextureView,
669
+ occlusionSampler: pipelineState.defaultSampler,
670
+ occlusionView: pipelineState.defaultWhiteTextureView,
671
+ },
672
+ )
2128
673
  : fallbackEntries;
2129
674
  const r = runtime.device.createBindGroup({
2130
675
  label: 'shadow-material-bg',
@@ -2140,248 +685,3 @@ function ensureSpotShadowMaterialBg(c: _InternalRenderPipelineContext): BindGrou
2140
685
  frameState.singletonMaterialCache.set('shadow-material-singleton', r.value);
2141
686
  return r.value;
2142
687
  }
2143
-
2144
- /**
2145
- * feat-20260625-spot-light-shadow-mapping M2 / w11 (D-1 + D-2). Records the
2146
- * spot-light shadow caster passes — one render pass per castShadow spot (cap 4)
2147
- * — that write each spot's perspective depth into its `spotShadowDepth` atlas
2148
- * tile. Driven by the URP `addSpotShadowPass` graph closure; reads
2149
- * `frameState.spotShadowSnapshots`.
2150
- *
2151
- * Per spot with `shadowAtlasTile >= 0` (castShadow + non-degenerate dir + not
2152
- * clipped) and a valid `lightViewProj`:
2153
- * (1) Write the spot perspective matrix into `shadowCasterCascadeBuffer`
2154
- * (D-1: spotLightViewProj lane at byte 16) and set `isSpot = 1` so the
2155
- * shadow_caster vertex shader routes through the spot matrix instead of
2156
- * the directional `view.lightViewProj_A..D` slots. The per-pass
2157
- * independent command encoder + queue.submit serialize each host write
2158
- * against that pass's GPU read.
2159
- * (2) Open an INDEPENDENT command encoder targeting the spotShadowDepth view
2160
- * with `depthLoadOp = (first valid tile ? clear : load)` — independent
2161
- * clear counting decoupled from the directional cascadeIndex (D-2). Set a
2162
- * per-tile viewport (col = tile % 2, row = tile / 2).
2163
- * (3) Reuse the vertex-only `forgeax::default-shadow-caster` PSO + the cached
2164
- * `view-shadow` BG + `shadow-material-singleton` + meshBindGroup built by
2165
- * recordShadowPass (or built on-demand here when no directional shadow
2166
- * ran this frame).
2167
- *
2168
- * AC-03 zero-shadow zero-pass: early-returns when no spot has a valid tile, so
2169
- * castShadow:false scenes (all tile=-1) record zero spot passes. After the
2170
- * loop, `isSpot` is reset to 0 so the next directional cascade pass (or next
2171
- * frame) sees the directional routing.
2172
- */
2173
- export function recordSpotShadowPass(c: _InternalRenderPipelineContext): void {
2174
- const { runtime, frameState, meshBindGroup, pipelineState } = c;
2175
- const snapshots = frameState.spotShadowSnapshots;
2176
- // AC-03: skip entirely when no spot projects a shadow this frame.
2177
- const casters = snapshots.filter((s) => s.shadowAtlasTile >= 0 && s.lightViewProj !== undefined);
2178
- if (casters.length === 0) return;
2179
- if (meshBindGroup === null) return;
2180
-
2181
- const shadowPipeline =
2182
- runtime.getMaterialShaderPipeline?.(
2183
- 'forgeax::default-shadow-caster',
2184
- false,
2185
- undefined,
2186
- 'triangle-list',
2187
- undefined,
2188
- undefined,
2189
- 'shadow-caster',
2190
- ) ?? null;
2191
- if (shadowPipeline === null) return;
2192
-
2193
- const spotView = frameState.currentSpotShadowView;
2194
- if (spotView === null) return;
2195
-
2196
- const shadowViewBg = ensureSpotShadowViewBg(c);
2197
- const shadowMaterialBg = ensureSpotShadowMaterialBg(c);
2198
- if (shadowViewBg === null || shadowMaterialBg === null) return;
2199
-
2200
- const tileCtx: SpotTileContext = {
2201
- spotView,
2202
- shadowViewBg,
2203
- shadowMaterialBg,
2204
- shadowPipeline,
2205
- meshBindGroup,
2206
- tileSize: pipelineState.perPassResources.shadowMapSize,
2207
- };
2208
-
2209
- let clearedAtlas = false;
2210
- for (let ci = 0; ci < casters.length; ci++) {
2211
- const snap = casters[ci];
2212
- if (snap === undefined || snap.lightViewProj === undefined) continue;
2213
- if (recordSpotTile(c, snap, ci, casters.length, clearedAtlas, tileCtx)) {
2214
- clearedAtlas = true;
2215
- }
2216
- }
2217
-
2218
- // Reset isSpot so the next directional cascade pass / next frame routes
2219
- // through view.lightViewProj_A..D again (D-1).
2220
- const resetPayload = new Uint32Array([0, 0, 0, 0]);
2221
- const resetWrite = runtime.device.queue.writeBuffer(
2222
- pipelineState.shadowCasterCascadeBuffer,
2223
- 0,
2224
- resetPayload,
2225
- );
2226
- if (!resetWrite.ok) runtime.errorRegistry.fire(resetWrite.error);
2227
- }
2228
-
2229
- /** Per-tile resources shared across the spot caster passes in one frame. */
2230
- interface SpotTileContext {
2231
- readonly spotView: TextureView;
2232
- readonly shadowViewBg: BindGroup;
2233
- readonly shadowMaterialBg: BindGroup;
2234
- readonly shadowPipeline: NonNullable<
2235
- ReturnType<NonNullable<_InternalRenderPipelineContext['runtime']['getMaterialShaderPipeline']>>
2236
- >;
2237
- readonly meshBindGroup: BindGroup;
2238
- readonly tileSize: number;
2239
- }
2240
-
2241
- /**
2242
- * Render one spot's perspective depth into its atlas tile. Writes isSpot=1 +
2243
- * the spot matrix into the cascade UBO (D-1), opens an independent encoder with
2244
- * a per-tile viewport, and clears the atlas on the first tile / loads on the
2245
- * rest (D-2). Returns true when this pass cleared the atlas (so the caller
2246
- * tracks the clear/load boundary). Errors fire to the registry and return the
2247
- * incoming `alreadyCleared` unchanged.
2248
- */
2249
- function recordSpotTile(
2250
- c: _InternalRenderPipelineContext,
2251
- snapshot: SpotLightSnapshot,
2252
- spotIndex: number,
2253
- spotCount: number,
2254
- alreadyCleared: boolean,
2255
- ctx: SpotTileContext,
2256
- ): boolean {
2257
- const { runtime, pipelineState } = c;
2258
- const lightViewProj = snapshot.lightViewProj;
2259
- const tile = snapshot.shadowAtlasTile;
2260
- if (lightViewProj === undefined || tile < 0) return alreadyCleared;
2261
- // D-1: cascade UBO byte offset of the spotLightViewProj mat4 lane (16 B for
2262
- // index/isSpot/2pad vec4, then the mat4). isSpot lane is u32 word 1.
2263
- const SPOT_LVP_OFFSET = 16;
2264
-
2265
- const headerWrite = runtime.device.queue.writeBuffer(
2266
- pipelineState.shadowCasterCascadeBuffer,
2267
- 0,
2268
- new Uint32Array([0, 1, 0, 0]), // index=0, isSpot=1, pad
2269
- );
2270
- if (!headerWrite.ok) {
2271
- runtime.errorRegistry.fire(headerWrite.error);
2272
- return alreadyCleared;
2273
- }
2274
- const matWrite = runtime.device.queue.writeBuffer(
2275
- pipelineState.shadowCasterCascadeBuffer,
2276
- SPOT_LVP_OFFSET,
2277
- lightViewProj,
2278
- );
2279
- if (!matWrite.ok) {
2280
- runtime.errorRegistry.fire(matWrite.error);
2281
- return alreadyCleared;
2282
- }
2283
-
2284
- const encResult = runtime.device.createCommandEncoder({ label: `spot-shadow-tile${tile}` });
2285
- if (!encResult.ok) {
2286
- runtime.errorRegistry.fire(encResult.error);
2287
- return alreadyCleared;
2288
- }
2289
- const enc = encResult.value;
2290
- const pass: RhiRenderPassEncoder = enc.beginRenderPass(
2291
- buildBeginRenderPassDescriptor(
2292
- { colorFormats: [], depthFormat: 'depth32float', sampleCount: 1 },
2293
- { colorViews: [], depthView: ctx.spotView },
2294
- 'shadow-caster',
2295
- { depthLoadOp: alreadyCleared ? 'load' : 'clear' },
2296
- ) as never,
2297
- );
2298
-
2299
- pass.setPipeline(ctx.shadowPipeline);
2300
- const col = tile % 2;
2301
- const row = Math.floor(tile / 2);
2302
- pass.setViewport(col * ctx.tileSize, row * ctx.tileSize, ctx.tileSize, ctx.tileSize, 0, 1);
2303
- pass.setBindGroup(0, ctx.shadowViewBg);
2304
- pass.setBindGroup(1, ctx.shadowMaterialBg, [0]);
2305
- emitSpotShadowPassBeginMarker(c, pass, snapshot, spotIndex, spotCount);
2306
- recordSpotShadowGeometry(c, pass, ctx.meshBindGroup);
2307
- emitSpotShadowPassEndMarker(c, pass, snapshot);
2308
-
2309
- pass.end();
2310
- const finishResult = enc.finish();
2311
- if (!finishResult.ok) {
2312
- runtime.errorRegistry.fire(finishResult.error);
2313
- return alreadyCleared;
2314
- }
2315
- const submitResult = runtime.device.queue.submit([finishResult.value]);
2316
- if (!submitResult.ok) runtime.errorRegistry.fire(submitResult.error);
2317
- return true;
2318
- }
2319
-
2320
- /**
2321
- * Walk the mesh-SSBO slot order and emit shadow-caster draws for the current
2322
- * spot tile pass. Triangle topologies only (line/point meshes cast no shadow).
2323
- * Reuses the per-entity instance BGs cached by recordShadowPass; falls back to
2324
- * the identity instance buffer when none is cached.
2325
- */
2326
- function recordSpotShadowGeometry(
2327
- c: _InternalRenderPipelineContext,
2328
- pass: RhiRenderPassEncoder,
2329
- meshBindGroup: BindGroup,
2330
- ): void {
2331
- const { frameState, pipelineState } = c;
2332
- const mainMembership = mainShadowMembership(c);
2333
- let lastVB: GpuBuffer | null = null;
2334
- let lastIB: GpuBuffer | null = null;
2335
- const shadowEntries =
2336
- c.validatedShadowEntries ??
2337
- c.validatedOrdered.flatMap((entry, validatedIndex) =>
2338
- isMainShadowRenderable(entry, mainMembership) ? [{ entry, validatedIndex }] : [],
2339
- );
2340
- for (const { entry, validatedIndex: ei } of shadowEntries) {
2341
- const submeshes = entry.mesh.submeshes;
2342
- const hasTriangle = submeshes.some(
2343
- (sm) => sm.topology === 'triangle-list' || sm.topology === 'triangle-strip',
2344
- );
2345
- if (!hasTriangle) continue;
2346
- if (entry.mesh.vertexBuffer !== lastVB) {
2347
- pass.setVertexBuffer(0, entry.mesh.vertexBuffer.handle);
2348
- lastVB = entry.mesh.vertexBuffer;
2349
- }
2350
- if (entry.mesh.indexed && entry.mesh.indexBuffer !== lastIB && entry.mesh.indexBuffer) {
2351
- pass.setIndexBuffer(entry.mesh.indexBuffer.handle, entry.mesh.indexFormat);
2352
- lastIB = entry.mesh.indexBuffer;
2353
- }
2354
- pass.setBindGroup(2, meshBindGroup, [ei * MESH_PER_ENTITY_STRIDE]);
2355
- const inst = entry.source.instances;
2356
- let instCount = 1;
2357
- let instBufferKey: object = pipelineState.identityInstanceBuffer as unknown as object;
2358
- if (inst !== undefined) {
2359
- const cached = frameState.instanceBuffers.get(
2360
- worldEntityKey(entry.source.worldId, inst.cacheKey),
2361
- );
2362
- if (
2363
- cached !== undefined &&
2364
- cached.uploadedArchVersion === inst.archVersion &&
2365
- cached.uploadedByteLength ===
2366
- temporalInstanceUploadByteLength(inst.transforms, c.runtime.device.caps.storageBuffer)
2367
- ) {
2368
- instBufferKey = cached.buffer.handle as unknown as object;
2369
- instCount = Math.max(1, inst.instanceCount);
2370
- }
2371
- }
2372
- const spotInstLeaf = frameState.instancesBgPerEntity
2373
- .get(worldEntityKey(entry.source.worldId, entry.source.entityKey))
2374
- ?.get(instBufferKey) as Map<string, BindGroup> | undefined;
2375
- const cachedInstBg = spotInstLeaf?.get('shadow-instances');
2376
- if (cachedInstBg === undefined) continue;
2377
- pass.setBindGroup(3, cachedInstBg);
2378
- for (const sm of submeshes) {
2379
- if (sm.topology !== 'triangle-list' && sm.topology !== 'triangle-strip') continue;
2380
- if (entry.mesh.indexed) {
2381
- pass.drawIndexed(sm.indexCount, instCount, sm.indexOffset, 0, 0);
2382
- } else {
2383
- pass.draw(sm.vertexCount, instCount, 0, 0);
2384
- }
2385
- }
2386
- }
2387
- }