jdryg / vg-renderer

A vector graphics renderer for bgfx, based on ideas from NanoVG and ImDrawList (Dear ImGUI)
BSD 2-Clause "Simplified" License
503 stars 55 forks source link

Rendering issue #24

Closed Arcnor closed 2 years ago

Arcnor commented 2 years ago

Hello,

First of all, thanks for making this available. I've converted a project of mine to it and got a nice performance improvement over NanoVG (from 20% usage to 10% usage), and given I'm only rendering rectangles I think I can get that much lower, but I digress.

My project is a reimplementation of https://github.com/movAX13h/Binmap which is a really nice tool. Normally, the tool looks like this:

BinmapCpp

However, I'm hitting some kind of bug and after playing a bit the image becomes this:

BinmapCppBug

Actually, I think it's flashing every frame between the 2 states. The thing is, the exact same commands are being sent in those 2 cases (and I've verified everything is balanced), so there must be some internal state that's getting out of whack.

I understand helping without more info is impossible, but I'd like to ask if you had any ideas of where I should be looking for debugging this issue. I also think it might be text related, as removing all text makes the issue disappear, but that might be a red herring.

I've also removed the CommandListCache just to test, but that wasn't it either.

Thanks in advance.

jdryg commented 2 years ago

Nice to know the library helps (even if it has issues :))

About the issue you are facing. I suspect you are using the D3D11 backend of bgfx. It is a known issue (to me :)). Unfortunately, I haven't found the root cause yet. It seems to be related with the way bgfx updates dynamic vertex and index buffers but I don't have a solution to it. All other backends seem to work correctly (OGL, Vulkan, D3D12).

Try changing USE_D3D11_STAGING_BUFFER inside renderer_d3d11.h from 0 to 1. It should be fixed.

I opened a discussion in bgfx for exposing this flag to the compiler in order to be able to set it without changing the source code, but it has not been implemented yet.

If the above doesn't resolve the issue, say it and I'll try to look into it (might need a repro case).

Arcnor commented 2 years ago

Hey, thanks for the fast response!

I'm actually using Metal on Mac, but if you think it might be a BGFX renderer bug, I can try changing to OpenGL and see what happens.

jdryg commented 2 years ago

Unfortunately, I'm not familiar with Metal (or the bgfx backend) and I don't know if it has a similar flag to try out.

Can you also try with Vulkan + MoltenVK?

Arcnor commented 2 years ago

...and I should have just done that instead of 2 comments (sorry!) but you're right, it doesn't happen on OpenGL, just on Metal, which is annoying...

I'll check that discussion, hopefully there might be tips there to try and fix the issue.

jdryg commented 2 years ago

I think the issue might also be resolved if you change vg-renderer to use transient buffers instead of dynamic buffers. Unfortunately, I don't have any plans to do this myself.

The difference between the 2 kind of buffers is that bgfx discards all the contents of transient buffers (_discard parameter is true) but not of the regular dynamic buffers.

As far as I know, there is no way in bgfx to create dynamic buffer with the same behavior as transient buffers (which might have been useful in other situations). The size limitation of transient buffers is the reason I'm not using them in vg-renderer.

jdryg commented 2 years ago

Check this commit if you want to try it out: https://github.com/JohnTM/vg-renderer/commit/c7a1b862959082b0e68ee4edd081dc5021024c17

It's from a fork and I haven't tried it out myself. So I don't know if this commit has all the required changes or if it actually works.

Arcnor commented 2 years ago

Well, that doesn't sound optimal then, but I'd definitely try that link, thanks!

I think it will be better to fix BGFX if the problem actually lies there. If the problem is actually dynamic buffers I'll try to dig into the issue at some point, maybe I can figure out why they're failing intermittently (or every 2 frames like in my case).

I'll close this in the meantime, as it's (sadly, as it will be much easier) not a vg problem.

Thanks for all the help!