GPU Capability Detection & Configuration

I’m currently building my first game in MonoGame. Can anyone give me some general direction on how to:

  1. Check the Graphics Card’s capabilities.
  2. Determine which of those capabilities I am relying on.
  3. Downgrade my code (or switch to Reach?) in response.

For example: If I am using the Color.FromNonPremultiplied functionality when I manually load png files, how do I know if my graphics card will support that? If it doesn’t, will switching to Reach (however that is done) fix that or will I need to find another approach?

Thanks in advanced for any help :slight_smile:

Graphics capabilities stuff is very much flawed in the current implementation unfortunately.
What platform are you targeting? For OpenGL, GraphicsProfile is not used currently. For DX, the GraphicsProfile determines what feature levels are added, which determine the capabilities of the GraphicsDevice, so in this case you can try to create a HiDef device and if that fails fall back to Reach. Devices that support DX11 will support HiDef (which is almost all of them currently). You can use one code path for all platforms since it doesn’t make a difference for OpenGL platforms.

If you’d like to help out in improving the implementation, let me know :slight_smile: There’s a lot of work to be done, but I don’t think it’s particularly hard.

This is a CPU operation, so GraphicsProfile won’t matter here.

For DX, minimum capabilities for both GraphicsProfiles can be found in this blog post by XNA hero Shawn Hargreaves. That also shows you of where GraphicsProfile matters.

EDIT: Also, when you do a graphics operation in MG, the capabilities of the device aren’t properly checked beforehand, so you might get unexpected native errors :confused:

Thanks for the response.

I’m building this in Linux Mint using Jetbrain’s Rider, so I’m targeting OpenGL (At least I think I am. The framework I referenced was DesktopGL. I took that to mean I was targeting OpenGL. Please tell me if I’m wrong :confused:). The game is very simple in terms of graphics (2D tile based).

I’m really giving my away my noobness here, but how do you know that Color.FromNonPremultiplied is a CPU operation? I’m not sure even how to educate myself on this. Did you look at the MG source code to determine that?

If I’m hearing you correctly though, with OpenGL, its one code path, but it might explode for certain GPUs or drivers?

Is there a way I can correlate common graphics operations with OGL versions and then code to a lowest common denominator?

Thanks so much :smiley:

Yes, that’s right.

It’s a simple operation on 4 floats, so it makes sense. When in doubt you can always check the source code.

For OpenGL you can find the actual capabilities of the GPU by creating a GraphicsDevice and checking GraphicsDevice.GraphicsCapabilities (that’s not the actual device capabilities for DX).
You might want to do that and fall back to simpler rendering if you run into hardware/driver limitations, since MG will crash if you try to do something that’s not supported. That said, with a 2D tile based game you really don’t have to worry about it.

OK. Thank you. I really appreciate your help!

1 Like

It looks like GraphicsDevice.GraphicsCapabilities doesn’t work anymore, possibly due to the removal of OpenTK in MonoGame. The command from this topic, GL.GetInteger(GetPName.MaxTextureSize, out foo), which appears to be a convenience function of OpenTK, doesn’t work anymore either.

What is the new way to find the OpenGL capabilities? I need to read the GL MAX_TEXTURE_SIZE so if a user’s system doesn’t support a 4096x4096 textured model, I can automatically downgrade to a 2048x2048 Texture2D to avoid displaying the blacked-out texture when a graphics card’s max texture size is exceeded:

I have not been able to detect the blacking effect from within MonoGame with BasicEffect.Texture.GetData, as it only reads back the original texture image, so it must be on the GPU side only. The only other options appear to be P/Invoking opengl32.dll, which looks difficult, or maybe including OpenTK in my game?