Skip to content
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

2DGraphics vsync is slow #489

Open
stephaneweg opened this issue Oct 14, 2024 · 13 comments
Open

2DGraphics vsync is slow #489

stephaneweg opened this issue Oct 14, 2024 · 13 comments

Comments

@stephaneweg
Copy link

Hi,

i have a little issue , and i dont know what is the cause.
in my kernel i use 2DGraphics ;
when i use the vsync option, it is verry slow, like 1 FPS , even if i draw a single rectangle ; it seems that the slow part is when it does "m_pFrameBuffer->WaitForVerticalSync();"

when i does not use the vsync option, it does a memcpy; and it's faster.

i what could be the cause of that ?

best regards

@rsta2
Copy link
Owner

rsta2 commented Oct 15, 2024 via email

@stephaneweg
Copy link
Author

stephaneweg commented Oct 15, 2024

I have tested the sample 41 with the same result (i am using an RPI 4B and a standard HDMI display)
but i think i solved my problem => in the config file, i now disabled the options to load dtoverlay (dtoverlay=vc4-kms-v3d)

it works better, but it still stuck a 30hz

@rsta2
Copy link
Owner

rsta2 commented Oct 15, 2024

Then clearing the screen an the drawing takes too long to reach 60 Hz. You may have to reduce the screen size (width, height), if it's important for you to have 60 Hz.

rsta2 added a commit that referenced this issue Oct 28, 2024
Before a new graphics frame has been prepared in the uncached display
buffer. Now a separate cached buffer is used, which speeds up operation.
The separate buffer is copied to the display buffer in the vertical sync
phase to suppress flickering. Now this class can be used on the
Raspberry Pi 5 too, but without vertical sync support.

Issue #489
@rsta2
Copy link
Owner

rsta2 commented Oct 28, 2024

There is an update on the develop branch, which speeds up operation very much. The class C2DGraphics can be used on the Raspberry Pi 5 now too, but without vertical sync support.

@KyleCardoza
Copy link

It's great that it's sped up. I'm wondering if you can explain to me why drawing to a third buffer and using memcpy to update the second buffer before swapping is faster than just writing directly to the second in the first place. Clearly it is, I applied your fix to my copy and it works, but I don't understand why.

@rsta2
Copy link
Owner

rsta2 commented Nov 25, 2024 via email

@KyleCardoza
Copy link

That makes sense, thank you. One more question if you don’t mind. Would DMA from the cached buffer to the framebuffer be faster than memcpy(), or is it about even?

@rsta2
Copy link
Owner

rsta2 commented Nov 26, 2024 via email

@KyleCardoza
Copy link

Very cool. What I've done on my end is take the current main branch C2DGraphics class and extensively modified it into a project specific class (two classes, actually, one that owns the framebuffer and one that deals with drawing to an arbitrary memory buffer) that supports clipping rectangles and alpha blending; I will try making my screen class use DMA to update the back buffer and see if that is better, worse, or the same.

@KyleCardoza
Copy link

Okay, I have implemented DMA write for updating the back-buffer from the cached draw buffer, and it's at least a little faster with a burst argument of zero; however, if I goose the burst argument up to 10, I pulled ~60fps at 1080p. I'm not sure how big a burst argument it can handle without causing bus problems, though. 16 crashes it at boot. I would imagine with more activity on all the CPU cores, bus contention with DMA gets worse?

@rsta2
Copy link
Owner

rsta2 commented Nov 26, 2024 via email

@KyleCardoza
Copy link

I presently have it at 5, but I will back it off to 2; I just wanted to see the limits. I've implemented a limiter when running at 1080p, so it stays at a locked 30fps; 960x540, the default resolution I chose, runs 60fps even without burst.

@rsta2
Copy link
Owner

rsta2 commented Nov 26, 2024

Good to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants