Repository navigation
DXGI-based VRAM detection for Windows GPU adapters - #3086
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds DXGI-based VRAM detection on Windows: new immutable Changes
Sequence DiagramsequenceDiagram
participant WGC as WindowsGraphicsCard
participant Parse as ParseUtil (PCI regex)
participant WD as WindowsDxgi
participant DXGI as dxgi.dll
participant Reg as Windows Registry
WGC->>WD: queryAdapters()
WD->>DXGI: CreateDXGIFactory / EnumAdapters / GetDesc
DXGI-->>WD: DxgiAdapterInfo(name,vendor,device, vram)
WD-->>WGC: List<DxgiAdapterInfo>
WGC->>Reg: Read MatchingDeviceId
WGC->>Parse: parseDeviceIdToVendorProductIds(id)
Parse-->>WGC: vendorId, deviceId (or null)
WGC->>WD: findMatch(adapters, vendorId, deviceId, adapterName)
alt DXGI match found
WD-->>WGC: DxgiAdapterInfo with dedicatedVideoMemory
WGC->>WGC: Use DXGI VRAM
else No DXGI match
WGC->>Reg: Read qwMemorySize (registry)
WGC->>WD: registryValueToVram(registryValue)
WD-->>WGC: vramBytes
WGC->>WGC: Use registry VRAM or 0
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3086 +/- ##
==========================================
+ Coverage 84.82% 85.38% +0.55%
==========================================
Files 33 33
Lines 1470 1478 +8
Branches 216 217 +1
==========================================
+ Hits 1247 1262 +15
+ Misses 124 118 -6
+ Partials 99 98 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java`:
- Around line 190-193: WMI fallback currently ignores DXGI matches and always
uses ADAPTERRAM; update getGraphicsCardsFromWmi(...) to accept the dxgiAdapters
collection (passed from queryAdapters()), use the already-parsed PNPDEVICEID to
call WindowsDxgi.findMatch(dxgiAdapters, pnpDeviceId) and prefer that DXGI match
when present, and only fall back to WmiUtil.getUint32asLong(...,
VideoControllerProperty.ADAPTERRAM, ...) when WindowsDxgi.findMatch returns no
match.
- Around line 87-88: WindowsDxgi.findMatch() currently reuses the same
dxgiAdapters list for every registry entry, causing multiple GPUs with identical
PCI IDs to all reference the same DxgiAdapterInfo; modify the matching logic in
WindowsGraphicsCard so after locating a match via WindowsDxgi.findMatch(...) on
the dxgiAdapters list you remove or mark that DxgiAdapterInfo as consumed (e.g.,
remove by index or use an iterator) so each DxgiAdapterInfo is assigned at most
once; update any repeated lookup sites (the dxgiAdapters variable use around
WindowsGraphicsCard and the matching block referenced in lines ~123-125) to
consume the matched entry instead of leaving it available for subsequent
matches.
- Around line 129-131: The registry fallback currently treats vram == 0 as a
miss and overwrites a valid DXGI result; change the conditional in
WindowsGraphicsCard so the registry fallback only runs when there was no DXGI
match (i.e., vram is negative/not set) rather than when vram <= 0. Concretely,
replace the check using vram <= 0 with vram < 0 (or the sentinel used to
indicate "no match") around the Advapi32Util.registryValueExists/getValue block
that calls registryValueToVram, so legitimate DedicatedVideoMemory == 0 values
are preserved.
In `@oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java`:
- Around line 56-65: The test currently passes using the exact adapter
description so it doesn't verify normalization; update the test in
WindowsDxgiTest to call WindowsDxgi.findMatch(...) with a variant of the adapter
name that only matches after normalization (for example remove "(R)" and "(TM)"
and/or collapse extra whitespace or use unicode ®/™), keeping the created
DxgiAdapterInfo("Intel(R) Arc(TM) A770 Graphics", ...) unchanged; ensure the
assertions still check that the returned DxgiAdapterInfo (from
WindowsDxgi.findMatch) is non-null and has the expected dedicated memory to
confirm normalization logic in findMatch is exercised.
- Around line 148-156: The test testQueryAdaptersOnWindows currently requires at
least one DXGI adapter and that VendorId > 0 which fails in DXGI-unavailable or
virtual environments; change the test in
WindowsDxgiTest.testQueryAdaptersOnWindows to accept an empty adapters list (do
not fail if adapters.isEmpty()), and only perform per-adapter assertions when
adapters are present: check a.getDescription() is not null and relax the vendor
check to allow non-negative IDs (vendorId >= 0) instead of strictly > 0; leave
the dedicated video memory assertion (>= 0) as-is. Ensure you reference
WindowsDxgi.queryAdapters() and DxgiAdapterInfo getters (getDescription,
getVendorId, getDedicatedVideoMemory) when locating the code to modify.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d8b6eea2-ea8d-469b-a912-25c774435e86
📒 Files selected for processing (4)
oshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.javaoshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.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: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, windows-latest
🔇 Additional comments (2)
oshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.java (1)
17-77: Nice lightweight carrier type.The immutable shape keeps the DXGI-to-hardware handoff simple and avoids accidental mutation during adapter matching.
oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java (1)
208-263: COM lifetime handling looks solid.Releasing both adapter and factory pointers in
finallyblocks keeps the DXGI enumeration path safe even whenEnumAdapters()orGetDesc()fail partway through.
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (5)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (3)
87-88:⚠️ Potential issue | 🟡 MinorConsume matched DXGI adapters once they're assigned.
WindowsDxgi.findMatch()returns the first vendor/device hit. Reusing the samedxgiAdapterslist for every registry card lets multiple same-ID adapters bind to that oneDxgiAdapterInfo, so one card's VRAM can be reused for its siblings.Simple one-to-one matching
- List<DxgiAdapterInfo> dxgiAdapters = WindowsDxgi.queryAdapters(); + List<DxgiAdapterInfo> dxgiAdapters = new ArrayList<>(WindowsDxgi.queryAdapters()); ... DxgiAdapterInfo dxgiMatch = WindowsDxgi.findMatch(dxgiAdapters, pciVendorId, pciDeviceId, name); if (dxgiMatch != null) { vram = dxgiMatch.getDedicatedVideoMemory(); + dxgiAdapters.remove(dxgiMatch); }Also applies to: 123-125
🤖 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 87 - 88, The code queries DXGI adapters once into dxgiAdapters (WindowsDxgi.queryAdapters()) and then uses WindowsDxgi.findMatch() repeatedly, which allows the same DxgiAdapterInfo to be matched to multiple registry cards; change the matching loop in WindowsGraphicsCard so after a successful match (a returned DxgiAdapterInfo) you consume it (e.g., remove it from the dxgiAdapters list or mark it consumed) so each DxgiAdapterInfo is used one-to-one with a registry card (refer to WindowsDxgi.findMatch(), DxgiAdapterInfo, and the loop that constructs WindowsGraphicsCard objects).
190-193:⚠️ Potential issue | 🟠 MajorThis fallback path can still use DXGI.
This method already has
NAMEand parsedPNPDEVICEID, so dropping straight toADAPTERRAMreintroduces the same 32-bit-capped VRAM source the PR is trying to avoid when registry enumeration fails. Pass the DXGI adapter list intogetGraphicsCardsFromWmi()and only useAdapterRAMwhenWindowsDxgi.findMatch()cannot identify a match.🤖 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 190 - 193, The WMI fallback should prefer DXGI-derived VRAM when possible: change getGraphicsCardsFromWmi(...) to accept the DXGI adapter list (pass the list from the caller where NAME and parsed PNPDEVICEID are available), call WindowsDxgi.findMatch(NAME, parsedPnpDeviceId, dxgiAdapters) and, if it returns a match, use the DXGI VRAM values from that match instead of falling straight to VideoControllerProperty.ADAPTERRAM; only call WmiUtil.getUint32asLong(cards, VideoControllerProperty.ADAPTERRAM, index) when WindowsDxgi.findMatch(...) yields no match.
121-131:⚠️ Potential issue | 🟠 MajorDon't treat a matched
0as a miss.
DedicatedVideoMemory == 0is a valid DXGI result for UMA/integrated adapters. Thevram <= 0check overwrites that authoritative match withqwMemorySize.Restrict the registry fallback to the no-match case
long vram = 0L; DxgiAdapterInfo dxgiMatch = WindowsDxgi.findMatch(dxgiAdapters, pciVendorId, pciDeviceId, name); if (dxgiMatch != null) { vram = dxgiMatch.getDedicatedVideoMemory(); - } - - // Fallback: 64-bit registry value qwMemorySize - if (vram <= 0 && Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, QW_MEMORY_SIZE)) { + } else if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, QW_MEMORY_SIZE)) { Object regValue = Advapi32Util.registryGetValue(WinReg.HKEY_LOCAL_MACHINE, fullKey, QW_MEMORY_SIZE); vram = registryValueToVram(regValue); }🤖 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 121 - 131, The code currently treats a DXGI match with getDedicatedVideoMemory() == 0 as a miss and falls back to the registry; change this so the registry fallback only runs when WindowsDxgi.findMatch(...) returns null. In WindowsGraphicsCard, after calling WindowsDxgi.findMatch(dxgiAdapters, pciVendorId, pciDeviceId, name) and assigning vram = dxgiMatch.getDedicatedVideoMemory(), do not enter the Advapi32Util.registryValueExists / registryGetValue path when dxgiMatch != null (even if vram == 0); only call Advapi32Util.registryValueExists and registryValueToVram when dxgiMatch == null to preserve authoritative 0 values from DxgiAdapterInfo.oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java (2)
56-65:⚠️ Potential issue | 🟡 MinorUse an input that only matches after normalization.
Line 63 still passes the exact adapter description, so this test would pass even if
findMatch()stopped callingnormalizeName(). Feed it a variant that only matches after stripping(R)/(TM)or collapsing whitespace.Minimal change
- DxgiAdapterInfo match = WindowsDxgi.findMatch(adapters, 0, 0, "Intel(R) Arc(TM) A770 Graphics"); + DxgiAdapterInfo match = WindowsDxgi.findMatch(adapters, 0, 0, "Intel Arc A770 Graphics");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java` around lines 56 - 65, The test testFindMatchByNormalizedName currently passes the exact adapter description so it doesn't verify normalization; update the input passed to WindowsDxgi.findMatch to a variant that only matches after normalization (e.g., remove or alter the "(R)" and "(TM)" markers or change spacing) while keeping the expected DxgiAdapterInfo with name "Intel(R) Arc(TM) A770 Graphics" and its dedicatedVideoMemory; this ensures WindowsDxgi.findMatch (and any normalizeName logic) is actually exercised when matching the DxgiAdapterInfo instance.
146-156:⚠️ Potential issue | 🟠 MajorMake the Windows integration test tolerate valid empty DXGI results.
WindowsDxgi.queryAdapters()is explicitly allowed to return an empty list, so assertingsize() > 0makes this test fail on valid Windows environments.VendorId > 0is also too strict for software or virtual adapters.One way to keep the test stable
- // On any Windows system with a display, there should be at least one adapter - assertThat("Should find at least one DXGI adapter", adapters.size(), is(greaterThan(0))); for (DxgiAdapterInfo a : adapters) { assertThat("Description should not be null", a.getDescription(), is(notNullValue())); - assertThat("VendorId should be positive", a.getVendorId(), is(greaterThan(0))); + assertThat("VendorId should be non-negative", a.getVendorId(), is(greaterThanOrEqualTo(0))); assertThat("DedicatedVideoMemory should be non-negative", a.getDedicatedVideoMemory(), is(greaterThanOrEqualTo(0L))); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java` around lines 146 - 156, Remove the hard failure for empty results in testQueryAdaptersOnWindows by deleting the assert that adapters.size() > 0 (allow WindowsDxgi.queryAdapters() to return an empty list), and relax the vendor ID check in the per-adapter assertions: change the VendorId expectation in the DxgiAdapterInfo assertions from greaterThan(0) to greaterThanOrEqualTo(0). Keep the existing checks for description not null and dedicatedVideoMemory >= 0; the for-loop over adapters can remain as-is (it will simply not execute if the list is empty).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Around line 7-8: The changelog entry currently splits the PR/title and the
author attribution into two list items; merge them into a single bullet by
folding the attribution line into the same bullet as the PR entry (i.e., change
the two lines "* [`#3086`](https://github.com/oshi/oshi/pull/3086): DXGI-based
VRAM detection for Windows GPU adapters" and " -
[`@claude`](https://github.com/claude), [`@dbwiddis`](https://github.com/dbwiddis)."
into one bullet such as "* [`#3086`](https://github.com/oshi/oshi/pull/3086):
DXGI-based VRAM detection for Windows GPU adapters —
[`@claude`](https://github.com/claude),
[`@dbwiddis`](https://github.com/dbwiddis).")
In `@oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java`:
- Around line 70-71: The static DxgiLib.INSTANCE (in interface DxgiLib) can
cause NoClassDefFoundError after a failed Native.load; update the code paths
that access DxgiLib.INSTANCE (notably in queryAdapters() and the similar block
around lines 213–217) to catch NoClassDefFoundError in addition to
UnsatisfiedLinkError so the method returns the documented empty list fallback;
locate uses of DxgiLib.INSTANCE in WindowsDxgi (and any helper methods that
touch it) and wrap the access in a try-catch that handles both
UnsatisfiedLinkError and NoClassDefFoundError, logging as before and returning
the empty list.
---
Duplicate comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java`:
- Around line 87-88: The code queries DXGI adapters once into dxgiAdapters
(WindowsDxgi.queryAdapters()) and then uses WindowsDxgi.findMatch() repeatedly,
which allows the same DxgiAdapterInfo to be matched to multiple registry cards;
change the matching loop in WindowsGraphicsCard so after a successful match (a
returned DxgiAdapterInfo) you consume it (e.g., remove it from the dxgiAdapters
list or mark it consumed) so each DxgiAdapterInfo is used one-to-one with a
registry card (refer to WindowsDxgi.findMatch(), DxgiAdapterInfo, and the loop
that constructs WindowsGraphicsCard objects).
- Around line 190-193: The WMI fallback should prefer DXGI-derived VRAM when
possible: change getGraphicsCardsFromWmi(...) to accept the DXGI adapter list
(pass the list from the caller where NAME and parsed PNPDEVICEID are available),
call WindowsDxgi.findMatch(NAME, parsedPnpDeviceId, dxgiAdapters) and, if it
returns a match, use the DXGI VRAM values from that match instead of falling
straight to VideoControllerProperty.ADAPTERRAM; only call
WmiUtil.getUint32asLong(cards, VideoControllerProperty.ADAPTERRAM, index) when
WindowsDxgi.findMatch(...) yields no match.
- Around line 121-131: The code currently treats a DXGI match with
getDedicatedVideoMemory() == 0 as a miss and falls back to the registry; change
this so the registry fallback only runs when WindowsDxgi.findMatch(...) returns
null. In WindowsGraphicsCard, after calling WindowsDxgi.findMatch(dxgiAdapters,
pciVendorId, pciDeviceId, name) and assigning vram =
dxgiMatch.getDedicatedVideoMemory(), do not enter the
Advapi32Util.registryValueExists / registryGetValue path when dxgiMatch != null
(even if vram == 0); only call Advapi32Util.registryValueExists and
registryValueToVram when dxgiMatch == null to preserve authoritative 0 values
from DxgiAdapterInfo.
In `@oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java`:
- Around line 56-65: The test testFindMatchByNormalizedName currently passes the
exact adapter description so it doesn't verify normalization; update the input
passed to WindowsDxgi.findMatch to a variant that only matches after
normalization (e.g., remove or alter the "(R)" and "(TM)" markers or change
spacing) while keeping the expected DxgiAdapterInfo with name "Intel(R) Arc(TM)
A770 Graphics" and its dedicatedVideoMemory; this ensures WindowsDxgi.findMatch
(and any normalizeName logic) is actually exercised when matching the
DxgiAdapterInfo instance.
- Around line 146-156: Remove the hard failure for empty results in
testQueryAdaptersOnWindows by deleting the assert that adapters.size() > 0
(allow WindowsDxgi.queryAdapters() to return an empty list), and relax the
vendor ID check in the per-adapter assertions: change the VendorId expectation
in the DxgiAdapterInfo assertions from greaterThan(0) to
greaterThanOrEqualTo(0). Keep the existing checks for description not null and
dedicatedVideoMemory >= 0; the for-loop over adapters can remain as-is (it will
simply not execute if the list is empty).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1642ed1f-c4e4-4ebd-a7e0-e6bd54e7b817
📒 Files selected for processing (5)
CHANGELOG.mdoshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.javaoshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.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). (1)
- GitHub Check: Codacy Static Code Analysis
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java (1)
297-317: Consider adding defensive null check foradaptersparameter.If
findMatchis called with anulllist, the for-each loops will throwNullPointerException. WhilequeryAdapters()never returnsnull, as a public API method, a defensive check would make the contract clearer.💡 Suggested defensive check
public static DxgiAdapterInfo findMatch(List<DxgiAdapterInfo> adapters, int vendorId, int deviceId, String adapterName) { + if (adapters == null || adapters.isEmpty()) { + return null; + } // Priority 1: vendor + device ID if (vendorId != 0 && deviceId != 0) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java` around lines 297 - 317, The method findMatch(List<DxgiAdapterInfo> adapters, int vendorId, int deviceId, String adapterName) can NPE if adapters is null; add a defensive null check at the top (e.g., if adapters == null || adapters.isEmpty() return null) so the for-each loops over adapters never throw; update only findMatch and keep behavior otherwise (still prefer vendor/device match first, then normalized name using normalizeName); this makes the public API robust even if callers (outside queryAdapters()) pass null.
🤖 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/jna/platform/windows/WindowsDxgi.java`:
- Around line 297-317: The method findMatch(List<DxgiAdapterInfo> adapters, int
vendorId, int deviceId, String adapterName) can NPE if adapters is null; add a
defensive null check at the top (e.g., if adapters == null || adapters.isEmpty()
return null) so the for-each loops over adapters never throw; update only
findMatch and keep behavior otherwise (still prefer vendor/device match first,
then normalized name using normalizeName); this makes the public API robust even
if callers (outside queryAdapters()) pass null.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e3f225f6-28d2-4241-aab1-7606cf7aac12
📒 Files selected for processing (4)
CHANGELOG.mdoshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.javaoshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.javaoshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
- oshi-core/src/main/java/oshi/driver/windows/DxgiAdapterInfo.java
- oshi-core/src/test/java/oshi/driver/windows/WindowsDxgiTest.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). (5)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Analyze (java)
🔇 Additional comments (8)
CHANGELOG.md (1)
6-8: Looks good.This now uses a single bullet and matches the surrounding changelog style.
oshi-core/src/main/java/oshi/jna/platform/windows/WindowsDxgi.java (7)
27-61: Well-documented utility class with clear DXGI API explanation.The vtable layout documentation (lines 38-44) is valuable for maintainers unfamiliar with DXGI COM interfaces. Good use of private constructor for the utility class pattern.
83-96: Past review concern properly addressed with static initialization guard.The static initializer catches both
UnsatisfiedLinkError(first failure) andNoClassDefFoundError(subsequent references to erroneous class), settingDXGI_AVAILABLEaccordingly. The flag check inqueryAdapters()(line 224) prevents further access attempts toDxgiLib.INSTANCEwhen the library is unavailable.This is a cleaner solution than catching at every call site.
119-133: LGTM!The structure mapping correctly uses
SIZE_Tfor pointer-sized memory fields and properly decomposesLUIDinto two 32-bit parts to match the Windows definition.
158-208: COM vtable wrappers are correctly implemented.The vtable slot indices match the documented inheritance chain (IUnknown → IDXGIObject → IDXGIFactory/IDXGIAdapter). The use of
COMInvoker._invokeNativeObjectand_invokeNativeIntfollows standard JNA COM patterns.
223-275: Solid resource management and error handling in queryAdapters().The nested try-finally blocks (lines 254-269 for adapter, lines 239-273 for factory) ensure COM objects are released even when exceptions occur. The explicit
desc.read()call on line 258 is essential since JNA doesn't automatically sync structure fields from native memory after the call.
329-345: LGTM!The
registryValueToVramcorrectly handles all three registry types:
Long(REG_QWORD) returned as-isInteger(REG_DWORD) converted usingInteger.toUnsignedLong()to preserve unsigned semanticsbyte[](REG_BINARY) interpreted as little-endian, correctly limited to 8 bytesThe little-endian conversion loop reads from highest to lowest index, placing each byte progressively into more significant positions.
353-359: LGTM!The normalization using
Locale.ROOTensures consistent lowercase behavior regardless of the JVM's default locale—important for fuzzy matching of adapter names that may contain locale-sensitive characters.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)
171-173: Reuse the first DXGI enumeration in the WMI fallback.This overload does a second
WindowsDxgi.queryAdapters()even thoughgetGraphicsCards()already fetched adapters. On the fallback path, that can produce a different match set than the registry pass and needlessly throws away the first DXGI enumeration. Prefer passing the existingdxgiAdapterslist through instead of re-querying here.🤖 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 171 - 173, The no-arg getGraphicsCardsFromWmi() currently re-calls WindowsDxgi.queryAdapters(), discarding the initial DXGI enumeration; change callers to pass the existing dxgiAdapters list into getGraphicsCardsFromWmi(List<...>) and implement/keep an overload that accepts a List parameter so the method uses the provided dxgiAdapters instead of calling WindowsDxgi.queryAdapters() again (update places that currently call the no-arg getGraphicsCardsFromWmi() to pass the dxgiAdapters variable, and remove the internal new ArrayList<>(WindowsDxgi.queryAdapters()) re-query).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@config/checkstyle-suppressions.xml`:
- Line 9: The suppression range in config/checkstyle-suppressions.xml currently
only covers lines 115-135 for ParseUtil.java, which misses the mixed-case
constants HZ, KHZ, MHZ, GHZ, THZ, PHZ defined at lines 108-113; update the
<suppress> entry for files="ParseUtil\.java" to cover the earlier lines (e.g.,
change lines="115-135" to lines="108-135") or add a second <suppress> for
files="ParseUtil\.java" with lines="108-113" so the ConstantName check is
suppressed for those constants HZ/KHZ/MHZ/GHZ/THZ/PHZ as well.
---
Nitpick comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java`:
- Around line 171-173: The no-arg getGraphicsCardsFromWmi() currently re-calls
WindowsDxgi.queryAdapters(), discarding the initial DXGI enumeration; change
callers to pass the existing dxgiAdapters list into
getGraphicsCardsFromWmi(List<...>) and implement/keep an overload that accepts a
List parameter so the method uses the provided dxgiAdapters instead of calling
WindowsDxgi.queryAdapters() again (update places that currently call the no-arg
getGraphicsCardsFromWmi() to pass the dxgiAdapters variable, and remove the
internal new ArrayList<>(WindowsDxgi.queryAdapters()) re-query).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a96c9f02-6691-48ff-a4f2-4a688383c6f9
📒 Files selected for processing (5)
CHANGELOG.mdconfig/checkstyle-suppressions.xmloshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/util/ParseUtil.javaoshi-core/src/test/java/oshi/util/ParseUtilTest.java
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
📜 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). (4)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Analyze (java)
🔇 Additional comments (3)
oshi-core/src/main/java/oshi/util/ParseUtil.java (1)
87-93: The new DeviceID parser looks solid.It cleanly covers both full PNPDeviceID strings and bare
MatchingDeviceId/VID_xxxx&PID_xxxxinputs while keeping the existingnull-on-no-match behavior consistent with the rest ofParseUtil.Also applies to: 1032-1053
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)
83-140: DXGI-first matching and fallback flow looks correct now.The one-to-one adapter consumption, the separate “matched vs. VRAM value” handling, and the WMI-side DXGI reuse all line up well with the Arc A770 regression this PR is fixing.
Also applies to: 198-212
oshi-core/src/test/java/oshi/util/ParseUtilTest.java (1)
545-573: Good coverage for the new parser.These cases exercise the exact Windows identifier shapes this PR depends on, especially the bare
MatchingDeviceIdpath that the existing serial parser could not handle.
Full disclosure: code written by Claude Sonnet 4.6. 🤖
Problem
OSHI reported incorrect VRAM for modern discrete GPUs on Windows. For example, an Intel Arc A770
(16 GB) was reported as having ~2 GB. The root cause was that
HardwareInformation.MemorySizeisa 32-bit registry value, and Windows writes the sentinel
0x7FFFF000(~2 GiB) into it for any GPUwith more than 2 GiB of dedicated VRAM. The 64-bit
HardwareInformation.qwMemorySizekey is absenton at least some Intel Arc driver installations, leaving no reliable registry fallback.
Solution
Use the DXGI API (
IDXGIAdapter::GetDesc) as the primary VRAM source.DXGI_ADAPTER_DESC.DedicatedVideoMemoryis the authoritative Windows API value for dedicated GPUmemory and is not subject to any 32-bit cap.
Changes
oshi/driver/windows/DxgiAdapterInfo.java(new)Plain immutable data class holding a DXGI adapter's description, PCI vendor ID, device ID, and
dedicatedVideoMemory. No native dependencies — fully unit-testable in isolation.oshi/jna/platform/windows/WindowsDxgi.java(new)Minimal JNA binding to
dxgi.dllusing the same vtable-basedCOMInvokerpattern already usedthroughout OSHI. Implements:
queryAdapters()— callsCreateDXGIFactorythenIDXGIFactory::EnumAdapters/IDXGIAdapter::GetDescin a loop; fails gracefully to an empty list ifdxgi.dllis unavailablefindMatch()— matches a DXGI adapter to a registry card by PCI vendor+device ID first, then bynormalized adapter name as a fallback
registryValueToVram()— handlesREG_QWORD(Long),REG_DWORD(Integer), andREG_BINARY(little-endian byte array)
normalizeName()— case-insensitive name normalization stripping(R)/(TM)and collapsingwhitespace
oshi/hardware/platform/windows/WindowsGraphicsCard.java(modified)WindowsDxgi.queryAdapters()once before the registry enumeration loopMatchingDeviceIdfrom each adapter's registry key and parsesVEN_xxxx&DEV_xxxxtoobtain PCI IDs for DXGI matching
WindowsDxgi.findMatch()as the primary VRAM sourceHardwareInformation.qwMemorySize(64-bit) if DXGI has no matchHardwareInformation.MemorySize(32-bit) entirely with an explanatory commentoshi/driver/windows/WindowsDxgiTest.java(new)13 tests covering:
findMatchby vendor+device ID, multi-GPU tie-breaking, name fallback, no-match,zero-ID fallback;
normalizeNameedge cases;registryValueToVramfor all three registry types;and a
@EnabledOnOs(OS.WINDOWS)integration test that callsqueryAdapters()against real hardware.Fixes #2907
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation