I am trying to draw a cube in DirectX. However, I am getting the following error message;
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT]
Here is the code for my shaders;
cbuffer WorldBuffer : register (b0)
{
matrix World;
matrix View;
matrix Projection;
}
struct VS_OUTPUT
{
float4 pos : SV_POSITION;
float4 color : COLOR0;
};
VS_OUTPUT VS(float4 pos : POSITION, float4 color : COLOR) : VS_OUTPUT_SEMANTICS
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.pos = mul(pos, World);
output.pos = mul(output.pos, View);
output.pos = mul(output.pos, Projection);
output.color = color;
return output;
}
float4 PS(VS_OUTPUT input : VS_OUTPUT_SEMANTICS) : SV_TARGET
{
return input.color;
}
Since I have given SV_POSITION
semantic to VS_OUTPUT.pos
, I think shader should be passing position, but it doesn't seem to work. How can I fix my shaders?
This is how I compile my shaders:
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG;
r = D3DCompileFromFile(L"shader.fx", NULL, NULL, "VS", "vs_5_0", flags, 0, &vertex_blob, &errMsg);
When using :
VS_OUTPUT VS(float4 pos : POSITION, float4 color : COLOR) : VS_OUTPUT_SEMANTICS
VS_OUTPUT_SEMANTICS will actually override the per element semantics, so instead of outputting a struct like :
struct VS_OUTPUT
{
float4 pos : SV_POSITION;
float4 color : COLOR0;
};
you actually output
struct VS_OUTPUT
{
float4 pos : VS_OUTPUT_SEMANTICS;
float4 color : VS_OUTPUT_SEMANTICS;
};
When you call :
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG;
r = D3DCompileFromFile(L"shader.fx", NULL, NULL, "VS", "vs_5_0", flags, 0, &vertex_blob, &errMsg);
Even if the shader compiles, you should still look in errMsg, as the compiler might issue some warnings (which in this case will be) :
"semantics in type overriden by variable/function or enclosing type"
If can also be a good idea to call D3DDisassemble on the resulting blob, this can give you the resulting reflection data in a text form.
In your vertex shader case you will have (only relevant part):
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION 0 xyzw 0 NONE float xyzw
// COLOR 0 xyzw 1 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// VS_OUTPUT_SEMANTICS 0 xyzw 0 NONE float xyzw
// VS_OUTPUT_SEMANTICS 1 xyzw 1 NONE float xyzw
//