Skip to content

Commit

Permalink
Corrected the Shared/Dedicated Usage/Limit values.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalilord committed Nov 8, 2020
1 parent b894a4b commit 9d86179
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 76 deletions.
30 changes: 18 additions & 12 deletions Common/d3dkmt.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ procedure TD3DKMTStatistics.Finalize;
procedure TD3DKMTStatistics.Initialize;
var
QueryStats: D3DKMT_QUERYSTATISTICS;
QueryAdapterInfo: D3DKMT_QUERYADAPTERINFO;
SegmentInfo: D3DKMT_SEGMENTSIZEINFO;
begin
FInitialized:=True;

Expand All @@ -96,6 +98,20 @@ procedure TD3DKMTStatistics.Initialize;
begin
FSegments:=QueryStats.QueryResult.AdapterInformation.NbSegments;
FNodeCount:=QueryStats.QueryResult.AdapterInformation.NodeCount;

ZeroMemory(@QueryAdapterInfo, SizeOf(QueryAdapterInfo));
ZeroMemory(@SegmentInfo, SizeOf(SegmentInfo));

QueryAdapterInfo.hAdapter:=FOpenAdapter.hAdapter;
QueryAdapterInfo.aType:=KMTQAITYPE_GETSEGMENTSIZE;
QueryAdapterInfo.pPrivateDriverData:=@SegmentInfo;
QueryAdapterInfo.PrivateDriverDataSize:=SizeOf(SegmentInfo);

if Succeeded(D3DKMTQueryAdapterInfo(QueryAdapterInfo)) then
begin
FDedicatedLimit:=SegmentInfo.DedicatedVideoMemorySize;
FSharedLimit:=SegmentInfo.SharedSystemMemorySize;
end;
end else
Finalize;
end else
Expand All @@ -109,8 +125,6 @@ procedure TD3DKMTStatistics.Update;
CommitLimit, BytesCommitted: UInt64;
begin
FMemoryUsage:=0;
FSharedLimit:=0;
FDedicatedLimit:=0;
FSharedUsage:=0;
FDedicatedUsage:=0;

Expand All @@ -127,19 +141,11 @@ procedure TD3DKMTStatistics.Update;
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(FSharedUsage, BytesCommitted)
else
Inc(FDedicatedUsage, BytesCommitted);
end;
end;
end;
end;
Expand Down
6 changes: 6 additions & 0 deletions Common/d3dkmthk.pas
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ D3DKMT_CLOSEADAPTER = record
hAdapter: ULONG; // in: adapter handle
end;

D3DKMT_SEGMENTSIZEINFO = record
DedicatedVideoMemorySize: ULONGLONG; // The size, in bytes, of memory that is dedicated from video memory.
DedicatedSystemMemorySize: ULONGLONG; // The size, in bytes, of memory that is dedicated from system memory.
SharedSystemMemorySize: ULONGLONG; // The size, in bytes, of memory from system memory that can be shared by many users.
end;

function D3DKMTQueryAdapterInfo(var Adapter: D3DKMT_QUERYADAPTERINFO): HRESULT; stdcall; external 'gdi32.dll';
function D3DKMTOpenAdapterFromHdc(var Adapter: D3DKMT_OPENADAPTERFROMHDC): HRESULT; stdcall; external 'gdi32.dll';
function D3DKMTOpenAdapterFromGdiDisplayName(var Adapter: D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME): HRESULT; stdcall; external 'gdi32.dll';
Expand Down
30 changes: 30 additions & 0 deletions Plugin/AMDPlugin.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ procedure Initialize(var AData: Pointer; ARm: Pointer); stdcall;
var
Measure: TMeasure;
begin
// AllocConsole;

// WriteLn('Initialize ->');

if NOT Assigned(ADL) then
ADL:=TADL.Create;
if NOT Assigned(List) then
Expand All @@ -120,6 +124,9 @@ begin
Measure.ID:=TMeasureID(Max(0, IndexStr(Measure.Name, MEASUREID_NAMES)));
Measure.Adapter:=Trunc(RmReadFormula(ARm, 'AdapterID', 0));

