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

Ignore buffer cycling until the first frame is rendered #274

Closed

Conversation

bullno1
Copy link
Contributor

@bullno1 bullno1 commented Mar 14, 2025

I have no idea why this works but it works.

The sprite batcher submits a flurry of s_update_buffer in the first frame and due to SDL's cycling it creates a huge number of spare buffers.
But after the first frame, there is only one update per frame.
This is why frame rate has zero effect on resource usage because everything is decided on the first frame.
SDL's buffer cycling indeed works: It keeps reusing the gazillions of buffers created on the first frame.

The workaround is to ignore cycling on the very first frame.
There is nothing inflight so there is no chance of corruption.

Resource usage even on the RAM side is tiny now.

I think there should be a better fix if the sprite batcher is better understood.

@bullno1
Copy link
Contributor Author

bullno1 commented Mar 14, 2025

Hmm a spritebatch_defrag before a spritebatch_flush makes more sense now that I think about it.

It also helps to deal with situations like new scenes/levels where a bunch of new sprites are added.

@RandyGaul
Copy link
Owner

Ah, yes, before any atlases are constructed it may be behaving where individual draw calls are submit. That might be the crux of the issue here. It's not supposed to do that though. Usually defrag would handle that. Something must have broken somewhere.

@RandyGaul
Copy link
Owner

I would make sure to check the command layer in CF cute_draw.h and make sure it's merging draw calls there properly as a first step

@bullno1
Copy link
Contributor Author

bullno1 commented Mar 14, 2025

I tried calling defrag before flush and it solves both RAM + VRAM usage without touching the cycling flags: #275

@bullno1
Copy link
Contributor Author

bullno1 commented Mar 14, 2025

Closing because this is a hack anw. It won't protect against situations like loading a new scene/level where there are a lot of new sprites.

@bullno1 bullno1 closed this Mar 14, 2025
@bullno1 bullno1 deleted the reduce-ram-usage-due-to-cycling branch March 14, 2025 01:58
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

Successfully merging this pull request may close these issues.

2 participants