intel / libvpl

Intel® Video Processing Library (Intel® VPL) API, dispatcher, and examples
https://intel.github.io/libvpl/
MIT License
262 stars 80 forks source link

How to select different devices with MFXLoad and MFXCreateSession API #86

Closed gitcchi closed 11 months ago

gitcchi commented 1 year ago

I have both an Intel Arc as well as an Intel UHD 770 iGPU, and would like to be able to select which hardware to use. I could not find what is the way to select the hardware adapter with the newer Load and CreateSession method. The documentation only mention it with the legacy API.

Could a code sample be provided that demonstrates this functionality?

rupakroyintel commented 1 year ago

@gitcchi Thanks for reaching out to us. For the 2.x APIs it is recommended to use MFXEnumImplementations() and MFXSetConfigFilterProperty() to query adapter capabilities and select a suitable adapter from the available hardware adapters as MFXQueryAdapters()* are deprecated starting from API 2.9. You can see the hello-createsession code example that shows the usage of these APIS. One of the major advantages of using 2. x APIs is that VPL runtime can allocate the video memory surfaces itself instead of the application doing so ("Internal Memory Management") and can also create the DX/VAAPI device internally instead of the app doing so and then calling SetHandle. More information can be found on this page.

gitcchi commented 1 year ago

@rupakroyintel Thank you for your reply, but it unfortunately does not help me fill in the holes. The hello-createsession code does not use MFXEnumImplementations and MFXSetConfigFilterProperty.

I can use the MFXEnumImplementations and with it I can see the two Intel devices. The missing part is how to set this in the config.

Can you please post an example of the MFXSetConfigFilterProperty calls with arguments that will select the implementation? Currently it is not clear which fields of mfxImplDescription need to be set to select the device. If all fields need to be overridden this would be quite cumbersome and a better way should be available.

Also, I believe the documentation text of MFXEnumImplementations needs updating, as it still assumes the output handle is a mfxImplDescription. This is now an opaque mfxHDL as you can select the type of info to query with the format argument.

gitcchi commented 1 year ago

@rupakroyintel Also 3 of the 4 links in your reply I cannot access. I get "Unauthorized access error".

jonrecker commented 1 year ago

More information and example code for selecting from among multiple GPUs is included in the guide here. The application may either user MFXSetConfigFilterProperty() to filter out implementations which do not match the desired adapter, and/or iterate over all available implementations using MFXEnumImplementations() then call MFXCreateSession() with the index "i" corresponding to the desired GPU. Some other examples of using MFXSetConfigFilterProperty with mfxExtendedDeviceId are in the unit tests here.

MFXEnumImplementations always returns an opaque handle of type mfxHDL, which should be interpreted (cast) based on which "format" was requested. The vpl-inspect tool has examples of using MFXEnumImplementations().

rupakroyintel commented 1 year ago

@rupakroyintel Also 3 of the 4 links in your reply I cannot access. I get "Unauthorized access error".

Sorry for the inconvenience. I have updated the links.

gitcchi commented 1 year ago

@jonrecker Thank you for the explanation and the link. With it I was able to successfully select the adapter using the filtering out method, by configuring the VendorID and VendorImplID with MFXSetConfigFilterProperty. I will try the MFXCreateSession index "i" appoach as well once my card is back from RMA, but I expect that approach to work as well.

My mention of the issue with MFXEnumImplementations is specifically with the spec text in the link. It assumes it can only be an mfxImplDescription, while as you mention it is an opaque mfxHDL. I assumed it was wrong because it was outdated, but if you say it has always been an opaque mfxHDL, then it is just wrongly described.

gitcchi commented 1 year ago

@rupakroyintel Thanks, I can confirm the links work for me now. It was mainly for future users with the same problem reading this issue.