Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Reduce overhead from excessive cache sharing for postprocessing nodes. #29198

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/RenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { LinearFilter } from '../constants.js';
import { Vector4 } from '../math/Vector4.js';
import { Source } from '../textures/Source.js';

let _RenderTargetId = 0;

/*
In options, we can specify:
* Texture parameters for an auto-generated target texture
Expand All @@ -26,6 +28,8 @@ class RenderTarget extends EventDispatcher {

this.viewport = new Vector4( 0, 0, width, height );

Object.defineProperty( this, 'id', { value: _RenderTargetId ++ } );

const image = { width: width, height: height, depth: 1 };

options = Object.assign( {
Expand Down Expand Up @@ -67,6 +71,8 @@ class RenderTarget extends EventDispatcher {

this.samples = options.samples;

this.isolate = false;

}

get texture() {
Expand Down
1 change: 1 addition & 0 deletions src/nodes/display/AfterImageNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AfterImageNode extends TempNode {

this._compRT = new RenderTarget();
this._compRT.texture.name = 'AfterImageNode.comp';
this._compRT.isolate = true;

this._oldRT = new RenderTarget();
this._oldRT.texture.name = 'AfterImageNode.old';
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/display/BloomNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class BloomNode extends TempNode {

renderTargetHorizontal.texture.name = 'UnrealBloomPass.h' + i;
renderTargetHorizontal.texture.generateMipmaps = false;
renderTargetHorizontal.isolate = true;

this._renderTargetsHorizontal.push( renderTargetHorizontal );

const renderTargetVertical = new RenderTarget( 1, 1, { type: HalfFloatType } );

renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i;
renderTargetVertical.texture.generateMipmaps = false;
renderTargetVertical.isolate = true;

this._renderTargetsVertical.push( renderTargetVertical );

Expand Down
15 changes: 6 additions & 9 deletions src/nodes/display/GaussianBlurNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import QuadMesh from '../../renderers/common/QuadMesh.js';
import { Vector2 } from '../../math/Vector2.js';
import { RenderTarget } from '../../core/RenderTarget.js';

// WebGPU: The use of a single QuadMesh for both gaussian blur passes results in a single RenderObject with a SampledTexture binding that
// alternates between source textures and triggers creation of new BindGroups and BindGroupLayouts every frame.

const _quadMesh1 = /*@__PURE__*/ new QuadMesh();
const _quadMesh2 = /*@__PURE__*/ new QuadMesh();
const _quadMesh = /*@__PURE__*/ new QuadMesh();

class GaussianBlurNode extends TempNode {

Expand All @@ -34,6 +30,8 @@ class GaussianBlurNode extends TempNode {
this._verticalRT = new RenderTarget();
this._verticalRT.texture.name = 'GaussianBlurNode.vertical';

this._verticalRT.isolate = true;

this._textureNode = passTexture( this, this._verticalRT.texture );

this.updateBeforeType = NodeUpdateType.RENDER;
Expand Down Expand Up @@ -65,8 +63,7 @@ class GaussianBlurNode extends TempNode {

const currentTexture = textureNode.value;

_quadMesh1.material = this._material;
_quadMesh2.material = this._material;
_quadMesh.material = this._material;

this.setSize( map.image.width, map.image.height );

Expand All @@ -85,7 +82,7 @@ class GaussianBlurNode extends TempNode {

this._passDirection.value.set( 1, 0 );

_quadMesh1.render( renderer );
_quadMesh.render( renderer );

// vertical

Expand All @@ -94,7 +91,7 @@ class GaussianBlurNode extends TempNode {

this._passDirection.value.set( 0, 1 );

_quadMesh2.render( renderer );
_quadMesh.render( renderer );

// restore

Expand Down
2 changes: 2 additions & 0 deletions src/renderers/common/RenderContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class RenderContexts {

attachmentState = `${ count }:${ format }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`;

if ( renderTarget.isolate === true ) attachmentState += `:${ renderTarget.id }`;

}

const chainMap = this.getChainMap( attachmentState );
Expand Down
1 change: 1 addition & 0 deletions src/renderers/common/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ function _createRenderTarget( width, height, params ) {
cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
cubeUVRenderTarget.texture.isPMREMTexture = true;
cubeUVRenderTarget.scissorTest = true;
cubeUVRenderTarget.isolate = true;
return cubeUVRenderTarget;

}
Expand Down
Loading