游戏开发论坛

 找回密码
 立即注册
搜索
查看: 6233|回复: 16

在DX9中用什么函数可以查看显存? 急 急 急..

[复制链接]

9

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
发表于 2007-12-19 16:24:00 | 显示全部楼层 |阅读模式
在DX9中用什么函数可以查看显存?可以随时查看使用过的显存量和没有被使用的显存大小?

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-20 08:34:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

dx9无。
但ddraw有。你可以在创建d3d设备的时候,同时建个ddraw设备,然后查询显存情况。别无它法。

DirectDraw 7.0
IDirectDraw7::GetAvailableVidMem
The IDirectDraw7::GetAvailableVidMem method retrieves the total amount of display memory available and the amount of display memory currently free for a given type of surface.

HRESULT GetAvailableVidMem(
  LPDDSCAPS2 lpDDSCaps2,  
  LPDWORD    lpdwTotal,   
  LPDWORD    lpdwFree     
);

Parameters
lpDDSCaps2
Address of a DDSCAPS2 structure that indicates the hardware capabilities of the proposed surface.
lpdwTotal
Address of a variable to be filled with the total amount of display memory available, in bytes. The value retrieved reflects the total video memory, minus the video memory required for the primary surface and any private caches that the display driver reserves.
lpdwFree
Address of a variable to be filled with the amount of display memory currently free that can be allocated for a surface that matches the capabilities specified by the structure at lpDDSCaps2.
Return Values
If the method succeeds, the return value is DD_OK.

If it fails, the method can return one of the following error values:

DDERR_INVALIDCAPS  
DDERR_INVALIDOBJECT  
DDERR_INVALIDPARAMS  
DDERR_NODIRECTDRAWHW  


If NULL is passed to either lpdwTotal or lpdwFree, the value for that parameter is not returned.

Remarks
The following C++ example demonstrates how to use IDirectDraw7::GetAvailableVidMem to determine both the total and free display memory available for texture-map surfaces:

// For this example, the lpDD variable is a valid
// pointer to an IDirectDraw interface.
LPDIRECTDRAW7 lpDD;
DDSCAPS2      ddsCaps2;
DWORD         dwTotal;
DWORD         dwFree;
HRESULT       hr;

hr = lpDD->QueryInterface(IID_IDirectDraw7, &lpDD);
if (FAILED(hr))
    return hr;

// Initialize the structure.
ZeroMemory(&ddsCaps2, sizeof(ddsCaps2));

ddsCaps2.dwCaps = DDSCAPS_TEXTURE;
hr = lpDD->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree);
if (FAILED(hr))
    return hr;

If the surface has the DDSCAPS_VIDEOMEMORY flag set, this method will return different amounts of video memory depending on whether or not the surface can be used as a 3-D texture. If the surface can be used for 3-D textures, the GetAvailableVidMem method will return the sum of the local video memory and the non-local video memory on AGP systems.

This method provides only a snapshot of the current display-memory state. The amount of free display memory is subject to change as surfaces are created and released. Therefore, you should use the free memory value only as an approximation. In addition, a particular display adapter card might make no distinction between two different memory types. For example, the adapter might use the same portion of display memory to store z-buffers and textures. So, allocating one type of surface (for example, a z-buffer) can affect the amount of display memory available for another type of surface (textures). Therefore, it is best to first allocate an application's fixed resources (such as front and back buffers and z-buffers) before determining how much memory is available for dynamic use (such as texture mapping).

This method was not implemented in the IDirectDraw interface.

9

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
 楼主| 发表于 2007-12-20 09:08:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

非常感谢楼上的,我现在遇到一个很郁闷的问题,愿楼上的给点意见,我在一个游戏的时候,通过任务管理器,发现在某个时刻我的电脑的虚拟内存(PF)急速上升400-500M,但进程的内存使用和虚拟内存的使用却没有什么变化,内存使用甚至会变的很小.我通过程序查看,在d3d设备释放的时候PF会突然下降几百M,我用的是ATI的显卡.

20

主题

222

帖子

276

积分

中级会员

Rank: 3Rank: 3

积分
276
发表于 2007-12-20 15:25:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

NVPerfHub

9

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
 楼主| 发表于 2007-12-21 08:48:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

NVPerfHub 是什么?可否说的详细点

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-21 11:12:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

dx 底层会占用大量内存,特别是你创建资源时使用managed风格。如果你d3d资源未及时释放,可能会使你的进程占用大量内存。
你可以下载RivaTuner进行realtime检测。

NVPerfHud,nvidia的性能调试软件,一般需要源代码(会crack除外 ),只能在nvdia的卡上跑。

9

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
 楼主| 发表于 2007-12-21 12:29:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

我是使用了很多managed风格的资源,但是我可以保证我所创建的资源绝对没有PF所显示的大,比如我只创建了300M左右的资源,但PF所显示的却有800M,只要退游戏,PF马上恢复正常

9

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
 楼主| 发表于 2007-12-21 13:00:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

ReallyBigBug
可以加QQ聊不,我的QQ是32400925

4

主题

69

帖子

205

积分

中级会员

Rank: 3Rank: 3

积分
205
发表于 2007-12-21 13:05:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

关注中,因为发现有的游戏一启动时就把显存给占光。也想知道如果获取当前显存的使用状况

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-21 16:48:00 | 显示全部楼层

Re:在DX9中用什么函数可以查看显存? 急 急 急.

IDirectDraw        DDraw;
IDirectDraw4>        DDraw4;
DirectDrawCreate(NULL, DDraw, NULL);
DDraw->QueryInterface(IID_IDirectDraw4, DDraw4);
//
DWORD dwTotal=0;
DWORD dwFree=0;
DDSCAPS2 caps;
ZeroMemory(&caps, sizeof(caps));
FLOAT DeltaVRam=0.0f;
caps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
if(DD_OK==DDraw4->GetAvailableVidMem(&caps, &dwTotal, &dwFree))
{
FLOAT LastUsed=gUsedLocalVRam;
gTotalLocalVRam=(FLOAT)dwTotal/1048576.0f;
gUsedLocalVRam=(FLOAT)(dwTotal - dwFree)/1048576.0f;

}
//
ZeroMemory(&caps, sizeof(caps));
caps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM;
dwTotal=0;dwFree=0;
if(DD_OK==DDraw4->GetAvailableVidMem(&caps, &dwTotal, &dwFree))
{
FLOAT LastUsed=gUsedAGPRam;
gTotalAGPRam = (FLOAT)dwTotal/1048576.0f;
gUsedAGPRam  = (FLOAT)(dwTotal - dwFree) / 1048576.0f;               
}

//这是我现在工程用的部分代码,基本函数就这几个,对local显存,agp内存进行查询。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-18 07:28

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表