From e88c269d022ae04c0b5fdaf71f03b44cc145820d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 2 Oct 2019 11:33:20 +1000 Subject: PostProcessing: Don't use GS expansion shader for quad buffering w/ OpenGL OpenGL doesn't render to a 2-layer backbuffer like D3D/Vulkan for quad-buffered stereo, instead drawing twice with the eye selected by glDrawBuffer() (see OGL::Renderer::RenderXFBToScreen). --- Source/Core/VideoCommon/PostProcessing.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/PostProcessing.cpp') diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 859715542b..d8666c1cee 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -714,11 +714,15 @@ bool PostProcessing::CompilePixelShader() bool PostProcessing::CompilePipeline() { + // OpenGL doesn't render to a 2-layer backbuffer like D3D/Vulkan for quad-buffered stereo, instead + // drawing twice and the eye selected by glDrawBuffer() (see OGL::Renderer::RenderXFBToScreen). + const bool use_quad_buffer_gs = g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer && + g_ActiveConfig.backend_info.api_type != APIType::OpenGL; + AbstractPipelineConfig config = {}; config.vertex_shader = m_vertex_shader.get(); - config.geometry_shader = g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer ? - g_shader_cache->GetTexcoordGeometryShader() : - nullptr; + config.geometry_shader = + use_quad_buffer_gs ? g_shader_cache->GetTexcoordGeometryShader() : nullptr; config.pixel_shader = m_pixel_shader.get(); config.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles); config.depth_state = RenderState::GetNoDepthTestingDepthState(); -- cgit v1.2.3 From b44a0980eb310b221feb84a195db63b89276a053 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 2 Oct 2019 11:52:52 +1000 Subject: PostProcessing: Use correct layer in quad-buffered modes Previously, only the left eye was being used. --- Source/Core/VideoCommon/PostProcessing.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'Source/Core/VideoCommon/PostProcessing.cpp') diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index d8666c1cee..0212793f98 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -441,8 +441,8 @@ std::string PostProcessing::GetUniformBufferHeader() const ss << " float4 resolution;\n"; ss << " float4 window_resolution;\n"; ss << " float4 src_rect;\n"; + ss << " int src_layer;\n"; ss << " uint time;\n"; - ss << " int layer;\n"; for (u32 i = 0; i < 2; i++) ss << " uint ubo_align_" << unused_counter++ << "_;\n"; ss << "\n"; @@ -518,10 +518,10 @@ static float4 ocol0; } ss << R"( -float4 Sample() { return texture(samp0, float3(v_tex0.xy, float(layer))); } -float4 SampleLocation(float2 location) { return texture(samp0, float3(location, float(layer))); } +float4 Sample() { return texture(samp0, v_tex0); } +float4 SampleLocation(float2 location) { return texture(samp0, float3(location, float(v_tex0.z))); } float4 SampleLayer(int layer) { return texture(samp0, float3(v_tex0.xy, float(layer))); } -#define SampleOffset(offset) textureOffset(samp0, float3(v_tex0.xy, float(layer)), offset) +#define SampleOffset(offset) textureOffset(samp0, v_tex0, offset) float2 GetWindowResolution() { @@ -543,6 +543,11 @@ float2 GetCoordinates() return v_tex0.xy; } +float GetLayer() +{ + return v_tex0.z; +} + uint GetTime() { return time; @@ -599,7 +604,7 @@ bool PostProcessing::CompileVertexShader() } ss << " v_tex0 = float3(float((id << 1) & 2), float(id & 2), 0.0f);\n"; ss << " opos = float4(v_tex0.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"; - ss << " v_tex0 = float3(src_rect.xy + (src_rect.zw * v_tex0.xy), 0.0f);\n"; + ss << " v_tex0 = float3(src_rect.xy + (src_rect.zw * v_tex0.xy), float(src_layer));\n"; if (g_ActiveConfig.backend_info.api_type == APIType::Vulkan) ss << " opos.y = -opos.y;\n"; @@ -621,8 +626,8 @@ struct BuiltinUniforms float resolution[4]; float window_resolution[4]; float src_rect[4]; - s32 time; - u32 layer; + s32 src_layer; + u32 time; u32 padding[2]; }; @@ -646,8 +651,8 @@ void PostProcessing::FillUniformBuffer(const MathUtil::Rectangle& src, {static_cast(src.left) * rcp_src_width, static_cast(src.top) * rcp_src_height, static_cast(src.GetWidth()) * rcp_src_width, static_cast(src.GetHeight()) * rcp_src_height}, - static_cast(m_timer.GetTimeElapsed()), - static_cast(src_layer), + static_cast(src_layer), + static_cast(m_timer.GetTimeElapsed()), }; u8* buf = m_uniform_staging_buffer.data(); -- cgit v1.2.3 From c98a5f7dfd6d5f779c4f18735656becc4fd9f365 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 2 Oct 2019 12:19:47 +1000 Subject: Renderer: Draw ImGui interface to both eyes --- Source/Core/VideoCommon/PostProcessing.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'Source/Core/VideoCommon/PostProcessing.cpp') diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 0212793f98..8329b74e79 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -719,15 +719,10 @@ bool PostProcessing::CompilePixelShader() bool PostProcessing::CompilePipeline() { - // OpenGL doesn't render to a 2-layer backbuffer like D3D/Vulkan for quad-buffered stereo, instead - // drawing twice and the eye selected by glDrawBuffer() (see OGL::Renderer::RenderXFBToScreen). - const bool use_quad_buffer_gs = g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer && - g_ActiveConfig.backend_info.api_type != APIType::OpenGL; - AbstractPipelineConfig config = {}; config.vertex_shader = m_vertex_shader.get(); config.geometry_shader = - use_quad_buffer_gs ? g_shader_cache->GetTexcoordGeometryShader() : nullptr; + g_renderer->UseGeometryShaderForUI() ? g_shader_cache->GetTexcoordGeometryShader() : nullptr; config.pixel_shader = m_pixel_shader.get(); config.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles); config.depth_state = RenderState::GetNoDepthTestingDepthState(); -- cgit v1.2.3 From 33a6d265e51c2289192eef15ffeec830b98b2410 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 2 Oct 2019 12:59:50 +1000 Subject: PostProcessing: Use interface blocks for shaders --- Source/Core/VideoCommon/PostProcessing.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/PostProcessing.cpp') diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 8329b74e79..23c0ded751 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -499,7 +499,18 @@ std::string PostProcessing::GetHeader() const else { ss << "SAMPLER_BINDING(0) uniform sampler2DArray samp0;\n"; - 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"; } @@ -597,7 +608,17 @@ bool PostProcessing::CompileVertexShader() } else { - ss << "VARYING_LOCATION(0) out float3 v_tex0;\n"; + if (g_ActiveConfig.backend_info.bSupportsGeometryShaders) + { + ss << "VARYING_LOCATION(0) out VertexData {\n"; + ss << " float3 v_tex0;\n"; + ss << "};\n"; + } + else + { + ss << "VARYING_LOCATION(0) out float3 v_tex0;\n"; + } + ss << "#define id gl_VertexID\n"; ss << "#define opos gl_Position\n"; ss << "void main() {\n"; -- cgit v1.2.3