Class WindowsDxgi

java.lang.Object
oshi.jna.platform.windows.WindowsDxgi

public final class WindowsDxgi extends Object
Minimal JNA binding to dxgi.dll for enumerating display adapters and reading DXGI_ADAPTER_DESC.DedicatedVideoMemory.

DXGI is the authoritative Windows API for dedicated GPU memory. It is not subject to the 2 GiB cap that affects the 32-bit registry value HardwareInformation.MemorySize.

COM vtable layout used here:

IUnknown   (vtable slots 0-2):  QueryInterface, AddRef, Release
IDXGIObject (slots 3-6):        SetPrivateData, SetPrivateDataInterface, GetPrivateData, GetParent
IDXGIFactory (slots 7-13):      EnumAdapters, MakeWindowAssociation, GetWindowAssociation,
                                 CreateSwapChain, CreateSoftwareAdapter, (IDXGIFactory1 adds 2 more)
IDXGIAdapter (slots 3-5 on adapter): EnumOutputs, GetDesc, CheckInterfaceSupport

This class should be considered non-API as it may be removed if/when its code is incorporated into the JNA project.

  • Method Details

    • queryAdapters

      public static List<DxgiAdapterInfo> queryAdapters()
      Enumerates all DXGI display adapters and returns their identity and dedicated video memory.

      Fails gracefully: if dxgi.dll is unavailable or any COM call fails, returns an empty list so callers can fall back to registry-based detection.

      Returns:
      list of DxgiAdapterInfo, one per adapter; empty if DXGI is unavailable
    • findMatch

      public static DxgiAdapterInfo findMatch(List<DxgiAdapterInfo> adapters, int vendorId, int deviceId, String adapterName)
      Finds the best-matching DXGI adapter for a given vendor ID, device ID, and adapter name.

      Matching priority:

      1. Vendor ID + Device ID (exact, both non-zero)
      2. Normalized name match (case-insensitive, ignoring (R), (TM), extra spaces)

      If multiple adapters share the same vendor+device ID (e.g. multi-GPU), the first one is returned. If no confident match is found, returns null.

      Parameters:
      adapters - list from queryAdapters()
      vendorId - PCI vendor ID parsed from the registry key (0 if unknown)
      deviceId - PCI device ID parsed from the registry key (0 if unknown)
      adapterName - adapter name from the registry DriverDesc value
      Returns:
      best-matching adapter, or null
    • registryValueToVram

      public static long registryValueToVram(Object value)
      Converts a registry value (REG_QWORD as Long, REG_DWORD as Integer, or REG_BINARY as byte[]) to a VRAM size in bytes. REG_BINARY is interpreted as little-endian.

      Exposed as public for testing.

      Parameters:
      value - the registry value object
      Returns:
      the VRAM size in bytes, or 0 if the value type is unrecognised
    • normalizeName

      public static String normalizeName(String name)
      Normalizes an adapter name for fuzzy matching: lower-case, strips (R)/(TM), collapses whitespace.
      Parameters:
      name - the raw adapter name, may be null
      Returns:
      normalized name, never null