Skip to content

Commit 9b0bc2f

Browse files
WebGPURenderer: Address review feedback on PR #33419.
- RenderContexts: drop attachment-state cache; rebuild the template literal every call. Benchmarked three variants (instance cache, WeakMap cache, no cache) and the cache provided no net benefit. Addresses review comments about monkey-patching render targets and avoiding comparison complexity for a short string. - WebGPUBackend: extract `_setTexelCopyInfo` and `_submit` module helpers to collapse repeated field-by-field mutation patterns. `_submit` replaces the three-line submit-array scratch pattern at 5 call sites; `_setTexelCopyInfo` collapses 10 field assignments in `copyTextureToTexture` into 2 helper calls. Addresses the readability comment on line 2641. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d2f09ff commit 9b0bc2f

2 files changed

Lines changed: 27 additions & 48 deletions

File tree

src/renderers/common/RenderContexts.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,8 @@ class RenderContexts {
5353
const format = renderTarget.texture.format;
5454
const type = renderTarget.texture.type;
5555
const count = renderTarget.textures.length;
56-
const samples = renderTarget.samples;
57-
const depthBuffer = renderTarget.depthBuffer;
58-
const stencilBuffer = renderTarget.stencilBuffer;
59-
60-
if ( renderTarget._attachmentState === undefined ||
61-
renderTarget._attachmentStateFormat !== format ||
62-
renderTarget._attachmentStateType !== type ||
63-
renderTarget._attachmentStateSamples !== samples ||
64-
renderTarget._attachmentStateCount !== count ||
65-
renderTarget._attachmentStateDepth !== depthBuffer ||
66-
renderTarget._attachmentStateStencil !== stencilBuffer ) {
67-
68-
renderTarget._attachmentState = `${ count }:${ format }:${ type }:${ samples }:${ depthBuffer }:${ stencilBuffer }`;
69-
renderTarget._attachmentStateFormat = format;
70-
renderTarget._attachmentStateType = type;
71-
renderTarget._attachmentStateSamples = samples;
72-
renderTarget._attachmentStateCount = count;
73-
renderTarget._attachmentStateDepth = depthBuffer;
74-
renderTarget._attachmentStateStencil = stencilBuffer;
75-
76-
}
77-
78-
attachmentState = renderTarget._attachmentState;
56+
57+
attachmentState = `${ count }:${ format }:${ type }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`;
7958

8059
}
8160

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ function _resetCurrentSets( sets ) {
5757

5858
}
5959

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+
70+
function _submit( queue, commandBuffer ) {
71+
72+
_submitArray[ 0 ] = commandBuffer;
73+
queue.submit( _submitArray );
74+
_submitArray[ 0 ] = null;
75+
76+
}
77+
6078
/**
6179
* A backend implementation targeting WebGPU.
6280
*
@@ -1254,9 +1272,7 @@ class WebGPUBackend extends Backend {
12541272

12551273
}
12561274

1257-
_submitArray[ 0 ] = renderContextData.encoder.finish();
1258-
this.device.queue.submit( _submitArray );
1259-
_submitArray[ 0 ] = null;
1275+
_submit( this.device.queue, renderContextData.encoder.finish() );
12601276

12611277

12621278
//
@@ -1534,9 +1550,7 @@ class WebGPUBackend extends Backend {
15341550

15351551
currentPass.end();
15361552

1537-
_submitArray[ 0 ] = encoder.finish();
1538-
device.queue.submit( _submitArray );
1539-
_submitArray[ 0 ] = null;
1553+
_submit( device.queue, encoder.finish() );
15401554

15411555
}
15421556

@@ -1705,9 +1719,7 @@ class WebGPUBackend extends Backend {
17051719

17061720
}
17071721

1708-
_submitArray[ 0 ] = groupData.cmdEncoderGPU.finish();
1709-
this.device.queue.submit( _submitArray );
1710-
_submitArray[ 0 ] = null;
1722+
_submit( this.device.queue, groupData.cmdEncoderGPU.finish() );
17111723

17121724
}
17131725

@@ -2626,16 +2638,8 @@ class WebGPUBackend extends Backend {
26262638
const sourceGPU = this.get( srcTexture ).texture;
26272639
const destinationGPU = this.get( dstTexture ).texture;
26282640

2629-
_texCopySrc.texture = sourceGPU;
2630-
_texCopySrc.mipLevel = srcLevel;
2631-
_texCopySrc.origin.x = srcX;
2632-
_texCopySrc.origin.y = srcY;
2633-
_texCopySrc.origin.z = srcZ;
2634-
_texCopyDst.texture = destinationGPU;
2635-
_texCopyDst.mipLevel = dstLevel;
2636-
_texCopyDst.origin.x = dstX;
2637-
_texCopyDst.origin.y = dstY;
2638-
_texCopyDst.origin.z = dstZ;
2641+
_setTexelCopyInfo( _texCopySrc, sourceGPU, srcLevel, srcX, srcY, srcZ );
2642+
_setTexelCopyInfo( _texCopyDst, destinationGPU, dstLevel, dstX, dstY, dstZ );
26392643
_texCopySize[ 0 ] = srcWidth;
26402644
_texCopySize[ 1 ] = srcHeight;
26412645
_texCopySize[ 2 ] = srcDepth;
@@ -2645,9 +2649,7 @@ class WebGPUBackend extends Backend {
26452649
_texCopySrc.texture = null;
26462650
_texCopyDst.texture = null;
26472651

2648-
_submitArray[ 0 ] = encoder.finish();
2649-
this.device.queue.submit( _submitArray );
2650-
_submitArray[ 0 ] = null;
2652+
_submit( this.device.queue, encoder.finish() );
26512653

26522654
if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
26532655

@@ -2780,9 +2782,7 @@ class WebGPUBackend extends Backend {
27802782

27812783
} else {
27822784

2783-
_submitArray[ 0 ] = encoder.finish();
2784-
this.device.queue.submit( _submitArray );
2785-
_submitArray[ 0 ] = null;
2785+
_submit( this.device.queue, encoder.finish() );
27862786

27872787
}
27882788

0 commit comments

Comments
 (0)