[vk, ogl] VK_QCOM ZTC, Bspline, Mitchell filter weights

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2025-09-25 07:44:47 +00:00
parent 62369aa2d5
commit a76b48a1ae
Signed by: Lizzie
GPG key ID: 00287378CADCAB13
18 changed files with 226 additions and 58 deletions

View file

@ -253,6 +253,9 @@
<item>@string/scaling_filter_nearest_neighbor</item>
<item>@string/scaling_filter_bilinear</item>
<item>@string/scaling_filter_bicubic</item>
<item>@string/scaling_filter_zero_tangent</item>
<item>@string/scaling_filter_bspline</item>
<item>@string/scaling_filter_mitchell</item>
<item>@string/scaling_filter_spline1</item>
<item>@string/scaling_filter_gaussian</item>
<item>@string/scaling_filter_lanczos</item>
@ -271,6 +274,9 @@
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
</integer-array>
<string-array name="rendererAntiAliasingNames">

View file

@ -1018,6 +1018,9 @@
<string name="scaling_filter_scale_force">ScaleForce</string>
<string name="scaling_filter_fsr">AMD FidelityFX™ Super Resolution</string>
<string name="scaling_filter_area">Area</string>
<string name="scaling_filter_zero_tangent">Zero-Tangent-Cardinal</string>
<string name="scaling_filter_bspline">B-Spline</string>
<string name="scaling_filter_mitchell">Mitchell-Netravali</string>
<!-- Anti-Aliasing -->
<string name="anti_aliasing_none">None</string>

View file

@ -143,7 +143,7 @@ ENUM(ConfirmStop, Ask_Always, Ask_Based_On_Game, Ask_Never);
ENUM(FullscreenMode, Borderless, Exclusive);
ENUM(NvdecEmulation, Off, Cpu, Gpu);
ENUM(ResolutionSetup, Res1_4X, Res1_2X, Res3_4X, Res1X, Res5_4X, Res3_2X, Res2X, Res3X, Res4X, Res5X, Res6X, Res7X, Res8X);
ENUM(ScalingFilter, NearestNeighbor, Bilinear, Bicubic, Spline1, Gaussian, Lanczos, ScaleForce, Fsr, Area, MaxEnum);
ENUM(ScalingFilter, NearestNeighbor, Bilinear, Bicubic, ZeroTangent, BSpline, Mitchell, Spline1, Gaussian, Lanczos, ScaleForce, Fsr, Area, MaxEnum);
ENUM(AntiAliasing, None, Fxaa, Smaa, MaxEnum);
ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch);
ENUM(ConsoleMode, Handheld, Docked);

View file

@ -555,6 +555,9 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QObject* parent)
PAIR(ScalingFilter, NearestNeighbor, tr("Nearest Neighbor")),
PAIR(ScalingFilter, Bilinear, tr("Bilinear")),
PAIR(ScalingFilter, Bicubic, tr("Bicubic")),
PAIR(ScalingFilter, ZeroTangent, tr("Zero-Tangent-Cardinal")),
PAIR(ScalingFilter, BSpline, tr("B-Spline")),
PAIR(ScalingFilter, Mitchell, tr("Mitchell-Netravali")),
PAIR(ScalingFilter, Spline1, tr("Spline-1")),
PAIR(ScalingFilter, Gaussian, tr("Gaussian")),
PAIR(ScalingFilter, Lanczos, tr("Lanczos")),

View file

