From bd9c876e36fcd4ea121abb81d9845d583789ec4a Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 20 Oct 2022 20:54:35 +0300 Subject: [PATCH] gl: Handle clip plane switching using API calls and the state tracker --- rpcs3/Emu/RSX/GL/GLDraw.cpp | 3 +++ rpcs3/Emu/RSX/GL/GLGSRender.cpp | 8 -------- rpcs3/Emu/RSX/GL/GLOverlays.cpp | 1 + rpcs3/Emu/RSX/GL/GLTextOut.h | 1 + rpcs3/Emu/RSX/GL/GLVertexProgram.cpp | 12 ++++++------ rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp | 19 +++++++++++++++++++ 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLDraw.cpp b/rpcs3/Emu/RSX/GL/GLDraw.cpp index dabd821c36..be402812e3 100644 --- a/rpcs3/Emu/RSX/GL/GLDraw.cpp +++ b/rpcs3/Emu/RSX/GL/GLDraw.cpp @@ -289,6 +289,9 @@ void GLGSRender::update_draw_state() break; } + // Clip planes + gl_state.clip_planes((current_vertex_program.output_mask >> CELL_GCM_ATTRIB_OUTPUT_UC0) & 0x3F); + // Sample control // TODO: MinSampleShading //gl_state.enable(rsx::method_registers.msaa_enabled(), GL_MULTISAMPLE); diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 49b02c3390..9ff528e8a2 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -320,14 +320,6 @@ void GLGSRender::on_init_thread() query.result = 0; } - //Clip planes are shader controlled; enable all planes driver-side - glEnable(GL_CLIP_DISTANCE0 + 0); - glEnable(GL_CLIP_DISTANCE0 + 1); - glEnable(GL_CLIP_DISTANCE0 + 2); - glEnable(GL_CLIP_DISTANCE0 + 3); - glEnable(GL_CLIP_DISTANCE0 + 4); - glEnable(GL_CLIP_DISTANCE0 + 5); - m_ui_renderer.create(); m_video_output_pass.create(); diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.cpp b/rpcs3/Emu/RSX/GL/GLOverlays.cpp index 4fe7b726fa..4e9ed84ffa 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.cpp +++ b/rpcs3/Emu/RSX/GL/GLOverlays.cpp @@ -133,6 +133,7 @@ namespace gl cmd->disable(GL_CULL_FACE); cmd->disable(GL_SCISSOR_TEST); + cmd->clip_planes(GL_NONE); if (enable_depth_writes) { diff --git a/rpcs3/Emu/RSX/GL/GLTextOut.h b/rpcs3/Emu/RSX/GL/GLTextOut.h index 40c51f161a..e288f1ff75 100644 --- a/rpcs3/Emu/RSX/GL/GLTextOut.h +++ b/rpcs3/Emu/RSX/GL/GLTextOut.h @@ -182,6 +182,7 @@ namespace gl glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao); load_program(cmd, scale_x, scale_y, shader_offsets.data(), counts.size(), color); + cmd->clip_planes(GL_NONE); m_vao.bind(); diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index 1d285fa46d..c4f04dee8a 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -88,13 +88,13 @@ static const vertex_reg_info reg_table[] = //Fog output shares a data source register with clip planes 0-2 so only declare when specified { "fog_c", true, "dst_reg5", ".xxxx", true, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_FOG }, //Warning: Always define all 3 clip plane groups together to avoid flickering with openGL - { "gl_ClipDistance[0]", false, "dst_reg5", ".y * user_clip_factor[0].x", false, "user_clip_enabled[0].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 }, - { "gl_ClipDistance[1]", false, "dst_reg5", ".z * user_clip_factor[0].y", false, "user_clip_enabled[0].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 }, - { "gl_ClipDistance[2]", false, "dst_reg5", ".w * user_clip_factor[0].z", false, "user_clip_enabled[0].z > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 }, + { "gl_ClipDistance[0]", false, "dst_reg5", ".y * user_clip_factor[0].x", false, "user_clip_enabled[0].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 }, + { "gl_ClipDistance[1]", false, "dst_reg5", ".z * user_clip_factor[0].y", false, "user_clip_enabled[0].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 }, + { "gl_ClipDistance[2]", false, "dst_reg5", ".w * user_clip_factor[0].z", false, "user_clip_enabled[0].z > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 }, { "gl_PointSize", false, "dst_reg6", ".x", false, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_POINTSIZE }, - { "gl_ClipDistance[3]", false, "dst_reg6", ".y * user_clip_factor[0].w", false, "user_clip_enabled[0].w > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 }, - { "gl_ClipDistance[4]", false, "dst_reg6", ".z * user_clip_factor[1].x", false, "user_clip_enabled[1].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 }, - { "gl_ClipDistance[5]", false, "dst_reg6", ".w * user_clip_factor[1].y", false, "user_clip_enabled[1].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 | CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 }, + { "gl_ClipDistance[3]", false, "dst_reg6", ".y * user_clip_factor[0].w", false, "user_clip_enabled[0].w > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 }, + { "gl_ClipDistance[4]", false, "dst_reg6", ".z * user_clip_factor[1].x", false, "user_clip_enabled[1].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 }, + { "gl_ClipDistance[5]", false, "dst_reg6", ".w * user_clip_factor[1].y", false, "user_clip_enabled[1].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 }, { "tc0", true, "dst_reg7", "", false, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX0 }, { "tc1", true, "dst_reg8", "", false, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX1 }, { "tc2", true, "dst_reg9", "", false, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX2 }, diff --git a/rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp b/rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp index f12a397f6e..45bf612a3b 100644 --- a/rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp +++ b/rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp @@ -10,6 +10,7 @@ namespace gl class driver_state { const u32 DEPTH_BOUNDS = 0xFFFF0001; + const u32 CLIP_PLANES = 0xFFFF0002; const u32 DEPTH_RANGE = 0xFFFF0004; const u32 STENCIL_FRONT_FUNC = 0xFFFF0005; const u32 STENCIL_BACK_FUNC = 0xFFFF0006; @@ -308,6 +309,24 @@ namespace gl } } + void clip_planes(GLuint mask) + { + if (!test_and_set_property(CLIP_PLANES, mask)) + { + for (u32 i = 0; i < 6; ++i) + { + if (mask & (1 << i)) + { + glEnable(GL_CLIP_DISTANCE0 + i); + } + else + { + glDisable(GL_CLIP_DISTANCE0 + i); + } + } + } + } + void use_program(GLuint program) { if (current_program == program)