Merge pull request #1449 from KhronosGroup/fix-1443

HLSL: Fix FragCoord.w.
This commit is contained in:
Hans-Kristian Arntzen 2020-08-20 19:20:48 +02:00 committed by GitHub
commit 4f0f0e5a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 62 additions and 0 deletions

View File

@ -55,6 +55,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.o_color = o_color;

View File

@ -22,6 +22,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -24,6 +24,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vColor = stage_input.vColor;
frag_main();
SPIRV_Cross_Output stage_output;

View File

@ -28,6 +28,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vIn = stage_input.vIn;
vIn2 = stage_input.vIn2;
frag_main();

View File

@ -24,6 +24,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
gl_SampleID = stage_input.gl_SampleID;
frag_main();
SPIRV_Cross_Output stage_output;

View File

@ -22,6 +22,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -24,6 +24,7 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vTex = stage_input.vTex;
vIndex = stage_input.vIndex;
frag_main();

View File

@ -26,6 +26,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -24,6 +24,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -28,5 +28,6 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
}

View File

@ -38,5 +38,6 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
}

View File

@ -38,5 +38,6 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
}

View File

@ -0,0 +1,27 @@
static float4 gl_FragCoord;
static float3 FragColor;
struct SPIRV_Cross_Input
{
float4 gl_FragCoord : SV_Position;
};
struct SPIRV_Cross_Output
{
float3 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = gl_FragCoord.xyz / gl_FragCoord.w.xxx;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -66,6 +66,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
Input = stage_input.Input;
InputI = stage_input.InputI;
InputU = stage_input.InputU;

View File

@ -28,5 +28,6 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
}

View File

@ -58,6 +58,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.o_color = o_color;

View File

@ -22,6 +22,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -24,6 +24,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vColor = stage_input.vColor;
frag_main();
SPIRV_Cross_Output stage_output;

View File

@ -31,6 +31,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vIn = stage_input.vIn;
vIn2 = stage_input.vIn2;
frag_main();

View File

@ -30,6 +30,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
gl_SampleID = stage_input.gl_SampleID;
frag_main();
SPIRV_Cross_Output stage_output;

View File

@ -27,6 +27,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -38,6 +38,7 @@ void frag_main()
void main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vTex = stage_input.vTex;
vIndex = stage_input.vIndex;
frag_main();

View File

@ -25,6 +25,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -23,6 +23,7 @@ void frag_main()
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;

View File

@ -0,0 +1,8 @@
#version 450
layout(location = 0) out vec3 FragColor;
void main()
{
FragColor = gl_FragCoord.xyz / gl_FragCoord.w;
}

View File

@ -2396,7 +2396,11 @@ void CompilerHLSL::emit_hlsl_entry_point()
if (legacy)
statement(builtin, " = stage_input.", builtin, " + float4(0.5f, 0.5f, 0.0f, 0.0f);");
else
{
statement(builtin, " = stage_input.", builtin, ";");
// ZW are undefined in D3D9, only do this fixup here.
statement(builtin, ".w = 1.0 / ", builtin, ".w;");
}
break;
case BuiltInVertexId: