Skip to content

Commit

Permalink
Added Measures for Driver Version and Date.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalilord committed Oct 7, 2020
1 parent c4d63b9 commit b894a4b
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 91 deletions.
55 changes: 39 additions & 16 deletions Common/adl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
interface

uses
Winapi.Windows, System.SysUtils, System.Generics.Collections, adl_structures, adl_defines, adl_sdk;
Winapi.Windows, System.SysUtils, System.Classes, System.Win.Registry, System.Generics.Collections, adl_structures, adl_defines, adl_sdk;

type
TADLAdapter = class
Expand Down Expand Up @@ -52,6 +52,8 @@ TADLAdapter = class
FBusSpeed: Integer;
FBusLanes: Integer;
FBusLanesMax: Integer;
FDriverDate: String;
FDriverVersion: String;
public
function IsLocation(ABusNumber, ADeviceNumber, AFunctionNumber: Integer): Boolean;
property PNP: String read FPNP;
Expand Down Expand Up @@ -81,6 +83,8 @@ TADLAdapter = class
property BusSpeed: Integer read FBusSpeed;
property BusLanes: Integer read FBusLanes;
property BusLanesMax: Integer read FBusLanesMax;
property DriverDate: String read FDriverDate;
property DriverVersion: String read FDriverVersion;
end;

TADL = class
Expand Down Expand Up @@ -225,6 +229,7 @@ procedure TADL.Initialize;

procedure TADL.Update;
var
Registry: TRegistry;
Adapter: TADLAdapter;
I, AdapterActive, IsSupported, IsEnabled, Version: Integer;
BiosInfo: TADLBiosInfo;
Expand Down Expand Up @@ -261,21 +266,39 @@ procedure TADL.Update;
FAdapter_MemoryInfo(AdapterInfo.iAdapterIndex, MemoryInfo);

Adapter:=TADLAdapter.Create;
Adapter.FBiosPartNumber:=String(AnsiString(BiosInfo.strPartNumber));
Adapter.FBiosVersion:=String(AnsiString(BiosInfo.strVersion));
Adapter.FBiosDate:=String(AnsiString(BiosInfo.strDate));
Adapter.FMemorySize:=MemoryInfo.iMemorySize;
Adapter.FMemoryType:=String(AnsiString(MemoryInfo.strMemoryType));
Adapter.FMemoryBandwidth:=MemoryInfo.iMemoryBandwidth;
Adapter.FIndex:=AdapterInfo.iAdapterIndex;
Adapter.FName:=String(AnsiString(AdapterInfo.strAdapterName));
Adapter.FPNP:=String(AnsiString(AdapterInfo.strPNPString));
Adapter.FDisplay:=String(AnsiString(AdapterInfo.strDisplayName));
Adapter.FBusNumber:=AdapterInfo.iBusNumber;
Adapter.FDeviceNumber:=AdapterInfo.iDeviceNumber;
Adapter.FFunctionNumber:=AdapterInfo.iFunctionNumber;
Adapter.FUpdate:=True;
FAdapters.Add(Adapter);
try
Adapter.FUpdate:=True;

Adapter.FBiosPartNumber:=String(AnsiString(BiosInfo.strPartNumber));
Adapter.FBiosVersion:=String(AnsiString(BiosInfo.strVersion));
Adapter.FBiosDate:=String(AnsiString(BiosInfo.strDate));
Adapter.FMemorySize:=MemoryInfo.iMemorySize;
Adapter.FMemoryType:=String(AnsiString(MemoryInfo.strMemoryType));
Adapter.FMemoryBandwidth:=MemoryInfo.iMemoryBandwidth;
Adapter.FIndex:=AdapterInfo.iAdapterIndex;
Adapter.FName:=String(AnsiString(AdapterInfo.strAdapterName));
Adapter.FPNP:=String(AnsiString(AdapterInfo.strPNPString));
Adapter.FDisplay:=String(AnsiString(AdapterInfo.strDisplayName));
Adapter.FBusNumber:=AdapterInfo.iBusNumber;
Adapter.FDeviceNumber:=AdapterInfo.iDeviceNumber;
Adapter.FFunctionNumber:=AdapterInfo.iFunctionNumber;

