Пример #1
0
int GpuUsage::getAtiUsage()
{
	/*HDC hdc = CreateDCA(0,"\\\\.\\DISPLAY1",0,0);
	if(hdc==NULL)
		return -1;*/
	NTSTATUS res;
	//D3DKMT_OPENADAPTERFROMHDC oafh;
	D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME oadn;
	//oafh.hDc = hdc;
	lstrcpyW(oadn.DeviceName, L"\\\\.\\DISPLAY1");
	res = D3DKMTOpenAdapterFromGdiDisplayName(&oadn);
	//res = D3DKMTOpenAdapterFromHdc(&oafh);
	if(res!=STATUS_SUCCESS)
	{
		//DeleteDC(hdc);
		return -1;
	}

	D3DKMT_ESCAPE esc;
	esc.hAdapter = oadn.hAdapter;
	esc.hDevice = 0;
	esc.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; 
	D3DDDI_ESCAPEFLAGS flag;
	flag.HardwareAccess=2;
	flag.Reserved=0;
	flag.Value=0x10002;
	esc.Flags = flag;

	AtiDriver ad;
	memset(&ad,0,sizeof(ad));
	ad.p1=2;
	ad.p2=0x010002;
	ad.p19 = 0x10c;
	ad.p20 = 0x80;
	ad.p21 = 0x10000;
	ad.p22 = 0x3000000;
	ad.p23 = 2;
	ad.p52=0x10;
	ad.p53=0x10;
	ad.p54=0xc0001a;
	ad.p57=0x28;
	ad.iSize=0x28;


	esc.pPrivateDriverData = &ad;
	esc.PrivateDriverDataSize = sizeof(AtiDriver);//0x10c;
	esc.hContext = 0;

	res = D3DKMTEscape(&esc);
	D3DKMT_CLOSEADAPTER ca;
	ca.hAdapter = oadn.hAdapter;
	D3DKMTCloseAdapter(&ca);
	if(res==STATUS_SUCCESS)
		return ad.iActivityPercent;
	return -1;
}
Пример #2
0
BOOLEAN EtpInitializeD3DStatistics(
    VOID
)
{
    PWSTR deviceInterfaceList;
    ULONG deviceInterfaceListLength = 0;
    PWSTR deviceInterface;
    D3DKMT_OPENADAPTERFROMDEVICENAME openAdapterFromDeviceName;
    D3DKMT_QUERYSTATISTICS queryStatistics;
    D3DKMT_CLOSEADAPTER closeAdapter;

    if (CM_Get_Device_Interface_List_Size(
                &deviceInterfaceListLength,
                (PGUID)&GUID_DISPLAY_DEVICE_ARRIVAL,
                NULL,
                CM_GET_DEVICE_INTERFACE_LIST_PRESENT
            ) != CR_SUCCESS)
    {
        return FALSE;
    }

    deviceInterfaceList = PhAllocate(deviceInterfaceListLength * sizeof(WCHAR));
    memset(deviceInterfaceList, 0, deviceInterfaceListLength * sizeof(WCHAR));

    if (CM_Get_Device_Interface_List(
                (PGUID)&GUID_DISPLAY_DEVICE_ARRIVAL,
                NULL,
                deviceInterfaceList,
                deviceInterfaceListLength,
                CM_GET_DEVICE_INTERFACE_LIST_PRESENT
            ) != CR_SUCCESS)
    {
        PhFree(deviceInterfaceList);
        return FALSE;
    }

    for (deviceInterface = deviceInterfaceList; *deviceInterface; deviceInterface += PhCountStringZ(deviceInterface) + 1)
    {
        memset(&openAdapterFromDeviceName, 0, sizeof(D3DKMT_OPENADAPTERFROMDEVICENAME));
        openAdapterFromDeviceName.pDeviceName = deviceInterface;

        if (NT_SUCCESS(D3DKMTOpenAdapterFromDeviceName(&openAdapterFromDeviceName)))
        {
            memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
            queryStatistics.Type = D3DKMT_QUERYSTATISTICS_ADAPTER;
            queryStatistics.AdapterLuid = openAdapterFromDeviceName.AdapterLuid;

            if (NT_SUCCESS(D3DKMTQueryStatistics(&queryStatistics)))
            {
                PETP_GPU_ADAPTER gpuAdapter;
                ULONG i;

                gpuAdapter = EtpAllocateGpuAdapter(queryStatistics.QueryResult.AdapterInformation.NbSegments);
                gpuAdapter->AdapterLuid = openAdapterFromDeviceName.AdapterLuid;
                gpuAdapter->Description = EtpQueryDeviceDescription(deviceInterface);
                gpuAdapter->NodeCount = queryStatistics.QueryResult.AdapterInformation.NodeCount;
                gpuAdapter->SegmentCount = queryStatistics.QueryResult.AdapterInformation.NbSegments;
                RtlInitializeBitMap(&gpuAdapter->ApertureBitMap, gpuAdapter->ApertureBitMapBuffer, queryStatistics.QueryResult.AdapterInformation.NbSegments);

                PhAddItemList(EtpGpuAdapterList, gpuAdapter);
                EtGpuTotalNodeCount += gpuAdapter->NodeCount;
                EtGpuTotalSegmentCount += gpuAdapter->SegmentCount;

                gpuAdapter->FirstNodeIndex = EtGpuNextNodeIndex;
                EtGpuNextNodeIndex += gpuAdapter->NodeCount;

                for (i = 0; i < gpuAdapter->SegmentCount; i++)
                {
                    memset(&queryStatistics, 0, sizeof(D3DKMT_QUERYSTATISTICS));
                    queryStatistics.Type = D3DKMT_QUERYSTATISTICS_SEGMENT;
                    queryStatistics.AdapterLuid = gpuAdapter->AdapterLuid;
                    queryStatistics.QuerySegment.SegmentId = i;

                    if (NT_SUCCESS(D3DKMTQueryStatistics(&queryStatistics)))
                    {
                        ULONG64 commitLimit;
                        ULONG aperture;

                        if (WindowsVersion >= WINDOWS_8)
                        {
                            commitLimit = queryStatistics.QueryResult.SegmentInformation.CommitLimit;
                            aperture = queryStatistics.QueryResult.SegmentInformation.Aperture;
                        }
                        else
                        {
                            commitLimit = queryStatistics.QueryResult.SegmentInformationV1.CommitLimit;
                            aperture = queryStatistics.QueryResult.SegmentInformationV1.Aperture;
                        }

                        if (aperture)
                            EtGpuSharedLimit += commitLimit;
                        else
                            EtGpuDedicatedLimit += commitLimit;

                        if (aperture)
                            RtlSetBits(&gpuAdapter->ApertureBitMap, i, 1);
                    }
                }
            }

            memset(&closeAdapter, 0, sizeof(D3DKMT_CLOSEADAPTER));
            closeAdapter.hAdapter = openAdapterFromDeviceName.hAdapter;
            D3DKMTCloseAdapter(&closeAdapter);
        }
    }

    PhFree(deviceInterfaceList);

    EtGpuNodeBitMapBuffer = PhAllocate(BYTES_NEEDED_FOR_BITS(EtGpuTotalNodeCount));
    RtlInitializeBitMap(&EtGpuNodeBitMap, EtGpuNodeBitMapBuffer, EtGpuTotalNodeCount);
    RtlSetBits(&EtGpuNodeBitMap, 0, 1);
    EtGpuNodeBitMapBitsSet = 1;

    return TRUE;
}