Skip to content

Hoist the Windows graphics card WMI fallback into a common base - #3544

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:windows-graphicscard-dedup
Jul 29, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:windows-graphicscard-dedup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Item 9c of the cross-OS consistency audit, completing the GPU family after #3542 (NvmlUtil) and #3543 (macOS GpuStats).

What was duplicated

The two Windows GraphicsCard twins duplicated the four correlation fields, their constructor, and the whole Win32_VideoController enumeration used as a fallback when the display device registry keys yield nothing. Only which driver returns the rows actually differed.

What changed

New WindowsGraphicsCard in oshi-common holds luidPrefix, lhmParent, pciBusNumber and pciBusId with protected getters, plus a static buildFromWmi. It takes the WmiResult and a CardFactory rather than running the query itself, so each twin supplies only its driver call and its own card type — the factory pattern from #3452.

WindowsGraphicsCardJNA 474 → 383, WindowsGraphicsCardFFM 287 → 224.

Behavior changes, all adopting what JNA already did

  1. Fixed: the FFM WMI path lost the PDH LUID fallback. It called DxgiUtil.buildLuidPrefix directly, while FFM's own registry path and both of JNA's paths use the local buildLuidPrefix, which falls back to a PDH instance lookup when DXGI reports an empty LUID. A card enumerated through the WMI path with an empty DXGI LUID therefore got no PDH prefix on FFM, leaving its GPU Engine and Adapter Memory counters unfilterable and its metrics unavailable. FFM was inconsistent with itself here, not only with JNA.
  2. FFM gains JNA's pre-Vista gate on this path. VersionHelpersFFM already exists and is used by WindowsBluetoothDeviceFFM and WindowsOSProcessFFM, so its absence here looks like an omission. Pre-Vista with a modern JDK is not a real combination, so this is a consistency change rather than a functional one.
  3. The working DXGI list always starts fresh from dxgiAdapters, as JNA did; FFM previously passed in its registry path's partially consumed list. Only observable if that loop matched adapters and still returned nothing.

No CHANGELOG: the LUID fix only restores metrics on a fallback path that requires the registry enumeration to have produced nothing, and the other two are unobservable in practice.

Testing

New WindowsGraphicsCardTest (9 cases). WmiResult is an interface, so the enumeration is testable without Windows — worth having, because this path only runs when the registry enumeration returns nothing and is otherwise near-unreachable on real hardware. It covers ghost-device skipping, DXGI ordering beating WMI row order, an adapter being consumed by only the first matching row, the DXGI-VRAM-over-AdapterRAM preference, vendor and device ID derivation, blank fields falling back to UNKNOWN, and the PCI correlation fields being deliberately unset on this path.

Local gate green: spotless, checkstyle, install, forbiddenapis, javadoc, clean full-reactor build, 1407 tests. NativeComparisonTest 40/40 on macOS. Windows runtime validation is CI-only, which pr.yaml runs automatically.

Summary by CodeRabbit

  • New Features

    • Improved Windows graphics-card detection and identification.
    • Preserves primary-adapter ordering and provides more accurate dedicated video memory when available.
    • Adds better handling for adapter relationships and hardware identifiers.
  • Bug Fixes

    • Filters inactive or invalid graphics-card entries when reliable system data is available.
    • Adds fallback handling for systems without modern graphics adapter information.
    • Improves handling of missing or blank adapter details.

The two Windows GraphicsCard twins duplicated the four correlation
fields, their constructor, and the whole Win32_VideoController
enumeration used as a fallback when the display device registry keys
yield nothing. Only which driver returns the rows actually differed.

New WindowsGraphicsCard in oshi-common holds luidPrefix, lhmParent,
pciBusNumber and pciBusId with protected getters, plus a static
buildFromWmi. It takes the WmiResult and a CardFactory rather than
running the query itself, so each twin supplies only its driver call
and its own card type.

WindowsGraphicsCardJNA 474 -> 383, WindowsGraphicsCardFFM 287 -> 224.

Behavior changes, all adopting what JNA already did:

- FIXED: the FFM WMI path lost the PDH LUID fallback. It called
  DxgiUtil.buildLuidPrefix directly, while FFM's own registry path and
  both of JNA's paths use the local buildLuidPrefix, which falls back
  to a PDH instance lookup when DXGI reports an empty LUID. A card
  enumerated through the WMI path with an empty DXGI LUID therefore
  got no PDH prefix on FFM, leaving its GPU Engine and Adapter Memory
  counters unfilterable and its metrics unavailable. FFM was
  inconsistent with itself here, not only with JNA.
