Merge pull request #7857 from stenzek/opengl-stereo

OGL: Fix stereoscopy
This commit is contained in:
Connor McLaughlin 2019-04-22 12:41:12 +10:00 committed by GitHub
commit 93be178f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 24 deletions

View File

@ -104,10 +104,23 @@ static void EmitVertexMainDeclaration(std::stringstream& ss, u32 num_tex_inputs,
<< ";\n"; << ";\n";
if (position_input) if (position_input)
ss << "ATTRIBUTE_LOCATION(" << SHADER_POSITION_ATTRIB << ") in float4 rawpos;\n"; ss << "ATTRIBUTE_LOCATION(" << SHADER_POSITION_ATTRIB << ") in float4 rawpos;\n";
for (u32 i = 0; i < num_tex_outputs; i++)
ss << "VARYING_LOCATION(" << i << ") out float3 v_tex" << i << ";\n"; if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
for (u32 i = 0; i < num_color_outputs; i++) {
ss << "VARYING_LOCATION(" << (num_tex_inputs + i) << ") out float4 v_col" << i << ";\n"; ss << "VARYING_LOCATION(0) out VertexData {\n";
for (u32 i = 0; i < num_tex_outputs; i++)
ss << " float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_color_outputs; i++)
ss << " float4 v_col" << i << ";\n";
ss << "};\n";
}
else
{
for (u32 i = 0; i < num_tex_outputs; i++)
ss << "VARYING_LOCATION(" << i << ") out float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_color_outputs; i++)
ss << "VARYING_LOCATION(" << (num_tex_inputs + i) << ") out float4 v_col" << i << ";\n";
}
ss << "#define opos gl_Position\n"; ss << "#define opos gl_Position\n";
ss << extra_inputs << "\n"; ss << extra_inputs << "\n";
ss << "void main()\n"; ss << "void main()\n";
@ -138,10 +151,23 @@ static void EmitPixelMainDeclaration(std::stringstream& ss, u32 num_tex_inputs,
case APIType::OpenGL: case APIType::OpenGL:
case APIType::Vulkan: case APIType::Vulkan:
{ {
for (u32 i = 0; i < num_tex_inputs; i++) if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
ss << "VARYING_LOCATION(" << i << ") in float3 v_tex" << i << ";\n"; {
for (u32 i = 0; i < num_color_inputs; i++) ss << "VARYING_LOCATION(0) in VertexData {\n";
ss << "VARYING_LOCATION(" << (num_tex_inputs + i) << ") in float4 v_col" << i << ";\n"; for (u32 i = 0; i < num_tex_inputs; i++)
ss << " in float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_color_inputs; i++)
ss << " in float4 v_col" << i << ";\n";
ss << "};\n";
}
else
{
for (u32 i = 0; i < num_tex_inputs; i++)
ss << "VARYING_LOCATION(" << i << ") in float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_color_inputs; i++)
ss << "VARYING_LOCATION(" << (num_tex_inputs + i) << ") in float4 v_col" << i << ";\n";
}
ss << "FRAGMENT_OUTPUT_LOCATION(0) out " << output_type << " ocol0;\n"; ss << "FRAGMENT_OUTPUT_LOCATION(0) out " << output_type << " ocol0;\n";
ss << extra_vars << "\n"; ss << extra_vars << "\n";
ss << "void main()\n"; ss << "void main()\n";
@ -218,15 +244,20 @@ std::string GeneratePassthroughGeometryShader(u32 num_tex, u32 num_colors)
{ {
ss << "layout(triangles) in;\n"; ss << "layout(triangles) in;\n";
ss << "layout(triangle_strip, max_vertices = 6) out;\n"; ss << "layout(triangle_strip, max_vertices = 6) out;\n";
for (u32 i = 0; i < num_tex; i++) if (num_tex > 0 || num_colors > 0)
{ {
ss << "layout(location = " << i << ") in float3 v_tex" << i << "[];\n"; ss << "VARYING_LOCATION(0) in VertexData {\n";
ss << "layout(location = " << i << ") out float3 out_tex" << i << ";\n"; for (u32 i = 0; i < num_tex; i++)
} ss << " float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_colors; i++) for (u32 i = 0; i < num_colors; i++)
{ ss << " float4 v_col" << i << ";\n";
ss << "layout(location = " << (num_tex + i) << ") in float4 v_col" << i << "[];\n"; ss << "} v_in[];\n";
ss << "layout(location = " << (num_tex + i) << ") out float4 out_col" << i << ";\n"; ss << "VARYING_LOCATION(0) out VertexData {\n";
for (u32 i = 0; i < num_tex; i++)
ss << " float3 v_tex" << i << ";\n";
for (u32 i = 0; i < num_colors; i++)
ss << " float4 v_col" << i << ";\n";
ss << "} v_out;\n";
} }
ss << "\n"; ss << "\n";
ss << "void main()\n"; ss << "void main()\n";
@ -240,9 +271,10 @@ std::string GeneratePassthroughGeometryShader(u32 num_tex, u32 num_colors)
{ {
ss << " gl_Position = gl_in[" << v << "].gl_Position;\n"; ss << " gl_Position = gl_in[" << v << "].gl_Position;\n";
for (u32 i = 0; i < num_tex; i++) for (u32 i = 0; i < num_tex; i++)
ss << " out_tex" << i << " = float3(v_tex" << i << "[" << v << "].xy, float(j));\n"; ss << " v_out.v_tex" << i << " = float3(v_in[" << v << "].v_tex" << i
<< ".xy, float(j));\n";
for (u32 i = 0; i < num_colors; i++) for (u32 i = 0; i < num_colors; i++)
ss << " out_col" << i << " = v_col" << i << "[" << v << "];\n"; ss << " v_out.v_col" << i << " = v_in[" << v << "].v_col" << i << ";\n";
ss << " EmitVertex();\n\n"; ss << " EmitVertex();\n\n";
} }
ss << " EndPrimitive();\n"; ss << " EndPrimitive();\n";

View File

@ -72,7 +72,16 @@ static void WriteHeader(char*& p, APIType ApiType)
WRITE(p, " float2 clamp_tb;\n"); WRITE(p, " float2 clamp_tb;\n");
WRITE(p, " float3 filter_coefficients;\n"); WRITE(p, " float3 filter_coefficients;\n");
WRITE(p, "};\n"); WRITE(p, "};\n");
WRITE(p, "VARYING_LOCATION(0) in float3 v_tex0;\n"); if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
WRITE(p, "VARYING_LOCATION(0) in VertexData {\n");
WRITE(p, " float3 v_tex0;\n");
WRITE(p, "};\n");
}
else
{
WRITE(p, "VARYING_LOCATION(0) in float3 v_tex0;\n");
}
WRITE(p, "SAMPLER_BINDING(0) uniform sampler2DArray samp0;\n"); WRITE(p, "SAMPLER_BINDING(0) uniform sampler2DArray samp0;\n");
WRITE(p, "FRAGMENT_OUTPUT_LOCATION(0) out float4 ocol0;\n"); WRITE(p, "FRAGMENT_OUTPUT_LOCATION(0) out float4 ocol0;\n");
} }
@ -1510,7 +1519,16 @@ float4 DecodePixel(int val)
} }
else else
{ {
ss << "VARYING_LOCATION(0) in float3 v_tex0;\n"; if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
ss << "VARYING_LOCATION(0) in VertexData {\n";
ss << " float3 v_tex0;\n";
ss << "};\n";
}
else
{
ss << "VARYING_LOCATION(0) in float3 v_tex0;\n";
}
ss << "FRAGMENT_OUTPUT_LOCATION(0) out float4 ocol0;\n"; ss << "FRAGMENT_OUTPUT_LOCATION(0) out float4 ocol0;\n";
ss << "void main() {\n"; ss << "void main() {\n";
ss << " float3 coords = v_tex0;\n"; ss << " float3 coords = v_tex0;\n";

View File

@ -67,8 +67,17 @@ ShaderCode GenerateVertexShader(APIType api_type)
} }
else if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) else if (api_type == APIType::OpenGL || api_type == APIType::Vulkan)
{ {
out.Write("VARYING_LOCATION(0) out float3 v_tex0;\n" if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
"#define id gl_VertexID\n" {
out.Write("VARYING_LOCATION(0) out VertexData {\n");
out.Write(" float3 v_tex0;\n");
out.Write("};\n");
}
else
{
out.Write("VARYING_LOCATION(0) out float3 v_tex0;\n");
}
out.Write("#define id gl_VertexID\n"
"#define opos gl_Position\n" "#define opos gl_Position\n"
"void main() {\n"); "void main() {\n");
} }
@ -112,8 +121,17 @@ ShaderCode GeneratePixelShader(APIType api_type, const UidData* uid_data)
"clamp_tb.x, clamp_tb.y), %s));\n" "clamp_tb.x, clamp_tb.y), %s));\n"
"}\n", "}\n",
mono_depth ? "0.0" : "uv.z"); mono_depth ? "0.0" : "uv.z");
out.Write("VARYING_LOCATION(0) in vec3 v_tex0;\n" if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
"FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;" {
out.Write("VARYING_LOCATION(0) in VertexData {\n");
out.Write(" float3 v_tex0;\n");
out.Write("};\n");
}
else
{
out.Write("VARYING_LOCATION(0) in vec3 v_tex0;\n");
}
out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;"
"void main()\n{\n"); "void main()\n{\n");
} }