@threenative/core 0.3.11 → 0.3.13

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 (236) hide show
  1. package/README.md +1 -1
  2. package/capabilities.json +1988 -204
  3. package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
  4. package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
  5. package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
  6. package/dist/chunk-4SRAQFTU.js +133 -0
  7. package/dist/chunk-CFGTPFUH.js +231 -0
  8. package/dist/chunk-DIPIJICH.js +8916 -0
  9. package/dist/chunk-EEABDLUC.js +2237 -0
  10. package/dist/chunk-EFWZWLPY.js +1895 -0
  11. package/dist/chunk-GXY7B3JG.js +46 -0
  12. package/dist/chunk-GYUZJQ7U.js +280 -0
  13. package/dist/chunk-H4J6IAJE.js +504 -0
  14. package/dist/chunk-KIRUKTBQ.js +187 -0
  15. package/dist/chunk-QWJEMUUT.js +94 -0
  16. package/dist/chunk-SV4QVUTQ.js +31 -0
  17. package/dist/chunk-U4YHUKKL.js +615 -0
  18. package/dist/chunk-VP43GIWW.js +18 -0
  19. package/dist/chunk-XDTZ4QMO.js +160 -0
  20. package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
  21. package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
  22. package/dist/hot.d.ts +5 -4
  23. package/dist/hot.js +5 -52
  24. package/dist/index.d.ts +633 -1351
  25. package/dist/index.js +12873 -23068
  26. package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
  27. package/dist/playtest.d.ts +5 -4
  28. package/dist/playtest.js +25 -75
  29. package/dist/quality-BYqKGAwo.d.ts +868 -0
  30. package/dist/react-css.js +1 -215
  31. package/dist/react.d.ts +3 -2
  32. package/dist/render-environment.d.ts +170 -0
  33. package/dist/render-environment.js +352 -0
  34. package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
  35. package/dist/spells/index.d.ts +643 -0
  36. package/dist/spells/index.js +1558 -0
  37. package/dist/spells/ultra/index.d.ts +1600 -0
  38. package/dist/spells/ultra/index.js +6804 -0
  39. package/dist/terrain-jobs-worker.js +1 -123
  40. package/dist/two-sided-foliage-W523J3UM.js +1 -0
  41. package/dist/ui-layer.js +6 -384
  42. package/dist/worker.js +13 -43
  43. package/dist/world.d.ts +988 -268
  44. package/dist/world.js +17464 -18290
  45. package/mcp/animation-server.mjs +1 -1
  46. package/mcp/animation.mjs +2 -3
  47. package/mcp/engine-server.mjs +245 -52
  48. package/mcp/servers.mjs +10 -3
  49. package/mcp/terrain.mjs +8 -0
  50. package/package.json +19 -7
  51. package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
  52. package/patches/three@0.187.0.patch +2004 -407
  53. package/src/animation-batch.ts +193 -0
  54. package/src/animation-layers.ts +7 -3
  55. package/src/animation.ts +209 -29
  56. package/src/asset-cache.ts +3 -3
  57. package/src/asset-memo.ts +202 -0
  58. package/src/assets.ts +437 -125
  59. package/src/auto-batch.ts +190 -44
  60. package/src/card-lod.ts +152 -0
  61. package/src/compressed-texture-preparation.ts +1008 -0
  62. package/src/compute-driven.ts +1 -1
  63. package/src/config.ts +8 -0
  64. package/src/debug.ts +103 -22
  65. package/src/dev-global.ts +54 -0
  66. package/src/engine-hooks.ts +37 -0
  67. package/src/frame-budget.ts +50 -23
  68. package/src/game-boot-phase.ts +269 -0
  69. package/src/game-dev-tools.ts +86 -0
  70. package/src/game-frame-loop.ts +958 -0
  71. package/src/game-renderer-metrics.ts +77 -0
  72. package/src/game-startup.ts +1076 -0
  73. package/src/game-ui.ts +84 -0
  74. package/src/game-validate.ts +70 -0
  75. package/src/game.ts +198 -2264
  76. package/src/gamepad-mappings.ts +269 -0
  77. package/src/generated/console-markers.ts +13 -0
  78. package/src/geometry-capture.ts +28 -4
  79. package/src/gpu-readings.ts +98 -0
  80. package/src/gpu-scene-bvh.ts +149 -36
  81. package/src/hot.ts +4 -7
  82. package/src/index.ts +141 -9
  83. package/src/input.ts +237 -25
  84. package/src/instanced-batch-lod.ts +3 -8
  85. package/src/interpolation.ts +171 -40
  86. package/src/launch-diagnostics.ts +22 -12
  87. package/src/look/ao-admission.ts +25 -0
  88. package/src/look/auto-exposure.ts +5 -16
  89. package/src/look/default-tone-mapping.ts +41 -5
  90. package/src/look/filmic-tone-mapping.ts +15 -13
  91. package/src/look/local-exposure.ts +2 -7
  92. package/src/look/look-diagnostics.ts +3 -3
  93. package/src/look/quad-pass.ts +21 -0
  94. package/src/look/quality.ts +14 -5
  95. package/src/look/unreal-bloom.ts +4 -13
  96. package/src/look/world-environment.ts +113 -103
  97. package/src/loop.ts +29 -0
  98. package/src/merge-parts.ts +20 -24
  99. package/src/model-lod.ts +139 -17
  100. package/src/particle-kinds.ts +515 -0
  101. package/src/particle-significance.ts +12 -0
  102. package/src/particles.ts +19 -10
  103. package/src/picking.ts +17 -3
  104. package/src/platform.ts +23 -4
  105. package/src/playtest.ts +27 -1
  106. package/src/profiling/FrameStages.ts +5 -6
  107. package/src/profiling/Spans.ts +3 -17
  108. package/src/profiling/debug-telemetry.ts +2 -6
  109. package/src/profiling/render-list-validate.ts +6 -15
  110. package/src/projection-apply.ts +4 -1
  111. package/src/projection-marker.ts +2 -1
  112. package/src/projection-plan.ts +9 -6
  113. package/src/quiet-markers.ts +3 -10
  114. package/src/render/cpu-bvh.ts +100 -0
  115. package/src/render/depth-pyramid.ts +6 -14
  116. package/src/render/environment/environmentContribution.ts +202 -0
  117. package/src/render/environment/environmentRadiance.ts +44 -0
  118. package/src/render/environment/environmentSampleCache.ts +56 -0
  119. package/src/render/environment/environmentSampling.ts +201 -0
  120. package/src/render/environment/environmentSnapshot.ts +71 -0
  121. package/src/render/environment/gate.ts +57 -0
  122. package/src/render/mesh-pool.ts +4 -20
  123. package/src/render/probe-trace.ts +872 -0
  124. package/src/render/probe-volume.ts +780 -34
  125. package/src/render/radiance-cache.ts +17 -0
  126. package/src/render/resolution-subrect.ts +2 -0
  127. package/src/render/rough-diffuse.ts +46 -12
  128. package/src/render/soft-shadow.ts +27 -12
  129. package/src/render/virtual-shadow-adaptive.ts +55 -0
  130. package/src/render/virtual-shadow-casters.ts +175 -0
  131. package/src/render/virtual-shadow-layers.ts +76 -0
  132. package/src/render/virtual-shadow-level.ts +224 -0
  133. package/src/render/virtual-shadow-markers.ts +193 -0
  134. package/src/render/virtual-shadow-options.ts +370 -0
  135. package/src/render/virtual-shadow-pages.ts +5 -0
  136. package/src/render/virtual-shadow-partial.ts +13 -0
  137. package/src/render/virtual-shadow.ts +231 -1008
  138. package/src/render/world-impostor-surface.ts +402 -40
  139. package/src/render/world-impostor.ts +5 -2
  140. package/src/render-camera-cull.ts +98 -3
  141. package/src/render-environment.ts +41 -0
  142. package/src/render-pass-budget.ts +34 -7
  143. package/src/renderProjection.ts +22 -0
  144. package/src/renderer-config.ts +36 -0
  145. package/src/renderer-facts.ts +37 -0
  146. package/src/renderer.ts +144 -65
  147. package/src/resolution-scaler.ts +3 -2
  148. package/src/scene-entry-inspectors.ts +61 -0
  149. package/src/snow-field.ts +2 -1
  150. package/src/spells/cast-pool.ts +361 -0
  151. package/src/spells/index.ts +177 -0
  152. package/src/spells/mechanisms.ts +295 -0
  153. package/src/spells/reaction-field.ts +415 -0
  154. package/src/spells/spell-lights.ts +139 -0
  155. package/src/spells/spell-world.ts +187 -0
  156. package/src/spells/spell.ts +397 -0
  157. package/src/spells/spells.ts +283 -0
  158. package/src/spells/ultra/engine/camera.ts +184 -0
  159. package/src/spells/ultra/engine/quality.ts +96 -0
  160. package/src/spells/ultra/index.ts +52 -0
  161. package/src/spells/ultra/main.ts +305 -0
  162. package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
  163. package/src/spells/ultra/spells/cast.ts +233 -0
  164. package/src/spells/ultra/spells/fire.ts +1267 -0
  165. package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
  166. package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
  167. package/src/spells/ultra/vfx/FxTarget.ts +61 -0
  168. package/src/spells/ultra/vfx/GroundField.ts +1399 -0
  169. package/src/spells/ultra/vfx/Particles.ts +1475 -0
  170. package/src/spells/ultra/vfx/Ribbons.ts +645 -0
  171. package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
  172. package/src/spells/ultra/vfx/Volumes.ts +489 -0
  173. package/src/spells/ultra/vfx/common.ts +1195 -0
  174. package/src/spells/ultra/vfx/noise.ts +441 -0
  175. package/src/startup-offscreen-bytes.ts +78 -0
  176. package/src/startup-readiness.ts +128 -34
  177. package/src/static-transform.ts +25 -19
  178. package/src/streamed-textures.ts +112 -0
  179. package/src/streaming.ts +68 -4
  180. package/src/texture-streaming.ts +331 -0
  181. package/src/version.ts +1 -1
  182. package/src/warmup.ts +56 -8
  183. package/src/water-surface.ts +9 -3
  184. package/src/worker.ts +12 -2
  185. package/src/world-bundle-safety.ts +446 -0
  186. package/src/world-cell-batches.ts +1178 -0
  187. package/src/world-cell-chunks.ts +1128 -0
  188. package/src/world-cell-data.ts +995 -0
  189. package/src/world-cell-impostors.ts +1461 -0
  190. package/src/world-cell-lod-bias.ts +151 -0
  191. package/src/world-cell-models.ts +1074 -0
  192. package/src/world-cell-options.ts +177 -0
  193. package/src/world-cell-placements.ts +798 -0
  194. package/src/world-cell-prewarm.ts +592 -0
  195. package/src/world-cell-readiness.ts +357 -0
  196. package/src/world-cell-records.ts +401 -0
  197. package/src/world-cell-render-bundles.ts +459 -0
  198. package/src/world-cell-render-gpu-dress.ts +710 -0
  199. package/src/world-cell-render-main-cull.ts +540 -0
  200. package/src/world-cell-render-shadow-claims.ts +198 -0
  201. package/src/world-cell-render-util.ts +259 -0
  202. package/src/world-cell-render.ts +1501 -0
  203. package/src/world-cell-residency.ts +754 -0
  204. package/src/world-cell-stale.ts +238 -0
  205. package/src/world-cells.ts +1335 -10418
  206. package/src/world-chunk-shadow.ts +308 -0
  207. package/src/world-collar.ts +315 -0
  208. package/src/world-gpu-flags.ts +131 -0
  209. package/src/world-gpu-readback.ts +881 -0
  210. package/src/world-gpu-reference.ts +524 -0
  211. package/src/world-gpu-scene.ts +256 -2286
  212. package/src/world-gpu-shadow.ts +203 -0
  213. package/src/world-gpu-types.ts +409 -0
  214. package/src/world-gpu-validation.ts +518 -0
  215. package/src/world-heightfield.ts +802 -0
  216. package/src/world-load-limiter.ts +111 -0
  217. package/src/world-model-sections.ts +80 -0
  218. package/src/world-noise.ts +241 -0
  219. package/src/world-package.ts +42 -0
  220. package/src/world-region.ts +1 -1
  221. package/src/world-river-ribbon.ts +282 -0
  222. package/src/world-root-frame.ts +39 -0
  223. package/src/world-shore-field.ts +91 -0
  224. package/src/world-static-pose.ts +163 -0
  225. package/src/world-surface-sampler.ts +48 -0
  226. package/src/world-terrain-splat.ts +361 -153
  227. package/src/world-tile-budget.ts +249 -0
  228. package/src/world-tile-geometry.ts +469 -0
  229. package/src/world-tile-lod.ts +408 -0
  230. package/src/world-tile-observation.ts +566 -0
  231. package/src/world-tile-stitch.ts +166 -0
  232. package/src/world-tiles.ts +247 -1755
  233. package/src/world-validate.ts +6 -14
  234. package/src/world-warm.ts +51 -0
  235. package/src/world-water-bodies.ts +359 -0
  236. package/src/world.ts +48 -741
@@ -12,7 +12,7 @@ index 0ee9b6d588348c3177b91d6093cfe8b167778db8..61f61f83b5a6123b4b94c98355a165df
12
12
  * Constructs a new batched mesh.
13
13
  *
14
14
  diff --git a/build/three.tsl.js b/build/three.tsl.js
15
- index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac460da91e2d 100644
15
+ index 7c8d2322834904c1247c79cda31beff8e2bfc497..b87cf38629b2c52804888a10bda3b814a1493316 100644
16
16
  --- a/build/three.tsl.js
17
17
  +++ b/build/three.tsl.js
18
18
  @@ -18530,6 +18530,13 @@ class TextureSizeNode extends Node {
@@ -54,7 +54,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
54
54
 
55
55
  // the columns view the matrices, so both share the same GPU buffer which is freed via instanceMatrix.dispose()
56
56
 
57
- @@ -24431,8 +24433,25 @@ const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
57
+ @@ -24431,8 +24433,30 @@ const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
58
58
 
59
59
  const instancedMesh = builder.object;
60
60
 
@@ -67,8 +67,11 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
67
67
  +
68
68
  + const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
69
69
  +
70
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
71
+ +
70
72
  + previousInstanceMatrix.array.set( scheduledPrevious );
71
73
  + previousInstanceMatrix.needsUpdate = true;
74
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
72
75
  +
73
76
  + } );
74
77
  +
