Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

fix(engine): stacked NR produced a black frame; temporal pass only ever armed one layer

Veyra Goal Agent7a2be4b1d16d
diff --git a/include/veyra/pipeline/NrInstance.h b/include/veyra/pipeline/NrInstance.h
index 374a8974..8c85b49f 100644
--- a/include/veyra/pipeline/NrInstance.h
+++ b/include/veyra/pipeline/NrInstance.h
@@ -57,6 +57,12 @@ public:
ID3D12Resource* baseFull() const { return baseFull_; }
void setBaseFull(ID3D12Resource* resource) { baseFull_ = resource; }
ID3D12Resource* outputFull() const { return outputFull_.Get(); }
+ // The finished full-extent image for this layer: the graph's residual
+ // texture for the last layer, the layer's own otherwise. A downstream layer
+ // reads this rather than `outputFull()` so a stabilised layer hands on the
+ // temporal pass's result instead of the pre-stabilisation composite.
+ ID3D12Resource* fullTarget() const { return fullTarget_ ? fullTarget_ : outputFull_.Get(); }
+ void setFullTarget(ID3D12Resource* resource) { fullTarget_ = resource; }
uint32_t fullWidth() const { return fullWidth_; }
uint32_t fullHeight() const { return fullHeight_; }
ID3D12Resource* zeroDepth() const { return zeroDepth_; }
@@ -72,6 +78,11 @@ public:
engine::ResidualSettings residualSettings{};
engine::ProtectionSettings protection{};
bool temporalEnabled = false;
+ // Decided when views are created: this layer runs the temporal pass, so it
+ // composites into the pass's raw input and the pass writes the real target.
+ // False (the default, and the whole stack when the switch is off) keeps the
+ // direct-to-target path.
+ bool stabilised = false;
bool enabled = true;
// Bumped when an upstream layer's settings or output change. A layer whose
// input revision moved drops its history, the same contract Magpie's
@@ -82,6 +93,9 @@ public:
private:
ComPtr<ID3D12Resource> input_, proxy_, neural_, finalRgba_, residual_, outputFull_;
ID3D12Resource* baseFull_ = nullptr;
+ // Not owned: either this layer's `outputFull_` or the graph's residual
+ // texture. Set when views are created.
+ ID3D12Resource* fullTarget_ = nullptr;
uint32_t fullWidth_ = 0, fullHeight_ = 0;
bool inputIsBorrowed_ = false;
ID3D12Resource* zeroMotion_ = nullptr;
diff --git a/scripts/hash-ui-migration.ps1 b/scripts/hash-ui-migration.ps1
index eb9b783c..83c2acf9 100644
--- a/scripts/hash-ui-migration.ps1
+++ b/scripts/hash-ui-migration.ps1
@@ -6,7 +6,7 @@ param([string]$App = 'E:\项目\Veyra\tests\ui-qml-migration-20260925\app',
[string]$Baseline = 'E:\项目\Veyra\tests\ui-qml-migration-20260925\hash-baseline.json',
[string]$Out = 'E:\项目\Veyra\logs\ui-qml-migration-20260925\hash',
[int]$Frames = 24,
- [string[]]$Cases = @('passthrough','nr','nr-style2','nr-residual','nr-protect','nr-temporal','dlss-sr','vsr','sr-nr','nr-sr','vsr-nr','color','color-nr','nr2','nr3','nr4'),
+ [string[]]$Cases = @('passthrough','nr','nr-style2','nr-residual','nr-protect','nr-temporal','dlss-sr','vsr','sr-nr','nr-sr','vsr-nr','color','color-nr','nr2','nr3','nr2-temporal','nr4'),
[switch]$Record)
$env:TEMP = 'E:\项目\Veyra\tmp\ui-qml-migration-20260925'; $env:TMP = $env:TEMP
New-Item -ItemType Directory -Force $Out | Out-Null
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index c3286abd..824df787 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -301,8 +301,17 @@ bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)
nvofStandalone_ = desc.enableNvofStandalone && !desc.noFeatures;
if(desc.opticalFlowBackend==engine::OpticalFlowBackend::AmdFidelityFx&&desc.amdFlowHalfResolution){nvofW_=std::max(1u,nvofW_/2);nvofH_=std::max(1u,nvofH_/2);}
uint64_t budget=0,usage=0;
- const uint64_t temporalBytes=desc_.nrTemporal?uint64_t(desc_.nrBeforeSr?srcW_:workW_)*(desc_.nrBeforeSr?srcH_:workH_)*40:0;
- const uint64_t estimate=uint64_t(workW_)*workH_*(fgEnabled_?100:76)+uint64_t(nrW_)*nrH_*32+uint64_t(srcW_)*srcH_*32+temporalBytes;
+ // Every NR layer allocates its own full set of textures, and a stabilised
+ // layer adds two history/guide pairs on top. The stack is bounded (16 nodes),
+ // so a deep chain can genuinely exhaust a small adapter; the estimate has to
+ // count the layers or the check would pass and allocation would fail later.
+ const uint64_t nrStackLayers=uint64_t(std::max<size_t>(1,desc_.nrLayersModel.size()));
+ const uint64_t temporalLayers=uint64_t(desc_.nrTemporal?std::max<size_t>(1,desc_.nrLayersTemporal.size()):0);
+ const uint64_t layerExtent=uint64_t(desc_.nrBeforeSr?srcW_:workW_)*(desc_.nrBeforeSr?srcH_:workH_);
+ const uint64_t temporalBytes=temporalLayers*layerExtent*40;
+ const uint64_t estimate=uint64_t(workW_)*workH_*(fgEnabled_?100:76)
+ +nrStackLayers*(uint64_t(nrW_)*nrH_*16+layerExtent*8)
+ +uint64_t(srcW_)*srcH_*32+temporalBytes;
if(context_.videoMemoryInfo(budget,usage)){
veyra::log::info("memory",std::format("graph lower-bound={}MiB budget={}MiB usage={}MiB; SDK allocations additional",estimate>>20,budget>>20,usage>>20));
if(usage>=budget||estimate>budget-usage){veyra::log::error("memory","insufficient adapter budget for requested graph textures");return false;}
@@ -1148,7 +1157,7 @@ bool EnhanceGraph::createComputePasses()
{
const UINT residualLayers=UINT(std::max<size_t>(1,nrInstances_.size()));
if(!residualPass_.loadShader("NrResidualComposite.dxil",cs)||
- !residualPass_.create(context_.device(),cs,3*residualLayers+1,3*residualLayers,1,24))return false;
+ !residualPass_.create(context_.device(),cs,4*residualLayers,3*residualLayers,residualLayers,24))return false;
}
if(!flowAdaptPass_.loadShader("FlowAdapt.dxil",cs)||!flowAdaptPass_.create(context_.device(),cs,3,1,1))return false;
if (!yuvPass_.loadShader("YuvToLinearRgb.dxil", cs) || !yuvPass_.create(context_.device(), cs, 12, 2, 1, 12+kColorGradeConstantCount, 4)) return false;
@@ -1223,7 +1232,7 @@ bool EnhanceGraph::createViews()
const UINT k = UINT(layerIndex);
ID3D12Resource* source = layerIndex == 0
? (desc_.nrBeforeSr ? srcRgba_.Get() : workRgba_.Get())
- : nrInstances_[layerIndex - 1]->outputFull();
+ : nrInstances_[layerIndex - 1]->fullTarget();
stagedSrv(source, DXGI_FORMAT_R16G16B16A16_FLOAT, downsamplePass_, 2 * k);
if (!layer->inputIsBorrowed()) {
makeUav(context_.device(), layer->input(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(downsamplePass_, 2 * layers + 2 * k));
@@ -1232,25 +1241,53 @@ bool EnhanceGraph::createViews()
}
// The residual composite runs once per layer. Layer 0 keeps the original
// slot triple (base, NR input, decoded output); every later layer owns the
- // group starting at 1+3k, whose base is the previous layer's result.
+ // group starting at 3k, whose base is the previous layer's finished result.
+ //
+ // Each layer also needs its OWN output descriptor. A single shared u0 meant
+ // every layer's composite landed in the same texture while the barrier after
+ // it named a different resource: layer 1 read a texture nothing had written,
+ // which is what turned a two-layer stack black.
for(size_t layerIndex=0;layerIndex<nrInstances_.size();++layerIndex){
const UINT k=UINT(layerIndex);
// The shader reads base (t0), the NR-extent input (t1) and the neural
// result (t2); the heap keeps those three per layer, in order.
ID3D12Resource* base=layerIndex==0
?(desc_.nrBeforeSr?srcRgba_.Get():workRgba_.Get())
- :nrInstances_[layerIndex-1]->outputFull();
+ :nrInstances_[layerIndex-1]->fullTarget();
stagedSrv(base,DXGI_FORMAT_R16G16B16A16_FLOAT,residualPass_,3*k+0);
stagedSrv(nrInstances_[layerIndex]->input(),DXGI_FORMAT_R16G16B16A16_FLOAT,residualPass_,3*k+1);
stagedSrv(nrInstances_[layerIndex]->finalRgba(),DXGI_FORMAT_R16G16B16A16_FLOAT,residualPass_,3*k+2);
}
- // Temporal stabilisation belongs to a layer; the graph keeps none of its own
- // once the stack exists, so the last layer's chain writes the final target.
- if(nrLayerCount_==1&&desc_.nrTemporal&&!nrInstances_.empty()&&
- !nrInstances_.front()->temporal().initialize(context_.device(),desc_.nrBeforeSr?srcRgba_.Get():workRgba_.Get(),flowTex_.Get(),residualRgba_.Get()))return false;
+ // Temporal stabilisation belongs to a layer, and its output is that layer's
+ // composite target: what the residual pass writes, what the next layer reads,
+ // and — for the last layer — what the output blit consumes. Initialising it
+ // with the residual target keeps one destination per layer; a previous
+ // version only ever initialised the single-layer case, so turning the switch
+ // on in a stacked chain did nothing at all.
{
- const UINT residualLayers=UINT(std::max<size_t>(1,nrInstances_.size()));
- makeUav(context_.device(),(nrLayerCount_==1&&desc_.nrTemporal&&!nrInstances_.empty())?nrInstances_.front()->temporal().raw():residualRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,cpu(residualPass_,3*residualLayers));
+ const UINT residualLayers = UINT(std::max<size_t>(1, nrInstances_.size()));
+ for (size_t layerIndex = 0; layerIndex < nrInstances_.size(); ++layerIndex) {
+ auto* layer = nrInstances_[layerIndex].get();
+ const bool last = layerIndex + 1 == nrInstances_.size();
+ // A stabilised layer composites into the temporal pass's raw input;
+ // the pass then writes the layer's full-extent target. Either way
+ // `fullTarget()` is the finished image the next layer reads.
+ layer->stabilised = layer->temporalEnabled;
+ ID3D12Resource* target = last ? residualRgba_.Get() : layer->outputFull();
+ layer->setFullTarget(target);
+ ID3D12Resource* base = layerIndex == 0
+ ? (desc_.nrBeforeSr ? srcRgba_.Get() : workRgba_.Get())
+ : nrInstances_[layerIndex - 1]->fullTarget();
+ // Initialisation MUST come before the descriptor write: it is what
+ // allocates the raw input the descriptor names. Writing the
+ // descriptor first bound a null resource, so the composite went
+ // nowhere and the final texture was never touched.
+ if (layer->stabilised &&
+ !layer->temporal().initialize(context_.device(), base, flowTex_.Get(), target)) return false;
+ makeUav(context_.device(),
+ layer->stabilised ? layer->temporal().raw() : target,
+ DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(residualPass_, 3 * residualLayers + UINT(layerIndex)));
+ }
}
stagedSrv(flowTex_.Get(),DXGI_FORMAT_R16G16_FLOAT,flowAdaptPass_,0);
makeUav(context_.device(),nrFlow_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowAdaptPass_,1));
@@ -2060,7 +2097,11 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
auto* layer=nrInstances_[layerIndex].get();
if(layer->handle()==nullptr||!layer->enabled)continue;
const bool last=(layerIndex+1==nrInstances_.size());
- const bool temporallyStabilised=last&&nrLayerCount_==1&&desc_.nrTemporal;
+ // A stabilised layer composites into the temporal pass's raw input
+ // (the pass then writes the real target); otherwise it writes the
+ // target directly. A stacked chain with the switch off keeps the
+ // byte-exact single-layer behaviour because no layer is stabilised.
+ const bool temporallyStabilised=layer->stabilised;
ID3D12Resource* destination=temporallyStabilised?layer->temporal().raw():(last?residualRgba_.Get():layer->outputFull());
const auto& r=layer->residualSettings;
const auto& protection=layer->protection;
@@ -2069,7 +2110,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
for(size_t i=0;i<4;++i){const auto q=protection.regions[i];c[8+i*4]=q.left;c[9+i*4]=q.top;c[10+i*4]=q.right;c[11+i*4]=q.bottom;}
const UINT residualLayers=UINT(std::max<size_t>(1,nrInstances_.size()));
residualPass_.bind(list,c,gpuHandleOf(residualPass_,3u*UINT(layerIndex)).ptr,
- gpuHandleOf(residualPass_,3u*residualLayers).ptr);
+ gpuHandleOf(residualPass_,3u*residualLayers+UINT(layerIndex)).ptr);
list->Dispatch(((desc_.nrBeforeSr?srcW_:workW_)+15)/16,((desc_.nrBeforeSr?srcH_:workH_)+15)/16,1);
tracker_.uavBarrier(list,destination);
tracker_.transition(list,destination,D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
diff --git a/src/pipeline/NrInstance.cpp b/src/pipeline/NrInstance.cpp
index 0031a01b..9fcec8f9 100644
--- a/src/pipeline/NrInstance.cpp
+++ b/src/pipeline/NrInstance.cpp
@@ -45,6 +45,7 @@ void NrInstance::close() {
residual_.Reset();
outputFull_.Reset();
baseFull_ = nullptr;
+ fullTarget_ = nullptr;
zeroMotion_ = zeroDepth_ = nullptr;
handle_ = nullptr;
parameters_ = nullptr;
diff --git a/tools/chain_hash_probe/main.cpp b/tools/chain_hash_probe/main.cpp
index c5b22bb1..ab42d1f6 100644
--- a/tools/chain_hash_probe/main.cpp
+++ b/tools/chain_hash_probe/main.cpp
@@ -89,6 +89,22 @@ bool configure(const std::string& name, uint32_t w, uint32_t h, pipeline::Enhanc
gd.protection.regions[0] = {.05f, .05f, .30f, .20f}; return true;
}
if (name == "nr-temporal") { nr(); gd.nrTemporal = true; return true; }
+ // Two layers with the per-layer switch on both: this is the combination the
+ // single-layer-only initialisation silently ignored (the switch did nothing
+ // once a chain had more than one layer).
+ if (name == "nr2-temporal") {
+ nr();
+ for (int n = 0; n < 2; ++n) {
+ engine::NrSettings model; model.intensity = 1.0f - 0.2f * float(n);
+ model.tone = 1.0f; model.structure = 1.0f; model.skin = -1.0f;
+ gd.nrLayersModel.push_back(model);
+ gd.nrLayersResidual.push_back(engine::ResidualSettings{});
+ gd.nrLayersTemporal.push_back(true);
+ gd.nrLayersProtection.push_back(engine::ProtectionSettings{});
+ }
+ gd.nrTemporal = true;
+ return true;
+ }
if (name == "dlss-sr") { sr(0); return true; }
if (name == "vsr") { sr(3); return true; }
if (name == "sr-nr") { sr(0); nr(); return true; }
@@ -107,7 +123,7 @@ bool configure(const std::string& name, uint32_t w, uint32_t h, pipeline::Enhanc
int main() {
const auto args = utf8Arguments();
- std::string input, caseName, outPath;
+ std::string input, caseName, outPath, dumpDir;
int frames = 24;
for (size_t i = 1; i < args.size(); ++i) {
auto next = [&] { return i + 1 < args.size() ? args[++i] : std::string(); };
@@ -115,6 +131,7 @@ int main() {
else if (args[i] == "--case") caseName = next();
else if (args[i] == "--frames") frames = std::stoi(next());
else if (args[i] == "--out") outPath = next();
+ else if (args[i] == "--dump-edge") dumpDir = next();
else { std::fprintf(stderr, "unknown arg %s\n", args[i].c_str()); return 2; }
}
if (input.empty() || caseName.empty() || frames <= 0) {
@@ -150,6 +167,12 @@ int main() {
if (!graph.initialize(gd) || !graph.createViews()) { std::fprintf(stderr, "graph init failed\n"); return 1; }
std::vector<std::string> hashes;
+ // Temporal-stability metric for the anti-flicker question: the mean absolute
+ // frame-to-frame change of the output. Lower means a steadier picture. It is
+ // computed on the same frames the hashes cover, so the two agree.
+ double temporalDeltaSum = 0.0;
+ double temporalDeltaPixels = 0.0;
+ std::vector<uint8_t> previousFrame;
bool reset = true;
for (int n = 0; n < frames; ++n) {
pipeline::FramePacket packet;
@@ -167,14 +190,29 @@ int main() {
return 1;
}
hashes.push_back(sha256Hex(image.pixels.data(), image.pixels.size()));
+ if (!dumpDir.empty()) {
+ // Raw RGBA8, one file per frame: lets a companion script measure how
+ // many pixels a stage actually changes, which a hash cannot show.
+ std::ofstream f(widen(std::format("{}/frame{:03d}_{}x{}.rgba", dumpDir, n, image.width, image.height)),
+ std::ios::binary);
+ f.write(reinterpret_cast<const char*>(image.pixels.data()), std::streamsize(image.pixels.size()));
+ }
+ if (!previousFrame.empty() && previousFrame.size() == image.pixels.size()) {
+ double sum = 0.0;
+ for (size_t i = 0; i < image.pixels.size(); ++i) sum += std::abs(int(image.pixels[i]) - int(previousFrame[i]));
+ temporalDeltaSum += sum / double(image.pixels.size());
+ temporalDeltaPixels += 1.0;
+ }
+ previousFrame = image.pixels;
}
(void)ring.waitIdle();
graph.shutdown();
- std::string json = std::format("{{\"case\":\"{}\",\"frames\":{},\"source\":\"{}x{}\",\"displayAspect\":{:.4f},\"rotation\":{},\"duration\":{:.3f},\"work\":\"{}x{}\",\"nr\":\"{}x{}\",\"hashes\":[",
+ std::string json = std::format("{{\"case\":\"{}\",\"frames\":{},\"source\":\"{}x{}\",\"displayAspect\":{:.4f},\"rotation\":{},\"duration\":{:.3f},\"work\":\"{}x{}\",\"nr\":\"{}x{}\",\"meanFrameDelta\":{:.4f},\"hashes\":[",
caseName, hashes.size(), info.width, info.height, info.displayAspect,
info.rotationDegrees, info.duration.toDouble(),
- graph.workWidth(), graph.workHeight(), graph.nrWidth(), graph.nrHeight());
+ graph.workWidth(), graph.workHeight(), graph.nrWidth(), graph.nrHeight(),
+ temporalDeltaPixels > 0 ? temporalDeltaSum / temporalDeltaPixels : 0.0);
for (size_t n = 0; n < hashes.size(); ++n) json += (n ? ",\"" : "\"") + hashes[n] + "\"";
json += "]}\n";
std::fputs(json.c_str(), stdout);