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

Dynamically resize the vertex buffer #13

Merged
merged 1 commit into from
May 4, 2024

Conversation

mardy
Copy link
Collaborator

@mardy mardy commented May 1, 2024

Avoid reserving memory if glBegin() is never called, and dynamically increase its size as needed. We never free the buffer memory, since it's likely that the same amount of memory will again be needed during the next frame.

src/gc_gl.c Outdated
return;
if (glparamstate.imm_mode.current_numverts >= glparamstate.imm_mode.current_vertices_size) {
if (!glparamstate.imm_mode.current_vertices) return;
int new_size = glparamstate.imm_mode.current_vertices_size * 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how keen I am on doubling every time. Have you done any profiling of how many vertices you end up with at peak usage? I can see doubling when current_vertices_size is small but maybe cap the increment somewhere? Is there a benefit to starting small?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it really depends on the application. I noticed the problem by running this code, and the maximum there is 162. Starting small makes sense, because we don't know how the API will be used and what is most important for the client: maybe it has objcts with a low number of vertices but high-definition textures, so it would rather save memory for that. Note that each vertex takes up quite a bit of memory (it's 12 floats, so 48 bytes).

I do agree that capping the increment makes sense. Maybe you double until we get to 256, after which we just add 256 every time. I'll do like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Avoid reserving memory if glBegin() is never called, and dynamically
increase its size as needed. We never free the buffer memory, since it's
likely that the same amount of memory will again be needed during the
next frame.
@mardy mardy force-pushed the dynamic-glbegin-buffer branch from aa07e7d to 3b359e1 Compare May 4, 2024 13:21
@WinterMute WinterMute merged commit 7e0c6f2 into devkitPro:master May 4, 2024
2 checks passed
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