mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 689870 - Add d3dkmtQueryStatistics.h and enable GPU reporter for Win7+. r=jrmuizel
This commit is contained in:
parent
f5117c4b6d
commit
de36de0e46
157
gfx/thebes/d3dkmtQueryStatistics.h
Normal file
157
gfx/thebes/d3dkmtQueryStatistics.h
Normal file
@ -0,0 +1,157 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/* This file is based on a header file that was briefly seen in the
|
||||
* Windows 8 RC SDK. The work for this file itself was based on the one in ProcessHacker at
|
||||
* http://processhacker.svn.sourceforge.net/viewvc/processhacker/2.x/trunk/plugins/ExtendedTools/d3dkmt.h?revision=4758&view=markup
|
||||
* For more details see Mozilla Bug 689870.
|
||||
*/
|
||||
|
||||
typedef struct _D3DKMTQS_COUNTER
|
||||
{
|
||||
ULONG Count;
|
||||
ULONGLONG Bytes;
|
||||
} D3DKMTQS_COUNTER;
|
||||
|
||||
typedef struct _D3DKMTQS_ADAPTER_INFO
|
||||
{
|
||||
ULONG NbSegments;
|
||||
|
||||
ULONG Filler[4];
|
||||
ULONGLONG Filler2[2]; // Assumed sizeof(LONGLONG) = sizeof(ULONGLONG)
|
||||
struct {
|
||||
ULONG Filler[14];
|
||||
} Filler_RDMAB;
|
||||
struct {
|
||||
ULONG Filler[9];
|
||||
} Filler_R;
|
||||
struct {
|
||||
ULONG Filler[4];
|
||||
D3DKMTQS_COUNTER Filler2;
|
||||
} Filler_P;
|
||||
struct {
|
||||
D3DKMTQS_COUNTER Filler[16];
|
||||
ULONG Filler2[2];
|
||||
} Filler_PF;
|
||||
struct {
|
||||
ULONGLONG Filler[8];
|
||||
} Filler_PT;
|
||||
struct {
|
||||
ULONG Filler[2];
|
||||
} Filler_SR;
|
||||
struct {
|
||||
ULONG Filler[7];
|
||||
} Filler_L;
|
||||
struct {
|
||||
D3DKMTQS_COUNTER Filler[7];
|
||||
} Filler_A;
|
||||
struct {
|
||||
D3DKMTQS_COUNTER Filler[4];
|
||||
} Filler_T;
|
||||
ULONG64 Reserved[8];
|
||||
} D3DKMTQS_ADAPTER_INFO;
|
||||
|
||||
typedef struct _D3DKMTQS_SEGMENT_INFO_WIN7
|
||||
{
|
||||
ULONG Filler[3];
|
||||
struct {
|
||||
ULONGLONG Filler;
|
||||
ULONG Filler2[2];
|
||||
} Filler_M;
|
||||
|
||||
ULONG Aperture;
|
||||
|
||||
ULONGLONG Filler3[5];
|
||||
ULONG64 Filler4[8];
|
||||
} D3DKMTQS_SEGMENT_INFO_WIN7;
|
||||
|
||||
typedef struct _D3DKMTQS_SEGMENT_INFO_WIN8
|
||||
{
|
||||
ULONGLONG Filler[3];
|
||||
struct {
|
||||
ULONGLONG Filler;
|
||||
ULONG Filler2[2];
|
||||
} Filler_M;
|
||||
|
||||
ULONG Aperture;
|
||||
|
||||
ULONGLONG Filler3[5];
|
||||
ULONG64 Filler4[8];
|
||||
} D3DKMTQS_SEGMENT_INFO_WIN8;
|
||||
|
||||
typedef struct _D3DKMTQS_SYSTEM_MEMORY
|
||||
{
|
||||
ULONGLONG BytesAllocated;
|
||||
ULONG Filler[2];
|
||||
ULONGLONG Filler2[7];
|
||||
} D3DKMTQS_SYSTEM_MEMORY;
|
||||
|
||||
typedef struct _D3DKMTQS_PROCESS_INFO
|
||||
{
|
||||
ULONG Filler[2];
|
||||
struct {
|
||||
ULONGLONG BytesAllocated;
|
||||
|
||||
ULONG Filler[2];
|
||||
ULONGLONG Filler2[7];
|
||||
} SystemMemory;
|
||||
ULONG64 Reserved[8];
|
||||
} D3DKMTQS_PROCESS_INFO;
|
||||
|
||||
typedef struct _D3DKMTQS_PROCESS_SEGMENT_INFO
|
||||
{
|
||||
ULONGLONG BytesCommitted;
|
||||
|
||||
ULONGLONG Filler[2];
|
||||
ULONG Filler2;
|
||||
struct {
|
||||
ULONG Filler;
|
||||
D3DKMTQS_COUNTER Filler2[6];
|
||||
ULONGLONG Filler3;
|
||||
} Filler3;
|
||||
struct {
|
||||
ULONGLONG Filler;
|
||||
} Filler4;
|
||||
ULONG64 Reserved[8];
|
||||
} D3DKMTQS_PROCESS_SEGMENT_INFO;
|
||||
|
||||
typedef enum _D3DKMTQS_TYPE
|
||||
{
|
||||
D3DKMTQS_ADAPTER = 0,
|
||||
D3DKMTQS_PROCESS = 1,
|
||||
D3DKMTQS_SEGMENT = 3,
|
||||
D3DKMTQS_PROCESS_SEGMENT = 4,
|
||||
} D3DKMTQS_TYPE;
|
||||
|
||||
typedef union _D3DKMTQS_RESULT
|
||||
{
|
||||
D3DKMTQS_ADAPTER_INFO AdapterInfo;
|
||||
D3DKMTQS_SEGMENT_INFO_WIN7 SegmentInfoWin7;
|
||||
D3DKMTQS_SEGMENT_INFO_WIN8 SegmentInfoWin8;
|
||||
D3DKMTQS_PROCESS_INFO ProcessInfo;
|
||||
D3DKMTQS_PROCESS_SEGMENT_INFO ProcessSegmentInfo;
|
||||
} D3DKMTQS_RESULT;
|
||||
|
||||
typedef struct _D3DKMTQS_QUERY_SEGMENT
|
||||
{
|
||||
ULONG SegmentId;
|
||||
} D3DKMTQS_QUERY_SEGMENT;
|
||||
|
||||
typedef struct _D3DKMTQS
|
||||
{
|
||||
__in D3DKMTQS_TYPE Type;
|
||||
__in LUID AdapterLuid;
|
||||
__in_opt HANDLE hProcess;
|
||||
__out D3DKMTQS_RESULT QueryResult;
|
||||
|
||||
union
|
||||
{
|
||||
__in D3DKMTQS_QUERY_SEGMENT QuerySegment;
|
||||
__in D3DKMTQS_QUERY_SEGMENT QueryProcessSegment;
|
||||
};
|
||||
} D3DKMTQS;
|
||||
|
||||
extern "C" {
|
||||
typedef __checkReturn NTSTATUS (APIENTRY *PFND3DKMTQS)(__in const D3DKMTQS *);
|
||||
}
|
@ -53,34 +53,9 @@ using namespace mozilla::gfx;
|
||||
#include "nsMemory.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Required headers are not available in the current consumer preview Win8
|
||||
* dev kit, disabling for now.
|
||||
*/
|
||||
#undef MOZ_WINSDK_TARGETVER
|
||||
|
||||
/**
|
||||
* XXX below should be >= MOZ_NTDDI_WIN8 or such which is not defined yet
|
||||
*/
|
||||
#if MOZ_WINSDK_TARGETVER > MOZ_NTDDI_WIN7
|
||||
#define ENABLE_GPU_MEM_REPORTER
|
||||
#endif
|
||||
|
||||
#if defined CAIRO_HAS_D2D_SURFACE || defined ENABLE_GPU_MEM_REPORTER
|
||||
#include "nsIMemoryReporter.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GPU_MEM_REPORTER
|
||||
#include <winternl.h>
|
||||
|
||||
/**
|
||||
* XXX need to check that extern C is really needed with Win8 SDK.
|
||||
* It was required for files I had available at push time.
|
||||
*/
|
||||
extern "C" {
|
||||
#include <d3dkmthk.h>
|
||||
}
|
||||
#endif
|
||||
#include "d3dkmtQueryStatistics.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
@ -190,7 +165,6 @@ typedef HRESULT(WINAPI*CreateDXGIFactory1Func)(
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GPU_MEM_REPORTER
|
||||
class GPUAdapterMultiReporter : public nsIMemoryMultiReporter {
|
||||
|
||||
// Callers must Release the DXGIAdapter after use or risk mem-leak
|
||||
@ -212,6 +186,14 @@ class GPUAdapterMultiReporter : public nsIMemoryMultiReporter {
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIMemoryMultiReporter abstract method implementation
|
||||
NS_IMETHOD
|
||||
GetName(nsACString &aName)
|
||||
{
|
||||
aName.AssignLiteral("gpuadapter");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIMemoryMultiReporter abstract method implementation
|
||||
NS_IMETHOD
|
||||
@ -227,7 +209,7 @@ public:
|
||||
IDXGIAdapter *DXGIAdapter;
|
||||
|
||||
HMODULE gdi32Handle;
|
||||
PFND3DKMT_QUERYSTATISTICS queryD3DKMTStatistics;
|
||||
PFND3DKMTQS queryD3DKMTStatistics;
|
||||
|
||||
winVers = gfxWindowsPlatform::WindowsOSVersion(&buildNum);
|
||||
|
||||
@ -236,35 +218,35 @@ public:
|
||||
return NS_OK;
|
||||
|
||||
if (gdi32Handle = LoadLibrary(TEXT("gdi32.dll")))
|
||||
queryD3DKMTStatistics = (PFND3DKMT_QUERYSTATISTICS)GetProcAddress(gdi32Handle, "D3DKMTQueryStatistics");
|
||||
queryD3DKMTStatistics = (PFND3DKMTQS)GetProcAddress(gdi32Handle, "D3DKMTQueryStatistics");
|
||||
|
||||
if (queryD3DKMTStatistics && GetDXGIAdapter(&DXGIAdapter)) {
|
||||
// Most of this block is understood thanks to wj32's work on Process Hacker
|
||||
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
D3DKMT_QUERYSTATISTICS queryStatistics;
|
||||
D3DKMTQS queryStatistics;
|
||||
|
||||
DXGIAdapter->GetDesc(&adapterDesc);
|
||||
DXGIAdapter->Release();
|
||||
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
|
||||
queryStatistics.Type = D3DKMT_QUERYSTATISTICS_PROCESS;
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
||||
queryStatistics.Type = D3DKMTQS_PROCESS;
|
||||
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
||||
queryStatistics.hProcess = ProcessHandle;
|
||||
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
||||
committedBytesUsed = queryStatistics.QueryResult.ProcessInformation.SystemMemory.BytesAllocated;
|
||||
committedBytesUsed = queryStatistics.QueryResult.ProcessInfo.SystemMemory.BytesAllocated;
|
||||
}
|
||||
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
|
||||
queryStatistics.Type = D3DKMT_QUERYSTATISTICS_ADAPTER;
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
||||
queryStatistics.Type = D3DKMTQS_ADAPTER;
|
||||
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
||||
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
||||
ULONG i;
|
||||
ULONG segmentCount = queryStatistics.QueryResult.AdapterInformation.NbSegments;
|
||||
ULONG segmentCount = queryStatistics.QueryResult.AdapterInfo.NbSegments;
|
||||
|
||||
for (i = 0; i < segmentCount; i++) {
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
|
||||
queryStatistics.Type = D3DKMT_QUERYSTATISTICS_SEGMENT;
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
||||
queryStatistics.Type = D3DKMTQS_SEGMENT;
|
||||
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
||||
queryStatistics.QuerySegment.SegmentId = i;
|
||||
|
||||
@ -272,24 +254,24 @@ public:
|
||||
bool aperture;
|
||||
|
||||
// SegmentInformation has a different definition in Win7 than later versions
|
||||
if (winVers > gfxWindowsPlatform::kWindows7)
|
||||
aperture = queryStatistics.QueryResult.SegmentInformation.Aperture;
|
||||
if (winVers < gfxWindowsPlatform::kWindows8)
|
||||
aperture = queryStatistics.QueryResult.SegmentInfoWin7.Aperture;
|
||||
else
|
||||
aperture = queryStatistics.QueryResult.SegmentInformationV1.Aperture;
|
||||
aperture = queryStatistics.QueryResult.SegmentInfoWin8.Aperture;
|
||||
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
|
||||
queryStatistics.Type = D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT;
|
||||
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
||||
queryStatistics.Type = D3DKMTQS_PROCESS_SEGMENT;
|
||||
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
||||
queryStatistics.hProcess = ProcessHandle;
|
||||
queryStatistics.QueryProcessSegment.SegmentId = i;
|
||||
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
||||
if (aperture)
|
||||
sharedBytesUsed += queryStatistics.QueryResult
|
||||
.ProcessSegmentInformation
|
||||
.ProcessSegmentInfo
|
||||
.BytesCommitted;
|
||||
else
|
||||
dedicatedBytesUsed += queryStatistics.QueryResult
|
||||
.ProcessSegmentInformation
|
||||
.ProcessSegmentInfo
|
||||
.BytesCommitted;
|
||||
}
|
||||
}
|
||||
@ -325,7 +307,6 @@ public:
|
||||
}
|
||||
};
|
||||
NS_IMPL_ISUPPORTS1(GPUAdapterMultiReporter, nsIMemoryMultiReporter)
|
||||
#endif // ENABLE_GPU_MEM_REPORTER
|
||||
|
||||
static __inline void
|
||||
BuildKeyNameFromFontName(nsAString &aName)
|
||||
@ -361,17 +342,13 @@ gfxWindowsPlatform::gfxWindowsPlatform()
|
||||
|
||||
UpdateRenderMode();
|
||||
|
||||
#ifdef ENABLE_GPU_MEM_REPORTER
|
||||
mGPUAdapterMultiReporter = new GPUAdapterMultiReporter();
|
||||
NS_RegisterMemoryMultiReporter(mGPUAdapterMultiReporter);
|
||||
#endif
|
||||
}
|
||||
|
||||
gfxWindowsPlatform::~gfxWindowsPlatform()
|
||||
{
|
||||
#ifdef ENABLE_GPU_MEM_REPORTER
|
||||
NS_UnregisterMemoryMultiReporter(mGPUAdapterMultiReporter);
|
||||
#endif
|
||||
|
||||
::ReleaseDC(NULL, mScreenDC);
|
||||
// not calling FT_Done_FreeType because cairo may still hold references to
|
||||
|
Loading…
Reference in New Issue
Block a user