From f64c912d02dfd5889fee1caacf0420b371e1e9d2 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 31 Jul 2024 03:36:08 +0300 Subject: [PATCH] gl: Fixes for asahi linux --- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 2 +- rpcs3/Emu/RSX/GL/GLPresent.cpp | 7 ++++--- rpcs3/Emu/RSX/GL/glutils/fbo.cpp | 12 ++++++++++++ rpcs3/Emu/RSX/GL/glutils/fbo.h | 8 ++++++++ rpcs3/Emu/RSX/GSFrameBase.h | 1 + .../GLSLSnippets/VideoOutCalibrationPass.glsl | 1 + rpcs3/rpcs3qt/gl_gs_frame.cpp | 2 ++ rpcs3/rpcs3qt/gs_frame.cpp | 15 +++++++++++++-- rpcs3/rpcs3qt/gs_frame.h | 1 + 9 files changed, 43 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 3780f83909..58367ed4c3 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -122,7 +122,7 @@ void GLGSRender::on_init_thread() gl::init(); gl::set_command_context(gl_state); - //Enable adaptive vsync if vsync is requested + // Enable adaptive vsync if vsync is requested gl::set_swapinterval(g_cfg.video.vsync ? -1 : 0); if (g_cfg.video.debug_output) diff --git a/rpcs3/Emu/RSX/GL/GLPresent.cpp b/rpcs3/Emu/RSX/GL/GLPresent.cpp index 6c0fa403c7..3ad9ed1c4d 100644 --- a/rpcs3/Emu/RSX/GL/GLPresent.cpp +++ b/rpcs3/Emu/RSX/GL/GLPresent.cpp @@ -271,8 +271,8 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info) if (!image_to_flip || aspect_ratio.x1 || aspect_ratio.y1) { - // Clear the window background to black - gl_state.clear_color(0, 0, 0, 0); + // Clear the window background to opaque black + gl_state.clear_color(0, 0, 0, 255); gl::screen.clear(gl::buffers::color); } @@ -302,6 +302,7 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info) const areai screen_area = coordi({}, { static_cast(buffer_width), static_cast(buffer_height) }); const bool use_full_rgb_range_output = g_cfg.video.full_rgb_range_output.get(); + const bool backbuffer_has_alpha = m_frame->has_alpha(); if (!m_upscaler || m_output_scaling != g_cfg.video.output_scaling) { @@ -322,7 +323,7 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info) } } - if (use_full_rgb_range_output && rsx::fcmp(avconfig.gamma, 1.f) && avconfig.stereo_mode == stereo_render_mode_options::disabled) + if (!backbuffer_has_alpha && use_full_rgb_range_output && rsx::fcmp(avconfig.gamma, 1.f) && avconfig.stereo_mode == stereo_render_mode_options::disabled) { // Blit source image to the screen m_upscaler->scale_output(cmd, image_to_flip, screen_area, aspect_ratio.flipped_vertical(), UPSCALE_AND_COMMIT | UPSCALE_DEFAULT_VIEW); diff --git a/rpcs3/Emu/RSX/GL/glutils/fbo.cpp b/rpcs3/Emu/RSX/GL/glutils/fbo.cpp index 66c977d392..b1f6300c01 100644 --- a/rpcs3/Emu/RSX/GL/glutils/fbo.cpp +++ b/rpcs3/Emu/RSX/GL/glutils/fbo.cpp @@ -75,6 +75,12 @@ namespace gl DSA_CALL3(NamedFramebufferDrawBuffers, FramebufferDrawBuffers, m_id, 1, &buf); } + void fbo::draw_buffer(swapchain_buffer buffer) const + { + GLenum buf = static_cast(buffer); + DSA_CALL3(NamedFramebufferDrawBuffers, FramebufferDrawBuffers, m_id, 1, &buf); + } + void fbo::draw_buffers(const std::initializer_list& indexes) const { rsx::simple_array ids; @@ -91,6 +97,12 @@ namespace gl DSA_CALL3(NamedFramebufferReadBuffer, FramebufferReadBuffer, m_id, buffer.id()); } + void fbo::read_buffer(swapchain_buffer buffer) const + { + GLenum buf = static_cast(buffer); + DSA_CALL3(NamedFramebufferReadBuffer, FramebufferReadBuffer, m_id, buf); + } + void fbo::draw_arrays(GLenum mode, GLsizei count, GLint first) const { save_binding_state save(*this); diff --git a/rpcs3/Emu/RSX/GL/glutils/fbo.h b/rpcs3/Emu/RSX/GL/glutils/fbo.h index da86051ede..9837c425cd 100644 --- a/rpcs3/Emu/RSX/GL/glutils/fbo.h +++ b/rpcs3/Emu/RSX/GL/glutils/fbo.h @@ -181,6 +181,12 @@ namespace gl draw_frame_buffer = GL_DRAW_FRAMEBUFFER }; + enum class swapchain_buffer + { + back = GL_BACK, + front = GL_FRONT + }; + void create(); void bind() const; void blit(const fbo& dst, areai src_area, areai dst_area, buffers buffers_ = buffers::color, filter filter_ = filter::nearest) const; @@ -191,9 +197,11 @@ namespace gl void recreate(); void draw_buffer(const attachment& buffer) const; + void draw_buffer(swapchain_buffer buffer) const; void draw_buffers(const std::initializer_list& indexes) const; void read_buffer(const attachment& buffer) const; + void read_buffer(swapchain_buffer buffer) const; void draw_arrays(GLenum mode, GLsizei count, GLint first = 0) const; void draw_arrays(const buffer& buffer, GLenum mode, GLsizei count, GLint first = 0) const; diff --git a/rpcs3/Emu/RSX/GSFrameBase.h b/rpcs3/Emu/RSX/GSFrameBase.h index 2834b44df8..4630334c41 100644 --- a/rpcs3/Emu/RSX/GSFrameBase.h +++ b/rpcs3/Emu/RSX/GSFrameBase.h @@ -25,6 +25,7 @@ public: virtual void flip(draw_context_t ctx, bool skip_frame = false) = 0; virtual int client_width() = 0; virtual int client_height() = 0; + virtual bool has_alpha() = 0; virtual display_handle_t handle() const = 0; diff --git a/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl b/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl index 3797d2b5f1..f33dbd6aa5 100644 --- a/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl +++ b/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl @@ -149,5 +149,6 @@ void main() ocol = (limit_range == FALSE) ? color : ((color * 220.) + 16.) / 255.; + ocol.a = 1.f; } )" diff --git a/rpcs3/rpcs3qt/gl_gs_frame.cpp b/rpcs3/rpcs3qt/gl_gs_frame.cpp index 01c4aa4259..7d4a5c8a01 100644 --- a/rpcs3/rpcs3qt/gl_gs_frame.cpp +++ b/rpcs3/rpcs3qt/gl_gs_frame.cpp @@ -11,9 +11,11 @@ gl_gs_frame::gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& ap { setSurfaceType(QSurface::OpenGLSurface); + m_format.setRenderableType(QSurfaceFormat::OpenGL); m_format.setMajorVersion(4); m_format.setMinorVersion(3); m_format.setProfile(QSurfaceFormat::CoreProfile); + m_format.setAlphaBufferSize(0); m_format.setDepthBufferSize(0); m_format.setSwapBehavior(QSurfaceFormat::SwapBehavior::DoubleBuffer); if (g_cfg.video.debug_output) diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 7f176813d8..e5faf27543 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -113,8 +113,14 @@ gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, setScreen(screen); setGeometry(geometry); setTitle(qstr(m_window_title)); - setVisibility(startup_visibility); - create(); + + if (g_cfg.video.renderer != video_renderer::opengl) + { + // Do not display the window before OpenGL is configured! + // This works fine in windows and X11 but wayland-egl will crash later. + setVisibility(startup_visibility); + create(); + } // TODO: enable in Qt6 //m_shortcut_handler = new shortcut_handler(gui::shortcuts::shortcut_handler_id::game_window, this, m_gui_settings); @@ -1216,3 +1222,8 @@ void gs_frame::progress_set_limit(int limit) { m_progress_indicator->set_range(0, limit); } + +bool gs_frame::has_alpha() +{ + return format().hasAlpha(); +} diff --git a/rpcs3/rpcs3qt/gs_frame.h b/rpcs3/rpcs3qt/gs_frame.h index e384a62f2c..48c15f9400 100644 --- a/rpcs3/rpcs3qt/gs_frame.h +++ b/rpcs3/rpcs3qt/gs_frame.h @@ -89,6 +89,7 @@ protected: void flip(draw_context_t context, bool skip_frame = false) override; int client_width() override; int client_height() override; + bool has_alpha() override; bool event(QEvent* ev) override;