diff options
| author | 2024-01-15 00:09:34 -0500 | |
|---|---|---|
| committer | 2024-01-31 11:27:20 -0500 | |
| commit | 60ee29aac386c31b9a9add6a12f051273fa45dae (patch) | |
| tree | 1640a3e44c8339ec4dd4241ca63256c12d7767ae /src | |
| parent | renderer_opengl: split out SMAA (diff) | |
| download | yuzu-60ee29aac386c31b9a9add6a12f051273fa45dae.tar.gz yuzu-60ee29aac386c31b9a9add6a12f051273fa45dae.tar.xz yuzu-60ee29aac386c31b9a9add6a12f051273fa45dae.zip | |
renderer_opengl: split out FXAA
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/video_core/host_shaders/fxaa.vert | 4 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_blit_screen.cpp | 22 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_blit_screen.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/present/fxaa.cpp | 40 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/present/fxaa.h | 27 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/present/fxaa.cpp | 2 |
7 files changed, 79 insertions, 24 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 524e2cae8..9879c3ad7 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -118,6 +118,8 @@ add_library(video_core STATIC | |||
| 118 | renderer_null/renderer_null.h | 118 | renderer_null/renderer_null.h |
| 119 | renderer_opengl/present/fsr.cpp | 119 | renderer_opengl/present/fsr.cpp |
| 120 | renderer_opengl/present/fsr.h | 120 | renderer_opengl/present/fsr.h |
| 121 | renderer_opengl/present/fxaa.cpp | ||
| 122 | renderer_opengl/present/fxaa.h | ||
| 121 | renderer_opengl/present/smaa.cpp | 123 | renderer_opengl/present/smaa.cpp |
| 122 | renderer_opengl/present/smaa.h | 124 | renderer_opengl/present/smaa.h |
| 123 | renderer_opengl/present/util.h | 125 | renderer_opengl/present/util.h |
diff --git a/src/video_core/host_shaders/fxaa.vert b/src/video_core/host_shaders/fxaa.vert index c2717d90d..223ab785e 100644 --- a/src/video_core/host_shaders/fxaa.vert +++ b/src/video_core/host_shaders/fxaa.vert | |||
| @@ -7,8 +7,8 @@ out gl_PerVertex { | |||
| 7 | vec4 gl_Position; | 7 | vec4 gl_Position; |
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | const vec2 vertices[4] = | 10 | const vec2 vertices[3] = |
| 11 | vec2[4](vec2(-1.0, 1.0), vec2(1.0, 1.0), vec2(-1.0, -1.0), vec2(1.0, -1.0)); | 11 | vec2[3](vec2(-1,-1), vec2(3,-1), vec2(-1, 3)); |
| 12 | 12 | ||
| 13 | layout (location = 0) out vec4 posPos; | 13 | layout (location = 0) out vec4 posPos; |
| 14 | 14 | ||
diff --git a/src/video_core/renderer_opengl/gl_blit_screen.cpp b/src/video_core/renderer_opengl/gl_blit_screen.cpp index cc343f171..44f6a0922 100644 --- a/src/video_core/renderer_opengl/gl_blit_screen.cpp +++ b/src/video_core/renderer_opengl/gl_blit_screen.cpp | |||
| @@ -5,8 +5,6 @@ | |||
| 5 | #include "video_core/host_shaders/ffx_a_h.h" | 5 | #include "video_core/host_shaders/ffx_a_h.h" |
| 6 | #include "video_core/host_shaders/ffx_fsr1_h.h" | 6 | #include "video_core/host_shaders/ffx_fsr1_h.h" |
| 7 | #include "video_core/host_shaders/full_screen_triangle_vert.h" | 7 | #include "video_core/host_shaders/full_screen_triangle_vert.h" |
| 8 | #include "video_core/host_shaders/fxaa_frag.h" | ||
| 9 | #include "video_core/host_shaders/fxaa_vert.h" | ||
| 10 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h" | 8 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h" |
| 11 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h" | 9 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h" |
| 12 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h" | 10 | #include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h" |
| @@ -22,6 +20,7 @@ | |||
| 22 | #include "video_core/renderer_opengl/gl_shader_util.h" | 20 | #include "video_core/renderer_opengl/gl_shader_util.h" |
| 23 | #include "video_core/renderer_opengl/gl_state_tracker.h" | 21 | #include "video_core/renderer_opengl/gl_state_tracker.h" |
| 24 | #include "video_core/renderer_opengl/present/fsr.h" | 22 | #include "video_core/renderer_opengl/present/fsr.h" |
| 23 | #include "video_core/renderer_opengl/present/fxaa.h" | ||
| 25 | #include "video_core/renderer_opengl/present/smaa.h" | 24 | #include "video_core/renderer_opengl/present/smaa.h" |
| 26 | #include "video_core/textures/decoders.h" | 25 | #include "video_core/textures/decoders.h" |
| 27 | 26 | ||
| @@ -67,9 +66,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_, | |||
| 67 | : rasterizer(rasterizer_), device_memory(device_memory_), state_tracker(state_tracker_), | 66 | : rasterizer(rasterizer_), device_memory(device_memory_), state_tracker(state_tracker_), |
| 68 | program_manager(program_manager_), device(device_) { | 67 | program_manager(program_manager_), device(device_) { |
| 69 | // Create shader programs | 68 | // Create shader programs |
| 70 | fxaa_vertex = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER); | ||
| 71 | fxaa_fragment = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER); | ||
| 72 | |||
| 73 | const auto replace_include = [](std::string& shader_source, std::string_view include_name, | 69 | const auto replace_include = [](std::string& shader_source, std::string_view include_name, |
| 74 | std::string_view include_content) { | 70 | std::string_view include_content) { |
| 75 | const std::string include_string = fmt::format("#include \"{}\"", include_name); | 71 | const std::string include_string = fmt::format("#include \"{}\"", include_name); |
| @@ -131,8 +127,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_, | |||
| 131 | glClearTexImage(framebuffer_texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 127 | glClearTexImage(framebuffer_texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 132 | framebuffer_data); | 128 | framebuffer_data); |
| 133 | 129 | ||
| 134 | aa_framebuffer.Create(); | ||
| 135 | |||
| 136 | // Enable unified vertex attributes and query vertex buffer address when the driver supports it | 130 | // Enable unified vertex attributes and query vertex buffer address when the driver supports it |
| 137 | if (device.HasVertexBufferUnifiedMemory()) { | 131 | if (device.HasVertexBufferUnifiedMemory()) { |
| 138 | glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV); | 132 | glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV); |
| @@ -244,13 +238,10 @@ void BlitScreen::ConfigureFramebufferTexture(const Tegra::FramebufferConfig& fra | |||
| 244 | framebuffer_texture.resource.Create(GL_TEXTURE_2D); | 238 | framebuffer_texture.resource.Create(GL_TEXTURE_2D); |
| 245 | glTextureStorage2D(framebuffer_texture.resource.handle, 1, internal_format, | 239 | glTextureStorage2D(framebuffer_texture.resource.handle, 1, internal_format, |
| 246 | framebuffer_texture.width, framebuffer_texture.height); | 240 | framebuffer_texture.width, framebuffer_texture.height); |
| 247 | aa_texture.Release(); | ||
| 248 | aa_texture.Create(GL_TEXTURE_2D); | ||
| 249 | glTextureStorage2D(aa_texture.handle, 1, GL_RGBA16F, | ||
| 250 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), | ||
| 251 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.height)); | ||
| 252 | glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0, aa_texture.handle, 0); | ||
| 253 | 241 | ||
| 242 | fxaa = std::make_unique<FXAA>( | ||
| 243 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), | ||
| 244 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.height)); | ||
| 254 | smaa = std::make_unique<SMAA>( | 245 | smaa = std::make_unique<SMAA>( |
| 255 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), | 246 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), |
| 256 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.height)); | 247 | Settings::values.resolution_info.ScaleUp(framebuffer_texture.height)); |
| @@ -323,10 +314,7 @@ void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer, | |||
| 323 | 314 | ||
| 324 | switch (anti_aliasing) { | 315 | switch (anti_aliasing) { |
| 325 | case Settings::AntiAliasing::Fxaa: { | 316 | case Settings::AntiAliasing::Fxaa: { |
| 326 | program_manager.BindPresentPrograms(fxaa_vertex.handle, fxaa_fragment.handle); | 317 | glBindTextureUnit(0, fxaa->Draw(program_manager, info.display_texture)); |
| 327 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle); | ||
| 328 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
| 329 | glBindTextureUnit(0, aa_texture.handle); | ||
| 330 | } break; | 318 | } break; |
| 331 | case Settings::AntiAliasing::Smaa: { | 319 | case Settings::AntiAliasing::Smaa: { |
| 332 | glBindTextureUnit(0, smaa->Draw(program_manager, info.display_texture)); | 320 | glBindTextureUnit(0, smaa->Draw(program_manager, info.display_texture)); |
diff --git a/src/video_core/renderer_opengl/gl_blit_screen.h b/src/video_core/renderer_opengl/gl_blit_screen.h index 945c7226a..2cb9a5015 100644 --- a/src/video_core/renderer_opengl/gl_blit_screen.h +++ b/src/video_core/renderer_opengl/gl_blit_screen.h | |||
| @@ -22,6 +22,7 @@ namespace OpenGL { | |||
| 22 | 22 | ||
| 23 | class Device; | 23 | class Device; |
| 24 | class FSR; | 24 | class FSR; |
| 25 | class FXAA; | ||
| 25 | class ProgramManager; | 26 | class ProgramManager; |
| 26 | class RasterizerOpenGL; | 27 | class RasterizerOpenGL; |
| 27 | class SMAA; | 28 | class SMAA; |
| @@ -77,8 +78,6 @@ private: | |||
| 77 | OGLSampler present_sampler; | 78 | OGLSampler present_sampler; |
| 78 | OGLSampler present_sampler_nn; | 79 | OGLSampler present_sampler_nn; |
| 79 | OGLBuffer vertex_buffer; | 80 | OGLBuffer vertex_buffer; |
| 80 | OGLProgram fxaa_vertex; | ||
| 81 | OGLProgram fxaa_fragment; | ||
| 82 | OGLProgram present_vertex; | 81 | OGLProgram present_vertex; |
| 83 | OGLProgram present_bilinear_fragment; | 82 | OGLProgram present_bilinear_fragment; |
| 84 | OGLProgram present_bicubic_fragment; | 83 | OGLProgram present_bicubic_fragment; |
| @@ -87,10 +86,9 @@ private: | |||
| 87 | 86 | ||
| 88 | /// Display information for Switch screen | 87 | /// Display information for Switch screen |
| 89 | TextureInfo framebuffer_texture; | 88 | TextureInfo framebuffer_texture; |
| 90 | OGLTexture aa_texture; | ||
| 91 | OGLFramebuffer aa_framebuffer; | ||
| 92 | 89 | ||
| 93 | std::unique_ptr<FSR> fsr; | 90 | std::unique_ptr<FSR> fsr; |
| 91 | std::unique_ptr<FXAA> fxaa; | ||
| 94 | std::unique_ptr<SMAA> smaa; | 92 | std::unique_ptr<SMAA> smaa; |
| 95 | 93 | ||
| 96 | /// OpenGL framebuffer data | 94 | /// OpenGL framebuffer data |
diff --git a/src/video_core/renderer_opengl/present/fxaa.cpp b/src/video_core/renderer_opengl/present/fxaa.cpp new file mode 100644 index 000000000..9425c42fa --- /dev/null +++ b/src/video_core/renderer_opengl/present/fxaa.cpp | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "video_core/host_shaders/fxaa_frag.h" | ||
| 5 | #include "video_core/host_shaders/fxaa_vert.h" | ||
| 6 | #include "video_core/renderer_opengl/gl_shader_manager.h" | ||
| 7 | #include "video_core/renderer_opengl/gl_shader_util.h" | ||
| 8 | #include "video_core/renderer_opengl/present/fxaa.h" | ||
| 9 | #include "video_core/renderer_opengl/present/util.h" | ||
| 10 | |||
| 11 | namespace OpenGL { | ||
| 12 | |||
| 13 | FXAA::FXAA(u32 width, u32 height) { | ||
| 14 | vert_shader = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER); | ||
| 15 | frag_shader = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER); | ||
| 16 | |||
| 17 | sampler = CreateBilinearSampler(); | ||
| 18 | |||
| 19 | framebuffer.Create(); | ||
| 20 | |||
| 21 | texture.Create(GL_TEXTURE_2D); | ||
| 22 | glTextureStorage2D(texture.handle, 1, GL_RGBA16F, width, height); | ||
| 23 | glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0); | ||
| 24 | } | ||
| 25 | |||
| 26 | FXAA::~FXAA() = default; | ||
| 27 | |||
| 28 | GLuint FXAA::Draw(ProgramManager& program_manager, GLuint input_texture) { | ||
| 29 | glFrontFace(GL_CCW); | ||
| 30 | |||
| 31 | program_manager.BindPresentPrograms(vert_shader.handle, frag_shader.handle); | ||
| 32 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle); | ||
| 33 | glBindTextureUnit(0, input_texture); | ||
| 34 | glDrawArrays(GL_TRIANGLES, 0, 3); | ||
| 35 | glFrontFace(GL_CW); | ||
| 36 | |||
| 37 | return texture.handle; | ||
| 38 | } | ||
| 39 | |||
| 40 | } // namespace OpenGL | ||
diff --git a/src/video_core/renderer_opengl/present/fxaa.h b/src/video_core/renderer_opengl/present/fxaa.h new file mode 100644 index 000000000..b898198f1 --- /dev/null +++ b/src/video_core/renderer_opengl/present/fxaa.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "video_core/renderer_opengl/gl_resource_manager.h" | ||
| 7 | |||
| 8 | namespace OpenGL { | ||
| 9 | |||
| 10 | class ProgramManager; | ||
| 11 | |||
| 12 | class FXAA { | ||
| 13 | public: | ||
| 14 | explicit FXAA(u32 width, u32 height); | ||
| 15 | ~FXAA(); | ||
| 16 | |||
| 17 | GLuint Draw(ProgramManager& program_manager, GLuint input_texture); | ||
| 18 | |||
| 19 | private: | ||
| 20 | OGLProgram vert_shader; | ||
| 21 | OGLProgram frag_shader; | ||
| 22 | OGLSampler sampler; | ||
| 23 | OGLFramebuffer framebuffer; | ||
| 24 | OGLTexture texture; | ||
| 25 | }; | ||
| 26 | |||
| 27 | } // namespace OpenGL | ||
diff --git a/src/video_core/renderer_vulkan/present/fxaa.cpp b/src/video_core/renderer_vulkan/present/fxaa.cpp index 6f87ddebb..6c772ada3 100644 --- a/src/video_core/renderer_vulkan/present/fxaa.cpp +++ b/src/video_core/renderer_vulkan/present/fxaa.cpp | |||
| @@ -133,7 +133,7 @@ VkImageView FXAA::Draw(Scheduler& scheduler, size_t image_index, VkImage source_ | |||
| 133 | BeginRenderPass(cmdbuf, renderpass, framebuffer, extent); | 133 | BeginRenderPass(cmdbuf, renderpass, framebuffer, extent); |
| 134 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); | 134 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 135 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, {}); | 135 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, {}); |
| 136 | cmdbuf.Draw(4, 1, 0, 0); | 136 | cmdbuf.Draw(3, 1, 0, 0); |
| 137 | cmdbuf.EndRenderPass(); | 137 | cmdbuf.EndRenderPass(); |
| 138 | TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL); | 138 | TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL); |
| 139 | }); | 139 | }); |