1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
#pragma once
#include "Common.h"
#include "ConstantBuffers.h"
#include "InputDepthInfo.h"
#include "InputNormalInfo.h"
#include "OutputInfo.h"
#include "ProjectionMatrixInfo.h"
#include "RandomTexture.h"
#include "RenderTargets_DX11.h"
#include "Shaders_DX11.h"
#include "States_DX11.h"
#include "AppState_DX11.h"
#include "TimestampQueries.h"
#include "BuildVersion.h"
#include "PerfMarkers.h"
namespace GFSDK
{
namespace SSAO
{
//--------------------------------------------------------------------------------
#if SUPPORT_D3D11
namespace D3D11
{
class Renderer : public GFSDK_SSAO_Context_D3D11
{
public:
Renderer(GFSDK_SSAO_CustomHeap NewDelete)
: m_NewDelete(NewDelete)
{
}
//
// API
//
GFSDK_SSAO_Status Create(ID3D11Device* pD3DDevice, GFSDK_SSAO_Version HeaderVersion);
void Release();
GFSDK_SSAO_Status PreCreateRTs(
const GFSDK_SSAO_Parameters& Parameters,
UINT ViewportWidth,
UINT ViewportHeight);
GFSDK_SSAO_Status GetProjectionMatrixDepthRange(
const GFSDK_SSAO_InputData_D3D11& InputData,
GFSDK_SSAO_ProjectionMatrixDepthRange& OutputDepthRange);
GFSDK_SSAO_Status RenderAO(
ID3D11DeviceContext* pDeviceContext,
const GFSDK_SSAO_InputData_D3D11& InputData,
const GFSDK_SSAO_Parameters& Parameters,
const GFSDK_SSAO_Output_D3D11& Output,
GFSDK_SSAO_RenderMask RenderMask = GFSDK_SSAO_RENDER_AO);
UINT GetAllocatedVideoMemoryBytes();
//
// Internals
//
#if ENABLE_RENDER_TIMES
static GFSDK::SSAO::RenderTimes s_RenderTimes;
#endif
#if ENABLE_DEBUG_MODES
enum ShaderType
{
NVSDK_HBAO_PLUS_PS,
NVSDK_DEBUG_HBAO_PLUS_PS,
};
static ShaderType s_AOShaderType;
#endif
private:
Generated::ShaderPermutations::NUM_STEPS GetNumStepsPermutation()
{
return (m_Options.StepCount == GFSDK_SSAO_STEP_COUNT_4) ? Generated::ShaderPermutations::NUM_STEPS_4 :
Generated::ShaderPermutations::NUM_STEPS_8;
}
Generated::ShaderPermutations::DEPTH_LAYER_COUNT GetDepthLayerCountPermutation()
{
return (m_Options.EnableDualLayerAO) ? Generated::ShaderPermutations::DEPTH_LAYER_COUNT_2 :
Generated::ShaderPermutations::DEPTH_LAYER_COUNT_1;
}
Generated::ShaderPermutations::RESOLVE_DEPTH GetResolveDepthPermutation()
{
return (m_InputDepth.Texture0.SampleCount == 1) ? Generated::ShaderPermutations::RESOLVE_DEPTH_0 :
Generated::ShaderPermutations::RESOLVE_DEPTH_1;
}
Generated::ShaderPermutations::FETCH_GBUFFER_NORMAL GetFetchNormalPermutation()
{
return (!m_InputNormal.Texture.IsSet()) ? Generated::ShaderPermutations::FETCH_GBUFFER_NORMAL_0 :
(m_InputNormal.Texture.SampleCount == 1) ? Generated::ShaderPermutations::FETCH_GBUFFER_NORMAL_1 :
Generated::ShaderPermutations::FETCH_GBUFFER_NORMAL_2;
}
Generated::ShaderPermutations::ENABLE_BLUR GetEnableBlurPermutation()
{
return (m_Options.Blur.Enable) ? Generated::ShaderPermutations::ENABLE_BLUR_1 :
Generated::ShaderPermutations::ENABLE_BLUR_0;
}
Generated::ShaderPermutations::KERNEL_RADIUS GetBlurKernelRadiusPermutation()
{
return (m_Options.Blur.Radius == GFSDK_SSAO_BLUR_RADIUS_2) ? Generated::ShaderPermutations::KERNEL_RADIUS_2 :
Generated::ShaderPermutations::KERNEL_RADIUS_4;
}
Generated::ShaderPermutations::ENABLE_SHARPNESS_PROFILE GetEnableSharpnessProfilePermutation()
{
return (m_Options.Blur.SharpnessProfile.Enable) ? Generated::ShaderPermutations::ENABLE_SHARPNESS_PROFILE_1 :
Generated::ShaderPermutations::ENABLE_SHARPNESS_PROFILE_0;
}
ID3D11SamplerState*& GetAODepthSamplerState()
{
return (m_Options.DepthClampMode == GFSDK_SSAO_CLAMP_TO_EDGE) ? m_States.GetSamplerStatePointClamp() :
m_States.GetSamplerStatePointBorder();
}
ID3D11ShaderResourceView* GetFullResNormalBufferSRV()
{
return (m_InputNormal.Texture.IsSet()) ? m_InputNormal.Texture.pSRV : m_RTs.GetFullResNormalTexture()->pSRV;
}
ID3D11ShaderResourceView* GetFullResViewDepthTexture2SRV()
{
return m_Options.EnableDualLayerAO ? m_RTs.GetFullResViewDepthTexture2()->pSRV : NULL;
}
UINT GetOutputMSAASampleMask()
{
return D3D11_DEFAULT_SAMPLE_MASK;
}
ID3D11BlendState* GetOutputBlendState()
{
return
(m_Output.Blend.Mode == GFSDK_SSAO_OVERWRITE_RGB) ? m_States.GetBlendStateDisabledPreserveAlpha() :
(m_Output.Blend.Mode == GFSDK_SSAO_MULTIPLY_RGB) ? m_States.GetBlendStateMultiplyPreserveAlpha() :
m_Output.Blend.CustomState.pBlendState;
}
const FLOAT* GetOutputBlendFactor()
{
return (m_Output.Blend.Mode == GFSDK_SSAO_CUSTOM_BLEND) ? m_Output.Blend.CustomState.pBlendFactor : NULL;
}
ID3D11DepthStencilView* GetOutputDepthStencilView()
{
return m_Output.DepthStencilBuffer.pDSV;
}
ID3D11DepthStencilState* GetOutputDepthStencilState()
{
return (m_Output.DepthStencil.Mode == GFSDK_SSAO_CUSTOM_DEPTH_STENCIL) ? m_Output.DepthStencil.CustomState.pDepthStencilState : m_States.GetDepthStencilStateDisabled();
}
UINT GetOutputDepthStencilRef()
{
return (m_Output.DepthStencil.Mode == GFSDK_SSAO_CUSTOM_DEPTH_STENCIL) ? m_Output.DepthStencil.CustomState.StencilRef : 0;
}
void CreateResources(ID3D11Device* pD3DDevice);
void ReleaseResources();
void SetFullscreenState(ID3D11DeviceContext* pDeviceContext);
void SetAOResolution(UINT Width, UINT Height);
void SetAOResolution(const SSAO::InputViewport &Viewport);
GFSDK_SSAO_Status SetDataFlow(
const GFSDK_SSAO_InputData_D3D11& InputData,
const GFSDK_SSAO_Parameters& Parameters,
const GFSDK_SSAO_Output_D3D11& Output);
GFSDK_SSAO_Status SetInputData(const GFSDK_SSAO_InputData_D3D11& InputData);
GFSDK_SSAO_Status SetInputDepths(const GFSDK_SSAO_InputDepthData_D3D11& DepthData);
GFSDK_SSAO_Status SetInputNormals(const GFSDK_SSAO_InputNormalData_D3D11& NormalData);
GFSDK_SSAO_Status SetAOParameters(const GFSDK_SSAO_Parameters& Parameters);
GFSDK_SSAO_Status SetOutput(const GFSDK_SSAO_Output_D3D11& Output);
GFSDK_SSAO_Status ValidateDataFlow();
void DrawLinearDepthPS(ID3D11DeviceContext* pDeviceContext);
void DrawDeinterleavedDepthPS(ID3D11DeviceContext* pDeviceContext);
void DrawReconstructedNormalPS(ID3D11DeviceContext* pDeviceContext);
void DrawCoarseAOPS(ID3D11DeviceContext* pDeviceContext);
void DrawReinterleavedAOPS(ID3D11DeviceContext* pDeviceContext);
void DrawReinterleavedAOPS_PreBlur(ID3D11DeviceContext* pDeviceContext);
void Render(ID3D11DeviceContext* pDeviceContext, GFSDK_SSAO_RenderMask RenderMask);
void RenderHBAOPlus(ID3D11DeviceContext* pDeviceContext, GFSDK_SSAO_RenderMask RenderMask);
void DrawBlurXPS(ID3D11DeviceContext* pDeviceContext);
void DrawBlurYPS(ID3D11DeviceContext* pDeviceContext);
void DrawDebugNormalsPS(ID3D11DeviceContext* pDeviceContext);
#if ENABLE_DEBUG_MODES
void DrawFullResAOPS(ID3D11DeviceContext* pDeviceContext);
void RenderDebugAO(ID3D11DeviceContext* pDeviceContext);
GFSDK::SSAO::D3D11::RandomTexture m_RandomTexture;
#endif
GFSDK::SSAO::D3D11::GlobalConstantBuffer m_GlobalCB;
GFSDK::SSAO::D3D11::PerPassConstantBuffers m_PerPassCBs;
GFSDK::SSAO::D3D11::InputDepthInfo m_InputDepth;
GFSDK::SSAO::D3D11::InputNormalInfo m_InputNormal;
GFSDK::SSAO::D3D11::OutputInfo m_Output;
GFSDK::SSAO::D3D11::RenderTargets m_RTs;
GFSDK::SSAO::D3D11::Shaders m_Shaders;
GFSDK::SSAO::D3D11::States m_States;
GFSDK_SSAO_Parameters m_Options;
GFSDK::SSAO::Viewports m_Viewports;
GFSDK::SSAO::BuildVersion m_BuildVersion;
GFSDK_SSAO_CustomHeap m_NewDelete;
#if ENABLE_RENDER_TIMES
GFSDK::SSAO::D3D11::TimestampQueries m_TimestampQueries;
#endif
#if ENABLE_DEBUG_MODES
GFSDK::SSAO::D3D11::DebugShaders m_DebugShaders;
#endif
};
} // namespace D3D11
#endif // SUPPORT_D3D11
} // namespace SSAO
} // namespace GFSDK
|