Time pass by

Sunshine and rain of a developer

DirectX DrawText Cause Vertex Shader linkage error. Here’s how to fix it

Posted by vanguard33 on June 21, 2009

When I drew 3D objects  and text together, the first frame was fine. However, the second frame failed. This bug took me very long time to debug.  The pseudo code looks like this:


EveryFrame(){

   Draw3d();

   DrawText();

}

The shader generated  following output:

D3D10: ERROR: ID3D10Device::Draw: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. The reason is that the input stage requires Semantic/Index (POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]

Here is a post about the detail. Breafly speaking, DirectX DrawText() function changes the inner state of device; therefore, the input layout is changed after the first frame and, of course, the program failed in the second frame.

The solution is to use D3DX10_SPRITE_SAVE_STATE flag.


void cGraphicsLayer::DrawTextString(int x, int y, 
 D3DXCOLOR color, const TCHAR* strOutput)
{
 m_pFontSprite->Begin(D3DX10_SPRITE_SAVE_STATE);
 RECT rect = {x, y, m_rcScreenRect.right, m_rcScreenRect.bottom};
 m_pFont->DrawText(m_pFontSprite, strOutput, -1, &rect, DT_LEFT, color);
 m_pFontSprite->End();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.