-
Notifications
You must be signed in to change notification settings - Fork 41
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
Update to new renderer #10
Conversation
Regressions: * Does not work in 2d anymore * The depth check option is now always on * Removed user Lines (not sure what their purpose was tbh) Improvements: * Does work with the new renerer * Uses wgsl I wrote TODOs laying out improvement paths. There are a few performance low-hanging fruits available. The depth check is kind of a monster. I wanted to have something out before trying it, because I'm strongly considering a uniform for this, so that the depth test can be modified at run time and is probably going to tank performance. Uploading uniforms to GPU under the new renderer requires an awful lot of additional code, due to the nature of wgpu, but it seems completely possible, just check the `shader_material` example in the bevy repository.
The persisting lines now are treated and stored separately from the temporary ones. This simplifies the logic for the temporary ones, and since it's the general case, it should improve performance.
Some more notes: It should be possible to simply unset the indices attribute for the mesh used for "Immediate mod" lines, this way, we don't even have to |
Wow! Thanks so much for the pull request! All the notes here sound great and agreeable, but I probably won’t get a chance to properly review this until after xmas, since I’m away atm. Will look properly when I get home! |
# Objective Instead of panicking when the `indices` field of a mesh is `None`, actually manage it. This is just a question of keeping track of the vertex buffer size. ## Notes * Relying on this change to improve performance on [bevy_debug_lines using the new renderer](Toqozz/bevy_debug_lines#10) * I'm still new to rendering, my only expertise with wgpu is the learn-wgpu tutorial, likely I'm overlooking something.
With bevyengine/bevy#3415 it is now possible to upload meshes to GPU without `indices` set. Before, it would panic. Removing `indices` enables us to simply remove the `ImmLinesStorage::fill_indices` code, since the ordering is exactly as the GPU would interpret the mesh otherwise.
It is configured through the plugin constructor now. It makes more sense than through the `DebugLines` resource, since it's configured at the beginning and won't change in the middle of running the plugin. This was already true before, the difference is that it is now made explicit to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit I haven't been following bevy 0.6 closely, but wow a lot has changed in rendering. I can't believe how complicated it is to do essentially the same thing we were doing before -- I thought it was supposed to get easier!
I really like what you've done to separate immediate and retained lines.
If the always_on_top
depth test thing makes things too complicated, I don't mind dropping the feature until bevy makes it easier to do.
I'll have to look up on what's changed (and actually test this code), but why doesn't 2D work with this approach? This is a pretty big deal because 2D is probably at least 50% of this plugin's usage.
Regarding the other comments:
|
I'll add the corrections you suggested and attempt to add back 2d support. I'll then set the PR as "open" and you can review again. |
At the cost of making the `RetLineStorage::fill_indices` and `mark_expired` methods a bit more complex, it is possible to only store the line index rather than two point indices of expired lines. This should encapsulate neatly the complex underlying storage that mirrors the mesh attribute buffers. Other side benefit is that `timestamp` and `expired` vectors have their size divided by two. I also added the `Line<T>` struct to make the arguments to mutating methods of LineStorage more understandable.
Regarding 2d support, this seems to be a blocker since I rely on mesh rendering for the lines shader. |
Various name changes and extra doc string. Also fixes a likely issue with `mark_expired`, which would add duplicates to the `expired` stack.
Lol I accidentally marked this as ready for review and I don't know how to set it back, sorry.
Ok. Guess we'll keep an eye on that.
The main code is good, just the bevy buffer setup and stuff seems crazy, but yeah I think this is probably the API. |
With the 2d Mesh PR merged, I managed to add back support for 2d. But I had to separate 2d and 3d rendering based on a feature flag. I don't think it's possible to conciliate the two. Is it still OK for you? |
This however, requires adding a feature flag :/
For a summary of the changes:
I'm sorry. It's not the panacea. But it's somewhere to start. |
After doing some tracing, using the I have difficulties interpreting the results of tracing. Timing precisely the line insertion operation, it seems After experimenting a bit; for example, reversing the I really don't see where the performance degradation comes from. Looking at the current code, there is really not that much more going on when inserting lines. The one sure source of slowness is the 2.4% higher MAX_LINES (from 128000 to 131072) but it doesn't explain why it's about 2 times slower. This inspired me though. I think I can make |
@Toqozz I'm done with this. I've no further improvements to make, unless you have any thing to point out. |
Hey, sorry but I won't be able to take a proper look at this until Saturday. Honestly though I'm happy to merge these changes into master for now (we don't guarantee stability on master anyway), and I'll come back to look at it properly and release the new version. |
Thanks for all the work you've put in! <3 |
This is a lot of code and hey, feel free to ignore it, I just wanted to hone my understanding of shader programming with the new bevy renderer. If you reject the PR, I really won't mind.
The code changes
The most notable changes in the code are:
Line
struct. We store the colors and positions as buffer, pretty much the way it's going to be uploaded to GPUduration=0.0
) and one for "retained" lines (with aduration
set), to be fair, I'm not even sure if it improves performance.User-facing changes
Changes:
lines: DebugLines
rather thanlines: ResMut<DebugLines>
to add linesLine
s no longer existDebugLinesPlugin
constructorRegressions:
The depth check option is now always onImprovements:
Possible improvements and depth check
I wrote TODOs laying out potential improvement paths.
I tried implementing the depth test using an uniform. I started an attempt but when
I got to 100 additional lines of code I kinda gave up. Seems the best starting point
is the
shader_material
example in the bevy repository.Edit: I now simply set it through the
DebugLinesPlugin
constructor.