Windows And Video Memory

Tom_Mulcahy 11 Feb 2009 12:13 PM 

The following explanations are overviews. In the interests of brevity, they neglect some corner cases.

Definitions:

Video memory: For our purposes, memory accessible by the GPU. For details, please see the “Graphics Memory Reporting through WDDM” whitepaper (http://www.microsoft.com/whdc/device/display/graphicsmemory.mspx).
Hardware acceleration: The process of performing computations on the GPU instead of the CPU.
GDI: Graphics Device Interface – a 2D rendering API.
Surface: A chunk of memory representing a 2D array of pixels.
Present (verb): A function used to request that the contents of a backbuffer be displayed on screen. E.g. In DXGI, IDXGISwapChain::Present.
GPU acceleration: Also known as hardware acceleration. This means performing work on the Graphics Processing Unit (GPU) instead of on the Central Processing Unit (CPU). When the GPU can be used, it is typically much faster than the CPU, hence the term “acceleration”.

Overview:

XP uses the XP driver model (XPDM) and video memory is a fixed/finite resource. Windows Vista and Windows 7 use the Windows Display Driver Model (WDDM) where graphics memory is virtualized. This means that in XPDM you are limited to the amount by the amount of physical memory on the graphics card, but in WDDM you are not. Therefore WDDM allows running either more applications or more resource intensive applications than was possible with XPDM. You can read more about WDDM athttp://msdn.microsoft.com/en-us/library/aa480220.aspx. There is no hard limit of video memory in either WDDM or XPDM, but depending on the driver, there are other limits. For example, some drivers have limits on the number of surfaces that can be created.

In Windows Vista and Windows 7 the Desktop Window Manager (DWM) is used. Instead of presenting directly to the front buffer as in Windows XP, apps present to a DWM buffer. The DWM then composes the buffers together to create the image you see on your screen.

Taking advantage of GPU acceleration:
In XP GDI is GPU accelerated to various degrees depending on how the OS is configured or the device driver (for details see Hooking Versus Punting: http://msdn.microsoft.com/en-us/library/ms799743.aspx). In Vista, GDI is not GPU accelerated however the performance difference is usually not perceptible by the user. In Windows 7, some limited GPU acceleration for GDI was added to enable some video memory optimizations. Direct3D and WPF are GPU accelerated on all 3 OS’s. Direct2D is GPU accelerated too, but it is currently available on Windows 7 only. Microsoft has announced that it will releasing Direct2D on Windows Vista, and it will be GPU accelerated there too.

The Desktop Window Manager uses GPU acceleration, so apps on Windows Vista and Windows 7 benefit automatically. For example, when you drag a window in XP the app receives a request to redraw the window. In Windows Vista and Windows 7, the DWM maintains a copy of the window contents in graphics memory, so the app doesn’t need to redraw the window.

If you notice an app performing worse in Windows Vista as compared to Windows XP, please don’t assume that there is nothing you can do about it. For example there used to be a performance problem with windbg.exe on Vista that was caused by an interaction with the DWM. Turning off the DWM did make the problem go away, but a change to windbg.exe fixed the problem for good. If you have performance problems, as a first step I’d recommend profiling your app to see what is hogging the CPU (especially compared to XP).

Virtual memory considerations:

Wikipedia has a great description of virtual memory, but here’s a quick overview: Processes store and retrieve information through addresses similar to the way people use phone numbers when making phone calls. Virtual memory addresses are to physical memory addresses as speed dial numbers are to a full phone numbers. Just as different people have the speed dial number “4” mapped to different full phone numbers, different processes have the virtual address “0x00A4B3C0” mapped to different physical memory addresses. Speed dial numbers are used as shortcuts, but virtual memory addresses are often longer than needed to address all of physical memory. So why are virtual memory addresses used?
1. Process isolation: Even assuming that you don’t have any malware on your computer, the computer equivalent of accidentally dialing the wrong phone number has devastating consequences. We restrict processes to using virtual memory addresses so they can’t interfere with memory belonging to other processes.
2. Contiguous memory: Processes often depend on having large sections of sequential addresses available.
3. Resource sharing: The amount of RAM installed on a typical PC is small enough that it’s possible to exhaust it by running many processes at the same time. If the processes used physical memory addresses, they would just fail when they ran exhausted physical memory. With virtual addresses, the OS can use both physical memory and hard disk space to hold the information to which a virtual address refers.

Virtual memory problems start when an app is compiled as 32-bit and it needs more than 2GB of virtual address space. You may wonder why 2GB? After all 2 raised to the 32 is 4GB. The answer is because the other 2GB of virtual address space is reserved for the kernel. There are ways to give your app slightly more user mode virtual address space at the cost of less kernel address space, but the best solution is to use a 64-bit OS and compile your app as 64-bit. See 64-bit programming for Game Developers (http://msdn.microsoft.com/en-us/library/bb147385.aspx) for more information (the material was written for game developers but it’s applicable to any app).

If you really, really can’t use a 64-bit OS, then you can try to look at ways to reduce virtual memory usage - and I say “try” because there’s no easy way to do that. So what does this have to do with video memory? 
1. Large mapable surfaces consume large amounts of virtual address space. In order to use video memory, the CPU has to populate it. One of the mechanisms for populating a surface is to “map”* it to a range of virtual addresses. When you create a mapable surface, Direct3D allocates a range of virtual addresses for this purpose. It does not do it at the time you map the surface because there might not be a large enough contiguous chunk of virtual memory available.
2. Even non-mapable surfaces may consume virtual address space under XPDM. It depends on the driver. Non-mapable surfaces consume virtual address space in Windows Vista RTM, but this was changed in Vista SP1 (and Windows 7) because it was causing problems for games.
3. WDDM drivers have a user mode component, so I’d expect that apps would use more user mode address space and less kernel address space on Windows Vista and Windows 7 as compared to Windows XP.
4. WPF is GPU accelerated, but it keeps around a system memory copy of resources, so virtual address space is used.
5. Direct2D does not keep a system memory copy of resources and uses non-mapable Direct3D surfaces internally, so virtual address space is conserved. (The tradeoff is that Direct2D apps must handle device removed errors)
6. As mentioned earlier, on Windows XP GDI calls may or may not be handled by graphics card driver. For device-managed surfaces (see http://msdn.microsoft.com/en-us/library/ms799615.aspx for information about GDI surface types) typically no virtual memory is used. On Windows Vista, GDI calls are never handled by the graphics card, so GDI objects do consume virtual memory. On Windows 7 there is some GDI acceleration, so some apps will consume less virtual memory as compared to Windows Vista.

Also good to know:
1. There are tools that let you view virtual address space - for example, Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx). If you can figure out what is eating up your address space, you might be able to take action.
2. Remember that virtual memory and physical memory are two separate things. You can use virtual memory address space without using physical memory (e.g. by calling VirtualAlloc with the MEM_RESERVE flag) and you can use physical memory without using virtual address space (e.g. by allocating non-lockable surfaces in Direct3D).
3. This white paper might be helpful: Virtual Address Space Usage in Windows Game Development (http://www.microsoft.com/whdc/device/display/WDDM_VA.mspx)

I hope this information helps you to not exceed your virtual memory limits, but if you still have problems you’ll have to switch to 64-bit Windows and compile your app as 64-bit.

* Map is the D3D10 API. The D3D9 API was LockRect.

Windows And Video Memory的更多相关文章

  1. System memory,AGP memory和video memory【转】

    system  memory就是电脑的内存条上的,一般都很大.显卡不能访问 . video memory就是显示卡上的显存,一般是32,64,128M这样,速度最快,显卡可直接访问 .用来描述电脑上一 ...

  2. 论文笔记:Heterogeneous Memory Enhanced Multimodal Attention Model for Video Question Answering

    Heterogeneous Memory Enhanced Multimodal Attention Model for Video Question Answering 2019-04-25 21: ...

  3. [转载]Memory Limits for Windows and Windows Server Releases

    Memory Limits for Windows and Windows Server Releases This topic describes the memory limits for sup ...

  4. SDL源码阅读笔记(2) video dirver的初始化及选择

    write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 前一篇文章 讲了SDL的除video以外的大部分模块.本文主要关注SDL的video模块部分. SD ...

  5. Asphyre Sphinx is a cross-platform framework for developing 2D/3D video games and interactive business applications

    Introduction Introduction Asphyre Sphinx is a cross-platform framework for developing 2D/3D video ga ...

  6. Video for Linux Two API Specification Revision 2.6.32【转】

    转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for ...

  7. Video for Linux Two API Specification revision0.24【转】

    转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification ...

  8. Windows桌面共享中一些常见的抓屏技术

    1. BitBlt 我想做Windows开发应该都知道这个API, 它能实现DC间的内容拷贝, 如果我们把源DC指定成Monitor DC或是桌面DC, 它就能实现抓屏功能. 对于通过这种方式的抓屏, ...

  9. Windows上x86程序正常但x64程序崩溃问题

    先看下面代码: #include <stdio.h> #include <windows.h> #include <memory> class Test { pub ...

随机推荐

  1. Sql Server Alter语句

    1:向表中添加字段 Alter table [表名] add [列名] 类型 2:  删除字段 Alter table [表名]  drop column [列名] 3:  修改表中字段类型 (可以修 ...

  2. 企业项目开发--分布式缓存Redis

    第九章 企业项目开发--分布式缓存Redis(1) 注意:本章代码将会建立在上一章的代码基础上,上一章链接<第八章 企业项目开发--分布式缓存memcached> 1.为什么用Redis ...

  3. 16090202(剑灵GPA)

    [目标] 剑灵GPA [思路] 1 2 绘制角色DrawCall body 5526面片 2.1[第一个DrawCall]63 RT 这个DrawCall PS VS 参数列表 VS // // Ge ...

  4. 深入了解 Scala 并发性

    2003 年,Herb Sutter 在他的文章 “The Free Lunch Is Over” 中揭露了行业中最不可告人的一个小秘密,他明确论证了处理器在速度上的发展已经走到了尽头,并且将由全新的 ...

  5. Strategy pattern策略模式

    在Java的集合框架中,经常需要通过构造方法传入一个比较器Comparator,或者创建比较器传入Collections的静态方法中作为方法参数,进行比较排序等,使用的是策略模式. 一.策略模式的定义 ...

  6. MySQL数据库的一些基本操作及注释

    --Created by mac on 2017/1/4. -- MySQL数据库 -- ****************** 一. 连接数据库服务器的基础命令 ******************* ...

  7. PDA项目介绍

    开发工具:Microsoft Visual Studio 2008 SDK:      Windows Mobile 6 SDK 数据库:     Oracle 开发语言:C#(3.5) 版本控制工具 ...

  8. [SHTSC 2014] 信号增幅仪

    最小覆盖圆算法.看着题解半蒙半抄的搞过去了… 主要参考以下http://blog.csdn.net/acdreamers/article/details/9406735http://blog.csdn ...

  9. IOS UIButton用法详解

    这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用.   //这里创建一个圆角矩形的按钮UIButton *button1 = [UIButton buttonWi ...

  10. OC内存管理

    内存问题 野指针异常:访问所有权的内存,如果想要安全访问,必须确保空间还在(确保访问的内存不是僵尸对象) 内存泄露:空间使用完之后没有及时释放 过度释放:对一块空间释放多次,立刻crash 内存溢出: ...