Skip to content

Fix GPU Stats not cycling through multiple GPUs#48503

Open
pratnala wants to merge 1 commit into
microsoft:mainfrom
pratnala:gpu-perf-monitor
Open

Fix GPU Stats not cycling through multiple GPUs#48503
pratnala wants to merge 1 commit into
microsoft:mainfrom
pratnala:gpu-perf-monitor

Conversation

@pratnala

@pratnala pratnala commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Command Palette's Performance Monitor dock band exposes "Previous GPU" / "Next GPU" commands, but on multi-GPU machines they did nothing and only one GPU was ever shown.

Root cause: GPUStats keyed GPUs by the phys_N token in the "GPU Engine" perf-counter instance names, assuming it enumerated physical adapters. On modern Windows that token is effectively always phys_0 (verified on a desktop with an RTX 4090 + AMD iGPU — all 1640 instances were phys_0), so every adapter collapsed into one bucket and the reported usage was the sum across adapters. The real per-adapter identifier is the LUID.

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Key GPUs by LUID (parsed from the instance name) instead of phys.
  • Resolve friendly adapter names via DXGI (IDXGIFactory1/IDXGIAdapter1 through CsWin32, AOT-safe) and filter out software adapters (Microsoft Basic Render Driver / WARP).
  • Discover adapters on each tick as well as at construction, so a GPU that registers counters later still appears.
  • Show the active GPU's name in the dock band subtitle so cycling is visible.

Validation Steps Performed

Tested on a desktop (RTX 4090 + AMD Radeon iGPU). Prev/Next GPU now cycles between "NVIDIA GeForce RTX 4090" and "AMD Radeon(TM) Graphics", each showing its own utilization; WARP is hidden.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Command Palette’s Performance Monitor GPU cycling on multi-GPU systems by switching GPU identity from the perf-counter phys_N token (which collapses to phys_0 on modern Windows) to the adapter LUID, and improves the dock band UX by showing the active GPU name.

Changes:

  • Key GPU perf-counter accumulation by adapter LUID and discover adapters dynamically as counters appear.
  • Resolve friendly GPU names via DXGI (CsWin32) and filter out software adapters (WARP / Microsoft Basic Render Driver).
  • Show the active GPU name in the dock band subtitle so Prev/Next GPU cycling is visible.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PerformanceMonitor/PerformanceWidgetsPage.cs Adds band subtitle support to show the active GPU name.
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PerformanceMonitor/NativeMethods.txt Extends CsWin32 inputs with DXGI factory/adapter APIs and structs.
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PerformanceMonitor/NativeMethods.json Adds CsWin32 generation settings (no marshaling; preserve COM HRESULT signatures).
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PerformanceMonitor/DevHome/Helpers/GPUStats.cs Switches GPU bucketing to LUID, adds on-tick GPU discovery, and integrates adapter naming.
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PerformanceMonitor/DevHome/Helpers/GpuAdapterNames.cs New DXGI-based adapter enumeration to map LUID → (name, software flag).

/// <c>(HighPart &lt;&lt; 32) | LowPart</c>. Returns an empty map on any failure;
/// callers fall back to generic names.
/// </summary>
internal static unsafe Dictionary<long, AdapterInfo> GetByLuid()

var luidKey = ((long)(uint)desc.AdapterLuid.HighPart << 32) | desc.AdapterLuid.LowPart;
var isSoftware = ((uint)desc.Flags & DxgiAdapterFlagSoftware) != 0;
var description = desc.Description.ToString().TrimEnd('\0');
Comment on lines +143 to +147
// A GPU can register counter instances after we were constructed
// (e.g. a discrete GPU coming out of an idle low-power state), so
// keep discovering here rather than only in the constructor.
AddGpuIfNew(luidKey);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CmdPal Performance Monitor doesn't switch GPUs

3 participants