Registry:=TRegistry.Create(KEY_READ);
try
Registry.RootKey:=HKEY_LOCAL_MACHINE;
if Registry.OpenKey(StringReplace(String(AnsiString(PAnsiChar(@AdapterInfo.strDriverPath[0]))), '\Registry\Machine\', '', [rfIgnoreCase]), False) then
try
Adapter.FDriverDate:=Registry.ReadString('DriverDate');
Adapter.FDriverVersion:=Registry.ReadString('DriverVersion');
finally
Registry.CloseKey;
end;
finally
FreeAndNil(Registry);
end;
finally
FAdapters.Add(Adapter);
end;
end;

if Assigned(Adapter) AND Adapter.FUpdate then
Expand Down
49 changes: 42 additions & 7 deletions Common/d3dkmt.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@
interface

uses
Winapi.Windows, System.SysUtils, d3dkmthk;
Winapi.Windows, System.SysUtils, System.Classes, d3dkmthk;

type
TD3DKMTStatistics = class
private
FDeviceName: String;
FInitialized: Boolean;
FOpenAdapter: D3DKMT_OPENADAPTERFROMDEVICENAME;
FUsedMemory: UInt64;
FSegments: Cardinal;
FNodeCount: Cardinal;
FMemoryUsage: UInt64;
FSharedLimit: UInt64;
FDedicatedLimit: UInt64;
FSharedUsage: UInt64;
FDedicatedUsage: UInt64;
protected
procedure Initialize;
procedure Finalize;
public
constructor Create(ADevicePNP: String);
destructor Destroy; override;
procedure Update;
property UsedMemory: UInt64 read FUsedMemory;
property MemoryUsage: UInt64 read FMemoryUsage;
property SharedLimit: UInt64 read FSharedLimit;
property DedicatedLimit: UInt64 read FDedicatedLimit;
property SharedUsage: UInt64 read FSharedUsage;
property DedicatedUsage: UInt64 read FDedicatedUsage;
end;

implementation
Expand Down Expand Up @@ -76,14 +85,18 @@ procedure TD3DKMTStatistics.Initialize;

ZeroMemory(@FOpenAdapter, SizeOf(FOpenAdapter));
FOpenAdapter.pDeviceName:=PChar(FDeviceName);

if Succeeded(D3DKMTOpenAdapterFromDeviceName(FOpenAdapter)) then
begin
ZeroMemory(@QueryStats, SizeOf(QueryStats));
QueryStats.Typ:=D3DKMT_QUERYSTATISTICS_ADAPTER;
QueryStats.AdapterLuid:=FOpenAdapter.AdapterLuid;

if Succeeded(D3DKMTQueryStatistics(QueryStats)) then
FSegments:=QueryStats.QueryResult.AdapterInformation.NbSegments
else
begin
FSegments:=QueryStats.QueryResult.AdapterInformation.NbSegments;
FNodeCount:=QueryStats.QueryResult.AdapterInformation.NodeCount;
end else
Finalize;
end else
Finalize;
Expand All @@ -93,8 +106,13 @@ procedure TD3DKMTStatistics.Update;
var
I: Integer;
QueryStats: D3DKMT_QUERYSTATISTICS;
CommitLimit, BytesCommitted: UInt64;
begin
FUsedMemory:=0;
FMemoryUsage:=0;
FSharedLimit:=0;
FDedicatedLimit:=0;
FSharedUsage:=0;
FDedicatedUsage:=0;

if FInitialized then
begin
Expand All @@ -104,8 +122,25 @@ procedure TD3DKMTStatistics.Update;
QueryStats.Typ:=D3DKMT_QUERYSTATISTICS_SEGMENT;
QueryStats.AdapterLuid:=FOpenAdapter.AdapterLuid;
QueryStats.QuerySegment.SegmentId:=I;

if Succeeded(D3DKMTQueryStatistics(QueryStats)) then
Inc(FUsedMemory, QueryStats.QueryResult.SegmentInformation.BytesResident);
begin
Inc(FMemoryUsage, QueryStats.QueryResult.SegmentInformation.BytesResident);

CommitLimit:=QueryStats.QueryResult.SegmentInformation.CommitLimit;
BytesCommitted:=QueryStats.QueryResult.SegmentInformation.BytesCommitted;
BytesCommitted:=QueryStats.QueryResult.SegmentInformation.BytesResident;

if QueryStats.QueryResult.SegmentInformation.Aperture <> 0 then
begin
Inc(FSharedLimit, CommitLimit);
Inc(FSharedUsage, BytesCommitted);
end else
begin
Inc(FDedicatedLimit, CommitLimit);
Inc(FDedicatedUsage, BytesCommitted);
end;
end;
end;
end;
end;
Expand Down
108 changes: 50 additions & 58 deletions Plugin/AMDPlugin.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
{ }
{ AMDPlugin - Rainmeter AMD GPU Plugin }
{ }
{ Version 0.2 }
{ Version 0.3 }
{ }
{ 2020-10-07 - 0.3 }
{ Added "DriverDate" Measure }
{ Added "DriverVersion" Measure }
{ Added "SharedLimit" Measure }
{ Added "SharedUsage" Measure }
{ Added "DedicatedLimit" Measure }
{ Added "DedicatedUsage" Measure }
{ 2020-10-05 - 0.2 }
{ Added "MemoryUsage" Measure }
{ 2020-10-03 - 0.1 }
Expand Down Expand Up @@ -37,16 +44,16 @@ const
type
TMeasureID = (Unknown, Temperature, Clock, MemoryClock, Voltage, Activity, PerformanceLevel,
PCIECurrentBusSpeed, PCIECurrentBusLanes, PCIEMaxBusLanes, FanSpeedRPM, FanSpeedPercent, MemoryType,
MemorySize, MemoryUsage, MemoryBandwidth, AdapterName, AdapterActive, FanSpeedPercentMin, FanSpeedPercentMax,
FanSpeedRPMMin, FanSpeedRPMMax, BiosDate, BiosVersion, BiosPartNumber, AdapterIdentifier, NumberOfAdapters,
NumberOfDisplays);
MemorySize, MemoryUsage, SharedLimit, DedicatedLimit, SharedUsage, DedicatedUsage, MemoryBandwidth, AdapterName,
AdapterActive, FanSpeedPercentMin, FanSpeedPercentMax, FanSpeedRPMMin, FanSpeedRPMMax, BiosDate, BiosVersion,
BiosPartNumber, AdapterIdentifier, NumberOfAdapters, NumberOfDisplays, DriverDate, DriverVersion);

const
MEASUREID_NAMES: Array[TMeasureID] of String = ('Unknown', 'Temperature', 'Clock', 'MemoryClock', 'Voltage', 'Activity', 'PerformanceLevel',
'PCIECurrentBusSpeed', 'PCIECurrentBusLanes', 'PCIEMaxBusLanes', 'FanSpeedRPM', 'FanSpeedPercent', 'MemoryType',
'MemorySize', 'MemoryUsage', 'MemoryBandwidth', 'AdapterName', 'AdapterActive', 'FanSpeedPercentMin', 'FanSpeedPercentMax',
'FanSpeedRPMMin', 'FanSpeedRPMMax', 'BiosDate', 'BiosVersion', 'BiosPartNumber', 'AdapterIdentifier', 'NumberOfAdapters',
'NumberOfDisplays');
'MemorySize', 'MemoryUsage', 'SharedLimit', 'DedicatedLimit', 'SharedUsage', 'DedicatedUsage', 'MemoryBandwidth', 'AdapterName',
'AdapterActive', 'FanSpeedPercentMin', 'FanSpeedPercentMax', 'FanSpeedRPMMin', 'FanSpeedRPMMax', 'BiosDate', 'BiosVersion',
'BiosPartNumber', 'AdapterIdentifier', 'NumberOfAdapters', 'NumberOfDisplays', 'DriverDate', 'DriverVersion');

