|
|
|
|
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!
- Website design & XNA + DirectX code : Riemer Grootjans - ©2003 - 2008 Riemer Grootjans
|
|
|
|
|