@@ -34,7 +34,7 @@ constexpr bool ALLOW_BLAS_MERGING = true;
34
34
constexpr bool ALLOW_HDR = false ; // use "WIN + ALT + B" to switch HDR mode
35
35
constexpr bool USE_LOW_PRECISION_FP_FORMATS = true ; // saves a bit of memory and performance
36
36
constexpr bool USE_DLSS_TNN = false ; // replace CNN (legacy) with TNN (better)
37
- constexpr bool USE_FSR = false ; // replace DLSS-SR with FSR
37
+ constexpr nri::UpscalerType upscalerType = nri::UpscalerType::DLSR;
38
38
constexpr bool NRD_ALLOW_DESCRIPTOR_CACHING = true ;
39
39
constexpr bool NRD_PROMOTE_FLOAT16_TO_32 = false ;
40
40
constexpr bool NRD_DEMOTE_FLOAT32_TO_16 = false ;
@@ -752,19 +752,29 @@ bool Sample::Initialize(nri::GraphicsAPI graphicsAPI)
752
752
753
753
if (m_DlssQuality != -1 )
754
754
{
755
- nri::UpscalerBits upscalerFlags = nri::UpscalerBits::AUTO_EXPOSURE | nri::UpscalerBits:: DEPTH_INFINITE;
755
+ nri::UpscalerBits upscalerFlags = nri::UpscalerBits::DEPTH_INFINITE;
756
756
upscalerFlags |= NRD_MODE < OCCLUSION ? nri::UpscalerBits::HDR : nri::UpscalerBits::NONE;
757
757
upscalerFlags |= m_ReversedZ ? nri::UpscalerBits::DEPTH_INVERTED : nri::UpscalerBits::NONE;
758
758
759
+ nri::UpscalerMode mode = nri::UpscalerMode::NATIVE;
760
+ if (m_DlssQuality == 0 )
761
+ mode = nri::UpscalerMode::ULTRA_PERFORMANCE;
762
+ else if (m_DlssQuality == 1 )
763
+ mode = nri::UpscalerMode::PERFORMANCE;
764
+ else if (m_DlssQuality == 2 )
765
+ mode = nri::UpscalerMode::BALANCED;
766
+ else if (m_DlssQuality == 3 )
767
+ mode = nri::UpscalerMode::QUALITY;
768
+
759
769
if (NRI.IsUpscalerSupported (*m_Device, nri::UpscalerType::DLSR))
760
770
{
761
771
nri::VideoMemoryInfo videoMemoryInfo1 = {};
762
772
NRI.QueryVideoMemoryInfo (*m_Device, nri::MemoryLocation::DEVICE, videoMemoryInfo1);
763
773
764
774
nri::UpscalerDesc upscalerDesc = {};
765
775
upscalerDesc.upscaleResolution = {(nri::Dim_t)GetOutputResolution ().x , (nri::Dim_t)GetOutputResolution ().y };
766
- upscalerDesc.type = USE_FSR ? nri::UpscalerType::FSR : nri::UpscalerType::DLSR ;
767
- upscalerDesc.mode = (nri::UpscalerMode)(( int32_t )nri::UpscalerMode::ULTRA_PERFORMANCE - m_DlssQuality) ;
776
+ upscalerDesc.type = upscalerType ;
777
+ upscalerDesc.mode = mode ;
768
778
upscalerDesc.flags = upscalerFlags;
769
779
upscalerDesc.preset = USE_DLSS_TNN ? 10 : 0 ;
770
780
NRI_ABORT_ON_FAILURE ( NRI.CreateUpscaler (*m_Device, upscalerDesc, m_DLSR) );
@@ -795,7 +805,7 @@ bool Sample::Initialize(nri::GraphicsAPI graphicsAPI)
795
805
nri::UpscalerDesc upscalerDesc = {};
796
806
upscalerDesc.upscaleResolution = {(nri::Dim_t)GetOutputResolution ().x , (nri::Dim_t)GetOutputResolution ().y };
797
807
upscalerDesc.type = nri::UpscalerType::DLRR;
798
- upscalerDesc.mode = (nri::UpscalerMode)(( int32_t )nri::UpscalerMode::ULTRA_PERFORMANCE - m_DlssQuality) ;
808
+ upscalerDesc.mode = mode ;
799
809
upscalerDesc.flags = upscalerFlags;
800
810
NRI_ABORT_ON_FAILURE ( NRI.CreateUpscaler (*m_Device, upscalerDesc, m_DLRR) );
801
811
@@ -2524,6 +2534,7 @@ nri::Format Sample::CreateSwapChain()
2524
2534
const nri::TextureDesc& swapChainTextureDesc = NRI.GetTextureDesc (*swapChainTextures[0 ]);
2525
2535
nri::Format swapChainFormat = swapChainTextureDesc.format ;
2526
2536
2537
+ m_SwapChainBuffers.clear ();
2527
2538
for (uint32_t i = 0 ; i < swapChainTextureNum; i++)
2528
2539
{
2529
2540
m_SwapChainBuffers.emplace_back ();
@@ -5075,12 +5086,12 @@ void Sample::RenderFrame(uint32_t frameIndex)
5075
5086
5076
5087
if (m_Settings.RR )
5077
5088
{
5078
- dispatchUpscaleDesc.guides .dlrr .mv = {Get (Texture::Mv), Get (Descriptor::Mv_Texture)};
5079
- dispatchUpscaleDesc.guides .dlrr .depth = {Get (Texture::ViewZ), Get (Descriptor::ViewZ_Texture)};
5080
- dispatchUpscaleDesc.guides .dlrr .diffuseAlbedo = {Get (Texture::RRGuide_DiffAlbedo), Get (Descriptor::RRGuide_DiffAlbedo_Texture)};
5081
- dispatchUpscaleDesc.guides .dlrr .specularAlbedo = {Get (Texture::RRGuide_SpecAlbedo), Get (Descriptor::RRGuide_SpecAlbedo_Texture)};
5082
- dispatchUpscaleDesc.guides .dlrr .normalRoughness = {Get (Texture::RRGuide_Normal_Roughness), Get (Descriptor::RRGuide_Normal_Roughness_Texture)};
5083
- dispatchUpscaleDesc.guides .dlrr .specularMvOrHitT = {Get (Texture::RRGuide_SpecHitDistance), Get (Descriptor::RRGuide_SpecHitDistance_Texture)};
5089
+ dispatchUpscaleDesc.guides .denoiser .mv = {Get (Texture::Mv), Get (Descriptor::Mv_Texture)};
5090
+ dispatchUpscaleDesc.guides .denoiser .depth = {Get (Texture::ViewZ), Get (Descriptor::ViewZ_Texture)};
5091
+ dispatchUpscaleDesc.guides .denoiser .diffuseAlbedo = {Get (Texture::RRGuide_DiffAlbedo), Get (Descriptor::RRGuide_DiffAlbedo_Texture)};
5092
+ dispatchUpscaleDesc.guides .denoiser .specularAlbedo = {Get (Texture::RRGuide_SpecAlbedo), Get (Descriptor::RRGuide_SpecAlbedo_Texture)};
5093
+ dispatchUpscaleDesc.guides .denoiser .normalRoughness = {Get (Texture::RRGuide_Normal_Roughness), Get (Descriptor::RRGuide_Normal_Roughness_Texture)};
5094
+ dispatchUpscaleDesc.guides .denoiser .specularMvOrHitT = {Get (Texture::RRGuide_SpecHitDistance), Get (Descriptor::RRGuide_SpecHitDistance_Texture)};
5084
5095
5085
5096
memcpy (&dispatchUpscaleDesc.settings .dlrr .worldToViewMatrix , &m_Camera.state .mWorldToView , sizeof (m_Camera.state .mWorldToView ));
5086
5097
memcpy (&dispatchUpscaleDesc.settings .dlrr .viewToClipMatrix , &m_Camera.state .mViewToClip , sizeof (m_Camera.state .mViewToClip ));
@@ -5089,21 +5100,17 @@ void Sample::RenderFrame(uint32_t frameIndex)
5089
5100
}
5090
5101
else
5091
5102
{
5092
- if (USE_FSR)
5103
+ dispatchUpscaleDesc.guides .upscaler .mv = {Get (Texture::Mv), Get (Descriptor::Mv_Texture)};
5104
+ dispatchUpscaleDesc.guides .upscaler .depth = {Get (Texture::ViewZ), Get (Descriptor::ViewZ_Texture)};
5105
+
5106
+ if (m_DLSR && upscalerType == nri::UpscalerType::FSR) // workaround for "conditional expression is constant"
5093
5107
{
5094
- dispatchUpscaleDesc.guides .fsr .mv = {Get (Texture::Mv), Get (Descriptor::Mv_Texture)};
5095
- dispatchUpscaleDesc.guides .fsr .depth = {Get (Texture::ViewZ), Get (Descriptor::ViewZ_Texture)};
5096
5108
dispatchUpscaleDesc.settings .fsr .zNear = 0 .1f ;
5097
5109
dispatchUpscaleDesc.settings .fsr .verticalFov = radians (m_Settings.camFov );
5098
5110
dispatchUpscaleDesc.settings .fsr .frameTime = m_Timer.GetSmoothedFrameTime ();
5099
5111
dispatchUpscaleDesc.settings .fsr .viewSpaceToMetersFactor = 1 .0f ;
5100
5112
dispatchUpscaleDesc.settings .fsr .sharpness = 0 .0f ;
5101
5113
}
5102
- else
5103
- {
5104
- dispatchUpscaleDesc.guides .dlsr .mv = {Get (Texture::Mv), Get (Descriptor::Mv_Texture)};
5105
- dispatchUpscaleDesc.guides .dlsr .depth = {Get (Texture::ViewZ), Get (Descriptor::ViewZ_Texture)};
5106
- }
5107
5114
5108
5115
NRI.CmdDispatchUpscale (commandBuffer, *m_DLSR, dispatchUpscaleDesc);
5109
5116
}
@@ -5208,7 +5215,9 @@ void Sample::RenderFrame(uint32_t frameIndex)
5208
5215
NRI.CmdDispatch (commandBuffer, {windowGridW, windowGridH, 1 });
5209
5216
}
5210
5217
5211
- const uint32_t backBufferIndex = NRI.AcquireNextSwapChainTexture (*m_SwapChain);
5218
+ uint32_t backBufferIndex = NRI.AcquireNextSwapChainTexture (*m_SwapChain);
5219
+ assert (backBufferIndex != nri::OUT_OF_DATE && " Oops, unhandled swap chain is out of date!" );
5220
+
5212
5221
const BackBuffer* backBuffer = &m_SwapChainBuffers[backBufferIndex];
5213
5222
5214
5223
{ // Copy to back-buffer
0 commit comments