Skip to content

Commit 559deba

Browse files
authored
WebGPUBackend: Reuse clear color instance. (mrdoob#33189)
1 parent 2bc2bd8 commit 559deba

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType, Compat
1818
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
1919
import { warnOnce, error } from '../../utils.js';
2020

21+
const _clearValue = { r: 0, g: 0, b: 0, a: 1 };
22+
2123
/**
2224
* A backend implementation targeting WebGPU.
2325
*
@@ -682,7 +684,21 @@ class WebGPUBackend extends Backend {
682684

683685
if ( renderContext.clearColor ) {
684686

685-
colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 };
687+
if ( i === 0 ) {
688+
689+
colorAttachment.clearValue = renderContext.clearColorValue;
690+
691+
} else {
692+
693+
_clearValue.r = 0;
694+
_clearValue.g = 0;
695+
_clearValue.b = 0;
696+
_clearValue.a = 1;
697+
698+
colorAttachment.clearValue = _clearValue;
699+
700+
}
701+
686702
colorAttachment.loadOp = GPULoadOp.Clear;
687703

688704
} else {
@@ -1224,15 +1240,18 @@ class WebGPUBackend extends Backend {
12241240

12251241
let colorAttachments = [];
12261242
let depthStencilAttachment;
1227-
let clearValue;
12281243

12291244
let supportsDepth;
12301245
let supportsStencil;
12311246

12321247
if ( color ) {
12331248

12341249
const clearColor = this.getClearColor();
1235-
clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
1250+
1251+
_clearValue.r = clearColor.r;
1252+
_clearValue.g = clearColor.g;
1253+
_clearValue.b = clearColor.b;
1254+
_clearValue.a = clearColor.a;
12361255

12371256
}
12381257

@@ -1249,7 +1268,7 @@ class WebGPUBackend extends Backend {
12491268

12501269
const colorAttachment = colorAttachments[ 0 ];
12511270

1252-
colorAttachment.clearValue = clearValue;
1271+
colorAttachment.clearValue = _clearValue;
12531272
colorAttachment.loadOp = GPULoadOp.Clear;
12541273
colorAttachment.storeOp = GPUStoreOp.Store;
12551274

@@ -1268,7 +1287,7 @@ class WebGPUBackend extends Backend {
12681287

12691288
const clearConfig = {
12701289
loadOp: color ? GPULoadOp.Clear : GPULoadOp.Load,
1271-
clearValue: color ? clearValue : undefined
1290+
clearValue: color ? _clearValue : undefined
12721291
};
12731292

12741293
if ( supportsDepth ) {

0 commit comments

Comments
 (0)