type
TMeasure = class
Expand Down Expand Up @@ -108,15 +115,17 @@ begin
MeasureUpdate;

Measure:=TMeasure.Create;
Measure.Name:=RmReadString(ARm, 'MeasureID', '', True);
Measure.ID:=TMeasureID(Max(0, IndexStr(Measure.Name, MEASUREID_NAMES)));
Measure.Adapter:=Trunc(RmReadFormula(ARm, 'AdapterID', 0));

if Measure.ID = MemoryUsage then
if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
Measure.D3DKMT:=TD3DKMTStatistics.Create(ADL.Adapters[Measure.Adapter].PNP);

List.Add(Measure);
try
Measure.Name:=RmReadString(ARm, 'MeasureID', '', True);
Measure.ID:=TMeasureID(Max(0, IndexStr(Measure.Name, MEASUREID_NAMES)));
Measure.Adapter:=Trunc(RmReadFormula(ARm, 'AdapterID', 0));

if Measure.ID IN [MemoryUsage, SharedLimit, DedicatedLimit, SharedUsage, DedicatedUsage] then
if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
Measure.D3DKMT:=TD3DKMTStatistics.Create(ADL.Adapters[Measure.Adapter].PNP);
finally
List.Add(Measure);
end;

AData:=Measure;
end;
Expand All @@ -141,7 +150,6 @@ begin
if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
begin
case Measure.ID of
Unknown : ;
Temperature : Result:=ADL.Adapters[Measure.Adapter].Temp;
Clock : Result:=ADL.Adapters[Measure.Adapter].Clock;
MemoryClock : Result:=ADL.Adapters[Measure.Adapter].Memory;
Expand All @@ -153,22 +161,18 @@ begin
PCIEMaxBusLanes : Result:=ADL.Adapters[Measure.Adapter].BusLanesMax;
FanSpeedRPM : Result:=ADL.Adapters[Measure.Adapter].FanRPM;
FanSpeedPercent : Result:=ADL.Adapters[Measure.Adapter].Fan;
MemoryType : ;
MemorySize : Result:=ADL.Adapters[Measure.Adapter].MemorySize;
MemoryUsage : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.UsedMemory;
MemoryUsage : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.MemoryUsage;
SharedLimit : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.SharedLimit;
DedicatedLimit : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.DedicatedLimit;
SharedUsage : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.SharedUsage;
DedicatedUsage : if Assigned(Measure.D3DKMT) then Result:=Measure.D3DKMT.DedicatedUsage;
MemoryBandwidth : Result:=ADL.Adapters[Measure.Adapter].MemoryBandwidth;
AdapterName : ;
AdapterActive : ;
FanSpeedPercentMin : Result:=0;
FanSpeedPercentMax : Result:=100;
FanSpeedRPMMin : Result:=0;
FanSpeedRPMMax : Result:=ADL.Adapters[Measure.Adapter].FanMaxRPM;
BiosDate : ;
BiosVersion : ;
BiosPartNumber : ;
AdapterIdentifier : ;
NumberOfAdapters : Result:=ADL.AdapterCount;
NumberOfDisplays : ;
end;
end;
end;
Expand All @@ -189,50 +193,38 @@ begin
if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
begin
case Measure.ID of
Unknown : ;
Temperature : ;
Clock : ;
MemoryClock : ;
Voltage : ;
Activity : ;
PerformanceLevel : ;
PCIECurrentBusSpeed : ;
PCIECurrentBusLanes : ;
PCIEMaxBusLanes : ;
FanSpeedRPM : ;
FanSpeedPercent : ;
MemoryType : Result:=PWideChar(ADL.Adapters[Measure.Adapter].MemoryType);
MemorySize : ;
MemoryUsage : ;
MemoryBandwidth : ;
AdapterName : Result:=PWideChar(ADL.Adapters[Measure.Adapter].Name);
AdapterActive : ;
FanSpeedPercentMin : ;
FanSpeedPercentMax : ;
FanSpeedRPMMin : ;
FanSpeedRPMMax : ;
BiosDate : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosDate);
BiosVersion : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosVersion);
BiosPartNumber : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosPartNumber);
AdapterIdentifier : ;
NumberOfAdapters : ;
NumberOfDisplays : ;
MemoryType : Result:=PWideChar(ADL.Adapters[Measure.Adapter].MemoryType);
AdapterName : Result:=PWideChar(ADL.Adapters[Measure.Adapter].Name);
BiosDate : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosDate);
BiosVersion : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosVersion);
BiosPartNumber : Result:=PWideChar(ADL.Adapters[Measure.Adapter].BiosPartNumber);
DriverDate : Result:=PWideChar(ADL.Adapters[Measure.Adapter].DriverDate);
DriverVersion : Result:=PWideChar(ADL.Adapters[Measure.Adapter].DriverVersion);
end;
end;
end;
end;

