Docs / Capabilities

Glossary: GpuPreferences

The members of GpuPreferences, in alphabetical order.

Color legend plain property method

The per-app graphics preference of Windows, read and set as Settings does it: for the current user, kept by the app’s exe.

A static class, in the namespace BorrowedTorch.Capabilities. The preference picks the video card Windows makes an app’s Direct3D devices on when the app names none, so a game whose renderer names none picks its card by setting its own, and draws with it from its next start. VideoCard.ReachedBy tells which preference reaches a card. The picking the video card page shows it in context, with code.

Windows keeps the preferences in HKEY_CURRENT_USER\Software\Microsoft\DirectX\UserGpuPreferences, as a text value named by the exe’s full path holding GpuPreference=2; among whatever else Windows keeps for the app (AppStatus=0;), which the methods leave as it is. Windows 11’s “specific GPU” choice isn’t read or written.

Names are colored by what they are: a property or a method; values and fields keep the plain color.

Properties

CanSetForCurrentProcess →

bool · Static, read-only. Whether a preference can be set for the current process, the exe it runs (Environment.ProcessPath): false for an app started as dotnet App.dll, whose process is dotnet’s own and whose preference would hold for every app started that way, and for a process with no exe path.

Methods

Get(string) →

Get(string executablePath = null) · Static. Returns the preference set for an exe, the current process’s when no path is given; null when none is set, which works as GpuPreference.WindowsDecides, and for a setting whose preference isn’t one of the three. A relative path is made full from the current directory.

Parameter Type Description
executablePath string The exe’s path, or null for the current process’s exe.

Remove(string) →

Remove(string executablePath = null) · Static. Takes the preference set for an exe away, the current process’s when no path is given, as if none had ever been set: the GpuPreference pair is taken out of the value, and the value is deleted when nothing else is left in it. Returns false when no preference was set. Throws as Set does.

Parameter Type Description
executablePath string The exe’s path, or null for the current process’s exe.

Set(GpuPreference, string) →

Set(GpuPreference preference, string executablePath = null) · Static. Sets the preference for an exe, the current process’s when no path is given: GpuPreference=n; is written last in the value, in place of any it had, and the rest is kept. It shows from the app’s next start. Throws an ArgumentOutOfRangeException for a preference that isn’t one of the three; an InvalidOperationException without a path when CanSetForCurrentProcess is false; and what the registry throws when it can’t be written: an UnauthorizedAccessException, a SecurityException or an IOException.

Parameter Type Description
preference GpuPreference The preference to set.
executablePath string The exe’s path, or null for the current process’s exe.