// WriteLn(' Name=', Measure.Name);
// WriteLn(' Adapter=', Measure.Adapter);

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);
Expand All @@ -128,6 +135,7 @@ begin
end;

AData:=Measure;
// WriteLn('<- Initialize');
end;

procedure Reload(AData: Pointer; ARm: Pointer; var AMaxValue: Double); stdcall;
Expand All @@ -139,6 +147,7 @@ function Update(AData: Pointer): Double; stdcall;
var
Measure: TMeasure;
begin
// WriteLn('Update ->');
Result:=0.0;

if Assigned(AData) then
Expand All @@ -147,8 +156,13 @@ begin

MeasureUpdate(Measure);

// WriteLn(' Measure: 0x', IntToHex(NativeInt(Measure), SizeOf(NativeInt) * 2));

if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
begin
// WriteLn(Format(' Name=%s'#13#10' Adapter=%d'#13#10' Count=%d', [Measure.Name, Measure.Adapter, ADL.AdapterCount]));
// WriteLn(Format(' D3DKMT=%s', [BoolToStr(Assigned(Measure.D3DKMT), True)]));

case Measure.ID of
Temperature : Result:=ADL.Adapters[Measure.Adapter].Temp;
Clock : Result:=ADL.Adapters[Measure.Adapter].Clock;
Expand Down Expand Up @@ -176,12 +190,16 @@ begin
end;
end;
end;

// WriteLn(' Value=', FormatFloat('0.00', Result));
// WriteLn('<- Update');
end;

function GetString(AData: Pointer): PWideChar; stdcall;
var
Measure: TMeasure;
begin
// WriteLn('GetString ->');
Result:=nil;

if Assigned(AData) then
Expand All @@ -190,8 +208,13 @@ begin

MeasureUpdate(Measure);

// WriteLn(' Measure: 0x', IntToHex(NativeInt(Measure), SizeOf(NativeInt) * 2));

if (Measure.Adapter >= 0) AND (Measure.Adapter < ADL.AdapterCount) then
begin
// WriteLn(Format(' Name=%s'#13#10' Adapter=%d'#13#10' Count=%d', [Measure.Name, Measure.Adapter, ADL.AdapterCount]));
// WriteLn(Format(' D3DKMT=%s', [BoolToStr(Assigned(Measure.D3DKMT), True)]));

case Measure.ID of
MemoryType : Result:=PWideChar(ADL.Adapters[Measure.Adapter].MemoryType);
AdapterName : Result:=PWideChar(ADL.Adapters[Measure.Adapter].Name);
Expand All @@ -203,6 +226,13 @@ begin
end;
end;
end;

// if Assigned(Result) then
// WriteLn(' Value=', Result)
// else
// WriteLn(' Value=<null>');

// WriteLn('<- GetString');
end;

