intel / compute-runtime

Intel® Graphics Compute Runtime for oneAPI Level Zero and OpenCL™ Driver
MIT License
1.15k stars 234 forks source link

cl_khr_gl_sharing GLX support #659

Closed smunaut closed 8 months ago

smunaut commented 1 year ago

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.

stereomato commented 1 year ago

One of the applications being Davinci Resolve

k1gen commented 1 year ago

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!

AdamCetnerowski commented 1 year ago

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.

smunaut commented 1 year ago

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 commented 1 year ago

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

smunaut commented 1 year ago

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 commented 1 year ago

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). ...

SimonBrandner commented 1 year ago

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

smunaut commented 1 year ago

@SimonBrandner Testers welcome :grin:

k1gen commented 1 year ago

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

SimonBrandner commented 1 year ago

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

smunaut commented 1 year ago

So you need to build :

(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 

Then just try to start resolve.

smunaut commented 1 year ago

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.

k1gen commented 1 year ago

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

smunaut commented 1 year ago

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.

k1gen commented 1 year ago

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

smunaut commented 1 year ago

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

smunaut commented 1 year ago

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).

specialworld83 commented 1 year ago

I tested it on Fedora 38 and I can say that it works perfectly.

https://www.codelinsoft.it/sito/blog/installare-da-vinci-resolve-con-scheda-video-iris-xe-graphics-su-fedora-38.html

https://www.codelinsoft.it/sito/images/2023/davinci_resolve.png

smunaut commented 1 year ago

@specialworld83 Thanks for testing !

cs commented 1 year ago

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?

smunaut commented 1 year ago

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

cs commented 1 year ago

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

smunaut commented 1 year ago

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

smunaut commented 1 year ago

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

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 commented 1 year ago

@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)

Leocraft1 commented 1 year ago

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

My DaVinci Resolve does not playback at all.

smunaut commented 1 year ago

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.

eero-t commented 12 months ago

@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).

SimonBrandner commented 8 months ago

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

smunaut commented 8 months ago

@SimonBrandner Hopefully that means #673 will be merged imminently :sweat_smile:

SimonBrandner commented 8 months ago

Awesome!

RannyBergamotte commented 7 months ago

Thanks so much smunaut and kallaballa for y'alls amazing work, I've been eyeing this issue for year now, so glad to see it fixed, can't wait for to arrive in the arch repos in a few months from now! Truly thank you!

wyup commented 7 months ago

Hi @specialworld83 @smunaut , I'm running Fedora 41 rawhide with i5-13500 iGPU, following this guide for building mesa branch 23.3-resolve, I get compilation error:

ninja -C build64 install

../src/amd/llvm/ac_llvm_helper.cpp: In function ‘LLVMOpaquePassManager* ac_create_passmgr(LLVMTargetLibraryInfoRef, bool)’:
../src/amd/llvm/ac_llvm_helper.cpp:311:28: error: ‘createLoopSinkPass’ no se declaró en este ámbito
311 | unwrap(passmgr)->add(createLoopSinkPass());
| ^~~~~~~~~~~~~~~~~~
[112/949] Compiling C object src/amd/vulkan/libvulkan_radeon.so.p/radv_cmd_buffer.c.o
ninja: build stopped: subcommand failed.
smunaut commented 7 months ago

@wyup Don't bother with that branch anymore, just build latest mesa release, it has everything you need in it.

wyup commented 7 months ago

@wyup Don't bother with that branch anymore, just build latest mesa release, it has everything you need in it.

do you mean generic https://gitlab.freedesktop.org/mesa/mesa.git ? There is no resolve branch... and I already have latest 24.0.3 version on my system.

I cloned it, but ninja -C build64 install doesn't even start building:

