-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathvrsrendermodule.h
More file actions
206 lines (177 loc) · 7.28 KB
/
vrsrendermodule.h
File metadata and controls
206 lines (177 loc) · 7.28 KB
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
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "core/contentmanager.h"
#include "render/rendermodule.h"
#include <FidelityFX/host/ffx_vrs.h>
#include <vector>
namespace cauldron
{
class RootSignature;
class RasterView;
class ParameterSet;
class PipelineObject;
class RenderTarget;
class Texture;
class ResourceView;
}
/// @defgroup FfxVrsSample FidelityFX VRS sample
/// Sample documentation for FidelityFX VRS
///
/// @ingroup SDKEffects
/// @defgroup VrsRM VrsRenderModule
/// VrsRenderModule Reference Documentation
///
/// @ingroup FfxVrsSample
/// @{
/**
* @class VRSRenderModule
*
* VRSRenderModule takes care of:
* - querying hardware VRS support
* - generating motion vectors of current frame
* - generating VRS image based on motion vectors and history color buffer
* - copying color buffer into history color buffer
* - displaying overlay of VRS image
* - setting VRS options
*/
class VRSRenderModule : public cauldron::RenderModule, public cauldron::ContentListener
{
public:
/**
* @brief Constructor
*/
VRSRenderModule();
/**
* @brief Destructor
*/
virtual ~VRSRenderModule();
/**
* This function checks hardware VRS suppport, builds user interface, creates GPU resources, sets up
* callback functions and initializes ffx_vrs backend.
*/
void Init(const json& initData) override;
/**
* Recreate the FFX API context to resize internal resources. Called by the framework when the resolution changes.
* @param resInfo New resolution info.
*/
void OnResize(const cauldron::ResolutionInfo& resInfo) override;
/**
* Calls ExecuteVRSImageGen to dipatch computer shader to generate VRS image.
*/
virtual void Execute(double deltaTime, cauldron::CommandList* pCmdList) override;
/**
* Creates pipeline object and sets up surface information for each mesh to be rendered in velocity pass.
*/
virtual void OnNewContentLoaded(cauldron::ContentBlock* pContentBlock) override;
/**
* @copydoc ContentListener::OnContentUnloaded()
*/
virtual void OnContentUnloaded(cauldron::ContentBlock* pContentBlock) override;
private:
void BuildUI();
void InitOverlay(const json& initData);
void InitMotionVectors(const json& initData);
void InitFfxBackend();
void InitFfxContext();
void DestroyFfxContext();
/**
* This callback function copies color buffer of current frame into HistoryColorBuffer
* to be used for next frame to generate VRS image.
*/
void CopyColorBufferCallback(double deltaTime, cauldron::CommandList* pCmdList);
/**
* This callback function draws VRS image over rendered scene.
*/
void DrawOverlayCallback(double deltaTime, cauldron::CommandList* pCmdList);
/**
* This callback function generates motion vector for each pixel. The motion vector
* will be used to determine on-screen position of a pixel in the last frame.
*/
void GenerateMotionVectorsCallback(double deltaTime, cauldron::CommandList* pCmdList);
void ToggleVariableShading();
void ToggleShadingRateImage();
void ToggleOverlay();
void SelectBaseShadingRate();
void SelectCombiner();
void UpdateVRSInfo();
void UpdateVRSContext(bool enabled);
void ExecuteVRSImageGen(double deltaTime, cauldron::CommandList* pCmdList);
// Content creation helpers - not thread safe
uint32_t CreatePipelineObject(const cauldron::Surface* pSurface);
bool m_EnableVariableShading = false;
uint32_t m_ShadingRateIndex = 0;
uint32_t m_ShadingRateCombinerIndex = 0;
bool m_EnableShadingRateImage = false;
uint32_t m_ShadingRateImageAlgorithmIndex = 0;
bool m_AllowAdditionalShadingRates = false;
uint32_t m_VRSTierSupported = 0;
float m_VRSThreshold = 0.015f;
float m_VRSMotionFactor = 0.01f;
FfxFloatCoords2D m_VRSFoveationCenter{0.5f, 0.5f};
FfxVrsFovRadii m_VRSFovRadii{0.2f, 0.3f, 0.4f, 0.5f};
bool m_VariableShadingEnabled = false;
bool m_ShadingRateImageEnabled = false;
std::vector<cauldron::ShadingRateCombiner> m_AvailableCombiners;
cauldron::FeatureInfo_VRS m_FeatureInfoVRS;
const cauldron::Texture* m_pMotionVectors = nullptr;
const cauldron::Texture* m_pDepthTarget = nullptr;
const cauldron::Texture* m_pColorTarget = nullptr;
const cauldron::Texture* m_pHistoryColorBuffer = nullptr;
const cauldron::Texture* m_pVRSTexture = nullptr;
// FidelityFX VRS information
FfxVrsContextDescription m_InitializationParameters = {};
FfxVrsContext m_VRSContext;
bool m_ContextCreated = false;
// Motion Vectors
bool m_GenerateMotionVectors = false;
cauldron::RootSignature* m_pMotionVectorsRootSignature = nullptr;
cauldron::ParameterSet* m_pMotionVectorsParameterSet = nullptr;
const cauldron::RasterView* m_pMotionVectorsRasterView = nullptr;
const cauldron::RasterView* m_pDepthRasterView = nullptr;
std::mutex m_CriticalSection;
struct PipelineSurfaceRenderInfo
{
const cauldron::Entity* pOwner = nullptr;
const cauldron::Surface* pSurface = nullptr;
};
struct PipelineHashObject
{
cauldron::PipelineObject* m_Pipeline = nullptr;
uint64_t m_PipelineHash = 0;
};
std::vector<PipelineHashObject> m_PipelineHashObjects;
struct MotionVectorsRenderData
{
PipelineSurfaceRenderInfo m_RenderSurface = {};
cauldron::PipelineObject* m_Pipeline = nullptr;
};
std::vector<MotionVectorsRenderData> m_MotionVectorsRenderSurfaces;
// Overlay
cauldron::RootSignature* m_pOverlayRootSignature = nullptr;
const cauldron::RasterView* m_pOverlayRasterView = nullptr;
cauldron::PipelineObject* m_pOverlayPipelineObj = nullptr;
const cauldron::Texture* m_pOverlayRenderTarget = nullptr;
cauldron::ParameterSet* m_pOverlayParameters = nullptr;
bool m_DrawOverlay = false;
/// @}
};