diff --git a/config/cardpick.go b/config/cardpick.go index 33124291..c2aeaf21 100644 --- a/config/cardpick.go +++ b/config/cardpick.go @@ -38,16 +38,15 @@ func (b *Binary) pickCard() error { idx = i } - // Check if the system actually has PRIME offload and there's no ambiguity with the GPUs. if prime { vk := b.Dxvk || b.Renderer == "Vulkan" - if n != 2 && (!vk && n != 1) { - return ErrOpenGLBlind + if n <= 1 { + return nil } - if n != 2 { - return nil + if n > 2 && !vk { + return ErrOpenGLBlind } if !sysinfo.Cards[0].Embedded { diff --git a/config/cardpick_test.go b/config/cardpick_test.go index 812b8737..6ac10ab5 100644 --- a/config/cardpick_test.go +++ b/config/cardpick_test.go @@ -8,11 +8,11 @@ import ( ) func TestCard(t *testing.T) { - sysinfo.Cards = []sysinfo.Card{} b := Binary{ ForcedGpu: "meow", Env: Environment{}, } + sysinfo.Cards = []sysinfo.Card{} if err := b.pickCard(); !errors.Is(err, strconv.ErrSyntax) { t.Fatal("expected to not handle string gpu") @@ -29,7 +29,7 @@ func TestCard(t *testing.T) { } } -func TestPRIMECard(t *testing.T) { +func TestIntegratedCard(t *testing.T) { b := Binary{ ForcedGpu: "integrated", Env: Environment{}, @@ -39,45 +39,76 @@ func TestPRIMECard(t *testing.T) { Driver: "i915", Embedded: true, }, + { + Driver: "nvidia", + Embedded: false, + }, } if err := b.pickCard(); err != nil { t.Fatal(err) } - if _, ok := b.Env["DRI_PRIME"]; ok { - t.Fatal("expected no change") - } - - sysinfo.Cards = append(sysinfo.Cards, sysinfo.Card{ - Driver: "nvidia", - Embedded: false, - }) - - if err := b.pickCard(); err != nil { - t.Fatal(err) - } - if v := b.Env["DRI_PRIME"]; v != "0" { - t.Fatal("expected change in prime index") + t.Fatal("expected change in integrated prime index") } if v := b.Env["__GLX_VENDOR_LIBRARY_NAME"]; v != "mesa" { t.Fatal("expected glx vendor to be mesa") } +} + +func TestDiscreteCard(t *testing.T) { + b := Binary{ + ForcedGpu: "prime-discrete", + Env: Environment{}, + } + sysinfo.Cards = []sysinfo.Card{ + { + Driver: "i915", + Embedded: true, + }, + { + Driver: "nvidia", + Embedded: false, + }, + } - b.ForcedGpu = "prime-discrete" - delete(b.Env, "DRI_PRIME") - delete(b.Env, "__GLX_VENDOR_LIBRARY_NAME") if err := b.pickCard(); err != nil { t.Fatal(err) } if v := b.Env["DRI_PRIME"]; v != "1" { - t.Fatal("expected change in descrete index") + t.Fatal("expected change in discrete prime index") } if v := b.Env["__GLX_VENDOR_LIBRARY_NAME"]; v != "nvidia" { t.Fatal("expected glx vendor to be nvidia") } -} \ No newline at end of file +} + +func TestVulkanCard(t *testing.T) { + b := Binary{ + ForcedGpu: "prime-discrete", + Renderer: "OpenGL", + Env: Environment{}, + } + sysinfo.Cards = []sysinfo.Card{ + { + Driver: "i915", + Embedded: true, + }, + { + Driver: "nvidia", + Embedded: false, + }, + { + Driver: "radeon", + Embedded: false, + }, + } + + if err := b.pickCard(); !errors.Is(err, ErrOpenGLBlind) { + t.Fatal("expected handle opengl skill issue") + } +}