From bdd0946a6fb68d4f41a43989c19c8d3f3691bd77 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 3 Sep 2020 22:05:01 +0200 Subject: [PATCH] WebGPURenderer: Apply viewport and scissor settings just once per pass. --- .../jsm/renderers/webgpu/WebGPURenderer.js | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/examples/jsm/renderers/webgpu/WebGPURenderer.js b/examples/jsm/renderers/webgpu/WebGPURenderer.js index 2ab1ecd0f4ce9d..a20968fd0d63ff 100644 --- a/examples/jsm/renderers/webgpu/WebGPURenderer.js +++ b/examples/jsm/renderers/webgpu/WebGPURenderer.js @@ -450,6 +450,32 @@ class WebGPURenderer { 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 ); + + } + + // process renderable objects + for ( let i = 0, l = renderList.length; i < l; i ++ ) { const renderItem = renderList[ i ]; @@ -480,30 +506,6 @@ class WebGPURenderer { const pipeline = this._renderPipelines.get( object ); passEncoder.setPipeline( pipeline ); - // rasterization - - 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 ); - - } - // bind group const bindGroup = this._bindings.get( object ).group;