-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add a patch to fix regression with nouveau #309
Conversation
This restores hardware acceleration on systems where the nouveau driver is loaded and NVIDIA hardware is present, including switchable graphics setups.
Started test build 57356 |
Build 57356 successful
|
I tested and it seems to work well. |
It's worth noting that this introduces a dependency on GBM from Mesa >= 21.1.0, which is probably too new. I wonder if the issue isn't just that the |
It's not related to the fallback path. Here's a minimal reproducer: https://gitlab.gnome.org/-/snippets/5989 $ ./nouveau_gbm_bug
Started iteration 0
Finished iteration 0
Started iteration 1
nouveau_gbm_bug: drmPrimeHandleToFD: No such file or directory The issue is due to the fact that nouveau only considers GEM handles "global" (i.e., may be shared in multiple objects) in specific scenarios, by calling the The concept of "get_handle" in the GBM API seems to be designed to be a simple getter; in the You can see that nouveau doesn't call the Edit: |
To be fair, that sounds like a Nouveau bug; when it's queried for a |
I couldn't find documentation that states the expected behavior of |
Yeah, that's definitely the expectation. I can't think of any other driver which returns a GEM handle that cannot be exported. Using the FD entrypoints is definitely better, but it's not OK to return GEM handles that ... aren't entirely GEM handles. |
Thanks for providing clarity on this. I'll try to see if I can figure out the best way to achieve this in nouveau. |
@fooishbar, I found additional context for the issue:
So it seems that the conclusion was that this was an application issue in the wlroots case, and it is now well-documented that this behavior is not allowed. Considering the above, how do you suggest we proceed? cc: @emersion |
Calling |
@fooishbar drivers generally only keep gem handle in their drmPrimeFDToHandle that could be theoretically shared, i.e. either previously imported or one that was originally allocated on that fd and then exported. which means if you call drmPrimeHandleToFD bypassing gbm, that handle won't be in the lookup cache and no amount of using gbm to import will fix that, stuff is broken at that point. hence why if you have gbm managing a drmfd, you cannot do anything else with these handle that does not go through gbm. there really can be only one owner of the drmfd gem bo handle space or things will break. so your rule needs to be that calling drmPrimeHandleToFD is totally ok, as long as you guarantee that that buffer never comes back to the same fd through any convoluted path. meaning you could import it in some kms display driver, or v4l device, but that's absolutely all you can safely do. closing the fd otoh is fine, since fd are fully refcounted |
oh also this is pretty much generic issue for all gbm/mesa drivers using drm underneath, shouldn't have anything to do with nouveau. but sounds like the reason nouveau is special is because it gets one of the alloc flags wrong and hence some hacks are needed (that WINSYS_HANDLE_TYPE_KMS mentioned above, I haven't dug into the code) |
Mmm, I guess I missed the memo that |
@fooishbar, @danvet, so looking at this minimal reproducer, is the logic in I did see that the drivers where this works do export the handles (add them to an internal map) as part of |
Yeah, personally I think it's nouveau at fault for exporting GEM handles to the user and then claiming that those handles ... can't be used. |
Thanks @fooishbar. I'd like to share some additional context. The only documentation I could find that may give a hint as to the intended nature of handles queried using
Mesa implements this requirement with So the @danvet, is this what you meant in the following quote?
If so, could one theorize that the handles that @fooishbar, I think that handles exported through GBM do indeed work with KMS APIs even in the nouveau case, so they are not entirely useless. Perhaps this was the only intention of the GBM API? To effectively provide the same promise provided by |
GBM definitely started as a bridge between EGL and KMS, but has been a lot more than that for a long time. I don't think the spec text is super relevant to what's going on here. It describes the handle as 'local to the DRM file descriptor', because that's what GEM handles are: scoped to the file descriptor (technically the file description, but close enough). Even then, it invalidates its own point by suggesting a 'global DRM name' i.e. flink, which would presumably fail in the same way as dmabuf export. It's also not clear what nouveau could gain from preventing export. I understand that you want a clear delineation between local and exported buffers, sure. But the only time you export a GEM handle is when a buffer is GBM or winsys, i.e. at the very tail end of your rendering where it's going to be used by a context-external consumer anyway. Even then, winsys (in the case of Wayland and DRI3) pulls an FD rather than a handle, so the only thing nouveau gains from this is the ability to keep gbm_bos within local space. I'd be stunned if this was a meaningful optimisation in any usecase, let alone one which justified the pain of an arbitrary division within the API. |
@doraskayo with import in a kms device I meant using your own drmfd for the display hardware, which must be not the same file descriptor as the one gbm using. otherwise you're right back to the confusion over who manages the drm handle space. So the only ok sequence is 1. open a drm kms fd to get your own fresh and private drmfd 2. get a dma-buf fd from somewhere 3. drmPrimeFD2Handle on your own drmfd that you opened in step 1 If it's some other drmfd that you're sharing with gbm for step 3, then you're in bad surprises territory again. Wrt the specifics of __DRI_IMAGE_ATTRIB_HANDLE I have no idea (would need to check the source in mesa), I think @fooishbar is the more compenten one for that. |
Closing this PR, this is now fixed in nouveau: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24648 Thanks for the help and advice, @fooishbar, @danvet. |
This restores hardware acceleration on systems where the nouveau driver is loaded and NVIDIA hardware is present, including switchable graphics setups.
An alternative to #308.