NVidia Optimus on newer notebooks

Discussion in 'Mac and Linux' started by DeathByDenim, July 3, 2013.

  1. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,326
    Likes Received:
    2,118
    I recently bought a new laptop and it comes with the NVidia Optimus technology, which means that you get an energy efficient graphics card for normal use (Intel HD4000) and a dedicated NVidia card for graphic intensive use (GT650M in my case). Obviously, I would like to use the NVidia card with PA.

    In Linux one can use Bumblebee to switch between the two cards. Prepending any command with "optirun" will result in the NVidia card being used. For example
    Code:
    glxspheres
    Will run glxspheres on the HD4000 and give me 60 fps. On the other hand
    Code:
    optirun glxspheres
    will give me roughly 160 fps.
    I've purchased nearly all of the Humble Bundle games and it works great with all of the games I've tried so far.

    However, when I try to run PA using optirun, I get this error:
    Code:
    X Error of failed request:  GLXUnsupportedPrivateRequest
      Major opcode of failed request:  153 (GLX)
      Minor opcode of failed request:  16 (X_GLXVendorPrivate)
      Serial number of failed request:  37
      Current serial number in output stream:  37
    This is using the NVidia version 313 drivers that come with Kubuntu 13.04. I've reported it as a bug on the bug tracker, but I'm wondering if this could be solved by manually installing the latest NVidia drivers (319.32). It's usually quite a hassle to get them working (although I haven't done it in a while), so I was wondering if you think that might help.

    P.S. PA works fine with the HD4000 card for now.
  2. Junke1990

    Junke1990 New Member

    Messages:
    3
    Likes Received:
    0
    I'm having trouble launching the game on Linux too. My Laptop is a ASUS N53SV (i7 with GT540M 2GB edition) (upgraded) with an SSD and 16gb RAM.

    I usually run games with steam by running "primusrun steam" which should work fine but not in this case. When I try that all I get is a black screen with (space?) sound. It does work when I do not run steam with optirun or primus(run) but the gameplay will be slow, 12fps on avarage but playable! (takes very long to load and may appear to be stuck, be patient).

    I've connected my steam account to UberEnt loged on to http://uberent.com/Launcher/ShowPADownloads to download the game to be able to run it outside of steam.

    If I run it without optimus (./PA) it does run with about the same results as with steam. If I run it with optirun (optirun ./PA) it will crash immediately. If I try running it with primus (primusrun ./PA) it wil results in just a black screen and some sound, same as run from steam with primusrun.

    Hope you guys will be able to fix this so I can enjoy the game with more than 12fps :)
  3. Nepenthes

    Nepenthes New Member

    Messages:
    7
    Likes Received:
    0
    Same here. I use primusrun to get games running, but just a black screen with some sound in PA.

    Here is the github page of project primus : https://github.com/amonakov/primus

    If PA team needs help to get logs, I can run the the game in APItrace.


    @junke1990 : you can put primusrun to a better use by not launching steam directly with primusrun, and instead modifying your games "command line options" (right click on a game -> properties) and entering :
    Code:
    primusrun %command%
    That way, you will be able to keep your pc cooler and more silent while having steam open (but no game running). The nvidia card will be active only when Steam actually launches a game.
  4. Junke1990

    Junke1990 New Member

    Messages:
    3
    Likes Received:
    0
    @nepenthes Thanks! I was just glad my games would run but that's even better!
  5. liamdawe

    liamdawe Active Member

    Messages:
    349
    Likes Received:
    61
    I would also go for Primus when I had my last laptop (switched to desktop far less hassle for Linux!) it did give a decent performance boost.

    Do you have any BIOS option to switch it to use only the dedicated graphics? That would help you even further, especially as optirun and Primus are both still quite rough.
  6. Junke1990

    Junke1990 New Member

    Messages:
    3
    Likes Received:
    0
    I don't, unfortunately most notebooks don't...
  7. mike545

    mike545 New Member

    Messages:
    5
    Likes Received:
    0
  8. SXX

    SXX Post Master General

    Messages:
    6,897
    Likes Received:
    1,811
    I'm don't have hardware with optimus, but just in case: are you sure that Coherent_Host started on right videocard?

    I asking because you poster about black screen on Nvidia videocard and actually game UI rendered in dedicated process which easily can start on Intel card.
  9. Nepenthes

    Nepenthes New Member

    Messages:
    7
    Likes Received:
    0
    VirtualGL and Primus (both being Bumblebee backends, VGL being the most stable one, and Primus being the best performance wise) are supposed to support forking well. I'm not saying it's perfect yet, but most weird forking behavior cases have been covered in the past, and all the process GL calls are supposed to be forwarded to the right GPU.

    Here is the log, showing the game is running on nvidia :
    http://pastebin.com/5UqevJfH
  10. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    I'd love to see this get worked out as well.

    primusrun just results in a black screen as listed above.

    I didn't look at my frame rate, but it wasn't super awesome.

    Also, I was running top on my machine, and it looks like only one core is really getting used. My other 3 cores seemed to be idle.
  11. SXX

    SXX Post Master General

    Messages:
    6,897
    Likes Received:
    1,811
    PA only use CPU for planet generation (it's can use all you cores). Everything else simulated on Uber servers, so game doesn't use CPU that much compared to any other RTS.
  12. mike545

    mike545 New Member

    Messages:
    5
    Likes Received:
    0
    The log also say for me that I am running on nvidia (when the screen is black).
  13. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    I hope our good developer friends don't let this bit of research of mine go to waste.

    I'm birthing a kidney stone at the moment, and I devoted my suffering time to try to test/research more info on this issue.

    So, I imagine there's some other black magic going on with primusrun, but what I've read today was that primusrun effectively calls:
    sudo tee /proc/acpi/bbswitch <<<ON # when you start an app, and ...
    sudo too /proc/acpi/bbswitch <<<OFF # when that app dies

    So, I went through my steam set up, and dropped my config changes for hl2 and primusrun.

    Then, I went in and:
    sudo tee /proc/acpi/bbswitch <<<ON
    sudo /etc/init.d/lightdm restart

    After logging back in, I brought up steam and launched hl2. It worked, no problems.

    When I kicked off PA, though, it logs that it's using my intel card and not the nvidia card.

    cat /proc/acpi/bbswitch still reported as ON, though.

    So, my guess is there's some kind of weirdness where when your run:
    primusrun /home/..../PA
    ... that PA actually gets configured to run on the nvidia card. But the forked process (ContentHostUI or whatever) loses whatever happened at the execution runtime to make that happen.

    I'll post this over in the ticket as well.
  14. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    Kidney Stone is still being a pain. Le sigh.

    I had a thought this morning, given that hl2 was acting was my baseline.

    I know when I first loaded hl2 on my laptop, I needed to use primusrun, but I hadn't confirmed that was still the case.

    So, this morning, I made sure /proc/acpi/bbswitch was OFF, and I launched hl2 without primusrun.

    To my surprise, it worked just fine. Great frame rate, smooth as silk. I switched over to the terminal to make sure /proc/acpi/bbswitch was still OFF, and it was.

    So, I don't know if hl2 has a one-time, up-front benefit from running with primusrun - or if there has been an update to hl2 that is linux-optimus sensitive.

    But I figured I'd throw that bit of extra data into the ring.
  15. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    Alrighty - I'd love to get a dev to lemme know they're seeing this.

    Anyhow, I made some progress tonight analyzing what's going on.

    Best I can tell, all of our in-game overlays and the whole nav/settings/menu system is using this same overlay architecture. It is these overlays, I think, that are the source of all problems for optimus users.

    Just to be sure it wasn't driver issue related, I went ahead and switched over to kmod:nvidia_experimental_310 via jockey-text

    Then to double check myself, I took a look at my nvidia settings: primusrun nvidia-setting -c :8

    I'm running's nvidia's 310.14 driver. Best as I can tell, that's as good as it gets for 12.10

    Then I started analyzing the runtime characeteristics of the game. So, there's PA, which spawns the ContentUI_Host. ContentUI_Host, on linux, is a script which exec's ContentUI_Host.bin. I'm pretty sure that these guys drive the menuing/overlay architecture.

    So, I switched the exec to be primusrun - didn't make a change. That made me really sad.

    But I was convinced that primusrun was doing what it needed to do, so I kept dabbling.

    I basically started to started PA without primus, memorized where on the screen I was clicking and typing. Listened for the audio cues that said where I was needed to click. And then I attempted to fly blind.

    You know what? It worked!

    I can actually get into the game by going through the motions. But none of the menus or overlays render (they're there, they respond to mouse events, but you just can't see them). The 3-D world, though, renders. You just never get to see it unless you are generating/editing a world or actually playing a game.

    Another thing - when running with primusrun, we have to disable vblank synchronisation. Otherwise it seems as though game performance gets locked into 60 FPS and below. To do this, you run with vblank_mode=0 primusrun [command]

    Running with primusrun felt like it was making a pretty significant difference, though it's hard to tell - I get 40 - 60 FPS in the early game just with raw processor power. Both of my primusrun tests though landed me on a small moon, and my FPS never went under 60. I doubt I generated much more than 100 units, and the AI went dumb on me both times.

    So fix the overlay stuff uber guys - it's the culprit for us optimus guys running linux.
  16. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    @ssx mentioned in another thread that the CoherenUI_Host is really just a rehosted Chromium.

    I did some research into primusrun and chromium working together - figured folks trying some WebGL would probably be seeing some problems without.

    Found this:

    Basically, in order to get WebGL working, people had to run chromium as so:

    primusrun chromium --enable-webgl --ignore-gpu-blacklist

    I still think vblank_mode=0 (that's a zero) should probably be up at the front.

    I'll keep researching, I guess. 20 FPS is kinda beastly.
  17. SXX

    SXX Post Master General

    Messages:
    6,897
    Likes Received:
    1,811
    That won't work for Coherent because Coherent is always hardware accelerated. E.g if hardware acceleration not available you'll get black screen. With "--disable-gpu" flag coherent just wont work at all.

    I'm tried many Chromium flags when I tried to fix cursor flickering.


    I doubt you'll ever get any Coherent output without VSync, at least it's like that for AMD cards.
  18. sechastain

    sechastain Member

    Messages:
    84
    Likes Received:
    22
    That's the thing - in optimus environments, simply running primusrun chromium does not result in chromium running with the gpu. Folks are having to pass these extra command line parameters to get it to work. My guess is something similar is afflicting us here.

    We need to get you an optimus machine then, so you can try many more ;)

    vblank and vsync are different. I'm not really clear on the difference because I don't have to be at the moment - I just know they're different. Wikipedia says so :)
  19. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,326
    Likes Received:
    2,118
    Where do you put those flags? I tried to use them with the PA executable, but that one wouldn't take it. I even looked at the binary with a hex editor and found some more flags than are displayed with --help, but nothing with webgl and the like. I also tried editing the host/CoherentUI_Host script and put the flags there, but it wouldn't even take --help.
  20. SXX

    SXX Post Master General

    Messages:
    6,897
    Likes Received:
    1,811
    Probably you put them in wrong place.
    I'll check it later and post back, because I checked it few versions ago.

Share This Page