D3DBook:Quick Start For Direct3D 9 Developer

From GDWiki
Jump to: navigation, search

Contents

Quick Start for Direct3D 9 Developer

Finally Microsoft's new 3D API keeps its old name and only gets a new version number. It even keeps most of its most fundamental concepts like using COM based interfaces and objects. The main state machine is still called the device that uses shader to draw something on the screen. But the step from the former version is wider this time. If we could move from Direct3D 8 to 9 in only a few days Direct3D 10 will properly force us to rethink the architecture of our Direct3D applications.

What's Lost

One reason for this is the lost backward compatibility for older hardware. Direct3D 10 will only work with GPUS that are fully Direct3D 10 compatible. If you need to support pre Direct3D 10 hardware and want to support the new Direct3D 10 features with the same application you have to write your render code twice for Direct3D 9 and 10.

But this somewhat painful cut has allowed removing some other outdated parts of Direct3D together with the capabilities bits and values. To support older hardware Direct3D 9 has still support fixed function vertex and pixel processing beside the more flexible shader system. With Direct3D 10 these functionality is gone. But not only were the fixed functions axed although every Direct3D 9 shader model is removed. Direct3D 10 will only support the new shader model 4. Together with this the only way to write such a shader is the use of High Level Shader Language (HLSL). Shader assembler is not longer an option and only supported as dissembler output for debugging purposes.

In the resource system we lost the surface type. Depending on the formerly usage it is replaced by different mechanisms. The explicit texture cube object is although gone. In Direct3D 10 cubes have become a special case of a 2D texture.

As any other resource type it can only be created using one of the predefined formats. In Direct3D 10 mode GPUs will no longer be able to offer additional formats with FourCC codes.

Together with the cut of the fixed function vertex and pixel processing Direct3D 10 lost some other related functions that now need to be done in the shader. On the vertex side there are no more clip planes. The pixel shader is now responsible to make the alpha test and texture coordinate wraps by its own. The whole pipeline functions to generate point sprites are gone. You will need the new geometry shader to replace this.

The basic support for higher order surfaces and tessellation that was part of Direct3D 9 but not supported by the relevant hardware is removed, too.

What's Different

Beside of elements that are lost forever Direct3D 10 changed multiple Direct3D 9 concepts. Direct3D 9 uses the surface type to represent every kind of two dimensional pixel arrays. As example this could be a depth stencil buffer or a single mip map from a texture. Explicit created surfaces like render targets are replaced by 2D textures. The different mip maps of a texture are now called sub resources. But there is no sub resource interface available. Therefore Direct3D 10 uses a new concept to attach these sub resources to the 3D pipeline. View objects defines how the pipeline should look at the data inside a resource object. Beside of limiting such a view to single sub resources they although offer some form of data format conversions.

The cut of the fixed functions vertex and pixel processing reduced the number of necessary render states significant. But as the other non shader units learn some new features the number is still high. To make the render state system faster Direct3D 10 uses collections of render states called state objects. Each one of these collections contains a whole configuration for one part of the 3D Pipeline. Like other resource the need to create once before the first usage. After this is done the configuration stored in this objects is immutable. This made it easier to change multiple states with only one call but requires the application to manage single state changes by itself.

The configuration of the texture sampler is done with a state object too. You can assign up to 16 sampler state objects to each shader. The binding to a resource, like a texture, is postponed to the shader program. This allows using the same texture sampler for different textures.

The shader constants that were stored in one arrays per shader type got a new home with Direct3D 10. These values are now stored in a buffer resources that could be attached to special slots. A buffer that is used for these purposes is called a constant buffer. Each shader can access up to 16 of these buffers in one shader program.

Another significant change is the replacement of the vertex declaration with an input layout. As the vertex declaration described only a binding between the vertex streams and the semantic usage of the fetched elements a input layout goes a step future. It will bind direct to the input register of the vertex shader. This made it necessary to create one input layout for every vertex shader with a different input side. Beside of this change the input layout will although take control over the instancing functionality.

Direct3D 10 uses a new extension mechanism called layer. These layers provide functions like additional debug checks or controlling the multithread behavior. The selection of these layers is done during device creation. In comparison to Direct3D 9 the multithread layer is enabled by default.

Lock and unlock operations are replaced with map and unmap. As the number of resources that could not be directly accessed has increased with Direct3D 10 there is a new function that allows transferring the content of a memory block to a resource without creating a system memory resource.

The draw methods are changed, too. In any place were Direct3D 9 wants the number of primitives you now have to provide the number of vertices. Additional the primitive type is removed from the parameter list and need to be set with another method before you call any draw method. Finally Direct3D 10 lost the methods that allow you to draw directly from a memory block without using buffer resources. One last change concerns the geometry instancing. If you want to use this technique you have to use one of two new special draw methods.

The pixel position is not longer based on the center of a pixel. Therefore there is no more need to add a half pixel offset in both directions for accurate pixel to screen mapping.

The usage of sRGB is not longer based on render states. It is bound to the data format and Direct3D 10 requires a stricter implementation when the hardware read or writes to such a resource.

What's New

The most significant new element of Direct3D 10 is the geometry shader. This third shader that is placed behind the vertex shader is the first shader that breaks the one to one rule. Every time it runs it can output a different number of primitives. Additional of this it supports every feature of the other shaders that are now based on a common shader core system.

Beside of this new 3D pipeline element the blend unit can now use two colors from the pixel shader for its operation. It can although generate an additional multisampling mask based on the alpha value of the pixel to improve the anti aliasing in alpha test situations.

Personal tools