From 894d19eb81ade7bee7a7a22d12b7e2a3a8d0a465 Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 11 Sep 2024 18:56:43 -0400 Subject: [PATCH] rt(d3d12): draw final pass to output targets --- librashader-runtime-d3d12/src/filter_chain.rs | 51 +++++++++++++++++-- librashader-runtime-d3d12/tests/triangle.rs | 4 +- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index dce34b1..1a5701e 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -824,6 +824,53 @@ impl FilterChainD3D12 { // try to hint the optimizer assert_eq!(last.len(), 1); if let Some(pass) = last.iter_mut().next() { + let index = passes_len - 1; + + source.filter = pass.config.filter; + source.wrap_mode = pass.config.wrap_mode; + + let feedback_target = &self.output_framebuffers[index]; + + if pass.pipeline.format != feedback_target.format { + // eprintln!("recompiling final pipeline"); + pass.pipeline.recompile( + feedback_target.format, + &self.common.root_signature, + &self.common.d3d12, + )?; + } + + self.residuals + .dispose_barriers(util::d3d12_resource_transition( + cmd, + &feedback_target.handle.resource(), + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET, + )); + + let view = feedback_target.create_render_target_view(&mut self.rtv_heap)?; + let out = RenderTarget::viewport_with_output(&view, viewport); + pass.draw( + cmd, + index, + &self.common, + pass.config.get_frame_count(frame_count), + options, + viewport, + &original, + &source, + &out, + QuadType::Final, + )?; + + self.residuals + .dispose_barriers(util::d3d12_resource_transition( + cmd, + &feedback_target.handle.resource(), + D3D12_RESOURCE_STATE_RENDER_TARGET, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + )); + if pass.pipeline.format != viewport.output.format { // eprintln!("recompiling final pipeline"); pass.pipeline.recompile( @@ -833,11 +880,7 @@ impl FilterChainD3D12 { )?; } - source.filter = pass.config.filter; - source.wrap_mode = pass.config.wrap_mode; - let out = RenderTarget::viewport(viewport); - pass.draw( cmd, passes_len - 1, diff --git a/librashader-runtime-d3d12/tests/triangle.rs b/librashader-runtime-d3d12/tests/triangle.rs index c511396..db45df4 100644 --- a/librashader-runtime-d3d12/tests/triangle.rs +++ b/librashader-runtime-d3d12/tests/triangle.rs @@ -5,12 +5,12 @@ use crate::hello_triangle::{DXSample, SampleCommandLine}; #[test] fn triangle_d3d12() { let sample = hello_triangle::d3d12_hello_triangle::Sample::new( - "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", + // "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", // "../test/shaders_slang/crt/crt-lottes.slangp", // "../test/basic.slangp", // "../test/shaders_slang/handheld/console-border/gbc-lcd-grid-v2.slangp", // "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp", - // "../test/shaders_slang/test/feedback.slangp", + "../test/shaders_slang/test/feedback.slangp", // "../test/shaders_slang/test/history.slangp", // "../test/shaders_slang/crt/crt-royale.slangp", // "../test/slang-shaders/vhs/VHSPro.slangp",