瀏覽代碼

Merge pull request #20274 from takahirox/SinglePassEncoder

WebGPURenderer: Single command encoder, pass encoder, and global rasterization settings for all renderable objects.
Michael Herzog 4 年之前
父節點
當前提交
f365f5363e
共有 1 個文件被更改,包括 34 次插入35 次删除
  1. 34 35
      examples/jsm/renderers/webgpu/WebGPURenderer.js

+ 34 - 35
examples/jsm/renderers/webgpu/WebGPURenderer.js

@@ -129,8 +129,39 @@ class WebGPURenderer {
 		const opaqueObjects = this._currentRenderList.opaque;
 		const transparentObjects = this._currentRenderList.transparent;
 
-		if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera );
-		if ( transparentObjects.length > 0 ) this._renderObjects( transparentObjects, camera );
+		const device = this._device;
+		const cmdEncoder = device.createCommandEncoder( {} );
+		const passEncoder = cmdEncoder.beginRenderPass( this._renderPassDescriptor );
+
+		// global rasterization settings for all renderable objects
+
+		const vp = this._viewport;
+
+		if ( vp !== null ) {
+
+			const width = Math.floor( vp.width * this._pixelRatio );
+			const height = Math.floor( vp.height * this._pixelRatio );
+
+			passEncoder.setViewport( vp.x, vp.y, width, height, vp.minDepth, vp.maxDepth );
+
+		}
+
+		const sc = this._scissor;
+
+		if ( sc !== null ) {
+
+			const width = Math.floor( sc.width * this._pixelRatio );
+			const height = Math.floor( sc.height * this._pixelRatio );
+
+			passEncoder.setScissorRect( sc.x, sc.y, width, height );
+
+		}
+
+		if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, passEncoder );
+		if ( transparentObjects.length > 0 ) this._renderObjects( transparentObjects, camera, passEncoder );
+
+		passEncoder.endPass();
+		device.defaultQueue.submit( [ cmdEncoder.finish() ] );
 
 	}
 
@@ -472,36 +503,7 @@ class WebGPURenderer {
 
 	}
 
-	_renderObjects( renderList, camera ) {
-
-		const device = this._device;
-
-		const cmdEncoder = device.createCommandEncoder( {} );
-		const passEncoder = cmdEncoder.beginRenderPass( this._renderPassDescriptor );
-
-		// global rasterization settings for all renderable objects
-
-		const vp = this._viewport;
-
-		if ( vp !== null ) {
-
-			const width = Math.floor( vp.width * this._pixelRatio );
-			const height = Math.floor( vp.height * this._pixelRatio );
-
-			passEncoder.setViewport( vp.x, vp.y, width, height, vp.minDepth, vp.maxDepth );
-
-		}
-
-		const sc = this._scissor;
-
-		if ( sc !== null ) {
-
-			const width = Math.floor( sc.width * this._pixelRatio );
-			const height = Math.floor( sc.height * this._pixelRatio );
-
-			passEncoder.setScissorRect( sc.x, sc.y, width, height );
-
-		}
+	_renderObjects( renderList, camera, passEncoder ) {
 
 		// process renderable objects
 
@@ -521,9 +523,6 @@ class WebGPURenderer {
 
 		}
 
-		passEncoder.endPass();
-		device.defaultQueue.submit( [ cmdEncoder.finish() ] );
-
 	}
 
 	_renderObject( object, passEncoder ) {