imgui-wgpu-rs icon indicating copy to clipboard operation
imgui-wgpu-rs copied to clipboard

Support for drawing many vertices using DrawCmd::vtx_offset

Open 4bb4 opened this issue 3 years ago • 2 comments

(Disclaimer: I'm not sure this even is the right place in the stack to ask this, but maybe if it's not, someone can point me to the correct place instead)

I've been using imgui-wgpu-rs with implot-rs for a while and it's been working well (aside from https://github.com/Yatekii/imgui-wgpu-rs/pull/44#issue-568755946, which I've still not been able to fix :D) until I plot a large amount of data. At that point, I hit imgui's "large meshes" limit (https://github.com/ocornut/imgui/blob/master/imconfig.h#L91). With the Glium backend, things still work because it advertises that it supports VtxOffset through the backend flags.

imgui-wgpu-rs doesn't advertise this flag, and when I just overwrote it myself to see if it'd work anyway, I got visual artifacts. Now my question is: Would it be possible for imgui-wgpu-rs to add support for these VtxOffsets? I have no knowledge of imgui's internals so far, but I'd be willing to put some effort towards making such support happen. I'd probably need some pointers for where to get started though.

Thanks in advance for any help / explanations!

4bb4 avatar Mar 15 '21 18:03 4bb4

Eyeballing the code of the two backends, I can see that the loop in https://github.com/Yatekii/imgui-wgpu-rs/blob/master/src/lib.rs#L539 looks similar to the loop in https://github.com/imgui-rs/imgui-rs/blob/master/imgui-glium-renderer/src/lib.rs#L213, and what Glium seems to do with the vtx_offset is slice into the vertex buffer (https://github.com/imgui-rs/imgui-rs/blob/master/imgui-glium-renderer/src/lib.rs#L242). I'll see if I can naively cobble something together that works.

4bb4 avatar Mar 15 '21 18:03 4bb4

Update: I was able to add VtxOffset support for version v0.12.0 (which I need for a project for now) in https://github.com/4bb4/imgui-wgpu-rs/tree/51-support-for-vtxoffset-v0.12.0 - it's not a lot of work (see https://github.com/4bb4/imgui-wgpu-rs/commit/fb8abdf28fc49504f2f2c61e4c1b6cdb57e3f16b).

Before this, drawing more than 64k vertices would crash with the aforementioned imgui assert, but with this change in place, I was able to draw upwards of 800k vertices without any issues! I've not created a PR to master here because I can't really test things on account of that other issue still being there with implot, but feel free to just apply the linked commit yourself.

Or, of course, if any of my changes don't make sense / destroy performance / set computers on fire, please also do let me know :D I don't really know what I'm doing after all, I just played with things until everything worked and looked roughly like the Glium implementation.

4bb4 avatar Mar 15 '21 20:03 4bb4