Platform SDK: DirectX

Device Types and Vertex Processing Requirements

The performance of vertex processing operations, including transformation and lighting, depends heavily on where the vertex buffer exists in memory and what type of rendering device is being used. Applications control the memory allocation for vertex buffers when they are created. When the D3DVBCAPS_SYSTEMMEMORY capability flag is set in the vertex buffer description, the vertex buffer is created in system memory. When the capability is not used, the device driver determines where the memory for the vertex buffer is best allocated, often referred to as "driver-optimal" memory. Driver-optimal memory can be local video memory, nonlocal video memory, or system memory.

[C++]

Direct3D applies vertex processing operations when you call the IDirect3DDevice7::DrawPrimitiveVB, IDirect3DDevice7::DrawIndexedPrimitiveVB, or IDirect3DVertexBuffer7::ProcessVertices method. These operations include transformation and lighting. The performance of these calls depends on the location of the buffer in memory, and whether that location is best for the given type of device (hardware or software).

[Visual Basic]

Direct3D applies vertex processing operations when you call the Direct3DDevice7.DrawPrimitiveVB, Direct3DDevice7.DrawIndexedPrimitiveVB, or Direct3DVertexBuffer7.ProcessVertices method. These operations include transformation and lighting. The performance of these calls depends on the location of the buffer in memory, and whether that location is best for the given type of device (hardware or software).

The reasoning you should apply to determine the memory location—system or driver optimal—for vertex buffers is the same as textures. In the case of textures, hardware rasterization works best when textures are allocated in driver-optimal memory, while software rasterization works best with system-memory textures. Likewise, vertex processing (including transformation and lighting) in hardware works best when the vertex buffers are allocated in driver-optimal memory, while software vertex processing works best with vertex buffers allocated in system memory.

Note  Vertex processing done by the ProcessVertices method is always done in software, so the source vertex buffer must always be in system memory. The destination vertex buffer can be allocated in driver-optimal memory unless the application will directly lock and read it, or if clipping is requested in the call to ProcessVertices (which requires reading from the vertex buffer when a vertex-buffer rendering method is called).

If your application performs its own vertex processing (and passes transformed, lit, and clipped vertices to the vertex-buffer rendering methods), then the application can directly write vertices into a vertex buffer allocated in driver-optimal memory. This technique prevents a redundant copy operation later. Note that this technique will not work well if your application reads data back from a vertex buffer, because read operations done by the host from driver-optimal memory can be very slow. So, if your application needs to read during processing or writes data to the buffer erratically, then a system-memory vertex buffer is a better choice.

When using the Direct3D vertex processing features (by passing untransformed vertices to vertex-buffer rendering methods), processing can occur in either hardware or software, depending on the device type. If the device is a TnLHAL Device (IID_IDirect3DTnLHALDevice), vertex processing is done in hardware and the vertex buffer should be created in driver-optimal memory for best performance. If the device is a HAL Device (IID_IDirect3DHALDevice), vertex processing is done in software and the vertex buffer should be created in system memory. When rendering with the RGB Device (IID_IDirect3DRGBDevice), all vertex buffers should be allocated in system memory.

[C++]

The following C++ style pseudo-code summarizes the logic you should apply when creating and processing vertex buffers.

if (software rasterization)
    use system-memory vertex buffers (D3DVBCAPS_SYSTEMMEMORY)
else if (application vertex processing)
    if (application does not read and does not use erratic writes)
        use driver-optimal vertex buffers
    else
        use system-memory vertex buffers (D3DVBCAPS_SYSTEMMEMORY)
else // Direct3D vertex processing
    if (TnLHAL device)
        use driver-optimal vertex buffers
    else if (HAL device)
        use system-memory vertex (D3DVBCAPS_SYSTEMMEMORY)
 
[Visual Basic]

The following Visual Basic style pseudo-code summarizes the logic you should apply when creating and processing vertex buffers.

If (software rasterization) Then
    use system-memory vertex buffers (D3DVBCAPS_SYSTEMMEMORY)
Else If (application vertex processing) Then
    If (application does not read and does not use erratic writes) Then
        use driver-optimal vertex buffers
    Else
        use system-memory vertex buffers (D3DVBCAPS_SYSTEMMEMORY)
Else // Direct3D vertex processing
    If (TnLHAL device) Then
        use driver-optimal vertex buffers
    Else If (HAL device)
        use system-memory vertex (D3DVBCAPS_SYSTEMMEMORY)
End If