Skip to content

Commit 507641d

Browse files
WebGPURenderer: Move TexelCopyTextureInfo into its own module.
The wrapper class for `GPUTexelCopyTextureInfo` is a standalone helper — move it out of `WebGPUTextureUtils.js` (which is about texture management) into `src/renderers/webgpu/utils/TexelCopyTextureInfo.js`, matching three.js's "one class per file" convention. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2f37c04 commit 507641d

3 files changed

Lines changed: 95 additions & 47 deletions

File tree

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
1212
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
1313
import WebGPUCapabilities from './utils/WebGPUCapabilities.js';
1414
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
15-
import WebGPUTextureUtils, { TexelCopyTextureInfo } from './utils/WebGPUTextureUtils.js';
15+
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
16+
import TexelCopyTextureInfo from './utils/TexelCopyTextureInfo.js';
1617

1718
import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType, Compatibility } from '../../constants.js';
1819
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Reusable wrapper around `GPUTexelCopyTextureInfo`. Mutates in place to avoid
3+
* per-frame GC pressure while keeping call sites readable via chainable setters.
4+
*
5+
* @private
6+
*/
7+
class TexelCopyTextureInfo {
8+
9+
/**
10+
* Constructs a new texel-copy texture info.
11+
*/
12+
constructor() {
13+
14+
/**
15+
* The source/destination GPU texture.
16+
*
17+
* @type {?GPUTexture}
18+
* @default null
19+
*/
20+
this.texture = null;
21+
22+
/**
23+
* The mip level of the texture to copy from/to.
24+
*
25+
* @type {number}
26+
* @default 0
27+
*/
28+
this.mipLevel = 0;
29+
30+
/**
31+
* The origin of the copy within the texture.
32+
*
33+
* @type {{x: number, y: number, z: number}}
34+
*/
35+
this.origin = { x: 0, y: 0, z: 0 };
36+
37+
}
38+
39+
/**
40+
* Sets the texture.
41+
*
42+
* @param {GPUTexture} texture - The GPU texture.
43+
* @return {TexelCopyTextureInfo} A reference to this instance.
44+
*/
45+
setTexture( texture ) {
46+
47+
this.texture = texture;
48+
return this;
49+
50+
}
51+
52+
/**
53+
* Sets the mip level.
54+
*
55+
* @param {number} mipLevel - The mip level.
56+
* @return {TexelCopyTextureInfo} A reference to this instance.
57+
*/
58+
setMipLevel( mipLevel ) {
59+
60+
this.mipLevel = mipLevel;
61+
return this;
62+
63+
}
64+
65+
/**
66+
* Sets the origin of the copy.
67+
*
68+
* @param {number} x - The x coordinate.
69+
* @param {number} y - The y coordinate.
70+
* @param {number} z - The z coordinate.
71+
* @return {TexelCopyTextureInfo} A reference to this instance.
72+
*/
73+
setOrigin( x, y, z ) {
74+
75+
this.origin.x = x;
76+
this.origin.y = y;
77+
this.origin.z = z;
78+
return this;
79+
80+
}
81+
82+
/**
83+
* Clears the texture reference so the scratch doesn't retain a GPU object across frames.
84+
*/
85+
reset() {
86+
87+
this.texture = null;
88+
89+
}
90+
91+
}
92+
93+
export default TexelCopyTextureInfo;

src/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,6 @@ const _compareToWebGPU = {
3535

3636
const _flipMap = [ 0, 1, 3, 2, 4, 5 ];
3737

38-
/**
39-
* Reusable wrapper around `GPUTexelCopyTextureInfo`. Mutates in place to avoid
40-
* per-frame GC pressure while keeping call sites readable via chainable setters.
41-
*/
42-
class TexelCopyTextureInfo {
43-
44-
constructor() {
45-
46-
this.texture = null;
47-
this.mipLevel = 0;
48-
this.origin = { x: 0, y: 0, z: 0 };
49-
50-
}
51-
52-
setTexture( texture ) {
53-
54-
this.texture = texture;
55-
return this;
56-
57-
}
58-
59-
setMipLevel( mipLevel ) {
60-
61-
this.mipLevel = mipLevel;
62-
return this;
63-
64-
}
65-
66-
setOrigin( x, y, z ) {
67-
68-
this.origin.x = x;
69-
this.origin.y = y;
70-
this.origin.z = z;
71-
return this;
72-
73-
}
74-
75-
reset() {
76-
77-
this.texture = null;
78-
79-
}
80-
81-
}
82-
8338
/**
8439
* A WebGPU backend utility module for managing textures.
8540
*
@@ -1715,5 +1670,4 @@ export function getFormat( texture, device ) {
17151670

17161671
}
17171672

1718-
export { TexelCopyTextureInfo };
17191673
export default WebGPUTextureUtils;

0 commit comments

Comments
 (0)