Files
Reims-Go/internal/host/host.go
T
NwflowerandClaude Opus 5.5 181ad64618 fix(display): mark HiDPI presets by reims-vgpu's own rule
Presets were flagged HiDPI by screen width alone, so a 2880x1800 preset
read "HiDPI" on a 100% screen where macOS runs it at 1x, and a VM left at
the 1920x1080 default ran 1x on a 200% screen.

- GuestStartsHiDPI follows upstream reims-vgpu 3731afd
  (RgfxDisplayIdentity.hpp, reims-vgpu-window features.md): HiDPI from a
  2048x1536 window above 160 ppi (150% scaling or more), or from
  3840x2160 at any scale.
- Presets are the 16:9 or 16:10 sizes that fit the screen's work area
  below a title bar, largest four; the largest HiDPI one is recommended.
  The display probe now reports the work area.
- When no preset is HiDPI, the resolution row says how to get there:
  borderless full screen, 150% Windows scaling, or not on this screen.

On this host (3072x1920 at 200%) the presets are 2560x1600 (HiDPI,
recommended), 1920x1200, 1680x1050 and 1280x800.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 23:48:52 -07:00

121 lines
4.5 KiB
Go

package host
import "strings"
type GPUKind string
const (
GPUDiscrete GPUKind = "discrete"
GPUIntegrated GPUKind = "integrated"
GPUVirtual GPUKind = "virtual"
GPUUnknown GPUKind = "unknown"
)
type GPUInfo struct {
Name string `json:"name"`
VulkanICD string `json:"vulkan_icd"`
Kind GPUKind `json:"kind"`
}
type WHPXState string
const (
WHPXReady WHPXState = "ready"
WHPXNoHypervisor WHPXState = "no_hypervisor"
WHPXMissing WHPXState = "missing"
WHPXUnsupported WHPXState = "unsupported"
)
type WHPXCapabilities struct {
ModernOS bool `json:"modern_os"`
APICEmulation bool `json:"apic_emulation"`
KernelIrqchipAvailable bool `json:"kernel_irqchip_available"`
NestedVirtProperty bool `json:"nested_virt_property"`
NestedVirtProbeError string `json:"nested_virt_probe_error,omitempty"`
}
type Report struct {
OS string `json:"os"`
Arch string `json:"arch"`
LogicalCPUs int `json:"logical_cpus"`
PhysicalCores int `json:"physical_cores"`
HasHybridCores bool `json:"has_hybrid_cores"`
PCoreCount int `json:"p_core_count"`
ECoreCount int `json:"e_core_count"`
LPECoreCount int `json:"lpe_core_count,omitempty"`
PCoreMask uint64 `json:"p_core_mask"`
PCoreMaskHex string `json:"p_core_mask_hex"`
PCoreLogicalCPUs []int `json:"p_core_logical_cpus,omitempty"`
ECoreLogicalCPUs []int `json:"e_core_logical_cpus,omitempty"`
NonLPEMask uint64 `json:"non_lpe_mask,omitempty"`
NonLPEMaskHex string `json:"non_lpe_mask_hex,omitempty"`
NonLPELogicalCPUs []int `json:"non_lpe_logical_cpus,omitempty"`
TotalRAMGB float64 `json:"total_ram_gb"`
AvailRAMGB float64 `json:"avail_ram_gb"`
MemoryLoadPct int `json:"memory_load_pct"`
// Commit memory: QEMU commits all guest RAM at start (CreateFileMapping), so
// a VM needs its memory free in the commit charge, not just in physical RAM.
// Measured 2026-11-28: 14.7 GiB commit free with 17.3 GiB physical free, and a
// 16G guest failed ("Cannot set up guest memory"). portable-runtime-spec.md §5.1.
CommitAvailGB float64 `json:"commit_avail_gb"`
CommitLimitGB float64 `json:"commit_limit_gb"`
DataRoot string `json:"data_root"`
DataRootDriveType string `json:"data_root_drive_type,omitempty"`
FreeDiskGB float64 `json:"free_disk_gb"`
WHPX WHPXState `json:"whpx"`
WHPXCaps WHPXCapabilities `json:"whpx_caps"`
NeedsColdRebootWorkaround bool `json:"needs_cold_reboot_workaround"`
GPUs []GPUInfo `json:"gpus"`
RecommendedGPU *GPUInfo `json:"recommended_gpu,omitempty"`
Displays []DisplayInfo `json:"displays,omitempty"`
PrimaryDisplay *DisplayInfo `json:"primary_display,omitempty"`
RecommendedResolution string `json:"recommended_resolution,omitempty"`
DisplayPresets []DisplayPreset `json:"display_presets,omitempty"`
HiDPIAdvice string `json:"hidpi_advice,omitempty"` // how to reach HiDPI when no preset does (display.go)
Audio AudioInfo `json:"audio"`
}
// ClassifyGPU distinguishes discrete, integrated, and virtual display adapters.
func ClassifyGPU(name string) GPUKind {
low := strings.ToLower(name)
for _, v := range []string{"todesk", "gameviewer", "parsec", "virtual", "idd", "microsoft basic", "spacedesk"} {
if strings.Contains(low, v) {
return GPUVirtual
}
}
for _, d := range []string{"nvidia", "geforce", "rtx", "gtx", "quadro", "radeon rx", "radeon pro", "intel(r) arc"} {
if strings.Contains(low, d) {
return GPUDiscrete
}
}
for _, i := range []string{"intel(r) uhd", "intel(r) hd", "intel(r) iris", "radeon(tm) graphics"} {
if strings.Contains(low, i) {
return GPUIntegrated
}
}
return GPUUnknown
}
// PickRecommendedGPU selects the best Vulkan GPU (preferring discrete over integrated, skipping virtual).
func PickRecommendedGPU(gpus []GPUInfo) *GPUInfo {
for i := range gpus {
if gpus[i].Kind == GPUDiscrete && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
for i := range gpus {
if gpus[i].Kind == GPUIntegrated && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
for i := range gpus {
if gpus[i].Kind != GPUVirtual && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
return nil
}