Rework color history in preparation for SSR (#4932)
This commit is contained in:
@@ -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, ¤t.color, ¤t.colorDesc);
|
||||
});
|
||||
return colorGradingConfig.asSubpass ? taa->tonemappedOutput : taa->output;
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@ public:
|
||||
|
||||
FrameGraphId<FrameGraphTexture> taa(FrameGraph& fg,
|
||||
FrameGraphId<FrameGraphTexture> input, FrameHistory& frameHistory,
|
||||
FrameGraphId<FrameGraphTexture> colorHistory,
|
||||
TemporalAntiAliasingOptions const& taaOptions,
|
||||
ColorGradingConfig colorGradingConfig) noexcept;
|
||||
|
||||
|
||||
@@ -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, ¤t.color, ¤t.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
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user