rayzee 7.4.0 → 7.4.1
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.
- package/README.md +1 -1
- package/dist/rayzee.es.js +605 -556
- package/dist/rayzee.es.js.map +1 -1
- package/dist/rayzee.umd.js +20 -20
- package/dist/rayzee.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/Passes/OIDNDenoiser.js +27 -3
- package/src/Processor/PackedRayBuffer.js +9 -29
- package/src/Processor/StorageTexturePool.js +11 -3
- package/src/Processor/VRAMTracker.js +50 -8
- package/src/Stages/ASVGF.js +27 -0
- package/src/Stages/BilateralFilter.js +12 -0
- package/src/Stages/EdgeFilter.js +12 -0
- package/src/Stages/MotionVector.js +10 -0
- package/src/Stages/NormalDepth.js +10 -0
- package/src/Stages/PathTracer.js +4 -2
- package/src/Stages/SSRC.js +16 -0
- package/src/Stages/Variance.js +13 -0
- package/src/TSL/GenerateKernel.js +1 -3
- package/src/TSL/ShadeKernel.js +2 -9
- package/src/managers/DenoisingManager.js +10 -0
package/package.json
CHANGED
|
@@ -137,6 +137,8 @@ export class OIDNDenoiser extends EventDispatcher {
|
|
|
137
137
|
|
|
138
138
|
// Track in-flight tile staging buffers so they can be destroyed on abort
|
|
139
139
|
this._pendingStagingBuffers = new Set();
|
|
140
|
+
// Per-run tile-blit promises; done() awaits these so capture waits for every tile to paint.
|
|
141
|
+
this._pendingTileBlits = [];
|
|
140
142
|
|
|
141
143
|
this.currentTZAUrl = null;
|
|
142
144
|
this.unet = null;
|
|
@@ -629,6 +631,9 @@ export class OIDNDenoiser extends EventDispatcher {
|
|
|
629
631
|
|
|
630
632
|
let abortDenoise = null;
|
|
631
633
|
|
|
634
|
+
// Fresh per-run list of tile-blit promises (the progress callback appends to it).
|
|
635
|
+
this._pendingTileBlits = [];
|
|
636
|
+
|
|
632
637
|
const abortHandler = () => {
|
|
633
638
|
|
|
634
639
|
if ( abortDenoise ) {
|
|
@@ -653,7 +658,23 @@ export class OIDNDenoiser extends EventDispatcher {
|
|
|
653
658
|
|
|
654
659
|
try {
|
|
655
660
|
|
|
656
|
-
|
|
661
|
+
if ( this._pendingTileBlits.length > 0 ) {
|
|
662
|
+
|
|
663
|
+
// Normal path: the progress callback already painted every tile progressively, with
|
|
664
|
+
// the same exposure/saturation/tonemap/sRGB math the full-frame readback uses (verified:
|
|
665
|
+
// tiles tile the image exactly, no overlap). Just wait for those blits — no redundant
|
|
666
|
+
// full-frame re-read + re-tonemap.
|
|
667
|
+
await Promise.allSettled( this._pendingTileBlits );
|
|
668
|
+
|
|
669
|
+
} else {
|
|
670
|
+
|
|
671
|
+
// Degenerate fallback (no per-tile progress was emitted): one authoritative full paint.
|
|
672
|
+
await this._displayGPUOutput( output );
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// DENOISING_END (which gates screenshot/video capture) fires only after this resolves,
|
|
677
|
+
// so the captured canvas is always complete.
|
|
657
678
|
resolve();
|
|
658
679
|
|
|
659
680
|
} catch ( err ) {
|
|
@@ -703,8 +724,9 @@ export class OIDNDenoiser extends EventDispatcher {
|
|
|
703
724
|
|
|
704
725
|
device.queue.submit( [ enc.finish() ] );
|
|
705
726
|
|
|
706
|
-
// Map and blit asynchronously — GPU copy is already queued
|
|
707
|
-
|
|
727
|
+
// Map and blit asynchronously — GPU copy is already queued. Track the whole chain so
|
|
728
|
+
// done() can await every tile paint before resolving (replaces the full-frame readback).
|
|
729
|
+
const tileBlit = staging.mapAsync( GPUMapMode.READ ).then( () => {
|
|
708
730
|
|
|
709
731
|
const f32 = new Float32Array( staging.getMappedRange() );
|
|
710
732
|
const tileImageData = new ImageData( clampedW, clampedH );
|
|
@@ -766,6 +788,8 @@ export class OIDNDenoiser extends EventDispatcher {
|
|
|
766
788
|
|
|
767
789
|
} );
|
|
768
790
|
|
|
791
|
+
this._pendingTileBlits.push( tileBlit );
|
|
792
|
+
|
|
769
793
|
}
|
|
770
794
|
} );
|
|
771
795
|
|
|
@@ -11,13 +11,12 @@ import { StorageInstancedBufferAttribute } from 'three/webgpu';
|
|
|
11
11
|
|
|
12
12
|
export const RAY_STRIDE = 7;
|
|
13
13
|
export const HIT_STRIDE = 2;
|
|
14
|
-
// Per-pixel G-buffer (first-hit MRT staging):
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// lane 1 — primary-hit surface ID for A-SVGF correlated-gradient re-projection (Tier 1); written at the
|
|
18
|
-
// bounce-0 hit, valid=0 on miss (Generate inits): .x=triIndex .y=meshIndex .z=packUnorm2x16(bary.u,bary.v) .w=valid
|
|
14
|
+
// Per-pixel G-buffer (first-hit MRT staging): 1 uvec4/pixel — half-packed normal/depth/albedo
|
|
15
|
+
// (pack2x16, no f32 bitcast); read by FinalWrite:
|
|
16
|
+
// .x=packSnorm2x16(normal.xy) .y=packSnorm2x16(normal.z, depth) .z=packUnorm2x16(albedo.rg) .w=packUnorm2x16(albedo.b, 0)
|
|
19
17
|
// Separate buffer from RAY (per-pixel, not per-ray×S) — written by Generate/Shade bounce-0.
|
|
20
|
-
|
|
18
|
+
// (A second lane reserved for an A-SVGF Tier-1 surface ID was removed — write-only, never read.)
|
|
19
|
+
export const GBUFFER_STRIDE = 1;
|
|
21
20
|
|
|
22
21
|
export const RAY = {
|
|
23
22
|
ORIGIN_META: 0, // vec4(origin.xyz, uintBitsToFloat(perRayBounces | sssSteps<<8)); pixelIndex == rayID
|
|
@@ -152,36 +151,17 @@ export const readRayRadiance = ( buf, id ) =>
|
|
|
152
151
|
// ── Per-pixel G-buffer (first-hit MRT). 2 uvec4/pixel (AoS), pack2x16 lanes. ──
|
|
153
152
|
// normal: raw unit vec3; depth: linear [0,1]; albedo: vec3 [0,1]. Packed values live in u32 lanes
|
|
154
153
|
// verbatim (no f32 bitcast) so NaN-range bit patterns (snorm ±1 → 0x7FFF) survive store/load intact.
|
|
155
|
-
//
|
|
156
|
-
const gbLane = ( pixelIndex
|
|
157
|
-
|
|
158
|
-
const base = uint( pixelIndex ).mul( GBUFFER_STRIDE );
|
|
159
|
-
return lane === 0 ? base : base.add( lane );
|
|
160
|
-
|
|
161
|
-
};
|
|
154
|
+
// One uvec4 per pixel (stride 1); AoS base = pixelIndex * GBUFFER_STRIDE.
|
|
155
|
+
const gbLane = ( pixelIndex ) => uint( pixelIndex ).mul( GBUFFER_STRIDE );
|
|
162
156
|
|
|
163
157
|
export const writeGBuffer = ( buf, pixelIndex, normal, depth, albedo ) =>
|
|
164
|
-
buf.element( gbLane( pixelIndex
|
|
158
|
+
buf.element( gbLane( pixelIndex ) ).assign( uvec4(
|
|
165
159
|
packSnorm2x16( vec2( normal.x, normal.y ) ),
|
|
166
160
|
packSnorm2x16( vec2( normal.z, depth ) ),
|
|
167
161
|
packUnorm2x16( vec2( albedo.x, albedo.y ) ),
|
|
168
162
|
packUnorm2x16( vec2( albedo.z, 0.0 ) ),
|
|
169
163
|
) );
|
|
170
|
-
export const readGBuffer = ( buf, pixelIndex ) => buf.element( gbLane( pixelIndex
|
|
171
|
-
|
|
172
|
-
// Lane 1 — primary-hit surface ID for A-SVGF correlated gradient re-projection (Tier 1).
|
|
173
|
-
// valid=0 marks a miss (no primary surface); bary packed unorm (both in [0,1]).
|
|
174
|
-
export const writeGBufferSurfaceID = ( buf, pixelIndex, triIndex, meshIndex, baryU, baryV, valid ) =>
|
|
175
|
-
buf.element( gbLane( pixelIndex, 1 ) ).assign( uvec4(
|
|
176
|
-
uint( triIndex ), uint( meshIndex ), packUnorm2x16( vec2( baryU, baryV ) ), uint( valid ),
|
|
177
|
-
) );
|
|
178
|
-
export const readGBufferSurfaceID = ( buf, pixelIndex ) => {
|
|
179
|
-
|
|
180
|
-
const p = buf.element( gbLane( pixelIndex, 1 ) );
|
|
181
|
-
const bary = unpackUnorm2x16( p.z );
|
|
182
|
-
return { triIndex: p.x, meshIndex: p.y, baryU: bary.x, baryV: bary.y, valid: p.w };
|
|
183
|
-
|
|
184
|
-
};
|
|
164
|
+
export const readGBuffer = ( buf, pixelIndex ) => buf.element( gbLane( pixelIndex ) );
|
|
185
165
|
|
|
186
166
|
// Decode for FinalWrite. normalDepth.xyz matches the prior path (normal*0.5+0.5), .w = raw depth.
|
|
187
167
|
export const gbDecodeNormalDepth = ( packed ) => {
|
|
@@ -141,16 +141,24 @@ export class StorageTexturePool {
|
|
|
141
141
|
* Copy StorageTextures → RenderTarget textures via GPU copy.
|
|
142
142
|
* Must be called after each compute dispatch.
|
|
143
143
|
* @param {WebGPURenderer} renderer
|
|
144
|
+
* @param {boolean} [includeAux=true] Copy the normalDepth + albedo attachments too. When no
|
|
145
|
+
* denoiser/OIDN consumes the aux MRT (default interactive), the wavefront doesn't write those
|
|
146
|
+
* StorageTextures, so skipping their copies saves two full-res GPU copies/frame. Color is always copied.
|
|
144
147
|
*/
|
|
145
|
-
copyToReadTargets( renderer ) {
|
|
148
|
+
copyToReadTargets( renderer, includeAux = true ) {
|
|
146
149
|
|
|
147
150
|
// Source write StorageTextures are over-allocated at the max size; the Box2 region
|
|
148
151
|
// restricts the copy to the active render size so source and destination extents match.
|
|
149
152
|
this._srcRegion.max.set( this.renderWidth, this.renderHeight );
|
|
150
153
|
|
|
151
154
|
renderer.copyTextureToTexture( this.writeColor, this.readTarget.textures[ 0 ], this._srcRegion );
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
|
|
156
|
+
if ( includeAux ) {
|
|
157
|
+
|
|
158
|
+
renderer.copyTextureToTexture( this.writeNormalDepth, this.readTarget.textures[ 1 ], this._srcRegion );
|
|
159
|
+
renderer.copyTextureToTexture( this.writeAlbedo, this.readTarget.textures[ 2 ], this._srcRegion );
|
|
160
|
+
|
|
161
|
+
}
|
|
154
162
|
|
|
155
163
|
}
|
|
156
164
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* VRAMTracker.js — current/peak GPU memory accounting.
|
|
3
3
|
*
|
|
4
|
-
* Measures
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Measures live GPU bytes: buffer attributes by backing-array byteLength, textures by
|
|
5
|
+
* dims × format/type — but ONLY when the backend actually holds a GPUTexture. three.js
|
|
6
|
+
* allocates a texture's GPUTexture lazily on first use, so a constructed-but-never-dispatched
|
|
7
|
+
* StorageTexture (e.g. a disabled stage's render targets) costs 0 here even though its JS
|
|
8
|
+
* `image` dimensions are set. Residency probing needs a renderer (constructor arg or
|
|
9
|
+
* setRenderer); without one it falls back to counting by dimensions (legacy behavior).
|
|
10
|
+
* Providers are thunks that read current state, so they survive reallocation (resize,
|
|
11
|
+
* scene/material/env reload). A per-pass WeakSet dedupes by resource identity, so
|
|
12
|
+
* overlapping registrations never double-count.
|
|
9
13
|
*/
|
|
10
14
|
|
|
11
15
|
import {
|
|
@@ -60,15 +64,23 @@ export function textureBytes( tex ) {
|
|
|
60
64
|
|
|
61
65
|
export class VRAMTracker {
|
|
62
66
|
|
|
63
|
-
constructor() {
|
|
67
|
+
constructor( renderer = null ) {
|
|
64
68
|
|
|
65
69
|
this._providers = [];
|
|
70
|
+
this._renderer = renderer;
|
|
66
71
|
this.current = 0;
|
|
67
72
|
this.peak = 0;
|
|
68
73
|
this.byCategory = {};
|
|
69
74
|
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
/** Late-bind the renderer so texture accounting can probe actual GPU residency. */
|
|
78
|
+
setRenderer( renderer ) {
|
|
79
|
+
|
|
80
|
+
this._renderer = renderer;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
/**
|
|
73
85
|
* @param {string} category - grouping label in the report
|
|
74
86
|
* @param {Function} fn - returns a resource or array of resources: buffer
|
|
@@ -138,12 +150,12 @@ export class VRAMTracker {
|
|
|
138
150
|
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
// texture / render target — dedupe by object identity
|
|
153
|
+
// texture / render target — dedupe by object identity; count only GPU-resident bytes
|
|
142
154
|
if ( r.isRenderTarget || r.isTexture ) {
|
|
143
155
|
|
|
144
156
|
if ( seen.has( r ) ) return 0;
|
|
145
157
|
seen.add( r );
|
|
146
|
-
return
|
|
158
|
+
return this._residentTextureBytes( r );
|
|
147
159
|
|
|
148
160
|
}
|
|
149
161
|
|
|
@@ -151,6 +163,36 @@ export class VRAMTracker {
|
|
|
151
163
|
|
|
152
164
|
}
|
|
153
165
|
|
|
166
|
+
// three.js allocates a texture's GPUTexture lazily on first dispatch; a never-used StorageTexture
|
|
167
|
+
// (disabled stage) has none. Count only when the backend holds a real GPUTexture so the report is
|
|
168
|
+
// resident VRAM, not JS-declared dimensions. No renderer bound → assume resident (legacy behavior).
|
|
169
|
+
_isResident( tex ) {
|
|
170
|
+
|
|
171
|
+
const backend = this._renderer?.backend;
|
|
172
|
+
if ( ! backend || typeof backend.get !== 'function' ) return true;
|
|
173
|
+
if ( typeof backend.has === 'function' && ! backend.has( tex ) ) return false;
|
|
174
|
+
const data = backend.get( tex );
|
|
175
|
+
return !! ( data && ( data.texture || data.gpuTexture ) );
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// RenderTarget bytes are attributed to its underlying texture(s); count each only if resident.
|
|
180
|
+
_residentTextureBytes( tex ) {
|
|
181
|
+
|
|
182
|
+
if ( tex.isRenderTarget ) {
|
|
183
|
+
|
|
184
|
+
const list = tex.textures?.length ? tex.textures : [ tex.texture ];
|
|
185
|
+
const w = tex.width || 0, h = tex.height || 0, d = tex.depth || 1;
|
|
186
|
+
let sum = 0;
|
|
187
|
+
for ( const t of list ) if ( t && this._isResident( t ) ) sum += w * h * d * texelBytes( t );
|
|
188
|
+
return sum;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return this._isResident( tex ) ? textureBytes( tex ) : 0;
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
154
196
|
/** Drop the high-water mark to the current value (call when a new render begins). */
|
|
155
197
|
resetPeak() {
|
|
156
198
|
|
package/src/Stages/ASVGF.js
CHANGED
|
@@ -832,6 +832,33 @@ export class ASVGF extends RenderStage {
|
|
|
832
832
|
|
|
833
833
|
}
|
|
834
834
|
|
|
835
|
+
// Free the over-allocated 2048² StorageTextures' GPU memory when the stage is disabled, so toggling
|
|
836
|
+
// the denoiser off reclaims VRAM. The JS texture objects + compiled compute nodes are kept; three.js
|
|
837
|
+
// lazily re-creates each GPUTexture on the next dispatch after re-enable. History re-anchors via the
|
|
838
|
+
// warm reset (the RTs are render-res, not 2048² — left alone).
|
|
839
|
+
releaseGPUMemory() {
|
|
840
|
+
|
|
841
|
+
this._temporalTexA?.dispose();
|
|
842
|
+
this._temporalTexB?.dispose();
|
|
843
|
+
this._outputModulatedTex?.dispose();
|
|
844
|
+
this._gradientStorageTex?.dispose();
|
|
845
|
+
this._heatmapStorageTex?.dispose();
|
|
846
|
+
// Render-res RT textures (sized to render resolution → meaningful VRAM at high res). Dispose the
|
|
847
|
+
// .texture, not the RenderTarget (RT.dispose() doesn't free the backing GPUTexture here); these RTs
|
|
848
|
+
// are copyTextureToTexture targets, so three.js reallocates on the next dispatch after re-enable.
|
|
849
|
+
// Drop the published context outputs first so the Compositor fallback (reads asvgf:output) can't
|
|
850
|
+
// sample a freed texture; render() re-publishes on re-enable.
|
|
851
|
+
this.context?.removeTexture( 'asvgf:demodulated' );
|
|
852
|
+
this.context?.removeTexture( 'asvgf:output' );
|
|
853
|
+
this.context?.removeTexture( 'asvgf:gradient' );
|
|
854
|
+
this._demodulatedRT?.texture?.dispose();
|
|
855
|
+
this._outputRT?.texture?.dispose();
|
|
856
|
+
this._gradientRT?.texture?.dispose();
|
|
857
|
+
this.heatmapTarget?.texture?.dispose();
|
|
858
|
+
this.resetTemporalData();
|
|
859
|
+
|
|
860
|
+
}
|
|
861
|
+
|
|
835
862
|
dispose() {
|
|
836
863
|
|
|
837
864
|
this._gradientNode?.dispose();
|
|
@@ -367,6 +367,18 @@ export class BilateralFilter extends RenderStage {
|
|
|
367
367
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
// Free the 2048² StorageTextures when disabled; three.js re-creates them on the next dispatch
|
|
371
|
+
// after re-enable (no temporal state to re-anchor). See ASVGF.releaseGPUMemory.
|
|
372
|
+
releaseGPUMemory() {
|
|
373
|
+
|
|
374
|
+
this._storageTexA?.dispose();
|
|
375
|
+
this._storageTexB?.dispose();
|
|
376
|
+
// Render-res RT texture (dispose .texture, not the RT — RT.dispose() doesn't free it here).
|
|
377
|
+
this.context?.removeTexture( 'bilateralFiltering:output' );
|
|
378
|
+
this._outputTarget?.texture?.dispose();
|
|
379
|
+
|
|
380
|
+
}
|
|
381
|
+
|
|
370
382
|
reset() {
|
|
371
383
|
|
|
372
384
|
// No temporal state to reset
|
package/src/Stages/EdgeFilter.js
CHANGED
|
@@ -267,6 +267,18 @@ export class EdgeFilter extends RenderStage {
|
|
|
267
267
|
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
// Free the 2048² StorageTexture when disabled; three.js re-creates it on the next dispatch
|
|
271
|
+
// after re-enable, and reset() clears the iteration history. See ASVGF.releaseGPUMemory.
|
|
272
|
+
releaseGPUMemory() {
|
|
273
|
+
|
|
274
|
+
this._outputStorageTex?.dispose();
|
|
275
|
+
// Render-res RT texture (dispose .texture, not the RT — RT.dispose() doesn't free it here).
|
|
276
|
+
this.context?.removeTexture( 'edgeFiltering:output' );
|
|
277
|
+
this.outputTarget?.texture?.dispose();
|
|
278
|
+
this.reset();
|
|
279
|
+
|
|
280
|
+
}
|
|
281
|
+
|
|
270
282
|
reset() {
|
|
271
283
|
|
|
272
284
|
this._iterations = 0;
|
|
@@ -495,6 +495,16 @@ export class MotionVector extends RenderStage {
|
|
|
495
495
|
* Reset — intentionally does NOT reset matricesInitialized.
|
|
496
496
|
* Motion vectors must track camera motion across pipeline resets.
|
|
497
497
|
*/
|
|
498
|
+
// Free the 2048² StorageTextures when disabled (no consumer); three.js re-creates them on the next
|
|
499
|
+
// dispatch after re-enable. _syncGBufferStages additionally reseeds camera history on re-enable.
|
|
500
|
+
releaseGPUMemory() {
|
|
501
|
+
|
|
502
|
+
this._screenSpaceStorageTex?.dispose();
|
|
503
|
+
this._worldSpaceStorageTex?.dispose();
|
|
504
|
+
this.reset();
|
|
505
|
+
|
|
506
|
+
}
|
|
507
|
+
|
|
498
508
|
reset() {
|
|
499
509
|
|
|
500
510
|
if ( ! this.matricesInitialized ) {
|
|
@@ -367,6 +367,16 @@ export class NormalDepth extends RenderStage {
|
|
|
367
367
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
// Free the 2048² StorageTextures when disabled (no consumer); three.js re-creates them on the next
|
|
371
|
+
// dispatch after re-enable, and reset() re-arms the dirty/history fast-path. See ASVGF.releaseGPUMemory.
|
|
372
|
+
releaseGPUMemory() {
|
|
373
|
+
|
|
374
|
+
this._outputStorageTex?.dispose();
|
|
375
|
+
this._shadingStorageTex?.dispose();
|
|
376
|
+
this.reset();
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
370
380
|
reset() {
|
|
371
381
|
|
|
372
382
|
this._dirty = true;
|
package/src/Stages/PathTracer.js
CHANGED
|
@@ -64,7 +64,7 @@ export class PathTracer extends PathTracerStage {
|
|
|
64
64
|
|
|
65
65
|
// VRAM accounting — providers are thunks reading CURRENT live resources,
|
|
66
66
|
// so they survive buffer/texture reallocation (resize, scene/material reload).
|
|
67
|
-
this.vramTracker = new VRAMTracker();
|
|
67
|
+
this.vramTracker = new VRAMTracker( this.renderer );
|
|
68
68
|
this._registerVRAMProviders();
|
|
69
69
|
|
|
70
70
|
console.log( 'PathTracer: initialized (wavefront)' );
|
|
@@ -322,7 +322,9 @@ export class PathTracer extends PathTracerStage {
|
|
|
322
322
|
|
|
323
323
|
this._maybeReadbackCounters();
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
// Skip the normalDepth/albedo copies when aux is off — the wavefront didn't write them and
|
|
326
|
+
// no stage reads them; saves two full-res GPU copies/frame in the default interactive path.
|
|
327
|
+
this.storageTextures.copyToReadTargets( this.renderer, this._auxGBufferEnabled );
|
|
326
328
|
|
|
327
329
|
const readTex = this.storageTextures.getReadTextures();
|
|
328
330
|
if ( context ) this._publishTexturesToContext( context, readTex );
|
package/src/Stages/SSRC.js
CHANGED
|
@@ -171,6 +171,22 @@ export class SSRC extends RenderStage {
|
|
|
171
171
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
// Free the 2048² StorageTextures when disabled; three.js re-creates them on the next dispatch
|
|
175
|
+
// after re-enable, and reset() clears the temporal cache. See ASVGF.releaseGPUMemory.
|
|
176
|
+
releaseGPUMemory() {
|
|
177
|
+
|
|
178
|
+
this._cacheTexA?.dispose();
|
|
179
|
+
this._cacheTexB?.dispose();
|
|
180
|
+
this._prevNDTexA?.dispose();
|
|
181
|
+
this._prevNDTexB?.dispose();
|
|
182
|
+
this._outputTex?.dispose();
|
|
183
|
+
// Render-res RT texture (dispose .texture, not the RT — RT.dispose() doesn't free it here).
|
|
184
|
+
this.context?.removeTexture( 'ssrc:output' );
|
|
185
|
+
this.outputTarget?.texture?.dispose();
|
|
186
|
+
this.reset();
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
174
190
|
reset() {
|
|
175
191
|
|
|
176
192
|
this._resetCache();
|
package/src/Stages/Variance.js
CHANGED
|
@@ -363,6 +363,19 @@ export class Variance extends RenderStage {
|
|
|
363
363
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
// Free the 2048² StorageTextures when disabled; three.js re-creates them on the next dispatch
|
|
367
|
+
// after re-enable, and reset() re-anchors the EMA. See ASVGF.releaseGPUMemory.
|
|
368
|
+
releaseGPUMemory() {
|
|
369
|
+
|
|
370
|
+
this._storageTexA?.dispose();
|
|
371
|
+
this._storageTexB?.dispose();
|
|
372
|
+
// Render-res RT texture (dispose .texture, not the RT — RT.dispose() doesn't free it here).
|
|
373
|
+
this.context?.removeTexture( 'variance:output' );
|
|
374
|
+
this._outputTarget?.texture?.dispose();
|
|
375
|
+
this.reset();
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
366
379
|
reset() {
|
|
367
380
|
|
|
368
381
|
this.currentMoments = 0;
|
|
@@ -19,7 +19,7 @@ import { Ray } from './Struct.js';
|
|
|
19
19
|
import { RAY_FLAG } from '../Processor/QueueManager.js';
|
|
20
20
|
import {
|
|
21
21
|
writeRayOriginMeta, writeRayDirFlags, writeRayThroughputPdf,
|
|
22
|
-
writeRayRadiance, writeGBuffer,
|
|
22
|
+
writeRayRadiance, writeGBuffer,
|
|
23
23
|
writeMediumStack,
|
|
24
24
|
} from '../Processor/PackedRayBuffer.js';
|
|
25
25
|
|
|
@@ -86,8 +86,6 @@ export function buildGenerateKernel( params ) {
|
|
|
86
86
|
|
|
87
87
|
// default: normal +Z, depth 1 (far), black albedo (background/miss)
|
|
88
88
|
writeGBuffer( gBufferRW, uint( pixelIndex ), vec3( 0.0, 0.0, 1.0 ), float( 1.0 ), vec3( 0.0 ) );
|
|
89
|
-
// surface-ID lane defaults to invalid (valid=0); Shade overwrites it at the bounce-0 hit.
|
|
90
|
-
writeGBufferSurfaceID( gBufferRW, uint( pixelIndex ), uint( 0 ), uint( 0 ), float( 0.0 ), float( 0.0 ), uint( 0 ) );
|
|
91
89
|
|
|
92
90
|
} );
|
|
93
91
|
|
package/src/TSL/ShadeKernel.js
CHANGED
|
@@ -51,9 +51,9 @@ import {
|
|
|
51
51
|
readMediumStack, writeMediumStack, readMediumSigmaA, writeMediumSigmaA,
|
|
52
52
|
readPathBounces, readSssSteps, readSSSMedium, writeSSSMedium,
|
|
53
53
|
readHitDistance, readHitBarycentrics, readHitNormal,
|
|
54
|
-
readHitMaterialIndex, readHitTriangleIndex,
|
|
54
|
+
readHitMaterialIndex, readHitTriangleIndex,
|
|
55
55
|
writeRayOriginMeta, writeRayDirFlags, writeRayThroughputPdf, writeRayRadiance,
|
|
56
|
-
writeGBuffer,
|
|
56
|
+
writeGBuffer, readGBuffer, gbDecodeNormalDepth,
|
|
57
57
|
readRayRadiance,
|
|
58
58
|
} from '../Processor/PackedRayBuffer.js';
|
|
59
59
|
|
|
@@ -64,9 +64,6 @@ const MISS_DIST = 1e19;
|
|
|
64
64
|
const CATCHER_T_MIN = 1e-4; // min ray-t for the analytic plane hit (skip behind/at the camera)
|
|
65
65
|
const CATCHER_LUMA_FLOOR = 1e-4; // denominator floor for the shadow ratio
|
|
66
66
|
const CATCHER_COVERAGE_MIN = 1e-3; // below this incident luma there is no shadow to catch
|
|
67
|
-
// Reserved G-buffer surface ID for catcher pixels (no real triangle); stable across frames so the
|
|
68
|
-
// denoiser treats the analytic plane as one coherent surface, not a background miss.
|
|
69
|
-
const CATCHER_SURFACE_ID = 0xFFFFFFFE;
|
|
70
67
|
|
|
71
68
|
export function buildShadeKernel( params ) {
|
|
72
69
|
|
|
@@ -297,7 +294,6 @@ export function buildShadeKernel( params ) {
|
|
|
297
294
|
|
|
298
295
|
const planeDepth = computeNDCDepth( { worldPos: planePoint, cameraProjectionMatrix, cameraViewMatrix } );
|
|
299
296
|
writeGBuffer( gBufferRW, pixelIndex, planeN, planeDepth, vec3( 1.0 ) );
|
|
300
|
-
writeGBufferSurfaceID( gBufferRW, pixelIndex, uint( CATCHER_SURFACE_ID ), uint( CATCHER_SURFACE_ID ), 0.5, 0.5, uint( 1 ) );
|
|
301
297
|
|
|
302
298
|
} );
|
|
303
299
|
|
|
@@ -587,9 +583,6 @@ export function buildShadeKernel( params ) {
|
|
|
587
583
|
// block before that capture, so a glass-then-escape pixel keeps this default aux — megakernel parity
|
|
588
584
|
// (objectNormal/objectColor stay at their init for transmissive-then-miss).
|
|
589
585
|
writeGBuffer( gBufferRW, pixelIndex, vec3( 0.0, 0.0, 1.0 ), linearDepth, vec3( 0.0 ) );
|
|
590
|
-
// Persist the primary-hit surface ID (Tier-1 A-SVGF correlated re-projection). Hit-only
|
|
591
|
-
// branch (misses Return above), so this marks the pixel valid; bary from the bounce-0 hit.
|
|
592
|
-
writeGBufferSurfaceID( gBufferRW, pixelIndex, hitTriIdx, readHitMeshIndex( hitBufferRO, rayID ), hitUV.x, hitUV.y, uint( 1 ) );
|
|
593
586
|
|
|
594
587
|
} );
|
|
595
588
|
|
|
@@ -370,6 +370,16 @@ export class DenoisingManager extends EventDispatcher {
|
|
|
370
370
|
// MRT read-targets directly). When none are active the wavefront skips those writes entirely.
|
|
371
371
|
s.pathTracer?.setAuxGBufferEnabled?.( normalNeeded || !! this.denoiser?.enabled );
|
|
372
372
|
|
|
373
|
+
// Reclaim VRAM: free the big 2048² StorageTextures of any denoiser/G-buffer stage that ended up
|
|
374
|
+
// disabled (lazily re-created on the next dispatch after re-enable). Every strategy/denoiser
|
|
375
|
+
// toggle funnels through here after the enabled flags above are settled, so this is the one
|
|
376
|
+
// choke point. dispose() is idempotent, so re-running it for an already-released stage is a no-op.
|
|
377
|
+
for ( const stage of [ s.asvgf, s.variance, s.bilateralFilter, s.ssrc, s.edgeFilter, nd, mv ] ) {
|
|
378
|
+
|
|
379
|
+
if ( stage && ! stage.enabled ) stage.releaseGPUMemory?.();
|
|
380
|
+
|
|
381
|
+
}
|
|
382
|
+
|
|
373
383
|
}
|
|
374
384
|
|
|
375
385
|
// ── Render Completion Chain ───────────────────────────────────
|