Skip to content

Commit 9016404

Browse files
SuperResolution: add StateTransitionMode to ExecuteSuperResolutionAttribs; clean up documentation
1 parent 65c99c5 commit 9016404

File tree

6 files changed

+44
-41
lines changed

6 files changed

+44
-41
lines changed

Graphics/SuperResolution/include/SuperResolutionBase.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <vector>
3535
#include <string>
36+
#include <array>
3637

3738
namespace Diligent
3839
{
@@ -109,6 +110,33 @@ class SuperResolutionBase : public ObjectBase<ISuperResolution>
109110
}
110111
}
111112

113+
protected:
114+
void TransitionResourceStates(const ExecuteSuperResolutionAttribs& Attribs, RESOURCE_STATE OutputTextureState = RESOURCE_STATE_UNORDERED_ACCESS)
115+
{
116+
if (Attribs.StateTransitionMode != RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
117+
return;
118+
119+
std::array<StateTransitionDesc, 7> Barriers;
120+
Uint32 BarrierCount = 0;
121+
122+
auto AddBarrier = [&](ITextureView* pView, RESOURCE_STATE NewState) {
123+
if (pView == nullptr)
124+
return;
125+
VERIFY_EXPR(BarrierCount < Barriers.size());
126+
Barriers[BarrierCount++] = StateTransitionDesc{pView->GetTexture(), RESOURCE_STATE_UNKNOWN, NewState, STATE_TRANSITION_FLAG_UPDATE_STATE};
127+
};
128+
129+
AddBarrier(Attribs.pColorTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
130+
AddBarrier(Attribs.pDepthTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
131+
AddBarrier(Attribs.pMotionVectorsSRV, RESOURCE_STATE_SHADER_RESOURCE);
132+
AddBarrier(Attribs.pOutputTextureView, OutputTextureState);
133+
AddBarrier(Attribs.pExposureTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
134+
AddBarrier(Attribs.pReactiveMaskTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
135+
AddBarrier(Attribs.pIgnoreHistoryMaskTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
136+
137+
Attribs.pContext->TransitionResourceStates(BarrierCount, Barriers.data());
138+
}
139+
112140
protected:
113141
SuperResolutionDesc m_Desc;
114142
SuperResolutionInfo m_Info;

Graphics/SuperResolution/include/SuperResolutionDLSS.hpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
/// Shared DLSS utilities used by per-API DLSS backend implementations.
3131

3232
#include <vector>
33-
#include <array>
3433

3534
#include <nvsdk_ngx_defs.h>
3635
#include <nvsdk_ngx_params.h>
@@ -118,29 +117,6 @@ class SuperResolutionDLSS : public SuperResolutionBase
118117
return m_pDLSSFeature;
119118
}
120119

121-
void TransitionResourceStates(const ExecuteSuperResolutionAttribs& Attribs)
122-
{
123-
std::array<StateTransitionDesc, 7> Barriers;
124-
Uint32 BarrierCount = 0;
125-
126-
auto AddBarrier = [&](ITextureView* pView, RESOURCE_STATE NewState) {
127-
if (pView == nullptr)
128-
return;
129-
VERIFY_EXPR(BarrierCount < Barriers.size());
130-
Barriers[BarrierCount++] = StateTransitionDesc{pView->GetTexture(), RESOURCE_STATE_UNKNOWN, NewState, STATE_TRANSITION_FLAG_UPDATE_STATE};
131-
};
132-
133-
AddBarrier(Attribs.pColorTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
134-
AddBarrier(Attribs.pDepthTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
135-
AddBarrier(Attribs.pMotionVectorsSRV, RESOURCE_STATE_SHADER_RESOURCE);
136-
AddBarrier(Attribs.pOutputTextureView, RESOURCE_STATE_UNORDERED_ACCESS);
137-
AddBarrier(Attribs.pExposureTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
138-
AddBarrier(Attribs.pReactiveMaskTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
139-
AddBarrier(Attribs.pIgnoreHistoryMaskTextureSRV, RESOURCE_STATE_SHADER_RESOURCE);
140-
141-
Attribs.pContext->TransitionResourceStates(BarrierCount, Barriers.data());
142-
}
143-
144120
protected:
145121
NVSDK_NGX_Parameter* const m_pNGXParams;
146122

Graphics/SuperResolution/interface/SuperResolution.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct ExecuteSuperResolutionAttribs
149149

150150
/// Output (upscaled) texture (unordered access view or render target view).
151151
///
152-
/// Must match SuperResolutionDesc::OutputWidth x OutputHeight.
152+
/// Must match SuperResolutionDesc::OutputWidth x SuperResolutionDesc::OutputWidthOutputHeight.
153153
ITextureView* pOutputTextureView DEFAULT_INITIALIZER(nullptr);
154154

155155
/// Exposure texture (shader resource view).
@@ -177,6 +177,11 @@ struct ExecuteSuperResolutionAttribs
177177
/// Format must be TEX_FORMAT_R8_UINT.
178178
ITextureView* pIgnoreHistoryMaskTextureSRV DEFAULT_INITIALIZER(nullptr);
179179

180+
/// Resource state transition mode.
181+
///
182+
/// Specifies whether the upscaler should perform resource state transitions for the input and output textures.
183+
RESOURCE_STATE_TRANSITION_MODE StateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
184+
180185
/// Jitter offset X applied to the projection matrix (in pixels).
181186
///
182187
/// Used for temporal upscaling.
@@ -294,7 +299,7 @@ DILIGENT_BEGIN_INTERFACE(ISuperResolution, IObject)
294299
///
295300
/// The command must be called outside of a render pass.
296301
/// All input textures must be in the appropriate states or
297-
/// TransitionMode should be set to RESOURCE_STATE_TRANSITION_MODE_TRANSITION.
302+
/// StateTransitionMode should be set to RESOURCE_STATE_TRANSITION_MODE_TRANSITION.
298303
///
299304
/// \remarks Supported contexts: graphics.
300305
VIRTUAL void METHOD(Execute)(THIS_

Graphics/SuperResolution/interface/SuperResolutionFactory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_TYPE, Uint8)
5555
SUPER_RESOLUTION_TYPE_TEMPORAL
5656
};
5757

58-
// Capability flags for spatial super resolution upscaling.
58+
/// Capability flags for spatial super resolution upscaling.
5959
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS, Uint32)
6060
{
61+
/// No special capabilities.
6162
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NONE = 0u,
6263

63-
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)
64+
/// The upscaler is a native hardware-accelerated implementation (e.g. DLSS, DirectSR, MetalFX)
6465
/// as opposed to a custom software fallback.
6566
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE = 1u << 0,
6667

@@ -76,6 +77,7 @@ DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS)
7677
/// Capability flags for temporal super resolution upscaling.
7778
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS, Uint32)
7879
{
80+
/// No special capabilities.
7981
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_NONE = 0u,
8082

8183
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)

Graphics/SuperResolution/src/DSRProviderD3D12.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,11 @@ void DILIGENT_CALL_TYPE SuperResolutionD3D12_DSR::Execute(const ExecuteSuperReso
230230
if (Attribs.ResetHistory)
231231
Flags |= DSR_SUPERRES_UPSCALER_EXECUTE_FLAG_RESET_HISTORY;
232232

233-
// Transition all textures to the states expected by DirectSR and flush the context.
234-
// DirectSR submits its own command list(s) to the command queue, so all rendering work must be submitted before DirectSR reads the inputs.
235233
// Input textures must be in D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, output must be in D3D12_RESOURCE_STATE_UNORDERED_ACCESS.
236-
pDeviceCtx->TransitionTextureState(Attribs.pColorTextureSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
237-
pDeviceCtx->TransitionTextureState(Attribs.pDepthTextureSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
238-
pDeviceCtx->TransitionTextureState(Attribs.pMotionVectorsSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
239-
pDeviceCtx->TransitionTextureState(Attribs.pOutputTextureView->GetTexture(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
240-
if (Attribs.pExposureTextureSRV)
241-
pDeviceCtx->TransitionTextureState(Attribs.pExposureTextureSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
242-
if (Attribs.pReactiveMaskTextureSRV)
243-
pDeviceCtx->TransitionTextureState(Attribs.pReactiveMaskTextureSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
244-
if (Attribs.pIgnoreHistoryMaskTextureSRV)
245-
pDeviceCtx->TransitionTextureState(Attribs.pIgnoreHistoryMaskTextureSRV->GetTexture(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
234+
TransitionResourceStates(Attribs, RESOURCE_STATE_UNORDERED_ACCESS);
235+
236+
// Flush the context.
237+
// DirectSR submits its own command list(s) to the command queue, so all rendering work must be submitted before DirectSR reads the inputs.
246238
pDeviceCtx->Flush();
247239

248240
if (HRESULT hr = pDSRUpscaler->Execute(&ExecuteParams, Attribs.TimeDeltaInSeconds, Flags); FAILED(hr))

Graphics/SuperResolution/src/FSRProvider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void SuperResolutionFSR::Execute(const ExecuteSuperResolutionAttribs& Attribs)
188188
ITextureView* pRTVs[] = {Attribs.pOutputTextureView};
189189
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
190190
pContext->SetPipelineState(m_pRCAS_PSO);
191-
pContext->CommitShaderResources(m_pRCAS_SRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
191+
pContext->CommitShaderResources(m_pRCAS_SRB, Attribs.StateTransitionMode);
192192
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
193193
}
194194

0 commit comments

Comments
 (0)