compute-runtime icon indicating copy to clipboard operation
compute-runtime copied to clipboard

cl_khr_gl_sharing GLX support

Open smunaut opened this issue 1 year ago • 29 comments

As discussed in #166 , although the extension has been added recently, only EGL context are supported and having GLX support is required for some applications.

smunaut avatar Jul 04 '23 18:07 smunaut

One of the applications being Davinci Resolve

stereomato avatar Jul 05 '23 03:07 stereomato

I'm interested in this too, because currently there's no way to use Davinci Resolve on Linux, even though EGL support (which took 4 years to develop) is merged. Waiting for any information on this!

k1gen avatar Jul 25 '23 23:07 k1gen

We are open to include this feature in the driver. We are not able to devote engineering effort to implementation at this time, but would welcome contributions from the community.

I'd also like to note that we recently added support for cl_khr_external_memory, which should show up in the August release.

AdamCetnerowski avatar Jul 31 '23 07:07 AdamCetnerowski

So when I had a quick look at this, one the main issue was the API used to implement the sharing with EGL eglExportDMABUFImageMESA has no real equivalent in GLX.

But when trying to work my way through #667 and talking with some mesa devs, they pointed out it shouldn't be using eglExportDMABUFImageMESA in the first place but instead use MesaGLInteropEGLExportObject, so I've been looking into making the switch.

Now obviously this is still EGL specific, but it has a direct GLX equivalent MesaGLInteropGLXExportObject at least.

smunaut avatar Aug 08 '23 08:08 smunaut

FWIW in the branch I pushed in #667 , I have now added GLX support as well.

smunaut avatar Aug 10 '23 11:08 smunaut

So the good new is that Resolve starts and you see something in the viewers now : https://i.imgur.com/qyfOARh.png The bad news is that it only does that when running in valgrind ... which like the name suggests, brings it to a grind :sweat:

smunaut avatar Aug 10 '23 12:08 smunaut

Found a workaround ... I had to remove the RTLD_DEEPBIND option used in intel-compute to load OsLibraries and then it starts. I'm not entirely sure what the issue is or what the consequences are of removing this, so still some check needed.

But now I can start resolve and see stuff in the viewers. It's a bit glitchy and I get some weird errors :

0x7f72886e4680 | IO                   | ERROR | 2023-08-10 23:23:50,585 | Failed to decode clip </tmp/osmodevcall-20210326-fixeria-osmoran-status-update_vp9.webm>, track 0, frame 27687: Requested position is outside of track bound.
0x7f72896e6680 | IO                   | ERROR | 2023-08-10 23:23:50,595 | Failed to decode clip </tmp/osmodevcall-20210326-fixeria-osmoran-status-update_vp9.webm>, track 0, frame 27805: Requested position is outside of track bound.
0x7f72886e4680 | IO                   | ERROR | 2023-08-10 23:23:50,618 | Failed to decode clip </tmp/osmodevcall-20210326-fixeria-osmoran-status-update_vp9.webm>, track 0, frame 27914: Failed to read the video frame from disk.
0x7f72886e4680 | IO                   | ERROR | 2023-08-10 23:23:50,655 | Failed to decode clip </tmp/osmodevcall-20210326-fixeria-osmoran-status-update_vp9.webm>, track 0, frame 28032: Failed to read the video frame from disk.
0x7f7288ee5680 | IO                   | ERROR | 2023-08-10 23:23:53,658 | Failed to decode clip </tmp/osmodevcall-20210326-fixeria-osmoran-status-update_vp9.webm>, track 0, frame 28149: Failed to read the video frame from disk.

But heh, progress !

Interestingly the BRAW standalone player works fine and also use CL/GL sharing (I can see the API calls). ...

smunaut avatar Aug 10 '23 21:08 smunaut

(just wanted to say thank you! - awesome to see someone trying to get Resolve working!)

SimonBrandner avatar Aug 10 '23 22:08 SimonBrandner

@SimonBrandner Testers welcome :grin:

smunaut avatar Aug 11 '23 08:08 smunaut

@smunaut hey, I'm on Arch and have a UHD620. what should I do to test?

k1gen avatar Aug 11 '23 09:08 k1gen

/me is on Nix; might be interesting trying to figure out how to test this :D

SimonBrandner avatar Aug 11 '23 09:08 SimonBrandner

So you need to build :

  • https://gitlab.freedesktop.org/246tnt/mesa/-/tree/clgl-export?ref_type=heads
  • https://github.com/smunaut/compute-runtime/tree/clgl

(make sure to checkout the correct branch as pointed in those links)

You can install in a temporary prefix like /tmp/test_root or something. And then :

export OCL_ICD_VENDORS=/tmp/_root/etc/OpenCL/vendors/
export LD_LIBRARY_PATH=/tmp/_root/lib64
export NEOReadDebugKeys=1
export DisableDeepBind=1 
  • Make sure the .icd gets installed in that subdirectory, IIRC I had to do something more than set the prefix for that but don't remember. You can also create that file by hand, it's just a text file pointing to the right .so
  • Beware of lib vs lib64 depends on your distro I think.