@@ -76,11 +79,13 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
76
79
  OnAfterObjectUpdate( ( { object } ) => {
77
80
 
78
81
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
82
+ +
83
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
79
84
  +
80
85
  const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
81
86
 
82
87
  previousInstanceMatrix.array.set( matrices.array );
83
- @@ -24474,8 +24493,25 @@ const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) => {
88
+ @@ -24474,8 +24498,30 @@ const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) => {
84
89
 
85
90
  if ( builder.needsPreviousData() ) {
86
91
 
@@ -93,8 +98,11 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
93
98
  +
94
99
  + const previous = getPreviousMatrix$1( object );
95
100
  +
101
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
102
+ +
96
103
  + previous.array.set( scheduledPrevious );
97
104
  + previous.needsUpdate = true;
105
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
98
106
  +
99
107
  + } );
100
108
  +
@@ -102,11 +110,13 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
102
110
  OnAfterObjectUpdate( ( { object } ) => {
103
111
 
104
112
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
113
+ +
114
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
105
115
  +
106
116
  const previous = getPreviousMatrix$1( object );
107
117
 
108
118
  previous.array.set( object.instanceMatrix.array );
109
- @@ -24914,7 +24950,11 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
119
+ @@ -24914,7 +24960,11 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
110
120
 
111
121
  if ( skeleton.previousBoneMatrices !== null ) {
112
122
 
@@ -119,7 +129,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
119
129
 
120
130
  if ( skeleton.previousBoneTexture !== null ) {
121
131
 
122
- @@ -24932,8 +24972,17 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
132
+ @@ -24932,8 +24982,17 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
123
133
 
124
134
  if ( needsPreviousData ) {
125
135
 
@@ -138,7 +148,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
138
148
 
139
149
  positionPrevious.assign( previousSkinnedPosition );
140
150
 
141
- @@ -24986,7 +25035,11 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
151
+ @@ -24986,7 +25045,11 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
142
152
 
143
153
  if ( skeleton.previousBoneMatrices !== null ) {
144
154
 
@@ -151,7 +161,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
151
161
 
152
162
  if ( skeleton.previousBoneTexture !== null ) {
153
163
 
154
- @@ -25006,8 +25059,15 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
164
+ @@ -25006,8 +25069,15 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
155
165
 
156
166
  setupPreviousBoneData( skeleton );
157
167
 
@@ -168,7 +178,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
168
178
 
169
179
  positionPrevious.assign( previousSkinnedPosition );
170
180
 
171
- @@ -26044,6 +26104,15 @@ class NodeMaterialObserver {
181
+ @@ -26044,6 +26114,15 @@ class NodeMaterialObserver {
172
182
  */
173
183
  this.renderId = 0;
174
184
 
@@ -184,7 +194,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
184
194
  }
185
195
 
186
196
  /**
187
- @@ -26222,6 +26291,88 @@ class NodeMaterialObserver {
197
+ @@ -26222,6 +26301,92 @@ class NodeMaterialObserver {
188
198
 
189
199
  }
190
200
 
@@ -235,7 +245,8 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
235
245
  + environmentRotation: scene.environmentRotation.clone(),
236
246
  + environmentIntensity: scene.environmentIntensity,
237
247
  + materialVersion: material.version,
238
- + geometryVersion: geometry.version
248
+ + geometryVersion: geometry.version,
249
+ + pmremSwaps: renderObject.renderer._tnPmremSwaps
239
250
  + };
240
251
  +
241
252
  + data.settledState = false;
@@ -248,7 +259,9 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
248
259
  + settled.environmentRotation.equals( scene.environmentRotation ) !== true ||
249
260
  + settled.environmentIntensity !== scene.environmentIntensity ||
250
261
  + settled.materialVersion !== material.version ||
251
- + settled.geometryVersion !== geometry.version ) {
262
+ + settled.geometryVersion !== geometry.version ||
263
+ + // a PMREM finished and swapped the texture its node samples: a settled object would keep the old one
264
+ + settled.pmremSwaps !== renderObject.renderer._tnPmremSwaps ) {
252
265
  +
253
266
  + // re-arm with the current state, so the object settles again once it stops changing
254
267
  +
@@ -257,6 +270,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
257
270
  + settled.environmentIntensity = scene.environmentIntensity;
258
271
  + settled.materialVersion = material.version;
259
272
  + settled.geometryVersion = geometry.version;
273
+ + settled.pmremSwaps = renderObject.renderer._tnPmremSwaps;
260
274
  +
261
275
  + data.settledState = false;
262
276
  +
@@ -273,7 +287,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
273
287
  /**
274
288
  * Returns an attribute data structure holding the attributes versions for
275
289
  * monitoring.
276
- @@ -26943,7 +27094,17 @@ class NodeMaterialObserver {
290
+ @@ -26943,7 +27108,17 @@ class NodeMaterialObserver {
277
291
  */
278
292
  needsRefresh( renderObject, nodeFrame ) {
279
293
 
@@ -292,7 +306,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
292
306
  return RenderObjectRefreshType.FULL;
293
307
 
294
308
  const { renderId } = nodeFrame;
295
- @@ -26986,10 +27147,14 @@ class NodeMaterialObserver {
309
+ @@ -26986,10 +27161,14 @@ class NodeMaterialObserver {
296
310
 
297
311
  }
298
312
 
@@ -309,7 +323,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
309
323
  return refreshType;
310
324
 
311
325
  const lightsData = this.getLights( renderObject.lightsNode, renderId );
312
- @@ -30631,7 +30796,8 @@ class VelocityNode extends Node {
326
+ @@ -30631,7 +30810,8 @@ class VelocityNode extends Node {
313
327
 
314
328
  const previousModelMatrix = getPreviousMatrix( object );
315
329
 
@@ -319,7 +333,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
319
333
 
320
334
  //
321
335
 
322
- @@ -31158,7 +31324,7 @@ class PassMultipleTextureNode extends PassTextureNode {
336
+ @@ -31158,7 +31338,7 @@ class PassMultipleTextureNode extends PassTextureNode {
323
337
  * @param {string} textureName - The output texture name.
324
338
  * @param {boolean} [previousTexture=false] - Whether previous frame data should be used or not.
325
339
  */
@@ -328,7 +342,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
328
342
 
329
343
  // null is passed to the super call since this class does not
330
344
  // use an external texture for rendering pass data into. Instead
331
- @@ -31179,6 +31345,8 @@ class PassMultipleTextureNode extends PassTextureNode {
345
+ @@ -31179,6 +31359,8 @@ class PassMultipleTextureNode extends PassTextureNode {
332
346
  * @type {boolean}
333
347
  */
334
348
  this.previousTexture = previousTexture;
@@ -337,7 +351,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
337
351
 
338
352
  /**
339
353
  * This flag can be used for type testing.
340
- @@ -31200,17 +31368,33 @@ class PassMultipleTextureNode extends PassTextureNode {
354
+ @@ -31200,17 +31382,33 @@ class PassMultipleTextureNode extends PassTextureNode {
341
355
 
342
356
  }
343
357
 
@@ -372,7 +386,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
372
386
  newNode.uvNode = this.uvNode;
373
387
  newNode.levelNode = this.levelNode;
374
388
  newNode.biasNode = this.biasNode;
375
- @@ -31441,6 +31625,8 @@ class PassNode extends Node {
389
+ @@ -31441,6 +31639,8 @@ class PassNode extends Node {
376
390
  * @type {Object<string, TextureNode>}
377
391
  */
378
392
  this._textureNodes = {};
@@ -381,7 +395,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
381
395
 
382
396
  /**
383
397
  * A dictionary holding the internal depth nodes.
384
- @@ -31753,12 +31939,33 @@ class PassNode extends Node {
398
+ @@ -31753,12 +31953,33 @@ class PassNode extends Node {
385
399
  this._previousTextures[ name ] = texture;
386
400
 
387
401
  this._textureNodes[ name ].updateTexture();
@@ -415,7 +429,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
415
429
  /**
416
430
  * Returns the texture node for the given output name.
417
431
  *
418
- @@ -32156,6 +32363,7 @@ class PassNode extends Node {
432
+ @@ -32156,6 +32377,7 @@ class PassNode extends Node {
419
433
 
420
434
  super.dispose();
421
435
 
@@ -423,7 +437,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
423
437
  this.renderTarget.dispose();
424
438
 
425
439
  }
426
- @@ -35793,6 +36001,17 @@ const shadowPositionWorld = /*@__PURE__*/ property( 'vec3', 'shadowPositionWorld
440
+ @@ -35793,6 +36015,17 @@ const shadowPositionWorld = /*@__PURE__*/ property( 'vec3', 'shadowPositionWorld
427
441
 
428
442
  const _shadowUniforms = /*@__PURE__*/ new WeakMap();
429
443
 
@@ -441,7 +455,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
441
455
  function getShadowUniforms( shadow ) {
442
456
 
443
457
  let uniforms = _shadowUniforms.get( shadow );
444
- @@ -35801,7 +36020,10 @@ function getShadowUniforms( shadow ) {
458
+ @@ -35801,7 +36034,10 @@ function getShadowUniforms( shadow ) {
445
459
 
446
460
  uniforms = {
447
461
  mapSize: reference( 'mapSize', 'vec2', shadow ).setGroup( renderGroup ),
@@ -453,7 +467,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
453
467
  };
454
468
 
455
469
  _shadowUniforms.set( shadow, uniforms );
456
- @@ -36849,11 +37071,7 @@ const BasicPointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp } )
470
+ @@ -36849,11 +37085,7 @@ const BasicPointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp } )
457
471
  */
458
472
  const PointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, distance, shadow }, builder ) => {
459
473
 
@@ -466,7 +480,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
466
480
 
467
481
  const texelSize = radius.div( mapSize.x ).toConst();
468
482
 
469
- @@ -36896,9 +37114,7 @@ const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCo
483
+ @@ -36896,9 +37128,7 @@ const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCo
470
484
  const shadowPositionAbs = shadowPosition.abs().toConst();
471
485
  const viewZ = shadowPositionAbs.x.max( shadowPositionAbs.y ).max( shadowPositionAbs.z );
472
486
 
@@ -477,7 +491,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
477
491
 
478
492
  const result = float( 1.0 ).toVar();
479
493
 
480
- @@ -37894,6 +38110,24 @@ class PMREMGenerator {
494
+ @@ -37894,6 +38124,24 @@ class PMREMGenerator {
481
495
  this._ggxMaterial = null;
482
496
  this._integrationMaterial = null;
483
497
 
@@ -502,7 +516,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
502
516
  }
503
517
 
504
518
  /**
505
- @@ -38034,11 +38268,11 @@ class PMREMGenerator {
519
+ @@ -38034,11 +38282,11 @@ class PMREMGenerator {
506
520
  */
507
521
  async fromEquirectangularAsync( equirectangular, renderTarget = null ) {
508
522
 
@@ -517,7 +531,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
517
531
 
518
532
  }
519
533
 
520
- @@ -38074,11 +38308,11 @@ class PMREMGenerator {
534
+ @@ -38074,11 +38322,11 @@ class PMREMGenerator {
521
535
  */
522
536
  async fromCubemapAsync( cubemap, renderTarget = null ) {
523
537
 
@@ -532,7 +546,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
532
546
 
533
547
  }
534
548
 
535
- @@ -38156,7 +38390,13 @@ class PMREMGenerator {
549
+ @@ -38156,7 +38404,13 @@ class PMREMGenerator {
536
550
 
537
551
  }
538
552
 
@@ -547,7 +561,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
547
561
 
548
562
  if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
549
563
 
550
- @@ -38168,6 +38408,12 @@ class PMREMGenerator {
564
+ @@ -38168,6 +38422,12 @@ class PMREMGenerator {
551
565
 
552
566
  }
553
567
 
@@ -560,7 +574,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
560
574
  const pmremTarget = renderTarget || this._allocateTarget();
561
575
 
562
576
  this._textureToCubemap( texture );
563
- @@ -38177,6 +38423,55 @@ class PMREMGenerator {
577
+ @@ -38177,6 +38437,55 @@ class PMREMGenerator {
564
578
 
565
579
  }
566
580
 
@@ -616,7 +630,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
616
630
  _allocateTarget() {
617
631
 
618
632
  const size = this._cubeSize;
619
- @@ -38245,7 +38540,122 @@ class PMREMGenerator {
633
+ @@ -38245,8 +38554,206 @@ class PMREMGenerator {
620
634
 
621
635
  }
622
636
 
@@ -692,7 +706,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
692
706
  + try {
693
707
  +
694
708
  + renderer.setMRT( null );
695
- +
709
+
696
710
  + // mipmaps are generated during the last face's render(), as in CubeCamera.update()
697
711
  + if ( face === 5 ) target.texture.mipmapsAutoUpdate = mipmapsAutoUpdate;
698
712
  +
@@ -737,13 +751,33 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
737
751
  + * @return {Promise<void>} A Promise that resolves when the source cubemap is complete.
738
752
  + */
739
753
  + async _textureToCubemapAsync( texture ) {
740
-
741
- let material;
742
-
743
- @@ -38273,6 +38683,89 @@ class PMREMGenerator {
744
-
745
- _uniformsMap.get( material ).envMap.value = texture;
746
-
754
+ +
755
+ + let material;
756
+ +
757
+ + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
758
+ +
759
+ + if ( this._cubemapMaterial === null ) {
760
+ +
761
+ + this._cubemapMaterial = _getCubemapMaterial();
762
+ +
763
+ + }
764
+ +
765
+ + material = this._cubemapMaterial;
766
+ +
767
+ + } else {
768
+ +
769
+ + if ( this._equirectMaterial === null ) {
770
+ +
771
+ + this._equirectMaterial = _getEquirectMaterial();
772
+ +
773
+ + }
774
+ +
775
+ + material = this._equirectMaterial;
776
+ +
777
+ + }
778
+ +
779
+ + _uniformsMap.get( material ).envMap.value = texture;
780
+ +
747
781
  + await this._renderCubeAsync( this._getSourceTarget(), 0, material );
748
782
  +
749
783
  + }
@@ -801,36 +835,10 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
801
835
  + }
802
836
  +
803
837
  + _textureToCubemap( texture ) {
804
- + let material;
805
- +
806
- + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
807
- +
808
- + if ( this._cubemapMaterial === null ) {
809
- +
810
- + this._cubemapMaterial = _getCubemapMaterial();
811
- +
812
- + }
813
- +
814
- + material = this._cubemapMaterial;
815
- +
816
- + } else {
817
- +
818
- + if ( this._equirectMaterial === null ) {
819
- +
820
- + this._equirectMaterial = _getEquirectMaterial();
821
- +
822
- + }
823
- +
824
- + material = this._equirectMaterial;
825
- +
826
- + }
827
- +
828
- + _uniformsMap.get( material ).envMap.value = texture;
829
- +
830
- this._renderCube( this._getSourceTarget(), 0, material );
838
+ let material;
831
839
 
832
- }
833
- @@ -38480,6 +38973,39 @@ function _getEquirectMaterial() {
840
+ if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
841
+ @@ -38480,6 +38987,39 @@ function _getEquirectMaterial() {
834
842
  }
835
843
 
836
844
  const _cache = new WeakMap();
@@ -870,7 +878,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
870
878
 
871
879
  /**
872
880
  * Generates a PMREM from the given texture.
873
- @@ -38493,6 +39019,14 @@ const _cache = new WeakMap();
881
+ @@ -38493,6 +39033,14 @@ const _cache = new WeakMap();
874
882
  function _getPMREMFromTexture( texture, renderer, generator ) {
875
883
 
876
884
  const cache = _getCache( renderer );
@@ -885,7 +893,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
885
893
 
886
894
  let renderTarget = cache.get( texture );
887
895
 
888
- @@ -38501,6 +39035,25 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
896
+ @@ -38501,6 +39049,25 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
889
897
  if ( pmremVersion !== texture.pmremVersion ) {
890
898
 
891
899
  const image = texture.image;
@@ -911,7 +919,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
911
919
 
912
920
  if ( texture.isCubeTexture ) {
913
921
 
914
- @@ -38531,29 +39084,7 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
922
+ @@ -38531,29 +39098,7 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
915
923
 
916
924
  renderTarget.texture.pmremVersion = texture.pmremVersion;
917
925
 
@@ -942,7 +950,7 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
942
950
 
943
951
  //
944
952
 
945
- @@ -38696,6 +39227,118 @@ class PMREMNode extends Node {
953
+ @@ -38696,6 +39241,118 @@ class PMREMNode extends Node {
946
954
 
947
955
  }
948
956
 
@@ -1061,8 +1069,18 @@ index 7c8d2322834904c1247c79cda31beff8e2bfc497..aa718836287becc1fa9c959ca616ac46
1061
1069
  set value( value ) {
1062
1070
 
1063
1071
  this._value = value;
1072
+ @@ -38758,6 +39415,9 @@ class PMREMNode extends Node {
1073
+
1074
+ this._pmrem = pmrem;
1075
+
1076
+ + // count the swap, so every settled object that samples this node refreshes once (NodeMaterialObserver)
1077
+ + if ( this._texture.value !== pmrem && frame.renderer ) frame.renderer._tnPmremSwaps = ( frame.renderer._tnPmremSwaps || 0 ) + 1;
1078
+ +
1079
+ this.updateFromTexture( pmrem );
1080
+
1081
+ }
1064
1082
  diff --git a/build/three.webgpu.js b/build/three.webgpu.js
1065
- index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5d4d882ed 100644
1083
+ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..a458a6d75ee95fdb9913222f4ed31c5c3cc56b09 100644
1066
1084
  --- a/build/three.webgpu.js
1067
1085
  +++ b/build/three.webgpu.js
1068
1086
  @@ -5182,7 +5182,7 @@ class Animation {
@@ -1119,7 +1137,15 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1119
1137
  return hashArray( _cacheKeyValues$1 );
1120
1138
 
1121
1139
  }
1122
- @@ -6947,6 +6957,14 @@ class Geometries extends DataMap {
1140
+ @@ -6485,6 +6495,7 @@ class RenderObjects {
1141
+ this.pipelines.delete( renderObject );
1142
+ this.bindings.deleteForRender( renderObject );
1143
+ this.nodes.delete( renderObject );
1144
+ + this.geometries.releaseRenderObject( renderObject );
1145
+
1146
+ chainMap.delete( renderObject.getChainArray() );
1147
+
1148
+ @@ -6947,6 +6958,17 @@ class Geometries extends DataMap {
1123
1149
  */
1124
1150
  this._registry = new FinalizationRegistry( ( ref ) => this._tracked.delete( ref ) );
1125
1151
 
@@ -1130,14 +1156,19 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1130
1156
  + * @type {WeakMap<RenderObject,Map<BufferAttribute,number>>}
1131
1157
  + */
1132
1158
  + this._settledAttributes = new WeakMap();
1159
+ + this._geometryAttributeOwners = new WeakMap();
1160
+ + this._sharedAttributeOwners = new WeakMap();
1161
+ + this._renderObjectAttributeGeometry = new WeakMap();
1133
1162
  +
1134
1163
  }
1135
1164
 
1136
1165
  /**
1137
- @@ -6972,10 +6990,69 @@ class Geometries extends DataMap {
1166
+ @@ -6971,11 +6993,173 @@ class Geometries extends DataMap {
1167
+ const geometry = renderObject.geometry;
1138
1168
 
1139
1169
  if ( this.has( geometry ) === false ) this.initGeometry( geometry );
1140
-
1170
+ + if ( this.geometryAttributesChanged( renderObject ) ) this.syncGeometryAttributes( renderObject );
1171
+ +
1141
1172
  + // A settled static object has no attribute that could have changed since the last refresh,
1142
1173
  + // unless a writer bumped one. An InstancedMesh's instance buffer is a vertex attribute of
1143
1174
  + // this draw, and a BufferGeometry carries no version of its own to announce the write, so
@@ -1146,7 +1177,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1146
1177
  + const monitor = renderObject.getMonitor();
1147
1178
  +
1148
1179
  + if ( monitor !== undefined && monitor.isSettled( renderObject ) === true && this.attributesChanged( renderObject ) === false ) return;
1149
- +
1180
+
1150
1181
  this.updateAttributes( renderObject );
1151
1182
 
1152
1183
  }
@@ -1164,13 +1195,18 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1164
1195
  + const index = this.getIndex( renderObject );
1165
1196
  + const settled = this._settledAttributes.get( renderObject );
1166
1197
  +
1167
- + if ( settled !== undefined && settled.size === attributes.length + ( index === null ? 0 : 1 ) ) {
1198
+ + if ( settled !== undefined && settled.attributes.length === attributes.length && settled.index === index ) {
1168
1199
  +
1169
1200
  + let changed = false;
1170
1201
  +
1171
- + for ( const attribute of attributes ) {
1202
+ + for ( let i = 0; i < attributes.length; i ++ ) {
1172
1203
  +
1173
- + if ( settled.get( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) !== attribute.version ) {
1204
+ + const attribute = attributes[ i ];
1205
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
1206
+ + const previous = settled.attributes[ i ];
1207
+ +
1208
+ + // an interleaved wrapper has no version of its own: its buffer's version is the write signal
1209
+ + if ( previous.attribute !== attribute || previous.data !== data || previous.version !== data.version ) {
1174
1210
  +
1175
1211
  + changed = true;
1176
1212
  + break;
@@ -1179,32 +1215,156 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1179
1215
  +
1180
1216
  + }
1181
1217
  +
1182
- + if ( changed === false && ( index === null || settled.get( index ) === index.version ) ) return false;
1218
+ + if ( changed === false && ( index === null || settled.indexVersion === index.version ) ) return false;
1219
+ +
1220
+ + }
1221
+ +
1222
+ + const versions = attributes.map( ( attribute ) => {
1223
+ +
1224
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
1225
+ + return { attribute, data, version: data.version };
1226
+ +
1227
+ + } );
1228
+ +
1229
+ + this._settledAttributes.set( renderObject, { attributes: versions, index, indexVersion: index === null ? undefined : index.version } );
1230
+ +
1231
+ + return true;
1232
+ +
1233
+ + }
1234
+ +
1235
+ + /** Compare the published attribute identities without allocating on settled frames. */
1236
+ + geometryAttributesChanged( renderObject ) {
1237
+ +
1238
+ + const geometry = renderObject.geometry;
1239
+ + const owner = this._geometryAttributeOwners.get( geometry )?.get( renderObject );
1240
+ + if ( owner === undefined || owner.index !== geometry.index ) return true;
1241
+ +
1242
+ + const attributes = renderObject.getAttributes();
1243
+ + if ( owner.attributes.length !== attributes.length ) return true;
1244
+ + for ( let i = 0; i < attributes.length; i ++ ) {
1245
+ + const attribute = attributes[ i ];
1246
+ + if ( owner.attributes[ i ] !== ( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) ) return true;
1247
+ + }
1248
+ +
1249
+ + return false;
1250
+ +
1251
+ + }
1252
+ +
1253
+ + /** Add this render object's current geometry attributes to the renderer's shared-resource owners. */
1254
+ + syncGeometryAttributes( renderObject ) {
1183
1255
  +
1256
+ + const { geometry } = renderObject;
1257
+ + const previousGeometry = this._renderObjectAttributeGeometry.get( renderObject );
1258
+ + if ( previousGeometry !== undefined && previousGeometry !== geometry ) this.releaseRenderObject( renderObject );
1259
+ + this._renderObjectAttributeGeometry.set( renderObject, geometry );
1260
+ + let geometryOwners = this._geometryAttributeOwners.get( geometry );
1261
+ +
1262
+ + if ( geometryOwners === undefined ) {
1263
+ + geometryOwners = new Map();
1264
+ + this._geometryAttributeOwners.set( geometry, geometryOwners );
1184
1265
  + }
1185
1266
  +
1186
- + const versions = new Map();
1267
+ + const previous = geometryOwners.get( renderObject )?.keys ?? new Map();
1268
+ + const current = new Map();
1269
+ + const attributes = renderObject.getAttributes();
1270
+ + const attributeKeys = [];
1187
1271
  +
1188
1272
  + for ( const attribute of attributes ) {
1273
+ + const key = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
1274
+ + current.set( key, true );
1275
+ + attributeKeys.push( key );
1276
+ + }
1277
+ + const index = geometry.index;
1278
+ + if ( index !== null ) current.set( index, true );
1279
+ +
1280
+ + for ( const key of current.keys() ) {
1281
+ + let record = this._sharedAttributeOwners.get( key );
1282
+ + if ( record === undefined ) record = { owners: new Set() };
1283
+ + if ( previous.has( key ) === false ) record.owners.add( renderObject );
1284
+ + this._sharedAttributeOwners.set( key, record );
1285
+ + }
1189
1286
  +
1190
- + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
1287
+ + for ( const key of previous.keys() ) {
1288
+ + if ( current.has( key ) === false ) this.releaseSharedAttribute( key, renderObject );
1289
+ + }
1191
1290
  +
1192
- + versions.set( data, data.version );
1291
+ + geometryOwners.set( renderObject, { keys: current, attributes: attributeKeys, index } );
1193
1292
  +
1293
+ + }
1294
+ +
1295
+ + /** Drop a render object from its geometry before its material-owned node attributes go stale. */
1296
+ + releaseRenderObject( renderObject ) {
1297
+ +
1298
+ + const geometry = this._renderObjectAttributeGeometry.get( renderObject );
1299
+ + if ( geometry === undefined ) return;
1300
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
1301
+ + const owned = geometryOwners?.get( renderObject )?.keys;
1302
+ + if ( owned !== undefined ) {
1303
+ + for ( const key of owned.keys() ) this.releaseSharedAttribute( key, renderObject );
1304
+ + geometryOwners.delete( renderObject );
1305
+ + if ( geometryOwners.size === 0 ) this._geometryAttributeOwners.delete( geometry );
1194
1306
  + }
1307
+ + this._renderObjectAttributeGeometry.delete( renderObject );
1195
1308
  +
1196
- + if ( index !== null ) versions.set( index, index.version );
1309
+ + }
1197
1310
  +
1198
- + this._settledAttributes.set( renderObject, versions );
1311
+ + /** Release a shared GPU resource only after its last live geometry render object lets it go. */
1312
+ + releaseSharedAttribute( key, owner ) {
1199
1313
  +
1200
- + return true;
1314
+ + const record = this._sharedAttributeOwners.get( key );
1315
+ + if ( record === undefined ) return;
1316
+ + record.owners.delete( owner );
1317
+ + if ( record.owners.size !== 0 ) return;
1318
+ +
1319
+ + this.attributes.delete( key );
1320
+ + this._sharedAttributeOwners.delete( key );
1321
+ +
1322
+ + }
1323
+ +
1324
+ + /** Release the recorded sets, not a potentially replaced render object's current attributes. */
1325
+ + releaseGeometryAttributes( geometry ) {
1326
+ +
1327
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
1328
+ + if ( geometryOwners === undefined ) return;
1329
+ + for ( const [ owner, attributes ] of geometryOwners ) {
1330
+ + for ( const key of attributes.keys.keys() ) this.releaseSharedAttribute( key, owner );
1331
+ + this._renderObjectAttributeGeometry.delete( owner );
1332
+ + }
1333
+ + this._geometryAttributeOwners.delete( geometry );
1201
1334
  +
1202
1335
  + }
1203
1336
  +
1204
1337
  /**
1205
1338
  * Initializes the given geometry.
1206
1339
  *
1207
- @@ -7100,8 +7177,10 @@ class Geometries extends DataMap {
1340
+ @@ -6993,23 +7177,10 @@ class Geometries extends DataMap {
1341
+
1342
+ this.info.memory.geometries --;
1343
+
1344
+ - // index
1345
+ -
1346
+ - const index = geometry.index;
1347
+ -
1348
+ - if ( index !== null ) {
1349
+ + // index and geometry attributes: release this geometry's owners, so a buffer another
1350
+ + // geometry still draws stays alive until its last owner lets it go
1351
+
1352
+ - this.attributes.delete( index );
1353
+ -
1354
+ - }
1355
+ -
1356
+ - // geometry attributes
1357
+ -
1358
+ - for ( const attribute of Object.values( geometry.attributes ) ) {
1359
+ -
1360
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
1361
+ -
1362
+ - }
1363
+ + this.releaseGeometryAttributes( geometry );
1364
+
1365
+ // wireframe attributes
1366
+
1367
+ @@ -7100,8 +7271,10 @@ class Geometries extends DataMap {
1208
1368
  const callId = this.info.render.calls;
1209
1369
 
1210
1370
  const bufferAttribute = this.backend.getBufferAttribute( attribute );
@@ -1216,7 +1376,27 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1216
1376
 
1217
1377
  this.attributes.update( bufferAttribute, type );
1218
1378
 
1219
- @@ -8688,7 +8767,7 @@ class Bindings extends DataMap {
1379
+ @@ -7185,17 +7358,9 @@ class Geometries extends DataMap {
1380
+ */
1381
+ deleteNodeAttributes( renderObject ) {
1382
+
1383
+ - const currentAttributes = new Set( Object.values( renderObject.geometry.attributes ) );
1384
+ + // node attributes can be shared with other render objects: release this object's owners
1385
+
1386
+ - for ( const attribute of renderObject.getAttributes() ) {
1387
+ -
1388
+ - if ( currentAttributes.has( attribute ) === false ) {
1389
+ -
1390
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
1391
+ -
1392
+ - }
1393
+ -
1394
+ - }
1395
+ + this.releaseRenderObject( renderObject );
1396
+
1397
+ }
1398
+
1399
+ @@ -8688,7 +8853,7 @@ class Bindings extends DataMap {
1220
1400
  */
1221
1401
  updateForRender( renderObject ) {
1222
1402
 
@@ -1225,7 +1405,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1225
1405
 
1226
1406
  }
1227
1407
 
1228
- @@ -8786,10 +8865,16 @@ class Bindings extends DataMap {
1408
+ @@ -8786,10 +8951,16 @@ class Bindings extends DataMap {
1229
1409
 
1230
1410
  } else if ( binding.isSampledTexture ) {
1231
1411
 
@@ -1242,7 +1422,29 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1242
1422
  binding.samplerKey = this.textures.updateSampler( binding );
1243
1423
 
1244
1424
  } else if ( binding.isStorageBuffer ) {
1245
- @@ -8886,12 +8971,13 @@ class Bindings extends DataMap {
1425
+ @@ -8834,6 +9005,21 @@ class Bindings extends DataMap {
1426
+
1427
+ if ( groupData.usedTimes === 0 ) {
1428
+
1429
+ + // Stop disposed bind groups from being invalidated by later texture disposal:
1430
+ + // untrack every texture the group was ever tracked on, not only its current one.
1431
+ + const bindingData = this.backend.get( bindGroup );
1432
+ + if ( bindingData.trackedTextures ) {
1433
+ +
1434
+ + for ( const textureData of bindingData.trackedTextures ) {
1435
+ +
1436
+ + textureData.bindGroups.delete( bindGroup );
1437
+ +
1438
+ + }
1439
+ +
1440
+ + bindingData.trackedTextures.clear();
1441
+ +
1442
+ + }
1443
+ +
1444
+ for ( const binding of bindGroup.bindings ) {
1445
+
1446
+ if ( binding.isUniformBuffer ) {
1447
+ @@ -8886,12 +9072,13 @@ class Bindings extends DataMap {
1246
1448
  * Updates the given array of bindings.
1247
1449
  *
1248
1450
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -1258,7 +1460,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1258
1460
 
1259
1461
  }
1260
1462
 
1261
- @@ -8902,11 +8988,27 @@ class Bindings extends DataMap {
1463
+ @@ -8902,12 +9089,32 @@ class Bindings extends DataMap {
1262
1464
  *
1263
1465
  * @param {BindGroup} bindGroup - The bind group to update.
1264
1466
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -1269,6 +1471,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1269
1471
 
1270
1472
  const { backend } = this;
1271
1473
 
1474
+ - let needsBindingsUpdate = false;
1272
1475
  + // A group a node added after this object's first draw has no buffers and no layout yet, and
1273
1476
  + // the pipeline reads that layout whatever this draw decides to do with it - so it is built
1274
1477
  + // here, on every draw. A group that did not exist cannot have been written either, so it is
@@ -1284,15 +1487,20 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1284
1487
  + // a settled object keeps the values it uploaded the last time it refreshed, so an object
1285
1488
  + // group it has already written is the one thing in here it may skip
1286
1489
  +
1287
- let needsBindingsUpdate = false;
1490
+ + // a destroyed texture dropped this group's cached GPU groups: rebuild it even if no binding reports a change
1491
+ + const bindingsData = backend.get( bindGroup );
1492
+ + const forceBindingsUpdate = bindingsData.forceUpdate === true;
1493
+ +
1494
+ + let needsBindingsUpdate = forceBindingsUpdate;
1288
1495
  let cacheBindings = true;
1289
1496
  let cacheKeyLength = 0;
1290
- @@ -8916,12 +9018,32 @@ class Bindings extends DataMap {
1497
+ let version = 0;
1498
+ @@ -8916,12 +9123,32 @@ class Bindings extends DataMap {
1291
1499
 
1292
1500
  for ( const binding of bindGroup.bindings ) {
1293
1501
 
1294
1502
  - const updatedGroup = this.nodes.updateGroup( binding );
1295
- + const updatedGroup = this.nodes.updateGroup( binding, settled );
1503
+ + const updatedGroup = forceBindingsUpdate || this.nodes.updateGroup( binding, settled );
1296
1504
 
1297
1505
  // every uniforms group is a uniform buffer. So if no update is required,
1298
1506
  // we move one with the next binding. Otherwise the next if block will update the group.
@@ -1322,7 +1530,38 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1322
1530
 
1323
1531
  //
1324
1532
 
1325
- @@ -10053,7 +10175,8 @@ class RenderContexts {
1533
+ @@ -8989,12 +9216,20 @@ class Bindings extends DataMap {
1534
+
1535
+ }
1536
+
1537
+ - // keep track which bind groups refer to the current texture (this is needed for dispose)
1538
+ + }
1539
+ +
1540
+ + // keep track which bind groups refer to the current texture (this is needed for dispose),
1541
+ + // also when the binding's first update reported no change: a destroy must reach this group
1542
+
1543
+ - texturesTextureData.bindGroups.add( bindGroup );
1544
+ + texturesTextureData.bindGroups.add( bindGroup );
1545
+ + if ( bindingsData.trackedTextures === undefined ) {
1546
+ +
1547
+ + bindingsData.trackedTextures = new Set();
1548
+
1549
+ }
1550
+
1551
+ + bindingsData.trackedTextures.add( texturesTextureData );
1552
+ +
1553
+ const textureData = backend.get( texture );
1554
+
1555
+ if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) {
1556
+ @@ -9061,6 +9296,7 @@ class Bindings extends DataMap {
1557
+ const cacheKey = cacheBindings ? _cacheKeyIds.join( ',' ) : '';
1558
+
1559
+ this.backend.updateBindings( bindGroup, bindings, cacheKey, version );
1560
+ + bindingsData.forceUpdate = false;
1561
+
1562
+ }
1563
+
1564
+ @@ -10053,7 +10289,8 @@ class RenderContexts {
1326
1565
 
1327
1566
  }
1328
1567
 
@@ -1332,7 +1571,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1332
1571
 
1333
1572
  renderState.clearDepthValue = this.renderer.getClearDepth();
1334
1573
  renderState.clearStencilValue = this.renderer.getClearStencil();
1335
- @@ -10135,6 +10258,10 @@ class Textures extends DataMap {
1574
+ @@ -10135,6 +10372,10 @@ class Textures extends DataMap {
1336
1575
  * @type {Set<HTMLTexture>}
1337
1576
  */
1338
1577
  this._htmlTextures = new Set();
@@ -1343,7 +1582,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1343
1582
 
1344
1583
  /**
1345
1584
  * Stores weak references to the textures and render targets
1346
- @@ -10162,6 +10289,12 @@ class Textures extends DataMap {
1585
+ @@ -10162,6 +10403,12 @@ class Textures extends DataMap {
1347
1586
  */
1348
1587
  dispose() {
1349
1588
 
@@ -1356,7 +1595,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1356
1595
  for ( const ref of this._tracked ) {
1357
1596
 
1358
1597
  const object = ref.deref();
1359
- @@ -10339,7 +10472,16 @@ class Textures extends DataMap {
1598
+ @@ -10339,7 +10586,16 @@ class Textures extends DataMap {
1360
1599
  */
1361
1600
  updateTexture( texture, options = {} ) {
1362
1601
 
@@ -1373,7 +1612,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1373
1612
  if ( textureData.initialized === true && textureData.version === texture.version ) return textureData.generation;
1374
1613
 
1375
1614
  // render target textures are created with their render target
1376
- @@ -10354,6 +10496,8 @@ class Textures extends DataMap {
1615
+ @@ -10354,6 +10610,8 @@ class Textures extends DataMap {
1377
1616
 
1378
1617
  }
1379
1618
 
@@ -1382,7 +1621,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1382
1621
  const isRenderTarget = texture.isRenderTargetTexture || texture.isDepthTexture || texture.isFramebufferTexture;
1383
1622
  const backend = this.backend;
1384
1623
 
1385
- @@ -10363,6 +10507,21 @@ class Textures extends DataMap {
1624
+ @@ -10363,6 +10621,22 @@ class Textures extends DataMap {
1386
1625
 
1387
1626
  backend.destroyTexture( texture );
1388
1627
 
@@ -1396,6 +1635,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1396
1635
  +
1397
1636
  + bindingsData.groups = undefined;
1398
1637
  + bindingsData.versions = undefined;
1638
+ + bindingsData.forceUpdate = true;
1399
1639
  +
1400
1640
  + }
1401
1641
  +
@@ -1404,13 +1644,14 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1404
1644
  }
1405
1645
 
1406
1646
  //
1407
- @@ -10502,9 +10661,18 @@ class Textures extends DataMap {
1647
+ @@ -10502,9 +10776,18 @@ class Textures extends DataMap {
1408
1648
 
1409
1649
  if ( texture.source.dataReady === true ) {
1410
1650
 
1411
1651
  - backend.updateTexture( texture, options );
1412
1652
  + if ( upload ) {
1413
- +
1653
+
1654
+ - texture.clearUpdateRanges();
1414
1655
  + this._initializeTexture( texture, textureData );
1415
1656
  + uploadPromise = upload( texture, options );
1416
1657
  +
@@ -1419,13 +1660,12 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1419
1660
  + backend.updateTexture( texture, options );
1420
1661
  +
1421
1662
  + texture.clearUpdateRanges();
1422
-
1423
- - texture.clearUpdateRanges();
1663
+ +
1424
1664
  + }
1425
1665
 
1426
1666
  }
1427
1667
 
1428
- @@ -10514,7 +10682,7 @@ class Textures extends DataMap {
1668
+ @@ -10514,7 +10797,7 @@ class Textures extends DataMap {
1429
1669
 
1430
1670
  }
1431
1671
 
@@ -1434,7 +1674,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1434
1674
 
1435
1675
  }
1436
1676
 
1437
- @@ -10531,6 +10699,20 @@ class Textures extends DataMap {
1677
+ @@ -10531,6 +10814,20 @@ class Textures extends DataMap {
1438
1678
 
1439
1679
  }
1440
1680
 
@@ -1455,7 +1695,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1455
1695
  // dispose handler
1456
1696
 
1457
1697
  if ( textureData.initialized !== true ) {
1458
- @@ -10573,11 +10755,119 @@ class Textures extends DataMap {
1698
+ @@ -10573,11 +10870,119 @@ class Textures extends DataMap {
1459
1699
 
1460
1700
  }
1461
1701
 
@@ -1578,7 +1818,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1578
1818
 
1579
1819
  }
1580
1820
 
1581
- @@ -10649,7 +10939,11 @@ class Textures extends DataMap {
1821
+ @@ -10649,7 +11054,11 @@ class Textures extends DataMap {
1582
1822
 
1583
1823
  } else {
1584
1824
 
@@ -1591,7 +1831,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1591
1831
 
1592
1832
  }
1593
1833
 
1594
- @@ -10762,6 +11056,8 @@ class Textures extends DataMap {
1834
+ @@ -10762,6 +11171,8 @@ class Textures extends DataMap {
1595
1835
  */
1596
1836
  _destroyTexture( texture ) {
1597
1837
 
@@ -1600,7 +1840,15 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1600
1840
  if ( this.has( texture ) === true ) {
1601
1841
 
1602
1842
  const textureData = this.get( texture );
1603
- @@ -13129,7 +13425,7 @@ class NodeBuilder {
1843
+ @@ -10791,6 +11202,7 @@ class Textures extends DataMap {
1844
+
1845
+ bindingsData.groups = undefined;
1846
+ bindingsData.versions = undefined;
1847
+ + bindingsData.forceUpdate = true;
1848
+
1849
+ // go through all bindings and if one points to the destroyed texture, trigger dispose as well
1850
+
1851
+ @@ -13129,7 +13541,7 @@ class NodeBuilder {
1604
1852
 
1605
1853
  let bindGroup = new BindGroup( groupName, bindings );
1606
1854
 
@@ -1609,7 +1857,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1609
1857
 
1610
1858
  bindGroup = this.renderer._bindings.getSharedBindGroup( bindGroup );
1611
1859
 
1612
- @@ -16304,7 +16600,7 @@ class NodeBuilder {
1860
+ @@ -16304,7 +16716,7 @@ class NodeBuilder {
1613
1861
 
1614
1862
  const mrt = this.renderer.getMRT();
1615
1863
 
@@ -1618,7 +1866,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1618
1866
 
1619
1867
  }
1620
1868
 
1621
- @@ -17783,15 +18079,17 @@ class NodeManager extends DataMap {
1869
+ @@ -17783,15 +18195,17 @@ class NodeManager extends DataMap {
1622
1870
  * Returns `true` if the given node uniforms group must be updated or not.
1623
1871
  *
1624
1872
  * @param {NodeUniformsGroup} nodeUniformsGroup - The node uniforms group.
@@ -1639,7 +1887,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1639
1887
 
1640
1888
  // check for update
1641
1889
 
1642
- @@ -18742,6 +19040,21 @@ class NodeManager extends DataMap {
1890
+ @@ -18742,6 +19156,21 @@ class NodeManager extends DataMap {
1643
1891
 
1644
1892
  }
1645
1893
 
@@ -1661,7 +1909,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1661
1909
  /**
1662
1910
  * Triggers the call of `updateBefore()` methods
1663
1911
  * for all nodes of the given render object.
1664
- @@ -18751,9 +19064,14 @@ class NodeManager extends DataMap {
1912
+ @@ -18751,9 +19180,14 @@ class NodeManager extends DataMap {
1665
1913
  updateBefore( renderObject ) {
1666
1914
 
1667
1915
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -1676,7 +1924,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1676
1924
  // update frame state for each node
1677
1925
 
1678
1926
  this.getNodeFrameForRender( renderObject ).updateBeforeNode( node );
1679
- @@ -18771,10 +19089,11 @@ class NodeManager extends DataMap {
1927
+ @@ -18771,10 +19205,11 @@ class NodeManager extends DataMap {
1680
1928
  updateAfter( renderObject ) {
1681
1929
 
1682
1930
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -1689,7 +1937,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1689
1937
 
1690
1938
  this.getNodeFrameForRender( renderObject ).updateAfterNode( node );
1691
1939
 
1692
- @@ -18851,9 +19170,14 @@ class NodeManager extends DataMap {
1940
+ @@ -18851,9 +19286,14 @@ class NodeManager extends DataMap {
1693
1941
 
1694
1942
  const nodeFrame = this.getNodeFrameForRender( renderObject );
1695
1943
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -1704,7 +1952,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1704
1952
  nodeFrame.updateNode( node );
1705
1953
 
1706
1954
  }
1707
- @@ -22707,6 +23031,14 @@ class Renderer {
1955
+ @@ -22707,6 +23147,14 @@ class Renderer {
1708
1956
  */
1709
1957
  this._bundles = null;
1710
1958
 
@@ -1719,7 +1967,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1719
1967
  /**
1720
1968
  * A reference to a renderer module for managing render lists.
1721
1969
  *
1722
- @@ -24638,6 +24970,18 @@ class Renderer {
1970
+ @@ -24638,6 +25086,18 @@ class Renderer {
1723
1971
 
1724
1972
  }
1725
1973
 
@@ -1738,7 +1986,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1738
1986
  /**
1739
1987
  * Can be used to transfer buffer data from a storage buffer attribute
1740
1988
  * from the GPU to the CPU in context of compute shaders.
1741
- @@ -25675,6 +26019,34 @@ class Renderer {
1989
+ @@ -25675,6 +26135,34 @@ class Renderer {
1742
1990
 
1743
1991
  }
1744
1992
 
@@ -1773,7 +2021,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1773
2021
  /**
1774
2022
  * Initializes the given render target.
1775
2023
  *
1776
- @@ -25999,7 +26371,8 @@ class Renderer {
2024
+ @@ -25999,7 +26487,8 @@ class Renderer {
1777
2025
  version,
1778
2026
  colorNode,
1779
2027
  depthNode,
@@ -1783,7 +2031,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1783
2031
  };
1784
2032
 
1785
2033
  this._cacheShadowNodes.set( material, cache );
1786
- @@ -26148,6 +26521,8 @@ class Renderer {
2034
+ @@ -26148,6 +26637,8 @@ class Renderer {
1787
2035
  let materialDisplacementMap;
1788
2036
  let materialDisplacementScale;
1789
2037
  let materialDisplacementBias;
@@ -1792,7 +2040,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1792
2040
 
1793
2041
  const previousSourceMaterial = this._currentSourceMaterial;
1794
2042
 
1795
- @@ -26173,6 +26548,8 @@ class Renderer {
2043
+ @@ -26173,6 +26664,8 @@ class Renderer {
1796
2044
  materialDisplacementMap = overrideMaterial.displacementMap;
1797
2045
  materialDisplacementScale = overrideMaterial.displacementScale;
1798
2046
  materialDisplacementBias = overrideMaterial.displacementBias;
@@ -1801,7 +2049,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1801
2049
 
1802
2050
  if ( material.positionNode && material.positionNode.isNode ) {
1803
2051
 
1804
- @@ -26191,7 +26568,7 @@ class Renderer {
2052
+ @@ -26191,7 +26684,7 @@ class Renderer {
1805
2053
 
1806
2054
  if ( overrideMaterial.isShadowPassMaterial ) {
1807
2055
 
@@ -1810,7 +2058,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1810
2058
 
1811
2059
  if ( this.shadowMap.type === VSMShadowMap ) {
1812
2060
 
1813
- @@ -26203,6 +26580,7 @@ class Renderer {
2061
+ @@ -26203,6 +26696,7 @@ class Renderer {
1814
2062
 
1815
2063
  }
1816
2064
 
@@ -1818,7 +2066,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1818
2066
  if ( colorNode !== null ) overrideMaterial.colorNode = colorNode;
1819
2067
  if ( depthNode !== null ) overrideMaterial.depthNode = depthNode;
1820
2068
  if ( positionNode !== null ) overrideMaterial.positionNode = positionNode;
1821
- @@ -26242,6 +26620,8 @@ class Renderer {
2069
+ @@ -26242,6 +26736,8 @@ class Renderer {
1822
2070
  scene.overrideMaterial.displacementMap = materialDisplacementMap;
1823
2071
  scene.overrideMaterial.displacementScale = materialDisplacementScale;
1824
2072
  scene.overrideMaterial.displacementBias = materialDisplacementBias;
@@ -1827,15 +2075,14 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1827
2075
 
1828
2076
  }
1829
2077
 
1830
- @@ -26303,25 +26683,18 @@ class Renderer {
2078
+ @@ -26303,25 +26799,18 @@ class Renderer {
1831
2079
 
1832
2080
  //
1833
2081
 
1834
2082
  - const refreshType = this._nodes.needsRefresh( renderObject );
1835
2083
  -
1836
2084
  - if ( refreshType === RenderObjectRefreshType.FULL ) {
1837
- + this._nodes.needsRefresh( renderObject );
1838
-
2085
+ -
1839
2086
  - this._nodes.updateBefore( renderObject );
1840
2087
  -
1841
2088
  - this._geometries.updateForRender( renderObject );
@@ -1846,7 +2093,8 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1846
2093
  - } else if ( refreshType === RenderObjectRefreshType.SHARED ) {
1847
2094
  -
1848
2095
  - this._nodes.updateBefore( renderObject );
1849
- -
2096
+ + this._nodes.needsRefresh( renderObject );
2097
+
1850
2098
  - this._nodes.updateForRender( renderObject );
1851
2099
  - this._bindings.updateSharedForRender( renderObject );
1852
2100
  -
@@ -1864,7 +2112,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1864
2112
 
1865
2113
  this._pipelines.updateForRender( renderObject );
1866
2114
 
1867
- @@ -26331,7 +26704,7 @@ class Renderer {
2115
+ @@ -26331,7 +26820,7 @@ class Renderer {
1868
2116
 
1869
2117
  this.backend.draw( renderObject, this.info );
1870
2118
 
@@ -1873,7 +2121,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1873
2121
 
1874
2122
  } else if ( this._currentRenderBundle !== null ) {
1875
2123
 
1876
- @@ -40878,6 +41251,9 @@ class WebGPUTextureUtils {
2124
+ @@ -40878,6 +41367,9 @@ class WebGPUTextureUtils {
1877
2125
  */
1878
2126
  this._samplerCache = new Map();
1879
2127
 
@@ -1883,7 +2131,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1883
2131
  }
1884
2132
 
1885
2133
  /**
1886
- @@ -41110,7 +41486,12 @@ class WebGPUTextureUtils {
2134
+ @@ -41110,7 +41602,12 @@ class WebGPUTextureUtils {
1887
2135
 
1888
2136
  }
1889
2137
 
@@ -1897,7 +2145,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1897
2145
 
1898
2146
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
1899
2147
 
1900
- @@ -41216,6 +41597,23 @@ class WebGPUTextureUtils {
2148
+ @@ -41216,6 +41713,23 @@ class WebGPUTextureUtils {
1901
2149
  destroyTexture( texture, isDefaultTexture = false ) {
1902
2150
 
1903
2151
  const backend = this.backend;
@@ -1921,7 +2169,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1921
2169
  const textureData = backend.get( texture );
1922
2170
 
1923
2171
  if ( textureData.texture !== undefined && isDefaultTexture === false && texture.isExternalTexture !== true && textureData.externalTexture !== true ) textureData.texture.destroy();
1924
- @@ -41311,64 +41709,59 @@ class WebGPUTextureUtils {
2172
+ @@ -41311,64 +41825,59 @@ class WebGPUTextureUtils {
1925
2173
  const canvasTarget = backend.renderer.getCanvasTarget();
1926
2174
  const { width, height } = backend.getDrawingBufferSize();
1927
2175
  const samples = backend.renderer.currentSamples;
@@ -1973,12 +2221,12 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
1973
2221
  - if ( depthTextureGPU !== undefined ) {
1974
2222
  -
1975
2223
  - if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type && depthTexture.samples === samples ) {
1976
- -
1977
- - return depthTextureGPU;
1978
2224
  + // Output and direct overlay passes alternate effective samples 4 and 1.
1979
2225
  + // Retain at most those two buffers for this canvas size and depth format.
1980
2226
  + let buffer = cache.textures.get( sampleCount );
1981
2227
 
2228
+ - return depthTextureGPU;
2229
+ -
1982
2230
  - }
1983
2231
  + if ( buffer === undefined ) {
1984
2232
 
@@ -2014,7 +2262,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2014
2262
  /**
2015
2263
  * Uploads the updated texture data to the GPU.
2016
2264
  *
2017
- @@ -41531,6 +41924,143 @@ class WebGPUTextureUtils {
2265
+ @@ -41531,6 +42040,143 @@ class WebGPUTextureUtils {
2018
2266
 
2019
2267
  }
2020
2268
 
@@ -2158,7 +2406,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2158
2406
  /**
2159
2407
  * Returns texture data as a typed array.
2160
2408
  *
2161
- @@ -41615,6 +42145,8 @@ class WebGPUTextureUtils {
2409
+ @@ -41615,6 +42261,8 @@ class WebGPUTextureUtils {
2162
2410
  */
2163
2411
  dispose() {
2164
2412
 
@@ -2167,7 +2415,82 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2167
2415
  this._samplerCache.clear();
2168
2416
 
2169
2417
  }
2170
- @@ -43612,7 +44144,7 @@ class WGSLNodeBuilder extends NodeBuilder {
2418
+ @@ -43142,6 +43790,13 @@ class WGSLNodeBuilder extends NodeBuilder {
2419
+
2420
+ super( object, renderer, new WGSLNodeParser() );
2421
+
2422
+ + /**
2423
+ + * Comparison samplers shared by identical keys, and the WGSL sampler name of each texture
2424
+ + * that reads through another texture's sampler.
2425
+ + */
2426
+ + this.sharedCompareSamplers = new Map();
2427
+ + this.samplerNames = new Map();
2428
+ +
2429
+ /**
2430
+ * A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
2431
+ * another dictionary which manages UBOs per group ('render','frame','object').
2432
+ @@ -43218,21 +43873,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2433
+
2434
+ if ( offsetSnippet ) {
2435
+
2436
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
2437
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
2438
+
2439
+ }
2440
+
2441
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
2442
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
2443
+
2444
+ } else {
2445
+
2446
+ if ( offsetSnippet ) {
2447
+
2448
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
2449
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
2450
+
2451
+ }
2452
+
2453
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
2454
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet } )`;
2455
+
2456
+ }
2457
+
2458
+ @@ -43264,21 +43919,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2459
+
2460
+ if ( offsetSnippet ) {
2461
+
2462
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2463
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2464
+
2465
+ }
2466
+
2467
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
2468
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
2469
+
2470
+ } else {
2471
+
2472
+ if ( offsetSnippet ) {
2473
+
2474
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2475
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2476
+
2477
+ }
2478
+
2479
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
2480
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
2481
+
2482
+ }
2483
+
2484
+ @@ -43541,7 +44196,7 @@ class WGSLNodeBuilder extends NodeBuilder {
2485
+ // Depth textures require integer level, regular textures use float
2486
+ const levelType = texture.isDepthTexture ? 'u32' : 'f32';
2487
+
2488
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
2489
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
2490
+
2491
+ }
2492
+
2493
+ @@ -43612,7 +44267,7 @@ class WGSLNodeBuilder extends NodeBuilder {
2171
2494
  * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
2172
2495
  * @return {string} The WGSL snippet.
2173
2496
  */
@@ -2176,7 +2499,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2176
2499
 
2177
2500
  if ( levelSnippet === null ) levelSnippet = '0u';
2178
2501
 
2179
- @@ -43630,7 +44162,14 @@ class WGSLNodeBuilder extends NodeBuilder {
2502
+ @@ -43630,7 +44285,14 @@ class WGSLNodeBuilder extends NodeBuilder {
2180
2503
 
2181
2504
  } else {
2182
2505
 
@@ -2192,39 +2515,237 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2192
2515
 
2193
2516
  if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
2194
2517
 
2195
- @@ -44258,7 +44797,7 @@ class WGSLNodeBuilder extends NodeBuilder {
2518
+ @@ -43678,6 +44340,18 @@ class WGSLNodeBuilder extends NodeBuilder {
2519
+ * @param {Texture} texture - The texture.
2520
+ * @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
2521
+ */
2522
+ + /**
2523
+ + * The WGSL sampler a texture reads through: its own, or a shared comparison sampler.
2524
+ + *
2525
+ + * @param {string} textureProperty - The texture's WGSL name.
2526
+ + * @return {string} The sampler's WGSL name.
2527
+ + */
2528
+ + getSamplerName( textureProperty ) {
2529
+ +
2530
+ + return this.samplerNames.get( textureProperty ) ?? `${ textureProperty }_sampler`;
2531
+ +
2532
+ + }
2533
+ +
2534
+ isSampleCompare( texture ) {
2196
2535
 
2197
- // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
2198
- // Also textureGather always need sampler.
2199
- - const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
2200
- + const needsSampler = node.isRawTextureNode !== true && ( node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null );
2536
+ return texture.isDepthTexture === true && texture.compareFunction !== null && this.renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
2537
+ @@ -43754,21 +44428,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2201
2538
 
2202
- if ( needsSampler ) {
2539
+ if ( offsetSnippet ) {
2203
2540
 
2204
- @@ -44671,7 +45210,10 @@ ${ flowData.code }
2541
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
2542
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
2205
2543
 
2206
- for ( const { name, property, type } of builtins.values() ) {
2544
+ }
2207
2545
 
2208
- - const invariant = this.context.invariant === true && shaderStage === 'vertex' && name === 'position' ? '@invariant ' : '';
2209
- + // the engine's `context( { invariantPosition: true } )` and upstream's `invariant`
2210
- + // ask for the same thing, and the position output is the only builtin it can apply to
2211
- +
2212
- + const invariant = ( this.context.invariant === true || this.context.invariantPosition === true ) && shaderStage === 'vertex' && name === 'position' ? '@invariant ' : '';
2546
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
2547
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
2213
2548
 
2214
- snippets.push( `${ invariant }@builtin( ${name} ) ${property} : ${type}` );
2549
+ } else {
2215
2550
 
2216
- @@ -44975,6 +45517,8 @@ ${ flowData.code }
2217
- getVaryings( shaderStage ) {
2551
+ if ( offsetSnippet ) {
2218
2552
 
2219
- const snippets = [];
2220
- + const policy = this.context.sampleInterpolation;
2221
- + const sampleInterpolation = typeof policy === 'function' ? policy( this.material ) === true : policy === true;
2553
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
2554
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
2222
2555
 
2223
- if ( shaderStage === 'vertex' ) {
2556
+ }
2224
2557
 
2225
- @@ -44997,7 +45541,12 @@ ${ flowData.code }
2558
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
2559
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
2226
2560
 
2227
- let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
2561
+ }
2562
+
2563
+ @@ -43801,21 +44475,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2564
+
2565
+ if ( offsetSnippet ) {
2566
+
2567
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2568
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2569
+
2570
+ }
2571
+
2572
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
2573
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
2574
+
2575
+ }
2576
+
2577
+ if ( offsetSnippet ) {
2578
+
2579
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2580
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2581
+
2582
+ }
2583
+
2584
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
2585
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet } )`;
2586
+
2587
+ } else {
2588
+
2589
+ @@ -43880,21 +44554,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2590
+
2591
+ if ( offsetSnippet ) {
2592
+
2593
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
2594
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
2595
+
2596
+ }
2597
+
2598
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
2599
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
2600
+
2601
+ }
2602
+
2603
+ if ( offsetSnippet ) {
2604
+
2605
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
2606
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
2607
+
2608
+ }
2609
+
2610
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet })`;
2611
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet })`;
2612
+
2613
+ }
2614
+
2615
+ @@ -43915,21 +44589,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2616
+
2617
+ if ( offsetSnippet ) {
2618
+
2619
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2620
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2621
+
2622
+ }
2623
+
2624
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
2625
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
2626
+
2627
+ }
2628
+
2629
+ if ( offsetSnippet ) {
2630
+
2631
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2632
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
2633
+
2634
+ }
2635
+
2636
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet })`;
2637
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet })`;
2638
+
2639
+ }
2640
+
2641
+ @@ -43952,21 +44626,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2642
+
2643
+ if ( offsetSnippet ) {
2644
+
2645
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2646
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2647
+
2648
+ }
2649
+
2650
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
2651
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
2652
+
2653
+ } else {
2654
+
2655
+ if ( offsetSnippet ) {
2656
+
2657
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2658
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
2659
+
2660
+ }
2661
+
2662
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
2663
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
2664
+
2665
+ }
2666
+
2667
+ @@ -44002,21 +44676,21 @@ class WGSLNodeBuilder extends NodeBuilder {
2668
+
2669
+ if ( offsetSnippet ) {
2670
+
2671
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
2672
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
2673
+
2674
+ }
2675
+
2676
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
2677
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
2678
+
2679
+ } else {
2680
+
2681
+ if ( offsetSnippet ) {
2682
+
2683
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
2684
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
2685
+
2686
+ }
2687
+
2688
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
2689
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet } )`;
2690
+
2691
+ }
2692
+
2693
+ @@ -44258,13 +44932,29 @@ class WGSLNodeBuilder extends NodeBuilder {
2694
+
2695
+ // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
2696
+ // Also textureGather always need sampler.
2697
+ - const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
2698
+ + const needsSampler = node.isRawTextureNode !== true && ( node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null );
2699
+
2700
+ - if ( needsSampler ) {
2701
+ + // Identical comparison samplers share one binding. Every shadow map of a clipmap compares the
2702
+ + // same way, and a sampler per map exhausts maxSamplersPerShaderStage (16 on most adapters).
2703
+ + const sharedKey = needsSampler && this.isSampleCompare( node.value ) && node.isSampleCompare() ? `${ groupName }:${ shaderStage }:${ node.value.compareFunction }:${ node.value.wrapS }:${ node.value.wrapT }:${ node.value.wrapR }:${ node.value.minFilter }:${ node.value.magFilter }` : null;
2704
+ + const sharedSampler = sharedKey === null ? undefined : this.sharedCompareSamplers.get( sharedKey );
2705
+ +
2706
+ + if ( sharedSampler !== undefined ) {
2707
+ +
2708
+ + this.samplerNames.set( uniformNode.name, sharedSampler.name );
2709
+ + nodeData.sharedSampler = true;
2710
+ +
2711
+ + bindings.push( texture );
2712
+ +
2713
+ + uniformGPU = [ sharedSampler, texture ];
2714
+ +
2715
+ + } else if ( needsSampler ) {
2716
+
2717
+ const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
2718
+ sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
2719
+
2720
+ + if ( sharedKey !== null ) this.sharedCompareSamplers.set( sharedKey, sampler );
2721
+ +
2722
+ bindings.push( sampler, texture );
2723
+
2724
+ uniformGPU = [ sampler, texture ];
2725
+ @@ -44671,7 +45361,10 @@ ${ flowData.code }
2726
+
2727
+ for ( const { name, property, type } of builtins.values() ) {
2728
+
2729
+ - const invariant = this.context.invariant === true && shaderStage === 'vertex' && name === 'position' ? '@invariant ' : '';
2730
+ + // the engine's `context( { invariantPosition: true } )` and upstream's `invariant`
2731
+ + // ask for the same thing, and the position output is the only builtin it can apply to
2732
+ +
2733
+ + const invariant = ( this.context.invariant === true || this.context.invariantPosition === true ) && shaderStage === 'vertex' && name === 'position' ? '@invariant ' : '';
2734
+
2735
+ snippets.push( `${ invariant }@builtin( ${name} ) ${property} : ${type}` );
2736
+
2737
+ @@ -44975,6 +45668,8 @@ ${ flowData.code }
2738
+ getVaryings( shaderStage ) {
2739
+
2740
+ const snippets = [];
2741
+ + const policy = this.context.sampleInterpolation;
2742
+ + const sampleInterpolation = typeof policy === 'function' ? policy( this.material ) === true : policy === true;
2743
+
2744
+ if ( shaderStage === 'vertex' ) {
2745
+
2746
+ @@ -44997,7 +45692,12 @@ ${ flowData.code }
2747
+
2748
+ let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
2228
2749
 
2229
2750
  - if ( varying.interpolationType ) {
2230
2751
  + if ( sampleInterpolation && ! /^(int|uint|ivec|uvec)/.test( varying.type ) && varying.interpolationType !== 'flat' ) {
@@ -2236,7 +2757,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2236
2757
 
2237
2758
  const samplingSnippet = varying.interpolationSampling !== null ? `, ${ varying.interpolationSampling } )` : ' )';
2238
2759
 
2239
- @@ -45059,9 +45608,12 @@ ${ flowData.code }
2760
+ @@ -45059,11 +45759,15 @@ ${ flowData.code }
2240
2761
  const textureNode = uniform.node;
2241
2762
  const texture = textureNode.value;
2242
2763
 
@@ -2250,9 +2771,13 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2250
2771
  + const uniformGPU = nodeData.uniformGPU;
2251
2772
  + const needsSampler = Array.isArray( uniformGPU ) && uniformGPU[ 0 ].isSampler === true && uniformGPU[ 0 ].isSampledTexture !== true;
2252
2773
 
2253
- if ( needsSampler ) {
2774
+ - if ( needsSampler ) {
2775
+ + // A shared comparison sampler is declared once, by the texture that created it.
2776
+ + if ( needsSampler && nodeData.sharedSampler !== true ) {
2254
2777
 
2255
- @@ -45083,7 +45635,7 @@ ${ flowData.code }
2778
+ if ( this.isSampleCompare( texture ) && textureNode.isSampleCompare() ) {
2779
+
2780
+ @@ -45083,7 +45787,7 @@ ${ flowData.code }
2256
2781
 
2257
2782
  const { primarySamples } = backend.utils.getTextureSampleData( texture );
2258
2783
 
@@ -2261,7 +2786,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2261
2786
 
2262
2787
  multisampled = '_multisampled';
2263
2788
 
2264
- @@ -45883,6 +46435,15 @@ class WebGPUAttributeUtils {
2789
+ @@ -45883,6 +46587,15 @@ class WebGPUAttributeUtils {
2265
2790
  buffer.unmap();
2266
2791
 
2267
2792
  bufferData.buffer = buffer;
@@ -2277,7 +2802,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2277
2802
 
2278
2803
  }
2279
2804
 
2280
- @@ -45902,6 +46463,11 @@ class WebGPUAttributeUtils {
2805
+ @@ -45902,6 +46615,11 @@ class WebGPUAttributeUtils {
2281
2806
  const bufferData = backend.get( bufferAttribute );
2282
2807
  const buffer = backend.get( bufferAttribute ).buffer;
2283
2808
 
@@ -2289,7 +2814,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2289
2814
  let array = bufferAttribute.array;
2290
2815
 
2291
2816
  const itemSize = bufferData._itemSize;
2292
- @@ -45990,6 +46556,9 @@ class WebGPUAttributeUtils {
2817
+ @@ -45990,6 +46708,9 @@ class WebGPUAttributeUtils {
2293
2818
 
2294
2819
  }
2295
2820
 
@@ -2299,7 +2824,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2299
2824
  }
2300
2825
 
2301
2826
  /**
2302
- @@ -46104,9 +46673,14 @@ class WebGPUAttributeUtils {
2827
+ @@ -46104,9 +46825,14 @@ class WebGPUAttributeUtils {
2303
2828
  const bufferAttribute = backend.getBufferAttribute( attribute );
2304
2829
  const data = backend.get( bufferAttribute );
2305
2830
 
@@ -2316,7 +2841,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2316
2841
 
2317
2842
  }
2318
2843
 
2319
- @@ -46389,18 +46963,16 @@ class WebGPUBindingUtils {
2844
+ @@ -46389,18 +47115,16 @@ class WebGPUBindingUtils {
2320
2845
 
2321
2846
  const bindingsData = backend.get( bindGroup );
2322
2847
 
@@ -2327,10 +2852,10 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2327
2852
  if ( bindingsData.layout ) {
2328
2853
 
2329
2854
  - return bindingsData.layout.layoutGPU;
2855
+ -
2856
+ - }
2330
2857
  + if ( bindingsData.layoutKey === bindGroupLayoutKey ) return bindingsData.layout.layoutGPU;
2331
2858
 
2332
- - }
2333
- -
2334
2859
  - // if not, assing one
2335
2860
  + this.deleteBindGroupData( bindGroup );
2336
2861
 
@@ -2340,7 +2865,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2340
2865
 
2341
2866
  // try to find an existing layout in the cache
2342
2867
 
2343
- @@ -46621,7 +47193,20 @@ class WebGPUBindingUtils {
2868
+ @@ -46621,7 +47345,20 @@ class WebGPUBindingUtils {
2344
2869
 
2345
2870
  let resourceGPU;
2346
2871
 
@@ -2362,7 +2887,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2362
2887
 
2363
2888
  resourceGPU = device.importExternalTexture( { source: textureData.externalTexture } );
2364
2889
 
2365
- @@ -46798,7 +47383,7 @@ class WebGPUBindingUtils {
2890
+ @@ -46798,7 +47535,7 @@ class WebGPUBindingUtils {
2366
2891
 
2367
2892
  const { primarySamples } = backend.utils.getTextureSampleData( binding.texture );
2368
2893
 
@@ -2371,7 +2896,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2371
2896
 
2372
2897
  texture.multisampled = true;
2373
2898
 
2374
- @@ -46840,7 +47425,7 @@ class WebGPUBindingUtils {
2899
+ @@ -46840,7 +47577,7 @@ class WebGPUBindingUtils {
2375
2900
 
2376
2901
  } else if ( type === FloatType ) {
2377
2902
 
@@ -2380,7 +2905,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2380
2905
 
2381
2906
  texture.sampleType = GPUTextureSampleType.Float;
2382
2907
 
2383
- @@ -46932,6 +47517,9 @@ class WebGPUBindingUtils {
2908
+ @@ -46932,6 +47669,9 @@ class WebGPUBindingUtils {
2384
2909
 
2385
2910
  }
2386
2911
 
@@ -2390,7 +2915,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2390
2915
  }
2391
2916
 
2392
2917
  /**
2393
- @@ -47356,7 +47944,13 @@ class WebGPUPipelineUtils {
2918
+ @@ -47356,7 +48096,13 @@ class WebGPUPipelineUtils {
2394
2919
 
2395
2920
  // Pop the error scope before awaiting the pipeline, so several pipelines
2396
2921
  // can be created at the same time without mixing their error scopes.
@@ -2405,7 +2930,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2405
2930
 
2406
2931
  if ( pipelinePromise !== null ) {
2407
2932
 
2408
- @@ -48693,6 +49287,27 @@ class WebGPUBackend extends Backend {
2933
+ @@ -48693,6 +49439,27 @@ class WebGPUBackend extends Backend {
2409
2934
  */
2410
2935
  this.compatibilityMode = null;
2411
2936
 
@@ -2433,7 +2958,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2433
2958
  /**
2434
2959
  * A reference to the device.
2435
2960
  *
2436
- @@ -48805,7 +49420,11 @@ class WebGPUBackend extends Backend {
2961
+ @@ -48805,7 +49572,11 @@ class WebGPUBackend extends Backend {
2437
2962
  xrCompatible: renderer.xr.enabled
2438
2963
  };
2439
2964
 
@@ -2446,7 +2971,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2446
2971
 
2447
2972
  if ( adapter === null ) {
2448
2973
 
2449
- @@ -49033,7 +49652,9 @@ class WebGPUBackend extends Backend {
2974
+ @@ -49033,7 +49804,9 @@ class WebGPUBackend extends Backend {
2450
2975
 
2451
2976
  let descriptor = canvasData.descriptor;
2452
2977
 
@@ -2457,7 +2982,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2457
2982
 
2458
2983
  descriptor = new GPURenderPassDescriptor();
2459
2984
  descriptor.colorAttachments.push( new GPURenderPassColorAttachment() );
2460
- @@ -49060,6 +49681,9 @@ class WebGPUBackend extends Backend {
2985
+ @@ -49060,6 +49833,9 @@ class WebGPUBackend extends Backend {
2461
2986
 
2462
2987
  canvasData.descriptor = descriptor;
2463
2988
  canvasData.samples = samples;
@@ -2467,7 +2992,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2467
2992
 
2468
2993
  }
2469
2994
 
2470
- @@ -51001,6 +51625,7 @@ class WebGPUBackend extends Backend {
2995
+ @@ -51001,6 +51777,7 @@ class WebGPUBackend extends Backend {
2471
2996
  const utils = this.utils;
2472
2997
 
2473
2998
  const sampleCount = utils.getSampleCountRenderContext( renderObject.context );
@@ -2475,7 +3000,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2475
3000
  const colorSpace = utils.getCurrentColorSpace( renderObject.context );
2476
3001
  const colorFormat = utils.getCurrentColorFormat( renderObject.context );
2477
3002
  const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context );
2478
- @@ -51025,7 +51650,8 @@ class WebGPUBackend extends Backend {
3003
+ @@ -51025,7 +51802,8 @@ class WebGPUBackend extends Backend {
2479
3004
  data.primitiveTopology !== primitiveTopology || data.stripIndexFormat !== stripIndexFormat ||
2480
3005
  data.frontFaceCW !== frontFaceCW ||
2481
3006
  data.geometryVersion !== renderObject.geometryVersion ||
@@ -2485,7 +3010,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2485
3010
  ) {
2486
3011
 
2487
3012
  data.material = material; data.materialVersion = material.version;
2488
- @@ -51048,6 +51674,7 @@ class WebGPUBackend extends Backend {
3013
+ @@ -51048,6 +51826,7 @@ class WebGPUBackend extends Backend {
2489
3014
  data.frontFaceCW = frontFaceCW;
2490
3015
  data.geometryVersion = renderObject.geometryVersion;
2491
3016
  data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
@@ -2493,7 +3018,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2493
3018
 
2494
3019
  needsUpdate = true;
2495
3020
 
2496
- @@ -51069,6 +51696,7 @@ class WebGPUBackend extends Backend {
3021
+ @@ -51069,6 +51848,7 @@ class WebGPUBackend extends Backend {
2497
3022
 
2498
3023
  const utils = this.utils;
2499
3024
  const renderContext = renderObject.context;
@@ -2501,7 +3026,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2501
3026
 
2502
3027
  // meshes with negative scale have a different frontFace render pipeline
2503
3028
  // descriptor value so the following must be honored in the cache key
2504
- @@ -51088,9 +51716,11 @@ class WebGPUBackend extends Backend {
3029
+ @@ -51088,9 +51868,11 @@ class WebGPUBackend extends Backend {
2505
3030
  material.side, material.alphaToCoverage,
2506
3031
  frontFaceCW,
2507
3032
  utils.getSampleCountRenderContext( renderContext ),
@@ -2513,7 +3038,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2513
3038
  renderObject.clippingContextCacheKey
2514
3039
  ].join();
2515
3040
 
2516
- @@ -51158,6 +51788,12 @@ class WebGPUBackend extends Backend {
3041
+ @@ -51158,6 +51940,12 @@ class WebGPUBackend extends Backend {
2517
3042
 
2518
3043
  }
2519
3044
 
@@ -2527,7 +3052,7 @@ index f8fc49fe7df98cbac4609603a1f2a2c6aea79675..b72762aeb47f25485ce9b7f6beab3cf5
2527
3052
  * Generates mipmaps for the given texture.
2528
3053
  *
2529
3054
  diff --git a/build/three.webgpu.nodes.js b/build/three.webgpu.nodes.js
2530
- index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab13501361 100644
3055
+ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..790d97c1247564c7fd3aea2ee54ea0a6ffa50c62 100644
2531
3056
  --- a/build/three.webgpu.nodes.js
2532
3057
  +++ b/build/three.webgpu.nodes.js
2533
3058
  @@ -179,6 +179,15 @@ class NodeMaterialObserver {
@@ -2546,7 +3071,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2546
3071
  }
2547
3072
 
2548
3073
  /**
2549
- @@ -357,6 +366,88 @@ class NodeMaterialObserver {
3074
+ @@ -357,6 +366,92 @@ class NodeMaterialObserver {
2550
3075
 
2551
3076
  }
2552
3077
 
@@ -2597,7 +3122,8 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2597
3122
  + environmentRotation: scene.environmentRotation.clone(),
2598
3123
  + environmentIntensity: scene.environmentIntensity,
2599
3124
  + materialVersion: material.version,
2600
- + geometryVersion: geometry.version
3125
+ + geometryVersion: geometry.version,
3126
+ + pmremSwaps: renderObject.renderer._tnPmremSwaps
2601
3127
  + };
2602
3128
  +
2603
3129
  + data.settledState = false;
@@ -2610,7 +3136,9 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2610
3136
  + settled.environmentRotation.equals( scene.environmentRotation ) !== true ||
2611
3137
  + settled.environmentIntensity !== scene.environmentIntensity ||
2612
3138
  + settled.materialVersion !== material.version ||
2613
- + settled.geometryVersion !== geometry.version ) {
3139
+ + settled.geometryVersion !== geometry.version ||
3140
+ + // a PMREM finished and swapped the texture its node samples: a settled object would keep the old one
3141
+ + settled.pmremSwaps !== renderObject.renderer._tnPmremSwaps ) {
2614
3142
  +
2615
3143
  + // re-arm with the current state, so the object settles again once it stops changing
2616
3144
  +
@@ -2619,6 +3147,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2619
3147
  + settled.environmentIntensity = scene.environmentIntensity;
2620
3148
  + settled.materialVersion = material.version;
2621
3149
  + settled.geometryVersion = geometry.version;
3150
+ + settled.pmremSwaps = renderObject.renderer._tnPmremSwaps;
2622
3151
  +
2623
3152
  + data.settledState = false;
2624
3153
  +
@@ -2635,7 +3164,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2635
3164
  /**
2636
3165
  * Returns an attribute data structure holding the attributes versions for
2637
3166
  * monitoring.
2638
- @@ -1078,7 +1169,17 @@ class NodeMaterialObserver {
3167
+ @@ -1078,7 +1173,17 @@ class NodeMaterialObserver {
2639
3168
  */
2640
3169
  needsRefresh( renderObject, nodeFrame ) {
2641
3170
 
@@ -2654,7 +3183,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2654
3183
  return RenderObjectRefreshType.FULL;
2655
3184
 
2656
3185
  const { renderId } = nodeFrame;
2657
- @@ -1121,10 +1222,14 @@ class NodeMaterialObserver {
3186
+ @@ -1121,10 +1226,14 @@ class NodeMaterialObserver {
2658
3187
 
2659
3188
  }
2660
3189
 
@@ -2671,7 +3200,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2671
3200
  return refreshType;
2672
3201
 
2673
3202
  const lightsData = this.getLights( renderObject.lightsNode, renderId );
2674
- @@ -13446,6 +13551,13 @@ class TextureSizeNode extends Node {
3203
+ @@ -13446,6 +13555,13 @@ class TextureSizeNode extends Node {
2675
3204
  const textureProperty = this.textureNode.build( builder, 'property' );
2676
3205
  const level = this.levelNode === null ? '0' : this.levelNode.build( builder, 'int' );
2677
3206
 
@@ -2685,7 +3214,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2685
3214
  const snippet = builder.generateTextureSize( this.textureNode.value, textureProperty, level );
2686
3215
 
2687
3216
  return builder.format( snippet, this.getNodeType( builder ) );
2688
- @@ -14180,7 +14292,7 @@ class TextureNode extends UniformNode {
3217
+ @@ -14180,7 +14296,7 @@ class TextureNode extends UniformNode {
2689
3218
 
2690
3219
  } else if ( this.sampler === false ) {
2691
3220
 
@@ -2694,7 +3223,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2694
3223
 
2695
3224
  } else if ( levelSnippet ) {
2696
3225
 
2697
- @@ -19985,13 +20097,8 @@ function createInstanceMatrixNode( builder, instanceMatrix ) {
3226
+ @@ -19985,13 +20101,8 @@ function createInstanceMatrixNode( builder, instanceMatrix ) {
2698
3227
 
2699
3228
  } else {
2700
3229
 
@@ -2710,7 +3239,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2710
3239
 
2711
3240
  // the columns view the matrices, so both share the same GPU buffer which is freed via instanceMatrix.dispose()
2712
3241
 
2713
- @@ -20239,8 +20346,25 @@ const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
3242
+ @@ -20239,8 +20350,30 @@ const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
2714
3243
 
2715
3244
  const instancedMesh = builder.object;
2716
3245
 
@@ -2723,8 +3252,11 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2723
3252
  +
2724
3253
  + const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
2725
3254
  +
3255
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
3256
+ +
2726
3257
  + previousInstanceMatrix.array.set( scheduledPrevious );
2727
3258
  + previousInstanceMatrix.needsUpdate = true;
3259
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
2728
3260
  +
2729
3261
  + } );
2730
3262
  +
@@ -2732,11 +3264,13 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2732
3264
  OnAfterObjectUpdate( ( { object } ) => {
2733
3265
 
2734
3266
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
3267
+ +
3268
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
2735
3269
  +
2736
3270
  const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
2737
3271
 
2738
3272
  previousInstanceMatrix.array.set( matrices.array );
2739
- @@ -20282,8 +20406,25 @@ const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) => {
3273
+ @@ -20282,8 +20415,30 @@ const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) => {
2740
3274
 
2741
3275
  if ( builder.needsPreviousData() ) {
2742
3276
 
@@ -2749,8 +3283,11 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2749
3283
  +
2750
3284
  + const previous = getPreviousMatrix$1( object );
2751
3285
  +
3286
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
3287
+ +
2752
3288
  + previous.array.set( scheduledPrevious );
2753
3289
  + previous.needsUpdate = true;
3290
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
2754
3291
  +
2755
3292
  + } );
2756
3293
  +
@@ -2758,11 +3295,13 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2758
3295
  OnAfterObjectUpdate( ( { object } ) => {
2759
3296
 
2760
3297
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
3298
+ +
3299
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
2761
3300
  +
2762
3301
  const previous = getPreviousMatrix$1( object );
2763
3302
 
2764
3303
  previous.array.set( object.instanceMatrix.array );
2765
- @@ -20722,7 +20863,11 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
3304
+ @@ -20722,7 +20877,11 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
2766
3305
 
2767
3306
  if ( skeleton.previousBoneMatrices !== null ) {
2768
3307
 
@@ -2775,7 +3314,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2775
3314
 
2776
3315
  if ( skeleton.previousBoneTexture !== null ) {
2777
3316
 
2778
- @@ -20740,8 +20885,17 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
3317
+ @@ -20740,8 +20899,17 @@ const skinning = /*@__PURE__*/ Fn( ( [ skinnedMesh ], builder ) => {
2779
3318
 
2780
3319
  if ( needsPreviousData ) {
2781
3320
 
@@ -2794,7 +3333,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2794
3333
 
2795
3334
  positionPrevious.assign( previousSkinnedPosition );
2796
3335
 
2797
- @@ -20794,7 +20948,11 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
3336
+ @@ -20794,7 +20962,11 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
2798
3337
 
2799
3338
  if ( skeleton.previousBoneMatrices !== null ) {
2800
3339
 
@@ -2807,7 +3346,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2807
3346
 
2808
3347
  if ( skeleton.previousBoneTexture !== null ) {
2809
3348
 
2810
- @@ -20814,8 +20972,15 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
3349
+ @@ -20814,8 +20986,15 @@ const computeSkinning = /*@__PURE__*/ Fn( ( [ skinnedMesh, toPosition = null ],
2811
3350
 
2812
3351
  setupPreviousBoneData( skeleton );
2813
3352
 
@@ -2824,7 +3363,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2824
3363
 
2825
3364
  positionPrevious.assign( previousSkinnedPosition );
2826
3365
 
2827
- @@ -28177,6 +28342,24 @@ class PMREMGenerator {
3366
+ @@ -28177,6 +28356,24 @@ class PMREMGenerator {
2828
3367
  this._ggxMaterial = null;
2829
3368
  this._integrationMaterial = null;
2830
3369
 
@@ -2849,7 +3388,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2849
3388
  }
2850
3389
 
2851
3390
  /**
2852
- @@ -28317,11 +28500,11 @@ class PMREMGenerator {
3391
+ @@ -28317,11 +28514,11 @@ class PMREMGenerator {
2853
3392
  */
2854
3393
  async fromEquirectangularAsync( equirectangular, renderTarget = null ) {
2855
3394
 
@@ -2864,7 +3403,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2864
3403
 
2865
3404
  }
2866
3405
 
2867
- @@ -28357,11 +28540,11 @@ class PMREMGenerator {
3406
+ @@ -28357,11 +28554,11 @@ class PMREMGenerator {
2868
3407
  */
2869
3408
  async fromCubemapAsync( cubemap, renderTarget = null ) {
2870
3409
 
@@ -2879,7 +3418,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2879
3418
 
2880
3419
  }
2881
3420
 
2882
- @@ -28439,7 +28622,13 @@ class PMREMGenerator {
3421
+ @@ -28439,7 +28636,13 @@ class PMREMGenerator {
2883
3422
 
2884
3423
  }
2885
3424
 
@@ -2894,7 +3433,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2894
3433
 
2895
3434
  if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
2896
3435
 
2897
- @@ -28451,6 +28640,12 @@ class PMREMGenerator {
3436
+ @@ -28451,6 +28654,12 @@ class PMREMGenerator {
2898
3437
 
2899
3438
  }
2900
3439
 
@@ -2907,7 +3446,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2907
3446
  const pmremTarget = renderTarget || this._allocateTarget();
2908
3447
 
2909
3448
  this._textureToCubemap( texture );
2910
- @@ -28460,6 +28655,55 @@ class PMREMGenerator {
3449
+ @@ -28460,6 +28669,55 @@ class PMREMGenerator {
2911
3450
 
2912
3451
  }
2913
3452
 
@@ -2963,7 +3502,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
2963
3502
  _allocateTarget() {
2964
3503
 
2965
3504
  const size = this._cubeSize;
2966
- @@ -28528,8 +28772,206 @@ class PMREMGenerator {
3505
+ @@ -28528,7 +28786,122 @@ class PMREMGenerator {
2967
3506
 
2968
3507
  }
2969
3508
 
@@ -3084,33 +3623,13 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3084
3623
  + * @return {Promise<void>} A Promise that resolves when the source cubemap is complete.
3085
3624
  + */
3086
3625
  + async _textureToCubemapAsync( texture ) {
3087
- +
3088
- + let material;
3089
- +
3090
- + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
3091
- +
3092
- + if ( this._cubemapMaterial === null ) {
3093
- +
3094
- + this._cubemapMaterial = _getCubemapMaterial();
3095
- +
3096
- + }
3097
- +
3098
- + material = this._cubemapMaterial;
3099
- +
3100
- + } else {
3101
- +
3102
- + if ( this._equirectMaterial === null ) {
3103
- +
3104
- + this._equirectMaterial = _getEquirectMaterial();
3105
- +
3106
- + }
3107
- +
3108
- + material = this._equirectMaterial;
3109
- +
3110
- + }
3111
- +
3112
- + _uniformsMap.get( material ).envMap.value = texture;
3113
- +
3626
+
3627
+ let material;
3628
+
3629
+ @@ -28556,6 +28929,89 @@ class PMREMGenerator {
3630
+
3631
+ _uniformsMap.get( material ).envMap.value = texture;
3632
+
3114
3633
  + await this._renderCubeAsync( this._getSourceTarget(), 0, material );
3115
3634
  +
3116
3635
  + }
@@ -3147,7 +3666,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3147
3666
  + const roughness = PMREMGenerator.lodToRoughness( lod, maxLod );
3148
3667
  +
3149
3668
  + if ( lod > maxLod - INTEGRATION_LEVELS ) {
3150
-
3669
+ +
3151
3670
  + integrationUniforms.roughness.value = roughness;
3152
3671
  +
3153
3672
  + await this._renderCubeAsync( pmremTarget, lod, this._integrationMaterial );
@@ -3168,10 +3687,36 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3168
3687
  + }
3169
3688
  +
3170
3689
  + _textureToCubemap( texture ) {
3171
- let material;
3690
+ + let material;
3691
+ +
3692
+ + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
3693
+ +
3694
+ + if ( this._cubemapMaterial === null ) {
3695
+ +
3696
+ + this._cubemapMaterial = _getCubemapMaterial();
3697
+ +
3698
+ + }
3699
+ +
3700
+ + material = this._cubemapMaterial;
3701
+ +
3702
+ + } else {
3703
+ +
3704
+ + if ( this._equirectMaterial === null ) {
3705
+ +
3706
+ + this._equirectMaterial = _getEquirectMaterial();
3707
+ +
3708
+ + }
3709
+ +
3710
+ + material = this._equirectMaterial;
3711
+ +
3712
+ + }
3713
+ +
3714
+ + _uniformsMap.get( material ).envMap.value = texture;
3715
+ +
3716
+ this._renderCube( this._getSourceTarget(), 0, material );
3172
3717
 
3173
- if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
3174
- @@ -28763,6 +29205,39 @@ function _getEquirectMaterial() {
3718
+ }
3719
+ @@ -28763,6 +29219,39 @@ function _getEquirectMaterial() {
3175
3720
  }
3176
3721
 
3177
3722
  const _cache = new WeakMap();
@@ -3211,7 +3756,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3211
3756
 
3212
3757
  /**
3213
3758
  * Generates a PMREM from the given texture.
3214
- @@ -28776,6 +29251,14 @@ const _cache = new WeakMap();
3759
+ @@ -28776,6 +29265,14 @@ const _cache = new WeakMap();
3215
3760
  function _getPMREMFromTexture( texture, renderer, generator ) {
3216
3761
 
3217
3762
  const cache = _getCache( renderer );
@@ -3226,7 +3771,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3226
3771
 
3227
3772
  let renderTarget = cache.get( texture );
3228
3773
 
3229
- @@ -28784,6 +29267,25 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
3774
+ @@ -28784,6 +29281,25 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
3230
3775
  if ( pmremVersion !== texture.pmremVersion ) {
3231
3776
 
3232
3777
  const image = texture.image;
@@ -3252,7 +3797,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3252
3797
 
3253
3798
  if ( texture.isCubeTexture ) {
3254
3799
 
3255
- @@ -28814,29 +29316,7 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
3800
+ @@ -28814,29 +29330,7 @@ function _getPMREMFromTexture( texture, renderer, generator ) {
3256
3801
 
3257
3802
  renderTarget.texture.pmremVersion = texture.pmremVersion;
3258
3803
 
@@ -3283,7 +3828,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3283
3828
 
3284
3829
  //
3285
3830
 
3286
- @@ -28979,6 +29459,118 @@ class PMREMNode extends Node {
3831
+ @@ -28979,6 +29473,118 @@ class PMREMNode extends Node {
3287
3832
 
3288
3833
  }
3289
3834
 
@@ -3402,7 +3947,17 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3402
3947
  set value( value ) {
3403
3948
 
3404
3949
  this._value = value;
3405
- @@ -31716,7 +32308,7 @@ class ChainMap {
3950
+ @@ -29041,6 +29647,9 @@ class PMREMNode extends Node {
3951
+
3952
+ this._pmrem = pmrem;
3953
+
3954
+ + // count the swap, so every settled object that samples this node refreshes once (NodeMaterialObserver)
3955
+ + if ( this._texture.value !== pmrem && frame.renderer ) frame.renderer._tnPmremSwaps = ( frame.renderer._tnPmremSwaps || 0 ) + 1;
3956
+ +
3957
+ this.updateFromTexture( pmrem );
3958
+
3959
+ }
3960
+ @@ -31716,7 +32325,7 @@ class ChainMap {
3406
3961
 
3407
3962
  let _id$a = 0;
3408
3963
  const _protoKeysCache = new WeakMap();
@@ -3411,7 +3966,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3411
3966
  const _enumProperties = [ 'side', 'blending', 'combine', 'normalMapType' ];
3412
3967
 
3413
3968
  function getKeys( obj ) {
3414
- @@ -32470,7 +33062,7 @@ class RenderObject {
3969
+ @@ -32470,7 +33079,7 @@ class RenderObject {
3415
3970
  *
3416
3971
  * @return {string} The geometry cache key.
3417
3972
  */
@@ -3420,7 +3975,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3420
3975
 
3421
3976
  const { geometry } = this;
3422
3977
 
3423
- @@ -32496,17 +33088,25 @@ class RenderObject {
3978
+ @@ -32496,17 +33105,25 @@ class RenderObject {
3424
3979
  const targets = geometry.morphAttributes[ name ];
3425
3980
 
3426
3981
  cacheKey += 'morph-' + name + ',';
@@ -3447,7 +4002,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3447
4002
  return cacheKey;
3448
4003
 
3449
4004
  }
3450
- @@ -32738,6 +33338,8 @@ class RenderObject {
4005
+ @@ -32738,6 +33355,8 @@ class RenderObject {
3451
4006
  _cacheKeyValues$1[ 3 ] = this.renderer.contextNode.id;
3452
4007
  _cacheKeyValues$1[ 4 ] = this.renderer.contextNode.version;
3453
4008
 
@@ -3456,7 +4011,15 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3456
4011
  return hashArray( _cacheKeyValues$1 );
3457
4012
 
3458
4013
  }
3459
- @@ -33481,6 +34083,14 @@ class Geometries extends DataMap {
4014
+ @@ -33019,6 +33638,7 @@ class RenderObjects {
4015
+ this.pipelines.delete( renderObject );
4016
+ this.bindings.deleteForRender( renderObject );
4017
+ this.nodes.delete( renderObject );
4018
+ + this.geometries.releaseRenderObject( renderObject );
4019
+
4020
+ chainMap.delete( renderObject.getChainArray() );
4021
+
4022
+ @@ -33481,6 +34101,17 @@ class Geometries extends DataMap {
3460
4023
  */
3461
4024
  this._registry = new FinalizationRegistry( ( ref ) => this._tracked.delete( ref ) );
3462
4025
 
@@ -3467,14 +4030,19 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3467
4030
  + * @type {WeakMap<RenderObject,Map<BufferAttribute,number>>}
3468
4031
  + */
3469
4032
  + this._settledAttributes = new WeakMap();
4033
+ + this._geometryAttributeOwners = new WeakMap();
4034
+ + this._sharedAttributeOwners = new WeakMap();
4035
+ + this._renderObjectAttributeGeometry = new WeakMap();
3470
4036
  +
3471
4037
  }
3472
4038
 
3473
4039
  /**
3474
- @@ -33506,10 +34116,69 @@ class Geometries extends DataMap {
4040
+ @@ -33505,11 +34136,173 @@ class Geometries extends DataMap {
4041
+ const geometry = renderObject.geometry;
3475
4042
 
3476
4043
  if ( this.has( geometry ) === false ) this.initGeometry( geometry );
3477
-
4044
+ + if ( this.geometryAttributesChanged( renderObject ) ) this.syncGeometryAttributes( renderObject );
4045
+ +
3478
4046
  + // A settled static object has no attribute that could have changed since the last refresh,
3479
4047
  + // unless a writer bumped one. An InstancedMesh's instance buffer is a vertex attribute of
3480
4048
  + // this draw, and a BufferGeometry carries no version of its own to announce the write, so
@@ -3483,7 +4051,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3483
4051
  + const monitor = renderObject.getMonitor();
3484
4052
  +
3485
4053
  + if ( monitor !== undefined && monitor.isSettled( renderObject ) === true && this.attributesChanged( renderObject ) === false ) return;
3486
- +
4054
+
3487
4055
  this.updateAttributes( renderObject );
3488
4056
 
3489
4057
  }
@@ -3501,13 +4069,18 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3501
4069
  + const index = this.getIndex( renderObject );
3502
4070
  + const settled = this._settledAttributes.get( renderObject );
3503
4071
  +
3504
- + if ( settled !== undefined && settled.size === attributes.length + ( index === null ? 0 : 1 ) ) {
4072
+ + if ( settled !== undefined && settled.attributes.length === attributes.length && settled.index === index ) {
3505
4073
  +
3506
4074
  + let changed = false;
3507
4075
  +
3508
- + for ( const attribute of attributes ) {
4076
+ + for ( let i = 0; i < attributes.length; i ++ ) {
4077
+ +
4078
+ + const attribute = attributes[ i ];
4079
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
4080
+ + const previous = settled.attributes[ i ];
3509
4081
  +
3510
- + if ( settled.get( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) !== attribute.version ) {
4082
+ + // an interleaved wrapper has no version of its own: its buffer's version is the write signal
4083
+ + if ( previous.attribute !== attribute || previous.data !== data || previous.version !== data.version ) {
3511
4084
  +
3512
4085
  + changed = true;
3513
4086
  + break;
@@ -3516,32 +4089,156 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3516
4089
  +
3517
4090
  + }
3518
4091
  +
3519
- + if ( changed === false && ( index === null || settled.get( index ) === index.version ) ) return false;
4092
+ + if ( changed === false && ( index === null || settled.indexVersion === index.version ) ) return false;
3520
4093
  +
3521
4094
  + }
3522
4095
  +
3523
- + const versions = new Map();
4096
+ + const versions = attributes.map( ( attribute ) => {
4097
+ +
4098
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
4099
+ + return { attribute, data, version: data.version };
4100
+ +
4101
+ + } );
4102
+ +
4103
+ + this._settledAttributes.set( renderObject, { attributes: versions, index, indexVersion: index === null ? undefined : index.version } );
4104
+ +
4105
+ + return true;
4106
+ +
4107
+ + }
4108
+ +
4109
+ + /** Compare the published attribute identities without allocating on settled frames. */
4110
+ + geometryAttributesChanged( renderObject ) {
4111
+ +
4112
+ + const geometry = renderObject.geometry;
4113
+ + const owner = this._geometryAttributeOwners.get( geometry )?.get( renderObject );
4114
+ + if ( owner === undefined || owner.index !== geometry.index ) return true;
4115
+ +
4116
+ + const attributes = renderObject.getAttributes();
4117
+ + if ( owner.attributes.length !== attributes.length ) return true;
4118
+ + for ( let i = 0; i < attributes.length; i ++ ) {
4119
+ + const attribute = attributes[ i ];
4120
+ + if ( owner.attributes[ i ] !== ( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) ) return true;
4121
+ + }
4122
+ +
4123
+ + return false;
4124
+ +
4125
+ + }
4126
+ +
4127
+ + /** Add this render object's current geometry attributes to the renderer's shared-resource owners. */
4128
+ + syncGeometryAttributes( renderObject ) {
4129
+ +
4130
+ + const { geometry } = renderObject;
4131
+ + const previousGeometry = this._renderObjectAttributeGeometry.get( renderObject );
4132
+ + if ( previousGeometry !== undefined && previousGeometry !== geometry ) this.releaseRenderObject( renderObject );
4133
+ + this._renderObjectAttributeGeometry.set( renderObject, geometry );
4134
+ + let geometryOwners = this._geometryAttributeOwners.get( geometry );
4135
+ +
4136
+ + if ( geometryOwners === undefined ) {
4137
+ + geometryOwners = new Map();
4138
+ + this._geometryAttributeOwners.set( geometry, geometryOwners );
4139
+ + }
4140
+ +
4141
+ + const previous = geometryOwners.get( renderObject )?.keys ?? new Map();
4142
+ + const current = new Map();
4143
+ + const attributes = renderObject.getAttributes();
4144
+ + const attributeKeys = [];
3524
4145
  +
3525
4146
  + for ( const attribute of attributes ) {
4147
+ + const key = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
4148
+ + current.set( key, true );
4149
+ + attributeKeys.push( key );
4150
+ + }
4151
+ + const index = geometry.index;
4152
+ + if ( index !== null ) current.set( index, true );
4153
+ +
4154
+ + for ( const key of current.keys() ) {
4155
+ + let record = this._sharedAttributeOwners.get( key );
4156
+ + if ( record === undefined ) record = { owners: new Set() };
4157
+ + if ( previous.has( key ) === false ) record.owners.add( renderObject );
4158
+ + this._sharedAttributeOwners.set( key, record );
4159
+ + }
3526
4160
  +
3527
- + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
4161
+ + for ( const key of previous.keys() ) {
4162
+ + if ( current.has( key ) === false ) this.releaseSharedAttribute( key, renderObject );
4163
+ + }
3528
4164
  +
3529
- + versions.set( data, data.version );
4165
+ + geometryOwners.set( renderObject, { keys: current, attributes: attributeKeys, index } );
4166
+ +
4167
+ + }
3530
4168
  +
4169
+ + /** Drop a render object from its geometry before its material-owned node attributes go stale. */
4170
+ + releaseRenderObject( renderObject ) {
4171
+ +
4172
+ + const geometry = this._renderObjectAttributeGeometry.get( renderObject );
4173
+ + if ( geometry === undefined ) return;
4174
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
4175
+ + const owned = geometryOwners?.get( renderObject )?.keys;
4176
+ + if ( owned !== undefined ) {
4177
+ + for ( const key of owned.keys() ) this.releaseSharedAttribute( key, renderObject );
4178
+ + geometryOwners.delete( renderObject );
4179
+ + if ( geometryOwners.size === 0 ) this._geometryAttributeOwners.delete( geometry );
3531
4180
  + }
4181
+ + this._renderObjectAttributeGeometry.delete( renderObject );
3532
4182
  +
3533
- + if ( index !== null ) versions.set( index, index.version );
4183
+ + }
3534
4184
  +
3535
- + this._settledAttributes.set( renderObject, versions );
4185
+ + /** Release a shared GPU resource only after its last live geometry render object lets it go. */
4186
+ + releaseSharedAttribute( key, owner ) {
3536
4187
  +
3537
- + return true;
4188
+ + const record = this._sharedAttributeOwners.get( key );
4189
+ + if ( record === undefined ) return;
4190
+ + record.owners.delete( owner );
4191
+ + if ( record.owners.size !== 0 ) return;
4192
+ +
4193
+ + this.attributes.delete( key );
4194
+ + this._sharedAttributeOwners.delete( key );
4195
+ +
4196
+ + }
4197
+ +
4198
+ + /** Release the recorded sets, not a potentially replaced render object's current attributes. */
4199
+ + releaseGeometryAttributes( geometry ) {
4200
+ +
4201
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
4202
+ + if ( geometryOwners === undefined ) return;
4203
+ + for ( const [ owner, attributes ] of geometryOwners ) {
4204
+ + for ( const key of attributes.keys.keys() ) this.releaseSharedAttribute( key, owner );
4205
+ + this._renderObjectAttributeGeometry.delete( owner );
4206
+ + }
4207
+ + this._geometryAttributeOwners.delete( geometry );
3538
4208
  +
3539
4209
  + }
3540
4210
  +
3541
4211
  /**
3542
4212
  * Initializes the given geometry.
3543
4213
  *
3544
- @@ -33634,8 +34303,10 @@ class Geometries extends DataMap {
4214
+ @@ -33527,23 +34320,10 @@ class Geometries extends DataMap {
4215
+
4216
+ this.info.memory.geometries --;
4217
+
4218
+ - // index
4219
+ -
4220
+ - const index = geometry.index;
4221
+ -
4222
+ - if ( index !== null ) {
4223
+ -
4224
+ - this.attributes.delete( index );
4225
+ -
4226
+ - }
4227
+ -
4228
+ - // geometry attributes
4229
+ -
4230
+ - for ( const attribute of Object.values( geometry.attributes ) ) {
4231
+ -
4232
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
4233
+ + // index and geometry attributes: release this geometry's owners, so a buffer another
4234
+ + // geometry still draws stays alive until its last owner lets it go
4235
+
4236
+ - }
4237
+ + this.releaseGeometryAttributes( geometry );
4238
+
4239
+ // wireframe attributes
4240
+
4241
+ @@ -33634,8 +34414,10 @@ class Geometries extends DataMap {
3545
4242
  const callId = this.info.render.calls;
3546
4243
 
3547
4244
  const bufferAttribute = this.backend.getBufferAttribute( attribute );
@@ -3553,7 +4250,27 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3553
4250
 
3554
4251
  this.attributes.update( bufferAttribute, type );
3555
4252
 
3556
- @@ -35222,7 +35893,7 @@ class Bindings extends DataMap {
4253
+ @@ -33719,17 +34501,9 @@ class Geometries extends DataMap {
4254
+ */
4255
+ deleteNodeAttributes( renderObject ) {
4256
+
4257
+ - const currentAttributes = new Set( Object.values( renderObject.geometry.attributes ) );
4258
+ -
4259
+ - for ( const attribute of renderObject.getAttributes() ) {
4260
+ -
4261
+ - if ( currentAttributes.has( attribute ) === false ) {
4262
+ -
4263
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
4264
+ + // node attributes can be shared with other render objects: release this object's owners
4265
+
4266
+ - }
4267
+ -
4268
+ - }
4269
+ + this.releaseRenderObject( renderObject );
4270
+
4271
+ }
4272
+
4273
+ @@ -35222,7 +35996,7 @@ class Bindings extends DataMap {
3557
4274
  */
3558
4275
  updateForRender( renderObject ) {
3559
4276
 
@@ -3562,7 +4279,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3562
4279
 
3563
4280
  }
3564
4281
 
3565
- @@ -35320,10 +35991,16 @@ class Bindings extends DataMap {
4282
+ @@ -35320,10 +36094,16 @@ class Bindings extends DataMap {
3566
4283
 
3567
4284
  } else if ( binding.isSampledTexture ) {
3568
4285
 
@@ -3579,7 +4296,29 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3579
4296
  binding.samplerKey = this.textures.updateSampler( binding );
3580
4297
 
3581
4298
  } else if ( binding.isStorageBuffer ) {
3582
- @@ -35420,12 +36097,13 @@ class Bindings extends DataMap {
4299
+ @@ -35368,6 +36148,21 @@ class Bindings extends DataMap {
4300
+
4301
+ if ( groupData.usedTimes === 0 ) {
4302
+
4303
+ + // Stop disposed bind groups from being invalidated by later texture disposal:
4304
+ + // untrack every texture the group was ever tracked on, not only its current one.
4305
+ + const bindingData = this.backend.get( bindGroup );
4306
+ + if ( bindingData.trackedTextures ) {
4307
+ +
4308
+ + for ( const textureData of bindingData.trackedTextures ) {
4309
+ +
4310
+ + textureData.bindGroups.delete( bindGroup );
4311
+ +
4312
+ + }
4313
+ +
4314
+ + bindingData.trackedTextures.clear();
4315
+ +
4316
+ + }
4317
+ +
4318
+ for ( const binding of bindGroup.bindings ) {
4319
+
4320
+ if ( binding.isUniformBuffer ) {
4321
+ @@ -35420,12 +36215,13 @@ class Bindings extends DataMap {
3583
4322
  * Updates the given array of bindings.
3584
4323
  *
3585
4324
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -3595,7 +4334,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3595
4334
 
3596
4335
  }
3597
4336
 
3598
- @@ -35436,11 +36114,27 @@ class Bindings extends DataMap {
4337
+ @@ -35436,12 +36232,32 @@ class Bindings extends DataMap {
3599
4338
  *
3600
4339
  * @param {BindGroup} bindGroup - The bind group to update.
3601
4340
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -3606,6 +4345,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3606
4345
 
3607
4346
  const { backend } = this;
3608
4347
 
4348
+ - let needsBindingsUpdate = false;
3609
4349
  + // A group a node added after this object's first draw has no buffers and no layout yet, and
3610
4350
  + // the pipeline reads that layout whatever this draw decides to do with it - so it is built
3611
4351
  + // here, on every draw. A group that did not exist cannot have been written either, so it is
@@ -3621,15 +4361,20 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3621
4361
  + // a settled object keeps the values it uploaded the last time it refreshed, so an object
3622
4362
  + // group it has already written is the one thing in here it may skip
3623
4363
  +
3624
- let needsBindingsUpdate = false;
4364
+ + // a destroyed texture dropped this group's cached GPU groups: rebuild it even if no binding reports a change
4365
+ + const bindingsData = backend.get( bindGroup );
4366
+ + const forceBindingsUpdate = bindingsData.forceUpdate === true;
4367
+ +
4368
+ + let needsBindingsUpdate = forceBindingsUpdate;
3625
4369
  let cacheBindings = true;
3626
4370
  let cacheKeyLength = 0;
3627
- @@ -35450,12 +36144,32 @@ class Bindings extends DataMap {
4371
+ let version = 0;
4372
+ @@ -35450,12 +36266,32 @@ class Bindings extends DataMap {
3628
4373
 
3629
4374
  for ( const binding of bindGroup.bindings ) {
3630
4375
 
3631
4376
  - const updatedGroup = this.nodes.updateGroup( binding );
3632
- + const updatedGroup = this.nodes.updateGroup( binding, settled );
4377
+ + const updatedGroup = forceBindingsUpdate || this.nodes.updateGroup( binding, settled );
3633
4378
 
3634
4379
  // every uniforms group is a uniform buffer. So if no update is required,
3635
4380
  // we move one with the next binding. Otherwise the next if block will update the group.
@@ -3659,7 +4404,38 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3659
4404
 
3660
4405
  //
3661
4406
 
3662
- @@ -36587,7 +37301,8 @@ class RenderContexts {
4407
+ @@ -35523,12 +36359,20 @@ class Bindings extends DataMap {
4408
+
4409
+ }
4410
+
4411
+ - // keep track which bind groups refer to the current texture (this is needed for dispose)
4412
+ + }
4413
+ +
4414
+ + // keep track which bind groups refer to the current texture (this is needed for dispose),
4415
+ + // also when the binding's first update reported no change: a destroy must reach this group
4416
+
4417
+ - texturesTextureData.bindGroups.add( bindGroup );
4418
+ + texturesTextureData.bindGroups.add( bindGroup );
4419
+ + if ( bindingsData.trackedTextures === undefined ) {
4420
+ +
4421
+ + bindingsData.trackedTextures = new Set();
4422
+
4423
+ }
4424
+
4425
+ + bindingsData.trackedTextures.add( texturesTextureData );
4426
+ +
4427
+ const textureData = backend.get( texture );
4428
+
4429
+ if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) {
4430
+ @@ -35595,6 +36439,7 @@ class Bindings extends DataMap {
4431
+ const cacheKey = cacheBindings ? _cacheKeyIds.join( ',' ) : '';
4432
+
4433
+ this.backend.updateBindings( bindGroup, bindings, cacheKey, version );
4434
+ + bindingsData.forceUpdate = false;
4435
+
4436
+ }
4437
+
4438
+ @@ -36587,7 +37432,8 @@ class RenderContexts {
3663
4439
 
3664
4440
  }
3665
4441
 
@@ -3669,7 +4445,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3669
4445
 
3670
4446
  renderState.clearDepthValue = this.renderer.getClearDepth();
3671
4447
  renderState.clearStencilValue = this.renderer.getClearStencil();
3672
- @@ -36669,6 +37384,10 @@ class Textures extends DataMap {
4448
+ @@ -36669,6 +37515,10 @@ class Textures extends DataMap {
3673
4449
  * @type {Set<HTMLTexture>}
3674
4450
  */
3675
4451
  this._htmlTextures = new Set();
@@ -3680,7 +4456,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3680
4456
 
3681
4457
  /**
3682
4458
  * Stores weak references to the textures and render targets
3683
- @@ -36696,6 +37415,12 @@ class Textures extends DataMap {
4459
+ @@ -36696,6 +37546,12 @@ class Textures extends DataMap {
3684
4460
  */
3685
4461
  dispose() {
3686
4462
 
@@ -3693,7 +4469,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3693
4469
  for ( const ref of this._tracked ) {
3694
4470
 
3695
4471
  const object = ref.deref();
3696
- @@ -36873,7 +37598,16 @@ class Textures extends DataMap {
4472
+ @@ -36873,7 +37729,16 @@ class Textures extends DataMap {
3697
4473
  */
3698
4474
  updateTexture( texture, options = {} ) {
3699
4475
 
@@ -3710,7 +4486,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3710
4486
  if ( textureData.initialized === true && textureData.version === texture.version ) return textureData.generation;
3711
4487
 
3712
4488
  // render target textures are created with their render target
3713
- @@ -36888,6 +37622,8 @@ class Textures extends DataMap {
4489
+ @@ -36888,6 +37753,8 @@ class Textures extends DataMap {
3714
4490
 
3715
4491
  }
3716
4492
 
@@ -3719,7 +4495,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3719
4495
  const isRenderTarget = texture.isRenderTargetTexture || texture.isDepthTexture || texture.isFramebufferTexture;
3720
4496
  const backend = this.backend;
3721
4497
 
3722
- @@ -36897,6 +37633,21 @@ class Textures extends DataMap {
4498
+ @@ -36897,6 +37764,22 @@ class Textures extends DataMap {
3723
4499
 
3724
4500
  backend.destroyTexture( texture );
3725
4501
 
@@ -3733,6 +4509,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3733
4509
  +
3734
4510
  + bindingsData.groups = undefined;
3735
4511
  + bindingsData.versions = undefined;
4512
+ + bindingsData.forceUpdate = true;
3736
4513
  +
3737
4514
  + }
3738
4515
  +
@@ -3741,7 +4518,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3741
4518
  }
3742
4519
 
3743
4520
  //
3744
- @@ -37036,9 +37787,18 @@ class Textures extends DataMap {
4521
+ @@ -37036,9 +37919,18 @@ class Textures extends DataMap {
3745
4522
 
3746
4523
  if ( texture.source.dataReady === true ) {
3747
4524
 
@@ -3762,7 +4539,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3762
4539
 
3763
4540
  }
3764
4541
 
3765
- @@ -37048,7 +37808,7 @@ class Textures extends DataMap {
4542
+ @@ -37048,7 +37940,7 @@ class Textures extends DataMap {
3766
4543
 
3767
4544
  }
3768
4545
 
@@ -3771,7 +4548,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3771
4548
 
3772
4549
  }
3773
4550
 
3774
- @@ -37065,6 +37825,20 @@ class Textures extends DataMap {
4551
+ @@ -37065,6 +37957,20 @@ class Textures extends DataMap {
3775
4552
 
3776
4553
  }
3777
4554
 
@@ -3792,7 +4569,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3792
4569
  // dispose handler
3793
4570
 
3794
4571
  if ( textureData.initialized !== true ) {
3795
- @@ -37107,11 +37881,119 @@ class Textures extends DataMap {
4572
+ @@ -37107,11 +38013,119 @@ class Textures extends DataMap {
3796
4573
 
3797
4574
  }
3798
4575
 
@@ -3915,7 +4692,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3915
4692
 
3916
4693
  }
3917
4694
 
3918
- @@ -37183,7 +38065,11 @@ class Textures extends DataMap {
4695
+ @@ -37183,7 +38197,11 @@ class Textures extends DataMap {
3919
4696
 
3920
4697
  } else {
3921
4698
 
@@ -3928,7 +4705,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3928
4705
 
3929
4706
  }
3930
4707
 
3931
- @@ -37296,6 +38182,8 @@ class Textures extends DataMap {
4708
+ @@ -37296,6 +38314,8 @@ class Textures extends DataMap {
3932
4709
  */
3933
4710
  _destroyTexture( texture ) {
3934
4711
 
@@ -3937,7 +4714,15 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3937
4714
  if ( this.has( texture ) === true ) {
3938
4715
 
3939
4716
  const textureData = this.get( texture );
3940
- @@ -43390,7 +44278,8 @@ class VelocityNode extends Node {
4717
+ @@ -37325,6 +38345,7 @@ class Textures extends DataMap {
4718
+
4719
+ bindingsData.groups = undefined;
4720
+ bindingsData.versions = undefined;
4721
+ + bindingsData.forceUpdate = true;
4722
+
4723
+ // go through all bindings and if one points to the destroyed texture, trigger dispose as well
4724
+
4725
+ @@ -43390,7 +44411,8 @@ class VelocityNode extends Node {
3941
4726
 
3942
4727
  const previousModelMatrix = getPreviousMatrix( object );
3943
4728
 
@@ -3947,7 +4732,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3947
4732
 
3948
4733
  //
3949
4734
 
3950
- @@ -43917,7 +44806,7 @@ class PassMultipleTextureNode extends PassTextureNode {
4735
+ @@ -43917,7 +44939,7 @@ class PassMultipleTextureNode extends PassTextureNode {
3951
4736
  * @param {string} textureName - The output texture name.
3952
4737
  * @param {boolean} [previousTexture=false] - Whether previous frame data should be used or not.
3953
4738
  */
@@ -3956,7 +4741,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3956
4741
 
3957
4742
  // null is passed to the super call since this class does not
3958
4743
  // use an external texture for rendering pass data into. Instead
3959
- @@ -43938,6 +44827,8 @@ class PassMultipleTextureNode extends PassTextureNode {
4744
+ @@ -43938,6 +44960,8 @@ class PassMultipleTextureNode extends PassTextureNode {
3960
4745
  * @type {boolean}
3961
4746
  */
3962
4747
  this.previousTexture = previousTexture;
@@ -3965,7 +4750,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
3965
4750
 
3966
4751
  /**
3967
4752
  * This flag can be used for type testing.
3968
- @@ -43959,17 +44850,33 @@ class PassMultipleTextureNode extends PassTextureNode {
4753
+ @@ -43959,17 +44983,33 @@ class PassMultipleTextureNode extends PassTextureNode {
3969
4754
 
3970
4755
  }
3971
4756
 
@@ -4000,7 +4785,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4000
4785
  newNode.uvNode = this.uvNode;
4001
4786
  newNode.levelNode = this.levelNode;
4002
4787
  newNode.biasNode = this.biasNode;
4003
- @@ -44200,6 +45107,8 @@ class PassNode extends Node {
4788
+ @@ -44200,6 +45240,8 @@ class PassNode extends Node {
4004
4789
  * @type {Object<string, TextureNode>}
4005
4790
  */
4006
4791
  this._textureNodes = {};
@@ -4009,7 +4794,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4009
4794
 
4010
4795
  /**
4011
4796
  * A dictionary holding the internal depth nodes.
4012
- @@ -44512,12 +45421,33 @@ class PassNode extends Node {
4797
+ @@ -44512,12 +45554,33 @@ class PassNode extends Node {
4013
4798
  this._previousTextures[ name ] = texture;
4014
4799
 
4015
4800
  this._textureNodes[ name ].updateTexture();
@@ -4043,7 +4828,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4043
4828
  /**
4044
4829
  * Returns the texture node for the given output name.
4045
4830
  *
4046
- @@ -44915,6 +45845,7 @@ class PassNode extends Node {
4831
+ @@ -44915,6 +45978,7 @@ class PassNode extends Node {
4047
4832
 
4048
4833
  super.dispose();
4049
4834
 
@@ -4051,7 +4836,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4051
4836
  this.renderTarget.dispose();
4052
4837
 
4053
4838
  }
4054
- @@ -48431,6 +49362,17 @@ const shadowPositionWorld = /*@__PURE__*/ property( 'vec3', 'shadowPositionWorld
4839
+ @@ -48431,6 +49495,17 @@ const shadowPositionWorld = /*@__PURE__*/ property( 'vec3', 'shadowPositionWorld
4055
4840
 
4056
4841
  const _shadowUniforms = /*@__PURE__*/ new WeakMap();
4057
4842
 
@@ -4069,7 +4854,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4069
4854
  function getShadowUniforms( shadow ) {
4070
4855
 
4071
4856
  let uniforms = _shadowUniforms.get( shadow );
4072
- @@ -48439,7 +49381,10 @@ function getShadowUniforms( shadow ) {
4857
+ @@ -48439,7 +49514,10 @@ function getShadowUniforms( shadow ) {
4073
4858
 
4074
4859
  uniforms = {
4075
4860
  mapSize: reference( 'mapSize', 'vec2', shadow ).setGroup( renderGroup ),
@@ -4081,7 +4866,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4081
4866
  };
4082
4867
 
4083
4868
  _shadowUniforms.set( shadow, uniforms );
4084
- @@ -49487,11 +50432,7 @@ const BasicPointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp } )
4869
+ @@ -49487,11 +50565,7 @@ const BasicPointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp } )
4085
4870
  */
4086
4871
  const PointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, distance, shadow }, builder ) => {
4087
4872
 
@@ -4094,7 +4879,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4094
4879
 
4095
4880
  const texelSize = radius.div( mapSize.x ).toConst();
4096
4881
 
4097
- @@ -49534,9 +50475,7 @@ const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCo
4882
+ @@ -49534,9 +50608,7 @@ const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCo
4098
4883
  const shadowPositionAbs = shadowPosition.abs().toConst();
4099
4884
  const viewZ = shadowPositionAbs.x.max( shadowPositionAbs.y ).max( shadowPositionAbs.z );
4100
4885
 
@@ -4105,7 +4890,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4105
4890
 
4106
4891
  const result = float( 1.0 ).toVar();
4107
4892
 
4108
- @@ -54331,7 +55270,7 @@ class NodeBuilder {
4893
+ @@ -54331,7 +55403,7 @@ class NodeBuilder {
4109
4894
 
4110
4895
  let bindGroup = new BindGroup( groupName, bindings );
4111
4896
 
@@ -4114,7 +4899,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4114
4899
 
4115
4900
  bindGroup = this.renderer._bindings.getSharedBindGroup( bindGroup );
4116
4901
 
4117
- @@ -57506,7 +58445,7 @@ class NodeBuilder {
4902
+ @@ -57506,7 +58578,7 @@ class NodeBuilder {
4118
4903
 
4119
4904
  const mrt = this.renderer.getMRT();
4120
4905
 
@@ -4123,7 +4908,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4123
4908
 
4124
4909
  }
4125
4910
 
4126
- @@ -58985,15 +59924,17 @@ class NodeManager extends DataMap {
4911
+ @@ -58985,15 +60057,17 @@ class NodeManager extends DataMap {
4127
4912
  * Returns `true` if the given node uniforms group must be updated or not.
4128
4913
  *
4129
4914
  * @param {NodeUniformsGroup} nodeUniformsGroup - The node uniforms group.
@@ -4144,7 +4929,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4144
4929
 
4145
4930
  // check for update
4146
4931
 
4147
- @@ -59944,6 +60885,21 @@ class NodeManager extends DataMap {
4932
+ @@ -59944,6 +61018,21 @@ class NodeManager extends DataMap {
4148
4933
 
4149
4934
  }
4150
4935
 
@@ -4166,7 +4951,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4166
4951
  /**
4167
4952
  * Triggers the call of `updateBefore()` methods
4168
4953
  * for all nodes of the given render object.
4169
- @@ -59953,9 +60909,14 @@ class NodeManager extends DataMap {
4954
+ @@ -59953,9 +61042,14 @@ class NodeManager extends DataMap {
4170
4955
  updateBefore( renderObject ) {
4171
4956
 
4172
4957
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -4181,7 +4966,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4181
4966
  // update frame state for each node
4182
4967
 
4183
4968
  this.getNodeFrameForRender( renderObject ).updateBeforeNode( node );
4184
- @@ -59973,10 +60934,11 @@ class NodeManager extends DataMap {
4969
+ @@ -59973,10 +61067,11 @@ class NodeManager extends DataMap {
4185
4970
  updateAfter( renderObject ) {
4186
4971
 
4187
4972
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -4194,7 +4979,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4194
4979
 
4195
4980
  this.getNodeFrameForRender( renderObject ).updateAfterNode( node );
4196
4981
 
4197
- @@ -60053,9 +61015,14 @@ class NodeManager extends DataMap {
4982
+ @@ -60053,9 +61148,14 @@ class NodeManager extends DataMap {
4198
4983
 
4199
4984
  const nodeFrame = this.getNodeFrameForRender( renderObject );
4200
4985
  const nodeBuilder = renderObject.getNodeBuilderState();
@@ -4209,7 +4994,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4209
4994
  nodeFrame.updateNode( node );
4210
4995
 
4211
4996
  }
4212
- @@ -63909,6 +64876,14 @@ class Renderer {
4997
+ @@ -63909,6 +65009,14 @@ class Renderer {
4213
4998
  */
4214
4999
  this._bundles = null;
4215
5000
 
@@ -4224,7 +5009,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4224
5009
  /**
4225
5010
  * A reference to a renderer module for managing render lists.
4226
5011
  *
4227
- @@ -65840,6 +66815,18 @@ class Renderer {
5012
+ @@ -65840,6 +66948,18 @@ class Renderer {
4228
5013
 
4229
5014
  }
4230
5015
 
@@ -4243,7 +5028,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4243
5028
  /**
4244
5029
  * Can be used to transfer buffer data from a storage buffer attribute
4245
5030
  * from the GPU to the CPU in context of compute shaders.
4246
- @@ -66877,6 +67864,34 @@ class Renderer {
5031
+ @@ -66877,6 +67997,34 @@ class Renderer {
4247
5032
 
4248
5033
  }
4249
5034
 
@@ -4278,7 +5063,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4278
5063
  /**
4279
5064
  * Initializes the given render target.
4280
5065
  *
4281
- @@ -67201,7 +68216,8 @@ class Renderer {
5066
+ @@ -67201,7 +68349,8 @@ class Renderer {
4282
5067
  version,
4283
5068
  colorNode,
4284
5069
  depthNode,
@@ -4288,7 +5073,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4288
5073
  };
4289
5074
 
4290
5075
  this._cacheShadowNodes.set( material, cache );
4291
- @@ -67350,6 +68366,8 @@ class Renderer {
5076
+ @@ -67350,6 +68499,8 @@ class Renderer {
4292
5077
  let materialDisplacementMap;
4293
5078
  let materialDisplacementScale;
4294
5079
  let materialDisplacementBias;
@@ -4297,7 +5082,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4297
5082
 
4298
5083
  const previousSourceMaterial = this._currentSourceMaterial;
4299
5084
 
4300
- @@ -67375,6 +68393,8 @@ class Renderer {
5085
+ @@ -67375,6 +68526,8 @@ class Renderer {
4301
5086
  materialDisplacementMap = overrideMaterial.displacementMap;
4302
5087
  materialDisplacementScale = overrideMaterial.displacementScale;
4303
5088
  materialDisplacementBias = overrideMaterial.displacementBias;
@@ -4306,7 +5091,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4306
5091
 
4307
5092
  if ( material.positionNode && material.positionNode.isNode ) {
4308
5093
 
4309
- @@ -67393,7 +68413,7 @@ class Renderer {
5094
+ @@ -67393,7 +68546,7 @@ class Renderer {
4310
5095
 
4311
5096
  if ( overrideMaterial.isShadowPassMaterial ) {
4312
5097
 
@@ -4315,7 +5100,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4315
5100
 
4316
5101
  if ( this.shadowMap.type === VSMShadowMap ) {
4317
5102
 
4318
- @@ -67405,6 +68425,7 @@ class Renderer {
5103
+ @@ -67405,6 +68558,7 @@ class Renderer {
4319
5104
 
4320
5105
  }
4321
5106
 
@@ -4323,7 +5108,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4323
5108
  if ( colorNode !== null ) overrideMaterial.colorNode = colorNode;
4324
5109
  if ( depthNode !== null ) overrideMaterial.depthNode = depthNode;
4325
5110
  if ( positionNode !== null ) overrideMaterial.positionNode = positionNode;
4326
- @@ -67444,6 +68465,8 @@ class Renderer {
5111
+ @@ -67444,6 +68598,8 @@ class Renderer {
4327
5112
  scene.overrideMaterial.displacementMap = materialDisplacementMap;
4328
5113
  scene.overrideMaterial.displacementScale = materialDisplacementScale;
4329
5114
  scene.overrideMaterial.displacementBias = materialDisplacementBias;
@@ -4332,7 +5117,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4332
5117
 
4333
5118
  }
4334
5119
 
4335
- @@ -67505,25 +68528,18 @@ class Renderer {
5120
+ @@ -67505,25 +68661,18 @@ class Renderer {
4336
5121
 
4337
5122
  //
4338
5123
 
@@ -4341,7 +5126,8 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4341
5126
  - if ( refreshType === RenderObjectRefreshType.FULL ) {
4342
5127
  -
4343
5128
  - this._nodes.updateBefore( renderObject );
4344
- -
5129
+ + this._nodes.needsRefresh( renderObject );
5130
+
4345
5131
  - this._geometries.updateForRender( renderObject );
4346
5132
  -
4347
5133
  - this._nodes.updateForRender( renderObject );
@@ -4353,8 +5139,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4353
5139
  -
4354
5140
  - this._nodes.updateForRender( renderObject );
4355
5141
  - this._bindings.updateSharedForRender( renderObject );
4356
- + this._nodes.needsRefresh( renderObject );
4357
-
5142
+ -
4358
5143
  - }
4359
5144
  + // Every step of a draw runs, settled or not. What a settled static object skips is decided
4360
5145
  + // inside each of them - its OBJECT node updates, its object uniform group write and its
@@ -4369,7 +5154,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4369
5154
 
4370
5155
  this._pipelines.updateForRender( renderObject );
4371
5156
 
4372
- @@ -67533,7 +68549,7 @@ class Renderer {
5157
+ @@ -67533,7 +68682,7 @@ class Renderer {
4373
5158
 
4374
5159
  this.backend.draw( renderObject, this.info );
4375
5160
 
@@ -4378,7 +5163,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4378
5163
 
4379
5164
  } else if ( this._currentRenderBundle !== null ) {
4380
5165
 
4381
- @@ -82080,6 +83096,9 @@ class WebGPUTextureUtils {
5166
+ @@ -82080,6 +83229,9 @@ class WebGPUTextureUtils {
4382
5167
  */
4383
5168
  this._samplerCache = new Map();
4384
5169
 
@@ -4388,7 +5173,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4388
5173
  }
4389
5174
 
4390
5175
  /**
4391
- @@ -82312,7 +83331,12 @@ class WebGPUTextureUtils {
5176
+ @@ -82312,7 +83464,12 @@ class WebGPUTextureUtils {
4392
5177
 
4393
5178
  }
4394
5179
 
@@ -4402,7 +5187,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4402
5187
 
4403
5188
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
4404
5189
 
4405
- @@ -82418,6 +83442,23 @@ class WebGPUTextureUtils {
5190
+ @@ -82418,6 +83575,23 @@ class WebGPUTextureUtils {
4406
5191
  destroyTexture( texture, isDefaultTexture = false ) {
4407
5192
 
4408
5193
  const backend = this.backend;
@@ -4426,7 +5211,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4426
5211
  const textureData = backend.get( texture );
4427
5212
 
4428
5213
  if ( textureData.texture !== undefined && isDefaultTexture === false && texture.isExternalTexture !== true && textureData.externalTexture !== true ) textureData.texture.destroy();
4429
- @@ -82513,64 +83554,59 @@ class WebGPUTextureUtils {
5214
+ @@ -82513,64 +83687,59 @@ class WebGPUTextureUtils {
4430
5215
  const canvasTarget = backend.renderer.getCanvasTarget();
4431
5216
  const { width, height } = backend.getDrawingBufferSize();
4432
5217
  const samples = backend.renderer.currentSamples;
@@ -4478,12 +5263,12 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4478
5263
  - if ( depthTextureGPU !== undefined ) {
4479
5264
  -
4480
5265
  - if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type && depthTexture.samples === samples ) {
4481
- -
4482
- - return depthTextureGPU;
4483
5266
  + // Output and direct overlay passes alternate effective samples 4 and 1.
4484
5267
  + // Retain at most those two buffers for this canvas size and depth format.
4485
5268
  + let buffer = cache.textures.get( sampleCount );
4486
5269
 
5270
+ - return depthTextureGPU;
5271
+ -
4487
5272
  - }
4488
5273
  + if ( buffer === undefined ) {
4489
5274
 
@@ -4519,7 +5304,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4519
5304
  /**
4520
5305
  * Uploads the updated texture data to the GPU.
4521
5306
  *
4522
- @@ -82733,6 +83769,143 @@ class WebGPUTextureUtils {
5307
+ @@ -82733,6 +83902,143 @@ class WebGPUTextureUtils {
4523
5308
 
4524
5309
  }
4525
5310
 
@@ -4663,7 +5448,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4663
5448
  /**
4664
5449
  * Returns texture data as a typed array.
4665
5450
  *
4666
- @@ -82817,6 +83990,8 @@ class WebGPUTextureUtils {
5451
+ @@ -82817,6 +84123,8 @@ class WebGPUTextureUtils {
4667
5452
  */
4668
5453
  dispose() {
4669
5454
 
@@ -4672,7 +5457,82 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4672
5457
  this._samplerCache.clear();
4673
5458
 
4674
5459
  }
4675
- @@ -84814,7 +85989,7 @@ class WGSLNodeBuilder extends NodeBuilder {
5460
+ @@ -84344,6 +85652,13 @@ class WGSLNodeBuilder extends NodeBuilder {
5461
+
5462
+ super( object, renderer, new WGSLNodeParser() );
5463
+
5464
+ + /**
5465
+ + * Comparison samplers shared by identical keys, and the WGSL sampler name of each texture
5466
+ + * that reads through another texture's sampler.
5467
+ + */
5468
+ + this.sharedCompareSamplers = new Map();
5469
+ + this.samplerNames = new Map();
5470
+ +
5471
+ /**
5472
+ * A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
5473
+ * another dictionary which manages UBOs per group ('render','frame','object').
5474
+ @@ -84420,21 +85735,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5475
+
5476
+ if ( offsetSnippet ) {
5477
+
5478
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
5479
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
5480
+
5481
+ }
5482
+
5483
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
5484
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
5485
+
5486
+ } else {
5487
+
5488
+ if ( offsetSnippet ) {
5489
+
5490
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
5491
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
5492
+
5493
+ }
5494
+
5495
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
5496
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet } )`;
5497
+
5498
+ }
5499
+
5500
+ @@ -84466,21 +85781,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5501
+
5502
+ if ( offsetSnippet ) {
5503
+
5504
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5505
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5506
+
5507
+ }
5508
+
5509
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
5510
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
5511
+
5512
+ } else {
5513
+
5514
+ if ( offsetSnippet ) {
5515
+
5516
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5517
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5518
+
5519
+ }
5520
+
5521
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
5522
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
5523
+
5524
+ }
5525
+
5526
+ @@ -84743,7 +86058,7 @@ class WGSLNodeBuilder extends NodeBuilder {
5527
+ // Depth textures require integer level, regular textures use float
5528
+ const levelType = texture.isDepthTexture ? 'u32' : 'f32';
5529
+
5530
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
5531
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
5532
+
5533
+ }
5534
+
5535
+ @@ -84814,7 +86129,7 @@ class WGSLNodeBuilder extends NodeBuilder {
4676
5536
  * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
4677
5537
  * @return {string} The WGSL snippet.
4678
5538
  */
@@ -4681,7 +5541,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4681
5541
 
4682
5542
  if ( levelSnippet === null ) levelSnippet = '0u';
4683
5543
 
4684
- @@ -84832,7 +86007,14 @@ class WGSLNodeBuilder extends NodeBuilder {
5544
+ @@ -84832,7 +86147,14 @@ class WGSLNodeBuilder extends NodeBuilder {
4685
5545
 
4686
5546
  } else {
4687
5547
 
@@ -4697,16 +5557,214 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4697
5557
 
4698
5558
  if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
4699
5559
 
4700
- @@ -85460,7 +86642,7 @@ class WGSLNodeBuilder extends NodeBuilder {
5560
+ @@ -84880,6 +86202,18 @@ class WGSLNodeBuilder extends NodeBuilder {
5561
+ * @param {Texture} texture - The texture.
5562
+ * @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
5563
+ */
5564
+ + /**
5565
+ + * The WGSL sampler a texture reads through: its own, or a shared comparison sampler.
5566
+ + *
5567
+ + * @param {string} textureProperty - The texture's WGSL name.
5568
+ + * @return {string} The sampler's WGSL name.
5569
+ + */
5570
+ + getSamplerName( textureProperty ) {
5571
+ +
5572
+ + return this.samplerNames.get( textureProperty ) ?? `${ textureProperty }_sampler`;
5573
+ +
5574
+ + }
5575
+ +
5576
+ isSampleCompare( texture ) {
5577
+
5578
+ return texture.isDepthTexture === true && texture.compareFunction !== null && this.renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
5579
+ @@ -84956,21 +86290,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5580
+
5581
+ if ( offsetSnippet ) {
5582
+
5583
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
5584
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
5585
+
5586
+ }
5587
+
5588
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
5589
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
5590
+
5591
+ } else {
5592
+
5593
+ if ( offsetSnippet ) {
5594
+
5595
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
5596
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
5597
+
5598
+ }
5599
+
5600
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
5601
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
5602
+
5603
+ }
5604
+
5605
+ @@ -85003,21 +86337,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5606
+
5607
+ if ( offsetSnippet ) {
5608
+
5609
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5610
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5611
+
5612
+ }
5613
+
5614
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
5615
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
5616
+
5617
+ }
5618
+
5619
+ if ( offsetSnippet ) {
5620
+
5621
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5622
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5623
+
5624
+ }
5625
+
5626
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
5627
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet } )`;
5628
+
5629
+ } else {
5630
+
5631
+ @@ -85082,21 +86416,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5632
+
5633
+ if ( offsetSnippet ) {
5634
+
5635
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
5636
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
5637
+
5638
+ }
5639
+
5640
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
5641
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
5642
+
5643
+ }
5644
+
5645
+ if ( offsetSnippet ) {
5646
+
5647
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
5648
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
5649
+
5650
+ }
5651
+
5652
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet })`;
5653
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet })`;
5654
+
5655
+ }
5656
+
5657
+ @@ -85117,21 +86451,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5658
+
5659
+ if ( offsetSnippet ) {
5660
+
5661
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5662
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5663
+
5664
+ }
5665
+
5666
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
5667
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
5668
+
5669
+ }
5670
+
5671
+ if ( offsetSnippet ) {
5672
+
5673
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5674
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
5675
+
5676
+ }
5677
+
5678
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet })`;
5679
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet })`;
5680
+
5681
+ }
5682
+
5683
+ @@ -85154,21 +86488,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5684
+
5685
+ if ( offsetSnippet ) {
5686
+
5687
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5688
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5689
+
5690
+ }
5691
+
5692
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
5693
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
5694
+
5695
+ } else {
5696
+
5697
+ if ( offsetSnippet ) {
5698
+
5699
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5700
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
5701
+
5702
+ }
5703
+
5704
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
5705
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
5706
+
5707
+ }
5708
+
5709
+ @@ -85204,21 +86538,21 @@ class WGSLNodeBuilder extends NodeBuilder {
5710
+
5711
+ if ( offsetSnippet ) {
5712
+
5713
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
5714
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
5715
+
5716
+ }
5717
+
5718
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
5719
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
5720
+
5721
+ } else {
5722
+
5723
+ if ( offsetSnippet ) {
5724
+
5725
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
5726
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
5727
+
5728
+ }
5729
+
5730
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
5731
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet } )`;
5732
+
5733
+ }
5734
+
5735
+ @@ -85460,13 +86794,29 @@ class WGSLNodeBuilder extends NodeBuilder {
4701
5736
 
4702
5737
  // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
4703
5738
  // Also textureGather always need sampler.
4704
5739
  - const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
4705
5740
  + const needsSampler = node.isRawTextureNode !== true && ( node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null );
5741
+ +
5742
+ + // Identical comparison samplers share one binding. Every shadow map of a clipmap compares the
5743
+ + // same way, and a sampler per map exhausts maxSamplersPerShaderStage (16 on most adapters).
5744
+ + const sharedKey = needsSampler && this.isSampleCompare( node.value ) && node.isSampleCompare() ? `${ groupName }:${ shaderStage }:${ node.value.compareFunction }:${ node.value.wrapS }:${ node.value.wrapT }:${ node.value.wrapR }:${ node.value.minFilter }:${ node.value.magFilter }` : null;
5745
+ + const sharedSampler = sharedKey === null ? undefined : this.sharedCompareSamplers.get( sharedKey );
4706
5746
 
4707
- if ( needsSampler ) {
5747
+ - if ( needsSampler ) {
5748
+ + if ( sharedSampler !== undefined ) {
5749
+ +
5750
+ + this.samplerNames.set( uniformNode.name, sharedSampler.name );
5751
+ + nodeData.sharedSampler = true;
5752
+ +
5753
+ + bindings.push( texture );
5754
+ +
5755
+ + uniformGPU = [ sharedSampler, texture ];
5756
+ +
5757
+ + } else if ( needsSampler ) {
5758
+
5759
+ const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
5760
+ sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
4708
5761
 
4709
- @@ -85873,7 +87055,10 @@ ${ flowData.code }
5762
+ + if ( sharedKey !== null ) this.sharedCompareSamplers.set( sharedKey, sampler );
5763
+ +
5764
+ bindings.push( sampler, texture );
5765
+
5766
+ uniformGPU = [ sampler, texture ];
5767
+ @@ -85873,7 +87223,10 @@ ${ flowData.code }
4710
5768
 
4711
5769
  for ( const { name, property, type } of builtins.values() ) {
4712
5770
 
@@ -4718,7 +5776,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4718
5776
 
4719
5777
  snippets.push( `${ invariant }@builtin( ${name} ) ${property} : ${type}` );
4720
5778
 
4721
- @@ -86177,6 +87362,8 @@ ${ flowData.code }
5779
+ @@ -86177,6 +87530,8 @@ ${ flowData.code }
4722
5780
  getVaryings( shaderStage ) {
4723
5781
 
4724
5782
  const snippets = [];
@@ -4727,7 +5785,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4727
5785
 
4728
5786
  if ( shaderStage === 'vertex' ) {
4729
5787
 
4730
- @@ -86199,7 +87386,12 @@ ${ flowData.code }
5788
+ @@ -86199,7 +87554,12 @@ ${ flowData.code }
4731
5789
 
4732
5790
  let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
4733
5791
 
@@ -4741,7 +5799,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4741
5799
 
4742
5800
  const samplingSnippet = varying.interpolationSampling !== null ? `, ${ varying.interpolationSampling } )` : ' )';
4743
5801
 
4744
- @@ -86261,9 +87453,12 @@ ${ flowData.code }
5802
+ @@ -86261,11 +87621,15 @@ ${ flowData.code }
4745
5803
  const textureNode = uniform.node;
4746
5804
  const texture = textureNode.value;
4747
5805
 
@@ -4755,9 +5813,13 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4755
5813
  + const uniformGPU = nodeData.uniformGPU;
4756
5814
  + const needsSampler = Array.isArray( uniformGPU ) && uniformGPU[ 0 ].isSampler === true && uniformGPU[ 0 ].isSampledTexture !== true;
4757
5815
 
4758
- if ( needsSampler ) {
5816
+ - if ( needsSampler ) {
5817
+ + // A shared comparison sampler is declared once, by the texture that created it.
5818
+ + if ( needsSampler && nodeData.sharedSampler !== true ) {
5819
+
5820
+ if ( this.isSampleCompare( texture ) && textureNode.isSampleCompare() ) {
4759
5821
 
4760
- @@ -86285,7 +87480,7 @@ ${ flowData.code }
5822
+ @@ -86285,7 +87649,7 @@ ${ flowData.code }
4761
5823
 
4762
5824
  const { primarySamples } = backend.utils.getTextureSampleData( texture );
4763
5825
 
@@ -4766,7 +5828,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4766
5828
 
4767
5829
  multisampled = '_multisampled';
4768
5830
 
4769
- @@ -87085,6 +88280,15 @@ class WebGPUAttributeUtils {
5831
+ @@ -87085,6 +88449,15 @@ class WebGPUAttributeUtils {
4770
5832
  buffer.unmap();
4771
5833
 
4772
5834
  bufferData.buffer = buffer;
@@ -4782,7 +5844,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4782
5844
 
4783
5845
  }
4784
5846
 
4785
- @@ -87104,6 +88308,11 @@ class WebGPUAttributeUtils {
5847
+ @@ -87104,6 +88477,11 @@ class WebGPUAttributeUtils {
4786
5848
  const bufferData = backend.get( bufferAttribute );
4787
5849
  const buffer = backend.get( bufferAttribute ).buffer;
4788
5850
 
@@ -4794,7 +5856,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4794
5856
  let array = bufferAttribute.array;
4795
5857
 
4796
5858
  const itemSize = bufferData._itemSize;
4797
- @@ -87192,6 +88401,9 @@ class WebGPUAttributeUtils {
5859
+ @@ -87192,6 +88570,9 @@ class WebGPUAttributeUtils {
4798
5860
 
4799
5861
  }
4800
5862
 
@@ -4804,7 +5866,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4804
5866
  }
4805
5867
 
4806
5868
  /**
4807
- @@ -87306,9 +88518,14 @@ class WebGPUAttributeUtils {
5869
+ @@ -87306,9 +88687,14 @@ class WebGPUAttributeUtils {
4808
5870
  const bufferAttribute = backend.getBufferAttribute( attribute );
4809
5871
  const data = backend.get( bufferAttribute );
4810
5872
 
@@ -4821,7 +5883,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4821
5883
 
4822
5884
  }
4823
5885
 
4824
- @@ -87591,18 +88808,16 @@ class WebGPUBindingUtils {
5886
+ @@ -87591,18 +88977,16 @@ class WebGPUBindingUtils {
4825
5887
 
4826
5888
  const bindingsData = backend.get( bindGroup );
4827
5889
 
@@ -4835,17 +5897,17 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4835
5897
  + if ( bindingsData.layoutKey === bindGroupLayoutKey ) return bindingsData.layout.layoutGPU;
4836
5898
 
4837
5899
  - }
4838
- -
4839
- - // if not, assing one
4840
5900
  + this.deleteBindGroupData( bindGroup );
4841
5901
 
5902
+ - // if not, assing one
5903
+ -
4842
5904
  - const entries = this._createLayoutEntries( bindGroup );
4843
5905
  - const bindGroupLayoutKey = hashString( JSON.stringify( entries ) );
4844
5906
  + }
4845
5907
 
4846
5908
  // try to find an existing layout in the cache
4847
5909
 
4848
- @@ -87823,7 +89038,20 @@ class WebGPUBindingUtils {
5910
+ @@ -87823,7 +89207,20 @@ class WebGPUBindingUtils {
4849
5911
 
4850
5912
  let resourceGPU;
4851
5913
 
@@ -4867,7 +5929,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4867
5929
 
4868
5930
  resourceGPU = device.importExternalTexture( { source: textureData.externalTexture } );
4869
5931
 
4870
- @@ -88000,7 +89228,7 @@ class WebGPUBindingUtils {
5932
+ @@ -88000,7 +89397,7 @@ class WebGPUBindingUtils {
4871
5933
 
4872
5934
  const { primarySamples } = backend.utils.getTextureSampleData( binding.texture );
4873
5935
 
@@ -4876,7 +5938,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4876
5938
 
4877
5939
  texture.multisampled = true;
4878
5940
 
4879
- @@ -88042,7 +89270,7 @@ class WebGPUBindingUtils {
5941
+ @@ -88042,7 +89439,7 @@ class WebGPUBindingUtils {
4880
5942
 
4881
5943
  } else if ( type === FloatType ) {
4882
5944
 
@@ -4885,7 +5947,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4885
5947
 
4886
5948
  texture.sampleType = GPUTextureSampleType.Float;
4887
5949
 
4888
- @@ -88134,6 +89362,9 @@ class WebGPUBindingUtils {
5950
+ @@ -88134,6 +89531,9 @@ class WebGPUBindingUtils {
4889
5951
 
4890
5952
  }
4891
5953
 
@@ -4895,7 +5957,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4895
5957
  }
4896
5958
 
4897
5959
  /**
4898
- @@ -88558,7 +89789,13 @@ class WebGPUPipelineUtils {
5960
+ @@ -88558,7 +89958,13 @@ class WebGPUPipelineUtils {
4899
5961
 
4900
5962
  // Pop the error scope before awaiting the pipeline, so several pipelines
4901
5963
  // can be created at the same time without mixing their error scopes.
@@ -4910,7 +5972,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4910
5972
 
4911
5973
  if ( pipelinePromise !== null ) {
4912
5974
 
4913
- @@ -89895,6 +91132,27 @@ class WebGPUBackend extends Backend {
5975
+ @@ -89895,6 +91301,27 @@ class WebGPUBackend extends Backend {
4914
5976
  */
4915
5977
  this.compatibilityMode = null;
4916
5978
 
@@ -4938,7 +6000,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4938
6000
  /**
4939
6001
  * A reference to the device.
4940
6002
  *
4941
- @@ -90007,7 +91265,11 @@ class WebGPUBackend extends Backend {
6003
+ @@ -90007,7 +91434,11 @@ class WebGPUBackend extends Backend {
4942
6004
  xrCompatible: renderer.xr.enabled
4943
6005
  };
4944
6006
 
@@ -4951,7 +6013,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4951
6013
 
4952
6014
  if ( adapter === null ) {
4953
6015
 
4954
- @@ -90235,7 +91497,9 @@ class WebGPUBackend extends Backend {
6016
+ @@ -90235,7 +91666,9 @@ class WebGPUBackend extends Backend {
4955
6017
 
4956
6018
  let descriptor = canvasData.descriptor;
4957
6019
 
@@ -4962,7 +6024,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4962
6024
 
4963
6025
  descriptor = new GPURenderPassDescriptor();
4964
6026
  descriptor.colorAttachments.push( new GPURenderPassColorAttachment() );
4965
- @@ -90262,6 +91526,9 @@ class WebGPUBackend extends Backend {
6027
+ @@ -90262,6 +91695,9 @@ class WebGPUBackend extends Backend {
4966
6028
 
4967
6029
  canvasData.descriptor = descriptor;
4968
6030
  canvasData.samples = samples;
@@ -4972,7 +6034,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4972
6034
 
4973
6035
  }
4974
6036
 
4975
- @@ -92203,6 +93470,7 @@ class WebGPUBackend extends Backend {
6037
+ @@ -92203,6 +93639,7 @@ class WebGPUBackend extends Backend {
4976
6038
  const utils = this.utils;
4977
6039
 
4978
6040
  const sampleCount = utils.getSampleCountRenderContext( renderObject.context );
@@ -4980,7 +6042,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4980
6042
  const colorSpace = utils.getCurrentColorSpace( renderObject.context );
4981
6043
  const colorFormat = utils.getCurrentColorFormat( renderObject.context );
4982
6044
  const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context );
4983
- @@ -92227,7 +93495,8 @@ class WebGPUBackend extends Backend {
6045
+ @@ -92227,7 +93664,8 @@ class WebGPUBackend extends Backend {
4984
6046
  data.primitiveTopology !== primitiveTopology || data.stripIndexFormat !== stripIndexFormat ||
4985
6047
  data.frontFaceCW !== frontFaceCW ||
4986
6048
  data.geometryVersion !== renderObject.geometryVersion ||
@@ -4990,7 +6052,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4990
6052
  ) {
4991
6053
 
4992
6054
  data.material = material; data.materialVersion = material.version;
4993
- @@ -92250,6 +93519,7 @@ class WebGPUBackend extends Backend {
6055
+ @@ -92250,6 +93688,7 @@ class WebGPUBackend extends Backend {
4994
6056
  data.frontFaceCW = frontFaceCW;
4995
6057
  data.geometryVersion = renderObject.geometryVersion;
4996
6058
  data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
@@ -4998,7 +6060,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
4998
6060
 
4999
6061
  needsUpdate = true;
5000
6062
 
5001
- @@ -92271,6 +93541,7 @@ class WebGPUBackend extends Backend {
6063
+ @@ -92271,6 +93710,7 @@ class WebGPUBackend extends Backend {
5002
6064
 
5003
6065
  const utils = this.utils;
5004
6066
  const renderContext = renderObject.context;
@@ -5006,7 +6068,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
5006
6068
 
5007
6069
  // meshes with negative scale have a different frontFace render pipeline
5008
6070
  // descriptor value so the following must be honored in the cache key
5009
- @@ -92290,9 +93561,11 @@ class WebGPUBackend extends Backend {
6071
+ @@ -92290,9 +93730,11 @@ class WebGPUBackend extends Backend {
5010
6072
  material.side, material.alphaToCoverage,
5011
6073
  frontFaceCW,
5012
6074
  utils.getSampleCountRenderContext( renderContext ),
@@ -5018,7 +6080,7 @@ index 39c897cb2f5f2092419c2cd4f464a88f1151d7d0..825b83f785e7d86ca3bababda95202ab
5018
6080
  renderObject.clippingContextCacheKey
5019
6081
  ].join();
5020
6082
 
5021
- @@ -92360,6 +93633,12 @@ class WebGPUBackend extends Backend {
6083
+ @@ -92360,6 +93802,12 @@ class WebGPUBackend extends Backend {
5022
6084
 
5023
6085
  }
5024
6086
 
@@ -5076,7 +6138,7 @@ index fe9885f8fc637d74f37d126c12b503d353e9c20c..6a815e9601d12d19b1328daa47187455
5076
6138
 
5077
6139
  const xSpan = xLen.div( totalStep ).toVar();
5078
6140
  diff --git a/src/materials/nodes/manager/NodeMaterialObserver.js b/src/materials/nodes/manager/NodeMaterialObserver.js
5079
- index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5f1cfbf9b 100644
6141
+ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..239556dc65ed767755f10a57d82dbfee0b79bce3 100644
5080
6142
  --- a/src/materials/nodes/manager/NodeMaterialObserver.js
5081
6143
  +++ b/src/materials/nodes/manager/NodeMaterialObserver.js
5082
6144
  @@ -173,6 +173,15 @@ class NodeMaterialObserver {
@@ -5095,7 +6157,7 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5095
6157
  }
5096
6158
 
5097
6159
  /**
5098
- @@ -351,6 +360,88 @@ class NodeMaterialObserver {
6160
+ @@ -351,6 +360,92 @@ class NodeMaterialObserver {
5099
6161
 
5100
6162
  }
5101
6163
 
@@ -5146,7 +6208,8 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5146
6208
  + environmentRotation: scene.environmentRotation.clone(),
5147
6209
  + environmentIntensity: scene.environmentIntensity,
5148
6210
  + materialVersion: material.version,
5149
- + geometryVersion: geometry.version
6211
+ + geometryVersion: geometry.version,
6212
+ + pmremSwaps: renderObject.renderer._tnPmremSwaps
5150
6213
  + };
5151
6214
  +
5152
6215
  + data.settledState = false;
@@ -5159,7 +6222,9 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5159
6222
  + settled.environmentRotation.equals( scene.environmentRotation ) !== true ||
5160
6223
  + settled.environmentIntensity !== scene.environmentIntensity ||
5161
6224
  + settled.materialVersion !== material.version ||
5162
- + settled.geometryVersion !== geometry.version ) {
6225
+ + settled.geometryVersion !== geometry.version ||
6226
+ + // a PMREM finished and swapped the texture its node samples: a settled object would keep the old one
6227
+ + settled.pmremSwaps !== renderObject.renderer._tnPmremSwaps ) {
5163
6228
  +
5164
6229
  + // re-arm with the current state, so the object settles again once it stops changing
5165
6230
  +
@@ -5168,6 +6233,7 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5168
6233
  + settled.environmentIntensity = scene.environmentIntensity;
5169
6234
  + settled.materialVersion = material.version;
5170
6235
  + settled.geometryVersion = geometry.version;
6236
+ + settled.pmremSwaps = renderObject.renderer._tnPmremSwaps;
5171
6237
  +
5172
6238
  + data.settledState = false;
5173
6239
  +
@@ -5184,7 +6250,7 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5184
6250
  /**
5185
6251
  * Returns an attribute data structure holding the attributes versions for
5186
6252
  * monitoring.
5187
- @@ -1072,7 +1163,17 @@ class NodeMaterialObserver {
6253
+ @@ -1072,7 +1167,17 @@ class NodeMaterialObserver {
5188
6254
  */
5189
6255
  needsRefresh( renderObject, nodeFrame ) {
5190
6256
 
@@ -5203,7 +6269,7 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5203
6269
  return RenderObjectRefreshType.FULL;
5204
6270
 
5205
6271
  const { renderId } = nodeFrame;
5206
- @@ -1115,10 +1216,14 @@ class NodeMaterialObserver {
6272
+ @@ -1115,10 +1220,14 @@ class NodeMaterialObserver {
5207
6273
 
5208
6274
  }
5209
6275
 
@@ -5221,7 +6287,7 @@ index ef3f6c708565ade074aaf8b0f370e003d5e264d9..bd94730965dcc321ecb12083980f7da5
5221
6287
 
5222
6288
  const lightsData = this.getLights( renderObject.lightsNode, renderId );
5223
6289
  diff --git a/src/nodes/accessors/Instance.js b/src/nodes/accessors/Instance.js
5224
- index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491dee9d607af 100644
6290
+ index 4566ef64b623f9924ca9add625053fb84dfc73fd..d8594793e78a2f0b8ad38cecef9451ed9c8a32aa 100644
5225
6291
  --- a/src/nodes/accessors/Instance.js
5226
6292
  +++ b/src/nodes/accessors/Instance.js
5227
6293
  @@ -1,6 +1,6 @@
@@ -5242,7 +6308,7 @@ index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491de
5242
6308
 
5243
6309
  instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', matrixCount ).element( instanceIndex );
5244
6310
 
5245
- @@ -294,8 +295,25 @@ export const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder
6311
+ @@ -294,8 +295,30 @@ export const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder
5246
6312
 
5247
6313
  const instancedMesh = builder.object;
5248
6314
 
@@ -5255,8 +6321,11 @@ index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491de
5255
6321
  +
5256
6322
  + const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
5257
6323
  +
6324
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
6325
+ +
5258
6326
  + previousInstanceMatrix.array.set( scheduledPrevious );
5259
6327
  + previousInstanceMatrix.needsUpdate = true;
6328
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
5260
6329
  +
5261
6330
  + } );
5262
6331
  +
@@ -5264,11 +6333,13 @@ index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491de
5264
6333
  OnAfterObjectUpdate( ( { object } ) => {
5265
6334
 
5266
6335
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
6336
+ +
6337
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
5267
6338
  +
5268
6339
  const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );
5269
6340
 
5270
6341
  previousInstanceMatrix.array.set( matrices.array );
5271
- @@ -337,8 +355,25 @@ export const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) =>
6342
+ @@ -337,8 +360,30 @@ export const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ], builder ) =>
5272
6343
 
5273
6344
  if ( builder.needsPreviousData() ) {
5274
6345
 
@@ -5281,8 +6352,11 @@ index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491de
5281
6352
  +
5282
6353
  + const previous = getPreviousMatrix( object );
5283
6354
  +
6355
+ + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] === scheduledPrevious ) return;
6356
+ +
5284
6357
  + previous.array.set( scheduledPrevious );
5285
6358
  + previous.needsUpdate = true;
6359
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = scheduledPrevious;
5286
6360
  +
5287
6361
  + } );
5288
6362
  +
@@ -5290,6 +6364,8 @@ index 4566ef64b623f9924ca9add625053fb84dfc73fd..57b6ebfcc3e8be56ec503a9d4ac491de
5290
6364
  OnAfterObjectUpdate( ( { object } ) => {
5291
6365
 
5292
6366
  + if ( object[ Symbol.for( 'threenative.velocity.previousInstanceMatrices' ) ] !== undefined ) return;
6367
+ +
6368
+ + object[ Symbol.for( 'threenative.velocity.previousInstanceMatricesApplied' ) ] = undefined;
5293
6369
  +
5294
6370
  const previous = getPreviousMatrix( object );
5295
6371
 
@@ -5620,7 +6696,7 @@ index ad570dfdc60027d409cf3872700df5b58190e47a..ac1515bf34c5f8aa1527442fa9bbc789
5620
6696
 
5621
6697
  _shadowUniforms.set( shadow, uniforms );
5622
6698
  diff --git a/src/nodes/pmrem/PMREMNode.js b/src/nodes/pmrem/PMREMNode.js
5623
- index 8b82efb52830b1930020a0f7fb46e6d75546918f..0f7851b615cadc9cb971e0377bfecb5c23c4afef 100644
6699
+ index 8b82efb52830b1930020a0f7fb46e6d75546918f..5dc2f396f729b6eca2d04c4114bb163930fc2e92 100644
5624
6700
  --- a/src/nodes/pmrem/PMREMNode.js
5625
6701
  +++ b/src/nodes/pmrem/PMREMNode.js
5626
6702
  @@ -10,6 +10,39 @@ import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
@@ -5854,6 +6930,16 @@ index 8b82efb52830b1930020a0f7fb46e6d75546918f..0f7851b615cadc9cb971e0377bfecb5c
5854
6930
  set value( value ) {
5855
6931
 
5856
6932
  this._value = value;
6933
+ @@ -288,6 +438,9 @@ class PMREMNode extends Node {
6934
+
6935
+ this._pmrem = pmrem;
6936
+
6937
+ + // count the swap, so every settled object that samples this node refreshes once (NodeMaterialObserver)
6938
+ + if ( this._texture.value !== pmrem && frame.renderer ) frame.renderer._tnPmremSwaps = ( frame.renderer._tnPmremSwaps || 0 ) + 1;
6939
+ +
6940
+ this.updateFromTexture( pmrem );
6941
+
6942
+ }
5857
6943
  diff --git a/src/objects/BatchedMesh.js b/src/objects/BatchedMesh.js
5858
6944
  index 048ea7bb6c12a7c29aec1174cab55c257acd016b..49bf94b353144dd0296a1172354d65942795a259 100644
5859
6945
  --- a/src/objects/BatchedMesh.js
@@ -5868,7 +6954,7 @@ index 048ea7bb6c12a7c29aec1174cab55c257acd016b..49bf94b353144dd0296a1172354d6594
5868
6954
  * Constructs a new batched mesh.
5869
6955
  *
5870
6956
  diff --git a/src/renderers/common/Bindings.js b/src/renderers/common/Bindings.js
5871
- index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac8094ad4ce9 100644
6957
+ index 54665d3ce701defa5242517ab4be343888ce4956..a0423e27dde75aaf072c8b26eb5101051e8b5193 100644
5872
6958
  --- a/src/renderers/common/Bindings.js
5873
6959
  +++ b/src/renderers/common/Bindings.js
5874
6960
  @@ -232,7 +232,7 @@ class Bindings extends DataMap {
@@ -5897,7 +6983,29 @@ index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac80
5897
6983
  binding.samplerKey = this.textures.updateSampler( binding );
5898
6984
 
5899
6985
  } else if ( binding.isStorageBuffer ) {
5900
- @@ -430,12 +436,13 @@ class Bindings extends DataMap {
6986
+ @@ -378,6 +384,21 @@ class Bindings extends DataMap {
6987
+
6988
+ if ( groupData.usedTimes === 0 ) {
6989
+
6990
+ + // Stop disposed bind groups from being invalidated by later texture disposal:
6991
+ + // untrack every texture the group was ever tracked on, not only its current one.
6992
+ + const bindingData = this.backend.get( bindGroup );
6993
+ + if ( bindingData.trackedTextures ) {
6994
+ +
6995
+ + for ( const textureData of bindingData.trackedTextures ) {
6996
+ +
6997
+ + textureData.bindGroups.delete( bindGroup );
6998
+ +
6999
+ + }
7000
+ +
7001
+ + bindingData.trackedTextures.clear();
7002
+ +
7003
+ + }
7004
+ +
7005
+ for ( const binding of bindGroup.bindings ) {
7006
+
7007
+ if ( binding.isUniformBuffer ) {
7008
+ @@ -430,12 +451,13 @@ class Bindings extends DataMap {
5901
7009
  * Updates the given array of bindings.
5902
7010
  *
5903
7011
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -5913,7 +7021,7 @@ index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac80
5913
7021
 
5914
7022
  }
5915
7023
 
5916
- @@ -446,11 +453,27 @@ class Bindings extends DataMap {
7024
+ @@ -446,12 +468,32 @@ class Bindings extends DataMap {
5917
7025
  *
5918
7026
  * @param {BindGroup} bindGroup - The bind group to update.
5919
7027
  * @param {Array<BindGroup>} bindings - The bind groups.
@@ -5924,6 +7032,7 @@ index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac80
5924
7032
 
5925
7033
  const { backend } = this;
5926
7034
 
7035
+ - let needsBindingsUpdate = false;
5927
7036
  + // A group a node added after this object's first draw has no buffers and no layout yet, and
5928
7037
  + // the pipeline reads that layout whatever this draw decides to do with it - so it is built
5929
7038
  + // here, on every draw. A group that did not exist cannot have been written either, so it is
@@ -5939,15 +7048,20 @@ index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac80
5939
7048
  + // a settled object keeps the values it uploaded the last time it refreshed, so an object
5940
7049
  + // group it has already written is the one thing in here it may skip
5941
7050
  +
5942
- let needsBindingsUpdate = false;
7051
+ + // a destroyed texture dropped this group's cached GPU groups: rebuild it even if no binding reports a change
7052
+ + const bindingsData = backend.get( bindGroup );
7053
+ + const forceBindingsUpdate = bindingsData.forceUpdate === true;
7054
+ +
7055
+ + let needsBindingsUpdate = forceBindingsUpdate;
5943
7056
  let cacheBindings = true;
5944
7057
  let cacheKeyLength = 0;
5945
- @@ -460,12 +483,32 @@ class Bindings extends DataMap {
7058
+ let version = 0;
7059
+ @@ -460,12 +502,32 @@ class Bindings extends DataMap {
5946
7060
 
5947
7061
  for ( const binding of bindGroup.bindings ) {
5948
7062
 
5949
7063
  - const updatedGroup = this.nodes.updateGroup( binding );
5950
- + const updatedGroup = this.nodes.updateGroup( binding, settled );
7064
+ + const updatedGroup = forceBindingsUpdate || this.nodes.updateGroup( binding, settled );
5951
7065
 
5952
7066
  // every uniforms group is a uniform buffer. So if no update is required,
5953
7067
  // we move one with the next binding. Otherwise the next if block will update the group.
@@ -5977,11 +7091,42 @@ index 54665d3ce701defa5242517ab4be343888ce4956..d44e9db6b1b87139f40eb33ab217ac80
5977
7091
 
5978
7092
  //
5979
7093
 
7094
+ @@ -533,12 +595,20 @@ class Bindings extends DataMap {
7095
+
7096
+ }
7097
+
7098
+ - // keep track which bind groups refer to the current texture (this is needed for dispose)
7099
+ + }
7100
+ +
7101
+ + // keep track which bind groups refer to the current texture (this is needed for dispose),
7102
+ + // also when the binding's first update reported no change: a destroy must reach this group
7103
+
7104
+ - texturesTextureData.bindGroups.add( bindGroup );
7105
+ + texturesTextureData.bindGroups.add( bindGroup );
7106
+ + if ( bindingsData.trackedTextures === undefined ) {
7107
+ +
7108
+ + bindingsData.trackedTextures = new Set();
7109
+
7110
+ }
7111
+
7112
+ + bindingsData.trackedTextures.add( texturesTextureData );
7113
+ +
7114
+ const textureData = backend.get( texture );
7115
+
7116
+ if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) {
7117
+ @@ -605,6 +675,7 @@ class Bindings extends DataMap {
7118
+ const cacheKey = cacheBindings ? _cacheKeyIds.join( ',' ) : '';
7119
+
7120
+ this.backend.updateBindings( bindGroup, bindings, cacheKey, version );
7121
+ + bindingsData.forceUpdate = false;
7122
+
7123
+ }
7124
+
5980
7125
  diff --git a/src/renderers/common/Geometries.js b/src/renderers/common/Geometries.js
5981
- index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aafc0132a6e 100644
7126
+ index 086ab906cd5b6a91552d2afbecceb006332815e9..5d9268aecd1189ff355055e120a8993cb1be48cc 100644
5982
7127
  --- a/src/renderers/common/Geometries.js
5983
7128
  +++ b/src/renderers/common/Geometries.js
5984
- @@ -161,6 +161,14 @@ class Geometries extends DataMap {
7129
+ @@ -161,6 +161,17 @@ class Geometries extends DataMap {
5985
7130
  */
5986
7131
  this._registry = new FinalizationRegistry( ( ref ) => this._tracked.delete( ref ) );
5987
7132
 
@@ -5992,14 +7137,19 @@ index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aaf
5992
7137
  + * @type {WeakMap<RenderObject,Map<BufferAttribute,number>>}
5993
7138
  + */
5994
7139
  + this._settledAttributes = new WeakMap();
7140
+ + this._geometryAttributeOwners = new WeakMap();
7141
+ + this._sharedAttributeOwners = new WeakMap();
7142
+ + this._renderObjectAttributeGeometry = new WeakMap();
5995
7143
  +
5996
7144
  }
5997
7145
 
5998
7146
  /**
5999
- @@ -186,10 +194,69 @@ class Geometries extends DataMap {
7147
+ @@ -185,11 +196,173 @@ class Geometries extends DataMap {
7148
+ const geometry = renderObject.geometry;
6000
7149
 
6001
7150
  if ( this.has( geometry ) === false ) this.initGeometry( geometry );
6002
-
7151
+ + if ( this.geometryAttributesChanged( renderObject ) ) this.syncGeometryAttributes( renderObject );
7152
+ +
6003
7153
  + // A settled static object has no attribute that could have changed since the last refresh,
6004
7154
  + // unless a writer bumped one. An InstancedMesh's instance buffer is a vertex attribute of
6005
7155
  + // this draw, and a BufferGeometry carries no version of its own to announce the write, so
@@ -6008,7 +7158,7 @@ index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aaf
6008
7158
  + const monitor = renderObject.getMonitor();
6009
7159
  +
6010
7160
  + if ( monitor !== undefined && monitor.isSettled( renderObject ) === true && this.attributesChanged( renderObject ) === false ) return;
6011
- +
7161
+
6012
7162
  this.updateAttributes( renderObject );
6013
7163
 
6014
7164
  }
@@ -6026,13 +7176,18 @@ index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aaf
6026
7176
  + const index = this.getIndex( renderObject );
6027
7177
  + const settled = this._settledAttributes.get( renderObject );
6028
7178
  +
6029
- + if ( settled !== undefined && settled.size === attributes.length + ( index === null ? 0 : 1 ) ) {
7179
+ + if ( settled !== undefined && settled.attributes.length === attributes.length && settled.index === index ) {
6030
7180
  +
6031
7181
  + let changed = false;
6032
7182
  +
6033
- + for ( const attribute of attributes ) {
7183
+ + for ( let i = 0; i < attributes.length; i ++ ) {
7184
+ +
7185
+ + const attribute = attributes[ i ];
7186
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
7187
+ + const previous = settled.attributes[ i ];
6034
7188
  +
6035
- + if ( settled.get( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) !== attribute.version ) {
7189
+ + // an interleaved wrapper has no version of its own: its buffer's version is the write signal
7190
+ + if ( previous.attribute !== attribute || previous.data !== data || previous.version !== data.version ) {
6036
7191
  +
6037
7192
  + changed = true;
6038
7193
  + break;
@@ -6041,32 +7196,156 @@ index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aaf
6041
7196
  +
6042
7197
  + }
6043
7198
  +
6044
- + if ( changed === false && ( index === null || settled.get( index ) === index.version ) ) return false;
7199
+ + if ( changed === false && ( index === null || settled.indexVersion === index.version ) ) return false;
7200
+ +
7201
+ + }
7202
+ +
7203
+ + const versions = attributes.map( ( attribute ) => {
7204
+ +
7205
+ + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
7206
+ + return { attribute, data, version: data.version };
7207
+ +
7208
+ + } );
7209
+ +
7210
+ + this._settledAttributes.set( renderObject, { attributes: versions, index, indexVersion: index === null ? undefined : index.version } );
7211
+ +
7212
+ + return true;
7213
+ +
7214
+ + }
7215
+ +
7216
+ + /** Compare the published attribute identities without allocating on settled frames. */
7217
+ + geometryAttributesChanged( renderObject ) {
7218
+ +
7219
+ + const geometry = renderObject.geometry;
7220
+ + const owner = this._geometryAttributeOwners.get( geometry )?.get( renderObject );
7221
+ + if ( owner === undefined || owner.index !== geometry.index ) return true;
7222
+ +
7223
+ + const attributes = renderObject.getAttributes();
7224
+ + if ( owner.attributes.length !== attributes.length ) return true;
7225
+ + for ( let i = 0; i < attributes.length; i ++ ) {
7226
+ + const attribute = attributes[ i ];
7227
+ + if ( owner.attributes[ i ] !== ( attribute.isInterleavedBufferAttribute ? attribute.data : attribute ) ) return true;
7228
+ + }
7229
+ +
7230
+ + return false;
6045
7231
  +
7232
+ + }
7233
+ +
7234
+ + /** Add this render object's current geometry attributes to the renderer's shared-resource owners. */
7235
+ + syncGeometryAttributes( renderObject ) {
7236
+ +
7237
+ + const { geometry } = renderObject;
7238
+ + const previousGeometry = this._renderObjectAttributeGeometry.get( renderObject );
7239
+ + if ( previousGeometry !== undefined && previousGeometry !== geometry ) this.releaseRenderObject( renderObject );
7240
+ + this._renderObjectAttributeGeometry.set( renderObject, geometry );
7241
+ + let geometryOwners = this._geometryAttributeOwners.get( geometry );
7242
+ +
7243
+ + if ( geometryOwners === undefined ) {
7244
+ + geometryOwners = new Map();
7245
+ + this._geometryAttributeOwners.set( geometry, geometryOwners );
6046
7246
  + }
6047
7247
  +
6048
- + const versions = new Map();
7248
+ + const previous = geometryOwners.get( renderObject )?.keys ?? new Map();
7249
+ + const current = new Map();
7250
+ + const attributes = renderObject.getAttributes();
7251
+ + const attributeKeys = [];
6049
7252
  +
6050
7253
  + for ( const attribute of attributes ) {
7254
+ + const key = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
7255
+ + current.set( key, true );
7256
+ + attributeKeys.push( key );
7257
+ + }
7258
+ + const index = geometry.index;
7259
+ + if ( index !== null ) current.set( index, true );
7260
+ +
7261
+ + for ( const key of current.keys() ) {
7262
+ + let record = this._sharedAttributeOwners.get( key );
7263
+ + if ( record === undefined ) record = { owners: new Set() };
7264
+ + if ( previous.has( key ) === false ) record.owners.add( renderObject );
7265
+ + this._sharedAttributeOwners.set( key, record );
7266
+ + }
6051
7267
  +
6052
- + const data = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
7268
+ + for ( const key of previous.keys() ) {
7269
+ + if ( current.has( key ) === false ) this.releaseSharedAttribute( key, renderObject );
7270
+ + }
7271
+ +
7272
+ + geometryOwners.set( renderObject, { keys: current, attributes: attributeKeys, index } );
6053
7273
  +
6054
- + versions.set( data, data.version );
7274
+ + }
6055
7275
  +
7276
+ + /** Drop a render object from its geometry before its material-owned node attributes go stale. */
7277
+ + releaseRenderObject( renderObject ) {
7278
+ +
7279
+ + const geometry = this._renderObjectAttributeGeometry.get( renderObject );
7280
+ + if ( geometry === undefined ) return;
7281
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
7282
+ + const owned = geometryOwners?.get( renderObject )?.keys;
7283
+ + if ( owned !== undefined ) {
7284
+ + for ( const key of owned.keys() ) this.releaseSharedAttribute( key, renderObject );
7285
+ + geometryOwners.delete( renderObject );
7286
+ + if ( geometryOwners.size === 0 ) this._geometryAttributeOwners.delete( geometry );
6056
7287
  + }
7288
+ + this._renderObjectAttributeGeometry.delete( renderObject );
7289
+ +
7290
+ + }
6057
7291
  +
6058
- + if ( index !== null ) versions.set( index, index.version );
7292
+ + /** Release a shared GPU resource only after its last live geometry render object lets it go. */
7293
+ + releaseSharedAttribute( key, owner ) {
6059
7294
  +
6060
- + this._settledAttributes.set( renderObject, versions );
7295
+ + const record = this._sharedAttributeOwners.get( key );
7296
+ + if ( record === undefined ) return;
7297
+ + record.owners.delete( owner );
7298
+ + if ( record.owners.size !== 0 ) return;
6061
7299
  +
6062
- + return true;
7300
+ + this.attributes.delete( key );
7301
+ + this._sharedAttributeOwners.delete( key );
7302
+ +
7303
+ + }
7304
+ +
7305
+ + /** Release the recorded sets, not a potentially replaced render object's current attributes. */
7306
+ + releaseGeometryAttributes( geometry ) {
7307
+ +
7308
+ + const geometryOwners = this._geometryAttributeOwners.get( geometry );
7309
+ + if ( geometryOwners === undefined ) return;
7310
+ + for ( const [ owner, attributes ] of geometryOwners ) {
7311
+ + for ( const key of attributes.keys.keys() ) this.releaseSharedAttribute( key, owner );
7312
+ + this._renderObjectAttributeGeometry.delete( owner );
7313
+ + }
7314
+ + this._geometryAttributeOwners.delete( geometry );
6063
7315
  +
6064
7316
  + }
6065
7317
  +
6066
7318
  /**
6067
7319
  * Initializes the given geometry.
6068
7320
  *
6069
- @@ -314,8 +381,10 @@ class Geometries extends DataMap {
7321
+ @@ -207,23 +380,10 @@ class Geometries extends DataMap {
7322
+
7323
+ this.info.memory.geometries --;
7324
+
7325
+ - // index
7326
+ -
7327
+ - const index = geometry.index;
7328
+ -
7329
+ - if ( index !== null ) {
7330
+ -
7331
+ - this.attributes.delete( index );
7332
+ -
7333
+ - }
7334
+ + // index and geometry attributes: release this geometry's owners, so a buffer another
7335
+ + // geometry still draws stays alive until its last owner lets it go
7336
+
7337
+ - // geometry attributes
7338
+ -
7339
+ - for ( const attribute of Object.values( geometry.attributes ) ) {
7340
+ -
7341
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
7342
+ -
7343
+ - }
7344
+ + this.releaseGeometryAttributes( geometry );
7345
+
7346
+ // wireframe attributes
7347
+
7348
+ @@ -314,8 +474,10 @@ class Geometries extends DataMap {
6070
7349
  const callId = this.info.render.calls;
6071
7350
 
6072
7351
  const bufferAttribute = this.backend.getBufferAttribute( attribute );
@@ -6078,6 +7357,26 @@ index 086ab906cd5b6a91552d2afbecceb006332815e9..0dbd75a8f0a5cbd9b0ef00d91b426aaf
6078
7357
 
6079
7358
  this.attributes.update( bufferAttribute, type );
6080
7359
 
7360
+ @@ -399,17 +561,9 @@ class Geometries extends DataMap {
7361
+ */
7362
+ deleteNodeAttributes( renderObject ) {
7363
+
7364
+ - const currentAttributes = new Set( Object.values( renderObject.geometry.attributes ) );
7365
+ -
7366
+ - for ( const attribute of renderObject.getAttributes() ) {
7367
+ + // node attributes can be shared with other render objects: release this object's owners
7368
+
7369
+ - if ( currentAttributes.has( attribute ) === false ) {
7370
+ -
7371
+ - this.attributes.delete( this.backend.getBufferAttribute( attribute ) );
7372
+ -
7373
+ - }
7374
+ -
7375
+ - }
7376
+ + this.releaseRenderObject( renderObject );
7377
+
7378
+ }
7379
+
6081
7380
  diff --git a/src/renderers/common/RenderContexts.js b/src/renderers/common/RenderContexts.js
6082
7381
  index 63cde4c5c1cb0eed01313ddd5a08e0bf6e803441..2bcdeba31fbab75bf5cf37875ca410c8253ad953 100644
6083
7382
  --- a/src/renderers/common/RenderContexts.js
@@ -6150,6 +7449,18 @@ index 8dd6bfdeee6d2601a87c97c1f8ad66a716386d00..44549f85b88dab756632b9c845cc7588
6150
7449
  return hashArray( _cacheKeyValues );
6151
7450
 
6152
7451
  }
7452
+ diff --git a/src/renderers/common/RenderObjects.js b/src/renderers/common/RenderObjects.js
7453
+ index 882a39dcc5ab9e62236c2e02e20aa282b90ee421..99d89385ccc4eef01c8072f809f976db455a66a0 100644
7454
+ --- a/src/renderers/common/RenderObjects.js
7455
+ +++ b/src/renderers/common/RenderObjects.js
7456
+ @@ -244,6 +244,7 @@ class RenderObjects {
7457
+ this.pipelines.delete( renderObject );
7458
+ this.bindings.deleteForRender( renderObject );
7459
+ this.nodes.delete( renderObject );
7460
+ + this.geometries.releaseRenderObject( renderObject );
7461
+
7462
+ chainMap.delete( renderObject.getChainArray() );
7463
+
6153
7464
  diff --git a/src/renderers/common/Renderer.js b/src/renderers/common/Renderer.js
6154
7465
  index fb1255af55606f4ab915e2798a9174e9e00ee209..7e6cae39fc140fb39868c6c77f1a6b1d358b0866 100644
6155
7466
  --- a/src/renderers/common/Renderer.js
@@ -6324,7 +7635,7 @@ index fb1255af55606f4ab915e2798a9174e9e00ee209..7e6cae39fc140fb39868c6c77f1a6b1d
6324
7635
  } else if ( this._currentRenderBundle !== null ) {
6325
7636
 
6326
7637
  diff --git a/src/renderers/common/Textures.js b/src/renderers/common/Textures.js
6327
- index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe26926e03edc8 100644
7638
+ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..ceea39f57fbe0a885e0dc75781e53d2e8a28104b 100644
6328
7639
  --- a/src/renderers/common/Textures.js
6329
7640
  +++ b/src/renderers/common/Textures.js
6330
7641
  @@ -68,6 +68,10 @@ class Textures extends DataMap {
@@ -6377,7 +7688,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6377
7688
  const isRenderTarget = texture.isRenderTargetTexture || texture.isDepthTexture || texture.isFramebufferTexture;
6378
7689
  const backend = this.backend;
6379
7690
 
6380
- @@ -296,6 +317,21 @@ class Textures extends DataMap {
7691
+ @@ -296,6 +317,22 @@ class Textures extends DataMap {
6381
7692
 
6382
7693
  backend.destroyTexture( texture );
6383
7694
 
@@ -6391,6 +7702,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6391
7702
  +
6392
7703
  + bindingsData.groups = undefined;
6393
7704
  + bindingsData.versions = undefined;
7705
+ + bindingsData.forceUpdate = true;
6394
7706
  +
6395
7707
  + }
6396
7708
  +
@@ -6399,7 +7711,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6399
7711
  }
6400
7712
 
6401
7713
  //
6402
- @@ -435,9 +471,18 @@ class Textures extends DataMap {
7714
+ @@ -435,9 +472,18 @@ class Textures extends DataMap {
6403
7715
 
6404
7716
  if ( texture.source.dataReady === true ) {
6405
7717
 
@@ -6420,7 +7732,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6420
7732
 
6421
7733
  }
6422
7734
 
6423
- @@ -447,7 +492,7 @@ class Textures extends DataMap {
7735
+ @@ -447,7 +493,7 @@ class Textures extends DataMap {
6424
7736
 
6425
7737
  }
6426
7738
 
@@ -6429,7 +7741,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6429
7741
 
6430
7742
  }
6431
7743
 
6432
- @@ -464,6 +509,20 @@ class Textures extends DataMap {
7744
+ @@ -464,6 +510,20 @@ class Textures extends DataMap {
6433
7745
 
6434
7746
  }
6435
7747
 
@@ -6450,7 +7762,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6450
7762
  // dispose handler
6451
7763
 
6452
7764
  if ( textureData.initialized !== true ) {
6453
- @@ -506,11 +565,119 @@ class Textures extends DataMap {
7765
+ @@ -506,11 +566,119 @@ class Textures extends DataMap {
6454
7766
 
6455
7767
  }
6456
7768
 
@@ -6573,7 +7885,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6573
7885
 
6574
7886
  }
6575
7887
 
6576
- @@ -582,7 +749,11 @@ class Textures extends DataMap {
7888
+ @@ -582,7 +750,11 @@ class Textures extends DataMap {
6577
7889
 
6578
7890
  } else {
6579
7891
 
@@ -6586,7 +7898,7 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6586
7898
 
6587
7899
  }
6588
7900
 
6589
- @@ -695,6 +866,8 @@ class Textures extends DataMap {
7901
+ @@ -695,6 +867,8 @@ class Textures extends DataMap {
6590
7902
  */
6591
7903
  _destroyTexture( texture ) {
6592
7904
 
@@ -6595,8 +7907,16 @@ index 1084b2f90288142f45e01ddc9dd44b32eaadce45..f8e762fcf1c7ca0a9192e38f2afe2692
6595
7907
  if ( this.has( texture ) === true ) {
6596
7908
 
6597
7909
  const textureData = this.get( texture );
7910
+ @@ -724,6 +898,7 @@ class Textures extends DataMap {
7911
+
7912
+ bindingsData.groups = undefined;
7913
+ bindingsData.versions = undefined;
7914
+ + bindingsData.forceUpdate = true;
7915
+
7916
+ // go through all bindings and if one points to the destroyed texture, trigger dispose as well
7917
+
6598
7918
  diff --git a/src/renderers/common/extras/PMREMGenerator.js b/src/renderers/common/extras/PMREMGenerator.js
6599
- index 44bc579ef34aca93ad7546bf625f3f7d1c507aaa..a46a6800f3fb18b654fb7757b3f87ed1092aac5a 100644
7919
+ index 44bc579ef34aca93ad7546bf625f3f7d1c507aaa..d0c54721bb76e8afc4007cd9ed5141b711f76a5a 100644
6600
7920
  --- a/src/renderers/common/extras/PMREMGenerator.js
6601
7921
  +++ b/src/renderers/common/extras/PMREMGenerator.js
6602
7922
  @@ -85,6 +85,24 @@ class PMREMGenerator {
@@ -7162,10 +8482,85 @@ index 719d67abe3986ca058794b63a441ce66bedde891..39001c639aafb8422852c8b75ce1ee35
7162
8482
  * Generates mipmaps for the given texture.
7163
8483
  *
7164
8484
  diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js
7165
- index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314a85a8bd5 100644
8485
+ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..7ca5b7e385ef028e52667b59f869cca7624bfcaa 100644
7166
8486
  --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js
7167
8487
  +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js
7168
- @@ -776,7 +776,7 @@ class WGSLNodeBuilder extends NodeBuilder {
8488
+ @@ -306,6 +306,13 @@ class WGSLNodeBuilder extends NodeBuilder {
8489
+
8490
+ super( object, renderer, new WGSLNodeParser() );
8491
+
8492
+ + /**
8493
+ + * Comparison samplers shared by identical keys, and the WGSL sampler name of each texture
8494
+ + * that reads through another texture's sampler.
8495
+ + */
8496
+ + this.sharedCompareSamplers = new Map();
8497
+ + this.samplerNames = new Map();
8498
+ +
8499
+ /**
8500
+ * A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
8501
+ * another dictionary which manages UBOs per group ('render','frame','object').
8502
+ @@ -382,21 +389,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8503
+
8504
+ if ( offsetSnippet ) {
8505
+
8506
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
8507
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
8508
+
8509
+ }
8510
+
8511
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
8512
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
8513
+
8514
+ } else {
8515
+
8516
+ if ( offsetSnippet ) {
8517
+
8518
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
8519
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
8520
+
8521
+ }
8522
+
8523
+ - return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
8524
+ + return `textureSample( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet } )`;
8525
+
8526
+ }
8527
+
8528
+ @@ -428,21 +435,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8529
+
8530
+ if ( offsetSnippet ) {
8531
+
8532
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8533
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8534
+
8535
+ }
8536
+
8537
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
8538
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
8539
+
8540
+ } else {
8541
+
8542
+ if ( offsetSnippet ) {
8543
+
8544
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8545
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8546
+
8547
+ }
8548
+
8549
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
8550
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
8551
+
8552
+ }
8553
+
8554
+ @@ -705,7 +712,7 @@ class WGSLNodeBuilder extends NodeBuilder {
8555
+ // Depth textures require integer level, regular textures use float
8556
+ const levelType = texture.isDepthTexture ? 'u32' : 'f32';
8557
+
8558
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
8559
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
8560
+
8561
+ }
8562
+
8563
+ @@ -776,7 +783,7 @@ class WGSLNodeBuilder extends NodeBuilder {
7169
8564
  * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
7170
8565
  * @return {string} The WGSL snippet.
7171
8566
  */
@@ -7174,7 +8569,7 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7174
8569
 
7175
8570
  if ( levelSnippet === null ) levelSnippet = '0u';
7176
8571
 
7177
- @@ -794,7 +794,14 @@ class WGSLNodeBuilder extends NodeBuilder {
8572
+ @@ -794,7 +801,14 @@ class WGSLNodeBuilder extends NodeBuilder {
7178
8573
 
7179
8574
  } else {
7180
8575
 
@@ -7190,16 +8585,214 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7190
8585
 
7191
8586
  if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
7192
8587
 
7193
- @@ -1422,7 +1429,7 @@ class WGSLNodeBuilder extends NodeBuilder {
8588
+ @@ -842,6 +856,18 @@ class WGSLNodeBuilder extends NodeBuilder {
8589
+ * @param {Texture} texture - The texture.
8590
+ * @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
8591
+ */
8592
+ + /**
8593
+ + * The WGSL sampler a texture reads through: its own, or a shared comparison sampler.
8594
+ + *
8595
+ + * @param {string} textureProperty - The texture's WGSL name.
8596
+ + * @return {string} The sampler's WGSL name.
8597
+ + */
8598
+ + getSamplerName( textureProperty ) {
8599
+ +
8600
+ + return this.samplerNames.get( textureProperty ) ?? `${ textureProperty }_sampler`;
8601
+ +
8602
+ + }
8603
+ +
8604
+ isSampleCompare( texture ) {
8605
+
8606
+ return texture.isDepthTexture === true && texture.compareFunction !== null && this.renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
8607
+ @@ -918,21 +944,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8608
+
8609
+ if ( offsetSnippet ) {
8610
+
8611
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
8612
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
8613
+
8614
+ }
8615
+
8616
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
8617
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
8618
+
8619
+ } else {
8620
+
8621
+ if ( offsetSnippet ) {
8622
+
8623
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
8624
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
8625
+
8626
+ }
8627
+
8628
+ - return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
8629
+ + return `textureSampleGrad( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
8630
+
8631
+ }
8632
+
8633
+ @@ -965,21 +991,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8634
+
8635
+ if ( offsetSnippet ) {
8636
+
8637
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8638
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8639
+
8640
+ }
8641
+
8642
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
8643
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
8644
+
8645
+ }
8646
+
8647
+ if ( offsetSnippet ) {
8648
+
8649
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8650
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8651
+
8652
+ }
8653
+
8654
+ - return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
8655
+ + return `textureSampleCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet } )`;
8656
+
8657
+ } else {
8658
+
8659
+ @@ -1044,21 +1070,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8660
+
8661
+ if ( offsetSnippet ) {
8662
+
8663
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
8664
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
8665
+
8666
+ }
8667
+
8668
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
8669
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet } )`;
8670
+
8671
+ }
8672
+
8673
+ if ( offsetSnippet ) {
8674
+
8675
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
8676
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ offsetSnippet } )`;
8677
+
8678
+ }
8679
+
8680
+ - return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet })`;
8681
+ + return `textureGather( ${componentSnippet}${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet })`;
8682
+
8683
+ }
8684
+
8685
+ @@ -1079,21 +1105,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8686
+
8687
+ if ( offsetSnippet ) {
8688
+
8689
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8690
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8691
+
8692
+ }
8693
+
8694
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
8695
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
8696
+
8697
+ }
8698
+
8699
+ if ( offsetSnippet ) {
8700
+
8701
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8702
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
8703
+
8704
+ }
8705
+
8706
+ - return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet })`;
8707
+ + return `textureGatherCompare( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ compareSnippet })`;
8708
+
8709
+ }
8710
+
8711
+ @@ -1116,21 +1142,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8712
+
8713
+ if ( offsetSnippet ) {
8714
+
8715
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8716
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8717
+
8718
+ }
8719
+
8720
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
8721
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
8722
+
8723
+ } else {
8724
+
8725
+ if ( offsetSnippet ) {
8726
+
8727
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8728
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
8729
+
8730
+ }
8731
+
8732
+ - return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
8733
+ + return `textureSampleLevel( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ levelSnippet } )`;
8734
+
8735
+ }
8736
+
8737
+ @@ -1166,21 +1192,21 @@ class WGSLNodeBuilder extends NodeBuilder {
8738
+
8739
+ if ( offsetSnippet ) {
8740
+
8741
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
8742
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
8743
+
8744
+ }
8745
+
8746
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
8747
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
8748
+
8749
+ } else {
8750
+
8751
+ if ( offsetSnippet ) {
8752
+
8753
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
8754
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
8755
+
8756
+ }
8757
+
8758
+ - return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
8759
+ + return `textureSampleBias( ${ textureProperty }, ${ this.getSamplerName( textureProperty ) }, ${ uvSnippet }, ${ biasSnippet } )`;
8760
+
8761
+ }
8762
+
8763
+ @@ -1422,13 +1448,29 @@ class WGSLNodeBuilder extends NodeBuilder {
7194
8764
 
7195
8765
  // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
7196
8766
  // Also textureGather always need sampler.
7197
8767
  - const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
7198
8768
  + const needsSampler = node.isRawTextureNode !== true && ( node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null );
8769
+ +
8770
+ + // Identical comparison samplers share one binding. Every shadow map of a clipmap compares the
8771
+ + // same way, and a sampler per map exhausts maxSamplersPerShaderStage (16 on most adapters).
8772
+ + const sharedKey = needsSampler && this.isSampleCompare( node.value ) && node.isSampleCompare() ? `${ groupName }:${ shaderStage }:${ node.value.compareFunction }:${ node.value.wrapS }:${ node.value.wrapT }:${ node.value.wrapR }:${ node.value.minFilter }:${ node.value.magFilter }` : null;
8773
+ + const sharedSampler = sharedKey === null ? undefined : this.sharedCompareSamplers.get( sharedKey );
7199
8774
 
7200
- if ( needsSampler ) {
8775
+ - if ( needsSampler ) {
8776
+ + if ( sharedSampler !== undefined ) {
8777
+ +
8778
+ + this.samplerNames.set( uniformNode.name, sharedSampler.name );
8779
+ + nodeData.sharedSampler = true;
8780
+ +
8781
+ + bindings.push( texture );
8782
+ +
8783
+ + uniformGPU = [ sharedSampler, texture ];
8784
+ +
8785
+ + } else if ( needsSampler ) {
7201
8786
 
7202
- @@ -1835,7 +1842,10 @@ ${ flowData.code }
8787
+ const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
8788
+ sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
8789
+
8790
+ + if ( sharedKey !== null ) this.sharedCompareSamplers.set( sharedKey, sampler );
8791
+ +
8792
+ bindings.push( sampler, texture );
8793
+
8794
+ uniformGPU = [ sampler, texture ];
8795
+ @@ -1835,7 +1877,10 @@ ${ flowData.code }
7203
8796
 
7204
8797
  for ( const { name, property, type } of builtins.values() ) {
7205
8798
 
@@ -7211,7 +8804,7 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7211
8804
 
7212
8805
  snippets.push( `${ invariant }@builtin( ${name} ) ${property} : ${type}` );
7213
8806
 
7214
- @@ -2139,6 +2149,8 @@ ${ flowData.code }
8807
+ @@ -2139,6 +2184,8 @@ ${ flowData.code }
7215
8808
  getVaryings( shaderStage ) {
7216
8809
 
7217
8810
  const snippets = [];
@@ -7220,7 +8813,7 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7220
8813
 
7221
8814
  if ( shaderStage === 'vertex' ) {
7222
8815
 
7223
- @@ -2161,7 +2173,12 @@ ${ flowData.code }
8816
+ @@ -2161,7 +2208,12 @@ ${ flowData.code }
7224
8817
 
7225
8818
  let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
7226
8819
 
@@ -7234,7 +8827,7 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7234
8827
 
7235
8828
  const samplingSnippet = varying.interpolationSampling !== null ? `, ${ varying.interpolationSampling } )` : ' )';
7236
8829
 
7237
- @@ -2223,9 +2240,12 @@ ${ flowData.code }
8830
+ @@ -2223,11 +2275,15 @@ ${ flowData.code }
7238
8831
  const textureNode = uniform.node;
7239
8832
  const texture = textureNode.value;
7240
8833
 
@@ -7248,9 +8841,13 @@ index 0d56c7a118e49e9f036dc13ad691b5b5b9c7fac6..c662dfaa40d14a04d38e886a0730c314
7248
8841
  + const uniformGPU = nodeData.uniformGPU;
7249
8842
  + const needsSampler = Array.isArray( uniformGPU ) && uniformGPU[ 0 ].isSampler === true && uniformGPU[ 0 ].isSampledTexture !== true;
7250
8843
 
7251
- if ( needsSampler ) {
8844
+ - if ( needsSampler ) {
8845
+ + // A shared comparison sampler is declared once, by the texture that created it.
8846
+ + if ( needsSampler && nodeData.sharedSampler !== true ) {
8847
+
8848
+ if ( this.isSampleCompare( texture ) && textureNode.isSampleCompare() ) {
7252
8849
 
7253
- @@ -2247,7 +2267,7 @@ ${ flowData.code }
8850
+ @@ -2247,7 +2303,7 @@ ${ flowData.code }
7254
8851
 
7255
8852
  const { primarySamples } = backend.utils.getTextureSampleData( texture );
7256
8853