Repository navigation
Filter disabled Windows GPU adapters and order by DXGI enumeration - #3087
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (8)
📝 WalkthroughWalkthroughImplements DXGI-first graphics card enumeration with ghost-adapter filtering and DXGI-based ordering (primary-desktop first), preserves DXGI VRAM values and falls back to WMI when needed; adds Changes
Sequence DiagramsequenceDiagram
participant Registry as Windows Registry
participant DXGI as DXGI Enumeration
participant Logic as Graphics Card Logic
participant WMI as WMI Fallback
participant Result as Graphics Cards List
Logic->>Registry: Query registry video controller entries
Registry-->>Logic: Registry controller data
Logic->>DXGI: Query DXGI adapters (if available)
alt DXGI Available
DXGI-->>Logic: DXGI adapter list (with VRAM, indices)
Logic->>Logic: Match registry entries to DXGI adapters (track dxgiIndex)
Logic->>Logic: Consume matched DXGI entries to avoid duplicates
Logic->>Logic: Filter out registry-only ghost/disabled adapters
Logic->>Logic: Order results by DXGI enumeration (primary-desktop first)
Logic-->>Result: DXGI-ordered cards + remaining non-DXGI cards
else DXGI Not Available / Empty
DXGI-->>Logic: No DXGI results
Logic->>WMI: Query WMI for graphics cards
WMI-->>Logic: WMI controller data
Logic->>Logic: Build list from WMI (preserve VRAM semantics)
Logic-->>Result: WMI-derived cards
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
CHANGELOG.md (1)
8-8: Use hyphen instead of em dash for consistency.Line 7 was just updated to use a hyphen delimiter, but this new entry uses an em dash. For consistency with line 7 and most other entries in the changelog, consider using a hyphen.
📝 Proposed fix
-* [`#3087`](https://github.com/oshi/oshi/pull/3087): Filter disabled Windows GPU adapters and order by DXGI enumeration — [`@dbwiddis`](https://github.com/dbwiddis). +* [`#3087`](https://github.com/oshi/oshi/pull/3087): Filter disabled Windows GPU adapters and order by DXGI enumeration - [`@dbwiddis`](https://github.com/dbwiddis).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@CHANGELOG.md` at line 8, The changelog entry for PR `#3087` uses an em dash — replace it with a hyphen to match the rest of the file's delimiter style; locate the line containing "* [`#3087`](https://github.com/oshi/oshi/pull/3087): Filter disabled Windows GPU adapters and order by DXGI enumeration — [`@dbwiddis`](https://github.com/dbwiddis)." and change the em dash to a hyphen so it reads "...DXGI enumeration - [`@dbwiddis`](https://github.com/dbwiddis)."oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)
134-146: Consider deferring DXGI consumption until card creation succeeds.The DXGI match is consumed from
remainingDxgiat line 141 before the registry fallback operations (lines 149-151). If aWin32Exceptionis thrown during registry access and caught at line 171, the card won't be created but the DXGI entry is already removed. In the rare case where this affects all registry entries, the WMI fallback at line 184 would receive a depletedremainingDxgi, potentially causing incorrect ordering.💡 Suggested fix: move consumption after card creation
long vram = -1L; int dxgiIndex = -1; DxgiAdapterInfo dxgiMatch = WindowsDxgi.findMatch(remainingDxgi, pciVendorId, pciDeviceId, name); if (dxgiMatch != null) { vram = dxgiMatch.getDedicatedVideoMemory(); dxgiIndex = dxgiAdapters.indexOf(dxgiMatch); - // Consume the matched entry so it cannot be assigned to a second registry card - // with the same PCI IDs (e.g. identical multi-GPU configurations). - remainingDxgi.remove(dxgiMatch); } else if (dxgiAvailable) { // DXGI is available but this registry entry has no matching adapter: // it is a ghost device (stale driver from hardware no longer present). Skip it. continue; } // ... existing fallback and normalization code ... GraphicsCard card = new WindowsGraphicsCard(Util.isBlank(name) ? Constants.UNKNOWN : name, Util.isBlank(deviceId) ? Constants.UNKNOWN : deviceId, Util.isBlank(vendor) ? Constants.UNKNOWN : vendor, Util.isBlank(versionInfo) ? Constants.UNKNOWN : versionInfo, vram); + // Consume the matched entry after successful card creation so it cannot be + // assigned to a second registry card with the same PCI IDs. + if (dxgiMatch != null) { + remainingDxgi.remove(dxgiMatch); + } if (dxgiIndex >= 0) { dxgiOrdered.put(dxgiIndex, card); } else { cardList.add(card); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java` around lines 134 - 146, The DXGI entry (dxgiMatch) is being removed from remainingDxgi before the registry-based card creation completes, which can deplete remainingDxgi if a Win32Exception aborts creation; change the logic in WindowsGraphicsCard so WindowsDxgi.findMatch(...) still identifies dxgiMatch and sets dxgiIndex/vram, but defer calling remainingDxgi.remove(dxgiMatch) (and any reliance on dxgiAdapters.indexOf(dxgiMatch)) until after the registry card object is successfully constructed (i.e., after the code path that can throw Win32Exception completes without error); ensure the removal only happens on successful creation so DXGI entries remain available for subsequent fallback/WMI processing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@CHANGELOG.md`:
- Line 8: The changelog entry for PR `#3087` uses an em dash — replace it with a
hyphen to match the rest of the file's delimiter style; locate the line
containing "* [`#3087`](https://github.com/oshi/oshi/pull/3087): Filter disabled
Windows GPU adapters and order by DXGI enumeration —
[`@dbwiddis`](https://github.com/dbwiddis)." and change the em dash to a hyphen so
it reads "...DXGI enumeration - [`@dbwiddis`](https://github.com/dbwiddis)."
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java`:
- Around line 134-146: The DXGI entry (dxgiMatch) is being removed from
remainingDxgi before the registry-based card creation completes, which can
deplete remainingDxgi if a Win32Exception aborts creation; change the logic in
WindowsGraphicsCard so WindowsDxgi.findMatch(...) still identifies dxgiMatch and
sets dxgiIndex/vram, but defer calling remainingDxgi.remove(dxgiMatch) (and any
reliance on dxgiAdapters.indexOf(dxgiMatch)) until after the registry card
object is successfully constructed (i.e., after the code path that can throw
Win32Exception completes without error); ensure the removal only happens on
successful creation so DXGI entries remain available for subsequent fallback/WMI
processing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f5a82bb-2489-4309-8868-4ef7aeeee45f
📒 Files selected for processing (4)
CHANGELOG.mdoshi-core/src/main/java/oshi/driver/windows/wmi/Win32VideoController.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Analyze (java)
🔇 Additional comments (5)
CHANGELOG.md (1)
7-7: LGTM - Formatting consistency improvement.The change from em dash to hyphen aligns with the formatting used in most other entries in the changelog.
oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java (1)
57-58: LGTM!Documentation-only change; the updated comment format is clearer.
oshi-core/src/main/java/oshi/driver/windows/wmi/Win32VideoController.java (1)
26-28: LGTM!The new
CONFIGMANAGERERRORCODEenum constant follows the existing naming convention. WQL is case-insensitive, so this correctly queries theConfigManagerErrorCodeproperty fromWin32_VideoController(where 0 indicates a properly working device).oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (2)
39-54: LGTM!The documentation clearly explains the VRAM detection priority, the 2 GiB cap workaround, and the ghost adapter filtering behavior. The addition of details about DXGI enumeration order guaranteeing the primary desktop adapter is first provides helpful context for API consumers.
201-261: LGTM!The WMI fallback path correctly mirrors the registry path's DXGI ordering and ghost-adapter filtering logic. The
ConfigManagerErrorCode != 0check at lines 212-215 appropriately identifies disabled/error devices, and only applying this filter when DXGI is available preserves backward compatibility on older systems.
e581785 to
a3ef7d8
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (2)
203-209: Consider clarifying parameter naming for dual usage.The
dxgiAdaptersparameter serves two roles: (1) the reference list forindexOflookups, and (2) the source for initializing the localremainingDxgi. While functionally correct, renaming tooriginalDxgiAdaptersor adding a brief comment would clarify this isn't modified within the method.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java` around lines 203 - 209, The parameter dxgiAdapters in getGraphicsCardsFromWmi is used both as the immutable reference for indexOf lookups and as the source for creating remainingDxgi, which can be confusing; rename the parameter to originalDxgiAdapters (or similar) and update all references within getGraphicsCardsFromWmi (including where you construct new ArrayList<>(remainingDxgi) and where you call indexOf) or alternatively add a short comment above the declaration explaining that dxgiAdapters is intentionally not mutated and that remainingDxgi is the working copy.
163-167: Comment is slightly imprecise but logic is correct.The comment mentions "if a Win32Exception aborts here" but the card constructor doesn't throw. The actual benefit is that if registry reads earlier in the try block fail (lines 111-127), the DXGI entry remains unconsumed for subsequent iterations. The deferred consumption pattern is correct; the comment could be clearer.
📝 Suggested comment clarification
- // Consume the matched DXGI entry only after successful card construction so it - // remains available for fallback/WMI processing if a Win32Exception aborts here. + // Consume the matched DXGI entry only after the full registry read succeeds, + // so it remains available if a Win32Exception from earlier registry operations + // causes this iteration to be skipped.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java` around lines 163 - 167, The existing comment in WindowsGraphicsCard near the deferred consumption of dxgiMatch is misleading about the failure mode; update the comment at the block that removes dxgiMatch from remainingDxgi to state that the DXGI entry is only removed after successful card construction so it remains available for fallback/WMI processing if earlier registry reads in the try block fail, rather than referencing a non-existent Win32Exception from the constructor; keep the deferred-removal logic as-is and mention the specific symbols dxgiMatch and remainingDxgi to make the intent clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java`:
- Around line 203-209: The parameter dxgiAdapters in getGraphicsCardsFromWmi is
used both as the immutable reference for indexOf lookups and as the source for
creating remainingDxgi, which can be confusing; rename the parameter to
originalDxgiAdapters (or similar) and update all references within
getGraphicsCardsFromWmi (including where you construct new
ArrayList<>(remainingDxgi) and where you call indexOf) or alternatively add a
short comment above the declaration explaining that dxgiAdapters is
intentionally not mutated and that remainingDxgi is the working copy.
- Around line 163-167: The existing comment in WindowsGraphicsCard near the
deferred consumption of dxgiMatch is misleading about the failure mode; update
the comment at the block that removes dxgiMatch from remainingDxgi to state that
the DXGI entry is only removed after successful card construction so it remains
available for fallback/WMI processing if earlier registry reads in the try block
fail, rather than referencing a non-existent Win32Exception from the
constructor; keep the deferred-removal logic as-is and mention the specific
symbols dxgiMatch and remainingDxgi to make the intent clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 195325ff-193d-40ef-b01f-d5005edfb454
📒 Files selected for processing (4)
CHANGELOG.mdoshi-core/src/main/java/oshi/driver/windows/wmi/Win32VideoController.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java
🚧 Files skipped from review as they are similar to previous changes (3)
- CHANGELOG.md
- oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java
- oshi-core/src/main/java/oshi/driver/windows/wmi/Win32VideoController.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 11, windows-latest
🔇 Additional comments (6)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (6)
49-53: Documentation clearly explains the new DXGI-first ordering and ghost adapter filtering.The added documentation accurately describes the behavior: DXGI enumeration excludes ghost adapters and guarantees primary desktop adapter first.
91-102: LGTM - DXGI setup and ordering approach is sound.Using
TreeMapkeyed by DXGI index guarantees primary-adapter-first ordering, and the match-and-consume pattern withremainingDxgicorrectly prevents duplicate matches.
134-142: LGTM - Correct index resolution and ghost adapter filtering.Using
dxgiAdapters.indexOf()on the original list (notremainingDxgi) ensures consistent DXGI enumeration indices even after matches are consumed. The ghost filtering logic correctly skips registry entries with no physical DXGI counterpart.
181-188: LGTM - Merge strategy and WMI fallback are correct.The merge correctly places DXGI-ordered cards first (TreeMap guarantees ascending key order). When falling back to WMI,
remainingDxgistill contains all original DXGI adapters since no cards were successfully created.
212-217: LGTM - ConfigManagerErrorCode filtering preserves compatibility.Filtering disabled devices only when DXGI is available ensures backward compatibility on systems where DXGI enumeration fails. The non-zero check correctly identifies problematic device entries.
243-263: LGTM - WMI DXGI matching and merge logic is correct.The WMI path correctly mirrors the registry path's ordering strategy. The removal of matched DXGI entries prevents duplicate matching, and the final merge preserves DXGI enumeration order.
a3ef7d8 to
03a5dd2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3087 +/- ##
==========================================
+ Coverage 84.64% 85.38% +0.74%
==========================================
Files 33 33
Lines 1478 1478
Branches 217 217
==========================================
+ Hits 1251 1262 +11
+ Misses 132 118 -14
- Partials 95 98 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When DXGI is available,
getGraphicsCards()now excludes ghost adapters (stale registry/WMI entries from hardware no longer physically present) and returns the list ordered by DXGI enumeration order, which guarantees the primary desktop adapter is first.ConfigManagerErrorCode != 0are skipped; DXGI ordering applied when adapters are availableFixes #2670
Summary by CodeRabbit
Bug Fixes
Documentation