From e489fac61b61996666d3197db86acd655819ca33 Mon Sep 17 00:00:00 2001 From: KojoZero Date: Fri, 24 Apr 2026 08:54:20 -0700 Subject: [PATCH] added uniforms for vulkan --- .../host_shaders/vulkan_present.frag | 2 ++ .../host_shaders/vulkan_present.vert | 2 ++ .../host_shaders/vulkan_present_anaglyph.frag | 2 ++ .../vulkan_present_interlaced.frag | 2 ++ .../renderer_opengl/renderer_opengl.cpp | 6 ++++ .../renderer_vulkan/renderer_vulkan.cpp | 35 +++++++++++++------ .../renderer_vulkan/renderer_vulkan.h | 6 +++- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/video_core/host_shaders/vulkan_present.frag b/src/video_core/host_shaders/vulkan_present.frag index 41c0916bd..01b158732 100644 --- a/src/video_core/host_shaders/vulkan_present.frag +++ b/src/video_core/host_shaders/vulkan_present.frag @@ -12,6 +12,8 @@ layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; vec4 o_resolution; + vec2 cursor_pos; + int cursor_enable; int screen_id_l; int screen_id_r; int layer; diff --git a/src/video_core/host_shaders/vulkan_present.vert b/src/video_core/host_shaders/vulkan_present.vert index 08b4d252c..2844fdafc 100644 --- a/src/video_core/host_shaders/vulkan_present.vert +++ b/src/video_core/host_shaders/vulkan_present.vert @@ -13,6 +13,8 @@ layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; vec4 o_resolution; + vec2 cursor_pos; + int cursor_enable; int screen_id_l; int screen_id_r; int layer; diff --git a/src/video_core/host_shaders/vulkan_present_anaglyph.frag b/src/video_core/host_shaders/vulkan_present_anaglyph.frag index a01ce63f6..2d768d87a 100644 --- a/src/video_core/host_shaders/vulkan_present_anaglyph.frag +++ b/src/video_core/host_shaders/vulkan_present_anaglyph.frag @@ -24,6 +24,8 @@ layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; vec4 o_resolution; + vec2 cursor_pos; + int cursor_enable; int screen_id_l; int screen_id_r; int layer; diff --git a/src/video_core/host_shaders/vulkan_present_interlaced.frag b/src/video_core/host_shaders/vulkan_present_interlaced.frag index b033a9dec..b150413f1 100644 --- a/src/video_core/host_shaders/vulkan_present_interlaced.frag +++ b/src/video_core/host_shaders/vulkan_present_interlaced.frag @@ -12,6 +12,8 @@ layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; vec4 o_resolution; + vec2 cursor_pos; + int cursor_enable; int screen_id_l; int screen_id_r; int layer; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 441475838..d0eaad708 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -640,6 +640,12 @@ void RendererOpenGL::DrawSingleScreenStereo(const ScreenInfo& screen_info_l, 1.0f / static_cast(screen_info_l.texture.height * scale_factor), 1.0f / static_cast(screen_info_l.texture.width * scale_factor)); glUniform4f(uniform_o_resolution, w, h, 1.0f / w, 1.0f / h); + if (currScreenDraw == 1){ + glUniform1i(uniform_cursor_enable, 1); + } else { + glUniform1i(uniform_cursor_enable, 0); + } + glUniform2f(uniform_cursor_pos, cursor_pos[0]/320.0f, cursor_pos[1]/240.0f); state.texture_units[0].texture_2d = screen_info_l.display_texture; state.texture_units[1].texture_2d = screen_info_r.display_texture; state.texture_units[0].sampler = sampler; diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 0a25c2036..7a00ed342 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -783,11 +783,17 @@ void RendererVulkan::DrawSingleScreen(u32 screen_id, float x, float y, float w, const u32 scale_factor = GetResolutionScaleFactor(); draw_info.i_resolution = - Common::MakeVec(static_cast(screen_info.texture.width * scale_factor), - static_cast(screen_info.texture.height * scale_factor), - 1.0f / static_cast(screen_info.texture.width * scale_factor), - 1.0f / static_cast(screen_info.texture.height * scale_factor)); - draw_info.o_resolution = Common::MakeVec(h, w, 1.0f / h, 1.0f / w); + Common::MakeVec(static_cast(screen_info.texture.height * scale_factor), + static_cast(screen_info.texture.width * scale_factor), + 1.0f / static_cast(screen_info.texture.height * scale_factor), + 1.0f / static_cast(screen_info.texture.width * scale_factor)); + draw_info.o_resolution = Common::MakeVec(w, h, 1.0f / w, 1.0f / h); + if (currScreenDraw == 1){ + draw_info.cursor_enable = 1; + } else { + draw_info.cursor_enable = 0; + } + draw_info.cursor_pos = Common::MakeVec(cursor_pos[0]/320.0f, cursor_pos[1]/240.0f); draw_info.screen_id_l = screen_id; scheduler.Record([this, offset = offset, info = draw_info](vk::CommandBuffer cmdbuf) { @@ -855,11 +861,17 @@ void RendererVulkan::DrawSingleScreenStereo(u32 screen_id_l, u32 screen_id_r, fl const u32 scale_factor = GetResolutionScaleFactor(); draw_info.i_resolution = - Common::MakeVec(static_cast(screen_info_l.texture.width * scale_factor), - static_cast(screen_info_l.texture.height * scale_factor), - 1.0f / static_cast(screen_info_l.texture.width * scale_factor), - 1.0f / static_cast(screen_info_l.texture.height * scale_factor)); - draw_info.o_resolution = Common::MakeVec(h, w, 1.0f / h, 1.0f / w); + Common::MakeVec(static_cast(screen_info_l.texture.height * scale_factor), + static_cast(screen_info_l.texture.width * scale_factor), + 1.0f / static_cast(screen_info_l.texture.height * scale_factor), + 1.0f / static_cast(screen_info_l.texture.width * scale_factor)); + draw_info.o_resolution = Common::MakeVec(w, h, 1.0f / w, 1.0f / h); + if (currScreenDraw == 1){ + draw_info.cursor_enable = 1; + } else { + draw_info.cursor_enable = 0; + } + draw_info.cursor_pos = Common::MakeVec(cursor_pos[0]/320.0f, cursor_pos[1]/240.0f); draw_info.screen_id_l = screen_id_l; draw_info.screen_id_r = screen_id_r; @@ -886,6 +898,7 @@ void RendererVulkan::DrawTopScreen(const Layout::FramebufferLayout& layout, if (!layout.top_screen_enabled) { return; } + currScreenDraw = 0; int leftside, rightside; leftside = Settings::values.swap_eyes_3d.GetValue() ? 1 : 0; rightside = Settings::values.swap_eyes_3d.GetValue() ? 0 : 1; @@ -944,7 +957,7 @@ void RendererVulkan::DrawBottomScreen(const Layout::FramebufferLayout& layout, if (!layout.bottom_screen_enabled) { return; } - + currScreenDraw = 1; const float bottom_screen_left = static_cast(bottom_screen.left); const float bottom_screen_top = static_cast(bottom_screen.top); const float bottom_screen_width = static_cast(bottom_screen.GetWidth()); diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index 14c9bd34f..481d76187 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h @@ -58,12 +58,14 @@ struct PresentUniformData { std::array modelview; Common::Vec4f i_resolution; Common::Vec4f o_resolution; + Common::Vec2f cursor_pos; + int cursor_enable = 0; int screen_id_l = 0; int screen_id_r = 0; int layer = 0; int reverse_interlaced = 0; }; -static_assert(sizeof(PresentUniformData) == 112, +static_assert(sizeof(PresentUniformData) == 124, "PresentUniformData does not structure in shader!"); class RendererVulkan : public VideoCore::RendererBase { @@ -151,6 +153,8 @@ private: vk::ShaderModule cursor_fragment_shader{}; vk::Pipeline cursor_pipeline{}; vk::UniquePipelineLayout cursor_pipeline_layout{}; + int currScreenDraw; // 0 is Top, 1 is Bottom + std::array cursor_pos = {0,0}; }; } // namespace Vulkan