[rlsw] Variant dispatch refactor + bunch of improvements#5996
Conversation
|
Also worth noting, I moved all configuration While doing so I noticed a small naming inconsistency, Happy to fix this either way, prefixing all config defines with |
I was actually hoping somebody would get around to this. I attempted it previously but you know better than I do. Embedded platforms, in theory, should see serious speed ups with it. I'll leave my measurements here when I get around to it. |
|
@Bigfoot71 thanks for this big update! I need some time to review it more carefully... In the meantime, keeping consistency with It's just a detail but would it be possible to move the |
The final number is about a 10% uplift to waving_cubes (630ms worst to 570ms worst) and bunnymark for me (30 more alpha-clipped bunnies at 5fps, totalling 250). Raster is definitely faster than it once was for very large single colour unlit triangles (say at least 10 pixels wide or larger). I did verify there wasn't any maths issues using prints on the interp check and indeed it does only set the interp flag when using the simple_shapes example. However dispatching many triangles (or even quads, apparently) still hits a limit purely because of the overhead needed to setup each span. And that's expected, so nothing we can do about it. Developers on embedded should be making sure to control their overdraw anyway (harkens back to the N64, etc). But these uplifts are definitely welcome when drawing, say, a giant black box to clear some area of the screen for text (like bunnymark). I think the most interesting benchmarks would be first person maze, etc, since those triangles are enormous. but I need to write a proper demo for it since my platform doesn't have enough buttons. |
Ran these examples. The optimization lifts us about 10% across the board. I'm having platform-specific issues with ram access completely irrelevant to this but these definitely help. I assume the uplift will be even more if the assets are in the fastest ram possible on the board. |
7350ed1 to
2fceb9c
Compare
No problem, I dropped the commit in question, there are no more I still kept the new Edit: I would propose this change in a separate PR, along with the fix for configuration defs consistency. |
|
@Bigfoot71 thank you very much! great improvements! |
Summary
While experimenting with a different way to handle framebuffers, I ended up simplifying the variant-generation system for the rasterizer's pipeline specializations.
That simplification unlocked a series of small cascading optimizations, which I've bundled into this PR.
Changes
Variant generation
SW_RASTER_VARIANTS(X)X-macro lists (one explicitNAME, FLAGSpair per specialization) with a token-based system, a variant is now just a plain list of state names (eg.TEXTURE_2D, DEPTH_TEST), from which the function name, itsSW_STATE_*flags, and its dispatch table slot are all derived automatically viaSW_FLAGS(...)/SW_NAME(...).SW_VEC_OPto cut down on repetitive per-component code across triangle/quad/line rasterizers.New pipeline state:
COLOR_INTERPSW_STATE_COLOR_INTERP, toggled off automatically when all vertices of a primitive share the same color.Rasterization optimizations
dWdx,dZdx,dCdx,dTdx,dTdy) are now computed once per triangle via a whole-triangle plane-gradient solve, instead of being recomputed on every scanline.COLOR_INTERP, noTEXTURE_2D; eg. plain depth/blend-only triangles).sw_texture_pick_sampler) instead of being recomputed for every sampled pixel.gotobased depth-test discard in triangle/quad/line rasterizers in favor of a branch that fully disappears from the compiled variants where depth testing is disabled.Misc
inlinekeywords, letting the compiler decide on its own, but keptSW_INLINE(forced inlining) only for the cases where it's known to matter.Performance
Without detailed profiling,
models_first_person_maze(O2, default conservative rlsw config) gained roughly 20 FPS avg on my Ryzen 5 3600.textures_bunny_markshowed no noticeable difference, but rasterization itself isn't the main bottleneck now on "modern desktop hardware" (as implemented, naturally).That said, the
COLOR_INTERPelimination should matter more on more limited targets where every avoided interpolation counts.Future work