- FFM gains JNA's pre-Vista gate on this path. VersionHelpersFFM
  already exists and is used by WindowsBluetoothDeviceFFM and
  WindowsOSProcessFFM, so its absence here looks like an omission.
  Pre-Vista with a modern JDK is not a real combination, so this is a
  consistency change rather than a functional one.
- The working DXGI list always starts fresh from dxgiAdapters, as JNA
  did; FFM previously passed in its registry path's partially consumed
  list. Only observable if that loop matched adapters and still
  returned nothing.

No CHANGELOG: the LUID fix only restores metrics on a fallback path
that requires the registry enumeration to have produced nothing, and
the other two changes are unobservable in practice.

New WindowsGraphicsCardTest stubs WmiResult, which is an interface, so
the enumeration is testable without Windows. It covers ghost-device
skipping, DXGI ordering beating row order, an adapter being consumed by
only the first matching row, the DXGI-VRAM-over-AdapterRAM preference,
vendor and device ID derivation, blank fields falling back to UNKNOWN,
and the PCI correlation fields being deliberately unset on this path.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50564647-4396-42dd-ad22-8947abd81f14

📥 Commits

Reviewing files that changed from the base of the PR and between 954adaf and 65eb0a6.

📒 Files selected for processing (4)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGraphicsCard.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGraphicsCardTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGraphicsCard.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGraphicsCard.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGraphicsCard.java (2)

34-69: LGTM!

Also applies to: 71-126, 128-213


15-15: 🎯 Functional Correctness

No change needed for normalizeName.

DxgiUtilJNA.normalizeName delegates to osh driver.common.windows.gpu.DxgiUtil.normalizeName, so this WMI fallback uses the same normalization as the JNA registry path.

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java (1)

11-11: LGTM!

Also applies to: 25-51, 63-70, 157-169

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java (1)

8-8: LGTM!

Also applies to: 28-41, 70-70, 84-85, 100-105, 249-254

oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGraphicsCardTest.java (1)

38-203: LGTM!


📝 Walkthrough

Walkthrough

Introduces a shared Windows graphics-card base class and WMI builder, migrates JNA and FFM implementations to it, and adds tests covering DXGI matching, ordering, fallback VRAM, metadata, and parent mapping.

Changes

Windows graphics-card enumeration

Layer / File(s) Summary
Shared WMI builder and metadata contract
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGraphicsCard.java
Adds shared adapter correlation fields, accessors, a CardFactory contract, and WMI construction using optional DXGI matching, VRAM selection, ordering, and LHM parent mapping.
JNA and FFM backend adoption
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
Moves both implementations to WindowsGraphicsCard, uses inherited metadata accessors for statistics, and delegates WMI fallback enumeration to buildFromWmi(...).
Enumeration behavior tests
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsGraphicsCardTest.java
Adds stubbed WMI tests for DXGI matching, ghost-row filtering, ordering, VRAM fallback, metadata defaults, empty results, PCI fields, and LHM parent mapping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WindowsGraphicsCardJNA
  participant buildFromWmi
  participant WMI
  participant DXGI
  participant CardFactory
  WindowsGraphicsCardJNA->>buildFromWmi: delegate WMI fallback construction
  buildFromWmi->>WMI: read video-controller rows
  buildFromWmi->>DXGI: match PCI IDs and select adapter metadata
  buildFromWmi->>CardFactory: construct ordered graphics cards
Loading

Possibly related PRs

  • oshi/oshi#3086: Introduces DXGI adapter metadata used for matching and dedicated VRAM selection.
  • oshi/oshi#3087: Covers related WMI ghost-row filtering and DXGI-based card ordering.

Poem

A rabbit hops through WMI rows,
While DXGI sets the flow;
Ghost cards vanish, primaries lead,
Shared fields serve each backend’s need.
Tests thump approval—swift and bright! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: moving the Windows graphics-card WMI fallback into a shared base class.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.09%. Comparing base (954adaf) to head (65eb0a6).

Files with missing lines Patch % Lines
...e/common/platform/windows/WindowsGraphicsCard.java 96.07% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master    #3544    +/-   ##
==========================================
  Coverage     79.08%   79.09%            
- Complexity     3720     3938   +218     
==========================================
  Files           701      702     +1     
  Lines         24187    24238    +51     
  Branches       4019     4033    +14     
==========================================
+ Hits          19128    19170    +42     
- Misses         2874     2880     +6     
- Partials       2185     2188     +3     
Flag Coverage Δ
linux 35.94% <96.07%> (+0.18%) ⬆️
macos 36.83% <96.07%> (+0.11%) ⬆️
windows 44.04% <96.07%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit 35b879f into oshi:master Jul 29, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the windows-graphicscard-dedup branch July 29, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant