Jump to content

[C#] Get available video card memory

blackfisch
Go to solution Solved by Franck,
40 minutes ago, blackfisch said:

Arma 3 has a startup parameter for VRAM and RAM

VRAM there is no way they can do it you need to actually allocate the memory to reserve it. I have done it with few texture before but that mean you have to load dummy textures in memory for X amount of ram and even this is not accurately whatever the amount you expected. Then when you want to use it you need to quickly release and reassign and wish another application did not just stole that place. Very dangerous territory.

 

It very likely a dummy value. On the other hand the RAM that is true, it's very common on large server application to have dedicated ram.

 

If you still want to do it i have a small solution for you. you can quite easy is request the video device information then have a database file with model to vram and i am pretty sure someone already have an exhaustive list on the web. you can probably cover 90% of the use case scenario with that.

Hey Guys,

 

I'm currently working on a small solution (Mod-Launcher) for our Arma 3 Server Project. Everything works fine so far, only problem that got reported is the available video memory (VRAM).

For clarification: The program has a button to start the game and some checkboxes and sliders to adjust startup parameters like maximum RAM and VRAM usage. There is where the problem is. No matter what graphics card is built into the system, it never show up as more than 4GB of video memory. I'm pretty sure this is because I use the 'Win32_VideoController'-Class, which is obviously a 32 bit class, and simply cannot handle more than 4GB.

 

So I'm basically looking for a way to get the amount of VRAM in bytes or something similar, so I can adjust the maximum slider value accordingly for input validation.

Note: I'm looking for the maximum available VRAM, not the currently free VRAM. If it's a 6GB card I don't care about how much is being used, i Just want 6GB as an output.

 

Current Code is:

private int GetVideoMemory()
{
    int vram = 0;

    foreach (ManagementObject mo in new ManagementObjectSearcher("select AdapterRAM from Win32_VideoController").Get())
    {
        var ram = mo.Properties["AdapterRAM"].Value as UInt32?;
        if (ram.HasValue)
        {
            vram = (int)(ram / 1048576); //convert to MB
        }
    }

    return vram;
}

 

 

Thanks for your help!

Link to comment
Share on other sites

Link to post
Share on other sites

Anything over 2.147GB of VRAM will cause an exception to be thrown, you should use the long data type.

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, schwellmo92 said:

Anything over 2.147GB of VRAM will cause an exception to be thrown, you should use the long data type.

He is fine, he used an unsigned int.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, schwellmo92 said:

4.294GB then, is that maybe his issue haha?

Exactly. WMI won't see anything above 4.3 GB.

 

So his code was "correct" for WMI but he can't use that.

 

1 hour ago, blackfisch said:

Note: I'm looking for the maximum available VRAM, not the currently free VRAM. If it's a 6GB card I don't care about how much is being used, i Just want 6GB as an output.

This is a tough info to get. This information is possible to get quite close to it in Linux but it is still quite hard.

There is not a single case i can see where the max ram available or commit is useful to know as all application need to check if memory can be allocated or not and determine that way if there is enough. Since you cannot limit the vram if is not an important information.

 

That being said, if you are absolutely need it you need to interface with the video card vendor drivers. For AMD it's pretty easy they have nothing signed. all drivers are pretty crappy (specially OpenGL interpretation). for Nvidia drivers are much more reliable but are a *&%@#$ to interface with specially WHQL ones.

 

The video card driver themselves do have this information but you have to maintain the code for each driver versions. Nvidia specially for the 3 years i have directly worked with their drivers for a cuda application, they changed the way you get the average temperature twice on the Quadro series drivers. I have never touch the commit or allocated ram but i know it was possible. Other team members back then had a dashboard that was showing it so they monitor heat vs watts vs iop vs vram stats.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay, so there is no reliable way of getting the info then? If so, I guess that's fine and I already have an idea for a workaround.

 

4 hours ago, Franck said:

There is not a single case i can see where the max ram available or commit is useful to know

Yeah, that's probably true. But as I said - the application is a game launcher with optional startup parameters. Arma 3 has a startup parameter for VRAM and RAM, with which you can manually allocate more memory by default, which helps the game run more smoothly (as far as my experience goes).

I guess I'll just add the option to manually override the max 4GB in the launcher, so that people who know their hardware can still get the best out of it.

 

Thanks a lot for your help!

Link to comment
Share on other sites

Link to post
Share on other sites

40 minutes ago, blackfisch said:

Arma 3 has a startup parameter for VRAM and RAM

VRAM there is no way they can do it you need to actually allocate the memory to reserve it. I have done it with few texture before but that mean you have to load dummy textures in memory for X amount of ram and even this is not accurately whatever the amount you expected. Then when you want to use it you need to quickly release and reassign and wish another application did not just stole that place. Very dangerous territory.

 

It very likely a dummy value. On the other hand the RAM that is true, it's very common on large server application to have dedicated ram.

 

If you still want to do it i have a small solution for you. you can quite easy is request the video device information then have a database file with model to vram and i am pretty sure someone already have an exhaustive list on the web. you can probably cover 90% of the use case scenario with that.

Link to comment
Share on other sites

Link to post
Share on other sites

With a little bit of C++ and the d3d11 libraries you can easily get the video adapter memory value and the video card description as well as much more for probably under a 100 lines of code. C# has ported libraries such a SlimDX and SharpDX as well for direct C# usage. 

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×