Skip to content
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

cl_khr_gl_sharing GLX support #659

Closed
smunaut opened this issue Jul 4, 2023 · 56 comments
Closed

cl_khr_gl_sharing GLX support #659

smunaut opened this issue Jul 4, 2023 · 56 comments
Labels
Feature request New driver feature

Comments

@smunaut
Copy link
Contributor

smunaut commented Jul 4, 2023

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
Copy link

One of the applications being Davinci Resolve

@JablonskiMateusz JablonskiMateusz added the Feature request New driver feature label Jul 7, 2023
@k1gen
Copy link

k1gen commented Jul 25, 2023

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
Copy link
Contributor

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
Copy link
Contributor Author

smunaut commented Aug 8, 2023

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
Copy link
Contributor Author

smunaut commented Aug 10, 2023

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

@smunaut
Copy link
Contributor Author

smunaut commented Aug 10, 2023

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 😓

@smunaut
Copy link
Contributor Author

smunaut commented Aug 10, 2023

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
Copy link

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

@smunaut
Copy link
Contributor Author

smunaut commented Aug 11, 2023

@SimonBrandner Testers welcome 😁

@smunaut smunaut closed this as completed Aug 11, 2023
@smunaut smunaut reopened this Aug 11, 2023
@k1gen
Copy link

k1gen commented Aug 11, 2023

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

@SimonBrandner
Copy link

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

@smunaut
Copy link
Contributor Author

smunaut commented Aug 11, 2023

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 
  • 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
Copy link
Contributor Author

smunaut commented Aug 11, 2023

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
Copy link

k1gen commented Aug 11, 2023

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

@smunaut
Copy link
Contributor Author

smunaut commented Aug 24, 2023

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
Copy link

k1gen commented Aug 24, 2023

hey @smunaut, can you backport 8b09bb8 and 894bab0? I can't compile your fork with gcc13 without them

@smunaut
Copy link
Contributor Author

smunaut commented Aug 24, 2023

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

@smunaut
Copy link
Contributor Author

smunaut commented Aug 24, 2023

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
Copy link

specialworld83 commented Oct 10, 2023

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
Copy link
Contributor Author

smunaut commented Oct 10, 2023

@specialworld83 Thanks for testing !

@cs
Copy link

cs commented Oct 12, 2023

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
Copy link
Contributor Author

smunaut commented Oct 12, 2023

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

@cs
Copy link

cs commented Oct 12, 2023

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

@smunaut
Copy link
Contributor Author

smunaut commented Oct 12, 2023

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

@smunaut
Copy link
Contributor Author

smunaut commented Oct 13, 2023

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
Copy link
Contributor Author

smunaut commented Oct 13, 2023

@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
Copy link
Contributor Author

smunaut commented Nov 13, 2023

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
Copy link

eero-t commented Nov 21, 2023

@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
Copy link

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

@smunaut
Copy link
Contributor Author

smunaut commented Mar 1, 2024

@SimonBrandner Hopefully that means #673 will be merged imminently 😅

@SimonBrandner
Copy link

Awesome!

@RannyBergamotte
Copy link

RannyBergamotte commented Mar 23, 2024

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
Copy link

wyup commented Mar 27, 2024

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
Copy link
Contributor Author

smunaut commented Mar 27, 2024

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

@wyup
Copy link

wyup commented Mar 27, 2024

@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
Copy link

wyup commented Mar 28, 2024

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
Copy link
Contributor Author

smunaut commented Mar 28, 2024

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
Copy link

wyup commented Mar 28, 2024

I'm on fedora rawhide 41

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

@smunaut
Copy link
Contributor Author

smunaut commented Mar 28, 2024

@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
Copy link

wyup commented Mar 28, 2024

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
Copy link
Contributor Author

smunaut commented Mar 28, 2024

What does clinfo say ?

@wyup
Copy link

wyup commented Mar 28, 2024

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
Copy link
Contributor Author

smunaut commented Mar 28, 2024

What CPU do you have ?

@wyup
Copy link

wyup commented Mar 28, 2024

i5-13500

@smunaut
Copy link
Contributor Author

smunaut commented Mar 28, 2024

Maybe you're hitting : #710 ? Are you on kernel 6.8.x ?

@wyup
Copy link

wyup commented Mar 28, 2024

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
Copy link

eero-t commented Mar 28, 2024

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
Copy link
Contributor Author

smunaut commented Mar 28, 2024

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

@eero-t
Copy link

eero-t commented Mar 28, 2024

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

@smunaut Could you mention that also on #710 ?

@smunaut
Copy link
Contributor Author

smunaut commented Mar 28, 2024

@eero-t That has nothing to do with #710 😅 You always need to do that with resolve and Intel ...

@wyup
Copy link

wyup commented Mar 28, 2024

it works!! you're a hero :-)

@vidalinux
Copy link

vidalinux commented Apr 12, 2024

Using this patch on Arch linux + Davinci Resolve + Intel Arc 770 with latest intel-compute-runtime, everything works good but video looks like this;
mpv-shot0016

@smunaut
Copy link
Contributor Author

smunaut commented Apr 12, 2024

@vidalinux I assume you're on intel Arc ?
If so, yeah there is a bug ... but I don't have access to Arc hardware so I can't debug/fix it.

@vidalinux
Copy link

@smunaut ok thanks for your answer. maybe @intel can donate one ;)

@wyup
Copy link

wyup commented Apr 19, 2024

Resolve doesn't start anymore after Fedora update:

#!/bin/bash
export NEOReadDebugKeys=1
export DisableDeepBind=1
export OverrideGpuAddressSpace=48
/opt/resolve/bin/resolve
diegohum@tower:~$ resolve
ActCCMessage Already in Table: Code= c005, Mode= 13, Level=  1, CmdKey= -1, Option= 0
ActCCMessage Already in Table: Code= c006, Mode= 13, Level=  1, CmdKey= -1, Option= 0
ActCCMessage Already in Table: Code= c007, Mode= 13, Level=  1, CmdKey= -1, Option= 0
ActCCMessage Already in Table: Code= 2282, Mode=  0, Level=  0, CmdKey= 8, Option= 0
PnlMsgActionStringAdapter Already in Table: Code= 615e, Mode=  0, Level=  0, CmdKey= -1, Option= 0
18.6.6.0007 Linux/Clang x86_64
Main thread starts: 8B02D100
0x7fa38b02d100 | Undefined            | INFO  | 2024-04-19 17:17:37,269 | --------------------------------------------------------------------------------
0x7fa38b02d100 | Undefined            | INFO  | 2024-04-19 17:17:37,269 | Loaded log config from /home/diegohum/.local/share/DaVinciResolve/configs/log-conf.xml
0x7fa38b02d100 | Undefined            | INFO  | 2024-04-19 17:17:37,269 | --------------------------------------------------------------------------------

kernel: 6.9.0-0.rc4.20240416git96fca68c4fbf7.38.fc41.x86_64
intel-compute-runtime-24.09.28717.17-1.fc41.src.rpm
clinfo.txt

However Resolve was prone to crashes. I couldn't load any h264/aac media files, it crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request New driver feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.