Skip to content

Commit 1bb17a9

Browse files
JMS55alice-i-cecilecart
authored
Initial DLSS implementation (#19864)
# Objective - Closes #8420 ## Solution - Initial implementation of DLSS upscaling, via https://github.com/bevyengine/dlss_wgpu. - Future PRs will work more on transparency, exposure, working with custom viewports, fixing inevitable resolution override bugs, etc. - DLSS framegen is not planned, but ray-reconstruction is for solari. - FSR3/4, XeSS2, and MetalFX temporal upscaling should be easy to add now if a future contributor wants to. In the future we could have an auto-temporal AA component that handles DLSS/FSR/XeSS/MetalFX/TAA fallbacks automatically. ## Testing - Did you test these changes? If so, how? - Run the anti_aliasing example - Are there any parts that need more testing? - Different types of scene content and rendering effects to make sure they work with DLSS/upscaling - Reviewing dlss_wgpu code --- ## Showcase ![bafkreib4u2hc7kgru7n6ujh6tjq5aydfcz7m7lfleexvfa6fdixegveaee](https://github.com/user-attachments/assets/891b32af-54d5-41da-81d8-d63fc085afec) --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
1 parent 3d89327 commit 1bb17a9

File tree

16 files changed

+930
-18
lines changed

16 files changed

+930
-18
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ tonemapping_luts = ["bevy_internal/tonemapping_luts", "ktx2", "bevy_image/zstd"]
475475
# Include SMAA Look Up Tables KTX2 Files
476476
smaa_luts = ["bevy_internal/smaa_luts"]
477477

478+
# NVIDIA Deep Learning Super Sampling
479+
dlss = ["bevy_internal/dlss"]
480+
481+
# Forcibly disable DLSS so that cargo build --all-features works without the DLSS SDK being installed. Not meant for users.
482+
force_disable_dlss = ["bevy_internal/force_disable_dlss"]
483+
478484
# Enable AccessKit on Unix backends (currently only works with experimental screen readers and forks.)
479485
accesskit_unix = ["bevy_internal/accesskit_unix"]
480486

@@ -1030,7 +1036,7 @@ doc-scrape-examples = true
10301036

10311037
[package.metadata.example.anti_aliasing]
10321038
name = "Anti-aliasing"
1033-
description = "Compares different anti-aliasing methods"
1039+
description = "Compares different anti-aliasing techniques supported by Bevy"
10341040
category = "3D Rendering"
10351041
# TAA not supported by WebGL
10361042
wasm = false

crates/bevy_anti_aliasing/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ trace = []
1313
webgl = []
1414
webgpu = []
1515
smaa_luts = ["bevy_image/ktx2", "bevy_image/zstd"]
16+
dlss = ["dep:dlss_wgpu", "dep:uuid", "bevy_render/raw_vulkan_init"]
17+
force_disable_dlss = ["dlss_wgpu?/mock"]
1618

1719
[dependencies]
1820
# bevy
@@ -32,6 +34,8 @@ bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.17.0-dev" }
3234

3335
# other
3436
tracing = { version = "0.1", default-features = false, features = ["std"] }
37+
dlss_wgpu = { version = "1", optional = true }
38+
uuid = { version = "1", optional = true }
3539

3640
[lints]
3741
workspace = true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use super::{prepare::DlssRenderContext, Dlss, DlssFeature};
2+
use bevy_camera::{Camera, MainPassResolutionOverride, Projection};
3+
use bevy_ecs::{
4+
query::{Has, With},
5+
system::{Commands, Query, ResMut},
6+
};
7+
use bevy_render::{sync_world::RenderEntity, view::Hdr, MainWorld};
8+
9+
pub fn extract_dlss<F: DlssFeature>(
10+
mut commands: Commands,
11+
mut main_world: ResMut<MainWorld>,
12+
cleanup_query: Query<Has<Dlss<F>>>,
13+
) {
14+
let mut cameras_3d = main_world
15+
.query_filtered::<(RenderEntity, &Camera, &Projection, Option<&mut Dlss<F>>), With<Hdr>>();
16+
17+
for (entity, camera, camera_projection, mut dlss) in cameras_3d.iter_mut(&mut main_world) {
18+
let has_perspective_projection = matches!(camera_projection, Projection::Perspective(_));
19+
let mut entity_commands = commands
20+
.get_entity(entity)
21+
.expect("Camera entity wasn't synced.");
22+
if dlss.is_some() && camera.is_active && has_perspective_projection {
23+
entity_commands.insert(dlss.as_deref().unwrap().clone());
24+
dlss.as_mut().unwrap().reset = false;
25+
} else if cleanup_query.get(entity) == Ok(true) {
26+
entity_commands.remove::<(Dlss<F>, DlssRenderContext<F>, MainPassResolutionOverride)>();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)