@ -38,6 +38,9 @@ static const std::map<Settings::ScalingFilter, QString> scaling_filter_texts_map
{Settings::ScalingFilter::Bilinear,
QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Bilinear"))},
{Settings::ScalingFilter::Bicubic, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Bicubic"))},
{Settings::ScalingFilter::ZeroTangent, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Zero-Tangent-Cardinal"))},
{Settings::ScalingFilter::BSpline, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "B-Spline"))},
{Settings::ScalingFilter::Mitchell, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Mitchell-Netravali"))},
{Settings::ScalingFilter::Spline1,
QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Spline-1"))},
{Settings::ScalingFilter::Gaussian,

View file

@ -44,6 +44,9 @@ set(SHADER_FILES
pitch_unswizzle.comp
present_area.frag
present_bicubic.frag
present_zero_tangent.frag
present_bspline.frag
present_mitchell.frag
present_gaussian.frag
present_lanczos.frag
present_spline1.frag

View file

@ -1,56 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#version 460 core
layout (location = 0) in vec2 frag_tex_coord;
layout (location = 0) out vec4 color;
layout (binding = 0) uniform sampler2D color_texture;
vec4 cubic(float v) {
vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
vec4 s = n * n * n;
float x = s.x;
float y = s.y - 4.0 * s.x;
float z = s.z - 4.0 * s.y + 6.0 * s.x;
float w = 6.0 - x - y - z;
return vec4(x, y, z, w) * (1.0 / 6.0);
vec4 cubic(float x) {
float x2 = x * x;
float x3 = x2 * x;
return vec4(1.0, x, x2, x3) * transpose(mat4x4(
0.0, 2.0, 0.0, 0.0,
-1.0, 0.0, 1.0, 0.0,
2.0, -5.0, 4.0, -1.0,
-1.0, 3.0, -3.0, 1.0
) * (1.0 / 2.0));
}
vec4 textureBicubic( sampler2D textureSampler, vec2 texCoords ) {
vec2 texSize = textureSize(textureSampler, 0);
vec2 invTexSize = 1.0 / texSize;
texCoords = texCoords * texSize - 0.5;
vec2 fxy = fract(texCoords);
texCoords -= fxy;
vec4 xcubic = cubic(fxy.x);
vec4 ycubic = cubic(fxy.y);
vec4 c = texCoords.xxyy + vec2(-0.5, +1.5).xyxy;
vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);
vec4 offset = c + vec4(xcubic.yw, ycubic.yw) / s;
offset *= invTexSize.xxyy;
vec4 sample0 = texture(textureSampler, offset.xz);
vec4 sample1 = texture(textureSampler, offset.yz);
vec4 sample2 = texture(textureSampler, offset.xw);
vec4 sample3 = texture(textureSampler, offset.yw);
float sx = s.x / (s.x + s.y);
float sy = s.z / (s.z + s.w);
return mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy);
vec4 textureBicubic(sampler2D samp, vec2 uv) {
vec2 tex_size = vec2(textureSize(samp, 0));
vec2 cc_tex = uv * tex_size - 0.5f;
vec2 fex = cc_tex - floor(cc_tex);
vec4 xcubic = cubic(fex.x);
vec4 ycubic = cubic(fex.y);
vec4 c = floor(cc_tex).xxyy + vec2(-0.5f, 1.5f).xyxy;
vec4 z = vec4(xcubic.yw, ycubic.yw);
vec4 s = vec4(xcubic.xz, ycubic.xz) + z;
vec4 offset = (c + z / s) * (1.0f / tex_size).xxyy;
vec2 n = vec2(s.x / (s.x + s.y), s.z / (s.z + s.w));
return mix(
mix(texture(samp, offset.yw), texture(samp, offset.xw), n.x),
mix(texture(samp, offset.yz), texture(samp, offset.xz), n.x),
n.y);
}
void main() {
color = textureBicubic(color_texture, frag_tex_coord);
}

View file

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#version 460 core
layout (location = 0) in vec2 frag_tex_coord;
layout (location = 0) out vec4 color;
layout (binding = 0) uniform sampler2D color_texture;
vec4 cubic(float x) {
float x2 = x * x;
float x3 = x2 * x;
return vec4(1.0, x, x2, x3) * transpose(mat4x4(
1.0, 4.0, 1.0, 0.0,
-3.0, 0.0, 3.0, 0.0,
3.0, -6.0, 3.0, 0.0,
-1.0, 3.0, -3.0, 1.0
) * (1.0 / 6.0));
}
vec4 textureBicubic(sampler2D samp, vec2 uv) {
vec2 tex_size = vec2(textureSize(samp, 0));
vec2 cc_tex = uv * tex_size - 0.5f;
vec2 fex = cc_tex - floor(cc_tex);
vec4 xcubic = cubic(fex.x);
vec4 ycubic = cubic(fex.y);
vec4 c = floor(cc_tex).xxyy + vec2(-0.5f, 1.5f).xyxy;
vec4 z = vec4(xcubic.yw, ycubic.yw);
vec4 s = vec4(xcubic.xz, ycubic.xz) + z;
vec4 offset = (c + z / s) * (1.0f / tex_size).xxyy;
vec2 n = vec2(s.x / (s.x + s.y), s.z / (s.z + s.w));
return mix(
mix(texture(samp, offset.yw), texture(samp, offset.xw), n.x),
mix(texture(samp, offset.yz), texture(samp, offset.xz), n.x),
n.y);
}
void main() {
color = textureBicubic(color_texture, frag_tex_coord);
}

View file

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#version 460 core
layout (location = 0) in vec2 frag_tex_coord;
layout (location = 0) out vec4 color;
layout (binding = 0) uniform sampler2D color_texture;
vec4 cubic(float x) {
float x2 = x * x;
float x3 = x2 * x;
return vec4(1.0, x, x2, x3) * transpose(mat4x4(
1.0, 16.0, 1.0, 0.0,
-9.0, 0.0, 9.0, 0.0,
15.0, -36.0, 27.0, -6.0,
-7.0, 21.0, -21.0, 7.0
) * (1.0 / 18.0));
}
vec4 textureBicubic(sampler2D samp, vec2 uv) {
vec2 tex_size = vec2(textureSize(samp, 0));
vec2 cc_tex = uv * tex_size - 0.5f;
vec2 fex = cc_tex - floor(cc_tex);
vec4 xcubic = cubic(fex.x);
vec4 ycubic = cubic(fex.y);
vec4 c = floor(cc_tex).xxyy + vec2(-0.5f, 1.5f).xyxy;
vec4 z = vec4(xcubic.yw, ycubic.yw);
vec4 s = vec4(xcubic.xz, ycubic.xz) + z;
vec4 offset = (c + z / s) * (1.0f / tex_size).xxyy;
vec2 n = vec2(s.x / (s.x + s.y), s.z / (s.z + s.w));
return mix(
mix(texture(samp, offset.yw), texture(samp, offset.xw), n.x),
mix(texture(samp, offset.yz), texture(samp, offset.xz), n.x),
n.y);
}
void main() {
color = textureBicubic(color_texture, frag_tex_coord);
}

View file

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#version 460 core
layout (location = 0) in vec2 frag_tex_coord;
layout (location = 0) out vec4 color;
layout (binding = 0) uniform sampler2D color_texture;
vec4 cubic(float x) {
float x2 = x * x;
float x3 = x2 * x;
return vec4(1.0, x, x2, x3) * transpose(mat4x4(
0.0, 2.0, 0.0, 0.0,
-2.0, 0.0, 2.0, 0.0,
4.0, -4.0, 2.0, -2.0,
-2.0, 2.0, -2.0, 1.0
) * (1.0 / 2.0));
}
vec4 textureBicubic(sampler2D samp, vec2 uv) {
vec2 tex_size = vec2(textureSize(samp, 0));
vec2 cc_tex = uv * tex_size - 0.5f;
vec2 fex = cc_tex - floor(cc_tex);
vec4 xcubic = cubic(fex.x);
vec4 ycubic = cubic(fex.y);
vec4 c = floor(cc_tex).xxyy + vec2(-0.5f, 1.5f).xyxy;
vec4 z = vec4(xcubic.yw, ycubic.yw);
vec4 s = vec4(xcubic.xz, ycubic.xz) + z;
vec4 offset = (c + z / s) * (1.0f / tex_size).xxyy;
vec2 n = vec2(s.x / (s.x + s.y), s.z / (s.z + s.w));
return mix(
mix(texture(samp, offset.yw), texture(samp, offset.xw), n.x),
mix(texture(samp, offset.yz), texture(samp, offset.xz), n.x),
n.y);
}
void main() {
color = textureBicubic(color_texture, frag_tex_coord);
}

View file

@ -8,6 +8,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "common/settings_enums.h"
#include "video_core/present.h"
#include "video_core/renderer_opengl/gl_blit_screen.h"
#include "video_core/renderer_opengl/gl_state_tracker.h"
@ -86,6 +87,15 @@ void BlitScreen::CreateWindowAdapt() {
case Settings::ScalingFilter::Bicubic:
window_adapt = MakeBicubic(device);
break;
case Settings::ScalingFilter::ZeroTangent:
window_adapt = MakeZeroTangent(device);
break;
case Settings::ScalingFilter::BSpline:
window_adapt = MakeBSpline(device);
break;
case Settings::ScalingFilter::Mitchell:
window_adapt = MakeMitchell(device);
break;
case Settings::ScalingFilter::Gaussian:
window_adapt = MakeGaussian(device);
break;

View file

@ -14,6 +14,9 @@
#include "video_core/host_shaders/present_gaussian_frag.h"
#include "video_core/host_shaders/present_lanczos_frag.h"
#include "video_core/host_shaders/present_spline1_frag.h"
#include "video_core/host_shaders/present_mitchell_frag_spv.h"
#include "video_core/host_shaders/present_bspline_frag_spv.h"
#include "video_core/host_shaders/present_zero_tangent_frag_spv.h"
#include "video_core/renderer_opengl/present/filters.h"
#include "video_core/renderer_opengl/present/util.h"
@ -39,6 +42,21 @@ std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device) {
HostShaders::PRESENT_BICUBIC_FRAG);
}
std::unique_ptr<WindowAdaptPass> MakeMitchell(const Device& device) {
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
HostShaders::PRESENT_MITCHELL_FRAG);
}
std::unique_ptr<WindowAdaptPass> MakeZeroTangent(const Device& device) {
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
HostShaders::PRESENT_ZERO_TANGENT_FRAG);
}
std::unique_ptr<WindowAdaptPass> MakeBSpline(const Device& device) {
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
HostShaders::PRESENT_BSPLINE_FRAG);
}
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device) {
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
HostShaders::PRESENT_GAUSSIAN_FRAG);

