XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   
My XNA Book
      
       Go to section on this site

Additional info


Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22


Ads

Checking device capabilities

Throughout the tutorials I often mention the Reference rasterizer. This Reference device offers a software simulation of a complete top-notch graphics card. This means that when using the Reference device, you can use all DirectX commands, and the correct output will be drawn to the screen, even if you don’t have the newest of video cards.

The backside, however, is that because all of this will be simulated in software, all of the calculations will happen on the system’s main CPU. The main system CPU is A LOT slower in performing these kind of tasks than the GPU, the processing unit of your graphics card. Because of this, the Reference device will deliver the correct results, but only for the simplest of cases you will reach one update per second, in most cases you’ll have to wait a couple of seconds for the next frames.

Luckily, DirectX provides a way to check whether a dedicated graphics card is present in the system, the static Manager class. This class supports several ways to check for hardware support in your system. You can use this simple routine for example to check if the graphics card supports vertex transformations:

 Caps DevCaps = D3D.Manager.GetDeviceCaps(0, D3D.DeviceType.Hardware);
 CreateFlags DevFlags = CreateFlags.SoftwareVertexProcessing;
 if (DevCaps.DeviceCaps.SupportsHardwareTransformAndLight)
 {
  DevFlags = CreateFlags.HardwareVertexProcessing;
 }

First you get the structure from the Manager that contains all the capailities of your hardware graphics card. Then you default your device creation flag to SoftwareVertexProcessing, and have it changed to HardwareVertexProcessing only when the hardware supports this.

If you’re working with HLSL shaders, or want to dynimically set the type of device, you can use this code:

 Caps DevCaps = D3D.Manager.GetDeviceCaps(0, D3D.DeviceType.Hardware);
 D3D.DeviceType DevType = D3D.DeviceType.Reference;
 CreateFlags DevFlags = CreateFlags.SoftwareVertexProcessing;
 if ((DevCaps.VertexShaderVersion >= new Version(2, 0)) && (DevCaps.PixelShaderVersion >= new Version(2, 0)))
 {
     DevType = D3D.DeviceType.Hardware;
     if (DevCaps.DeviceCaps.SupportsHardwareTransformAndLight)
     {
         DevFlags = CreateFlags.HardwareVertexProcessing;
     if (DevCaps.DeviceCaps.SupportsPureDevice)
     {
         DevFlags |= CreateFlags.PureDevice;
     }
 }
 
 device = new D3D.Device(0, DevType, this, DevFlags, presentParams);

After getting the device capabilities, we default our device to the Reference rasterizer, and the creation flag to SoftwareVertexProcessing, which are the lowest settings possible. After verifying that our device supports shaders, we switch to the Hardware rasterizer. If our hardware also is capable of calculation all our transformations, we change to this creation flag. If our device is a pure device, we add this to the creation flags. A pure device is the fastest kind of device, as it allows some special kind of memory transactions. Finally, we create the device with the selected type of device and creation flags.

So when using this code, you make sure you have created the ‘best’ kind of device, and that you’re program will not crash on initialization. But even pure devices can have other limitations, such as the size of the maximum allowable lights, indices in an index buffer, or DirectX commands it cannot perform. Maybe your application will crash when it tries to use a backbuffer format your graphics card doesn’t support. All of this can be checked this way:

 if (DevCaps.MaxVertexIndex < 30000)
     //do something

This will check if the device can handle index buffers with up to 30000 indices. If not, you will have to come up with an idea to handle this. Just scroll through the properties of DevCaps, and you’ll see you can check almost every detail of your hardware.

When looking for supported screen formats, the current resolution and more of the like, you can select the Default one from the Adapters list. An adapter can be thought of as a connection port from your pc to a monitor. On my Radeon I have a normal vga-out and a svideo out. Together with the tv-out on my mainboard, this gives 3 Adapters. From this default adapter, you can find more info on the current display mode, as well as the supported display modes by this adapter. Displaying all supported display modes of your default adapter would go like this:

 AdapterInformation adinfo = D3D.Manager.Adapters.Default;
 
 string line = "";
 foreach (DisplayMode dispmode in adinfo.SupportedDisplayModes)
 {
     line = string.Format("{0} - {1}x{2}:{3}", line, dispmode.Width, dispmode.Height, dispmode.Format);
 }
 
 MessageBox.Show(line);

This conlcudes checking hardware capablities. If you have any comments on this, don’t hesitate to put them on the forum!



Click here to go to the forum on this chapter!






Google
 
Webwww.riemers.net


If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans
Translations

This site in English
This site in Korean
This site in Czech

Microsoft MVP Award



2007 - 2011 MVP Award
DirectX - XNA

Contents

News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)
-- Expand all --


Thank you!

Support this site --
any amount is welcome !

Stay up-to-date

I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!