procedure Finalize(AData: Pointer); stdcall
Expand Down
16 changes: 8 additions & 8 deletions Plugin/AMDPlugin.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
<Manifest_File>(None)</Manifest_File>
<Debugger_HostApplication>C:\Program Files\Rainmeter\Rainmeter.exe</Debugger_HostApplication>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.0.6;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>6</VerInfo_Build>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.0.8;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>8</VerInfo_Build>
<DCC_ExeOutput>$(APPDATA)\Rainmeter\Plugins</DCC_ExeOutput>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
Expand All @@ -124,16 +124,16 @@
<DCC_DebugInformation>0</DCC_DebugInformation>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<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_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.4.1;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>2</VerInfo_Build>
<VerInfo_Release>3</VerInfo_Release>
<VerInfo_Release>4</VerInfo_Release>
<VerInfo_Build>1</VerInfo_Build>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<Manifest_File>(None)</Manifest_File>
<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>
<VerInfo_Keys>FileDescription=$(MSBuildProjectName) $(Platform) $(Config);FileVersion=1.0.4.1;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_Release>4</VerInfo_Release>
<VerInfo_Build>1</VerInfo_Build>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
Expand Down
Binary file modified Plugin/AMDPlugin.res
Binary file not shown.
152 changes: 97 additions & 55 deletions Testing/Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object frmMain: TfrmMain
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = 'AMD GPU Info'
ClientHeight = 327
ClientWidth = 185
ClientHeight = 215
ClientWidth = 456
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Expand Down Expand Up @@ -74,7 +74,7 @@ object frmMain: TfrmMain
end
object btnGetInfo: TButton
Left = 8
Top = 268
Top = 155
Width = 80
Height = 25
Caption = 'Start'
Expand Down Expand Up @@ -107,7 +107,7 @@ object frmMain: TfrmMain
end
object Button1: TButton
Left = 94
Top = 268
Top = 155
Width = 80
Height = 25
Caption = 'Stop'
Expand All @@ -132,8 +132,8 @@ object frmMain: TfrmMain
end
object TrackBar1: TTrackBar
Left = 0
Top = 296
Width = 185
Top = 184
Width = 456
Height = 31
Align = alBottom
Max = 1000
Expand All @@ -142,7 +142,6 @@ object frmMain: TfrmMain
TabOrder = 7
TickMarks = tmBoth
TickStyle = tsNone
ExplicitTop = 185
end
object edVRAM: TEdit
Left = 56
Expand All @@ -152,55 +151,98 @@ object frmMain: TfrmMain
TabOrder = 8
Text = 'n/a'
end
object lblMemoryUsage: TStaticText
Left = 8
Top = 155
Width = 169
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = 'lblMemoryUsage'
object GroupBox1: TGroupBox
Left = 183
Top = 8
Width = 265
Height = 141
Caption = ' TD3DKMT Memory Info '
TabOrder = 9
end
object lblSharedLimit: TStaticText
Left = 8
Top = 176
Width = 169
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = 'lblSharedLimit'
TabOrder = 10
end
object lblDedicatedLimit: TStaticText
Left = 8
Top = 199
Width = 169
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = 'lblDedicatedLimit'
TabOrder = 11
end
object lblSharedUsage: TStaticText
Left = 8
Top = 222
Width = 169
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = 'lblSharedUsage'
TabOrder = 12
end
object lblDedicatedUsage: TStaticText
Left = 8
Top = 245
Width = 169
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = 'lblDedicatedUsage'
TabOrder = 13
object Label5: TLabel
Left = 12
Top = 24
Width = 75
Height = 13
Caption = 'Memory Usage:'
end
object Label6: TLabel
Left = 12
Top = 45
Width = 62
Height = 13
Caption = 'Shared Limit:'
end
object Label7: TLabel
Left = 12
Top = 68
Width = 76
Height = 13
Caption = 'Dedicated Limit:'
end
object Label8: TLabel
Left = 12
Top = 91
Width = 71
Height = 13
Caption = 'Shared Usage:'
end
object Label9: TLabel
Left = 12
Top = 114
Width = 85
Height = 13
Caption = 'Dedicated Usage:'
end
object lblMemoryUsage: TStaticText
Left = 104
Top = 24
Width = 158
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = '-'
TabOrder = 0
end
object lblSharedLimit: TStaticText
Left = 104
Top = 45
Width = 158
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = '-'
TabOrder = 1
end
object lblDedicatedLimit: TStaticText
Left = 104
Top = 68
Width = 158
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = '-'
TabOrder = 2
end
object lblSharedUsage: TStaticText
Left = 103
Top = 91
Width = 159
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = '-'
TabOrder = 3
end
object lblDedicatedUsage: TStaticText
Left = 103
Top = 114
Width = 159
Height = 17
AutoSize = False
BorderStyle = sbsSunken
Caption = '-'
TabOrder = 4
end
end
object tmrUpdate: TTimer
Enabled = False
Expand Down
Loading

0 comments on commit 9d86179

Please sign in to comment.