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: remove some debugging code #29822

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

aardgoose
Copy link
Contributor

I think this can be safely removed, I have only see it trigger when working on a PR and breaking something.

Copy link

github-actions bot commented Nov 6, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 692.21
171.45
692.21
171.45
+0 B
+0 B
WebGPU 821.89
221.91
821.67
221.84
-219 B
-72 B
WebGPU Nodes 821
221.7
820.79
221.63
-219 B
-73 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.56
112.27
464.56
112.27
+0 B
+0 B
WebGPU 542.09
146.75
541.87
146.68
-219 B
-77 B
WebGPU Nodes 498.03
136.5
497.81
136.41
-219 B
-88 B

@RenaudRohlinger
Copy link
Collaborator

I still have this issue when one of my app freezes (on resize event is triggered recreating multiples RTTs in runtime for example) while the bindGroup gets constantly recreated because of a binding issue similar to #29198 (comment).
I can fix it in my code but I believe that a potential solution might lie in improving the caching strategy for RTTs.
Let's just keep this bit while #29198 is still unresolved. 🙏

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 18, 2024

@RenaudRohlinger With #29845 merged, is it now safe to merge this PR as well?

@RenaudRohlinger
Copy link
Collaborator

I can still reproduce the issue when the window is resized:
image

After examining the entire pipeline, I think it makes sense that this issue occurs. The WebGPURenderer lacks the safeguards present in the WebGLRenderer that prevent a texture reallocated at runtime from destroying a newly reallocated texture instead of the old one.

I'm referring to the deallocateTexture (and initTexture) function in the WebGLTextures class of the WebGLRenderer:

const webglTexture = webglTextures[ textureProperties.__cacheKey ];
webglTexture.usedTimes --;

// the WebGLTexture object is not used anymore, remove it

if ( webglTexture.usedTimes === 0 ) {

deleteTexture( texture );

}

// remove the weak map entry if no WebGLTexture uses the source anymore

if ( Object.keys( webglTextures ).length === 0 ) {

_sources.delete( source );

}

This code ensures that textures are only deleted when they are no longer in use by tracking the usedTimes property. It prevents the accidental deletion of textures that have been reallocated during runtime events like window resizing.

By adding a similar safeguard in the WebGPURenderer, we can probably prevent the GPU from deleting newly created textures that are still in use. Implementing reference counting and proper texture management, as done in the WebGLRenderer, should resolve the issue observed during window resizing. Also I'm not sure yet if this should be handled in the Textures Class or in each backend instead.

@RenaudRohlinger
Copy link
Collaborator

Which makes me think about this comment:

I also want to call it before display it the first time to init the renderTexture in the memory before drawing on it and avoid extra uploadtime, same for initTexture to avoid upload when it matters.
#29898 (comment)

I don't think we really have yet a logic of ressource management with pre-allocation and dynamic re-allocation of the Textures. /cc @sunag

@sunag
Copy link
Collaborator

sunag commented Nov 18, 2024

@RenaudRohlinger Maybe you have a small example so we can reproduce this issue?

@Makio64
Copy link
Contributor

Makio64 commented Nov 21, 2024

On a Dataviz project using a lot of RT and drawing into each others, I got the same Bindings._update: binding should be available on resize @RenaudRohlinger is mentioning.

I wanted to make a fiddle to reproduce it yesterday but currently the example is too simple and didnt trigger the issue..
Still it can be a good starting point to reproce the issue: https://jsfiddle.net/Makio64/3brnfyt7/

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.

5 participants