~emersion/go-drm

ref: 2fc5fd8f18101b1e924cb6082803ac1f7f84614a go-drm/fourcc.go -rw-r--r-- 1.3 KiB
2fc5fd8fSimon Ser Parse NVIDIA modifiers a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package drm

//go:generate ./fourcc.py

import (
	"fmt"
	"strings"
)

type Format uint32

func (f Format) Name() string {
	if name := f.str(); name != "" {
		return name
	}
	return "unknown"
}

func (f Format) String() string {
	return fmt.Sprintf("%s (0x%X)", f.Name(), uint32(f))
}

type ModifierVendor uint8

func (vendor ModifierVendor) String() string {
	if name := vendor.str(); name != "" {
		return name
	}
	return "unknown"
}

type Modifier uint64

func (mod Modifier) Vendor() ModifierVendor {
	return ModifierVendor(mod >> 56)
}

func (mod Modifier) Name() string {
	var name string
	switch mod.Vendor() {
	case ModifierVendorNVIDIA:
		name = modifierNameNVIDIA(uint64(mod))
	}
	if name != "" {
		return name
	}

	if name := mod.str(); name != "" {
		return name
	}
	if vendor := mod.Vendor().str(); vendor != "" {
		return fmt.Sprintf("%s(unknown)", strings.ToUpper(vendor))
	}
	return "unknown"
}

func (mod Modifier) String() string {
	return fmt.Sprintf("%s (0x%X)", mod.Name(), uint64(mod))
}

func modifierNameNVIDIA(mod uint64) string {
	if mod & 0x10 == 0 {
		return ""
	}

	h := mod & 0xF
	k := (mod >> 12) & 0xFF
	g := (mod >> 20) & 0x3
	s := (mod >> 22) & 0x1
	c := (mod >> 23) & 0x7

	return fmt.Sprintf("NVIDIA_BLOCK_LINEAR_2D(h=%v, k=%v, g=%v, s=%v, c=%v)", h, k, g, s, c)
}