-
Notifications
You must be signed in to change notification settings - Fork 234
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
feature/ocl: Improve Linux CL/GL sharing support #673
Conversation
I have tested this on my machine, and the app I wanted to work (DaVinci Resolve) - worked flawlessly on UHD620! |
So any chance someone from intel can review / comment or just general advise on what is required to get this merged ? |
Thanks for the review, I'll try to address these next week. |
e1f390d
to
b1149c2
Compare
@JablonskiMateusz Ok, so it took me a while longer to finally get to it, but I have addressed the comments above, rebased over master (and also tested only the 23.30 release) and seems to all be fine. |
@@ -10,29 +10,8 @@ | |||
|
|||
namespace NEO { | |||
GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) { |
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.
is this class still needed ?
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, it's used by the "common code" shared between linux / windows. The alternative would be #ifdef
in the common code but I wanted to avoid touching windows / common code as much as possible.
glDeviceHandle = contextInfo.deviceHandle; | ||
|
||
return retVal; | ||
std::unique_ptr<OsLibrary> dynLibrary(OsLibrary::load(""));; |
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.
(1) - I know that we cannot link using load-time linking as GL sharing is optional but what is an issue with run-time linking by name? When user is using GL interop then GL library need to be available in the system
(2) I totally agree, we cannot use GL symbols directly
(3) This approach assumes that GL is loaded before OCL is loaded but I can imagine a scenario where CL is initialized before GL is even loaded and in such case I hope should try to load GL to determine if sharing is available.
@JablonskiMateusz Responding here for the libGL thing because for some reason, github doesn't me put a reply to that specific comment 🤷 (1) Because for whatever reason the user is free to have loaded (through whatever mechanism) any GL library and possibly not the first one that would be returned by a normal libdl lookup of (3) In the In the |
We cannot assume that GL is already loaded. Where does that requirement come from? We need to try to open gl library in order to expose the extension - that's our baseline. |
But we don't know which GL library ... it's not our choice. It's be 100% valid for a user to do If you don't want to assume GL is already loaded to return the extension, then I would return it all the time. Which from reading the extension spec is perfectly valid since all that's needed is that there is some way/combination of GL context/device for which we could support it. |
Btw. @smunaut have you looked (e.g. latrace'd) what Nvidia and AMD OpenCL drivers do? |
AMD looksup symbols in the global scope without loading anything it self, you can see it here : (Now, here they lookup The AMD implementation always advertises the extension, it's statically present in the list of supported extension and it doesn't do any checks before it returns it AFAICT. ( https://github.com/ROCm-Developer-Tools/clr/blob/5914ac3c6e9b3848023a7fa25e19e560b1c38541/rocclr/device/device.hpp#L204 ) In Mesa's rusticl they also just search the global scope : https://gitlab.freedesktop.org/mesa/mesa/-/commit/02f7d3640021f23d54022c6fbdf1304c44672033#cb331a47f57adfd7e2565e461a25af9ec00ff8e6_0_32 As for NVIDIA, I'm not sure, no sources I can look at ... I'd need to try it. |
I think we may self load in this case. Extension can be exposed always but to work with sharing GL library needs to be loaded. |
|
@smunaut please adjust commit msg to https://github.com/intel/compute-runtime/blob/master/CONTRIBUTING.md#commit-message-guidelines I think squash to single commit would be needed |
Is squashing really needed ? It makes the diff really hard to read and also means I can't put explanation of why a particular change was done that way in the commit message since it's all globbed up into a giant unreadable diff. All the commits would belong in |
it will be squashed in the end but we can do this on our side. Let's keep it here without squashing. However, I got some errors when applying the PR:
Also, when fixed the issue locally I got test failures:
Could you please ensure that this code is working after rebase? |
fa44cc1
to
7aef244
Compare
3c72253
to
a4888b3
Compare
7a09c51
to
93e941f
Compare
I'm doing what I can to test but again, I'm trying to rebase to master and build here but I just can't ... I can build |
Ok, I managed to build master on my machine (seems there is a requirement for some specific version of dependencies that are not checked by the build system). So I rebased and checked it build. I added a couple of small fixes and removed non-applicable broken tests. Running I didn't change the commit message since if you squash on your side you'll have to make a new one anyway so at that point you can use the |
- They're broken. The eglCreateContext doesn't even have the right prototype, attempting to call it would crash - They're unused. If at some point we need them, we can re-implement them propertly - They increase dependency on EGL which makes adding GLX support harder for nothing Signed-off-by: Sylvain Munaut <[email protected]>
Unused, no equivalent on linux anyway Signed-off-by: Sylvain Munaut <[email protected]>
Those don't exist on linux and won't exist, so no point in keeping these around. Signed-off-by: Sylvain Munaut <[email protected]>
…sLinux This is not used and OS_HANDLE can't hold anything anyway since it's 32 bits. Signed-off-by: Sylvain Munaut <[email protected]>
This is just the header and function prototypes and wrapper so far. The interop header comes from MESA repository at https://gitlab.freedesktop.org/mesa/mesa and can be found under mesa/include/GL/mesa_glinterop.h It has been stripped of the WGL prototypes since we don't need those here and they cause a type conflict in this project. Signed-off-by: Sylvain Munaut <[email protected]>
…MESA Signed-off-by: Sylvain Munaut <[email protected]>
Signed-off-by: Sylvain Munaut <[email protected]>
…laced Signed-off-by: Sylvain Munaut <[email protected]>
Those are not required anymore Signed-off-by: Sylvain Munaut <[email protected]>
Signed-off-by: Sylvain Munaut <[email protected]>
Signed-off-by: Sylvain Munaut <[email protected]>
This is not used and wouldn't be a good idea to call it anyway since we can't rely/modify the GL bind context anyway Signed-off-by: Sylvain Munaut <[email protected]>
The debug flag is -1 when not specified so previously it would enable them all the time, no matter what isGlSharingEnabled() returns Signed-off-by: Sylvain Munaut <[email protected]>
Check if 'glEnable' is in the global scope. This would indicate a GL library has been loaded by the application and that it's worth doing CL/GL interop. We can't really test further because we don't know if user wants GLX or EGL or if those extensions are supported ... Signed-off-by: Sylvain Munaut <[email protected]>
In a CL/GL sharing application we can't go and load another GL library explicitely, it might not be the one the user has used. But we know that whatever the user wants to share with, it has to be loaded already when he requests the context, so we can just lookup the symbols in the global scope. Signed-off-by: Sylvain Munaut <[email protected]>
This seems to be re-used and the windows equivalent resets it after finalize. Signed-off-by: Sylvain Munaut <[email protected]>
Signed-off-by: Sylvain Munaut <[email protected]>
We always consider it to be enabled. Signed-off-by: Sylvain Munaut <[email protected]>
Theses were heavily reliant on the old implementation and don't test anything of value. (CL/GL sharing is completely broken yet the test pass ...). So get rid of that junk. Signed-off-by: Sylvain Munaut <[email protected]>
We need to wait for sync to actually be done Signed-off-by: Sylvain Munaut <[email protected]>
Just rebased on top of master again. |
👋 |
Hi @smunaut |
@JablonskiMateusz I've updated the PR title and description to match those guidelines. I didn't update the commits themselves since AFAIR you said you would squash them all together and I assume the final commit title/description will be taken from the PR. |
Merged outside of github. Thanks @JablonskiMateusz |
This PR is aimed at drastically improving the support for the CL/GL sharing extension on linux.
The current support is not really usable as it only supports a few texture format, and only on EGL contexts. It is also pretty buggy since it requires the texture to be bound when placing the CL call to share it which is just plain wrong and will not work in many applications.
This new version makes used of the "official" interop extension from MESA which is available for GLX and EGL contexts, allows sharing of buffers and not just texture and supports many more formats.
This is still far from being a fully compliant / full featured version of the extension, but it's a big step forward in my opinion and allows to run some real applications. I've tested gr-fosphor (SDR spectrum display) and Davinci Resolve as examples. Both of theses don't work without theses improvements.
Resolves: #659
Resolves: #667
Signed-off-by: Sylvain Munaut [email protected]