1//go:build linux
2
3package vkdevice
4
5import (
6 "github.com/bnema/wlturbo/protocol/linuxdmabuf"
7 "golang.org/x/sys/unix"
8 "os"
9 "testing"
10)
11
12func TestModifierIntersection(t *testing.T) {
13 tranches := [][]linuxdmabuf.FormatEntry{{{Format: XRGB8888, Modifier: 11}, {Format: ARGB8888, Modifier: 22}}, {{Format: XRGB8888, Modifier: 33}, {Format: ARGB8888, Modifier: 44}}}
14 for _, tc := range []struct {
15 alpha bool
16 available map[uint64]bool
17 want uint64
18 }{
19 {false, map[uint64]bool{11: true, 33: true}, 11},
20 {false, map[uint64]bool{33: true}, 33},
21 {true, map[uint64]bool{11: true, 22: true, 44: true}, 22},
22 {true, map[uint64]bool{11: true, 44: true}, 44},
23 } {
24 got, err := ChooseModifier(tranches, tc.alpha, tc.available)
25 if err != nil || got.Value != tc.want {
26 t.Fatalf("alpha=%v want=%d got=%+v err=%v", tc.alpha, tc.want, got, err)
27 }
28 }
29 if _, err := ChooseModifier(tranches, true, map[uint64]bool{11: true, 33: true}); err == nil {
30 t.Fatal("transparent accepted XRGB")
31 }
32}
33
34func TestExportableModifiersHardware(t *testing.T) {
35 path := os.Getenv("NEFERGUI_RENDER_NODE")
36 if path == "" {
37 t.Skip("set NEFERGUI_RENDER_NODE to matching DRM render node")
38 }
39 var stat unix.Stat_t
40 if err := unix.Stat(path, &stat); err != nil {
41 t.Fatal(err)
42 }
43 d, err := Open(DeviceIdentity(uint64(stat.Rdev)))
44 if err != nil {
45 t.Fatal(err)
46 }
47 defer d.Close()
48 mods, err := d.ExportableModifiers()
49 if err != nil {
50 t.Fatal(err)
51 }
52 if len(mods) == 0 {
53 t.Fatal("matched Vulkan device has no one-plane exportable B8G8R8A8 color+readback modifiers")
54 }
55 for mod := range mods {
56 t.Logf("render node %s exportable DRM modifier %#x", path, mod)
57 }
58}