Skip to content

WebGPURenderer: Rebind textureNode value post RenderTarget resize#28372

Closed
RenaudRohlinger wants to merge 1 commit into
mrdoob:devfrom
RenaudRohlinger:utsubo/fix/texturenode-size-rebind
Closed

WebGPURenderer: Rebind textureNode value post RenderTarget resize#28372
RenaudRohlinger wants to merge 1 commit into
mrdoob:devfrom
RenaudRohlinger:utsubo/fix/texturenode-size-rebind

Conversation

@RenaudRohlinger

Copy link
Copy Markdown
Collaborator

Related issue: #28289

Description

Additional fix to #28289, when resizing a RenderTarget, for example using a PostProcess pipeline with a PassNode, the resize will trigger this.renderTarget.setSize(), which will dispatch dispose, destroying the associated textures in the backend and then losing the proper binding on the GPU side.

This PR ensures the textureNode.value gets updated right after the resize event of the associated RenderTarget. Otherwise, if a resize event gets triggered after the updateBefore call and before binding.update(), the following error would be triggered because the condition in binding.update() (this.texture !== textureNode.value) would not be satisfied.
image

This happens because the rebinding of textureNode.value = rtt.texture isn't triggered yet by updateBefore, which will occur in the next frame.

This contribution is funded by Utsubo

@RenaudRohlinger RenaudRohlinger requested a review from sunag May 14, 2024 03:25
@RenaudRohlinger RenaudRohlinger added this to the r165 milestone May 14, 2024
@sunag

sunag commented May 14, 2024

Copy link
Copy Markdown
Collaborator

How I can reproduce this warning in some PP example? I tried resize the windows but not happened...

@RenaudRohlinger RenaudRohlinger removed this from the r165 milestone May 14, 2024
@RenaudRohlinger

RenaudRohlinger commented May 14, 2024

Copy link
Copy Markdown
Collaborator Author

Seems like it came from one of my custom postprocessing node that was constantly re-creating a texture node in the updateBefore method generating a difference in the binding.update() condition:

updateBefore(frame) {
    //this was generating the error
    this._textureNode = texture(this._fbo.texture);
}

So I simply moved it to the constructor. And it seems to solve the issue.

That's why my PR did fix my issue, because it was making sure the textureNode was always properly up to date even if the textureNode was getting re-created every frame in the updateBefore loop.

Sorry about that, this one was pretty tricky to debug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants