简体   繁体   English

需要OpenGL GPU内存清理吗?

[英]OpenGL GPU Memory cleanup, required?

Do I have to clean up all DisplayLists, Textures, (Geometry-)Shaders and so on by hand via the glDelete* functions, or does the GPU mem get freed automagically when my Program exits/crashes? 我是否必须通过glDelete *函数手动清理所有DisplayLists,Textures,(Geometry-)着色器等,或者当我的程序退出/崩溃时GPU mem是否会自动释放?

Note: GPU mem refers to dedicated memory on a dedicated Graphics card, not CPU memory. 注意:GPU mem是指专用显卡上的专用内存,而不是CPU内存。

释放上下文,其他所有内容都是上下文本地的(除非您启用了显示列表共享)并将随之消失。

As others mentioned, your OS (in collaboration with the driver resource manager) should release the resources. 正如其他人所提到的,您的操作系统(与驱动程序资源管理器合作)应该释放资源。 That's what OSes are for. 这就是操作系统的用途。 It's worth noting that this has nothing to do with OpenGL, but is something that is part of the charter of well behaved OSes and their associated drivers. 值得注意的是,这与OpenGL无关,但它是行为良好的操作系统及其相关驱动程序的一部分。 The OS is there to handle all the system resources. 操作系统可以处理所有系统资源。 OpenGL ones are just but a subset of them, and they are no different from, say a file handle. OpenGL只是它们的一部分,它们与文件句柄没什么区别。 Now to get more concrete, you should specify which OS you care about. 现在要更具体,您应该指定您关心的操作系统。

BTW, This is where I take exception with ChrisF's answer. 顺便说一句,这是我对ChrisF的答案不以为然的地方。 It should not be up to the driver to decide it needs to do cleanup. 决定它需要进行清理不应该由驾驶员决定。 OS driver models will have a clear interface between the user-mode OpenGL driver (that shouldn't do actual gfx resource allocation, since it's shared in the machine), the OS (that provides the equivalent of system calls to allocate resources) and the kernel-mode driver (that is merely there to execute the OS orders in a way that is compatible with the gpu). 操作系统驱动程序模型将在用户模式OpenGL驱动程序(不应该执行实际的gfx资源分配,因为它在机器中共享),操作系统(提供相当于系统调用以分配资源)和内核模式驱动程序(仅用于以与gpu兼容的方式执行OS命令)。 This is at least the case with the WIN2K and WDDM models. 这至少是WIN2K和WDDM型号的情况。

So... if your process crashes or otherwise terminates, in those models, it's the OS responsibility to call the kernel-mode driver to free all the resources that were associated with the process. 因此......如果您的进程崩溃或以其他方式终止,在这些模型中,操作系统负责调用内核模式驱动程序以释放与该进程关联的所有资源。

Now, whether you should or not is really something that is a little like asking tabs-or-spaces in source code. 现在,无论你是否应该这样做,有点像在源代码中询问标签或空格。 Different people have different beliefs here. 不同的人在这里有不同的信仰。 "the OS will do it anyways, quitting immediately is a better end-user experience" vs "I want to know whether I'm leaking memory because if my program is long-running, I really don't want it to hit OOM errors. Best way to do that is to be leak-free throughout" are the 2 main lines of thought I'm aware of. “操作系统无论如何都会这样做,立即退出是一种更好的最终用户体验”vs“我想知道我是否在泄漏内存,因为如果我的程序长时间运行,我真的不希望它出现OOM错误最好的方法是在整个过程中保持无泄漏“这是我所知道的两条主要思路。

When your program exits (or crashes) then any memory it currently has allocated should be freed eventually in the same way that main memory is usually freed when a program exits. 当程序退出(或崩溃)时,它当前分配的任何内存最终应该以与程序退出时通常释放主内存相同的方式释放。 It may be some time before the GPU "realises" that the memory is available for use again. 在GPU“意识到”存储器可再次使用之前可能还需要一段时间。

However, you shouldn't rely on this behaviour as it may depend on how the graphics card drivers have been implemented. 但是,您不应该依赖此行为,因为它可能取决于显卡驱动程序的实现方式。 It's far better to make explicit clean up calls when you (as programmer) know that you won't need that memory again. 当你(作为程序员)知道你不再需要那个内存时,做出明确的清理调用要好得多。

All your GPU resources will be released when your program exits. 程序退出时,将释放所有GPU资源。 An easy way to test is to not delete things, and run your app repeatedly to see if it fails the allocations after a few iterations. 一种简单的测试方法是不删除内容,并重复运行您的应用程序,以查看在几次迭代后它是否未通过分配。

In Opengl, there is no memory to store the drawing information. 在Opengl中,没有用于存储绘图信息的内存。 here, when we execute the opengl program, that time calling draw frame method calling at sequentially. 在这里,当我们执行opengl程序时,那个时候调用draw frame方法按顺序调用。 Anyway, if we draw a line or circle means, anytime its calling draw frame method for drawing at specified place.but, opengl does not store that line in memory. 无论如何,如果我们绘制一条线或圆圈意味着,任何时候它的调用绘制框架方法都可以在指定的位置绘制。但是,opengl不会将该行存储在内存中。 Anytime, its drawing only. 任何时候,它只是绘图。 but, when we saw, that line is dawned successfully. 但是,当我们看到时,那条线已成功曙光。

Ex: In Android Opengl es2.0 used this renderer class inside drawframe method(inside draw method) to draw the lines or circles etc.. i used this Opengl es2.0 Program in android autocad app development.. if you want to clear the dawned lines use this method in renderer class inside onDrawframe method GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 例如:在Android中,Opengl es2.0在drawframe方法中使用了这个渲染器类(在draw方法中)来绘制线条或圆圈等。我在android autocad app开发中使用了这个Opengl es2.0程序..如果你想清除dawned行在onDrawframe方法GLES20.glClearColor(0.0f,0.0f,0.0f,1.0f)中的renderer类中使用此方法; GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM