Jump to content
  • Advertisement
Sign in to follow this  
mpledge52

Getting Graphics Information

This topic is 3894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all. I've written an application and its nearing its final stages. One of the things I want to add is a sort of performance checker, i.e. before running the program it will get some system information and set some variables relating to the performance accordingly. So if the system had only 256MB ram it wouldn't load as much data. I have found functions to retreive processer information and memory information, but I am yet to find something that can return information on the graphics available (memory, core speed, mem speed etc). Is there any C functions/library where I can retreive such data? It only needs to be a very basic judge of performance. I'm using Windows XP, Visual Studio 2005, C, OpenGL and GLUT. So anything that works with these would be fantastic. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Information on the display device is typically queried through whatever graphics API you're using. I'm not an OpenGL guy, but I'm pretty sure it has some functions that should get you the information you need (I know Direct3D has them). If nobody here knows, you may want to ask the OpenGL forum to point you in the right direction.

Share this post


Link to post
Share on other sites
In OpenGL you can get some information about the video card with the glGetString() function:


glGetString(GL_VERSION); // OpenGL Version
glGetString(GL_VENDOR); // Vendor of Video Card
glGetString(GL_RENDERER); // Device being used to Render in OpenGL
glGetString(GL_EXTENSIONS); // space-delimited list of Extensions supported by your video card



Oddly enough, these functions seem to return const GLubyte *, which you'll probably have to typecast into something more useful (like a char*).

In order to find out about the capabilities of the CPU, use x86 and the CPUID instruction. Here's some really useful code that I wrote from both Intel and AMD documentation:


string featureList = "";
char cpuVendorID[13], cpuName[49];
int highestEax, highestExtEax, features, extFeatures, msrs;

__asm {
; Gets the CPU's Vendor ID
mov eax, 0
CPUID
mov DWORD PTR cpuVendorID[0], ebx
mov DWORD PTR cpuVendorID[4], edx
mov DWORD PTR cpuVendorID[8], ecx

; Gets the basic feature list, and determines how much data cpuid can give
mov highestEax, eax;
mov eax, 1
CPUID
mov features, edx
mov msrs, ecx
mov eax, 0x80000000
CPUID
mov highestExtEax, eax
}
cpuVendorID[12] = '\0';

// Populate feature list
if(features & 0x00800000) featureList.append(" MMX");
if(features & 0x02000000) featureList.append(" SSE");
if(features & 0x04000000) featureList.append(" SSE2");
if(msrs & 0x00000001) featureList.append(" SSE3");
if(msrs & 0x00000200) featureList.append(" SSSE3");
if(msrs & 0x00080000) featureList.append(" SSE4.1");
if(msrs & 0x00100000) featureList.append(" SSE4.2");

// Populate features from AMD extensions
if(highestExtEax >= 0x80000001) {
__asm {
mov eax, 0x80000001
CPUID
mov extFeatures, edx
}
if(extFeatures & 0x80000000) featureList.append(" 3dNow");
if(extFeatures & 0x40000000) featureList.append(" 3dNowExt");
if(extFeatures & 0x00400000) featureList.append(" MmxExt");
}

// Eliminate the preceding space in the string
if(featureList.length() > 0) featureList = featureList.substr(1);

// Get the number of processor cores
int numCores = 0;
if(highestEax >= 0x00000004) { // using the Intel method
__asm {
mov ecx, 0
mov eax, 4
CPUID
mov numCores, eax
and numCores, 0xFC000000
shr numCores, 26
}
numCores++;
}
if(numCores == 0 && highestExtEax >= 0x80000008) {
__asm {
mov ecx, 0
mov eax, 0x80000008
CPUID
mov numCores, ecx
and numCores, 0x000000FF
}
numCores++;
}

// Get the name of the CPU
if(highestExtEax >= 0x80000004) {
__asm {
mov eax, 0x80000002
CPUID
mov DWORD PTR cpuName[0], eax
mov DWORD PTR cpuName[4], ebx
mov DWORD PTR cpuName[8], ecx
mov DWORD PTR cpuName[12], edx
mov eax, 0x80000003
CPUID
mov DWORD PTR cpuName[16], eax
mov DWORD PTR cpuName[20], ebx
mov DWORD PTR cpuName[24], ecx
mov DWORD PTR cpuName[28], edx
mov eax, 0x80000004
CPUID
mov DWORD PTR cpuName[32], eax
mov DWORD PTR cpuName[36], ebx
mov DWORD PTR cpuName[40], ecx
mov DWORD PTR cpuName[44], edx
}
cpuName[48] = '\0'
}
else {
cpuName[0] = '\0';
}





This works properly for both AMD and Intel CPUs. Also, because the guts of the code are in assembly, it will work with any OS / implementation (as long as the CPU supports CPUID - but this is universal on PCs).
There is more information you can retrieve such as stepping and cache information, but that's for another time.

Retrieving info about memory is not universal - there's info for how to do it in Windows here and for Linux by reading the file /proc/meminfo - the first line should be something like "Memtotal:" followed by the size in bytes.

Hope this helps!

Share this post


Link to post
Share on other sites
Thanks Claymore but I'm after more numerical performance figures, something that I can compare far easier that the name of the card. Does such a thing exist?

Thanks

Share this post


Link to post
Share on other sites
Not really - at least, not in OpenGL.
Something that I did in my game engine was to keep a counter of how many triangles I rendered each frame, as well as the frame rate. If you multiply the numbers together, you get the number of triangles / second you can render...and I found this number to be pretty constant for a particular video card, regardless of what I have in the scene.
The only other data I keep track of for performance is how many CPUs and at what speed (from my code above).

Share this post


Link to post
Share on other sites
I've seen a few games run a quick benchmark before setting the graphics mode. Basically, try a bunch of things, see how well they work, and use that information to determine what you do. A bit hackish, but possibly more reliable than querying for arbitrary numbers.

Cheers,
--Brian

Share this post


Link to post
Share on other sites
Quote:
Original post by Nairb
I've seen a few games run a quick benchmark before setting the graphics mode. Basically, try a bunch of things, see how well they work, and use that information to determine what you do. A bit hackish, but possibly more reliable than querying for arbitrary numbers.


That's what I was thinking of doing actually because I've done a similar thing for calculating cpu speed. Do you know of any code for such a benchmark?

Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!