-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add ForcedGpu option #206
Add ForcedGpu option #206
Conversation
Also did some refactoring to share validation logic across binaries
In these circumstances, there's no way for us to determine the right gpu ...so abort and prompt the user to explictly choose it... ...or to try the vulkan renderer
PR is finished and ready for review! Overview of functionality and changes:
|
It's actually unnecessary to check the card's vendor. Instead, just check for its driver. If it's nvidia, apply the... ...GLX workaround.
Now gpu works entirely around indexes
I just noticed this and it was really bothering me. It had to be fixed.
@apprehensions Remember when I said I wouldn't be making any more changes? sorry i lied lol I noticed this and felt an uncontrollable urge to fix it the code is now one line more polished |
@apprehensions Branch updated to 8b061c5 Will be making the requested adjustments soon |
Hopefully the last refactor of this code
Refactor around sysinfo is done. |
internal/config/cardpick.go
Outdated
func pickCard(opt string, env Environment, isVulkan bool) error { | ||
if opt == "" { //Default value for opt | ||
opt = "none" | ||
} | ||
|
||
var cIndex int | ||
var indexStr string | ||
|
||
prime := false | ||
|
||
switch opt { | ||
//Handle PRIME options | ||
case "integrated": | ||
cIndex = 0 | ||
prime = true | ||
case "prime-discrete": | ||
cIndex = 1 | ||
prime = true | ||
//Skip pickCard logic option | ||
case "none": | ||
return nil | ||
//Otherwise, interpret opt as a card index | ||
default: | ||
var err error | ||
cIndex, err = strconv.Atoi(opt) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if cIndex < 0 { | ||
return errors.New("card index cannot be negative") | ||
} | ||
|
||
indexStr = strconv.Itoa(cIndex) | ||
|
||
//PRIME Validation | ||
if prime { | ||
allowed, err := primeIsAllowed(isVulkan) | ||
if err != nil { | ||
return err | ||
} | ||
if !allowed { | ||
return nil | ||
} | ||
} | ||
|
||
if len(sysinfo.Cards) < cIndex+1 { | ||
return errors.New("gpu not found") | ||
} | ||
|
||
c := sysinfo.Cards[cIndex] | ||
|
||
env.SetIfUndefined("MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE", "1") | ||
env.SetIfUndefined("DRI_PRIME", indexStr) | ||
|
||
if strings.HasSuffix(c.Driver, "nvidia") { //Workaround for OpenGL in nvidia GPUs | ||
env.SetIfUndefined("__GLX_VENDOR_LIBRARY_NAME", "nvidia") | ||
} else { | ||
env.SetIfUndefined("__GLX_VENDOR_LIBRARY_NAME", "mesa") | ||
} | ||
|
||
log.Printf("Chose card %s (%s).", c.Path, indexStr) | ||
|
||
env.Setenv() | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
Co-authored-by: sewn <[email protected]> Signed-off-by: Jrelvas <[email protected]>
oops that has to be fixed |
Co-authored-by: sewn <[email protected]> Signed-off-by: Jrelvas <[email protected]>
Co-authored-by: sewn <[email protected]> Signed-off-by: Jrelvas <[email protected]>
9931d71
to
e97a9ba
Compare
Co-authored-by: sewn <[email protected]> Signed-off-by: Jrelvas <[email protected]>
Tested. Nothing appears to be broken! |
internal/config/cardpick.go
Outdated
b.Env.Set("__GLX_VENDOR_LIBRARY_NAME", "mesa") | ||
} | ||
|
||
b.Env.Setenv() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to setup
Awesome work and patience |
This PR adds two new options which improve the functionality of Vinegar for laptop users (and users with exotic 3+ graphics card machines). The actual env variables are abstracted away, making this work with the gpus of all three vendors.
Wine's vulkan implementation chooses the dgpu by default, but this isn't the case with its opengl implementation. This change makes opengl use the dgpu by default, matching vulkan's behavior. It also lets users disable prime much more easily, without needing to tinker with env variables which may vary depending on their hardware.
Mostly complete, but it still needs some code cleanup and to prevent launching if the user is using OpenGL and has more than two GPUs (there's no way for us or gl to know the right one, so the user must explictly define it.)