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

Atomic KMS: enable bypass #3595

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

tarek-y-ismail
Copy link
Contributor

@tarek-y-ismail tarek-y-ismail commented Sep 11, 2024

Apologies for the general suckiness of the code, will improve that once it actually works.

To test:

./build/bin/miral-kiosk --show-splash=off --platform-display-libs=mir:atomic-kms --platform-rendering-libs=mir:gbm-kms --cursor=null &
sleep 2
glmark2-wayland

Note that until hardware cursor support is merged, the cursor must be disabled when testing bypass (current implementation works only with one renderable)

@tarek-y-ismail tarek-y-ismail requested a review from RAOF September 11, 2024 14:47
@tarek-y-ismail tarek-y-ismail self-assigned this Sep 11, 2024

for (std::size_t i = 0; i < std::min(4zu, plane_descriptors.size()); i++)
{
bo_handles[i] = plane_descriptors[i].dma_buf;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where the problem lies; drmModeAddFB2 expects GEM handles, and you're giving it dmabuf file descriptors.

Here is the necessary DRM API for converting the two, along with an ominous warning about the sharp edges of that API.

Since I think we share the underlying FD with the RenderingPlatform (and so with EGL etc), I think we'll need to do the “everything goes through gbm” route. That means going through gbm_bo_import (with type = GBM_BO_IMPORT_FD_MODIFIER and flags = GBM_BO_USE_SCANOUT) and then pulling all the GEM handles out with gbm_bo_get_handle_for_plane (and then handling the lifetime of the gbm_bo, keeping a track of it, and destroying it when necessary)

@RAOF RAOF force-pushed the initial-atomic-kms-platform branch from d172bfa to 6e64d62 Compare September 12, 2024 07:48
@tarek-y-ismail tarek-y-ismail force-pushed the atomic-kms-enable-bypass branch 3 times, most recently from eeec45a to 3bd9e74 Compare September 13, 2024 06:55
@tarek-y-ismail tarek-y-ismail marked this pull request as ready for review September 13, 2024 12:09
@tarek-y-ismail tarek-y-ismail requested a review from a team as a code owner September 13, 2024 12:09
@tarek-y-ismail tarek-y-ismail force-pushed the atomic-kms-enable-bypass branch from a420ff3 to 8031474 Compare September 24, 2024 06:57
@Saviq Saviq added the triaged Triage into JIRA to plan it in label Oct 7, 2024
@tarek-y-ismail
Copy link
Contributor Author

Could reuse a rebase after we figure out why artifacts appear when bypass is active.

@Saviq
Copy link
Collaborator

Saviq commented Oct 8, 2024

Could reuse a rebase after we figure out why artifacts appear when bypass is active.

Feel free to rebase the chain of PRs already.

src/platforms/atomic-kms/server/kms/display_buffer.cpp Outdated Show resolved Hide resolved
for (std::size_t i = 0; i < std::min(MAX_PLANES, plane_descriptors.size()); i++)
gem_handles[i] = gbm_bo_get_handle_for_plane(gbm_bo, i).u32;

auto fb_id = std::shared_ptr<uint32_t>{
Copy link
Contributor

Choose a reason for hiding this comment

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

As it stands, I think this code leaks a gbm_bo each time it's called? It calls gbm_bo_import, which will allocate a gbm_bo, but nothing every frees it.

Maybe import_gbm_bo should return a shared_ptr<gbm_bo> with cleanup functor, and that should in turn be captured by this shared_ptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I didn't know that, I thought we only got a (cached) handle to the buffer object (i.e. created once on the first import and reused later).

Copy link
Contributor Author

@tarek-y-ismail tarek-y-ismail Oct 14, 2024

Choose a reason for hiding this comment

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

Also, I've noticed that I import and destroy a buffer object every frame, this doesn't feel correct (unless the GBM code handles this). I think it might also be related to the artifacts showing in glmark2

@tarek-y-ismail tarek-y-ismail requested a review from RAOF October 14, 2024 11:08
@tarek-y-ismail tarek-y-ismail force-pushed the initial-atomic-kms-platform branch from 24b446d to 0dc388b Compare October 15, 2024 14:55
@tarek-y-ismail tarek-y-ismail force-pushed the atomic-kms-enable-bypass branch from e252b73 to bd7b097 Compare October 15, 2024 15:26
RAOF added 2 commits October 17, 2024 17:35
…orted for scanout.

The compositor code is expecting `framebuffer_for` to sometimes return `nullptr`; this is fine.
What's *not* fine is passing a null `fb_id` to `AtomicKmsFbHandle` and then returning a
*non*-null `Framebuffer` that's broken :)
@tarek-y-ismail tarek-y-ismail force-pushed the atomic-kms-enable-bypass branch from bd7b097 to 82cdf9c Compare October 17, 2024 14:40
Base automatically changed from initial-atomic-kms-platform to main November 7, 2024 14:11
@AlanGriffiths
Copy link
Collaborator

@tarek-y-ismail what is the status of this PR? Clearly it needs conflicts resolved, but does it need more?

@tarek-y-ismail
Copy link
Contributor Author

what is the status of this PR? Clearly it needs conflicts resolved, but does it need more?

@RAOF is investigating the artifacts.

@tarek-y-ismail
Copy link
Contributor Author

Small update:
To help pinpoint the cause of artifacts and figure out whether it's a driver thing, a mesa thing, or a kernel thing (both AMD and Intel GPUs show the bug, we still don't know about nvidia since it's naughty with atomic KMS), I tried running with --driver-quirks=allow:driver:nvidia, which caused a crash in gbm_surface_create as mentioned in #3252. Hardcoding 0 for flags caused another crash somewhere in drm_fb_id_from_dma_buffer, related to gbm_bo. I tried debugging it for a bit, but couldn't pinpoint further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Triage into JIRA to plan it in
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants