如何测量 Android 上的 VRAM 消耗?

发布于 2024-09-07 08:55:29 字数 53 浏览 3 评论 0原文

我想获取 Android 设备 VRAM 大小。

有没有从程序中获取的方法?

I want to acquire Android Device VRAM size.

Is there a method for acquisition from the program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

若沐 2024-09-14 08:55:29

我们使用 Nexus One 来计算一下:

屏幕分辨率为 480x800。因此所需的最小视频内存大小为:
400 * 800 * 4 字节 = 1536000 字节

假设驱动程序可能(通常应该)使用多个缓冲区,我们还应该期望如下值:

1536000 * 2 字节 = 3072000 字节
1536000 * 3 字节 = 4608000 字节
etc...

如果值不是 1536000(或者通常是 W x H x 4)的倍数,那就很奇怪了。


在对 Android 内部进行一些搜索后,我发现了这个文档

...Android 对驱动程序提出了两个要求:可直接写入的可映射内存的线性地址空间...通过调用 /dev/fb0 上的 open 来访问驱动程序...

所以我尝试获取/dev/graphics/fb0 文件(在我的设备上没有 /dev/fb0)。

但直接的方法行不通:

 File file = new File("/dev/graphics/fb0");
 file.length(); // ==0, doesn't work, no read access

使用下一个技巧,您可以获得 fb0 的实际大小:
>adb pull /dev/graphics/fb0
1659 KB/s(2.712 秒内 4608000 字节)

视频内存约为 4mb (Nexus One)。让我们检查一下这是否是 Nexus 屏幕尺寸的倍数:

4608000/1536000 = 3

它看起来是一个正确的值。我们还可以说驱动程序使用三个屏幕缓冲区。


因此,作为结论,您可以使用 adb 检测视频内存大小,但由于文件访问限制,您无法在运行时从 Android 应用程序使用此方法。

Let's do some calculation using Nexus One:

Screen resolution is 480x800. So minimum required video memory size would be:
400 * 800 * 4 bytes = 1536000 bytes

Assuming that driver may (and normally should) use several buffers, we should also expect values like:

1536000 * 2 bytes = 3072000 bytes
1536000 * 3 bytes = 4608000 bytes
etc...

It would be weird to have values that are not multiple of 1536000 (or W x H x 4 in general).


After some searches on Android internals I've found this documentation :

...Android makes two requirements of the driver: a linear address space of mappable memory that it can write to directly...accessing the driver by calling open on /dev/fb0...

So I tried and take size of /dev/graphics/fb0 file (on my device there is no /dev/fb0).

But a direct approach doesn't work:

 File file = new File("/dev/graphics/fb0");
 file.length(); // ==0, doesn't work, no read access

Using next trick you can get actual size of fb0:
>adb pull /dev/graphics/fb0
1659 KB/s (4608000 bytes in 2.712s)

Video memory is ~4mb (Nexus One). Let's check if this is multiple of Nexus screen size:

4608000/1536000 = 3

It looks like a right value. And we also can say that driver uses three screen buffers.


So, as a conclusion, you can detect video memory size using adb, but you can't use this approach from your android application in runtime due to file access restrictions.

弱骨蛰伏 2024-09-14 08:55:29

您通常在移动设备上没有专用的“VRAM”。至少 PowerVR 架构不具备这种能力(该架构凭借 MBX 和 SGX 内核完全主导市场)。

也就是说,OpenGL 驱动程序会分配普通 RAM,直到您用完为止,分配的越多,留给应用程序的内存就越少。

You typically do not have a dedicated "VRAM" on mobile devices. At least you don't have it with PowerVR architectures (wich totally dominate the market with their MBX and SGX cores).

That is, the OpenGL driver allocates normal RAM until you run out of it, and the more you allocate the less you have left for your application.

世态炎凉 2024-09-14 08:55:29

Android/OpenGL API 不提供从给定设备读取 VRAM 大小的显式方法。

穷人解决方案
您可以尝试以经验方式添加 1MB 纹理来推断 VRAM 大小,直到从 gl.glGetError() 收到内存不足错误。

The Android/OpenGL APIs don't offer explicit methods to read the VRAM size from a given device.

Poor man solution:
You could try to infer the VRAM size in an empiric way adding 1MB texture until you get an out of memory error from gl.glGetError().

乖乖哒 2024-09-14 08:55:29

从您的“dmesg”输出中,您可以读取 VRAM,因此对于我的平板电脑:

> [    0.000000] Machine: TDM3730 [    0.000000] Reserving 12582912
> bytes SDRAM for VRAM
> 
> 7>[    3.929962] VRAM: checking region 9f400000 3072                  
> <4>[    3.929992] Failed. Allocating 4194304 bytes for fb 0           
> <7>[    3.935333] VRAM: alloc mem type 0 size 4194304 paddr dec2bd4c  
> <7>[    3.935485] VRAM: checking region 9f400000 3072                 
> <7>[    3.935485] VRAM: found 9f400000, end a0000000                  
> <6>[    3.936584] android_usb gadget: high speed config #1: android   
> <4>[    3.960113] allocating 4194304 bytes for fb 1

或详细信息:

http://pastebin.com /jQSXQqHh

From your "dmesg" output u can read off the VRAM, so for my Tablet:

> [    0.000000] Machine: TDM3730 [    0.000000] Reserving 12582912
> bytes SDRAM for VRAM
> 
> 7>[    3.929962] VRAM: checking region 9f400000 3072                  
> <4>[    3.929992] Failed. Allocating 4194304 bytes for fb 0           
> <7>[    3.935333] VRAM: alloc mem type 0 size 4194304 paddr dec2bd4c  
> <7>[    3.935485] VRAM: checking region 9f400000 3072                 
> <7>[    3.935485] VRAM: found 9f400000, end a0000000                  
> <6>[    3.936584] android_usb gadget: high speed config #1: android   
> <4>[    3.960113] allocating 4194304 bytes for fb 1

or details at:

http://pastebin.com/jQSXQqHh

乞讨 2024-09-14 08:55:29

很简单,只需计算 RAM 的可用容量和实际容量有多少 Mb RAM,例如我的联想 a369i 有 512 RAM 模块,但在设置应用程序中仅显示 471 Mb 可用,因此剩下的 41Mb 保留给 GPU,所以结论我的 a369i 有 41Mb vram

此方法基于共享图形内存 (wiki)

Is simple just count how many Mb ram that from usable to real capacity of the ram, example for my lenovo a369i has 512 RAM Module, but in setting app only showing 471 Mb usable so the 41Mb left is reserved for the GPU, so the conclusion is my a369i has 41Mb vram

This method is based from shared graphics memory (wiki)

梦回梦里 2024-09-14 08:55:29

我怀疑 android.os.StatFs 就是您正在寻找的:

http: //developer.android.com/reference/android/os/StatFs.html

I suspect that android.os.StatFs is what you're looking for:

http://developer.android.com/reference/android/os/StatFs.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文