Skip to content

Kernel: Improve early framebuffer scroll speed with in-memory buffer #25998

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VIJAY-0
Copy link

@VIJAY-0 VIJAY-0 commented Jun 15, 2025

  • Introduced (u8 inMemBuffer[]) as a shadow RAM buffer mirroring VRAM layout
  • Updated scroll logic to use memmove on RAM buffer instead of reading from VRAM
  • After scrolling, flush entire RAM buffer to VRAM using memcpy

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Jun 15, 2025
@BuggieBot
Copy link
Member

Hello!

One or more of the commit messages in this PR do not match the SerenityOS code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

@Hendiadyoin1
Copy link
Contributor

First of all: Welcome to the project!
now,
it seems like you did not test your code locally as it fails to compile,
this is likely at least partially caused by a misunderstanding of how un-sized arrays work in c++, especially in classes.
You also don't seem to follow the naming schemes and commit naming policy mentioned in the contributing guidelines.
In case you are using AI tools such as Github-Copilot, that is fine within reason, please always double check that everything you let it generate is semantically correct and represents your intentions and understanding of the code.

@VIJAY-0
Copy link
Author

VIJAY-0 commented Jun 15, 2025

hi ,
thanks for pointing out the issue with array, this is my first PR btw and i am figuring out on the go.
i had one more question regarding build , may i directly create PR and check the build? it is nearly impossible for me to build it on my pc.

@Hendiadyoin1
Copy link
Contributor

What issues are you encountering?
Maybe someone can help you over in our build-issues discord channel

In general testing builds through the CI is discouraged, as it is for example quite slow and will trigger the BuggieBot quite often,
we usually only do it to check some cross platform or compiler stuff

@VIJAY-0 VIJAY-0 force-pushed the fix-framebuffer-scrolling branch from 1555d0e to d29a8be Compare June 19, 2025 11:35
@VIJAY-0
Copy link
Author

VIJAY-0 commented Jun 19, 2025

@Hendiadyoin1
can you please review this and guide me through it.

@Hendiadyoin1
Copy link
Contributor

Current issue is that the code is malformatted,
to avoid this you should set up clang-format in your IDE and/or set up our pre-commit hook,
both of which are recommended and described somewhere in our docs

Avoid slow framebuffer reads during early console scrolling by
maintaining an in-memory buffer. Scrolling now memcpy's full lines
from this buffer to the framebuffer, replacing character-wise copies.

Fixes SerenityOS#25960
@VIJAY-0 VIJAY-0 force-pushed the fix-framebuffer-scrolling branch from d29a8be to d142881 Compare June 22, 2025 05:25
@VIJAY-0 VIJAY-0 changed the title Optimize framebuffer scrolling using RAM buffer with single memcpy flush Kernel: Improve early framebuffer scroll speed with in-memory buffer Jun 22, 2025

memmove(m_in_memory_buffer, m_in_memory_buffer + framebuffer_pitch(), (height() - 1) * framebuffer_pitch());
Copy link
Member

Choose a reason for hiding this comment

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

Please test your code before submitting a PR. This only scrolls by 1 pixel, not by 1 entire line.

Comment on lines +78 to +79
int m_in_memory_buffer_size;
u8* m_in_memory_buffer { nullptr };
Copy link
Member

Choose a reason for hiding this comment

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

Please use a FixedArray. This code is currently very C-like.

Comment on lines +50 to +54
if (!m_in_memory_buffer) {
m_in_memory_buffer_size = height * framebuffer_pitch();
m_in_memory_buffer = (u8*)kmalloc(m_in_memory_buffer_size);
memset(m_in_memory_buffer, 0, m_in_memory_buffer_size);
}
Copy link
Member

@spholz spholz Jun 24, 2025

Choose a reason for hiding this comment

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

Double-buffering the framebuffer was not quite what I meant in my issue.
I think we should have a buffer containing the characters (not the pixels) currently on the screen.
Storing all pixels in a back buffer would also work, but is quite wasteful.

@@ -225,6 +225,11 @@ GenericFramebufferConsoleImpl::FramebufferOffset GenericFramebufferConsoleImpl::
return { (&framebuffer_data()[x * sizeof(u32) * (m_glyph_columns + m_glyph_spacing) + y * m_glyph_rows * framebuffer_pitch()]) };
}

GenericFramebufferConsoleImpl::FramebufferOffset GenericFramebufferConsoleImpl::inmembuffer_offset(size_t x, size_t y)
Copy link
Member

Choose a reason for hiding this comment

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

This function is not necessary with this current approach (storing the pixel data in a second buffer).

Also, inmembuffer is not really a good name that fits our coding style. What you made here is essentially a back buffer (https://en.wikipedia.org/wiki/Multiple_buffering#Software_double_buffering).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 pr-needs-review PR needs review from a maintainer or community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants