aboutsummaryrefslogtreecommitdiff
path: root/src/Renderer_DX12.h
blob: 724a6e622ca9612879cf2683359500b1d800b708 (plain) (blame)
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
/* 
* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved. 
* 
* NVIDIA CORPORATION and its licensors retain all intellectual property 
* and proprietary rights in and to this software, 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. 
*/

#pragma once
#include "Common.h"
#include "ConstantBuffers.h"
#include "InputDepthInfo.h"
#include "InputNormalInfo.h"
#include "OutputInfo.h"
#include "ProjectionMatrixInfo.h"
#include "RandomTexture.h"
#include "RenderOptions.h"
#include "RenderTargets_DX12.h"
#include "Shaders_DX12.h"
#include "PipelineStateObjects_DX12.h"
#include "States_DX12.h"
#include "TimestampQueries.h"
#include "BuildVersion.h"
#include "PerfMarkers.h"

namespace GFSDK
{
namespace SSAO
{

//--------------------------------------------------------------------------------
#if SUPPORT_D3D12
namespace D3D12
{

//--------------------------------------------------------------------------------
class Renderer : public GFSDK_SSAO_Context_D3D12
{
public:
    Renderer(GFSDK_SSAO_CustomHeap NewDelete)
        : m_NewDelete(NewDelete)
    {
    }

    //
    // API
    //

    GFSDK_SSAO_Status Create(
        ID3D12Device* pDevice, 
        GFSDK_SSAO_UINT NodeMask, 
        const GFSDK_SSAO_DescriptorHeaps_D3D12& DescriptorHeaps,
        GFSDK_SSAO_Version HeaderVersion);

    void Release();

    GFSDK_SSAO_Status PreCreateRTs(
        ID3D12CommandQueue* pCmdQueue,
        const GFSDK_SSAO_Parameters& Parameters,
        UINT ViewportWidth,
        UINT ViewportHeight);

     GFSDK_SSAO_Status GetProjectionMatrixDepthRange(
         const GFSDK_SSAO_InputData_D3D12& InputData,
         GFSDK_SSAO_ProjectionMatrixDepthRange& OutputDepthRange);

    GFSDK_SSAO_Status RenderAO(
        ID3D12CommandQueue* pCmdQueue,
        ID3D12GraphicsCommandList* pCmdList,
        const GFSDK_SSAO_InputData_D3D12& InputData,
        const GFSDK_SSAO_Parameters& Parameters,
        const GFSDK_SSAO_Output_D3D12& Output,
        GFSDK_SSAO_RenderMask RenderMask = GFSDK_SSAO_RENDER_AO);

    UINT GetAllocatedVideoMemoryBytes();

    //
    // Internals
    //

private:
    Generated::ShaderPermutations::RESOLVE_DEPTH GetResolveDepthPermutation()
    {
        return (m_InputDepth.Texture.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_FOREGROUND_AO GetEnableForegroundAOPermutation()
    {
        return (m_Options.EnableForegroundAO) ?     Generated::ShaderPermutations::ENABLE_FOREGROUND_AO_1 :
                                                    Generated::ShaderPermutations::ENABLE_FOREGROUND_AO_0;
    }
    Generated::ShaderPermutations::ENABLE_BACKGROUND_AO GetEnableBackgroundAOPermutation()
    {
        return (m_Options.EnableBackgroundAO) ?     Generated::ShaderPermutations::ENABLE_BACKGROUND_AO_1 :
                                                    Generated::ShaderPermutations::ENABLE_BACKGROUND_AO_0;
    }
    Generated::ShaderPermutations::ENABLE_DEPTH_THRESHOLD GetEnableDepthThresholdPermutation()
    {
        return (m_Options.EnableDepthThreshold) ?   Generated::ShaderPermutations::ENABLE_DEPTH_THRESHOLD_1 :
                                                    Generated::ShaderPermutations::ENABLE_DEPTH_THRESHOLD_0;
    }
    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;
    }

    const ShaderResourceView* GetFullResNormalBufferSRV()
    {
        return m_InputNormal.Texture.IsSet() ? &m_InputNormal.Texture.SRV : &m_RTs.GetFullResNormalTexture()->SRV;
    }

    const FLOAT* GetOutputBlendFactor()
    {
        return (m_Output.Blend.Mode == GFSDK_SSAO_CUSTOM_BLEND) ? m_Output.Blend.CustomState.pBlendFactor : NULL;
    }

    void CreateResources(GFSDK_D3D12_GraphicsContext* pD3DDevice);
    void ReleaseResources();

    void SetAOResolution(UINT Width, UINT Height);
    void SetAOResolution(const SSAO::InputViewport &Viewport);

    GFSDK_SSAO_Status SetDataFlow(
        const GFSDK_SSAO_InputData_D3D12& InputData,
        const GFSDK_SSAO_Parameters& Parameters,
        const GFSDK_SSAO_Output_D3D12& Output);

    GFSDK_SSAO_Status SetInputData(const GFSDK_SSAO_InputData_D3D12& InputData);
    GFSDK_SSAO_Status SetInputDepths(const GFSDK_SSAO_InputDepthData_D3D12& DepthData);
    GFSDK_SSAO_Status SetInputNormals(const GFSDK_SSAO_InputNormalData_D3D12& NormalData);
    GFSDK_SSAO_Status SetAOParameters(const GFSDK_SSAO_Parameters& Parameters);
    GFSDK_SSAO_Status SetOutput(const GFSDK_SSAO_Output_D3D12& Output);
    GFSDK_SSAO_Status ValidateDataFlow();

    void DrawLinearDepthPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawDeinterleavedDepthPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawReconstructedNormalPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawCoarseAOPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawReinterleavedAOPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawReinterleavedAOPS_PreBlur(GFSDK_D3D12_GraphicsContext* pGraphicsContext);

    void Render(GFSDK_D3D12_GraphicsContext* pGraphicsContext, GFSDK_SSAO_RenderMask RenderMask);
    void RenderHBAOPlus(GFSDK_D3D12_GraphicsContext* pGraphicsContext, GFSDK_SSAO_RenderMask RenderMask);

    void DrawBlurXPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawBlurYPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);
    void DrawDebugNormalsPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext);

    GFSDK::SSAO::D3D12::GlobalConstantBuffer m_GlobalCB;
    GFSDK::SSAO::D3D12::PerPassConstantBuffers m_PerPassCBs;
    GFSDK::SSAO::D3D12::InputDepthInfo m_InputDepth;
    GFSDK::SSAO::D3D12::InputNormalInfo m_InputNormal;
    GFSDK::SSAO::D3D12::OutputInfo m_Output;
    GFSDK::SSAO::D3D12::RenderTargets m_RTs;
    GFSDK::SSAO::D3D12::Shaders m_Shaders;
    GFSDK::SSAO::D3D12::States m_States;
    GFSDK::SSAO::D3D12::RandomTexture m_RandomTexture;
    GFSDK::SSAO::RenderOptions m_Options;
    GFSDK::SSAO::Viewports m_Viewports;
    ShaderResourceView m_FullResViewDepthSRV;
    GFSDK::SSAO::BuildVersion m_BuildVersion;
    GFSDK_SSAO_CustomHeap m_NewDelete;

    LinearDepthPSO m_LinearDepthPSO;
    DebugNormalsPSO m_DebugNormalsPSO;
    DeinterleavedDepthPSO m_DeinterleavedDepthPSO;
    ReconstructNormalPSO m_ReconstructNormalPSO;
    CoarseAOPSO m_CoarseAOPSO;
    ReinterleavedAOBlurPSO m_ReinterleavedAOBlurPSO;
    ReinterleavedAOPSO m_ReinterleavedAOPSO;
    BlurXPSO m_BlurXPSO;
    BlurYPSO m_BlurYPSO;

    GFSDK_D3D12_GraphicsContext m_GraphicsContext;
};

} // namespace D3D12
#endif // SUPPORT_D3D12

} // namespace SSAO
} // namespace GFSDK