renderer_opengl: split out FXAA
This commit is contained in:
parent
b90eff4bc6
commit
60ee29aac3
7 changed files with 79 additions and 24 deletions
|
@ -118,6 +118,8 @@ add_library(video_core STATIC
|
||||||
renderer_null/renderer_null.h
|
renderer_null/renderer_null.h
|
||||||
renderer_opengl/present/fsr.cpp
|
renderer_opengl/present/fsr.cpp
|
||||||
renderer_opengl/present/fsr.h
|
renderer_opengl/present/fsr.h
|
||||||
|
renderer_opengl/present/fxaa.cpp
|
||||||
|
renderer_opengl/present/fxaa.h
|
||||||
renderer_opengl/present/smaa.cpp
|
renderer_opengl/present/smaa.cpp
|
||||||
renderer_opengl/present/smaa.h
|
renderer_opengl/present/smaa.h
|
||||||
renderer_opengl/present/util.h
|
renderer_opengl/present/util.h
|
||||||
|
|
|
@ -7,8 +7,8 @@ out gl_PerVertex {
|
||||||
vec4 gl_Position;
|
vec4 gl_Position;
|
||||||
};
|
};
|
||||||
|
|
||||||
const vec2 vertices[4] =
|
const vec2 vertices[3] =
|
||||||
vec2[4](vec2(-1.0, 1.0), vec2(1.0, 1.0), vec2(-1.0, -1.0), vec2(1.0, -1.0));
|
vec2[3](vec2(-1,-1), vec2(3,-1), vec2(-1, 3));
|
||||||
|
|
||||||
layout (location = 0) out vec4 posPos;
|
layout (location = 0) out vec4 posPos;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
#include "video_core/host_shaders/ffx_a_h.h"
|
#include "video_core/host_shaders/ffx_a_h.h"
|
||||||
#include "video_core/host_shaders/ffx_fsr1_h.h"
|
#include "video_core/host_shaders/ffx_fsr1_h.h"
|
||||||
#include "video_core/host_shaders/full_screen_triangle_vert.h"
|
#include "video_core/host_shaders/full_screen_triangle_vert.h"
|
||||||
#include "video_core/host_shaders/fxaa_frag.h"
|
|
||||||
#include "video_core/host_shaders/fxaa_vert.h"
|
|
||||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h"
|
#include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h"
|
||||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h"
|
#include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h"
|
||||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h"
|
#include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h"
|
||||||
|
@ -22,6 +20,7 @@
|
||||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
||||||
#include "video_core/renderer_opengl/present/fsr.h"
|
#include "video_core/renderer_opengl/present/fsr.h"
|
||||||
|
#include "video_core/renderer_opengl/present/fxaa.h"
|
||||||
#include "video_core/renderer_opengl/present/smaa.h"
|
#include "video_core/renderer_opengl/present/smaa.h"
|
||||||
#include "video_core/textures/decoders.h"
|
#include "video_core/textures/decoders.h"
|
||||||
|
|
||||||
|
@ -67,9 +66,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
|
||||||
: rasterizer(rasterizer_), device_memory(device_memory_), state_tracker(state_tracker_),
|
: rasterizer(rasterizer_), device_memory(device_memory_), state_tracker(state_tracker_),
|
||||||
program_manager(program_manager_), device(device_) {
|
program_manager(program_manager_), device(device_) {
|
||||||
// Create shader programs
|
// Create shader programs
|
||||||
fxaa_vertex = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER);
|
|
||||||
fxaa_fragment = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
const auto replace_include = [](std::string& shader_source, std::string_view include_name,
|
const auto replace_include = [](std::string& shader_source, std::string_view include_name,
|
||||||
std::string_view include_content) {
|
std::string_view include_content) {
|
||||||
const std::string include_string = fmt::format("#include \"{}\"", include_name);
|
const std::string include_string = fmt::format("#include \"{}\"", include_name);
|
||||||
|
@ -131,8 +127,6 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
|
||||||
glClearTexImage(framebuffer_texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
glClearTexImage(framebuffer_texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||||
framebuffer_data);
|
framebuffer_data);
|
||||||
|
|
||||||
aa_framebuffer.Create();
|
|
||||||
|
|
||||||
// Enable unified vertex attributes and query vertex buffer address when the driver supports it
|
// Enable unified vertex attributes and query vertex buffer address when the driver supports it
|
||||||
if (device.HasVertexBufferUnifiedMemory()) {
|
if (device.HasVertexBufferUnifiedMemory()) {
|
||||||
glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
|
glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
|
||||||
|
@ -244,13 +238,10 @@ void BlitScreen::ConfigureFramebufferTexture(const Tegra::FramebufferConfig& fra
|
||||||
framebuffer_texture.resource.Create(GL_TEXTURE_2D);
|
framebuffer_texture.resource.Create(GL_TEXTURE_2D);
|
||||||
glTextureStorage2D(framebuffer_texture.resource.handle, 1, internal_format,
|
glTextureStorage2D(framebuffer_texture.resource.handle, 1, internal_format,
|
||||||
framebuffer_texture.width, framebuffer_texture.height);
|
framebuffer_texture.width, framebuffer_texture.height);
|
||||||
aa_texture.Release();
|
|
||||||
aa_texture.Create(GL_TEXTURE_2D);
|
fxaa = std::make_unique<FXAA>(
|
||||||
glTextureStorage2D(aa_texture.handle, 1, GL_RGBA16F,
|
|
||||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
||||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
||||||
glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0, aa_texture.handle, 0);
|
|
||||||
|
|
||||||
smaa = std::make_unique<SMAA>(
|
smaa = std::make_unique<SMAA>(
|
||||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
||||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
||||||
|
@ -323,10 +314,7 @@ void BlitScreen::DrawScreen(const Tegra::FramebufferConfig& framebuffer,
|
||||||
|
|
||||||
switch (anti_aliasing) {
|
switch (anti_aliasing) {
|
||||||
case Settings::AntiAliasing::Fxaa: {
|
case Settings::AntiAliasing::Fxaa: {
|
||||||
program_manager.BindPresentPrograms(fxaa_vertex.handle, fxaa_fragment.handle);
|
glBindTextureUnit(0, fxaa->Draw(program_manager, info.display_texture));
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle);
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
glBindTextureUnit(0, aa_texture.handle);
|
|
||||||
} break;
|
} break;
|
||||||
case Settings::AntiAliasing::Smaa: {
|
case Settings::AntiAliasing::Smaa: {
|
||||||
glBindTextureUnit(0, smaa->Draw(program_manager, info.display_texture));
|
glBindTextureUnit(0, smaa->Draw(program_manager, info.display_texture));
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace OpenGL {
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class FSR;
|
class FSR;
|
||||||
|
class FXAA;
|
||||||
class ProgramManager;
|
class ProgramManager;
|
||||||
class RasterizerOpenGL;
|
class RasterizerOpenGL;
|
||||||
class SMAA;
|
class SMAA;
|
||||||
|
@ -77,8 +78,6 @@ private:
|
||||||
OGLSampler present_sampler;
|
OGLSampler present_sampler;
|
||||||
OGLSampler present_sampler_nn;
|
OGLSampler present_sampler_nn;
|
||||||
OGLBuffer vertex_buffer;
|
OGLBuffer vertex_buffer;
|
||||||
OGLProgram fxaa_vertex;
|
|
||||||
OGLProgram fxaa_fragment;
|
|
||||||
OGLProgram present_vertex;
|
OGLProgram present_vertex;
|
||||||
OGLProgram present_bilinear_fragment;
|
OGLProgram present_bilinear_fragment;
|
||||||
OGLProgram present_bicubic_fragment;
|
OGLProgram present_bicubic_fragment;
|
||||||
|
@ -87,10 +86,9 @@ private:
|
||||||
|
|
||||||
/// Display information for Switch screen
|
/// Display information for Switch screen
|
||||||
TextureInfo framebuffer_texture;
|
TextureInfo framebuffer_texture;
|
||||||
OGLTexture aa_texture;
|
|
||||||
OGLFramebuffer aa_framebuffer;
|
|
||||||
|
|
||||||
std::unique_ptr<FSR> fsr;
|
std::unique_ptr<FSR> fsr;
|
||||||
|
std::unique_ptr<FXAA> fxaa;
|
||||||
std::unique_ptr<SMAA> smaa;
|
std::unique_ptr<SMAA> smaa;
|
||||||
|
|
||||||
/// OpenGL framebuffer data
|
/// OpenGL framebuffer data
|
||||||
|
|
40
src/video_core/renderer_opengl/present/fxaa.cpp
Normal file
40
src/video_core/renderer_opengl/present/fxaa.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "video_core/host_shaders/fxaa_frag.h"
|
||||||
|
#include "video_core/host_shaders/fxaa_vert.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
|
#include "video_core/renderer_opengl/present/fxaa.h"
|
||||||
|
#include "video_core/renderer_opengl/present/util.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
FXAA::FXAA(u32 width, u32 height) {
|
||||||
|
vert_shader = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER);
|
||||||
|
frag_shader = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
sampler = CreateBilinearSampler();
|
||||||
|
|
||||||
|
framebuffer.Create();
|
||||||
|
|
||||||
|
texture.Create(GL_TEXTURE_2D);
|
||||||
|
glTextureStorage2D(texture.handle, 1, GL_RGBA16F, width, height);
|
||||||
|
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FXAA::~FXAA() = default;
|
||||||
|
|
||||||
|
GLuint FXAA::Draw(ProgramManager& program_manager, GLuint input_texture) {
|
||||||
|
glFrontFace(GL_CCW);
|
||||||
|
|
||||||
|
program_manager.BindPresentPrograms(vert_shader.handle, frag_shader.handle);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
||||||
|
glBindTextureUnit(0, input_texture);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
glFrontFace(GL_CW);
|
||||||
|
|
||||||
|
return texture.handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace OpenGL
|
27
src/video_core/renderer_opengl/present/fxaa.h
Normal file
27
src/video_core/renderer_opengl/present/fxaa.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
class ProgramManager;
|
||||||
|
|
||||||
|
class FXAA {
|
||||||
|
public:
|
||||||
|
explicit FXAA(u32 width, u32 height);
|
||||||
|
~FXAA();
|
||||||
|
|
||||||
|
GLuint Draw(ProgramManager& program_manager, GLuint input_texture);
|
||||||
|
|
||||||
|
private:
|
||||||
|
OGLProgram vert_shader;
|
||||||
|
OGLProgram frag_shader;
|
||||||
|
OGLSampler sampler;
|
||||||
|
OGLFramebuffer framebuffer;
|
||||||
|
OGLTexture texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace OpenGL
|
|
@ -133,7 +133,7 @@ VkImageView FXAA::Draw(Scheduler& scheduler, size_t image_index, VkImage source_
|
||||||
BeginRenderPass(cmdbuf, renderpass, framebuffer, extent);
|
BeginRenderPass(cmdbuf, renderpass, framebuffer, extent);
|
||||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, {});
|
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, {});
|
||||||
cmdbuf.Draw(4, 1, 0, 0);
|
cmdbuf.Draw(3, 1, 0, 0);
|
||||||
cmdbuf.EndRenderPass();
|
cmdbuf.EndRenderPass();
|
||||||
TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL);
|
TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue