-
Notifications
You must be signed in to change notification settings - Fork 7
/
hardware.go
76 lines (60 loc) · 1.96 KB
/
hardware.go
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
74
75
76
package main
import (
"fmt"
"github.com/jaypipes/ghw"
"strings"
)
func searchHardwareAcceleration() {
nvidia := false
amd := false
intel := false
gpus, err := ghw.GPU()
if err != nil {
handleSoftError("Getting GPU info error", err.Error())
return
}
logMessage(fmt.Sprintf("Detected GPUs (%d): ", len(gpus.GraphicsCards)), false)
for index, gpu := range gpus.GraphicsCards {
vendor := strings.ToLower(gpu.DeviceInfo.Vendor.Name)
logDebug(fmt.Sprintf("GPU ID: %d, Vendor: %s", index, vendor), false)
if strings.Contains(vendor, "nvidia") {
nvidia = true
} else if strings.Contains(vendor, "amd") || strings.Contains(vendor, "advanced micro devices") {
amd = true
} else if strings.Contains(vendor, "intel") {
intel = true
}
logMessage(fmt.Sprintf(" %d. %s", index+1, gpu.DeviceInfo.Product.Name), false)
}
if (nvidia && intel) || (amd && intel) {
intel = false
logDebug("Ignoring Intel iGPU, detected NVIDIA/AMD dGPU)", false)
}
if nvidia && amd { // AMD is iGPU
amd = false
logDebug("Ignoring AMD iGPU, detected NVIDIA dGPU", false)
}
if nvidia {
hwaccelParams = append(hwaccelParams, "-hwaccel_device", "cuda", "-hwaccel_output_format", "cuda")
addEncoders("nvidia")
logMessage("Available GPU acceleration: CUDA + NVENC", false)
} else if amd {
hwaccelParams = append(hwaccelParams, "-hwaccel_device", "opencl")
addEncoders("advanced micro devices")
logMessage("Available GPU acceleration: AMF", false)
} else if intel {
settings.CompatibilityMode = true
addEncoders("cpu")
logMessage("Intel GPUs are not supported - application may not work correctly", false)
} else {
settings.CompatibilityMode = true
addEncoders("cpu")
logMessage("There's no available GPU acceleration, application may not work correctly! Please verify your GPU drivers or report bug on GitHub", false)
}
for index, encoder := range availableEncoders {
if encoder.Vendor != "cpu" {
settings.Encoder = int32(index)
break
}
}
}