View file

@ -17,6 +17,9 @@ namespace OpenGL {
std::unique_ptr<WindowAdaptPass> MakeNearestNeighbor(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeBilinear(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeZeroTangent(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeMitchell(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeBSpline(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeSpline1(const Device& device);
std::unique_ptr<WindowAdaptPass> MakeLanczos(const Device& device);

View file

@ -7,6 +7,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
#include "common/common_types.h"
#include "video_core/host_shaders/present_area_frag_spv.h"
@ -14,6 +15,9 @@
#include "video_core/host_shaders/present_gaussian_frag_spv.h"
#include "video_core/host_shaders/present_lanczos_frag_spv.h"
#include "video_core/host_shaders/present_spline1_frag_spv.h"
#include "video_core/host_shaders/present_mitchell_frag_spv.h"
#include "video_core/host_shaders/present_bspline_frag_spv.h"
#include "video_core/host_shaders/present_zero_tangent_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_scaleforce_fp16_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_scaleforce_fp32_frag_spv.h"
@ -52,13 +56,27 @@ std::unique_ptr<WindowAdaptPass> MakeSpline1(const Device& device, VkFormat fram
BuildShader(device, PRESENT_SPLINE1_FRAG_SPV));
}
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device, VkFormat frame_format) {
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device, VkFormat frame_format, VkCubicFilterWeightsQCOM qcom_weights) {
// No need for handrolled shader -- if the VK impl can do it for us ;)
if (device.IsExtFilterCubicSupported())
return std::make_unique<WindowAdaptPass>(device, frame_format, CreateCubicSampler(device),
BuildShader(device, VULKAN_PRESENT_FRAG_SPV));
return std::make_unique<WindowAdaptPass>(device, frame_format, CreateBilinearSampler(device),
BuildShader(device, PRESENT_BICUBIC_FRAG_SPV));
if (device.IsExtFilterCubicSupported()) {
return std::make_unique<WindowAdaptPass>(device, frame_format, CreateCubicSampler(device,
qcom_weights), BuildShader(device, VULKAN_PRESENT_FRAG_SPV));
} else {
return std::make_unique<WindowAdaptPass>(device, frame_format, CreateBilinearSampler(device), [&](){
switch (qcom_weights) {
case VK_CUBIC_FILTER_WEIGHTS_CATMULL_ROM_QCOM:
return BuildShader(device, PRESENT_BICUBIC_FRAG_SPV);
case VK_CUBIC_FILTER_WEIGHTS_ZERO_TANGENT_CARDINAL_QCOM:
return BuildShader(device, PRESENT_ZERO_TANGENT_FRAG_SPV);
case VK_CUBIC_FILTER_WEIGHTS_B_SPLINE_QCOM:
return BuildShader(device, PRESENT_BSPLINE_FRAG_SPV);
case VK_CUBIC_FILTER_WEIGHTS_MITCHELL_NETRAVALI_QCOM:
return BuildShader(device, PRESENT_MITCHELL_FRAG_SPV);
default:
UNREACHABLE();
}
}());
}
}
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device, VkFormat frame_format) {

View file

@ -17,7 +17,7 @@ class MemoryAllocator;
std::unique_ptr<WindowAdaptPass> MakeNearestNeighbor(const Device& device, VkFormat frame_format);
std::unique_ptr<WindowAdaptPass> MakeBilinear(const Device& device, VkFormat frame_format);
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device, VkFormat frame_format);
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device, VkFormat frame_format, VkCubicFilterWeightsQCOM qcom_weights);
std::unique_ptr<WindowAdaptPass> MakeSpline1(const Device& device, VkFormat frame_format);
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device, VkFormat frame_format);
std::unique_ptr<WindowAdaptPass> MakeLanczos(const Device& device, VkFormat frame_format);

View file

@ -624,8 +624,8 @@ vk::Sampler CreateNearestNeighborSampler(const Device& device) {
return device.GetLogical().CreateSampler(ci_nn);
}
vk::Sampler CreateCubicSampler(const Device& device) {
const VkSamplerCreateInfo ci_nn{
vk::Sampler CreateCubicSampler(const Device& device, VkCubicFilterWeightsQCOM qcom_weights) {
VkSamplerCreateInfo ci_nn{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
@ -645,7 +645,14 @@ vk::Sampler CreateCubicSampler(const Device& device) {
.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
.unnormalizedCoordinates = VK_FALSE,
};
const VkSamplerCubicWeightsCreateInfoQCOM ci_qcom_nn{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CUBIC_WEIGHTS_CREATE_INFO_QCOM,
.pNext = nullptr,
.cubicWeights = qcom_weights
};
// If not specified, assume Catmull-Rom
if (qcom_weights != VK_CUBIC_FILTER_WEIGHTS_CATMULL_ROM_QCOM)
ci_nn.pNext = &ci_qcom_nn;
return device.GetLogical().CreateSampler(ci_nn);
}

View file

@ -57,7 +57,7 @@ VkWriteDescriptorSet CreateWriteDescriptorSet(std::vector<VkDescriptorImageInfo>
VkDescriptorSet set, u32 binding);
vk::Sampler CreateBilinearSampler(const Device& device);
vk::Sampler CreateNearestNeighborSampler(const Device& device);
vk::Sampler CreateCubicSampler(const Device& device);
vk::Sampler CreateCubicSampler(const Device& device, std::optional<VkCubicFilterWeightsQCOM> qcom_weights);
void BeginRenderPass(vk::CommandBuffer& cmdbuf, VkRenderPass render_pass, VkFramebuffer framebuffer,
VkExtent2D extent);

View file

@ -7,6 +7,7 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <vulkan/vulkan_core.h>
#include "video_core/framebuffer_config.h"
#include "video_core/present.h"
#include "video_core/renderer_vulkan/present/filters.h"
@ -41,7 +42,16 @@ void BlitScreen::SetWindowAdaptPass() {
window_adapt = MakeNearestNeighbor(device, swapchain_view_format);
break;
case Settings::ScalingFilter::Bicubic:
window_adapt = MakeBicubic(device, swapchain_view_format);
window_adapt = MakeBicubic(device, swapchain_view_format, VK_CUBIC_FILTER_WEIGHTS_CATMULL_ROM_QCOM);
break;
case Settings::ScalingFilter::ZeroTangent:
window_adapt = MakeBicubic(device, swapchain_view_format, VK_CUBIC_FILTER_WEIGHTS_ZERO_TANGENT_CARDINAL_QCOM);
break;
case Settings::ScalingFilter::BSpline:
window_adapt = MakeBicubic(device, swapchain_view_format, VK_CUBIC_FILTER_WEIGHTS_B_SPLINE_QCOM);
break;
case Settings::ScalingFilter::Mitchell:
window_adapt = MakeBicubic(device, swapchain_view_format, VK_CUBIC_FILTER_WEIGHTS_MITCHELL_NETRAVALI_QCOM);
break;
case Settings::ScalingFilter::Spline1:
window_adapt = MakeSpline1(device, swapchain_view_format);