Rework color history in preparation for SSR (#4932)

This commit is contained in:
Ben Doherty
2021-12-08 13:35:54 -08:00
committed by GitHub
parent df42213daf
commit 9f75d34bb8
4 changed files with 45 additions and 8 deletions
+2 -7
View File
@@ -2177,19 +2177,17 @@ void PostProcessManager::prepareTaa(FrameHistory& frameHistory,
FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
FrameGraphId<FrameGraphTexture> input, FrameHistory& frameHistory,
FrameGraphId<FrameGraphTexture> colorHistory,
TemporalAntiAliasingOptions const& taaOptions,
ColorGradingConfig colorGradingConfig) noexcept {
FrameHistoryEntry const& entry = frameHistory[0];
FrameGraphId<FrameGraphTexture> colorHistory;
mat4f const* historyProjection = nullptr;
if (UTILS_UNLIKELY(!entry.color.handle)) {
if (UTILS_UNLIKELY(!colorHistory)) {
// if we don't have a history yet, just use the current color buffer as history
colorHistory = input;
historyProjection = &frameHistory.getCurrent().projection;
} else {
colorHistory = fg.import("TAA history", entry.colorDesc,
FrameGraphTexture::Usage::SAMPLEABLE, entry.color);
historyProjection = &entry.projection;
}
@@ -2296,9 +2294,6 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
colorGradingSubpass(driver, colorGradingConfig);
}
driver.endRenderPass();
// perform TAA here using colorHistory + input -> output
resources.detach(data.output, &current.color, &current.colorDesc);
});
return colorGradingConfig.asSubpass ? taa->tonemappedOutput : taa->output;
}
+1
View File
@@ -126,6 +126,7 @@ public:
FrameGraphId<FrameGraphTexture> taa(FrameGraph& fg,
FrameGraphId<FrameGraphTexture> input, FrameHistory& frameHistory,
FrameGraphId<FrameGraphTexture> colorHistory,
TemporalAntiAliasingOptions const& taaOptions,
ColorGradingConfig colorGradingConfig) noexcept;
+39 -1
View File
@@ -589,7 +589,25 @@ void FRenderer::renderJob(ArenaScope& arena, FView& view) {
// TAA for color pass
if (taaOptions.enabled) {
input = ppm.taa(fg, input, view.getFrameHistory(), taaOptions, colorGradingConfig);
input = ppm.taa(fg, input, view.getFrameHistory(),
getColorHistory(fg, view.getFrameHistory()), taaOptions, colorGradingConfig);
}
struct ExportColorHistoryData {
FrameGraphId<FrameGraphTexture> color;
};
if (taaOptions.enabled) {
fg.addPass<ExportColorHistoryData>("Export color history", [&](FrameGraph::Builder& builder,
auto& data) {
// We need to use sideEffect here to ensure this pass won't be culled. The "output" of
// this pass is going to be used during the next frame as an "import".
builder.sideEffect();
data.color = builder.sample(input);
}, [&view](FrameGraphResources const& resources, auto const& data, backend::DriverApi&) {
FrameHistory& frameHistory = view.getFrameHistory();
FrameHistoryEntry& current = frameHistory.getCurrent();
resources.detach(data.color, &current.color, &current.colorDesc);
});
}
// --------------------------------------------------------------------------------------------
@@ -1248,6 +1266,26 @@ void FRenderer::initializeClearFlags() {
| TargetBufferFlags::DEPTH_AND_STENCIL;
}
FrameGraphId<FrameGraphTexture> FRenderer::getColorHistory(FrameGraph& fg,
FrameHistory const& frameHistory) noexcept {
// Here we import the previous frame's color output and cache it in the blackboard. This ensures
// we only import it once per frame even across multiple calls to getColorHistory.
Blackboard& blackboard = fg.getBlackboard();
if (auto history = blackboard.get<FrameGraphTexture>("colorHistory")) {
return history;
}
FrameHistoryEntry const& entry = frameHistory[0];
if (UTILS_UNLIKELY(!entry.color.handle)) {
return {};
}
FrameGraphId<FrameGraphTexture> colorHistory = fg.import("Color history", entry.colorDesc,
FrameGraphTexture::Usage::SAMPLEABLE, entry.color);
blackboard["colorHistory"] = colorHistory;
return colorHistory;
}
// ------------------------------------------------------------------------------------------------
// Trampoline calling into private implementation
// ------------------------------------------------------------------------------------------------
+3
View File
@@ -187,6 +187,9 @@ private:
return clock::now() - getUserEpoch();
}
static FrameGraphId<FrameGraphTexture> getColorHistory(FrameGraph& fg,
FrameHistory const& frameHistory) noexcept;
// keep a reference to our engine
FEngine& mEngine;
FrameSkipper mFrameSkipper;