WebGPURenderer: Improve performance tracking logic for better accuracy #28748
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related PR: #28741
Description
This is the second part of #28741, continuing my efforts to enhance performance tracking in the new Renderer:
This PR continues to enhance the accuracy of performance tracking. It now tracks performance more accurately without negatively impacting it. This is achieved by monitoring the number of compute programs executed per animation loop and resetting values only after the total timestamp has been correctly accumulated. This involves checking the total number of calls in each cycle using two new variables: previousFrameCalls and timestampCalls.
Basically the monitoring logic has been unwired from the renderer. The await behavior in resolveTimestampAsync has been updated to a simple promise as it was stalling the app loop, altering the array buffers consumed by the programs resulting in instability.
Before this PR (for a simulation with more than 90 compute shaders per frame):
![Screenshot 2024-06-26 at 15 17 34](https://private-user-images.githubusercontent.com/15867665/343031407-5b0f5009-c12d-45ee-b7f7-aa6adb3b3c84.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwNzYzMDgsIm5iZiI6MTcyNTA3NjAwOCwicGF0aCI6Ii8xNTg2NzY2NS8zNDMwMzE0MDctNWIwZjUwMDktYzEyZC00NWVlLWI3ZjctYWE2YWRiM2IzYzg0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDAzNDY0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU0Y2NjNjA2MzRlODEzZDBjZDQ0ZGY0NWI3YzA5Y2JjZjk5ZmNlMTVlOGQyY2U4N2FmMjdhNTU1NWMxNjFhNGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FJ5eRDhFw1vEGEgS4OlbLz7YpbyYK6TtVl0iLGH5SvE)
After this PR (the numbers regarding compute programs now make a lot more sense):
![Screenshot 2024-06-26 at 15 13 08](https://private-user-images.githubusercontent.com/15867665/343031503-7f671027-935b-4824-8f22-e56d3f6e0d8a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwNzYzMDgsIm5iZiI6MTcyNTA3NjAwOCwicGF0aCI6Ii8xNTg2NzY2NS8zNDMwMzE1MDMtN2Y2NzEwMjctOTM1Yi00ODI0LThmMjItZTU2ZDNmNmUwZDhhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDAzNDY0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRkMzlhYmEyZTU4MGIzOWJjM2JmNzg0Y2FhYzBiYjc0OWU2ZmFmZmZjZTE0YjgyYWNiNTg1ZDUzZjU4MTgzNjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.sEP2Q2eyn6H_WCvbXcZHN0lfJ-QeCXFovqqo2AEUndM)
By the way while testing the WebGL part I noticed some odd numbers in the
webgpu_compute_particles_snow.html
example. The WebGPU part runs at around 75 fps, whereas the WebGL backend easily runs at a full 144 fps+ on dev. This is previous to that PR, this PR just highlight the issue. /cc @sunagThis contribution is funded by Utsubo