summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Liam2024-01-14 21:11:28 -0500
committerGravatar Liam2024-01-31 11:27:20 -0500
commitb90eff4bc666548a77eb58ac152408c80ff952b3 (patch)
tree1b7532cf61703be3cfe496a74481eeac31a06e92 /src
parentrenderer_vulkan: split up blit screen resources into separate antialias and w... (diff)
downloadyuzu-b90eff4bc666548a77eb58ac152408c80ff952b3.tar.gz
yuzu-b90eff4bc666548a77eb58ac152408c80ff952b3.tar.xz
yuzu-b90eff4bc666548a77eb58ac152408c80ff952b3.zip
renderer_opengl: split out SMAA
Diffstat (limited to 'src')
-rw-r--r--src/video_core/CMakeLists.txt7
-rw-r--r--src/video_core/renderer_opengl/gl_blit_screen.cpp90
-rw-r--r--src/video_core/renderer_opengl/gl_blit_screen.h17
-rw-r--r--src/video_core/renderer_opengl/present/fsr.cpp (renamed from src/video_core/renderer_opengl/gl_fsr.cpp)2
-rw-r--r--src/video_core/renderer_opengl/present/fsr.h (renamed from src/video_core/renderer_opengl/gl_fsr.h)0
-rw-r--r--src/video_core/renderer_opengl/present/smaa.cpp108
-rw-r--r--src/video_core/renderer_opengl/present/smaa.h35
-rw-r--r--src/video_core/renderer_opengl/present/util.h32
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp1
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.h1
10 files changed, 197 insertions, 96 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 825815ebd..524e2cae8 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -116,6 +116,11 @@ add_library(video_core STATIC
116 renderer_null/null_rasterizer.h 116 renderer_null/null_rasterizer.h
117 renderer_null/renderer_null.cpp 117 renderer_null/renderer_null.cpp
118 renderer_null/renderer_null.h 118 renderer_null/renderer_null.h
119 renderer_opengl/present/fsr.cpp
120 renderer_opengl/present/fsr.h
121 renderer_opengl/present/smaa.cpp
122 renderer_opengl/present/smaa.h
123 renderer_opengl/present/util.h
119 renderer_opengl/blit_image.cpp 124 renderer_opengl/blit_image.cpp
120 renderer_opengl/blit_image.h 125 renderer_opengl/blit_image.h
121 renderer_opengl/gl_blit_screen.cpp 126 renderer_opengl/gl_blit_screen.cpp
@@ -129,8 +134,6 @@ add_library(video_core STATIC
129 renderer_opengl/gl_device.h 134 renderer_opengl/gl_device.h
130 renderer_opengl/gl_fence_manager.cpp 135 renderer_opengl/gl_fence_manager.cpp
131 renderer_opengl/gl_fence_manager.h 136 renderer_opengl/gl_fence_manager.h
132 renderer_opengl/gl_fsr.cpp
133 renderer_opengl/gl_fsr.h
134 renderer_opengl/gl_graphics_pipeline.cpp 137 renderer_opengl/gl_graphics_pipeline.cpp
135 renderer_opengl/gl_graphics_pipeline.h 138 renderer_opengl/gl_graphics_pipeline.h
136 renderer_opengl/gl_rasterizer.cpp 139 renderer_opengl/gl_rasterizer.cpp
diff --git a/src/video_core/renderer_opengl/gl_blit_screen.cpp b/src/video_core/renderer_opengl/gl_blit_screen.cpp
index 88757ba38..cc343f171 100644
--- a/src/video_core/renderer_opengl/gl_blit_screen.cpp
+++ b/src/video_core/renderer_opengl/gl_blit_screen.cpp
@@ -13,22 +13,16 @@
13#include "video_core/host_shaders/opengl_present_frag.h" 13#include "video_core/host_shaders/opengl_present_frag.h"
14#include "video_core/host_shaders/opengl_present_scaleforce_frag.h" 14#include "video_core/host_shaders/opengl_present_scaleforce_frag.h"
15#include "video_core/host_shaders/opengl_present_vert.h" 15#include "video_core/host_shaders/opengl_present_vert.h"
16#include "video_core/host_shaders/opengl_smaa_glsl.h"
17#include "video_core/host_shaders/present_bicubic_frag.h" 16#include "video_core/host_shaders/present_bicubic_frag.h"
18#include "video_core/host_shaders/present_gaussian_frag.h" 17#include "video_core/host_shaders/present_gaussian_frag.h"
19#include "video_core/host_shaders/smaa_blending_weight_calculation_frag.h" 18
20#include "video_core/host_shaders/smaa_blending_weight_calculation_vert.h"
21#include "video_core/host_shaders/smaa_edge_detection_frag.h"
22#include "video_core/host_shaders/smaa_edge_detection_vert.h"
23#include "video_core/host_shaders/smaa_neighborhood_blending_frag.h"
24#include "video_core/host_shaders/smaa_neighborhood_blending_vert.h"
25#include "video_core/renderer_opengl/gl_blit_screen.h" 19#include "video_core/renderer_opengl/gl_blit_screen.h"
26#include "video_core/renderer_opengl/gl_rasterizer.h" 20#include "video_core/renderer_opengl/gl_rasterizer.h"
27#include "video_core/renderer_opengl/gl_shader_manager.h" 21#include "video_core/renderer_opengl/gl_shader_manager.h"
28#include "video_core/renderer_opengl/gl_shader_util.h" 22#include "video_core/renderer_opengl/gl_shader_util.h"
29#include "video_core/renderer_opengl/gl_state_tracker.h" 23#include "video_core/renderer_opengl/gl_state_tracker.h"
30#include "video_core/smaa_area_tex.h" 24#include "video_core/renderer_opengl/present/fsr.h"
31#include "video_core/smaa_search_tex.h" 25#include "video_core/renderer_opengl/present/smaa.h"
32#include "video_core/textures/decoders.h" 26#include "video_core/textures/decoders.h"
33 27
34namespace OpenGL { 28namespace OpenGL {
@@ -84,24 +78,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
84 shader_source.replace(pos, include_string.size(), include_content); 78 shader_source.replace(pos, include_string.size(), include_content);
85 }; 79 };
86 80
87 const auto SmaaShader = [&](std::string_view specialized_source, GLenum stage) {
88 std::string shader_source{specialized_source};
89 replace_include(shader_source, "opengl_smaa.glsl", HostShaders::OPENGL_SMAA_GLSL);
90 return CreateProgram(shader_source, stage);
91 };
92
93 smaa_edge_detection_vert = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_VERT, GL_VERTEX_SHADER);
94 smaa_edge_detection_frag =
95 SmaaShader(HostShaders::SMAA_EDGE_DETECTION_FRAG, GL_FRAGMENT_SHADER);
96 smaa_blending_weight_calculation_vert =
97 SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_VERT, GL_VERTEX_SHADER);
98 smaa_blending_weight_calculation_frag =
99 SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_FRAG, GL_FRAGMENT_SHADER);
100 smaa_neighborhood_blending_vert =
101 SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_VERT, GL_VERTEX_SHADER);
102 smaa_neighborhood_blending_frag =
103 SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_FRAG, GL_FRAGMENT_SHADER);
104
105 present_vertex = CreateProgram(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER); 81 present_vertex = CreateProgram(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER);
106 present_bilinear_fragment = CreateProgram(HostShaders::OPENGL_PRESENT_FRAG, GL_FRAGMENT_SHADER); 82 present_bilinear_fragment = CreateProgram(HostShaders::OPENGL_PRESENT_FRAG, GL_FRAGMENT_SHADER);
107 present_bicubic_fragment = CreateProgram(HostShaders::PRESENT_BICUBIC_FRAG, GL_FRAGMENT_SHADER); 83 present_bicubic_fragment = CreateProgram(HostShaders::PRESENT_BICUBIC_FRAG, GL_FRAGMENT_SHADER);
@@ -157,15 +133,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
157 133
158 aa_framebuffer.Create(); 134 aa_framebuffer.Create();
159 135
160 smaa_area_tex.Create(GL_TEXTURE_2D);
161 glTextureStorage2D(smaa_area_tex.handle, 1, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT);
162 glTextureSubImage2D(smaa_area_tex.handle, 0, 0, 0, AREATEX_WIDTH, AREATEX_HEIGHT, GL_RG,
163 GL_UNSIGNED_BYTE, areaTexBytes);
164 smaa_search_tex.Create(GL_TEXTURE_2D);
165 glTextureStorage2D(smaa_search_tex.handle, 1, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT);
166 glTextureSubImage2D(smaa_search_tex.handle, 0, 0, 0, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GL_RED,
167 GL_UNSIGNED_BYTE, searchTexBytes);
168
169 // Enable unified vertex attributes and query vertex buffer address when the driver supports it 136 // Enable unified vertex attributes and query vertex buffer address when the driver supports it
170 if (device.HasVertexBufferUnifiedMemory()) { 137 if (device.HasVertexBufferUnifiedMemory()) {
171 glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV); 138 glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
@@ -176,6 +143,8 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
176 } 143 }
177} 144}
178 145
146BlitScreen::~BlitScreen() = default;
147
179FramebufferTextureInfo BlitScreen::PrepareRenderTarget( 148FramebufferTextureInfo BlitScreen::PrepareRenderTarget(
180 const Tegra::FramebufferConfig& framebuffer) { 149 const Tegra::FramebufferConfig& framebuffer) {
181 // If framebuffer is provided, reload it from memory to a texture 150 // If framebuffer is provided, reload it from memory to a texture
@@ -281,16 +250,10 @@ void BlitScreen::ConfigureFramebufferTexture(const Tegra::FramebufferConfig& fra
281 Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), 250 Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
282 Settings::values.resolution_info.ScaleUp(framebuffer_texture.height)); 251 Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
283 glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0, aa_texture.handle, 0); 252 glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0, aa_texture.handle, 0);
284 smaa_edges_tex.Release(); 253
285 smaa_edges_tex.Create(GL_TEXTURE_2D); 254 smaa = std::make_unique<SMAA>(
286 glTextureStorage2D(smaa_edges_tex.handle, 1, GL_RG16F, 255 Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
287 Settings::values.resolution_info.ScaleUp(framebuffer_texture.width), 256 Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
288 Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
289 smaa_blend_tex.Release();
290 smaa_blend_tex.Create(GL_TEXTURE_2D);
291 glTextureStorage2D(smaa_blend_tex.handle, 1, GL_RGBA16F,
292 Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
293 Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
294} 257}
295 258
296void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer, 259void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer,
@@ -363,39 +326,10 @@ void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer,
363 program_manager.BindPresentPrograms(fxaa_vertex.handle, fxaa_fragment.handle); 326 program_manager.BindPresentPrograms(fxaa_vertex.handle, fxaa_fragment.handle);
364 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle); 327 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle);
365 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 328 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
329 glBindTextureUnit(0, aa_texture.handle);
366 } break; 330 } break;
367 case Settings::AntiAliasing::Smaa: { 331 case Settings::AntiAliasing::Smaa: {
368 glClearColor(0, 0, 0, 0); 332 glBindTextureUnit(0, smaa->Draw(program_manager, info.display_texture));
369 glFrontFace(GL_CCW);
370 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle);
371 glBindSampler(1, present_sampler.handle);
372 glBindSampler(2, present_sampler.handle);
373
374 glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
375 smaa_edges_tex.handle, 0);
376 glClear(GL_COLOR_BUFFER_BIT);
377 program_manager.BindPresentPrograms(smaa_edge_detection_vert.handle,
378 smaa_edge_detection_frag.handle);
379 glDrawArrays(GL_TRIANGLES, 0, 3);
380
381 glBindTextureUnit(0, smaa_edges_tex.handle);
382 glBindTextureUnit(1, smaa_area_tex.handle);
383 glBindTextureUnit(2, smaa_search_tex.handle);
384 glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
385 smaa_blend_tex.handle, 0);
386 glClear(GL_COLOR_BUFFER_BIT);
387 program_manager.BindPresentPrograms(smaa_blending_weight_calculation_vert.handle,
388 smaa_blending_weight_calculation_frag.handle);
389 glDrawArrays(GL_TRIANGLES, 0, 3);
390
391 glBindTextureUnit(0, info.display_texture);
392 glBindTextureUnit(1, smaa_blend_tex.handle);
393 glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
394 aa_texture.handle, 0);
395 program_manager.BindPresentPrograms(smaa_neighborhood_blending_vert.handle,
396 smaa_neighborhood_blending_frag.handle);
397 glDrawArrays(GL_TRIANGLES, 0, 3);
398 glFrontFace(GL_CW);
399 } break; 333 } break;
400 default: 334 default:
401 UNREACHABLE(); 335 UNREACHABLE();
@@ -403,8 +337,6 @@ void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer,
403 337
404 glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); 338 glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb);
405 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); 339 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
406
407 glBindTextureUnit(0, aa_texture.handle);
408 } 340 }
409 glDisablei(GL_SCISSOR_TEST, 0); 341 glDisablei(GL_SCISSOR_TEST, 0);
410 342
diff --git a/src/video_core/renderer_opengl/gl_blit_screen.h b/src/video_core/renderer_opengl/gl_blit_screen.h
index 13d769958..945c7226a 100644
--- a/src/video_core/renderer_opengl/gl_blit_screen.h
+++ b/src/video_core/renderer_opengl/gl_blit_screen.h
@@ -8,7 +8,6 @@
8 8
9#include "core/hle/service/nvnflinger/pixel_format.h" 9#include "core/hle/service/nvnflinger/pixel_format.h"
10#include "video_core/host1x/gpu_device_memory_manager.h" 10#include "video_core/host1x/gpu_device_memory_manager.h"
11#include "video_core/renderer_opengl/gl_fsr.h"
12#include "video_core/renderer_opengl/gl_resource_manager.h" 11#include "video_core/renderer_opengl/gl_resource_manager.h"
13 12
14namespace Layout { 13namespace Layout {
@@ -22,7 +21,10 @@ struct FramebufferConfig;
22namespace OpenGL { 21namespace OpenGL {
23 22
24class Device; 23class Device;
24class FSR;
25class ProgramManager;
25class RasterizerOpenGL; 26class RasterizerOpenGL;
27class SMAA;
26class StateTracker; 28class StateTracker;
27 29
28/// Structure used for storing information about the textures for the Switch screen 30/// Structure used for storing information about the textures for the Switch screen
@@ -50,6 +52,7 @@ public:
50 Tegra::MaxwellDeviceMemoryManager& device_memory, 52 Tegra::MaxwellDeviceMemoryManager& device_memory,
51 StateTracker& state_tracker, ProgramManager& program_manager, 53 StateTracker& state_tracker, ProgramManager& program_manager,
52 Device& device); 54 Device& device);
55 ~BlitScreen();
53 56
54 void ConfigureFramebufferTexture(const Tegra::FramebufferConfig& framebuffer); 57 void ConfigureFramebufferTexture(const Tegra::FramebufferConfig& framebuffer);
55 58
@@ -87,18 +90,8 @@ private:
87 OGLTexture aa_texture; 90 OGLTexture aa_texture;
88 OGLFramebuffer aa_framebuffer; 91 OGLFramebuffer aa_framebuffer;
89 92
90 OGLProgram smaa_edge_detection_vert;
91 OGLProgram smaa_blending_weight_calculation_vert;
92 OGLProgram smaa_neighborhood_blending_vert;
93 OGLProgram smaa_edge_detection_frag;
94 OGLProgram smaa_blending_weight_calculation_frag;
95 OGLProgram smaa_neighborhood_blending_frag;
96 OGLTexture smaa_area_tex;
97 OGLTexture smaa_search_tex;
98 OGLTexture smaa_edges_tex;
99 OGLTexture smaa_blend_tex;
100
101 std::unique_ptr<FSR> fsr; 93 std::unique_ptr<FSR> fsr;
94 std::unique_ptr<SMAA> smaa;
102 95
103 /// OpenGL framebuffer data 96 /// OpenGL framebuffer data
104 std::vector<u8> gl_framebuffer_data; 97 std::vector<u8> gl_framebuffer_data;
diff --git a/src/video_core/renderer_opengl/gl_fsr.cpp b/src/video_core/renderer_opengl/present/fsr.cpp
index 429dcdc6c..e5945b80b 100644
--- a/src/video_core/renderer_opengl/gl_fsr.cpp
+++ b/src/video_core/renderer_opengl/present/fsr.cpp
@@ -3,9 +3,9 @@
3 3
4#include "common/settings.h" 4#include "common/settings.h"
5#include "video_core/fsr.h" 5#include "video_core/fsr.h"
6#include "video_core/renderer_opengl/gl_fsr.h"
7#include "video_core/renderer_opengl/gl_shader_manager.h" 6#include "video_core/renderer_opengl/gl_shader_manager.h"
8#include "video_core/renderer_opengl/gl_shader_util.h" 7#include "video_core/renderer_opengl/gl_shader_util.h"
8#include "video_core/renderer_opengl/present/fsr.h"
9 9
10namespace OpenGL { 10namespace OpenGL {
11using namespace FSR; 11using namespace FSR;
diff --git a/src/video_core/renderer_opengl/gl_fsr.h b/src/video_core/renderer_opengl/present/fsr.h
index a5092e396..a5092e396 100644
--- a/src/video_core/renderer_opengl/gl_fsr.h
+++ b/src/video_core/renderer_opengl/present/fsr.h
diff --git a/src/video_core/renderer_opengl/present/smaa.cpp b/src/video_core/renderer_opengl/present/smaa.cpp
new file mode 100644
index 000000000..a9a0eb6c6
--- /dev/null
+++ b/src/video_core/renderer_opengl/present/smaa.cpp
@@ -0,0 +1,108 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "video_core/host_shaders/opengl_smaa_glsl.h"
5#include "video_core/host_shaders/smaa_blending_weight_calculation_frag.h"
6#include "video_core/host_shaders/smaa_blending_weight_calculation_vert.h"
7#include "video_core/host_shaders/smaa_edge_detection_frag.h"
8#include "video_core/host_shaders/smaa_edge_detection_vert.h"
9#include "video_core/host_shaders/smaa_neighborhood_blending_frag.h"
10#include "video_core/host_shaders/smaa_neighborhood_blending_vert.h"
11#include "video_core/renderer_opengl/gl_shader_manager.h"
12#include "video_core/renderer_opengl/gl_shader_util.h"
13#include "video_core/renderer_opengl/present/smaa.h"
14#include "video_core/renderer_opengl/present/util.h"
15#include "video_core/smaa_area_tex.h"
16#include "video_core/smaa_search_tex.h"
17
18namespace OpenGL {
19
20SMAA::SMAA(u32 width, u32 height) {
21 const auto SmaaShader = [&](std::string_view specialized_source, GLenum stage) {
22 std::string shader_source{specialized_source};
23 ReplaceInclude(shader_source, "opengl_smaa.glsl", HostShaders::OPENGL_SMAA_GLSL);
24 return CreateProgram(shader_source, stage);
25 };
26
27 edge_detection_vert = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_VERT, GL_VERTEX_SHADER);
28 edge_detection_frag = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_FRAG, GL_FRAGMENT_SHADER);
29 blending_weight_calculation_vert =
30 SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_VERT, GL_VERTEX_SHADER);
31 blending_weight_calculation_frag =
32 SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_FRAG, GL_FRAGMENT_SHADER);
33 neighborhood_blending_vert =
34 SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_VERT, GL_VERTEX_SHADER);
35 neighborhood_blending_frag =
36 SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_FRAG, GL_FRAGMENT_SHADER);
37
38 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
39 glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
40 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
41 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
42 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
43 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
44 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
45 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
46
47 area_tex.Create(GL_TEXTURE_2D);
48 glTextureStorage2D(area_tex.handle, 1, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT);
49 glTextureSubImage2D(area_tex.handle, 0, 0, 0, AREATEX_WIDTH, AREATEX_HEIGHT, GL_RG,
50 GL_UNSIGNED_BYTE, areaTexBytes);
51 search_tex.Create(GL_TEXTURE_2D);
52 glTextureStorage2D(search_tex.handle, 1, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT);
53 glTextureSubImage2D(search_tex.handle, 0, 0, 0, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GL_RED,
54 GL_UNSIGNED_BYTE, searchTexBytes);
55
56 edges_tex.Create(GL_TEXTURE_2D);
57 glTextureStorage2D(edges_tex.handle, 1, GL_RG16F, width, height);
58
59 blend_tex.Create(GL_TEXTURE_2D);
60 glTextureStorage2D(blend_tex.handle, 1, GL_RGBA16F, width, height);
61
62 sampler = CreateBilinearSampler();
63
64 framebuffer.Create();
65
66 texture.Create(GL_TEXTURE_2D);
67 glTextureStorage2D(texture.handle, 1, GL_RGBA16F, width, height);
68 glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
69}
70
71SMAA::~SMAA() = default;
72
73GLuint SMAA::Draw(ProgramManager& program_manager, GLuint input_texture) {
74 glClearColor(0, 0, 0, 0);
75 glFrontFace(GL_CCW);
76 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
77 glBindSampler(0, sampler.handle);
78 glBindSampler(1, sampler.handle);
79 glBindSampler(2, sampler.handle);
80
81 glBindTextureUnit(0, input_texture);
82 glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, edges_tex.handle, 0);
83 glClear(GL_COLOR_BUFFER_BIT);
84 program_manager.BindPresentPrograms(edge_detection_vert.handle, edge_detection_frag.handle);
85 glDrawArrays(GL_TRIANGLES, 0, 3);
86
87 glBindTextureUnit(0, edges_tex.handle);
88 glBindTextureUnit(1, area_tex.handle);
89 glBindTextureUnit(2, search_tex.handle);
90 glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, blend_tex.handle, 0);
91 glClear(GL_COLOR_BUFFER_BIT);
92 program_manager.BindPresentPrograms(blending_weight_calculation_vert.handle,
93 blending_weight_calculation_frag.handle);
94 glDrawArrays(GL_TRIANGLES, 0, 3);
95
96 glBindTextureUnit(0, input_texture);
97 glBindTextureUnit(1, blend_tex.handle);
98 glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
99 program_manager.BindPresentPrograms(neighborhood_blending_vert.handle,
100 neighborhood_blending_frag.handle);
101 glClear(GL_COLOR_BUFFER_BIT);
102 glDrawArrays(GL_TRIANGLES, 0, 3);
103 glFrontFace(GL_CW);
104
105 return texture.handle;
106}
107
108} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/present/smaa.h b/src/video_core/renderer_opengl/present/smaa.h
new file mode 100644
index 000000000..a48cb4fa9
--- /dev/null
+++ b/src/video_core/renderer_opengl/present/smaa.h
@@ -0,0 +1,35 @@
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
8namespace OpenGL {
9
10class ProgramManager;
11
12class SMAA {
13public:
14 explicit SMAA(u32 width, u32 height);
15 ~SMAA();
16
17 GLuint Draw(ProgramManager& program_manager, GLuint input_texture);
18
19private:
20 OGLProgram edge_detection_vert;
21 OGLProgram blending_weight_calculation_vert;
22 OGLProgram neighborhood_blending_vert;
23 OGLProgram edge_detection_frag;
24 OGLProgram blending_weight_calculation_frag;
25 OGLProgram neighborhood_blending_frag;
26 OGLTexture area_tex;
27 OGLTexture search_tex;
28 OGLTexture edges_tex;
29 OGLTexture blend_tex;
30 OGLSampler sampler;
31 OGLFramebuffer framebuffer;
32 OGLTexture texture;
33};
34
35} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/present/util.h b/src/video_core/renderer_opengl/present/util.h
new file mode 100644
index 000000000..0aa8b110c
--- /dev/null
+++ b/src/video_core/renderer_opengl/present/util.h
@@ -0,0 +1,32 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <string>
7
8#include "common/assert.h"
9#include "video_core/renderer_opengl/gl_resource_manager.h"
10
11namespace OpenGL {
12
13static inline void ReplaceInclude(std::string& shader_source, std::string_view include_name,
14 std::string_view include_content) {
15 const std::string include_string = fmt::format("#include \"{}\"", include_name);
16 const std::size_t pos = shader_source.find(include_string);
17 ASSERT(pos != std::string::npos);
18 shader_source.replace(pos, include_string.size(), include_content);
19};
20
21static inline OGLSampler CreateBilinearSampler() {
22 OGLSampler sampler;
23 sampler.Create();
24 glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
25 glSamplerParameteri(sampler.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
26 glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
27 glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
28 glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
29 return sampler;
30}
31
32} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 38b0aacf4..3d75fd17a 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -17,7 +17,6 @@
17#include "core/frontend/emu_window.h" 17#include "core/frontend/emu_window.h"
18#include "core/telemetry_session.h" 18#include "core/telemetry_session.h"
19#include "video_core/renderer_opengl/gl_blit_screen.h" 19#include "video_core/renderer_opengl/gl_blit_screen.h"
20#include "video_core/renderer_opengl/gl_fsr.h"
21#include "video_core/renderer_opengl/gl_rasterizer.h" 20#include "video_core/renderer_opengl/gl_rasterizer.h"
22#include "video_core/renderer_opengl/gl_shader_manager.h" 21#include "video_core/renderer_opengl/gl_shader_manager.h"
23#include "video_core/renderer_opengl/gl_shader_util.h" 22#include "video_core/renderer_opengl/gl_shader_util.h"
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h
index 23aff055a..7ab163372 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.h
+++ b/src/video_core/renderer_opengl/renderer_opengl.h
@@ -10,7 +10,6 @@
10 10
11#include "video_core/renderer_base.h" 11#include "video_core/renderer_base.h"
12#include "video_core/renderer_opengl/gl_device.h" 12#include "video_core/renderer_opengl/gl_device.h"
13#include "video_core/renderer_opengl/gl_fsr.h"
14#include "video_core/renderer_opengl/gl_rasterizer.h" 13#include "video_core/renderer_opengl/gl_rasterizer.h"
15#include "video_core/renderer_opengl/gl_resource_manager.h" 14#include "video_core/renderer_opengl/gl_resource_manager.h"
16#include "video_core/renderer_opengl/gl_shader_manager.h" 15#include "video_core/renderer_opengl/gl_shader_manager.h"