Then just try to start resolve.

smunaut avatar Aug 11 '23 09:08 smunaut

btw, I'm on the unofficial blackmagic discord and on the freedesktop one, so you can ping me there username 246tnt which might be easier than github issues. Also on IRC as tnt on libera.

smunaut avatar Aug 11 '23 09:08 smunaut

@smunaut I will dm you as olk on libera once I have time to test it. thanks for your work

k1gen avatar Aug 11 '23 11:08 k1gen

For anyone following, here's a preview of the current state : https://youtu.be/-PW1J2Y42x0

That video actually shows a bug in the color parade, I know what the bug is and already have a workaround, just talking right now with the mesa guys to see what the best fix would be.

smunaut avatar Aug 24 '23 13:08 smunaut

hey @smunaut, can you backport https://github.com/intel/compute-runtime/commit/8b09bb855e2503e033f684da9b1fcd08802c2156 and https://github.com/intel/compute-runtime/commit/894bab05efb447d249c9f0afdbf0ca62c82395c6? I can't compile your fork with gcc13 without them

k1gen avatar Aug 24 '23 16:08 k1gen

Ah will do. But gimme some time, I haven't actually pushed the latest stuff :sweat_smile:
I'll do that tonight.

smunaut avatar Aug 24 '23 16:08 smunaut

Ok pushed.

You need the 23.2-resolve branch from my MESA tree : https://gitlab.freedesktop.org/246tnt/mesa/-/tree/23.2-resolve?ref_type=heads And the clgl branch of this tree (compute-runtime).

smunaut avatar Aug 24 '23 19:08 smunaut

@specialworld83 Thanks for testing !

smunaut avatar Oct 10 '23 20:10 smunaut

Unfortunately, the preview video in Davinci Resolve is not rendering correctly for me.

Screenshot (this is supposed to show a flat gradient from black to white): screenhot_2023-10-12_000

That said, it doesn't crash or anything, and when I export my Davinci Resolve project, it is all correct again.

I'm using a fully updated Arch Linux with an Intel Arc 750. I manually compiled mesa (source: https://gitlab.freedesktop.org/246tnt/mesa/-/tree/23.2-resolve?ref_type=heads) and intel-compute-runtime (source: https://github.com/smunaut/compute-runtime/tree/clgl-23.30.26918.9).

How can I help to fix this?

cs avatar Oct 12 '23 15:10 cs

Do you use IRC or discord ? Would be easier to do this in a "live" session :)

smunaut avatar Oct 12 '23 15:10 smunaut

@smunaut Discord? Can you send me the right Link?

cs avatar Oct 12 '23 15:10 cs

We can probably create a thread in #resolve on the BMD discord : https://discord.com/invite/blackmagic-design-community-479297254528647188

smunaut avatar Oct 12 '23 15:10 smunaut

So just to update the issue here. There were 2 bugs identified :

  • One in Mesa itself where it export the texture reporting it as being linear while it is in fact tiled ... The export code doesn't handle GFX12.5+ (Alchemist) cards properly since they have a new tiling mode ...
  • One in the new code where the tiling mode is not supported and I'm not sure how to set it.

Note however that theses are not regression, it doesn't work any better in the current cl_khr_gl_sharing support that's currently merged in, so theses patches are still an improvement.

smunaut avatar Oct 13 '23 10:10 smunaut

@JablonskiMateusz @eero-t Maybe one of you knows : How can I specify which tiling mode to use ? I know which one is used by mesa, but now I need to tell the compute stack about it ... I found a linearStorage flag but that's a bit restrictive, I need to specify some specific mode ... (and then there is a aux stuff but ... one thing at a time)

smunaut avatar Oct 13 '23 18:10 smunaut

Any update? How do I install the patch for OpenCL libraries?

My DaVinci Resolve does not playback at all.

Leocraft1 avatar Nov 13 '23 10:11 Leocraft1

There is an open PR I need to address a couple comments on it and update it to latest code, but I'm a bit busy with life stuff ATM so might take a few weeks until I get to it.

smunaut avatar Nov 13 '23 10:11 smunaut

@JablonskiMateusz @eero-t Maybe one of you knows : How can I specify which tiling mode to use ? I know which one is used by mesa, but now I need to tell the compute stack about it ... I found a linearStorage flag but that's a bit restrictive, I need to specify some specific mode ... (and then there is a aux stuff but ... one thing at a time)

Sorry, unfortunately I don't know either (I'm not driver developer / related to this project, just an occasional bug commenter).

eero-t avatar Nov 21 '23 10:11 eero-t

@Compute-Runtime-Automation, why was this closed - is it fixed?

SimonBrandner avatar Mar 01 '24 12:03 SimonBrandner