Skip to content

Commit f31ddce

Browse files
committed
MetalFX: change fallback behaviour
Closes godotengine#103782
1 parent b5bdb88 commit f31ddce

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

servers/rendering/renderer_viewport.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,22 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) {
145145
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_OFF;
146146
}
147147

148-
// Verify MetalFX upscaling support.
149-
if (
150-
(scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_METALFX_TEMPORAL && !RD::get_singleton()->has_feature(RD::SUPPORTS_METALFX_TEMPORAL)) ||
151-
(scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_METALFX_SPATIAL && !RD::get_singleton()->has_feature(RD::SUPPORTS_METALFX_SPATIAL))) {
152-
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_BILINEAR;
153-
WARN_PRINT_ONCE("MetalFX upscaling is not supported in the current renderer. Falling back to bilinear 3D resolution scaling.");
148+
if (scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_METALFX_TEMPORAL && !RD::get_singleton()->has_feature(RD::SUPPORTS_METALFX_TEMPORAL)) {
149+
if (RD::get_singleton()->has_feature(RD::SUPPORTS_METALFX_SPATIAL)) {
150+
// Prefer MetalFX spatial if it is supported, which will be much more efficient than FSR2,
151+
// as the hardware already will struggle with FSR2.
152+
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_METALFX_SPATIAL;
153+
WARN_PRINT_ONCE("MetalFX temporal upscaling is not supported by the current renderer or hardware. Falling back to MetalFX Spatial scaling.");
154+
} else {
155+
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_FSR2;
156+
WARN_PRINT_ONCE("MetalFX upscaling is not supported by the current renderer or hardware. Falling back to FSR 2 scaling.");
157+
}
158+
scaling_type = RS::scaling_3d_mode_type(scaling_3d_mode);
159+
}
160+
161+
if (scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_METALFX_SPATIAL && !RD::get_singleton()->has_feature(RD::SUPPORTS_METALFX_SPATIAL)) {
162+
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_FSR;
163+
WARN_PRINT_ONCE("MetalFX spatial upscaling is not supported by the current renderer or hardware. Falling back to FSR scaling.");
154164
}
155165

156166
RS::ViewportMSAA msaa_3d = p_viewport->msaa_3d;
@@ -160,11 +170,9 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) {
160170
double min_scale = (double)RD::get_singleton()->limit_get(RD::LIMIT_METALFX_TEMPORAL_SCALER_MIN_SCALE) / 1000'000.0;
161171
double max_scale = (double)RD::get_singleton()->limit_get(RD::LIMIT_METALFX_TEMPORAL_SCALER_MAX_SCALE) / 1000'000.0;
162172
if ((double)scaling_3d_scale < min_scale || (double)scaling_3d_scale > max_scale) {
163-
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_BILINEAR;
164-
WARN_PRINT_ONCE(vformat("MetalFX temporal upscaling scale is outside limits; scale must be between %f and %f. Falling back to bilinear 3D resolution scaling.", min_scale, max_scale));
165-
}
166-
167-
if (msaa_3d != RS::VIEWPORT_MSAA_DISABLED) {
173+
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_FSR2;
174+
WARN_PRINT_ONCE(vformat("MetalFX temporal upscaling scale is outside limits; scale must be between %f and %f. Falling back to FSR 2 3D resolution scaling.", min_scale, max_scale));
175+
} else if (msaa_3d != RS::VIEWPORT_MSAA_DISABLED) {
168176
WARN_PRINT_ONCE("MetalFX temporal upscaling does not support 3D MSAA. Disabling 3D MSAA internally.");
169177
msaa_3d = RS::VIEWPORT_MSAA_DISABLED;
170178
}
@@ -174,7 +182,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) {
174182
bool use_taa = p_viewport->use_taa;
175183

176184
if (scaling_3d_is_not_bilinear && (scaling_3d_scale >= (1.0 + EPSILON))) {
177-
// FSR is not designed for downsampling.
185+
// FSR and MetalFX is not designed for downsampling.
178186
// Fall back to bilinear scaling.
179187
WARN_PRINT_ONCE("FSR 3D resolution scaling is not designed for downsampling. Falling back to bilinear 3D resolution scaling.");
180188
scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_BILINEAR;
@@ -188,8 +196,8 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) {
188196
}
189197

190198
if (use_taa && (scaling_type == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL)) {
191-
// FSR2 can't be used with TAA.
192-
// Turn it off and prefer using FSR2.
199+
// Temporal upscalers can't be used with TAA.
200+
// Turn it off and prefer using the temporal upscaler.
193201
WARN_PRINT_ONCE("FSR 2 or MetalFX Temporal is not compatible with TAA. Disabling TAA internally.");
194202
use_taa = false;
195203
}

0 commit comments

Comments
 (0)