Sign in to follow this  
krammark23

Unity Detect Hardware Acceleration with C#

Recommended Posts

Hello, I was wondering if there was any way I could write a C# program that would test for the following features on a video card: 3d acceleration <- most important. amount of memory video hw transform and lighting video hw rasterization pixel shader version vertex shader version I think DirectX can do it but I need a way that would not require DirectX. I've taken a look through the forum archives and came accross these threads: http://www.gamedev.net/community/forums/topic.asp?topic_id=332735 http://www.gamedev.net/community/forums/topic.asp?topic_id=152450 It seems like the only ways I can find out these things about the video card is to use DirectX or do benchmarking. Is this correct? I've also taken a look at WMI but that doesn't seem to return the things that I'm looking for. Another thing, I've tried finding out whether or not the card supports 3d acceleration with the WMI through the CIM_VideoController AcceleratorCapabilities properties but it's returning a null value. Anyone have an idea on what the problem might be? Thanks again, Mark

Share this post


Link to post
Share on other sites
Well if you're using C# then it's highly likely you're running on a Windows OS (unless you're wanting to go via the Mono project?) and you can guarantee that a version of DirectX will be present. You can work up from there to retrieve the information...

I haven't tried it myself, but I'm pretty sure late-binding will allow you to remove any compile-time dependencies on a specific DirectX version if thats what you're worried about.

hth
Jack

Share this post


Link to post
Share on other sites
Given up on the C#. Using C now. Still hesitant with relying on DX.
I stumbled on this http://www.opengl.org/resources/faq/technical/mswindows.htm#0030

I'm trying to do it the win32 way that the site suggested but I'm not sure if I'm doing this correctly.

My code:
---------------------------------------------------------------
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);


hDC = GetDC(hwnd);
DescribePixelFormat(hDC, 1, sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc);
---------------------------------------------------------------

The value for dwFlags in pixelDesc is 0x00000034. From what I understand, this means that PFD_GENERIC_ACCELERATED (5th bit) and PFD_GENERIC_FORMAT (6th bit) are set - thus the machine is hardware accelerated. Does this mean that the machine this code is running on IS using hardware acceleration?

Or does this procedure only tell me that the machine is NOT using hw acceleration if PFD_GENERIC_ACCELERATED is clear and PFD_GENERIC_FORMAT is set.

I am a little confused here since according to http://msdn2.microsoft.com/en-us/library/ms537569.aspx the 4th bit (PFD_SUPPORT_OPENGL) is not set, implying that my buffer does not support OpenGL drawing, which I thought it would.


Thanks in advance,
Mark

Share this post


Link to post
Share on other sites
Well, no 3D app is going to be hardware accelerated unless you are using either DirectX or OpenGL anyway. That's just how video card drivers are implemented.

You can also always ship with a DirectX installer.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by krammark23
One more thing, if I do use DX, how would I know which version of DX is running on the machine?


There's a way to query the DX version number in Windows. Search on msdn.microsoft.com to find out how.

However, what most games do is just bundle the correct DirectX installer into the game's installer. The DirectX installer will update the user's machine if their current version of DX is lower than the installer's version. That way no one can install your game without also having installed the correct version of DX.

It's good practice to have the application query the DX version also, but bundling the installer with your game is just a nicer user experience.

-me

Share this post


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

Sign in to follow this