-
-
Notifications
You must be signed in to change notification settings - Fork 30
Optimize pen line drawing using instanced rendering #11
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
Conversation
I guess there needs to be a webgl1 fallback The equivalent (?) extension https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays seems to have very good support https://web3dsurvey.com/webgl/extensions/ANGLE_instanced_arrays, may not be worth maintaining another fallback for 0.05% of users |
I have added a fallback to |
I basically copy+pasted the old code back as a second fallback if no webgl2 and no webgl1 extension so there should no downside at all now, going to test this on a whole bunch of different systems to make sure there's no surprises |
Numbers from running https://scratch.mit.edu/projects/1056145815/ on a bunch of systems
I don't have telemetry but I'm pretty sure >99% of our users just have WebGL2 natively so that's the most important column. Seems to vary between "a tiny bit faster" and "very significantly faster", so that's great Unscientific, only one run, no averaging, no attempt to control for thermals or background tasks, expect big error bars...
|
anything else you want to change before merge? |
I would be happy with a marge where this is at. I have thought of one very minor speed improvement but it may not be worth retesting everything, it would only speed up GPU performance not CPU which I think is the main bottleneck. Basically when instance rendering instead of drawing |
I've implemented that now if you wanna investigate, otherwise I'm happy to just revert that commit and merge. |
Didn't seem to help but also doesn't appear to hurt Gonna check a couple more computers with weird or old graphics hardware |
Yeah that was my conclusion as well. I suspect most GPU drivers are smart enough to do this optimization anyways so it ends up being equivalent. |
on staging, to go up whenever i remember |
This is an optimization for the pen line drawing which results in an increase in performance in some projects, particularly raycasters or other 3D projects which draw a lot of lines. For me, this results in a bigger performance boost in firefox then chrome, but is very measurable in both.
The main difference is instead of writing the attributes for each pen line 6 times (once for each vertex), I am using instance rendering to only need to write the data once. This also allows all pen lines to share the same short vertex position buffer instead of having to have identical data copied a lot of times.
I have also merged all attributes (other than position) into one buffer, which allows the data to be written faster by the CPU and read faster by the GPU. It also saved on opengl calls.
The tests for this don't pass on my computer and the output is fairly incomprehensible, I suspect it's something about my environment given tests seemingly unrelated to what I've changed are failing.
I'm not sure how to test this more rigorously, definitely need to do more before merging, but I'm happy with the state the code is in.