@@ -105,14 +105,19 @@ FF_MAYBE_UNUSED static const char* drmFindRenderFromCard(const char* drmCardKey,
105105
106106static const char * drmDetectAmdSpecific (const FFGPUOptions * options , FFGPUResult * gpu , const char * drmKey , FFstrbuf * buffer )
107107{
108- #if FF_HAVE_DRM_AMDGPU
109108 const char * error = drmFindRenderFromCard (drmKey , buffer );
110109 if (error ) return error ;
111- return ffDrmDetectAmdgpu (options , gpu , buffer -> chars );
112- #else
113- FF_UNUSED (options , gpu , drmKey , buffer );
114- return "Fastfetch is not compiled with libdrm_amdgpu support" ;
110+ if (ffStrbufEqualS (& gpu -> driver , "radeon" ))
111+ return ffDrmDetectRadeon (options , gpu , buffer -> chars );
112+ else
113+ {
114+ #if FF_HAVE_DRM_AMDGPU
115+ return ffDrmDetectAmdgpu (options , gpu , buffer -> chars );
116+ #else
117+ FF_UNUSED (options , gpu , drmKey , buffer );
118+ return "Fastfetch is not compiled with libdrm_amdgpu support" ;
115119#endif
120+ }
116121}
117122
118123static void pciDetectAmdSpecific (const FFGPUOptions * options , FFGPUResult * gpu , FFstrbuf * pciDir , FFstrbuf * buffer )
@@ -135,47 +140,50 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu,
135140 ffStrbufAppendC (pciDir , '/' );
136141
137142 const uint32_t hwmonLen = pciDir -> length ;
138- ffStrbufAppendS (pciDir , "in1_input" ); // Northbridge voltage in millivolts (APUs only)
139- if (ffPathExists (pciDir -> chars , FF_PATHTYPE_ANY ))
140- gpu -> type = FF_GPU_TYPE_INTEGRATED ;
141- else
142- gpu -> type = FF_GPU_TYPE_DISCRETE ;
143-
144143 uint64_t value = 0 ;
145144 if (options -> temp )
146145 {
147- ffStrbufSubstrBefore (pciDir , hwmonLen );
148146 ffStrbufAppendS (pciDir , "temp1_input" ); // The on die GPU temperature in millidegrees Celsius
149147 if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
150148 gpu -> temperature = (double ) value / 1000 ;
151149 }
152150
153- if (options -> driverSpecific )
151+ if (ffStrbufEqualS ( & gpu -> driver , "amdgpu" )) // Ancient radeon drivers don't have these files
154152 {
155- ffStrbufSubstrBefore (pciDir , pciDirLen );
156- ffStrbufAppendS (pciDir , "/mem_info_vis_vram_total" );
157- if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
158- {
159- if (gpu -> type == FF_GPU_TYPE_DISCRETE )
160- gpu -> dedicated .total = value ;
161- else
162- gpu -> shared .total = value ;
153+ ffStrbufSubstrBefore (pciDir , hwmonLen );
154+ ffStrbufAppendS (pciDir , "in1_input" ); // Northbridge voltage in millivolts (APUs only)
155+ if (ffPathExists (pciDir -> chars , FF_PATHTYPE_ANY ))
156+ gpu -> type = FF_GPU_TYPE_INTEGRATED ;
157+ else
158+ gpu -> type = FF_GPU_TYPE_DISCRETE ;
163159
164- ffStrbufSubstrBefore (pciDir , pciDir -> length - (uint32_t ) strlen ("/mem_info_vis_vram_total" ));
165- ffStrbufAppendS (pciDir , "/mem_info_vis_vram_used" );
160+ if (options -> driverSpecific )
161+ {
162+ ffStrbufSubstrBefore (pciDir , pciDirLen );
163+ ffStrbufAppendS (pciDir , "/mem_info_vis_vram_total" );
166164 if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
167165 {
168166 if (gpu -> type == FF_GPU_TYPE_DISCRETE )
169- gpu -> dedicated .used = value ;
167+ gpu -> dedicated .total = value ;
170168 else
171- gpu -> shared .used = value ;
169+ gpu -> shared .total = value ;
170+
171+ ffStrbufSubstrBefore (pciDir , pciDir -> length - (uint32_t ) strlen ("/mem_info_vis_vram_total" ));
172+ ffStrbufAppendS (pciDir , "/mem_info_vis_vram_used" );
173+ if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
174+ {
175+ if (gpu -> type == FF_GPU_TYPE_DISCRETE )
176+ gpu -> dedicated .used = value ;
177+ else
178+ gpu -> shared .used = value ;
179+ }
172180 }
173- }
174181
175- ffStrbufSubstrBefore (pciDir , pciDirLen );
176- ffStrbufAppendS (pciDir , "/gpu_busy_percent" );
177- if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
178- gpu -> coreUsage = (double ) value ;
182+ ffStrbufSubstrBefore (pciDir , pciDirLen );
183+ ffStrbufAppendS (pciDir , "/gpu_busy_percent" );
184+ if (ffReadFileBuffer (pciDir -> chars , buffer ) && (value = ffStrbufToUInt (buffer , 0 )))
185+ gpu -> coreUsage = (double ) value ;
186+ }
179187 }
180188}
181189
0 commit comments