@@ -32,24 +32,26 @@ const (
3232)
3333
3434// supportedMetrics lists metrics that are currently functional.
35- // Memory metrics (memory_dedicated, memory_shared) are defined as constants but not yet
36- // supported because PDH doesn't provide total VRAM counters needed for percentage calculation.
3735var supportedMetrics = map [string ]bool {
3836 MetricUtilization : true ,
3937 MetricUtilization3D : true ,
4038 MetricUtilizationCopy : true ,
4139 MetricUtilizationEncode : true ,
4240 MetricUtilizationDecode : true ,
41+ MetricMemoryDedicated : true ,
42+ MetricMemoryShared : true ,
4343}
4444
4545// AdapterInfo contains information about a GPU adapter.
4646// Index is a sequential number (0, 1, 2, ...) assigned during discovery.
4747// On Windows, LUID (Locally Unique Identifier) is the primary key used to
4848// distinguish adapters, since all GPUs report phys_0 in PDH instance names.
4949type AdapterInfo struct {
50- Index int
51- Name string
52- LUID string // Locally Unique Identifier from PDH instance names (Windows only)
50+ Index int
51+ Name string
52+ LUID string // Locally Unique Identifier from PDH instance names (Windows only)
53+ DedicatedVideoMemory uint64 // Total dedicated VRAM in bytes (from DXGI, Windows only)
54+ SharedSystemMemory uint64 // Total shared system memory in bytes (from DXGI, Windows only)
5355}
5456
5557// Reader is the interface for reading GPU metrics
@@ -75,8 +77,9 @@ type Widget struct {
7577 Renderer * render.MetricRenderer
7678
7779 // GPU configuration
78- adapter int // GPU adapter index
79- metric string // Metric to display
80+ adapter int // GPU adapter index
81+ metric string // Metric to display
82+ textFormat string // Format string for bar text overlay (from text.format)
8083
8184 // GPU metrics reader
8285 reader Reader
@@ -110,9 +113,15 @@ func New(cfg config.WidgetConfig) (*Widget, error) {
110113 }
111114 }
112115
116+ // Extract text format for bar overlay
117+ textFormat := ""
118+ if cfg .Text != nil {
119+ textFormat = cfg .Text .Format
120+ }
121+
113122 // Validate metric
114123 if ! supportedMetrics [metric ] {
115- return nil , fmt .Errorf ("unsupported GPU metric: %q (supported: utilization, utilization_3d, utilization_copy, utilization_video_encode, utilization_video_decode)" , metric )
124+ return nil , fmt .Errorf ("unsupported GPU metric: %q (supported: utilization, utilization_3d, utilization_copy, utilization_video_encode, utilization_video_decode, memory_dedicated, memory_shared )" , metric )
116125 }
117126
118127 // Initialize reader (platform-specific)
@@ -142,6 +151,7 @@ func New(cfg config.WidgetConfig) (*Widget, error) {
142151 Renderer : mr .Renderer ,
143152 adapter : adapter ,
144153 metric : metric ,
154+ textFormat : textFormat ,
145155 reader : reader ,
146156 readerFailed : readerFailed ,
147157 history : util.NewRingBuffer [float64 ](mr .HistoryLen ),
@@ -203,11 +213,17 @@ func (w *Widget) Render() (image.Image, error) {
203213 return img , nil
204214 }
205215
216+ // Determine text format: use configured format for text mode, default for others
217+ textFmt := "%.0f"
218+ if w .textFormat != "" {
219+ textFmt = w .textFormat
220+ }
221+
206222 // Use strategy pattern for rendering
207223 w .strategy .Render (img , render.MetricData {
208224 Value : w .currentValue ,
209225 History : w .history .ToSlice (),
210- TextFormat : "%.0f" ,
226+ TextFormat : textFmt ,
211227 ContentArea : image .Rect (content .X , content .Y , content .X + content .Width , content .Y + content .Height ),
212228 GaugeArea : image .Rect (0 , 0 , pos .W , pos .H ),
213229 }, w .Renderer )
0 commit comments