瀏覽代碼

WebGPURenderer: clear() - use cached descriptor properties and views were possible (#27551)

* remove redundant code

* use cached descriptor properties for clear()

* remove unused import

---------

Co-authored-by: aardgoose <[email protected]>
aardgoose 1 年之前
父節點
當前提交
c6c81de3ab
共有 1 個文件被更改,包括 13 次插入32 次删除
  1. 13 32
      examples/jsm/renderers/webgpu/WebGPUBackend.js

+ 13 - 32
examples/jsm/renderers/webgpu/WebGPUBackend.js

@@ -7,8 +7,6 @@ import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat
 import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
 import Backend from '../common/Backend.js';
 
-import { DepthFormat, WebGPUCoordinateSystem } from 'three';
-
 import WebGPUUtils from './utils/WebGPUUtils.js';
 import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
 import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
@@ -138,7 +136,7 @@ class WebGPUBackend extends Backend {
 
 	}
 
-	_getDefaultRenderPassDescriptor( renderContext ) {
+	_getDefaultRenderPassDescriptor() {
 
 		let descriptor = this.defaultRenderPassdescriptor;
 
@@ -146,12 +144,14 @@ class WebGPUBackend extends Backend {
 
 		if ( descriptor === null ) {
 
+			const renderer = this.renderer;
+
 			descriptor = {
 				colorAttachments: [ {
 					view: null
 				} ],
 				depthStencilAttachment: {
-					view: this.textureUtils.getDepthBuffer( renderContext.depth, renderContext.stencil ).createView()
+					view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
 				}
 			};
 
@@ -259,12 +259,6 @@ class WebGPUBackend extends Backend {
 				view: depthTextureData.texture.createView(),
 			};
 
-			if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {
-
-				renderContext.stencil = false;
-
-			}
-
 			descriptor = {
 				colorAttachments,
 				depthStencilAttachment
@@ -317,13 +311,13 @@ class WebGPUBackend extends Backend {
 
 		let descriptor;
 
-		if ( renderContext.textures !== null ) {
+		if ( renderContext.textures === null ) {
 
-			descriptor = this._getRenderPassDescriptor( renderContext );
+			descriptor = this._getDefaultRenderPassDescriptor();
 
 		} else {
 
-			descriptor = this._getDefaultRenderPassDescriptor( renderContext );
+			descriptor = this._getRenderPassDescriptor( renderContext );
 
 		}
 
@@ -578,7 +572,7 @@ class WebGPUBackend extends Backend {
 		const device = this.device;
 		const renderer = this.renderer;
 
-		const colorAttachments = [];
+		let colorAttachments = [];
 
 		let depthStencilAttachment;
 		let clearValue;
@@ -602,36 +596,23 @@ class WebGPUBackend extends Backend {
 			depth = depth && supportsDepth;
 			stencil = stencil && supportsStencil;
 
-			if ( color ) {
-
-				const antialias = this.parameters.antialias;
-
-				const colorAttachment = {};
-
-				if ( antialias === true ) {
+			const descriptor = this._getDefaultRenderPassDescriptor();
 
-					colorAttachment.view = this.colorBuffer.createView();
-					colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
+			if ( color ) {
 
-				} else {
+				colorAttachments = descriptor.colorAttachments;
 
-					colorAttachment.view = this.context.getCurrentTexture().createView();
-
-				}
+				const colorAttachment = colorAttachments[ 0 ];
 
 				colorAttachment.clearValue = clearValue;
 				colorAttachment.loadOp = GPULoadOp.Clear;
 				colorAttachment.storeOp = GPUStoreOp.Store;
 
-				colorAttachments.push( colorAttachment );
-
 			}
 
 			if ( depth || stencil ) {
 
-				depthStencilAttachment = {
-					view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
-				};
+				depthStencilAttachment = descriptor.depthStencilAttachment;
 
 			}