ninja -C build64 install
ninja: Entering directory `build64'
ninja: error: loading 'build.ninja': No such file or directory

with previous branch 23.2-resolve https://gitlab.freedesktop.org/246tnt/mesa.git it started building...

wyup commented 7 months ago

Any chance to add compatibility for intel integrated GPU detection for Resolve by installing corresponding binary rpm packages? I already have mesa, compute-runtime and cl-gc:

I mean, I have latest mesa-dri-drivers, mesa-va-drivers-freeworld, intel-media-driver, intel-compute-runtime, intel-opencl, intel-igc, oneVPL-intel-gpu, mesa-libGL, mesa-libOpenCL.... what else do i need not to build?

smunaut commented 7 months ago

Which distribution ?

The latests release of intel-compute-runtime doesn't have the patch yet. It's been merged in master but there was no stable release since. The only distribution to have release a package including the patch is fedora and this happened like ... 12h ago or so.

wyup commented 7 months ago

I'm on fedora rawhide 41

intel-compute-runtime-23.35.27191.9-1.fc40.x86_64

smunaut commented 7 months ago

@wyup See https://src.fedoraproject.org/rpms/intel-compute-runtime there is now intel-compute-runtime-24.09.28717.12-1.fc41 since this morning.

wyup commented 7 months ago

I've upgraded intel-compute-runtime, intel-opencl, intel-level-zero, intel-ocloc and intel-opencl to 24.09.28717.12-1.fc41 but Resolve does not detect iGPU.

smunaut commented 7 months ago

What does clinfo say ?

wyup commented 7 months ago
Number of platforms                               2
  Platform Name                                   rusticl
  Platform Vendor                                 Mesa/X.org
  Platform Version                                OpenCL 3.0 
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_byte_addressable_store cl_khr_create_command_queue cl_khr_expect_assume cl_khr_extended_versioning cl_khr_icd cl_khr_il_program cl_khr_spirv_no_integer_wrap_decoration
  Platform Extensions with Version                cl_khr_byte_addressable_store                                    0x400000 (1.0.0)
                                                  cl_khr_create_command_queue                                      0x400000 (1.0.0)
                                                  cl_khr_expect_assume                                             0x400000 (1.0.0)
                                                  cl_khr_extended_versioning                                       0x400000 (1.0.0)
                                                  cl_khr_icd                                                       0x400000 (1.0.0)
                                                  cl_khr_il_program                                                0x400000 (1.0.0)
                                                  cl_khr_spirv_no_integer_wrap_decoration                          0x400000 (1.0.0)
  Platform Numeric Version                        0xc00000 (3.0.0)
  Platform Extensions function suffix             MESA
  Platform Host timer resolution                  1ns

  Platform Name                                   Clover
  Platform Vendor                                 Mesa
  Platform Version                                OpenCL 1.1 Mesa 24.0.3
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd
  Platform Extensions function suffix             MESA

  Platform Name                                   rusticl
Number of devices                                 0

  Platform Name                                   Clover
Number of devices                                 0

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  rusticl
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   <error: 0 devices, multiple matching platforms!>
  clCreateContext(NULL, ...) [default]            No devices found in platform
  clCreateContext(NULL, ...) [other]              <error: no devices in non-default plaforms>
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No devices found in platform

ICD loader properties
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.3.2
  ICD loader Profile                              OpenCL 3.0
smunaut commented 7 months ago

What CPU do you have ?

wyup commented 7 months ago

i5-13500

smunaut commented 7 months ago

Maybe you're hitting : https://github.com/intel/compute-runtime/issues/710 ? Are you on kernel 6.8.x ?

wyup commented 7 months ago

I'm on 6.9.0-0.rc1.17.fc41.x86_64 it looks somebody made it with this guide on a intel iris Xe discrete GPU

eero-t commented 7 months ago

I'm on 6.9.0-0.rc1.17.fc41.x86_64

Then you are impacted by the bug. Workaround:

export NEOReadDebugKeys=1
export OverrideGpuAddressSpace=48
smunaut commented 7 months ago

And also add export DisableDeepBind=1 or resolve will likely crash.

eero-t commented 7 months ago

And also add export DisableDeepBind=1 or resolve will likely crash.

@smunaut Could you mention that also on #710 ?