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
Fix driver probing, DRI3 and Xwayland support #614
Conversation
1e98eae
to
da969d3
Compare
Didn't realise the autotools build was still used. Squashed a fix in the respective commit. |
da969d3
to
2bf3f3f
Compare
2bf3f3f
to
944fda6
Compare
Pushed a minor fix (were printing null instead of the env/api override string). For testing I've used
For all the various readers, please give this a test. Let me know if it doesn't work or thumbs up if it does. |
@XinfengZhang @uartie humble ping? |
944fda6
to
f70c621
Compare
Fixing the LIBVA_DRIVER_NAME high-lighted a pre-existing issue, so Ive pulled it out for now. Will follow-up at later stage addressing that. For now the MR is good to land. |
/* | ||
* Copyright © 2022 Collabora Ltd. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose to use SPDX instead of whole license text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT no SPDX notations are used in the project. So while I'm in favour (esp with it's an ISO standard), it's something better handled a) as follow-up and b) across the whole project.
|
reply = xcb_dri3_open_reply(conn, cookie, NULL /* error */); | ||
|
||
if (!reply || reply->nfd != 1) { | ||
free(reply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will crash if reply is NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? The !reply
will be evaluated and the second comparison will be skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, reply->nfd
will be skipped, but !reply
will be true and it will try to execute free(NULL)
. that's where it will crash. Though it depends on free()
implementation, for what I remember it will crash.
I suggest code should be:
if (!reply) {
return -1;
}
if (reply->nfd != 1) {
free(reply);
return -1;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
free(NULL)
is safe for any compliant implementations. In particular Xorg, Mesa and Wayland (to name a few) depend on this behaviour. Adding a workaround here provides a disservice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick look the project already depends on well-behaved C runtime - see va/drm/va_drm.c
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, to dispel any doubts you may possibly have, here's the exact quote from C99 standard, paragraph 7.20.3.2 The free function
(emphasis is mine):
The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hi-Angel do you mind sending a mesa patch for fold the if checks? Alternatively I'll get to it tomorrow. Using it as an argument is clutching at straws.
@dvrogozh I appreciate the time review comments - especially the two issues you've spotted.
Although it feels like we've lost track of the bigger picture and we're waist deep into bikeshedding. This is a
feature (or bugfix if you're likely minded) that users have been waiting for over 5 years. Other MRs #612 #613 fix serious bugs, or remove obsolete and irrelevant code #617 or make the codebase more consistent/flexible and future/feature prone #615.
Splitting hairs about if checks before free()
isn't the most productive use of our time. There are genuine useful MRs and many more to come that sorely need maintainer. As suggested earlier - if the team is short on time, do consider granting commit access to other active people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hi-Angel do you mind sending a mesa patch for fold the if checks?
Done https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17974
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still did not change my opinion on this item. If function don't need to be called, it should not be called. To me the following code makes much more sense regardless that it takes more space.
if (!reply)
return -1;
if (reply->nfd != 1) {
free(reply);
return -1;
}
As for the other places within libva - we are not fixing everything in this PR. If I would notice that in other PRs I would comment the same. So, that's not a motivation to use the same here.
I will remove my -1 from this review, but I won't +1 it as well.
f70c621
to
7d06fa8
Compare
v4 includes:
|
7d06fa8
to
b3f413d
Compare
v5: drop bonus fd ownership comment, close() as applicable |
reply = xcb_dri3_open_reply(conn, cookie, NULL /* error */); | ||
|
||
if (!reply || reply->nfd != 1) { | ||
free(reply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, reply->nfd
will be skipped, but !reply
will be true and it will try to execute free(NULL)
. that's where it will crash. Though it depends on free()
implementation, for what I remember it will crash.
I suggest code should be:
if (!reply) {
return -1;
}
if (reply->nfd != 1) {
free(reply);
return -1;
}
reply = xcb_dri3_open_reply(conn, cookie, NULL /* error */); | ||
|
||
if (!reply || reply->nfd != 1) { | ||
free(reply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a workaround here provides a disservice.
I am sorry, but that's not a workaround. Pointer might be NULL. You have no reason to call free, so don't call it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for late response, from the code logic, it will check the connection , and finally get the device node name, then open it and call drm function to get the driver name and candidates , right?
so, it resolve the problem of driver name retrieving on XWayland which only support DRI3 , not support DRI2. but it expose another question about the support of vaPutSurface:
from this logic, if driver still only support DRI2, the vaPutSurface will certainly failed, of course, maybe it could be resolved later (we are recommended to use DMA buffer sharing instead of vaPutSurface)
I think we can do that step-by-step. Authentication goes first. But adding a note for vaPutSurface behavior with DRI3 would be nice. @evelikov : can you, please, also rebase the code on tip of the master. This will take in some ci adjustments. |
b3f413d
to
162c0ec
Compare
I rebased it with web operation |
162c0ec
to
bbe90ee
Compare
As mentioned in the summary - I've explicitly omitted vaPutSurface. There are many reasons for that:
|
there are conflict with #615 , and also need run style_unify script. |
bbe90ee
to
c298394
Compare
Should be all good now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM , thanks
The radeonsi driver can work with both radeon and amdgpu. Add the extra combo into the mapping table. Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reuse the upstream drmGetNodeTypeFromFd(), which has been part of libdrm version 2.4.59 (we require 2.4.60). Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
DRI3 has been a thing for 5+ years, sadly libva never learned how to query the server for the fd. Add basic support for that, where we fall-back to the DRM module's drm module name to driver mappings. v2: setup the autotools build v3: explicitly handle all node types in va_isDRI3Connected() v4: enhance fd ownership comment, flip node-type switch arms. v5: drop fd ownership comment, close() as applicable v6: null check after XGetXCBConnection() Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
c298394
to
c832349
Compare
Humble ping - what can I do to move this forward? Would be great to have it merged before its 3 month anniversary 😉 |
sorry to let you feel any inconvenience , actually, I just tested it, it could pass with vainfo --display=x11 under wayland. |
and it will be a part of 2.17 release, is it ok? |
Above all - I fully agree, this is not a something to pick for 2.16 and it should be in master for at least a week before going into a release. Also there is no inconvenience, although clarity is sorely missing. In particular, it is fine if you prefer that both maintainers have to review every MR. It's also fine for reviews or merging to take time. But please document that in the CONTRIBUTING (as requested in #622). For example: In some cases they will approve PRs, while not merging them due to X reasons. In such cases reply to the PR if it has been left unmerged for X weeks. Feel free to reuse ^^ substituting X/Y/Z as applicable. |
thanks, will change the contributing guide, 1 approval from maintainer is mandatory, and no objection from maintainers , merged it |
Great thanks. Do you mind closing the following PRs and issues: |
I closed them. |
This MR fixes some pre-existing bugs in the libva (backend) driver handling and adds DRI3 support.
In other words:
the LIBVA_DRIVER_NAME override works correctlypulled out for nowNote: Only DRI3 open/fd retrieval is added enough for GetDisplay. All the winsys part is deliberately omitted, since it is heavily driver specific and makes little sense to add here.
In practise the x11/wayland winsys code in libva-{x11,wayland} has never been appealing enough to be used in the Mesa VA drivers. If i965 (legacy intel-driver) or iHD (new intel-media-driver) are interested they can adapt it to their needs.