procedure Finalize(AData: Pointer); stdcall;
procedure Finalize(AData: Pointer); stdcall
var
Measure: TMeasure;
begin
if Assigned(List) then
if Assigned(AData) then
begin
Measure:=List.Extract(AData);
if Assigned(Measure) then
Measure.Free;
end;

if Assigned(List) AND (List.Count = 0) then
FreeAndNil(List);
if Assigned(ADL) then
if Assigned(ADL) AND NOT Assigned(List) then
FreeAndNil(ADL);
end;

function GetPluginVersion: Cardinal; stdcall;
begin
Result:=2;
Result:=3;
end;

function GetPluginAuthor: PWideChar; stdcall;
Expand Down
10 changes: 6 additions & 4 deletions Plugin/AMDPlugin.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@
<DCC_DebugInformation>0</DCC_DebugInformation>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.0.21;InternalName=$(MSBuildProjectName);LegalCopyright=(c) 2020 by NaliLord;OriginalFilename=AMDPlugin.dll;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=Rainmeter AMD GPU Plugin;ProductVersion=1.0.0.0</VerInfo_Keys>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.3.2;InternalName=$(MSBuildProjectName);LegalCopyright=(c) 2020 by NaliLord;OriginalFilename=AMDPlugin.dll;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=Rainmeter AMD GPU Plugin;ProductVersion=1.0.0.0</VerInfo_Keys>
<Manifest_File>(None)</Manifest_File>
<VerInfo_Build>21</VerInfo_Build>
<VerInfo_Build>2</VerInfo_Build>
<VerInfo_Release>3</VerInfo_Release>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<Manifest_File>(None)</Manifest_File>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.0.28;InternalName=$(MSBuildProjectName);LegalCopyright=(c) 2020 by NaliLord;OriginalFilename=AMDPlugin.dll;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=Rainmeter AMD GPU Plugin;ProductVersion=1.0.0.0</VerInfo_Keys>
<VerInfo_Build>28</VerInfo_Build>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.3.2;InternalName=$(MSBuildProjectName);LegalCopyright=(c) 2020 by NaliLord;OriginalFilename=AMDPlugin.dll;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=Rainmeter AMD GPU Plugin;ProductVersion=1.0.0.0</VerInfo_Keys>
<VerInfo_Build>2</VerInfo_Build>
<VerInfo_Release>3</VerInfo_Release>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
Expand Down
Binary file modified Plugin/AMDPlugin.res
Binary file not shown.
Loading

0 comments on commit b894a4b

Please sign in to comment.