Error: Invalid vs_2_0 output semantic - hlsl

Its says: Invalid vs_2_0 output semantic SV_Target.
So for some reason Visual Studio 2017 is compiling my pixel shader as if it is a vertex shader. But in the properties panel I specified it to be a ps_5_0. Is there something I'm missing that should be specified?
Vertex shader:-
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
struct Input {
float3 Pos : POSITION;
float4 Color: COLOR;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
VS_OUTPUT main(Input input)
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul(input.Pos, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Color = input.Color;
return output;
}
Pixel shader:-
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
float4 main(VS_OUTPUT input) : SV_Target
{
return input.Color;
}
And here are my settings for the pixel shader.
I hope someone can help me.

Open the Property page for the .hlsl file, and in HLSL Compiler/General/Shader Type select Pixel Shader.

And don't forget to set this propertie for debug and release.

You can resolve the issue by modifying the shader property
properties -> HLSL Compiler -> General -> Shader Type -> Pixel Shader (/ps)
OR
Configuration properties -> General -> Excluded from Build = Yes.

Related

Blur when downscale image rendered by DirectX

I am using DirectX for rendering video, but the issue is video is blur when downscale the video frame.
As I know, I need to write an high-quality down-scale filter in shader.hlsl file:
My current shader code:
struct VS_INPUT
{
float3 inPos : POSITION;
float2 inTexCoord : TEXCOORD;
};
struct VS_OUTPUT
{
float4 outPosition : SV_POSITION;
float2 outTexCoord : TEXCOORD;
};
VS_OUTPUT vs_main(VS_INPUT input)
{
VS_OUTPUT output;
output.outPosition = float4(input.inPos, 1.0f);
output.outTexCoord = input.inTexCoord;
return output;
}
struct PS_INPUT
{
float4 inPosition : SV_POSITION;
float2 inTexCoord : TEXCOORD;
};
Texture2D luminanceChannel : TEXTURE: register(t0);
Texture2D chrominanceChannel : TEXTURE: register(t1);
SamplerState defaultSampler : SAMPLER: register(s0);
static const float3x3 YUVtoRGBCoeffMatrix =
{
1.164383f, 1.164383f, 1.164383f,
0.000000f, -0.391762f, 2.017232f,
1.596027f, -0.812968f, 0.000000f
};
float3 ConvertYUVtoRGB(float3 yuv)
{
yuv -= float3(0.062745f, 0.501960f, 0.501960f);
yuv = mul(yuv, YUVtoRGBCoeffMatrix);
return saturate(yuv);
}
float4 PS(PS_INPUT input) : SV_TARGET
{
float y = luminanceChannel.Sample(defaultSampler, input.inTexCoord);
float2 uv = chrominanceChannel.Sample(defaultSampler, input.inTexCoord);
return float4(ConvertYUVtoRGB(float3(y, uv)), 1.f);
}
Can you give me a guide for it? Thanks.

Adding geometry shader causes "shader linkage error"

I'm adding a geometry shader (a very simple one) to my DirectX 11 program. I've already got vertex and pixel shader written, and they work just as expected - no errors, no warnings. The shaders are simple, too. The vertex shader is:
cbuffer PerApplication : register(b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register(b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register(b2)
{
matrix worldMatrix;
}
struct VertexShaderInput
{
float4 position : POSITION;
float4 color: COLOR;
};
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
//entry point
VertexShaderOutput SimpleVertexShader(VertexShaderInput IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.color = IN.color;
OUT.position = mul(mvp, IN.position);
return OUT;
}
The pixel shader is:
struct PixelShaderInput
{
float4 color : COLOR;
};
float4 SimplePixelShader(PixelShaderInput IN) : SV_TARGET
{
return IN.color;
}
Well, as I've said, that's working pretty well. Then I'm adding a geometry shader, which doesn't actually do anything, it just takes a triangle and returns the same triangle. The geometry shader is:
struct VertexInput
{
float4 color : COLOR;
float4 position : POSITIONT;
};
struct VertexOutput
{
float4 color : COLOR;
float4 position : SV_Position;
};
[maxvertexcount(3)]
void SimpleGeometryShader(triangle VertexInput input[3], inout TriangleStream<VertexOutput> stream)
{
VertexOutput v1 = { input[0].color, input[0].position };
stream.Append(v1);
VertexOutput v2 = { input[1].color, input[1].position };
stream.Append(v2);
VertexOutput v3 = { input[2].color, input[2].position };
stream.Append(v3);
stream.RestartStrip();
}
Doing this also requires to change the vertex shader, which now returns
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : POSITIONT; //I'm not returning SV_Position in vertex shader anymore.
};
And the program itself works, and it works as expected, I see what I expect to see. But there are now two D3D11 errors:
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (POSITIONT,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: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (TEXCOORD,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
Both are pretty strange. The vertex shader clearly returns a POSITIONT, and COLOR and POSITIONT are in the same order. What's my mistake?
The reason of the problem was that beside of rendering the scene using the shaders that I provided I was also drawing text using some library. Obviously, there were some vertex and pixel shaders involved in it with their own input and output signatures. Setting geometry shader to null solved my problem.

How to compile from shader assembler code in DirectX 11?

D3DXAssembleShader function was used in DirectX 9 for compiling shaders from Assembly. It's not supported in DirectX 11. Is there any alternative to create shaders from Assembler code?
I am aware of compiling from fx or hlsl files but for my project purposes, I should compile only using assembly.
The following code was used in DirectX 9:
static const char VertexShaderCode[] = \
"vs.3.0\n"
"dcl_position v0\n"
"dcl_position o0\n"
"mov o0, v0\n";
D3DXAssembleShader(VertexShaderCode,sizeof(VertexShaderCode), 0,0, DLL, &VSBuffer, 0);
I am looking for an alternative to the above code in DirectX11 using D3D11 dll's.
I want to modify my asm file like below and create vertex and pixel shaders:
dcl_output o0.xyzw -> dcl_output.o0.zw
Will I be able to do the same in fx or hlsl file?
FX file:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR )
{
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;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( VS_OUTPUT input ) : SV_Target
{
return input.Color;
}
Compiling from HLSL shader assembly isn't officially supported for Shader Model 4.0, 4.1, 5.0, or 5.1.
When you build with fxc.exe you get disassembly for debugging & optimization purposes

HLSL error X3000: unrecognized identifier

I don't have any experience with hlsl and can't figure out how to fix this error. Here is my SimpleVertexShader.hlsl file
cbuffer PerApplication : register (b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register (b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register (b2)
{
matrix worldMatrix;
}
struct AppData
{
float3 position : POSITION;
float3 color : COLOR;
};
struct VertexShaderOuput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
VertexShaderOuput SimpleVertexShader(AppData IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.position = mul(mvp, float4(IN.position, 1.0f));
OUT.color = float4(IN.color, 1.0f);
return OUT;
}
I get an error X3000: unrecognized identifier 'VertexShaderOutput' as well as unrecognized identifier 'OUT'. I am using Visual Studio 2013. And under the Properties for this file I have these settings:
HLSL Compiler>Entrypoint Name: SimpleVertexShader
Shader Type: Vertex Shader (/vs)
Shader Model: Shader Model 4 (/4_0).
HLSL Compiler>Output Files>Header Variable Name: g_vs
Object File Name: $(OutDir)%(Filename)_d.cso.
(the _d is only under the Debug configuration.)

Getting the color of a vertex in HLSL?

I have the following vertex and pixel shaders:
struct VS_INPUT
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
float4 Color : TEXCOORD1;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
float4x4 projview_matrix;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.Position = mul(Input.Position, projview_matrix);
Output.Color = Input.Color;
Output.TexCoord = Input.TexCoord;
return Output;
}
px
texture tex;
sampler2D s = sampler_state {
texture = <tex>;
};
float4 ps_main(VS_OUTPUT Input) : COLOR0
{
float4 pixel = tex2D(s, Input.TexCoord.xy);
return pixel;
}
This is for a 2d game. The vertices of the quads contain tinting colors that I want to use to tint the bitmap. How can I obtain the color of the current vertex so I can multiply it in the pixel shader by the current pixel color?
Thanks
In your pixel shader, do:
float4 pixel = tex2D(s, Input.TexCoord.xy) * Input.Color;
The Input.Color value will be linearly interpreted across your plane for you, just like Input.TexCoord is. To blend two color vectors together, you simply multiply them together. It may also be advisable to do:
float4 pixel = tex2D(s, Input.TexCoord.xy) * Input.Color;
pixel = saturate(pixel);
The saturate() function will clip each RGB value in your color in the range of 0.0 to 1.0, which may avoid any possible display artifacts.