|
1 | 1 | # Prefer Discrete GPU |
2 | 2 |
|
3 | | -For laptops with multiple GPUs, its likely that applications won't launch using the discrete GPU on Windows, but rather than integrated GPU. This can lead to realtime applications like games under-performing by default. |
| 3 | +[](https://github.com/silbinarywolf/preferdiscretegpu/actions) |
| 4 | + |
| 5 | +**This is a CGo package. Unfortunately there is no way to enable this behaviour without CGo as of Go 1.14** |
| 6 | + |
| 7 | +For laptops with multiple GPUs, its likely that applications won't launch using the discrete GPU on Windows, but rather the integrated GPU. This can lead to real-time applications like games under-performing by default, which is not the ideal user experience. |
| 8 | + |
| 9 | +This library exports global variables for NVIDIA and AMD drivers so that they use high performance graphics rendering settings. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +``` |
| 14 | +go get https://github.com/silbinarywolf/preferdiscretegpu |
| 15 | +``` |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +* Golang 1.12+ |
| 20 | + |
| 21 | +## How to use |
| 22 | + |
| 23 | +Just import the package for side-effects. This will have no additional behaviour on non-Windows systems. |
| 24 | + |
| 25 | +```go |
| 26 | +package main |
| 27 | + |
| 28 | +import ( |
| 29 | + "fmt" |
| 30 | + |
| 31 | + _ "github.com/silbinarywolf/preferdiscretegpu" |
| 32 | +) |
| 33 | + |
| 34 | +func main() { |
| 35 | + // your code here |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## How to test if this package is working |
| 40 | + |
| 41 | +1) Open up the Windows Command Line (not Powershell) and run the following: |
| 42 | + |
| 43 | +**NOTE: if you have have an older or newer version of Visual Studio installed, vcvarsall.bat will be in a different folder** |
| 44 | +``` |
| 45 | +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" |
| 46 | +``` |
| 47 | + |
| 48 | +2) Build the test application that consumes this library |
| 49 | +``` |
| 50 | +go build -v -o testapp.exe ./testapp |
| 51 | +``` |
| 52 | + |
| 53 | +3) Run dumpbin on it: |
| 54 | +``` |
| 55 | +dumpbin /exports testapp.exe |
| 56 | +``` |
| 57 | + |
| 58 | +4) It should give you an output mentioning the NVIDIA/AMD constants, like so: |
| 59 | +``` |
| 60 | +Microsoft (R) COFF/PE Dumper Version 14.00.24213.1 |
| 61 | +Copyright (C) Microsoft Corporation. All rights reserved. |
| 62 | +
|
| 63 | +
|
| 64 | +Dump of file testapp.exe |
| 65 | +
|
| 66 | +File Type: EXECUTABLE IMAGE |
| 67 | +
|
| 68 | + Section contains the following exports for a.out.exe |
| 69 | +
|
| 70 | + 00000000 characteristics |
| 71 | + 5F153BFB time date stamp Mon Jul 20 16:38:51 2020 |
| 72 | + 0.00 version |
| 73 | + 1 ordinal base |
| 74 | + 2 number of functions |
| 75 | + 2 number of names |
| 76 | +
|
| 77 | + ordinal hint RVA name |
| 78 | +
|
| 79 | + 1 0 000B6C00 AmdPowerXpressRequestHighPerformance |
| 80 | + 2 1 000B6C04 NvOptimusEnablement |
| 81 | +
|
| 82 | + Summary |
| 83 | +
|
| 84 | + 1000 .CRT |
| 85 | + 30000 .bss |
| 86 | + 15000 .data |
| 87 | + 1000 .debug_abbrev |
| 88 | + 1000 .debug_aranges |
| 89 | + 14000 .debug_frame |
| 90 | + 1000 .debug_gdb_scripts |
| 91 | + 82000 .debug_info |
| 92 | + 35000 .debug_line |
| 93 | + 88000 .debug_loc |
| 94 | + 9000 .debug_pubnames |
| 95 | + E000 .debug_pubtypes |
| 96 | + 30000 .debug_ranges |
| 97 | + 1000 .debug_str |
| 98 | + 1000 .edata |
| 99 | + 1000 .idata |
| 100 | + 1000 .pdata |
| 101 | + C7000 .rdata |
| 102 | + A000 .reloc |
| 103 | + A1000 .text |
| 104 | + 1000 .tls |
| 105 | + 1000 .xdata |
| 106 | +``` |
| 107 | + |
| 108 | +## Credits |
| 109 | + |
| 110 | +* [Hakan Guleryuz](https://groups.google.com/forum/#!topic/golang-nuts/7OHZcXUegF0) for documenting how they were able to export the NVIDIA/AMD variables in Golang and for giving information |
| 111 | +* [SFML Contributors](https://github.com/SFML/SFML/commit/9a453ed9e3846e9f7998295b8966428a9a0b86f6#diff-93134bfcdd8e19cbd5fe05a57a658950R63) for inspiring how this feature should be consumed (ie. opt-in imported package) |
0 commit comments