@@ -25,13 +25,58 @@ const _clearValue = { r: 0, g: 0, b: 0, a: 1 };
2525
2626const _submitArray = [ null ] ;
2727
28- const _copySrc = { texture : null , origin : [ 0 , 0 , 0 ] } ;
29- const _copyDst = { texture : null } ;
28+ /**
29+ * Reusable wrapper around `GPUTexelCopyTextureInfo`. Mutates in place to avoid
30+ * per-frame GC pressure while keeping call sites readable via chainable setters.
31+ */
32+ class TexelCopyTextureInfo {
33+
34+ constructor ( ) {
35+
36+ this . texture = null ;
37+ this . mipLevel = 0 ;
38+ this . origin = { x : 0 , y : 0 , z : 0 } ;
39+
40+ }
41+
42+ setTexture ( texture ) {
43+
44+ this . texture = texture ;
45+ return this ;
46+
47+ }
48+
49+ setMipLevel ( mipLevel ) {
50+
51+ this . mipLevel = mipLevel ;
52+ return this ;
53+
54+ }
55+
56+ setOrigin ( x , y , z ) {
57+
58+ this . origin . x = x ;
59+ this . origin . y = y ;
60+ this . origin . z = z ;
61+ return this ;
62+
63+ }
64+
65+ reset ( ) {
66+
67+ this . texture = null ;
68+
69+ }
70+
71+ }
72+
73+ const _copySrc = new TexelCopyTextureInfo ( ) ;
74+ const _copyDst = new TexelCopyTextureInfo ( ) ;
3075const _copySize = [ 0 , 0 ] ;
3176
3277const _texCopyEncoderOptions = { label : '' } ;
33- const _texCopySrc = { texture : null , mipLevel : 0 , origin : { x : 0 , y : 0 , z : 0 } } ;
34- const _texCopyDst = { texture : null , mipLevel : 0 , origin : { x : 0 , y : 0 , z : 0 } } ;
78+ const _texCopySrc = new TexelCopyTextureInfo ( ) ;
79+ const _texCopyDst = new TexelCopyTextureInfo ( ) ;
3580const _texCopySize = [ 0 , 0 , 0 ] ;
3681
3782const _clearEncoderOptions = { label : 'clear' } ;
@@ -57,16 +102,6 @@ function _resetCurrentSets( sets ) {
57102
58103}
59104
60- function _setTexelCopyInfo ( info , texture , mipLevel , x , y , z ) {
61-
62- info . texture = texture ;
63- info . mipLevel = mipLevel ;
64- info . origin . x = x ;
65- info . origin . y = y ;
66- info . origin . z = z ;
67-
68- }
69-
70105function _submit ( queue , commandBuffer ) {
71106
72107 _submitArray [ 0 ] = commandBuffer ;
@@ -2638,16 +2673,16 @@ class WebGPUBackend extends Backend {
26382673 const sourceGPU = this . get ( srcTexture ) . texture ;
26392674 const destinationGPU = this . get ( dstTexture ) . texture ;
26402675
2641- _setTexelCopyInfo ( _texCopySrc , sourceGPU , srcLevel , srcX , srcY , srcZ ) ;
2642- _setTexelCopyInfo ( _texCopyDst , destinationGPU , dstLevel , dstX , dstY , dstZ ) ;
2676+ _texCopySrc . setTexture ( sourceGPU ) . setMipLevel ( srcLevel ) . setOrigin ( srcX , srcY , srcZ ) ;
2677+ _texCopyDst . setTexture ( destinationGPU ) . setMipLevel ( dstLevel ) . setOrigin ( dstX , dstY , dstZ ) ;
26432678 _texCopySize [ 0 ] = srcWidth ;
26442679 _texCopySize [ 1 ] = srcHeight ;
26452680 _texCopySize [ 2 ] = srcDepth ;
26462681
26472682 encoder . copyTextureToTexture ( _texCopySrc , _texCopyDst , _texCopySize ) ;
26482683
2649- _texCopySrc . texture = null ;
2650- _texCopyDst . texture = null ;
2684+ _texCopySrc . reset ( ) ;
2685+ _texCopyDst . reset ( ) ;
26512686
26522687 _submit ( this . device . queue , encoder . finish ( ) ) ;
26532688
@@ -2730,18 +2765,15 @@ class WebGPUBackend extends Backend {
27302765
27312766 }
27322767
2733- _copySrc . texture = sourceGPU ;
2734- _copySrc . origin [ 0 ] = rectangle . x ;
2735- _copySrc . origin [ 1 ] = rectangle . y ;
2736- _copySrc . origin [ 2 ] = 0 ;
2737- _copyDst . texture = destinationGPU ;
2768+ _copySrc . setTexture ( sourceGPU ) . setOrigin ( rectangle . x , rectangle . y , 0 ) ;
2769+ _copyDst . setTexture ( destinationGPU ) ;
27382770 _copySize [ 0 ] = rectangle . z ;
27392771 _copySize [ 1 ] = rectangle . w ;
27402772
27412773 encoder . copyTextureToTexture ( _copySrc , _copyDst , _copySize ) ;
27422774
2743- _copySrc . texture = null ;
2744- _copyDst . texture = null ;
2775+ _copySrc . reset ( ) ;
2776+ _copyDst . reset ( ) ;
27452777
27462778 // mipmaps must be genereated with the same encoder otherwise the copied texture data
27472779 // might be out-of-sync, see #31768
0 commit comments