shaders-builtin: Add SMAA filter (#4313)

* gl: Add FSR and expose all screen filters

FSR runs EASU then RCAS as fragment shaders; ES 3.0 emulates
textureGather. The Qt and Android filter lists now match Vulkan.
The FidelityFX headers are copied into shaders-builtin with 0u fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* shaders: Skip clang-format for the FidelityFX headers

They are vendored copies, like AreaTex.h and SearchTex.h.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* vulkan: Wait for in-flight frames before resizing SMAA targets

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: nishinji <nishinji@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-10 18:53:21 +09:00
1 parent 74e96290f8
commit c6d2db7fd4
38 files changed
+22031 -104

No files matched your search

@@ -476,11 +476,7 @@ private fun GpuSettingsSection(
)
val screenFilterTitle = stringResource(R.string.settings_gpu_screen_filter)
val screenFilterHelp = helpEntry(screenFilterTitle, stringResource(R.string.settings_gpu_screen_filter_desc))
val filterOptions = if (isVulkan) {
listOf("Nearest", "Bilinear", "Bicubic", "FXAA", "FSR")
} else {
listOf("Bilinear", "FXAA")
}
val filterOptions = listOf("Nearest", "Bilinear", "Bicubic", "FXAA", "SMAA", "FSR")
val selectedFilter = cfg.screenFilter.takeIf { it in filterOptions } ?: filterOptions.first()
SettingsChoiceField(
title = screenFilterTitle,
+7 -2
View File
@@ -20,6 +20,11 @@
#include <glutil/object.h>
#include <util/fs.h>
#include <string_view>
namespace gl {
UniqueGLObject load_shaders(const fs::path &vertex_file_path, const fs::path &fragment_file_path);
}
// the preludes are inserted between the #version line and the shader file, which is
// where #define and #include-like shared sources have to go
UniqueGLObject load_shaders(const fs::path &vertex_file_path, const fs::path &fragment_file_path,
std::string_view vertex_prelude = "", std::string_view fragment_prelude = "");
} // namespace gl
+10 -3
View File
@@ -31,9 +31,12 @@
* \brief Loads (compiles, links) GLSL shaders at specified file paths
* \param vertex_file_path File path of the vertex shader
* \param fragment_file_path File path of the fragment shader
* \param vertex_prelude Source inserted before the vertex shader file (defines, shared code)
* \param fragment_prelude Source inserted before the fragment shader file (defines, shared code)
* \return SharedGLObject that holds the resulting program id. Empty if loading was unsuccessful
*/
UniqueGLObject gl::load_shaders(const fs::path &vertex_file_path, const fs::path &fragment_file_path) {
UniqueGLObject gl::load_shaders(const fs::path &vertex_file_path, const fs::path &fragment_file_path,
std::string_view vertex_prelude, std::string_view fragment_prelude) {
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
@@ -65,15 +68,17 @@ UniqueGLObject gl::load_shaders(const fs::path &vertex_file_path, const fs::path
// Compile vertex shader
const GLchar *vs_sources[] = {
gl_version.c_str(),
vertex_prelude.data(),
vs_code.data()
};
GLint vs_lengths[] = {
(GLint)gl_version.size(),
(GLint)vertex_prelude.size(),
(GLint)vs_code.size()
};
glShaderSource(vs, 2, vs_sources, vs_lengths);
glShaderSource(vs, 3, vs_sources, vs_lengths);
glCompileShader(vs);
// Check vertex shader
@@ -90,13 +95,15 @@ UniqueGLObject gl::load_shaders(const fs::path &vertex_file_path, const fs::path
// Compile fragment shader
const GLchar *fs_sources[] = {
gl_version.c_str(),
fragment_prelude.data(),
fs_code.data()
};
GLint fs_lengths[] = {
(GLint)gl_version.size(),
(GLint)fragment_prelude.size(),
(GLint)fs_code.size()
};
glShaderSource(fs, 2, fs_sources, fs_lengths);
glShaderSource(fs, 3, fs_sources, fs_lengths);
glCompileShader(fs);
// Check fragment shader
+5 -12
View File
@@ -1922,13 +1922,9 @@ void MainWindow::setup_status_bar() {
});
sb->addWidget(m_accuracy_button);
auto get_filter_names = [this]() -> QStringList {
if (emuenv.cfg.current_config.backend_renderer == "Vulkan")
return { QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("FSR") };
else
return { QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA") };
auto get_filter_names = []() -> QStringList {
return { QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("SMAA"), QStringLiteral("FSR") };
};
auto apply_screen_filter = [this](const std::string &filter) {
@@ -2101,11 +2097,8 @@ void MainWindow::update_accuracy_button() {
void MainWindow::update_screen_filter_button() {
auto &cc = emuenv.cfg.current_config;
const QStringList valid = (cc.backend_renderer == "Vulkan")
? QStringList{ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("FSR") }
: QStringList{ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA") };
const QStringList valid{ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("SMAA"), QStringLiteral("FSR") };
const QString current = QString::fromStdString(cc.screen_filter);
if (!valid.contains(current)) {
+2 -7
View File
@@ -1490,13 +1490,8 @@ void SettingsDialog::update_gpu_visibility() {
: m_ui->screen_filter_box->currentText();
m_ui->screen_filter_box->clear();
if (is_vulkan) {
m_ui->screen_filter_box->addItems({ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("FSR") });
} else {
m_ui->screen_filter_box->addItems({ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA") });
}
m_ui->screen_filter_box->addItems({ QStringLiteral("Nearest"), QStringLiteral("Bilinear"),
QStringLiteral("Bicubic"), QStringLiteral("FXAA"), QStringLiteral("SMAA"), QStringLiteral("FSR") });
const int idx = m_ui->screen_filter_box->findText(previous);
m_ui->screen_filter_box->setCurrentIndex(idx >= 0 ? idx : 0);
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,133 @@
// clang-format off: verbatim lookup table from the SMAA reference implementation
/**
* Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com)
* Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com)
* Copyright (C) 2013 Belen Masia (bmasia@unizar.es)
* Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com)
* Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. As clarification, there
* is no requirement that the copyright notice and permission be included in
* binary distributions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef SEARCHTEX_H
#define SEARCHTEX_H
#define SEARCHTEX_WIDTH 64
#define SEARCHTEX_HEIGHT 16
#define SEARCHTEX_PITCH SEARCHTEX_WIDTH
#define SEARCHTEX_SIZE (SEARCHTEX_HEIGHT * SEARCHTEX_PITCH)
/**
* Stored in R8 format. Load it in the following format:
* - DX9: D3DFMT_L8
* - DX10: DXGI_FORMAT_R8_UNORM
*/
static const unsigned char searchTexBytes[] = {
0xfe, 0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x7f, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00,
0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0xfe, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0xfe,
0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xfe, 0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x7f, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00,
0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0xfe, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0xfe,
0xfe, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f,
0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f,
0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f,
0x7f, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x00,
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
#endif
@@ -23,6 +23,15 @@
namespace renderer::gl {
enum class ScreenFilter {
BILINEAR,
NEAREST,
BICUBIC,
FXAA,
SMAA,
FSR,
};
class ScreenRenderer {
public:
ScreenRenderer() = default;
@@ -39,13 +48,7 @@ public:
return m_screen_texture;
}
enum class Filter {
Bilinear,
Nearest,
FXAA,
Bicubic
};
Filter filter = Filter::Bilinear;
void set_filter(ScreenFilter new_filter);
private:
struct screen_vertex {
@@ -58,6 +61,24 @@ private:
using screen_vertices_t = screen_vertex[screen_vertex_count];
// compiles the three SMAA programs and uploads the precomputed lookup tables,
// returns false (and leaves SMAA unusable) if anything went wrong
bool init_smaa(const fs::path &static_assets);
// (re)creates the offscreen edges/blend targets when the source resolution changes
void resize_smaa_targets(GLsizei width, GLsizei height);
// runs the edge detection and blending weight passes into the offscreen targets
void render_smaa_offscreen(GLuint texture, const SceFVector2 &texture_size);
// compiles the two FSR programs (upscaling then sharpening), returns false
// (and leaves FSR unusable) if anything went wrong
bool init_fsr(const fs::path &static_assets);
// (re)creates the intermediate upscaled target when the output size changes
void resize_fsr_target(GLsizei width, GLsizei height);
// upscales the source into the intermediate target, then sharpens it onto the screen
void render_fsr(const SceFVector2 &viewport_pos, const SceFVector2 &viewport_size, const float *uvs, const SceFVector2 &texture_size, GLuint default_fbo);
void setup_vertex_attributes(GLuint program);
ScreenFilter m_filter = ScreenFilter::BILINEAR;
GLuint m_vao{ 0 };
GLuint m_vbo{ 0 };
SharedGLObject m_render_shader_nofilter;
@@ -77,6 +98,30 @@ private:
GLuint current_sampler() const;
float last_uvs[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
// SMAA: two offscreen passes at the source resolution followed by a screen pass
SharedGLObject m_smaa_shader_edge;
SharedGLObject m_smaa_shader_blend;
SharedGLObject m_smaa_shader_neighborhood;
// full source quad (uv 0..1), used by the two offscreen passes
GLuint m_smaa_vao{ 0 };
GLuint m_smaa_vbo{ 0 };
GLuint m_smaa_area_texture{ 0 };
GLuint m_smaa_search_texture{ 0 };
GLuint m_smaa_edges_texture{ 0 };
GLuint m_smaa_blend_texture{ 0 };
GLuint m_smaa_edges_fbo{ 0 };
GLuint m_smaa_blend_fbo{ 0 };
GLsizei m_smaa_width{ 0 };
GLsizei m_smaa_height{ 0 };
// FSR: EASU upscales into an intermediate target of the output size, RCAS sharpens it onto the screen
SharedGLObject m_fsr_shader_easu;
SharedGLObject m_fsr_shader_rcas;
GLuint m_fsr_texture{ 0 };
GLuint m_fsr_fbo{ 0 };
GLsizei m_fsr_width{ 0 };
GLsizei m_fsr_height{ 0 };
};
} // namespace renderer::gl
+2 -1
View File
@@ -82,7 +82,8 @@ enum struct Filter : int {
BILINEAR = 1 << 1,
BICUBIC = 1 << 2,
FXAA = 1 << 3,
FSR = 1 << 4
SMAA = 1 << 4,
FSR = 1 << 5,
};
struct State {
@@ -132,6 +132,79 @@ public:
}
};
class SMAAScreenFilter : public ScreenFilter {
private:
// offscreen render targets, one (edges, blend) pair per swapchain image,
// sized to the source texture resolution (lazily (re)created)
std::vector<vkutil::Image> edges_images;
std::vector<vkutil::Image> blend_images;
std::vector<vk::Framebuffer> edges_framebuffers;
std::vector<vk::Framebuffer> blend_framebuffers;
uint32_t cached_src_width = 0;
uint32_t cached_src_height = 0;
// precomputed SMAA lookup tables (shared, read-only)
vkutil::Image area_tex;
vkutil::Image search_tex;
// render pass used by the edge and blend passes (one RGBA8 color attachment)
vk::RenderPass offscreen_render_pass;
// one SPIR-V module per stage, all compiled from SMAA.hlsl
vk::ShaderModule edge_vertex_shader;
vk::ShaderModule edge_fragment_shader;
vk::ShaderModule blend_vertex_shader;
vk::ShaderModule blend_fragment_shader;
vk::ShaderModule neighborhood_vertex_shader;
vk::ShaderModule neighborhood_fragment_shader;
vk::DescriptorSetLayout edge_set_layout;
vk::DescriptorSetLayout blend_set_layout;
vk::DescriptorSetLayout neighborhood_set_layout;
vk::DescriptorPool descriptor_pool;
std::vector<vk::DescriptorSet> edge_sets; // per swapchain image
std::vector<vk::DescriptorSet> blend_sets;
std::vector<vk::DescriptorSet> neighborhood_sets;
vk::PipelineLayout edge_pipeline_layout;
vk::PipelineLayout blend_pipeline_layout;
vk::PipelineLayout neighborhood_pipeline_layout;
vk::Pipeline edge_pipeline;
vk::Pipeline blend_pipeline;
vk::Pipeline neighborhood_pipeline;
vk::Sampler linear_sampler;
vk::Sampler point_sampler;
// host-visible quad buffer (swapchain_size * 2 quads)
vkutil::Buffer vao;
void create_samplers();
void create_render_pass();
void load_shaders();
void create_lut_textures();
void create_descriptors();
void create_pipelines();
vk::Pipeline build_pipeline(vk::ShaderModule vertex_shader, vk::ShaderModule fragment_shader,
vk::PipelineLayout layout, vk::RenderPass render_pass);
void ensure_targets(uint32_t width, uint32_t height);
void destroy_targets();
void bind_fullscreen_quad(vk::CommandBuffer cmd, bool sub_region, const Viewport &viewport);
public:
SMAAScreenFilter(ScreenRenderer &screen_renderer)
: ScreenFilter(screen_renderer) {}
~SMAAScreenFilter();
void init() override;
void render(bool is_pre_renderpass, vk::ImageView src_img, vk::ImageLayout src_layout, const Viewport &viewport) override;
std::string_view get_name() override {
return "SMAA";
}
// pass 3 draws into the default (clearing) render pass, like the single-pass
// filters, so we do NOT need the post-processing render pass.
// -> leave need_post_processing_render_pass() at its default (false).
};
class FSRScreenFilter : public ScreenFilter {
private:
// dst of the easu shader, src of the rcas shader
+9 -5
View File
@@ -799,18 +799,22 @@ std::vector<uint32_t> GLState::dump_frame(DisplayState &display, uint32_t &width
int GLState::get_supported_filters() {
return static_cast<int>(Filter::NEAREST) | static_cast<int>(Filter::BILINEAR)
| static_cast<int>(Filter::BICUBIC) | static_cast<int>(Filter::FXAA);
| static_cast<int>(Filter::BICUBIC) | static_cast<int>(Filter::FXAA) | static_cast<int>(Filter::SMAA) | static_cast<int>(Filter::FSR);
}
void GLState::set_screen_filter(const std::string_view &filter) {
if (filter == "Nearest")
screen_renderer.filter = ScreenRenderer::Filter::Nearest;
screen_renderer.set_filter(ScreenFilter::NEAREST);
else if (filter == "FXAA")
screen_renderer.filter = ScreenRenderer::Filter::FXAA;
screen_renderer.set_filter(ScreenFilter::FXAA);
else if (filter == "SMAA")
screen_renderer.set_filter(ScreenFilter::SMAA);
else if (filter == "FSR")
screen_renderer.set_filter(ScreenFilter::FSR);
else if (filter == "Bicubic")
screen_renderer.filter = ScreenRenderer::Filter::Bicubic;
screen_renderer.set_filter(ScreenFilter::BICUBIC);
else
screen_renderer.filter = ScreenRenderer::Filter::Bilinear;
screen_renderer.set_filter(ScreenFilter::BILINEAR);
}
int GLState::get_max_anisotropic_filtering() {
+402 -60
View File
@@ -16,21 +16,55 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <glutil/shader.h>
#include <renderer/AreaTex.h>
#include <renderer/SearchTex.h>
#include <renderer/gl/screen_render.h>
#include <util/log.h>
#include <string>
#include <vector>
namespace renderer::gl {
const SharedGLObject &ScreenRenderer::current_shader() const {
switch (filter) {
case Filter::FXAA: return m_render_shader_fxaa;
case Filter::Bicubic: return m_render_shader_bicubic;
switch (m_filter) {
case ScreenFilter::FXAA: return m_render_shader_fxaa;
case ScreenFilter::SMAA: return m_smaa_shader_neighborhood;
case ScreenFilter::BICUBIC: return m_render_shader_bicubic;
case ScreenFilter::FSR: return m_fsr_shader_rcas;
default: return m_render_shader_nofilter; // Bilinear / Nearest
}
}
GLuint ScreenRenderer::current_sampler() const {
return (filter == Filter::Nearest) ? m_sampler_nearest : m_sampler_linear;
return (m_filter == ScreenFilter::NEAREST) ? m_sampler_nearest : m_sampler_linear;
}
void ScreenRenderer::setup_vertex_attributes(GLuint program) {
const GLint pos_attrib = glGetAttribLocation(program, "position_vertex");
const GLint uv_attrib = glGetAttribLocation(program, "uv_vertex");
// 1st attribute: positions
glVertexAttribPointer(
pos_attrib, // attribute index
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(0) // array buffer offset
);
glEnableVertexAttribArray(pos_attrib);
// 2nd attribute: uvs
glVertexAttribPointer(
uv_attrib, // attribute index
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(3 * sizeof(GLfloat)) // array buffer offset
);
glEnableVertexAttribArray(uv_attrib);
}
bool ScreenRenderer::init(const fs::path &static_assets) {
@@ -63,6 +97,11 @@ bool ScreenRenderer::init(const fs::path &static_assets) {
glSamplerParameteri(m_sampler_nearest, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glSamplerParameteri(m_sampler_nearest, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// SMAA is optional, the filter simply stays unavailable if it could not be set up
init_smaa(static_assets);
// so is FSR
init_fsr(static_assets);
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
@@ -77,32 +116,7 @@ bool ScreenRenderer::init(const fs::path &static_assets) {
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer_data), vertex_buffer_data, GL_DYNAMIC_DRAW);
const auto &shader = current_shader();
GLint posAttrib = glGetAttribLocation(*shader, "position_vertex");
GLint uvAttrib = glGetAttribLocation(*shader, "uv_vertex");
// 1st attribute: positions
glVertexAttribPointer(
posAttrib, // attribute index
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(0) // array buffer offset
);
glEnableVertexAttribArray(posAttrib);
// 2nd attribute: uvs
glVertexAttribPointer(
uvAttrib, // attribute index
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(3 * sizeof(GLfloat)) // array buffer offset
);
glEnableVertexAttribArray(uvAttrib);
setup_vertex_attributes(*m_render_shader_nofilter);
glClearColor(32.0f / 255.0f, 178.0f / 255.0f, 170.0f / 255.0f, 1.0f);
glClearDepthf(1.0f);
@@ -110,6 +124,294 @@ bool ScreenRenderer::init(const fs::path &static_assets) {
return true;
}
void ScreenRenderer::set_filter(ScreenFilter new_filter) {
if (new_filter == ScreenFilter::SMAA && !m_smaa_shader_neighborhood) {
LOG_WARN("SMAA is not available, falling back to bilinear");
new_filter = ScreenFilter::BILINEAR;
}
if (new_filter == ScreenFilter::FSR && !m_fsr_shader_rcas) {
LOG_WARN("FSR is not available, falling back to bilinear");
new_filter = ScreenFilter::BILINEAR;
}
m_filter = new_filter;
}
bool ScreenRenderer::init_smaa(const fs::path &static_assets) {
const auto builtin_shaders_path = static_assets / "shaders-builtin/opengl";
// the SMAA library is a single header shared with the vulkan backend, it is pasted
// in front of each shader (along with its configuration) instead of being #included
std::vector<char> smaa_library;
if (!fs_utils::read_data(static_assets / "shaders-builtin/SMAA.hlsl", smaa_library)) {
LOG_ERROR("Couldn't open SMAA.hlsl, SMAA will not be available");
return false;
}
// SMAA_GLSL_3 only needs GLSL 1.30 features, so the same code works on GLES 3.0
const std::string config = "#define SMAA_GLSL_3 1\n"
"#define SMAA_PRESET_HIGH 1\n"
"uniform vec4 rt_metrics;\n"
"#define SMAA_RT_METRICS rt_metrics\n";
// the pixel shaders use discard, which is not allowed in a vertex shader
const std::string vertex_prelude = config + "#define SMAA_INCLUDE_PS 0\n" + std::string(smaa_library.data(), smaa_library.size());
const std::string fragment_prelude = config + "#define SMAA_INCLUDE_VS 0\n" + std::string(smaa_library.data(), smaa_library.size());
m_smaa_shader_edge = ::gl::load_shaders(builtin_shaders_path / "smaa_edge.vert",
builtin_shaders_path / "smaa_edge.frag", vertex_prelude, fragment_prelude);
m_smaa_shader_blend = ::gl::load_shaders(builtin_shaders_path / "smaa_blend.vert",
builtin_shaders_path / "smaa_blend.frag", vertex_prelude, fragment_prelude);
m_smaa_shader_neighborhood = ::gl::load_shaders(builtin_shaders_path / "smaa_neighborhood.vert",
builtin_shaders_path / "smaa_neighborhood.frag", vertex_prelude, fragment_prelude);
if (!m_smaa_shader_edge || !m_smaa_shader_blend || !m_smaa_shader_neighborhood) {
LOG_ERROR("Couldn't compile the SMAA shaders, SMAA will not be available");
m_smaa_shader_edge.reset();
m_smaa_shader_blend.reset();
m_smaa_shader_neighborhood.reset();
return false;
}
// bind each sampler to the texture unit it is given in render_smaa_offscreen / render
glUseProgram(*m_smaa_shader_blend);
glUniform1i(glGetUniformLocation(*m_smaa_shader_blend, "edges_tex"), 0);
glUniform1i(glGetUniformLocation(*m_smaa_shader_blend, "area_tex"), 1);
glUniform1i(glGetUniformLocation(*m_smaa_shader_blend, "search_tex"), 2);
glUseProgram(*m_smaa_shader_neighborhood);
glUniform1i(glGetUniformLocation(*m_smaa_shader_neighborhood, "fb"), 0);
glUniform1i(glGetUniformLocation(*m_smaa_shader_neighborhood, "blend_tex"), 1);
glUseProgram(0);
// upload the two precomputed lookup tables
// their rows are not always a multiple of 4 bytes (the search texture is 66 wide)
GLint last_unpack_alignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &last_unpack_alignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const auto upload_lut = [](GLuint &texture, GLenum internal_format, GLenum format,
GLsizei width, GLsizei height, const void *data, GLint filter) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
};
upload_lut(m_smaa_area_texture, GL_RG8, GL_RG, AREATEX_WIDTH, AREATEX_HEIGHT, areaTexBytes, GL_LINEAR);
upload_lut(m_smaa_search_texture, GL_R8, GL_RED, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, searchTexBytes, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, last_unpack_alignment);
glBindTexture(GL_TEXTURE_2D, 0);
// the offscreen passes always cover the whole source texture, so unlike the screen
// quad their uvs never change
static const screen_vertices_t offscreen_vertices = {
{ { -1.f, -1.f, 0.0f }, { 0.f, 0.f } },
{ { 1.f, -1.f, 0.0f }, { 1.f, 0.f } },
{ { 1.f, 1.f, 0.0f }, { 1.f, 1.f } },
{ { -1.f, 1.f, 0.0f }, { 0.f, 1.f } }
};
glGenVertexArrays(1, &m_smaa_vao);
glBindVertexArray(m_smaa_vao);
glGenBuffers(1, &m_smaa_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_smaa_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(offscreen_vertices), offscreen_vertices, GL_STATIC_DRAW);
glBindVertexArray(0);
glGenFramebuffers(1, &m_smaa_edges_fbo);
glGenFramebuffers(1, &m_smaa_blend_fbo);
glGenTextures(1, &m_smaa_edges_texture);
glGenTextures(1, &m_smaa_blend_texture);
return true;
}
void ScreenRenderer::resize_smaa_targets(GLsizei width, GLsizei height) {
if (width == m_smaa_width && height == m_smaa_height)
return;
const auto attach = [&](GLuint fbo, GLuint texture) {
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
LOG_ERROR("Incomplete SMAA framebuffer ({}x{})", width, height);
};
attach(m_smaa_edges_fbo, m_smaa_edges_texture);
attach(m_smaa_blend_fbo, m_smaa_blend_texture);
glBindTexture(GL_TEXTURE_2D, 0);
m_smaa_width = width;
m_smaa_height = height;
}
void ScreenRenderer::render_smaa_offscreen(GLuint texture, const SceFVector2 &texture_size) {
const auto width = static_cast<GLsizei>(texture_size.x);
const auto height = static_cast<GLsizei>(texture_size.y);
resize_smaa_targets(width, height);
glViewport(0, 0, width, height);
glBindVertexArray(m_smaa_vao);
glBindBuffer(GL_ARRAY_BUFFER, m_smaa_vbo);
const auto run_pass = [&](GLuint fbo, GLuint program) {
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);
glUniform4f(glGetUniformLocation(program, "rt_metrics"),
1.0f / texture_size.x, 1.0f / texture_size.y, texture_size.x, texture_size.y);
setup_vertex_attributes(program);
glDrawArrays(GL_TRIANGLE_FAN, 0, screen_vertex_count);
};
// the lookup tables carry their own filtering (linear for the area one, point for
// the search one), a leftover sampler object would override it
glBindSampler(0, 0);
glBindSampler(1, 0);
glBindSampler(2, 0);
// pass 1: edge detection, reads the source color
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
run_pass(m_smaa_edges_fbo, *m_smaa_shader_edge);
// pass 2: blending weight calculation, reads the edges and both lookup tables
glBindTexture(GL_TEXTURE_2D, m_smaa_edges_texture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_smaa_area_texture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_smaa_search_texture);
run_pass(m_smaa_blend_fbo, *m_smaa_shader_blend);
// leave the lookup tables behind, pass 3 needs unit 1 for the blend texture
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
}
bool ScreenRenderer::init_fsr(const fs::path &static_assets) {
const auto builtin_shaders_path = static_assets / "shaders-builtin";
// the FidelityFX library is made of two headers shared with the vulkan backend,
// they are pasted in front of each shader (along with its configuration)
std::vector<char> ffx_a;
std::vector<char> ffx_fsr1;
if (!fs_utils::read_data(builtin_shaders_path / "ffx_a.h", ffx_a) || !fs_utils::read_data(builtin_shaders_path / "ffx_fsr1.h", ffx_fsr1)) {
LOG_ERROR("Couldn't open the FidelityFX headers, FSR will not be available");
return false;
}
// packHalf2x16 needs GLSL 4.20, and the library only uses it for a constant the 32-bit path never reads
std::string config = "#define A_GPU 1\n"
"#define A_GLSL 1\n"
"#define packHalf2x16(v) 0u\n";
#ifdef __ANDROID__
// GLSL ES 3.0 has neither textureGather nor the bitfield functions (the library only
// uses the latter in helpers we do not call), and defaults to mediump integers
config += "precision highp int;\n"
"precision highp sampler2D;\n"
"#define FSR_EMULATE_GATHER 1\n"
"uint bitfieldExtract(uint value, int offset, int bits) { return (value >> uint(offset)) & ((1u << uint(bits)) - 1u); }\n"
"uint bitfieldInsert(uint base, uint insert, int offset, int bits) {\n"
" uint mask = ((1u << uint(bits)) - 1u) << uint(offset);\n"
" return (base & ~mask) | ((insert << uint(offset)) & mask);\n"
"}\n";
#endif
const std::string library = std::string(ffx_a.data(), ffx_a.size()) + std::string(ffx_fsr1.data(), ffx_fsr1.size());
const std::string easu_prelude = config + "#define FSR_EASU_F 1\n" + library;
const std::string rcas_prelude = config + "#define FSR_RCAS_F 1\n" + library;
const auto opengl_shaders_path = builtin_shaders_path / "opengl";
m_fsr_shader_easu = ::gl::load_shaders(opengl_shaders_path / "render_main.vert",
opengl_shaders_path / "fsr_easu.frag", "", easu_prelude);
m_fsr_shader_rcas = ::gl::load_shaders(opengl_shaders_path / "render_main.vert",
opengl_shaders_path / "fsr_rcas.frag", "", rcas_prelude);
if (!m_fsr_shader_easu || !m_fsr_shader_rcas) {
LOG_ERROR("Couldn't compile the FSR shaders, FSR will not be available");
m_fsr_shader_easu.reset();
m_fsr_shader_rcas.reset();
return false;
}
return true;
}
void ScreenRenderer::resize_fsr_target(GLsizei width, GLsizei height) {
if (m_fsr_texture && width == m_fsr_width && height == m_fsr_height)
return;
if (!m_fsr_texture) {
glGenFramebuffers(1, &m_fsr_fbo);
glGenTextures(1, &m_fsr_texture);
}
glBindTexture(GL_TEXTURE_2D, m_fsr_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_fsr_fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fsr_texture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
LOG_ERROR("Incomplete FSR framebuffer ({}x{})", width, height);
m_fsr_width = width;
m_fsr_height = height;
}
void ScreenRenderer::render_fsr(const SceFVector2 &viewport_pos, const SceFVector2 &viewport_size, const float *uvs, const SceFVector2 &texture_size, GLuint default_fbo) {
const auto width = static_cast<GLsizei>(viewport_size.x);
const auto height = static_cast<GLsizei>(viewport_size.y);
if (width <= 0 || height <= 0)
return;
resize_fsr_target(width, height);
// pass 1: upscale the displayed part of the source to the size it has on screen
glBindFramebuffer(GL_FRAMEBUFFER, m_fsr_fbo);
glViewport(0, 0, width, height);
glUseProgram(*m_fsr_shader_easu);
setup_vertex_attributes(*m_fsr_shader_easu);
glUniform4f(glGetUniformLocation(*m_fsr_shader_easu, "input_region"),
uvs[0] * texture_size.x, uvs[1] * texture_size.y,
(uvs[2] - uvs[0]) * texture_size.x, (uvs[3] - uvs[1]) * texture_size.y);
glUniform2f(glGetUniformLocation(*m_fsr_shader_easu, "texture_size"), texture_size.x, texture_size.y);
glUniform2f(glGetUniformLocation(*m_fsr_shader_easu, "output_size"), static_cast<float>(width), static_cast<float>(height));
glDrawArrays(GL_TRIANGLE_FAN, 0, screen_vertex_count);
// pass 2: sharpen it onto the screen, one to one
const auto origin_x = static_cast<GLint>(viewport_pos.x);
const auto origin_y = static_cast<GLint>(viewport_pos.y);
glBindFramebuffer(GL_FRAMEBUFFER, default_fbo);
glViewport(origin_x, origin_y, width, height);
glBindTexture(GL_TEXTURE_2D, m_fsr_texture);
glBindSampler(0, m_sampler_nearest);
glUseProgram(*m_fsr_shader_rcas);
setup_vertex_attributes(*m_fsr_shader_rcas);
glUniform2f(glGetUniformLocation(*m_fsr_shader_rcas, "output_origin"), static_cast<float>(origin_x), static_cast<float>(origin_y));
// in stops, same default as the vulkan backend
glUniform1f(glGetUniformLocation(*m_fsr_shader_rcas, "sharpness"), 0.2f);
glDrawArrays(GL_TRIANGLE_FAN, 0, screen_vertex_count);
}
void ScreenRenderer::render(const SceFVector2 &viewport_pos, const SceFVector2 &viewport_size, const float *uvs, const GLuint texture, const SceFVector2 texture_size, GLuint default_fbo) {
// Code for backup and restore is taken from ImGui project ImGui_ImplSdlGL3_RenderDrawData
// Backup GL state
@@ -143,12 +445,21 @@ void ScreenRenderer::render(const SceFVector2 &viewport_pos, const SceFVector2 &
GLboolean last_color_mask[4];
glGetBooleanv(GL_COLOR_WRITEMASK, last_color_mask);
glBindFramebuffer(GL_FRAMEBUFFER, default_fbo);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
#ifndef __ANDROID__
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
// the first two SMAA passes render the whole source into offscreen targets, the last
// one is the screen pass below
if (m_filter == ScreenFilter::SMAA)
render_smaa_offscreen(texture, texture_size);
glBindFramebuffer(GL_FRAMEBUFFER, default_fbo);
glViewport(static_cast<GLint>(viewport_pos.x), static_cast<GLint>(viewport_pos.y), static_cast<GLsizei>(viewport_size.x),
static_cast<GLsizei>(viewport_size.y));
@@ -162,9 +473,6 @@ void ScreenRenderer::render(const SceFVector2 &viewport_pos, const SceFVector2 &
const auto &shader = current_shader();
const GLint posAttrib = glGetAttribLocation(*shader, "position_vertex");
const GLint uvAttrib = glGetAttribLocation(*shader, "uv_vertex");
glUseProgram(*shader);
glBindVertexArray(m_vao);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
@@ -206,35 +514,12 @@ void ScreenRenderer::render(const SceFVector2 &viewport_pos, const SceFVector2 &
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer_data), vertex_buffer_data, GL_DYNAMIC_DRAW);
}
// 1st attribute: positions
glVertexAttribPointer(
posAttrib, // attribute index
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(0) // array buffer offset
);
glEnableVertexAttribArray(posAttrib);
// 2nd attribute: uvs
glVertexAttribPointer(
uvAttrib, // attribute index
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
screen_vertex_size, // stride
reinterpret_cast<void *>(3 * sizeof(GLfloat)) // array buffer offset
);
glEnableVertexAttribArray(uvAttrib);
setup_vertex_attributes(*shader);
glBindTexture(GL_TEXTURE_2D, texture);
glBindSampler(0, current_sampler());
#ifndef __ANDROID__
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
if (filter == Filter::FXAA) {
if (m_filter == ScreenFilter::FXAA) {
// FXAA must run at the input (render) resolution, 1:1 with the source texture,
// otherwise it operates on an already upscaled (blurred) image.
// Pass 1: run FXAA into an intermediate FBO sized to the render resolution.
@@ -279,11 +564,29 @@ void ScreenRenderer::render(const SceFVector2 &viewport_pos, const SceFVector2 &
static_cast<GLint>(viewport_pos.x + viewport_size.x),
static_cast<GLint>(viewport_pos.y + viewport_size.y),
GL_COLOR_BUFFER_BIT, GL_NEAREST);
} else if (m_filter == ScreenFilter::FSR) {
render_fsr(viewport_pos, viewport_size, uvs, texture_size, default_fbo);
} else {
// Bilinear / Nearest / Bicubic draw directly to the screen.
if (m_filter == ScreenFilter::SMAA) {
const GLint rt_metrics_location = glGetUniformLocation(*shader, "rt_metrics");
glUniform4f(rt_metrics_location, 1 / texture_size.x, 1 / texture_size.y, texture_size.x, texture_size.y);
// the blending weights computed by the offscreen passes cover the whole source,
// so they are addressed with the same uvs as the color texture
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_smaa_blend_texture);
glActiveTexture(GL_TEXTURE0);
}
// Bilinear / Nearest / Bicubic / SMAA draw directly to the screen.
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
if (m_filter == ScreenFilter::SMAA) {
// only unit 0 is saved and restored below
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
}
// Restore modified GL state
glUseProgram(last_program);
glBindFramebuffer(GL_FRAMEBUFFER, last_framebuffer);
@@ -345,6 +648,45 @@ void ScreenRenderer::destroy() {
glDeleteTextures(1, &m_screen_texture);
m_screen_texture = 0;
glDeleteFramebuffers(1, &m_smaa_edges_fbo);
glDeleteFramebuffers(1, &m_smaa_blend_fbo);
m_smaa_edges_fbo = 0;
m_smaa_blend_fbo = 0;
glDeleteTextures(1, &m_smaa_edges_texture);
glDeleteTextures(1, &m_smaa_blend_texture);
glDeleteTextures(1, &m_smaa_area_texture);
glDeleteTextures(1, &m_smaa_search_texture);
m_smaa_edges_texture = 0;
m_smaa_blend_texture = 0;
m_smaa_area_texture = 0;
m_smaa_search_texture = 0;
glDeleteBuffers(1, &m_smaa_vbo);
m_smaa_vbo = 0;
glDeleteVertexArrays(1, &m_smaa_vao);
m_smaa_vao = 0;
m_smaa_width = 0;
m_smaa_height = 0;
m_smaa_shader_edge.reset();
m_smaa_shader_blend.reset();
m_smaa_shader_neighborhood.reset();
m_fsr_shader_easu.reset();
m_fsr_shader_rcas.reset();
if (m_fsr_fbo) {
glDeleteFramebuffers(1, &m_fsr_fbo);
m_fsr_fbo = 0;
}
if (m_fsr_texture) {
glDeleteTextures(1, &m_fsr_texture);
m_fsr_texture = 0;
}
m_fsr_width = 0;
m_fsr_height = 0;
}
ScreenRenderer::~ScreenRenderer() {
+1 -1
View File
@@ -1324,7 +1324,7 @@ uint32_t VKState::get_features_mask() {
}
int VKState::get_supported_filters() {
int filters = static_cast<int>(Filter::NEAREST) | static_cast<int>(Filter::BILINEAR) | static_cast<int>(Filter::BICUBIC) | static_cast<int>(Filter::FXAA);
int filters = static_cast<int>(Filter::NEAREST) | static_cast<int>(Filter::BILINEAR) | static_cast<int>(Filter::BICUBIC) | static_cast<int>(Filter::FXAA) | static_cast<int>(Filter::SMAA);
if (support_fsr)
filters |= static_cast<int>(Filter::FSR);
return filters;
@@ -20,6 +20,9 @@
#include "renderer/vulkan/state.h"
#include "renderer/AreaTex.h"
#include "renderer/SearchTex.h"
namespace renderer::vulkan {
ScreenFilter::ScreenFilter(ScreenRenderer &screen_renderer)
@@ -367,6 +370,583 @@ vk::Sampler FXAAScreenFilter::create_sampler() {
return screen.state.device.createSampler(sampler_info);
}
// ---------------------------------------------------------------------------
// SMAA 1x (Subpixel Morphological Anti-Aliasing)
//
// Three graphics passes:
// 1. edge detection -> edges image (offscreen, source resolution)
// 2. blending weight calc -> blend image (offscreen, reads edges+Area+Search)
// 3. neighborhood blending -> swapchain (reads source color + blend image)
//
// Passes 1 & 2 run in the pre-renderpass phase into our own render pass.
// Pass 3 runs inside the main swapchain render pass like the single-pass
// filters, so need_post_processing_render_pass() stays false (default) and the
// default render pass clears the swapchain for us.
//
// All passes run at the source texture resolution and address the whole source
// in [0,1]; only pass 3 narrows the UVs to the content sub-region, so colorTex
// and blendTex line up under a single texcoord.
//
// Shader binding contract (matches the smaa_*.vert/frag wrappers around SMAA.hlsl):
// push_constant : vec4 rt_metrics = (1/w, 1/h, w, h), stages vertex+fragment
// vertex inputs : loc0 = vec3 position (xy NDC), loc1 = vec2 uv
// edge set : binding0 = colorTex (linear/clamp)
// blend set : binding0 = edgesTex (linear), binding1 = areaTex (linear),
// binding2 = searchTex (point)
// neighborhood set: binding0 = colorTex (linear), binding1 = blendTex (linear)
// ---------------------------------------------------------------------------
struct SMAAConstant {
float rt_metrics[4]; // 1/w, 1/h, w, h
};
SMAAScreenFilter::~SMAAScreenFilter() {
vk::Device device = screen.state.device;
device.waitIdle();
destroy_targets();
area_tex.destroy();
search_tex.destroy();
device.destroy(edge_pipeline);
device.destroy(blend_pipeline);
device.destroy(neighborhood_pipeline);
device.destroy(edge_pipeline_layout);
device.destroy(blend_pipeline_layout);
device.destroy(neighborhood_pipeline_layout);
device.destroy(descriptor_pool);
device.destroy(edge_set_layout);
device.destroy(blend_set_layout);
device.destroy(neighborhood_set_layout);
device.destroy(edge_vertex_shader);
device.destroy(edge_fragment_shader);
device.destroy(blend_vertex_shader);
device.destroy(blend_fragment_shader);
device.destroy(neighborhood_vertex_shader);
device.destroy(neighborhood_fragment_shader);
device.destroy(offscreen_render_pass);
device.destroy(linear_sampler);
device.destroy(point_sampler);
}
void SMAAScreenFilter::create_samplers() {
vk::Device device = screen.state.device;
vk::SamplerCreateInfo linear_info{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
.addressModeU = vk::SamplerAddressMode::eClampToEdge,
.addressModeV = vk::SamplerAddressMode::eClampToEdge,
.addressModeW = vk::SamplerAddressMode::eClampToEdge,
};
linear_sampler = device.createSampler(linear_info);
vk::SamplerCreateInfo point_info{
.magFilter = vk::Filter::eNearest,
.minFilter = vk::Filter::eNearest,
.addressModeU = vk::SamplerAddressMode::eClampToEdge,
.addressModeV = vk::SamplerAddressMode::eClampToEdge,
.addressModeW = vk::SamplerAddressMode::eClampToEdge,
};
point_sampler = device.createSampler(point_info);
}
void SMAAScreenFilter::create_render_pass() {
// single RGBA8 color attachment, used by both the edge and the blend pass
vk::AttachmentDescription color_attachment{
.format = vk::Format::eR8G8B8A8Unorm,
.samples = vk::SampleCountFlagBits::e1,
.loadOp = vk::AttachmentLoadOp::eClear,
.storeOp = vk::AttachmentStoreOp::eStore,
.stencilLoadOp = vk::AttachmentLoadOp::eDontCare,
.stencilStoreOp = vk::AttachmentStoreOp::eDontCare,
.initialLayout = vk::ImageLayout::eUndefined,
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
};
subpass.setColorAttachments(color_ref);
// make the written attachment visible to later fragment-shader reads
// (blend reads edges, neighborhood reads blend)
vk::SubpassDependency dependency{
.srcSubpass = 0,
.dstSubpass = VK_SUBPASS_EXTERNAL,
.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput,
.dstStageMask = vk::PipelineStageFlagBits::eFragmentShader,
.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
};
vk::RenderPassCreateInfo pass_info{};
pass_info.setAttachments(color_attachment);
pass_info.setSubpasses(subpass);
pass_info.setDependencies(dependency);
offscreen_render_pass = screen.state.device.createRenderPass(pass_info);
}
void SMAAScreenFilter::load_shaders() {
// one module per stage, each compiled from SMAA.hlsl with a thin GLSL wrapper
const fs::path p = screen.state.static_assets / "shaders-builtin/vulkan";
// load_shader returns a null module when the file is missing, which would only
// blow up much later inside createGraphicsPipeline, so report it here instead
auto load = [&](const char *name) {
vk::ShaderModule module = vkutil::load_shader(screen.state.device, p / name);
if (!module)
LOG_CRITICAL("Could not load SMAA shader {}", name);
return module;
};
edge_vertex_shader = load("smaa_edge.vert.spv");
edge_fragment_shader = load("smaa_edge.frag.spv");
blend_vertex_shader = load("smaa_blend.vert.spv");
blend_fragment_shader = load("smaa_blend.frag.spv");
neighborhood_vertex_shader = load("smaa_neighborhood.vert.spv");
neighborhood_fragment_shader = load("smaa_neighborhood.frag.spv");
}
void SMAAScreenFilter::create_lut_textures() {
vk::Device device = screen.state.device;
auto upload = [&](vkutil::Image &img, vk::Format format, uint32_t w, uint32_t h,
const void *data, vk::DeviceSize size) {
img.format = format;
img.width = w;
img.height = h;
img.init_image(vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst);
vkutil::Buffer staging(size);
staging.init_buffer(vk::BufferUsageFlagBits::eTransferSrc, vkutil::vma_mapped_alloc);
memcpy(staging.mapped_data, data, size);
vk::CommandBuffer cmd = vkutil::create_single_time_command(device, screen.state.general_command_pool);
img.transition_to_discard(cmd, vkutil::ImageLayout::TransferDst);
vk::BufferImageCopy region{
.bufferOffset = 0,
.bufferRowLength = w,
.bufferImageHeight = h,
.imageSubresource = vkutil::color_subresource_layer,
.imageOffset = { 0, 0, 0 },
.imageExtent = { w, h, 1 },
};
cmd.copyBufferToImage(staging.buffer, img.image, vk::ImageLayout::eTransferDstOptimal, region);
img.transition_to(cmd, vkutil::ImageLayout::SampledImage);
vkutil::end_single_time_command(device, screen.state.general_queue, screen.state.general_command_pool, cmd);
staging.destroy();
};
upload(area_tex, vk::Format::eR8G8Unorm, AREATEX_WIDTH, AREATEX_HEIGHT,
areaTexBytes, static_cast<vk::DeviceSize>(AREATEX_SIZE));
upload(search_tex, vk::Format::eR8Unorm, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT,
searchTexBytes, static_cast<vk::DeviceSize>(SEARCHTEX_SIZE));
}
void SMAAScreenFilter::create_descriptors() {
vk::Device device = screen.state.device;
const uint32_t n = screen.swapchain_size;
auto make_layout = [&](uint32_t count) {
std::vector<vk::DescriptorSetLayoutBinding> bindings(count);
for (uint32_t i = 0; i < count; i++) {
bindings[i] = vk::DescriptorSetLayoutBinding{
.binding = i,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
};
}
vk::DescriptorSetLayoutCreateInfo info{};
info.setBindings(bindings);
return device.createDescriptorSetLayout(info);
};
edge_set_layout = make_layout(1);
blend_set_layout = make_layout(3);
neighborhood_set_layout = make_layout(2);
// (1 + 3 + 2) combined image samplers per swapchain image
vk::DescriptorPoolSize pool_size{
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = n * 6,
};
vk::DescriptorPoolCreateInfo pool_info{ .maxSets = n * 3 };
pool_info.setPoolSizes(pool_size);
descriptor_pool = device.createDescriptorPool(pool_info);
auto alloc_sets = [&](vk::DescriptorSetLayout layout) {
std::vector<vk::DescriptorSetLayout> layouts(n, layout);
vk::DescriptorSetAllocateInfo info{ .descriptorPool = descriptor_pool };
info.setSetLayouts(layouts);
return device.allocateDescriptorSets(info);
};
edge_sets = alloc_sets(edge_set_layout);
blend_sets = alloc_sets(blend_set_layout);
neighborhood_sets = alloc_sets(neighborhood_set_layout);
}
vk::Pipeline SMAAScreenFilter::build_pipeline(vk::ShaderModule vertex_shader, vk::ShaderModule fragment_shader,
vk::PipelineLayout layout, vk::RenderPass render_pass) {
std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
vk::PipelineShaderStageCreateInfo{
.stage = vk::ShaderStageFlagBits::eVertex, .module = vertex_shader, .pName = "main" },
vk::PipelineShaderStageCreateInfo{
.stage = vk::ShaderStageFlagBits::eFragment, .module = fragment_shader, .pName = "main" },
};
// reuse the file-local screen_vertex layout (pos vec3 @0, uv vec2 @12)
vk::VertexInputBindingDescription binding_descr{
.binding = 0,
.stride = screen_vertex_size,
.inputRate = vk::VertexInputRate::eVertex,
};
std::array<vk::VertexInputAttributeDescription, 2> attr_descr = {
vk::VertexInputAttributeDescription{
.location = 0, .binding = 0, .format = vk::Format::eR32G32B32Sfloat, .offset = offsetof(screen_vertex, pos) },
vk::VertexInputAttributeDescription{
.location = 1, .binding = 0, .format = vk::Format::eR32G32Sfloat, .offset = offsetof(screen_vertex, uv) },
};
vk::PipelineVertexInputStateCreateInfo vertex_input{};
vertex_input.setVertexBindingDescriptions(binding_descr);
vertex_input.setVertexAttributeDescriptions(attr_descr);
vk::PipelineInputAssemblyStateCreateInfo input_assembly{
.topology = vk::PrimitiveTopology::eTriangleStrip,
};
vk::PipelineViewportStateCreateInfo viewport_state{ .viewportCount = 1, .scissorCount = 1 };
vk::PipelineRasterizationStateCreateInfo rasterizer{
.polygonMode = vk::PolygonMode::eFill,
.cullMode = vk::CullModeFlagBits::eNone,
.frontFace = vk::FrontFace::eClockwise,
.lineWidth = 1.0f,
};
vk::PipelineMultisampleStateCreateInfo multisampling{
.rasterizationSamples = vk::SampleCountFlagBits::e1,
};
vk::PipelineColorBlendAttachmentState blend_attachment{
.blendEnable = VK_FALSE,
.colorWriteMask = vkutil::default_color_mask,
};
vk::PipelineColorBlendStateCreateInfo color_blending{};
color_blending.setAttachments(blend_attachment);
static vk::DynamicState dynamic_states[] = {
vk::DynamicState::eViewport,
vk::DynamicState::eScissor,
};
vk::PipelineDynamicStateCreateInfo dynamic_info{};
dynamic_info.setDynamicStates(dynamic_states);
vk::GraphicsPipelineCreateInfo pipeline_info{
.pVertexInputState = &vertex_input,
.pInputAssemblyState = &input_assembly,
.pViewportState = &viewport_state,
.pRasterizationState = &rasterizer,
.pMultisampleState = &multisampling,
.pColorBlendState = &color_blending,
.pDynamicState = &dynamic_info,
.layout = layout,
.renderPass = render_pass,
.subpass = 0,
};
pipeline_info.setStages(stages);
const auto result = screen.state.device.createGraphicsPipeline(VK_NULL_HANDLE, pipeline_info);
if (result.result != vk::Result::eSuccess)
LOG_CRITICAL("Failed to create SMAA pipeline.");
return result.value;
}
void SMAAScreenFilter::create_pipelines() {
vk::Device device = screen.state.device;
auto make_pipeline_layout = [&](vk::DescriptorSetLayout set_layout) {
vk::PipelineLayoutCreateInfo info{};
info.setSetLayouts(set_layout);
vk::PushConstantRange range{
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
.offset = 0,
.size = sizeof(SMAAConstant),
};
info.setPushConstantRanges(range);
return device.createPipelineLayout(info);
};
edge_pipeline_layout = make_pipeline_layout(edge_set_layout);
blend_pipeline_layout = make_pipeline_layout(blend_set_layout);
neighborhood_pipeline_layout = make_pipeline_layout(neighborhood_set_layout);
edge_pipeline = build_pipeline(edge_vertex_shader, edge_fragment_shader,
edge_pipeline_layout, offscreen_render_pass);
blend_pipeline = build_pipeline(blend_vertex_shader, blend_fragment_shader,
blend_pipeline_layout, offscreen_render_pass);
neighborhood_pipeline = build_pipeline(neighborhood_vertex_shader, neighborhood_fragment_shader,
neighborhood_pipeline_layout, screen.default_render_pass);
}
void SMAAScreenFilter::init() {
create_samplers();
create_render_pass();
load_shaders();
create_lut_textures();
create_descriptors();
create_pipelines();
// host-visible quad buffer holding swapchain_size * 2 quads:
// [0 .. n) -> offscreen quads (uv 0..1)
// [n .. 2n) -> present quads (uv = content sub-region)
vao.size = sizeof(screen_vertices_t) * screen.swapchain_size * 2;
vao.init_buffer(vk::BufferUsageFlagBits::eVertexBuffer, vkutil::vma_mapped_alloc);
cached_src_width = 0;
cached_src_height = 0;
}
void SMAAScreenFilter::ensure_targets(uint32_t width, uint32_t height) {
if (width == cached_src_width && height == cached_src_height && !edges_images.empty())
return;
// frames in flight still use the old targets and descriptor sets,
// the source size only changes when the game switches resolution so we can afford to wait
if (!edges_images.empty())
screen.state.device.waitIdle();
destroy_targets();
const uint32_t n = screen.swapchain_size;
edges_images.resize(n);
blend_images.resize(n);
edges_framebuffers.resize(n);
blend_framebuffers.resize(n);
vk::Device device = screen.state.device;
const vk::ImageUsageFlags usage = vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled;
auto make_fb = [&](vkutil::Image &img) {
vk::FramebufferCreateInfo fb_info{
.renderPass = offscreen_render_pass,
.width = width,
.height = height,
.layers = 1,
};
fb_info.setAttachments(img.view);
return device.createFramebuffer(fb_info);
};
for (uint32_t i = 0; i < n; i++) {
edges_images[i].format = vk::Format::eR8G8B8A8Unorm;
edges_images[i].width = width;
edges_images[i].height = height;
edges_images[i].init_image(usage);
edges_framebuffers[i] = make_fb(edges_images[i]);
blend_images[i].format = vk::Format::eR8G8B8A8Unorm;
blend_images[i].width = width;
blend_images[i].height = height;
blend_images[i].init_image(usage);
blend_framebuffers[i] = make_fb(blend_images[i]);
}
// write the bindings that only depend on per-image resources:
// blend set -> edges[i], areaTex, searchTex
// neighborhood set -> blendTex = blend[i]
std::vector<vk::DescriptorImageInfo> img_infos;
std::vector<vk::WriteDescriptorSet> writes;
img_infos.reserve(n * 4);
writes.reserve(n * 4);
auto push_write = [&](vk::DescriptorSet set, uint32_t binding, vk::Sampler sampler, vk::ImageView view) {
img_infos.push_back(vk::DescriptorImageInfo{
.sampler = sampler,
.imageView = view,
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
});
vk::WriteDescriptorSet w{
.dstSet = set,
.dstBinding = binding,
.dstArrayElement = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
};
w.setImageInfo(img_infos.back());
writes.push_back(w);
};
for (uint32_t i = 0; i < n; i++) {
push_write(blend_sets[i], 0, linear_sampler, edges_images[i].view);
push_write(blend_sets[i], 1, linear_sampler, area_tex.view);
push_write(blend_sets[i], 2, point_sampler, search_tex.view);
push_write(neighborhood_sets[i], 1, linear_sampler, blend_images[i].view);
}
// safe because img_infos is reserved up-front and never reallocated, so the
// pointers stored by setImageInfo stay valid until updateDescriptorSets.
device.updateDescriptorSets(writes, {});
cached_src_width = width;
cached_src_height = height;
}
void SMAAScreenFilter::destroy_targets() {
vk::Device device = screen.state.device;
for (auto fb : edges_framebuffers)
device.destroy(fb);
for (auto fb : blend_framebuffers)
device.destroy(fb);
edges_framebuffers.clear();
blend_framebuffers.clear();
for (auto &img : edges_images)
img.destroy();
for (auto &img : blend_images)
img.destroy();
edges_images.clear();
blend_images.clear();
}
void SMAAScreenFilter::bind_fullscreen_quad(vk::CommandBuffer cmd, bool sub_region, const Viewport &viewport) {
// offscreen passes process the whole source in [0,1]; the neighborhood pass
// narrows to the content sub-region so colorTex and blendTex share one uv.
float u0 = 0.0f, v0 = 0.0f, u1 = 1.0f, v1 = 1.0f;
if (sub_region) {
u0 = viewport.offset_x / static_cast<float>(viewport.texture_width);
v0 = viewport.offset_y / static_cast<float>(viewport.texture_height);
u1 = (viewport.offset_x + viewport.width) / static_cast<float>(viewport.texture_width);
v1 = (viewport.offset_y + viewport.height) / static_cast<float>(viewport.texture_height);
}
// triangle strip; if the output is vertically flipped, swap v0/v1.
screen_vertices_t verts = {
{ { -1.0f, -1.0f, 0.0f }, { u0, v0 } },
{ { 1.0f, -1.0f, 0.0f }, { u1, v0 } },
{ { -1.0f, 1.0f, 0.0f }, { u0, v1 } },
{ { 1.0f, 1.0f, 0.0f }, { u1, v1 } },
};
const uint32_t slot = screen.swapchain_image_idx + (sub_region ? screen.swapchain_size : 0);
const vk::DeviceSize offset = slot * sizeof(screen_vertices_t);
memcpy(static_cast<uint8_t *>(vao.mapped_data) + offset, verts, sizeof(verts));
cmd.bindVertexBuffers(0, vao.buffer, offset);
}
void SMAAScreenFilter::render(bool is_pre_renderpass, vk::ImageView src_img, vk::ImageLayout src_layout, const Viewport &viewport) {
const uint32_t idx = screen.swapchain_image_idx;
vk::CommandBuffer cmd = screen.current_cmd_buffer;
const uint32_t src_w = viewport.texture_width;
const uint32_t src_h = viewport.texture_height;
SMAAConstant constant{
.rt_metrics = { 1.0f / src_w, 1.0f / src_h,
static_cast<float>(src_w), static_cast<float>(src_h) }
};
if (is_pre_renderpass) {
ensure_targets(src_w, src_h);
// the source color view changes every frame -> bind it into the edge set
// (binding 0) and the neighborhood set (binding 0).
std::array<vk::DescriptorImageInfo, 2> src_infos = {
vk::DescriptorImageInfo{ .sampler = linear_sampler, .imageView = src_img, .imageLayout = src_layout },
vk::DescriptorImageInfo{ .sampler = linear_sampler, .imageView = src_img, .imageLayout = src_layout },
};
std::array<vk::WriteDescriptorSet, 2> src_writes = {
vk::WriteDescriptorSet{ .dstSet = edge_sets[idx], .dstBinding = 0, .descriptorType = vk::DescriptorType::eCombinedImageSampler },
vk::WriteDescriptorSet{ .dstSet = neighborhood_sets[idx], .dstBinding = 0, .descriptorType = vk::DescriptorType::eCombinedImageSampler },
};
src_writes[0].setImageInfo(src_infos[0]);
src_writes[1].setImageInfo(src_infos[1]);
screen.state.device.updateDescriptorSets(src_writes, {});
vk::Viewport vp{ 0.0f, 0.0f, static_cast<float>(src_w), static_cast<float>(src_h), 0.0f, 1.0f };
vk::Rect2D scissor{ { 0, 0 }, { src_w, src_h } };
vk::ClearValue clear{ .color = { std::array<float, 4>{ 0.0f, 0.0f, 0.0f, 0.0f } } };
auto run_pass = [&](vk::Framebuffer fb, vk::Pipeline pipeline, vk::PipelineLayout layout,
vk::DescriptorSet set) {
vk::RenderPassBeginInfo begin{
.renderPass = offscreen_render_pass,
.framebuffer = fb,
.renderArea = scissor,
};
begin.setClearValues(clear);
cmd.beginRenderPass(begin, vk::SubpassContents::eInline);
cmd.setViewport(0, vp);
cmd.setScissor(0, scissor);
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, layout, 0, set, {});
cmd.pushConstants(layout, vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
0, sizeof(SMAAConstant), &constant);
bind_fullscreen_quad(cmd, /*sub_region=*/false, viewport);
cmd.draw(screen_vertex_count, 1, 0, 0);
cmd.endRenderPass();
};
// pass 1: edge detection (reads source color)
run_pass(edges_framebuffers[idx], edge_pipeline, edge_pipeline_layout, edge_sets[idx]);
// pass 2: blending weight calculation (reads edges + AreaTex + SearchTex)
run_pass(blend_framebuffers[idx], blend_pipeline, blend_pipeline_layout, blend_sets[idx]);
// the offscreen render pass leaves them in ShaderReadOnly (= SampledImage)
edges_images[idx].layout = vkutil::ImageLayout::SampledImage;
blend_images[idx].layout = vkutil::ImageLayout::SampledImage;
return;
}
// pass 3: neighborhood blending into the (already open) swapchain pass.
// letterbox viewport, identical math to the single-pass filters.
vk::Viewport vp{};
{
const float window_aspect = static_cast<float>(screen.extent.width) / screen.extent.height;
const float vita_aspect = static_cast<float>(DEFAULT_RES_WIDTH) / DEFAULT_RES_HEIGHT;
const bool pixel_perfect = screen.state.fullscreen_hd_res_pixel_perfect & screen.state.fullscreen
& !(screen.extent.width % DEFAULT_RES_WIDTH) & !(screen.extent.height % (DEFAULT_RES_HEIGHT - 4));
if (screen.state.stretch_the_display_area && !pixel_perfect) {
vp.width = static_cast<float>(screen.extent.width);
vp.height = static_cast<float>(screen.extent.height);
vp.x = 0.0f;
vp.y = 0.0f;
} else if ((window_aspect > vita_aspect) && !pixel_perfect) {
vp.width = screen.extent.height * vita_aspect;
vp.height = static_cast<float>(screen.extent.height);
vp.x = (screen.extent.width - vp.width) / 2.0f;
vp.y = 0.0f;
} else {
vp.width = static_cast<float>(screen.extent.width);
vp.height = screen.extent.width / vita_aspect;
vp.x = 0.0f;
vp.y = (screen.extent.height - vp.height) / 2.0f;
}
vp.minDepth = 0.0f;
vp.maxDepth = 1.0f;
}
vk::Rect2D scissor{ { 0, 0 }, screen.extent };
cmd.setViewport(0, vp);
cmd.setScissor(0, scissor);
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, neighborhood_pipeline);
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, neighborhood_pipeline_layout, 0,
neighborhood_sets[idx], {});
cmd.pushConstants(neighborhood_pipeline_layout,
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
0, sizeof(SMAAConstant), &constant);
bind_fullscreen_quad(cmd, /*sub_region=*/true, viewport);
cmd.draw(screen_vertex_count, 1, 0, 0);
}
// ------------FSR 1.0 (FidelityFX Super Resolution) ------------
struct EasuConstant {
Viewport viewport;
vk::Extent2D output_size;
@@ -589,7 +589,9 @@ void ScreenRenderer::set_filter(const std::string_view &filter) {
this->filter = std::make_unique<BilinearScreenFilter>(*this);
} else
this->filter = std::make_unique<FSRScreenFilter>(*this);
} else if (filter == "FXAA")
} else if (filter == "SMAA")
this->filter = std::make_unique<SMAAScreenFilter>(*this);
else if (filter == "FXAA")
this->filter = std::make_unique<FXAAScreenFilter>(*this);
else if (filter == "Bicubic")
this->filter = std::make_unique<BicubicScreenFilter>(*this);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,65 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// FSR 1.0 edge adaptive upscaling pass. The FidelityFX headers and the defines
// (A_GPU, A_GLSL, FSR_EASU_F) are pasted in front of this file by ScreenRenderer.
in vec2 uv_frag;
uniform sampler2D fb;
// xy: top left of the displayed area in the source texture, zw: its size (in pixels)
uniform vec4 input_region;
uniform vec2 texture_size;
uniform vec2 output_size;
out vec4 color_frag;
// the fsr callbacks take the 4 texels textureGather would return
#ifdef FSR_EMULATE_GATHER
vec4 gather_texels(vec2 p, int channel) {
ivec2 last = textureSize(fb, 0) - 1;
ivec2 i0 = ivec2(floor(p * vec2(last + 1) - 0.5));
ivec2 i1 = i0 + 1;
i0 = clamp(i0, ivec2(0), last);
i1 = clamp(i1, ivec2(0), last);
return vec4(
texelFetch(fb, ivec2(i0.x, i1.y), 0)[channel],
texelFetch(fb, ivec2(i1.x, i1.y), 0)[channel],
texelFetch(fb, ivec2(i1.x, i0.y), 0)[channel],
texelFetch(fb, ivec2(i0.x, i0.y), 0)[channel]);
}
AF4 FsrEasuRF(AF2 p) { return gather_texels(p, 0); }
AF4 FsrEasuGF(AF2 p) { return gather_texels(p, 1); }
AF4 FsrEasuBF(AF2 p) { return gather_texels(p, 2); }
#else
AF4 FsrEasuRF(AF2 p) { return textureGather(fb, p, 0); }
AF4 FsrEasuGF(AF2 p) { return textureGather(fb, p, 1); }
AF4 FsrEasuBF(AF2 p) { return textureGather(fb, p, 2); }
#endif
void main() {
AU4 con0, con1, con2, con3;
FsrEasuConOffset(con0, con1, con2, con3, input_region.z, input_region.w, texture_size.x, texture_size.y,
output_size.x, output_size.y, input_region.x, input_region.y);
// gl_FragCoord counts from the bottom while the source texture starts at the top of the image
AU2 pos = AU2(gl_FragCoord.x, output_size.y - 1.0 - floor(gl_FragCoord.y));
AF3 c;
FsrEasuF(c, pos, con0, con1, con2, con3);
color_frag = vec4(c, 1.0);
}
@@ -0,0 +1,40 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// FSR 1.0 contrast adaptive sharpening pass. The FidelityFX headers and the defines
// (A_GPU, A_GLSL, FSR_RCAS_F) are pasted in front of this file by ScreenRenderer.
in vec2 uv_frag;
uniform sampler2D fb;
// where the upscaled image starts in the framebuffer
uniform vec2 output_origin;
uniform float sharpness;
out vec4 color_frag;
AF4 FsrRcasLoadF(ASU2 p) { return texelFetch(fb, clamp(p, ivec2(0), textureSize(fb, 0) - 1), 0); }
void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {}
void main() {
AU4 con;
FsrRcasCon(con, sharpness);
AF3 c;
FsrRcasF(c.r, c.g, c.b, AU2(gl_FragCoord.xy - output_origin), con);
color_frag = vec4(c, 1.0);
}
@@ -0,0 +1,36 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 2: blending weight calculation.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
uniform sampler2D edges_tex;
uniform sampler2D area_tex;
uniform sampler2D search_tex;
in vec2 uv_frag;
in vec2 pixcoord_frag;
in vec4 offset_frag[3];
out vec4 color_frag;
void main() {
// subsample indices are always zero for SMAA 1x
color_frag = SMAABlendingWeightCalculationPS(uv_frag, pixcoord_frag, offset_frag,
edges_tex, area_tex, search_tex, vec4(0.0));
}
@@ -0,0 +1,33 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 2: blending weight calculation.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
in vec3 position_vertex;
in vec2 uv_vertex;
out vec2 uv_frag;
out vec2 pixcoord_frag;
out vec4 offset_frag[3];
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAABlendingWeightCalculationVS(uv_vertex, pixcoord_frag, offset_frag);
}
@@ -0,0 +1,31 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 1: edge detection.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
uniform sampler2D fb;
in vec2 uv_frag;
in vec4 offset_frag[3];
out vec4 color_frag;
void main() {
color_frag = vec4(SMAALumaEdgeDetectionPS(uv_frag, offset_frag, fb), 0.0, 0.0);
}
@@ -0,0 +1,32 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 1: edge detection.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
in vec3 position_vertex;
in vec2 uv_vertex;
out vec2 uv_frag;
out vec4 offset_frag[3];
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAAEdgeDetectionVS(uv_vertex, offset_frag);
}
@@ -0,0 +1,32 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 3: neighborhood blending, drawn straight to the screen.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
uniform sampler2D fb;
uniform sampler2D blend_tex;
in vec2 uv_frag;
in vec4 offset_frag;
out vec4 color_frag;
void main() {
color_frag = SMAANeighborhoodBlendingPS(uv_frag, offset_frag, fb, blend_tex);
}
@@ -0,0 +1,32 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// SMAA pass 3: neighborhood blending, drawn straight to the screen.
// The SMAA.hlsl library and the rt_metrics uniform are injected as a prelude by
// ScreenRenderer::init_smaa.
in vec3 position_vertex;
in vec2 uv_vertex;
out vec2 uv_frag;
out vec4 offset_frag;
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAANeighborhoodBlendingVS(uv_vertex, offset_frag);
}
@@ -0,0 +1,45 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_VS 0
#include "../SMAA.hlsl"
layout(location = 0) in vec2 uv_frag;
layout(location = 1) in vec2 pixcoord_frag;
layout(location = 2) in vec4 offset_frag[3];
layout(binding = 0) uniform sampler2D edges_tex;
layout(binding = 1) uniform sampler2D area_tex;
layout(binding = 2) uniform sampler2D search_tex;
layout(location = 0) out vec4 color_out;
void main() {
// subsampleIndices is always zero for SMAA 1x
color_out = SMAABlendingWeightCalculationPS(uv_frag, pixcoord_frag, offset_frag,
edges_tex, area_tex, search_tex, vec4(0.0));
}
Binary file not shown.
@@ -0,0 +1,42 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(location = 0) in vec3 position_vertex;
layout(location = 1) in vec2 uv_vertex;
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_PS 0
#include "../SMAA.hlsl"
layout(location = 0) out vec2 uv_frag;
layout(location = 1) out vec2 pixcoord_frag;
layout(location = 2) out vec4 offset_frag[3];
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAABlendingWeightCalculationVS(uv_vertex, pixcoord_frag, offset_frag);
}
Binary file not shown.
@@ -0,0 +1,41 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_VS 0
#include "../SMAA.hlsl"
layout(location = 0) in vec2 uv_frag;
layout(location = 1) in vec4 offset_frag[3];
layout(binding = 0) uniform sampler2D color_tex;
layout(location = 0) out vec4 color_out;
void main() {
vec2 edges = SMAALumaEdgeDetectionPS(uv_frag, offset_frag, color_tex);
color_out = vec4(edges, 0.0, 0.0);
}
Binary file not shown.
@@ -0,0 +1,41 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(location = 0) in vec3 position_vertex;
layout(location = 1) in vec2 uv_vertex;
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_PS 0
#include "../SMAA.hlsl"
layout(location = 0) out vec2 uv_frag;
layout(location = 1) out vec4 offset_frag[3];
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAAEdgeDetectionVS(uv_vertex, offset_frag);
}
Binary file not shown.
@@ -0,0 +1,41 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_VS 0
#include "../SMAA.hlsl"
layout(location = 0) in vec2 uv_frag;
layout(location = 1) in vec4 offset_frag;
layout(binding = 0) uniform sampler2D color_tex;
layout(binding = 1) uniform sampler2D blend_tex;
layout(location = 0) out vec4 color_out;
void main() {
color_out = SMAANeighborhoodBlendingPS(uv_frag, offset_frag, color_tex, blend_tex);
}
@@ -0,0 +1,41 @@
// Vita3K emulator project
// Copyright (C) 2026 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#version 450
#extension GL_GOOGLE_include_directive : require
layout(location = 0) in vec3 position_vertex;
layout(location = 1) in vec2 uv_vertex;
layout(push_constant) uniform constants {
vec4 rt_metrics; // 1/w, 1/h, w, h
} pc;
#define SMAA_RT_METRICS pc.rt_metrics
#define SMAA_GLSL_4 1
#define SMAA_PRESET_HIGH 1
#define SMAA_INCLUDE_PS 0
#include "../SMAA.hlsl"
layout(location = 0) out vec2 uv_frag;
layout(location = 1) out vec4 offset_frag;
void main() {
gl_Position = vec4(position_vertex, 1.0);
uv_frag = uv_vertex;
SMAANeighborhoodBlendingVS(uv_vertex, offset_frag);
}