[Mesa-dev] [GSOC] DriConf Replacement

Nicolai Hähnle nhaehnle at gmail.com
Mon Jan 22 12:32:46 UTC 2018


Hi Jean,

thanks for the interest :)

On 17.01.2018 21:50, Jean Hertel wrote:
> Hello Michel,
> Hello Nicolai,
> 
> I have spent some more time reading the Mesa source code and trying to figure out how the prime configuration works.
> If i understood correctly the driconf XML format should have an option inside each application indicating if PRIME should be used. This option is named "device_id" and defines the device which this application should run.

Yes. The format is implicitly defined by loader_get_user_preferred_fd in 
src/loader/loader.c:

1: Just pick any render device which is non-default
pci-XXXX_XX_XX_X: The device given by its PCI bus address


> So when Mesa loads the configuration, if the application has the "device_id" it will run under this driver. Am I correct?
> If this is the case, then to correctly support PRIME the expected behavior of the configuration GUI should be:
> 1 - Find out if this is a PRIME setup
> 2 - If its PRIME, give the user an option to select on which device this application should run.
> 
> Some more questions that I still have to understand:
> - How do we detect at user-land that we are under a PRIME setup?

First of all, I'd say the best way to enumerate devices is to use 
libdrm's drmGetDevices2. Roughly speaking, you have a PRIME setup if you 
have at least two devices.

This function fills in data structures that include the pci bus info 
required to build the pci-XXXX_* string above.


> - I suppose there is some way to query the device_id directly from Mesa (maybe using Xlib). Any idea which API can be called for this?

I take it the real question here on top of the above is, how do you find 
out which device is being used by default?

Assuming you're working under X, you can use the GLX_MESA_query_renderer 
extension to query the PCI vendor and device ID, and then search for 
those in the device list returned by drmGetDevices2. This will work for 
all PRIME laptops.

Where this fails is if somebody builds a system with two identical GPUs. 
I admit I can't think of an overly easy solution to this right now. What 
you could do is go to the level of libxcb-dri3 and basically copy what 
loader_dri3_open does to open the DRM fd. With that in hand, you can 
then use drmGetDevice2 to get the the details you need. I have to say 
I'm not entirely sure whether that will work if the UI toolkit has 
already loaded OpenGL.

Neither of these work with native Wayland -- you can either rely on 
Xwayland or ask somebody who knows more about Wayland :)

If none of this works, we could always consider adding an OpenGL 
extension to return the relevant information. It *is* a bit silly that 
you can have an OpenGL context in your hand and not be able to tell 
which device it lives on...


> - Having the device_id, how can I get additional data for this device (for example the vendor name and the full hardware description). I assume there is already an API that makes this possible, as the actual driconf is capable of identifying the hardware correctly.

Maybe look at what the existing driconf does? :)

More seriously though, here are some ways to get more information:

- Query the PCI IDs database; on Ubuntu that's part of the pciutils 
package. I don't know what the distro-portable way to do that is though.

- Create an OpenGL context on the device, by opening the DRM device file 
directly and then using libgbm + EGL with the GBM platform. From there 
you can query stuff like OpenGL version, extensions, and obviously the 
driver's vendor and renderer strings.


> Sorry If I'm making too much questions, but I'm really interested in understand how this work.

Not at all, happy to help :)

Cheers,
Nicolai

P.S.: I tried to build your tool, but it needs some fairly recent 
versions of a bunch of dependencies. I'll give it a shot again after 
updating my systems.


> 
> Kind Regards,
> Jean Hertel
> 
> 
> De: Jean Hertel <jean.hertel at hotmail.com>
> Enviado: domingo, 7 de janeiro de 2018 20:10
> Para: Michel Dänzer; Nicolai Hähnle
> Cc: mesa-dev at lists.freedesktop.org
> Assunto: Re: [Mesa-dev] [GSOC] DriConf Replacement
>    
> 
> Hello Michael,
> 
> Finally I found some free time to spent on this.
> Can you please give me a small example on how I can get the device_ids ?
> 
> Currently to retrieve the available driver options I'm doing something like this:
> 
> 1 - Count the number of screens using "ScreenCount" function from Xlib.
> 2 - For each screen retrieve the driver name with "glXGetScreenDriver".
> 3 - For each driver retrieve the available options with "glXGetDriverConfig".
> 
> Please note that my knowledge about openGL, x11 and mesa is almost zero, so if you have any documentation that I can read it would be nice too.
> 
> Kind Regards,
> Jean Hertel
> 
> ---------
> On 10/04/17 06:02 AM, Michel Dänzer wrote:
>    
>> On 05/04/17 05:26 PM, Nicolai Hähnle wrote:
>>> On 04.04.2017 01:52, Jean Hertel wrote:
>>>
>>> 2c) Consider adding an option to configure PRIME to driconf.
>>>
>>> [2b and 2c will also require changes in Mesa; also, you may want to get
>>> rid of the implicit dependency on xdriinfo]
>>
>> FWIW, Mesa already supports 2c) with DRI3, via the device_id option.
>>
>>
>      
> 


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list