Skip to content

Commit 7769afd

Browse files
aardgooseaardgoose
authored andcommitted
WebGPURenderer: clear() - use cached descriptor properties and views were possible (mrdoob#27551)
* remove redundant code * use cached descriptor properties for clear() * remove unused import --------- Co-authored-by: aardgoose <[email protected]>
1 parent 33bf869 commit 7769afd

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

examples/jsm/renderers/webgpu/WebGPUBackend.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat
77
import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
88
import Backend from '../common/Backend.js';
99

10-
import { DepthFormat, WebGPUCoordinateSystem } from 'three';
11-
1210
import WebGPUUtils from './utils/WebGPUUtils.js';
1311
import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
1412
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
@@ -138,20 +136,22 @@ class WebGPUBackend extends Backend {
138136

139137
}
140138

141-
_getDefaultRenderPassDescriptor( renderContext ) {
139+
_getDefaultRenderPassDescriptor() {
142140

143141
let descriptor = this.defaultRenderPassdescriptor;
144142

145143
const antialias = this.parameters.antialias;
146144

147145
if ( descriptor === null ) {
148146

147+
const renderer = this.renderer;
148+
149149
descriptor = {
150150
colorAttachments: [ {
151151
view: null
152152
} ],
153153
depthStencilAttachment: {
154-
view: this.textureUtils.getDepthBuffer( renderContext.depth, renderContext.stencil ).createView()
154+
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
155155
}
156156
};
157157

@@ -259,12 +259,6 @@ class WebGPUBackend extends Backend {
259259
view: depthTextureData.texture.createView(),
260260
};
261261

262-
if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {
263-
264-
renderContext.stencil = false;
265-
266-
}
267-
268262
descriptor = {
269263
colorAttachments,
270264
depthStencilAttachment
@@ -317,13 +311,13 @@ class WebGPUBackend extends Backend {
317311

318312
let descriptor;
319313

320-
if ( renderContext.textures !== null ) {
314+
if ( renderContext.textures === null ) {
321315

322-
descriptor = this._getRenderPassDescriptor( renderContext );
316+
descriptor = this._getDefaultRenderPassDescriptor();
323317

324318
} else {
325319

326-
descriptor = this._getDefaultRenderPassDescriptor( renderContext );
320+
descriptor = this._getRenderPassDescriptor( renderContext );
327321

328322
}
329323

@@ -578,7 +572,7 @@ class WebGPUBackend extends Backend {
578572
const device = this.device;
579573
const renderer = this.renderer;
580574

581-
const colorAttachments = [];
575+
let colorAttachments = [];
582576

583577
let depthStencilAttachment;
584578
let clearValue;
@@ -602,36 +596,23 @@ class WebGPUBackend extends Backend {
602596
depth = depth && supportsDepth;
603597
stencil = stencil && supportsStencil;
604598

605-
if ( color ) {
606-
607-
const antialias = this.parameters.antialias;
608-
609-
const colorAttachment = {};
610-
611-
if ( antialias === true ) {
599+
const descriptor = this._getDefaultRenderPassDescriptor();
612600

613-
colorAttachment.view = this.colorBuffer.createView();
614-
colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
601+
if ( color ) {
615602

616-
} else {
603+
colorAttachments = descriptor.colorAttachments;
617604

618-
colorAttachment.view = this.context.getCurrentTexture().createView();
619-
620-
}
605+
const colorAttachment = colorAttachments[ 0 ];
621606

622607
colorAttachment.clearValue = clearValue;
623608
colorAttachment.loadOp = GPULoadOp.Clear;
624609
colorAttachment.storeOp = GPUStoreOp.Store;
625610

626-
colorAttachments.push( colorAttachment );
627-
628611
}
629612

630613
if ( depth || stencil ) {
631614

632-
depthStencilAttachment = {
633-
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
634-
};
615+
depthStencilAttachment = descriptor.depthStencilAttachment;
635616

636617
}
637618

0 commit comments

Comments
 (0)