I'm trying to render text in my DX11 project, by using SpriteFont
and SpriteBatch
.
Everything worked before adding the code in, but when the code in uncommented, I get the following error and nothing renders.
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. Semantic 'TEXCOORD' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. 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]
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (NORMAL,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
I have tried to change the DeviceContext & Device, but still the same error.
//Draw Text
g_spriteBatch = std::make_unique<SpriteBatch>(g_pImmediateContext);
g_spriteFont = std::make_unique<SpriteFont>(g_pd3dDevice1, L"Data\\game_font.spritefont");
//Render Text
g_spriteBatch->Begin();
//g_spriteFont->DrawString(g_spriteBatch.get(), L"Score: 0", XMFLOAT2(0,0), DirectX::Colors::White);
g_spriteBatch->End();
I've tried using different Devices and DeviceContext's, but still the same error.
I have been trying many different ways to get this working. This is what my render function looks like at the moment
Updated: 18/02/2019
void Render() {
float backgroundColour[] = { 0.0f, 0.1f, 0.5f, 0.0f };
g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, backgroundColour);
g_pImmediateContext->ClearDepthStencilView(g_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
g_pImmediateContext->IASetInputLayout(g_pVertexLayout);
g_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
g_pImmediateContext->RSSetState(g_rasterState);
g_pImmediateContext->OMSetDepthStencilState(g_depthStencilState, 0);
g_pImmediateContext->VSSetShader(g_pVertexShader, NULL, 0);
g_pImmediateContext->PSSetShader(g_pPixelShader, NULL, 0);
UINT stride = sizeof(SimpleVertex);
UINT offset = 0;
g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
g_pImmediateContext->Draw(3, 0);
//g_pImmediateContext->DrawIndexed(36, 0, 0);
//Draw Text
spriteBatch->Begin();
spriteFont->DrawString(spriteBatch.get(), L"Test", DirectX::XMFLOAT2(0, 0), DirectX::Colors::White);
spriteBatch->End();
//Present our back buffer to the front buffer
g_pSwapChain->Present(0, NULL);
}
When running the project, I get the following error
D3D11 ERROR: ID3D11DeviceContext::IASetVertexBuffers: A Buffer trying to be bound to slot 0 did not have the appropriate bind flag set at creation time to allow the Buffer to be bound as a VertexBuffer. [ STATE_SETTING ERROR #238: IASETVERTEXBUFFERS_INVALIDBUFFER]
This is the code that stores the data for a tri and sets up the index/vertex buffer
SimpleVertex vertices[] =
{
SimpleVertex(-0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 0.0f),
SimpleVertex( 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.0f),
SimpleVertex( 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 0.0f),
};
D3D11_BUFFER_DESC bd = {};
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * ARRAYSIZE(vertices);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
if (FAILED(hr))
{
printf("Failed ro Create Vertex Buffer.");
return hr;
}
I have changed D3D11_BIND_INDEX_BUFFER
to D3D11_BIND_VERTEX_BUFFER
and the same error occurs.
Following this, the following warnings are produced too.
D3D11 WARNING: ID3D11DeviceContext::Draw: Vertex Buffer at the input vertex slot 0 is not big enough for what the Draw*() call expects to traverse. This is OK, as reading off the end of the Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior. [ EXECUTION WARNING #356: DEVICE_DRAW_VERTEX_BUFFER_TOO_SMALL]
D3D11 WARNING: ID3D11DeviceContext::Draw: The size of the Constant Buffer at slot 0 of the Vertex Shader unit is too small (64 bytes provided, 192 bytes, at least, expected). This is OK, as out-of-bounds reads are defined to return 0. It is also possible the developer knows the missing data will not be used anyway. This is only a problem if the developer actually intended to bind a sufficiently large Constant Buffer for what the shader expects. [ EXECUTION WARNING #351: DEVICE_DRAW_CONSTANT_BUFFER_TOO_SMALL]
D3D11 WARNING: ID3D11DeviceContext::Draw: Input vertex slot 0 has stride 24 which is less than the minimum stride logically expected from the current Input Layout (32 bytes). This is OK, as hardware is perfectly capable of reading overlapping data. However the developer probably did not intend to make use of this behavior. [ EXECUTION WARNING #355: DEVICE_DRAW_VERTEX_BUFFER_STRIDE_TOO_SMALL]
SpriteBatch
uses. – Chuck WalbournspriteBatch
function seems to be causing the shader linker errors.g_pImmediateContext->DrawIndexed(36, 0, 0);
The error appears on this line. – George_HspriteBatch->Begin(); spriteFont->DrawString(spriteBatch.get(), L"TEXT PLACEHOLDER", XMFLOAT2(1.0f, 1.0f)); spriteBatch->End();
Something about this removes settings/states so that the input layout and vertex buffers need to be set again. I moved around some of the states into the render function too. While this worked, the FPS seemed to drop. With the two cubes in the scene, the depth buffer seemed to have stopped working, where cube2 would always seem to overlap cube1. – George_HSpriteBatch
changes, which includes the input layout and vertex shader which is required for really any drawing. In general you should not assume any state is set, and at the start of the frame you set the render target & viewport/scissors. Then before each draw call you change whatever state you need. "Capturing and restoring" state which is what the old legacyID3DXFont
did is extremely slow. – Chuck Walbourn