From 2bb50f29cb85bdd54221e2229ad14ba80e772d43 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:24:17 -0500 Subject: [PATCH 1/4] B8: a refused frame always has an explicit result; the front end is tested against the real backend The front end's refused-frame contract (clean/fsr/src/frontend.cpp) is explicit for every model: WrongGPU's upscaler, then the stand-in, then AMD's FSR, and last, when none of them could upscale the frame (the stand-in cannot be made or fails, AMD's FSR is missing or its dispatch fails, including for a context WrongGPU already handed to AMD), the game's own colour is copied into the output unscaled (new passthrough_d3d12.cpp, Platform::passThrough) with one warning line, and the game gets FFX_API_RETURN_OK instead of an error with no output. When that is impossible too the error goes back with one line saying why, as before; an OptiScaler custom slot keeps getting the error (its host upscales). Tests: test_frontend.cpp covers each failure case for models M, K and L. New test_refusal_integration.cpp drives refused frames through the REAL network backend (the runtime DLL's Context) and the real front end on a D3D12 device, with a scripted executor (executor=dx12-test, executor_test.cpp) standing in for the D3D12 executor: K and the M control, with and without AMD's FSR, repeated refusals, the stand-in working and not, the real pass-through checked on the output's pixels, and no HIP runtime ever loaded. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/CMakeLists.txt | 2 +- clean/fsr/README.md | 12 +- clean/fsr/src/frontend.cpp | 131 ++++++- clean/fsr/src/frontend.h | 12 + clean/fsr/src/passthrough_d3d12.cpp | 100 ++++++ clean/fsr/src/passthrough_d3d12.h | 12 + clean/fsr/src/win_util.h | 11 + clean/fsr/tests/test_frontend.cpp | 120 ++++++- clean/fsr/tests/test_refusal_integration.cpp | 340 +++++++++++++++++++ clean/runtime/interop/backend.cpp | 18 +- clean/runtime/interop/executor.h | 5 + clean/runtime/interop/executor_select.h | 2 +- clean/runtime/interop/executor_test.cpp | 47 +++ 13 files changed, 788 insertions(+), 24 deletions(-) create mode 100644 clean/fsr/src/passthrough_d3d12.cpp create mode 100644 clean/fsr/src/passthrough_d3d12.h create mode 100644 clean/fsr/tests/test_refusal_integration.cpp diff --git a/clean/fsr/CMakeLists.txt b/clean/fsr/CMakeLists.txt index 0f5af475..bbb7690e 100644 --- a/clean/fsr/CMakeLists.txt +++ b/clean/fsr/CMakeLists.txt @@ -172,7 +172,7 @@ if(WIN32) endif() # Windows parts shared by the three DLLs: settings, loading AMD's originals, D3D12 queries, the stand-in. - add_library(wg_fsr_win STATIC src/win_util.cpp src/standin_d3d12.cpp src/d3d12_hooks.cpp src/statistics_query.cpp src/split_progress.cpp src/overlay.cpp src/asi_bridge.cpp + add_library(wg_fsr_win STATIC src/win_util.cpp src/standin_d3d12.cpp src/passthrough_d3d12.cpp src/d3d12_hooks.cpp src/statistics_query.cpp src/split_progress.cpp src/overlay.cpp src/asi_bridge.cpp src/settings_bridge.cpp) if(WG_SPLIT_PROGRESS_QA) target_compile_definitions(wg_fsr_win PRIVATE WRONGGPU_SPLIT_PROGRESS_QA=1) diff --git a/clean/fsr/README.md b/clean/fsr/README.md index 278cff08..18f99bce 100644 --- a/clean/fsr/README.md +++ b/clean/fsr/README.md @@ -269,7 +269,17 @@ OptiScaler folder ships `amd_fidelityfx_upscaler_dx12.dll`; OptiScaler.ini `[Lib - **Frames the upscaler does not take:** `WG_ERROR_UNSUPPORTED` from the upscaler's dispatch (the network runtime with `hip_switch=off`, its default since 2026-11-04: frames above the render size checked at create) hands the context to AMD's FSR at once; - without AMD's FSR the stand-in upscales such frames. + without AMD's FSR the stand-in upscales such frames. This is one contract for every model (K refused frames take exactly + model M's path), and what a frame gets is explicit (B8): WrongGPU's upscaler, then the stand-in, then AMD's FSR, and last, + when none of them could upscale it (the stand-in cannot be made or fails, AMD's FSR is missing or its dispatch fails), the + game's own colour is copied into the output unscaled (`passthrough_d3d12.cpp`: the active region, cut to both textures, at + the output's origin; the same format family is needed) with one warning line, and the game gets `FFX_API_RETURN_OK`, never + an error for a frame whose textures can be copied. When even that is impossible (no command list, another format family) + the error goes back with one line saying why, as before; in OptiScaler's custom slot the error always goes back (its host + upscales). `tests/test_frontend.cpp` covers each failure case for models M, K and L; `tests/test_refusal_integration.cpp` + drives refused frames through the real network backend (the runtime DLL's `Context`, with the scripted executor + `executor=dx12-test`) and the real front end on a D3D12 device (WARP is enough), with and without AMD's FSR, the stand-in + working and not, checks the copied pixels, and that no HIP runtime is ever loaded. - **Model location:** the front end looks for the converted model (`model.wgcm`, Model K in `K\`) in `[fsr] model_dir` of `wronggpu.ini` (relative: from the data folder), then `\WrongGPU\model`, and passes the first folder that has it to the runtime as `model_dir=`; otherwise the runtime's own default (`%LOCALAPPDATA%\WrongGPU\model`, diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index ace7a686..232f8437 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -58,6 +58,7 @@ struct FrontEnd::UpscaleContext { bool amdLast = false; // the last frame was one of AMD's FSR for such a frame (AMD's history continues) bool broken = false; // the upscaler failed for good: it is not parked uint64_t brokenFrames = 0; // bug hunt F1: frames since the upscaler failed for good (it is not called again) + uint64_t passThroughFrames = 0; // B8: frames of this context that were passed through unscaled (nothing could upscale them) uint32_t resizes = 0; // bug hunt H: upscalers created again for the frames' output size (Config::maxOutputResizes) bool resizeFailed = false; // ... and such a create failed: no more attempts for this context // Issue #58: upscalers and stand-ins a resize replaced. Command lists the game recorded before may still use them @@ -948,6 +949,75 @@ bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend return false; } +// B8: the last step of the refused-frame contract. Nothing upscaled this frame (the upscaler refused it, the stand-in could +// not be made or failed, AMD's FSR is missing or failed): the game's own colour is copied into the output unscaled +// (Platform::passThrough) and the game gets FFX_API_RETURN_OK with one warning line (LogPoint counts), instead of an error and +// an output nobody wrote. False when that is impossible too (the reason is logged), or in OptiScaler's custom slot, whose +// host upscales a frame the upscaler answers an error for. +bool FrontEnd::PassThroughFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what) { + if (config_.customSlot) return false; + std::string why; + bool ok = false; + uint32_t w = 0, h = 0; + if (!frame) { + why = "the frame's inputs could not be read"; + } else if (!platform_.passThrough) { + why = "this platform has no pass-through"; + } else { + WgFrame f = *frame; + if (!UsableForStandIn(f)) { + why = "the frame has no command list, colour texture or output texture"; + } else { + w = f.render_width < f.output_width ? f.render_width : f.output_width; + h = f.render_height < f.output_height ? f.render_height : f.output_height; + ok = platform_.passThrough(f, &why); + } + } + const uint64_t n = ++u.passThroughFrames; + if (ok) { + if ((n == 1 || n >= 10) && LogPoint(n)) // one line, then at 10, 100, ... + Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + + "; nothing upscaled it: the game's own colour is passed through to the output unscaled (" + std::to_string(w) + "x" + + std::to_string(h) + ", " + std::to_string(n) + " such frame(s) in this context)"); + Report(u, UpscaleState::Failed, frame, "frame passed through unscaled: " + what); + return true; + } + if ((n == 1 || n >= 10) && LogPoint(n)) // one line, then at 10, 100, ... + Log(tag + " ERROR U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + + "; nothing upscaled it and it cannot be passed through (" + why + ")"); + return false; +} + +// B8: AMD's FSR was asked for this frame and its dispatch failed (rc). The stand-in is tried, then the pass-through; if both +// fail (or in a custom slot) AMD's own error goes back, as before. +ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc) { + const std::string what = "AMD FSR dispatch failed (" + std::string(RcName(rc)) + ")"; + if (frame && !config_.customSlot) { + WgFrame f = *frame; + if (UsableForStandIn(f)) { + if (!u.fallbackBackend && platform_.standIn) u.fallbackBackend = platform_.standIn(config_); + if (u.fallbackBackend && u.fallbackBackend != u.backend) { + if (!u.fallback) { + WgCreateInfo info = u.createInfo; + AdaptCreateInfo(u.fallbackBackend, nullptr, info); + if (u.fallbackBackend->create(&info, &u.fallback) != WG_OK) u.fallback = nullptr; + } + AdaptFrame(u.fallbackBackend, f); + if (u.fallback && u.fallbackBackend->dispatch(u.fallback, &f) == WG_OK) { + Log(tag + " note U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + "; the stand-in upscales it"); + u.resetNext = true; + if (platform_.afterDispatch) platform_.afterDispatch(f, true); + Report(u, UpscaleState::StandIn, &f); + return FFX_API_RETURN_OK; + } + } + } + u.resetNext = true; + if (PassThroughFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; + } + return rc; +} + // Bug hunt F1 (a): the upscaler failed for good (u.broken) and AMD's FSR did not take the context over (none, or // fallback_to_amd = 0): it is not called again (each call would fail and log again, every frame). In OptiScaler's custom // slot the error goes back to the host, which makes a new context (Dispatch's run of failures decides when that stops); @@ -973,6 +1043,7 @@ ffxReturnCode_t FrontEnd::BrokenFrame(UpscaleContext& u, WgFrame& frame, const s } } } + if (PassThroughFrame(u, tag, frameIndex, &frame, what)) return FFX_API_RETURN_OK; // B8: never no output if (LogPoint(n)) Log(tag + " ERROR U" + std::to_string(u.id) + ": " + what + " -> ERROR_RUNTIME_ERROR"); Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); return FFX_API_RETURN_ERROR_RUNTIME_ERROR; @@ -1582,9 +1653,11 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe if (u.mode == UpscaleContext::Mode::Amd) { const ffxReturnCode_t rc = u.amdApi->dispatch(&u.amd, &d.header); Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); - Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, - "AMD FSR dispatch failed: " + std::string(RcName(rc))); - return rc; + if (rc == FFX_API_RETURN_OK) { + Report(u, UpscaleState::Amd, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); + return rc; + } + return AfterAmdFailure(u, tag, frameIndex, &frame, rc); // B8: the stand-in, then the pass-through } Log(tag + " note U" + std::to_string(u.id) + ": AMD FSR is not available for this context; the stand-in upscales its frames"); } @@ -1631,9 +1704,11 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe amd.reset = true; // AMD's history starts here const ffxReturnCode_t rc = u.amdApi->dispatch(&u.amd, &amd.header); Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); - Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, - "AMD FSR dispatch failed: " + std::string(RcName(rc))); - return rc; + if (rc == FFX_API_RETURN_OK) { + Report(u, UpscaleState::Amd, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); + return rc; + } + return AfterAmdFailure(u, tag, frameIndex, &frame, rc); // B8: the stand-in, then the pass-through } Log(tag + " note U" + std::to_string(u.id) + ": AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take"); } @@ -1673,10 +1748,14 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe if (u.mode == UpscaleContext::Mode::Amd) { const ffxReturnCode_t rc = u.amdApi->dispatch(&u.amd, &d.header); Log(tag + " -> " + RcName(rc) + " (forwarded to AMD after the failure)"); - Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, - u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); - return rc; + if (rc == FFX_API_RETURN_OK) { + Report(u, UpscaleState::Amd, nullptr, u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); + return rc; + } + return AfterAmdFailure(u, tag, frameIndex, mapped ? &frame : nullptr, rc); // B8 } + if (mapped && PassThroughFrame(u, tag, frameIndex, &frame, "WrongGPU's upscaler failed (" + u.failReason + ") and AMD FSR is not available")) + return FFX_API_RETURN_OK; // B8: never no output Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); Log(tag + " -> ERROR_RUNTIME_ERROR"); return r == WG_ERROR_PARAMETER ? FFX_API_RETURN_ERROR_PARAMETER : FFX_API_RETURN_ERROR_RUNTIME_ERROR; @@ -1697,9 +1776,11 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca if (!u.amdLast) amd.reset = true; const ffxReturnCode_t rc = u.amdApi->dispatch(&u.amd, &amd.header); Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); - Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, - u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); - return rc; + if (rc == FFX_API_RETURN_OK) { + Report(u, UpscaleState::Amd, nullptr, u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); + return rc; + } + return AfterAmdFailure(u, tag, frameIndex, frame, rc); // B8 } } u.resetNext = true; // this frame goes past the upscaler: its next one starts without history @@ -1734,11 +1815,18 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca if (run == 1 || rc != FFX_API_RETURN_OK) Log(tag + " note U" + std::to_string(u.id) + ": " + what + ": AMD FSR upscales this frame -> " + RcName(rc) + "; the context stays WrongGPU's (AMD FSR takes it over after " + std::to_string(kBadFrameRun) + " such frames in a row)"); - Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, - what + "; AMD FSR dispatch failed: " + RcName(rc), what); + if (rc == FFX_API_RETURN_OK) { + Report(u, UpscaleState::Amd, nullptr, what + "; AMD FSR dispatch failed: " + RcName(rc), what); + return rc; + } + u.amdLast = false; + if (PassThroughFrame(u, tag, frameIndex, frame, what + "; AMD FSR dispatch failed (" + RcName(rc) + ")")) + return FFX_API_RETURN_OK; // B8: the stand-in was tried first (step 1), now the frame passes through + Report(u, UpscaleState::Failed, nullptr, what + "; AMD FSR dispatch failed: " + RcName(rc), what); return rc; } - // 3. Nobody: the frame fails, the context stays. + // 3. Nobody could upscale it: the game's own colour is passed through unscaled (B8), else the frame fails, the context stays. + if (PassThroughFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; if (run == 1 || ShouldLogDispatch(frameIndex)) Log(tag + (amdOnly ? " note U" : " ERROR U") + std::to_string(u.id) + ": " + what + ": no upscaler for this frame (" + (config_.fallbackToAmd ? "AMD FSR is not available" : "fallback_to_amd = 0") + ") -> " + @@ -1875,9 +1963,20 @@ ffxReturnCode_t FrontEnd::Dispatch(ffxContext* context, const ffxDispatchDescHea ++u->dispatches; const ffxReturnCode_t rc = original->dispatch(&u->amd, desc); if (log || rc != FFX_API_RETURN_OK) Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); - if (desc->type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE) + if (desc->type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE) { + if (rc != FFX_API_RETURN_OK && u->upscaler) { + // B8: a context WrongGPU handed to AMD's FSR (its upscaler is kept, unused) whose AMD dispatch fails: the stand-in, then the + // pass-through (a context that was AMD's from the start is the game's own FSR and keeps AMD's answer) + WgFrame frame; + std::string problem, notes; + const uint64_t frameIndex = u->dispatches - 1; + if (MapDispatch(*reinterpret_cast(desc), u->create, config_, platform_.resourceInfo, + u->map, frameIndex, frame, problem, notes)) + return AfterAmdFailure(*u, tag, frameIndex, &frame, rc); + } Report(*u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); + } return rc; } const ffxReturnCode_t rc = original->dispatch(context, desc); diff --git a/clean/fsr/src/frontend.h b/clean/fsr/src/frontend.h index e33a9b74..2f910635 100644 --- a/clean/fsr/src/frontend.h +++ b/clean/fsr/src/frontend.h @@ -70,6 +70,11 @@ struct Platform { std::function diagnosticFailure; std::function diagnosticResult; std::function standIn; + // The last resort for a frame nothing could upscale (B8): records into frame.command_list a copy of the game's own colour + // into the output texture, unscaled (the active region, cut to both textures, at the output's origin). False with the + // reason in *why when it cannot (another format family, no list); the frame then has no output and the front end says so. + // May be empty (no pass-through on this platform). + std::function passThrough; // Every upscale dispatch WrongGPU's upscaler recorded (WG_OK), with its frame (frame capture, capture.h); standIn: // the one-frame stand-in upscaled it. May be empty. std::function afterDispatch; @@ -219,6 +224,13 @@ class FrontEnd { std::string FailureKey(const WgUpscalerBackend* backend, const UpscaleContext& u) const; void ResizeForFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag); // bug hunt H ffxReturnCode_t BrokenFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag, uint64_t frameIndex); // bug hunt F1 + // B8, the refused-frame contract: what a frame gets is explicit. Order: WrongGPU's upscaler, the stand-in, AMD's FSR, and + // last the game's own colour passed through unscaled (Platform::passThrough) with one warning line; the game is never + // answered with an error for a frame whose textures could be copied (a custom slot excepted: its host upscales on an + // error). PassThroughFrame: the last step (true: the frame has an output). AfterAmdFailure: AMD's dispatch failed for this + // frame (rc): the stand-in, then the pass-through; else rc. + bool PassThroughFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what); + ffxReturnCode_t AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc); void Fail(UpscaleContext& u, const std::string& why, uint64_t call, bool error = true); // Platform::status for one upscale dispatch of `u` (frame: the mapped frame when WrongGPU upscaled it, else null). // amdReason: why AMD's FSR upscaled this one frame of a context that stays WrongGPU's (state Amd). diff --git a/clean/fsr/src/passthrough_d3d12.cpp b/clean/fsr/src/passthrough_d3d12.cpp new file mode 100644 index 00000000..3ca4cc9a --- /dev/null +++ b/clean/fsr/src/passthrough_d3d12.cpp @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: MIT +// The last resort of the front end's refused-frame contract (B8, frontend.h Platform::passThrough): when nothing could +// upscale a frame, the game's own colour is copied into the output texture, unscaled, so that the game gets an image and an +// answer it can use instead of an error and an output nobody wrote. WrongGPU's own code. +#include "passthrough_d3d12.h" + +#define WIN32_LEAN_AND_MEAN +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#include + +#include +#include +#include + +namespace wgfsr { + +namespace { + +// The typeless group of a format: CopyTextureRegion needs both textures in the same one. +DXGI_FORMAT TypelessGroup(DXGI_FORMAT f) { + switch (f) { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_TYPELESS; + case DXGI_FORMAT_R16G16B16A16_TYPELESS: case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16B16A16_UNORM: + case DXGI_FORMAT_R16G16B16A16_UINT: case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16B16A16_SINT: + return DXGI_FORMAT_R16G16B16A16_TYPELESS; + case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R10G10B10A2_UNORM: case DXGI_FORMAT_R10G10B10A2_UINT: + return DXGI_FORMAT_R10G10B10A2_TYPELESS; + case DXGI_FORMAT_R8G8B8A8_TYPELESS: case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8B8A8_UINT: case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8B8A8_SINT: + return DXGI_FORMAT_R8G8B8A8_TYPELESS; + case DXGI_FORMAT_B8G8R8A8_TYPELESS: case DXGI_FORMAT_B8G8R8A8_UNORM: case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: + return DXGI_FORMAT_B8G8R8A8_TYPELESS; + default: return f; + } +} + +D3D12_RESOURCE_BARRIER Transition(ID3D12Resource* r, D3D12_RESOURCE_STATES from, D3D12_RESOURCE_STATES to) { + D3D12_RESOURCE_BARRIER b = {}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition.pResource = r; + b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + b.Transition.StateBefore = from; + b.Transition.StateAfter = to; + return b; +} + +} // namespace + +bool CopyColorToOutput(const WgFrame& f, std::string* why) { + auto fail = [&](const char* m) { + if (why) *why = m; + return false; + }; + auto* list = static_cast(f.command_list); + auto* src = static_cast(f.color.resource); + auto* dst = static_cast(f.output.resource); + if (!list || !src || !dst) return fail("no command list, colour or output texture"); + const D3D12_RESOURCE_DESC sd = src->GetDesc(), dd = dst->GetDesc(); + if (sd.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || dd.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) + return fail("the colour or the output is not a 2D texture"); + if (sd.SampleDesc.Count != 1 || dd.SampleDesc.Count != 1) return fail("a multisampled texture cannot be copied"); + if (TypelessGroup(sd.Format) != TypelessGroup(dd.Format)) + return fail("the colour and the output texture are in different format families"); + const uint32_t x = f.render_x, y = f.render_y; + if (x >= sd.Width || y >= sd.Height) return fail("the active region lies outside the colour texture"); + const uint32_t w = (uint32_t)std::min({f.render_width ? f.render_width : sd.Width, sd.Width - x, dd.Width}); + const uint32_t h = (uint32_t)std::min({f.render_height ? f.render_height : sd.Height, sd.Height - y, dd.Height}); + if (!w || !h) return fail("an empty region"); + const D3D12_RESOURCE_STATES from_src = static_cast(f.color.state); + const D3D12_RESOURCE_STATES from_dst = static_cast(f.output.state); + + D3D12_RESOURCE_BARRIER before[2], after[2]; + UINT nb = 0, na = 0; + if (from_src != D3D12_RESOURCE_STATE_COPY_SOURCE) { + before[nb++] = Transition(src, from_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + after[na++] = Transition(src, D3D12_RESOURCE_STATE_COPY_SOURCE, from_src); + } + if (from_dst != D3D12_RESOURCE_STATE_COPY_DEST) { + before[nb++] = Transition(dst, from_dst, D3D12_RESOURCE_STATE_COPY_DEST); + after[na++] = Transition(dst, D3D12_RESOURCE_STATE_COPY_DEST, from_dst); + } + if (nb) list->ResourceBarrier(nb, before); + D3D12_TEXTURE_COPY_LOCATION s = {}, d = {}; + s.pResource = src; + s.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + s.SubresourceIndex = 0; + d.pResource = dst; + d.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + d.SubresourceIndex = 0; + D3D12_BOX box = {x, y, 0, x + w, y + h, 1}; + list->CopyTextureRegion(&d, 0, 0, 0, &s, &box); + if (na) list->ResourceBarrier(na, after); + return true; +} + +} // namespace wgfsr diff --git a/clean/fsr/src/passthrough_d3d12.h b/clean/fsr/src/passthrough_d3d12.h new file mode 100644 index 00000000..a2b3c72b --- /dev/null +++ b/clean/fsr/src/passthrough_d3d12.h @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +#pragma once +// The last resort of the front end's refused-frame contract (B8): the game's own colour copied into the output texture, +// unscaled. Records into frame.command_list (D3D12 CopyTextureRegion with the transitions the textures' states ask for, and +// back); false with the reason in *why when it cannot (no list, another format family, a multisampled texture, an empty region). +#include + +#include "../include/wronggpu_upscaler.h" + +namespace wgfsr { +bool CopyColorToOutput(const WgFrame& frame, std::string* why); +} diff --git a/clean/fsr/src/win_util.h b/clean/fsr/src/win_util.h index 0e72e086..b3f71f2c 100644 --- a/clean/fsr/src/win_util.h +++ b/clean/fsr/src/win_util.h @@ -14,6 +14,7 @@ #include "d3d12_hooks.h" #include "overlay.h" #include "param_map.h" +#include "passthrough_d3d12.h" namespace wgwin { @@ -77,6 +78,15 @@ const wgfsr::OriginalApi* CompareApi(const std::string& path); // detail: why not, for the log. wgfsr::ProbeResult CheckProviderModule(HMODULE m, const std::wstring& requested, std::string& detail); +// B8: the front end's Platform has a pass-through (the game's colour copied into the output, the last resort for a frame +// nothing could upscale); another platform type (the FSR 3.0 hook's) has none and is left as it is. +template +auto SetPassThrough(PlatformT& p, int) -> decltype(p.passThrough = &wgfsr::CopyColorToOutput, void()) { + p.passThrough = &wgfsr::CopyColorToOutput; +} +template +void SetPassThrough(PlatformT&, long) {} + // Interface version 2 services of a front end's platform (FrontEnd or fsr30::Hook): the split service, the dispatch // notes for the submission trace, the one-frame stand-in, the overlay's status. Also passes this DLL's settings to // the D3D12 hooks and the overlay. @@ -109,6 +119,7 @@ void AddSplitServices(PlatformT& p, const wgfsr::Config& config) { p.services = &SplitServices; p.noteDispatch = &NoteDispatch; p.standIn = &StandInForFallback; + SetPassThrough(p, 0); // the last resort of the refused-frame contract (frontend.h), where the platform has it } bool D3D12ResourceInfo(void* resource, wgfsr::ResourceInfo* out); diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 2db49e57..402f36d4 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -197,14 +197,21 @@ static const WgUpscalerBackend* g_useBackend = &g_backend; static std::vector g_standInFrames; static WgCreateInfo g_standInCreate{}; static int g_standInDestroyed = 0; +static bool g_standInCreateFails = false; // B8: the stand-in cannot be made +static bool g_standInDispatchFails = false; // B8: the stand-in's dispatch fails +static bool g_passThroughOn = false; // B8: Platform::passThrough exists +static bool g_passThroughOk = true; // ... and succeeds +static std::vector g_passFrames; // the frames it was given +static std::function g_passThroughReal; // test_refusal_integration.cpp: the real copy static WgResult StandInCreate(const WgCreateInfo* info, WgUpscaler** out) { g_standInCreate = *info; + if (g_standInCreateFails) return WG_ERROR_DEVICE; *out = reinterpret_cast(new FakeUpscaler{2}); return WG_OK; } static WgResult StandInDispatch(WgUpscaler*, const WgFrame* frame) { g_standInFrames.push_back(*frame); - return WG_OK; + return g_standInDispatchFails ? WG_ERROR_DEVICE : WG_OK; } static void StandInDestroy(WgUpscaler* u) { ++g_standInDestroyed; @@ -306,6 +313,16 @@ static std::unique_ptr MakeFrontEnd(const Config& config) { if (frame) frame->command_list_type = 2; // as the D3D12 side would fill it in }; p.standIn = [](const Config&) -> const WgUpscalerBackend* { return &g_standIn; }; + if (g_passThroughOn) + p.passThrough = [](const WgFrame& f, std::string* why) { + g_passFrames.push_back(f); + if (g_passThroughReal) return g_passThroughReal(f, why); + if (!g_passThroughOk) { + if (why) *why = "the fake pass-through refuses"; + return false; + } + return true; + }; p.splitBlocked = [](void*) -> const char* { ++g_splitBlockedAsked; return g_splitBlocked; @@ -361,6 +378,11 @@ static void Reset() { g_createGate = true; g_useBackend = &g_backend; g_standInFrames.clear(); + g_standInCreateFails = g_standInDispatchFails = false; + g_passThroughOn = false; + g_passThroughOk = true; + g_passFrames.clear(); + g_passThroughReal = nullptr; g_standInCreate = WgCreateInfo{}; g_standInDestroyed = 0; g_servicesAsked.clear(); @@ -1880,6 +1902,11 @@ static void TestFailedFrameProviderTruth() { if (failure == 2) g_amdDispatchResult = FFX_API_RETURN_ERROR_RUNTIME_ERROR; auto dispatch = MakeDispatch(); if (failure == 3) dispatch.flags = FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB; + if (failure == 2) { + // B8: AMD's dispatch fails after the upscaler failed: the stand-in upscales the frame (it was an error before) + CHECK(fe->Dispatch(&ctx, &dispatch.header) == FFX_API_RETURN_OK); + CHECK(!g_statuses.empty() && g_statuses.back().state == UpscaleState::StandIn); + } else { CHECK(fe->Dispatch(&ctx, &dispatch.header) != FFX_API_RETURN_OK); CHECK(!g_statuses.empty()); if (!g_statuses.empty()) { @@ -1888,6 +1915,7 @@ static void TestFailedFrameProviderTruth() { status.state != UpscaleState::StandIn && status.state != UpscaleState::Compare); CHECK(!status.reason.empty()); } + } CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } for (bool comparison : {false, true}) { @@ -2446,6 +2474,95 @@ static void TestRefusedFrames() { } } +// B8 (REVIEW-215d P1): what a refused frame gets is explicit. The upscaler answers WG_ERROR_UNSUPPORTED for frames 1 .. 3; the +// stand-in cannot be made, or fails, AMD's FSR is missing or fails: the game's own colour is passed through unscaled with +// one warning line and the answer is OK, never an error for a frame whose textures can be copied. Every model (the contract is +// shared); a custom slot keeps returning the error (its host upscales). +static void TestRefusedFrameContract() { + const uint64_t models[] = {kWrongGpuProviderVersionId, kWrongGpuKProviderVersionId, kWrongGpuLProviderVersionId}; + for (const uint64_t model : models) { + // setup: no AMD / AMD with this dispatch result; stand-in made and working / create fails / dispatch fails; + // pass-through absent / working / refusing; custom slot + struct Case { + const char* name; + bool amd; + ffxReturnCode_t amdResult; + bool standInCreateFails, standInDispatchFails, passThrough, passOk, customSlot; + }; + const ffxReturnCode_t amdBad = FFX_API_RETURN_ERROR_RUNTIME_ERROR; + const Case cases[] = { + {"no AMD, stand-in create fails, pass-through ok", false, FFX_API_RETURN_OK, true, false, true, true, false}, + {"no AMD, stand-in dispatch fails, pass-through ok", false, FFX_API_RETURN_OK, false, true, true, true, false}, + {"no AMD, stand-in fails, pass-through refuses", false, FFX_API_RETURN_OK, true, false, true, false, false}, + {"no AMD, stand-in fails, no pass-through", false, FFX_API_RETURN_OK, true, false, false, true, false}, + {"AMD dispatch fails, stand-in ok", true, amdBad, false, false, true, true, false}, + {"AMD dispatch fails, stand-in create fails, pass-through ok", true, amdBad, true, false, true, true, false}, + {"AMD dispatch fails, stand-in dispatch fails, pass-through ok", true, amdBad, false, true, true, true, false}, + {"AMD dispatch fails, stand-in fails, pass-through refuses", true, amdBad, true, false, true, false, false}, + {"custom slot, no AMD, stand-in fails", false, FFX_API_RETURN_OK, true, false, true, true, true}, + }; + for (const Case& c : cases) { + Reset(); + g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_originalAvailable = c.amd; + g_amdDispatchResult = c.amdResult; + g_standInCreateFails = c.standInCreateFails; + g_standInDispatchFails = c.standInDispatchFails; + g_passThroughOn = c.passThrough; + g_passThroughOk = c.passOk; + Config config; + config.hosted = true; + config.customSlot = c.customSlot; + auto fe = MakeFrontEnd(config); + UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); + own.version.versionId = model; + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK && fe->OwnContextCount() == 1); + ffxDispatchDescUpscale d = MakeDispatch(); + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && g_statuses.back().state == UpscaleState::Network); + g_unsupportedAt = {1, 2, 3}; + std::vector rcs; + for (int i = 0; i < 3; ++i) rcs.push_back(fe->Dispatch(&ctx, &d.header)); + const bool standInWorks = !c.standInCreateFails && !c.standInDispatchFails; + const bool passes = c.passThrough && c.passOk && !c.customSlot; + // the first refused frame goes to AMD when it exists (the context is AMD's from then on, and AMD's dispatch fails for + // every frame): each frame has the stand-in, else the pass-through, else AMD's own error + if (c.amd && c.amdResult != FFX_API_RETURN_OK) { + for (ffxReturnCode_t rc : rcs) CHECK(rc == (standInWorks || passes ? FFX_API_RETURN_OK : amdBad)); + if (standInWorks) { + CHECK(g_standInFrames.size() == 3 && g_passFrames.empty()); + } else if (passes) { + CHECK(g_passFrames.size() == 3 && CountLog("the game's own colour is passed through to the output unscaled") == 1); + } else { + CHECK(g_passFrames.size() == (c.passThrough ? 3u : 0u)); + CHECK(CountLog("cannot be passed through") == 1); + } + CHECK(CountLog("HIP") == 0); + } else if (!c.amd) { + for (ffxReturnCode_t rc : rcs) CHECK(rc == (standInWorks || passes ? FFX_API_RETURN_OK : FFX_API_RETURN_ERROR_RUNTIME_ERROR)); + if (!standInWorks) { + CHECK(g_passFrames.size() == (c.passThrough && !c.customSlot ? 3u : 0u)); + if (passes) { + CHECK(g_statuses.back().state == UpscaleState::Failed && + g_statuses.back().reason.find("passed through unscaled") != std::string::npos); + CHECK(CountLog("the game's own colour is passed through to the output unscaled") == 1); // one line, not one a frame + for (const WgFrame& f : g_passFrames) CHECK(f.command_list && f.color.resource && f.output.resource); + } else if (!c.customSlot) { + CHECK(CountLog("cannot be passed through") == 1); + CHECK(g_statuses.back().state == UpscaleState::Failed); + } else { + CHECK(g_passFrames.empty()); // a custom slot's host upscales on the error + } + } else { + CHECK(g_passFrames.empty() && g_standInFrames.size() == 3); + } + CHECK(CountLog("HIP") == 0); + } + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + } +} + static void TestSplitBlocked() { Reset(); g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; @@ -3493,6 +3610,7 @@ int main() { TestRegistryEntries(); TestUnsupportedFrames(); TestRefusedFrames(); + TestRefusedFrameContract(); TestSplitBlocked(); TestRuntimeProviderName(); TestWithoutModelKItems(); diff --git a/clean/fsr/tests/test_refusal_integration.cpp b/clean/fsr/tests/test_refusal_integration.cpp new file mode 100644 index 00000000..b663b2d1 --- /dev/null +++ b/clean/fsr/tests/test_refusal_integration.cpp @@ -0,0 +1,340 @@ +// SPDX-License-Identifier: MIT +// B8 (REVIEW-215d P2): the front end and the REAL network backend (the runtime DLL's Context, the same code a game runs) with +// a controllable executor (executor=dx12-test: the D3D12 route, scripted frame by frame), driving refused frames for model K +// and, as the control, model M; with and without AMD's FSR; repeated; with the stand-in working and failing; and with the +// real last resort (passthrough_d3d12.cpp) copying the game's colour into the output, checked on the output's pixels. HIP is +// never started: no amdhip64 module is loaded in this process and the backend never logs the HIP runtime's start. +// +// Windows, a D3D12 device (WARP is enough, no GPU slot needed; a GPU through gpu_slot also works) and the runtime DLL of a build +// (python clean/runner/build.py --rocm --out --runtime-only). Not part of the CI (no runtime DLL there); the +// front end's fixtures are test_frontend.cpp's, included below. From the repository root, with the registry header generated +// (python clean/wgshared/tools/gen_registry.py --out-dir ): +// clang++ -std=c++17 -O1 -D_CRT_SECURE_NO_WARNINGS -I /include -I clean/wgshared/include -I clean/fsr/include +// -I clean/third_party/fidelityfx-sdk-1.1.4 clean/fsr/tests/test_refusal_integration.cpp clean/fsr/src/passthrough_d3d12.cpp +// clean/fsr/src/{frontend,param_map,ffx_describe,config,fsr30_hook,fsr30_map,amd_compare,async_create}.cpp +// -ld3d12 -ldxgi -o test_refusal_integration.exe +// test_refusal_integration.exe \wronggpu_runtime.dll +#define main wg_frontend_unit_main +#include "test_frontend.cpp" +#undef main + +#include +#include +#include + +#include +#include + +#include "../src/passthrough_d3d12.h" + +namespace { + +template +void Release(T*& p) { + if (p) p->Release(); + p = nullptr; +} + +struct Gpu { + ID3D12Device* device = nullptr; + ID3D12CommandQueue* queue = nullptr; + ID3D12CommandAllocator* alloc = nullptr; + ID3D12GraphicsCommandList* list = nullptr; + ID3D12Fence* fence = nullptr; + uint64_t fenceValue = 0; + HANDLE event = nullptr; + ID3D12Resource *color = nullptr, *depth = nullptr, *motion = nullptr, *output = nullptr; +}; + +constexpr UINT kRenderW = 1706, kRenderH = 960, kOutW = 2560, kOutH = 1440; + +ID3D12Resource* MakeTexture(ID3D12Device* dev, DXGI_FORMAT fmt, UINT w, UINT h, D3D12_RESOURCE_FLAGS flags, + D3D12_RESOURCE_STATES state) { + D3D12_HEAP_PROPERTIES hp = {}; + hp.Type = D3D12_HEAP_TYPE_DEFAULT; + D3D12_RESOURCE_DESC d = {}; + d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + d.Width = w; + d.Height = h; + d.DepthOrArraySize = 1; + d.MipLevels = 1; + d.Format = fmt; + d.SampleDesc.Count = 1; + d.Flags = flags; + ID3D12Resource* r = nullptr; + if (FAILED(dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &d, state, nullptr, IID_PPV_ARGS(&r)))) return nullptr; + return r; +} + +ID3D12Resource* MakeBuffer(ID3D12Device* dev, UINT64 bytes, D3D12_HEAP_TYPE type, D3D12_RESOURCE_STATES state) { + D3D12_HEAP_PROPERTIES hp = {}; + hp.Type = type; + D3D12_RESOURCE_DESC d = {}; + d.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + d.Width = bytes; + d.Height = d.DepthOrArraySize = d.MipLevels = 1; + d.SampleDesc.Count = 1; + d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + ID3D12Resource* r = nullptr; + if (FAILED(dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &d, state, nullptr, IID_PPV_ARGS(&r)))) return nullptr; + return r; +} + +void Wait(Gpu& g) { + g.queue->Signal(g.fence, ++g.fenceValue); + if (g.fence->GetCompletedValue() < g.fenceValue) { + g.fence->SetEventOnCompletion(g.fenceValue, g.event); + WaitForSingleObject(g.event, 60000); + } +} + +void Submit(Gpu& g) { + g.list->Close(); + ID3D12CommandList* l[] = {g.list}; + g.queue->ExecuteCommandLists(1, l); + Wait(g); +} + +void Begin(Gpu& g) { + g.alloc->Reset(); + g.list->Reset(g.alloc, nullptr); +} + +// The colour texture's pixel (x, y): RGBA16F, a pattern the output's copy can be checked against +uint16_t Pixel(UINT x, UINT y, UINT channel) { return (uint16_t)(0x3400 + ((x * 7 + y * 13 + channel * 101) & 0x3FF)); } + +bool MakeGpu(Gpu& g) { + IDXGIFactory4* f = nullptr; + IDXGIAdapter* warp = nullptr; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&f))) || FAILED(f->EnumWarpAdapter(IID_PPV_ARGS(&warp)))) return false; + const HRESULT hr = D3D12CreateDevice(warp, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&g.device)); + warp->Release(); + f->Release(); + if (FAILED(hr)) return false; + D3D12_COMMAND_QUEUE_DESC qd = {}; + qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + if (FAILED(g.device->CreateCommandQueue(&qd, IID_PPV_ARGS(&g.queue))) || + FAILED(g.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g.alloc))) || + FAILED(g.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g.alloc, nullptr, IID_PPV_ARGS(&g.list))) || + FAILED(g.device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g.fence)))) + return false; + g.event = CreateEventW(nullptr, FALSE, FALSE, nullptr); + const D3D12_RESOURCE_STATES srv = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; + g.color = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, + D3D12_RESOURCE_STATE_COPY_DEST); + g.depth = MakeTexture(g.device, DXGI_FORMAT_R32_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, srv); + g.motion = MakeTexture(g.device, DXGI_FORMAT_R16G16_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | srv); + g.output = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kOutW, kOutH, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + if (!g.color || !g.depth || !g.motion || !g.output) return false; + // the colour's pattern, through an upload buffer + D3D12_RESOURCE_DESC cd = g.color->GetDesc(); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; + UINT rows = 0; + UINT64 rowBytes = 0, total = 0; + g.device->GetCopyableFootprints(&cd, 0, 1, 0, &fp, &rows, &rowBytes, &total); + ID3D12Resource* up = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); + if (!up) return false; + uint8_t* map = nullptr; + up->Map(0, nullptr, reinterpret_cast(&map)); + for (UINT y = 0; y < rows; ++y) { + auto* row = reinterpret_cast(map + fp.Footprint.RowPitch * (size_t)y); + for (UINT x = 0; x < kRenderW; ++x) + for (UINT c = 0; c < 4; ++c) row[x * 4 + c] = Pixel(x, y, c); + } + up->Unmap(0, nullptr); + Begin(g); + D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {}; + dst.pResource = g.color; + dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + src.pResource = up; + src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + src.PlacedFootprint = fp; + g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + D3D12_RESOURCE_BARRIER b = {}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition.pResource = g.color; + b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + b.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; + b.Transition.StateAfter = srv; + g.list->ResourceBarrier(1, &b); + Submit(g); + up->Release(); + return true; +} + +// Row 0 of the output texture, the first `pixels` pixels as RGBA16F halves +bool ReadOutputRow0(Gpu& g, UINT pixels, std::vector* out) { + D3D12_RESOURCE_DESC od = g.output->GetDesc(); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; + UINT rows = 0; + UINT64 rowBytes = 0, total = 0; + g.device->GetCopyableFootprints(&od, 0, 1, 0, &fp, &rows, &rowBytes, &total); + ID3D12Resource* rb = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); + if (!rb) return false; + Begin(g); + D3D12_RESOURCE_BARRIER b = {}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition.pResource = g.output; + b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + b.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; + g.list->ResourceBarrier(1, &b); + D3D12_TEXTURE_COPY_LOCATION src = {}, dst = {}; + src.pResource = g.output; + src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + dst.pResource = rb; + dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + dst.PlacedFootprint = fp; + g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + std::swap(b.Transition.StateBefore, b.Transition.StateAfter); + g.list->ResourceBarrier(1, &b); + Submit(g); + uint8_t* map = nullptr; + rb->Map(0, nullptr, reinterpret_cast(&map)); + out->assign(reinterpret_cast(map), reinterpret_cast(map) + (size_t)pixels * 4); + rb->Unmap(0, nullptr); + rb->Release(); + return true; +} + +void RealRefusals(const char* dllPath) { + HMODULE dll = LoadLibraryA(dllPath); + std::printf("runtime DLL %s\n", dll ? "loaded" : "NOT loaded"); + std::fflush(stdout); + CHECK(dll != nullptr); + if (!dll) return; + auto get = reinterpret_cast(reinterpret_cast(GetProcAddress(dll, "wgGetUpscalerBackend"))); + const WgUpscalerBackend* real = get ? get(WG_UPSCALER_INTERFACE_VERSION) : nullptr; + CHECK(real != nullptr); + if (!real) return; + std::printf("backend %p\n", (const void*)real); + std::fflush(stdout); + Gpu g; + CHECK(MakeGpu(g)); + std::printf("WARP device and textures: %s\n", g.output ? "ready" : "FAILED"); + std::fflush(stdout); + if (!g.output) return; + CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); + + struct Scenario { + const char* name; + bool amd, standInCreateFails, realPassThrough; + const char* script; + int frames; + }; + // frame 0 is taken; the refused frames follow; 'o' after them is taken again (the context stays usable, no counter) + const Scenario scenarios[] = { + {"AMD available", true, false, false, "orrrrr", 6}, + {"no AMD, stand-in works, five refusals in a row then taken", false, false, false, "orrrrroo", 8}, + {"no AMD, stand-in cannot be made: the game's own colour is passed through", false, true, true, "orrr", 4}, + }; + for (const bool model_k : {true, false}) { // model K, and model M as the control + for (const Scenario& sc : scenarios) { + std::printf("scenario: %s, %s\n", model_k ? "model K" : "model M", sc.name); + std::fflush(stdout); + const int failuresBefore = g_failures; + Reset(); + g_originalAvailable = sc.amd; + g_standInCreateFails = sc.standInCreateFails; + g_passThroughOn = true; + if (sc.realPassThrough) g_passThroughReal = [](const WgFrame& f, std::string* why) { return wgfsr::CopyColorToOutput(f, why); }; + g_useBackend = real; + g_resources[g.color] = {dxgi::R16G16B16A16_FLOAT, kRenderW, kRenderH}; + g_resources[g.depth] = {dxgi::R32_FLOAT, kRenderW, kRenderH}; + g_resources[g.motion] = {dxgi::R16G16_FLOAT, kRenderW, kRenderH}; + g_resources[g.output] = {dxgi::R16G16B16A16_FLOAT, kOutW, kOutH}; + const std::string options = std::string("executor=dx12-test;test_script=") + sc.script + (model_k ? ";model=K" : ""); + _putenv_s("WG_RUNTIME_OPTIONS", options.c_str()); + Config config; + config.hosted = true; + auto fe = MakeFrontEnd(config); + UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); + own.version.versionId = model_k ? kWrongGpuKProviderVersionId : kWrongGpuProviderVersionId; + own.backend.device = g.device; + ffxContext ctx = nullptr; + const std::string tag = std::string(model_k ? "model K, " : "model M, ") + sc.name; + CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK && fe->OwnContextCount() == 1); + CHECK(CountLog("network runtime ready: executor dx12-scripted") == 1); + ffxDispatchDescUpscale d = MakeDispatch(); + d.commandList = g.list; + d.color = Res(g.color, FFX_API_SURFACE_FORMAT_R16G16B16A16_FLOAT, kRenderW, kRenderH, FFX_API_RESOURCE_STATE_COMPUTE_READ); + d.depth = Res(g.depth, FFX_API_SURFACE_FORMAT_R32_FLOAT, kRenderW, kRenderH, FFX_API_RESOURCE_STATE_COMPUTE_READ); + d.motionVectors = Res(g.motion, FFX_API_SURFACE_FORMAT_R16G16_FLOAT, kRenderW, kRenderH, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + d.output = Res(g.output, FFX_API_SURFACE_FORMAT_R16G16B16A16_FLOAT, kOutW, kOutH, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS); + d.renderSize = {kRenderW, kRenderH}; + d.upscaleSize = {kOutW, kOutH}; + Begin(g); + std::vector rc; + std::vector state; + for (int i = 0; i < sc.frames; ++i) { + rc.push_back(fe->Dispatch(&ctx, &d.header)); + state.push_back(g_statuses.empty() ? UpscaleState::Failed : g_statuses.back().state); + } + Submit(g); // the game's list, with whatever the front end recorded in it, runs + CHECK(g.device->GetDeviceRemovedReason() == S_OK); + for (ffxReturnCode_t r : rc) CHECK(r == FFX_API_RETURN_OK); // every frame has an upscaler, whatever the refusals + CHECK(state[0] == UpscaleState::Network); // frame 0 is the real backend's + // the refusals came from the real backend's code path (backend.cpp dispatch_record), one line, not a counter + CHECK(CountLog(model_k ? "model K: the D3D12 executor does not take this frame" + : "executor dx12 (default on RDNA 4) does not take this frame") == 1); + CHECK(CountLog("ERROR_RUNTIME_ERROR") == 0); + if (sc.amd) { + // the first refused frame hands the context to AMD's FSR for good: the rest are AMD's + CHECK(state[1] == UpscaleState::Amd && !g_amd.empty() && g_amd.back().fn == "dispatch"); + for (int i = 2; i < sc.frames; ++i) CHECK(state[i] == UpscaleState::Amd); + CHECK(CountLog("WrongGPU frame: frame=") == 2 && g_standInFrames.empty()); // the backend was asked for frames 0 and 1 only + } else if (!sc.standInCreateFails) { + // the stand-in takes each refused frame (five in a row included); the context stays WrongGPU's: the taken + // frames after the refusals are the real backend's again + for (int i = 1; i <= 5; ++i) CHECK(state[i] == UpscaleState::StandIn); + CHECK(state[6] == UpscaleState::Network && state[7] == UpscaleState::Network); + CHECK(g_standInFrames.size() == 5 && g_amd.empty() && g_passFrames.empty()); + CHECK(CountLog("AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take") == 1); + } else { + // no stand-in: the game's colour is copied into the output by the real last resort, checked on the pixels + for (int i = 1; i < sc.frames; ++i) + CHECK(state[i] == UpscaleState::Failed && g_statuses.back().reason.find("passed through unscaled") != std::string::npos); + CHECK(g_passFrames.size() == 3 && g_amd.empty()); + CHECK(CountLog("the game's own colour is passed through to the output unscaled") == 1); + std::vector px; + CHECK(ReadOutputRow0(g, 8, &px) && px.size() == 32); + bool same = px.size() == 32; + for (UINT x = 0; same && x < 8; ++x) + for (UINT c = 0; c < 4; ++c) same = same && px[x * 4 + c] == Pixel(x, 0, c); + CHECK(same); // the output's first pixels are the colour's + } + // HIP never started: no HIP runtime line, no amdhip64 module + CHECK(CountLog("about to start the HIP runtime") == 0); + CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + if (g_failures != failuresBefore) { // the log of a failed scenario + std::lock_guard lock(g_logMutex); + for (const std::string& line : g_log) std::printf(" log: %s\n", line.c_str()); + } + std::printf(" %s: states", tag.c_str()); + for (UpscaleState s : state) std::printf(" %d", (int)s); + std::printf(", checks so far %d, failures %d\n", g_checks, g_failures); + g_passThroughReal = nullptr; + } + } + _putenv_s("WG_RUNTIME_OPTIONS", ""); + Release(g.color); + Release(g.depth); + Release(g.motion); + Release(g.output); +} + +} // namespace + +int main(int argc, char** argv) { + const char* dll = argc > 1 ? argv[1] : std::getenv("WG_TEST_RUNTIME_DLL"); + if (!dll || !*dll) { + std::printf("SKIP: no runtime DLL (argument or WG_TEST_RUNTIME_DLL)\n"); + return 0; + } + RealRefusals(dll); + std::printf("%d checks, %d failures\n", g_checks, g_failures); + return g_failures ? 1 : 0; +} diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 31486b09..51dae459 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -168,6 +168,7 @@ struct Options { int test_view = 0; // d3d12-test executor: 0 color, 1 depth, 2 motion bool test_handles = false; // d3d12-test executor: make shared objects with NT handles (sharing paths) bool test_keep = false; // d3d12-test executor with test_handles: keep the arena for later contexts (pool) + std::string test_script; // dx12-test executor: one character per frame (executor.h make_scripted_dx12_executor) bool timing_stages = true; // timing_stages=0: keep D3D12 full-span timestamps only bool timing_log = false; // one timing summary line every 300 dispatches bool watchdog = false; // diagnostics: report a dispatch or network frame stuck for more than 3 s @@ -221,6 +222,7 @@ Options parse_options(const char* text) { else if (key == "model_format") o.model_format = value; else if (key == "test_handles") o.test_handles = value == "1"; else if (key == "test_keep") o.test_keep = value == "1"; + else if (key == "test_script") o.test_script = value; else if (key == "share_path") o.share_path = value; else if (key == "timing_log") o.timing_log = value == "1"; else if (key == "timing_stages") o.timing_stages = value != "0"; @@ -600,6 +602,7 @@ class Context { say(WG_LOG_WARN, "WG_RUNTIME_OPTIONS is longer than 4095 characters and is ignored"); } Options o = parse_options(text.c_str()); + bool test_model_k = false; // dx12-test: the model the options name (no configure_hip there) { // the executor (executor_select.h): the option, else the default (dx12 for model M on RDNA 4); one log line why ExecutorRequest q; q.executor = o.executor; @@ -609,6 +612,7 @@ class Context { std::string merr; // model K only (Model L runs on the D3D12 executor in builds with it: runtime.cpp, native D3D12 backend 3) q.model_k = wgrt::model_from_options(probe, &model, &merr) && model == wgrt::ModelId::K; + test_model_k = q.model_k; q.adapter_known = adapter_info(device_, &q.adapter, &q.vendor_id, &q.software); q.sparkle_guard = o.sparkle_guard > 0.0f; q.capture = !o.capture_dir.empty(); @@ -632,7 +636,7 @@ class Context { split_ = split; share_path_opt_ = o.share_path; input_copy_opt_ = o.input_copy; - if (!split && o.executor != "dx12") + if (!split && o.executor != "dx12" && o.executor != "dx12-test") return fail(WG_ERROR_UNSUPPORTED, "the front end offers no command-list split (interface version 2)"); if (!o.unknown.empty()) say(WG_LOG_INFO, "options passed on to the network runtime: " + o.unknown); if (o.motion_outres != "original" && o.motion_outres != "point") @@ -645,6 +649,10 @@ class Context { bool dx12 = false; if (o.executor == "d3d12-test") { exec_ = make_test_executor(o.test_view, o.test_handles, o.test_keep); + } else if (o.executor == "dx12-test") { +#ifndef WG_NO_MODEL_K + model_k_ = test_model_k; +#endif } else if (o.executor == "hip" || o.executor == "dx12") { if (!configure_hip(o, &err)) return fail(WG_ERROR, err); } else { @@ -659,15 +667,17 @@ class Context { // the game's command list. Paths without D3D12 ports, and the diagnostics that need HIP, got the HIP executor // above (choose_executor). (Motion at output resolution: the D3D12 ports of the emo / pmo kernels read the game's // motion texture with motion_outres=original; with point the executor's D3D12 pass resamples it.) - dx12 = o.executor == "dx12"; + const bool dx12_test = o.executor == "dx12-test"; + dx12 = o.executor == "dx12" || dx12_test; + if (dx12_test) dx12_default_ = true; // the scripted executor stands in for the default D3D12 executor if (dx12) { - exec_ = make_d3d12_executor(rt_cfg_); + exec_ = dx12_test ? make_scripted_dx12_executor(o.test_script) : make_d3d12_executor(rt_cfg_); exec_->set_log_sink([this](bool warning, const std::string& m) { say(warning ? WG_LOG_WARN : WG_LOG_INFO, "D3D12 executor: " + m); }); no_slots_ = true; // its kernels read the game's textures: no slot buffers (fences and a 128 KB flag arena only) if (!exec_->prepare(&err) || !exec_->prepare_device(device_, &err) || - !make_shared_objects(false, "arena", &err) || !exec_->init(device_, set_, &err)) { + (!dx12_test && !make_shared_objects(false, "arena", &err)) || !exec_->init(device_, set_, &err)) { // model K: no HIP route in a game; the one error line below is the whole report, the game keeps its own upscaler if (model_k_) return fail(WG_ERROR_UNSUPPORTED, dx12_refused_line_k(dx12_default_, err)); say(WG_LOG_WARN, dx12_refused_line(dx12_default_, err)); diff --git a/clean/runtime/interop/executor.h b/clean/runtime/interop/executor.h index c9a0d881..f8be0694 100644 --- a/clean/runtime/interop/executor.h +++ b/clean/runtime/interop/executor.h @@ -231,6 +231,11 @@ std::unique_ptr make_hip_executor(const WgRtConfig& cfg, const std::st // handles: behave like an executor that imports the shared objects (tests of the sharing paths). // keep (with handles): also like one whose arena import is kept for later contexts (tests of the arena pool). std::unique_ptr make_test_executor(int view, bool handles, bool keep = false); +// executor=dx12-test (tests of the backend's frame paths, no GPU work): an executor on the D3D12 route (records into the game's +// list, no slots, no fences) that answers each frame as `script` says, one character per frame, the last repeated: 'o' the frame +// is taken (nothing is recorded, the output counts as written), 'r' refused ("frame not taken (nothing recorded)", as the D3D12 +// executor refuses a render size or a missing output texture), 'f' a failure inside the network. +std::unique_ptr make_scripted_dx12_executor(const std::string& script); // executor=dx12: cfg as for the HIP executor (its backend field is ignored: the pure D3D12 device on the game's device). std::unique_ptr make_d3d12_executor(const WgRtConfig& cfg); // The D3D12 executor's output route of its last frame (one phrase for the log), empty for other executors. diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index 5dc379bd..c5c84115 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -63,7 +63,7 @@ inline std::string k_sparkle_off_line() { inline ExecutorChoice choose_executor(const ExecutorRequest& r) { ExecutorChoice c; const std::string& e = r.executor; - if (e == "d3d12-test") { + if (e == "d3d12-test" || e == "dx12-test") { // the offline test executors (dx12-test: the D3D12 route, scripted) c.executor = e; return c; } diff --git a/clean/runtime/interop/executor_test.cpp b/clean/runtime/interop/executor_test.cpp index 48913b67..105c22ae 100644 --- a/clean/runtime/interop/executor_test.cpp +++ b/clean/runtime/interop/executor_test.cpp @@ -4,6 +4,7 @@ // `out`, and signals `done`. view 0: color times the exposure (so the exposure plumbing is visible); 1: depth (d, d, // d); 2: motion in render pixels (mx, my, 0). WrongGPU's own code. #include +#include #include #include "executor.h" @@ -293,4 +294,50 @@ std::unique_ptr make_test_executor(int view, bool handles, bool keep) return std::unique_ptr(new TestExecutor(view, handles, keep)); } +// ---- executor=dx12-test: the scripted executor on the D3D12 route (executor.h make_scripted_dx12_executor) ---------------- + +namespace { + +class ScriptedDx12Executor final : public Executor { + public: + explicit ScriptedDx12Executor(std::string script) : script_(script.empty() ? "o" : std::move(script)) {} + const char* name() const override { return "dx12-scripted"; } + bool needs_handles() const override { return false; } + bool init(ID3D12Device*, const SharedSet&, std::string*) override { return true; } + bool submit(const Job&, bool*, std::string* err) override { + *err = "the scripted executor records into the game's list"; + return false; + } + bool records_into_list() const override { return true; } + bool record(const Job& job, ID3D12GraphicsCommandList*, bool* output_written, std::string* err) override { + const size_t k = job.value ? (size_t)(job.value - 1) : 0; + const char c = script_[k < script_.size() ? k : script_.size() - 1]; + const std::string n = std::to_string((unsigned long long)job.value); + *output_written = false; + if (c == 'r') { + *err = "frame not taken (nothing recorded): scripted refusal of frame " + n; + return false; + } + completed_ = job.value; + if (c == 'f') { + *err = "scripted failure of frame " + n + " inside the network"; + return false; + } + *output_written = true; + return true; + } + uint64_t completed() const override { return completed_; } + void drain() override {} + + private: + std::string script_; + uint64_t completed_ = 0; +}; + +} // namespace + +std::unique_ptr make_scripted_dx12_executor(const std::string& script) { + return std::unique_ptr(new ScriptedDx12Executor(script)); +} + } // namespace wgi From 26633de730b0ec49e4e7a25ffa340aee2deaa423 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:47:43 -0500 Subject: [PATCH 2/4] B8: the last resort is the backend's bilinear output pass; no raw copy (REVIEW-228) Drop the raw CopyTextureRegion pass-through (it wrote only the render-sized corner, transitioned unrelated subresources and copied bits between format families). When the stand-in and AMD's FSR could not upscale a frame, the front end now asks the upscaler for its existing bilinear output pass: WgFrame::flags WG_FRAME_BILINEAR (the backend says it answers it with WG_BACKEND_BILINEAR_FRAME), and the runtime records the Converter's fallback pass (format aware, the full output size, its own barrier handling, no HIP). The game gets OK with one warning line per context; the counts are logged at destroy. When that is impossible too, the error goes back and the reason is logged for the first such frame, also after earlier successes. AMD's failures are logged once per context and counted, however long the run; AMD's per-frame context create is retried at 1, 2, 3, 10, 100 ... A frame flagged non-linear (sRGB / PQ) is mapped before the AMD-only fallback, so it gets the same last resort. Tests: test_frontend.cpp (every failure case for models M, K and L over 300 frames, log size bounded, success then an invalid output, AMD create failing, non-linear frames). test_refusal_integration.cpp (the real backend, the scripted executor) checks every pixel of the backend's bilinear output for consecutive frames after a sentinel fill, with a negative control, that model K's alpha follows the colour's alpha and M's is 1, that wgDiagHipExecutorsMade stays 0, and fails without the runtime DLL. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/CMakeLists.txt | 2 +- clean/fsr/README.md | 23 +- clean/fsr/include/wronggpu_upscaler.h | 10 + clean/fsr/src/frontend.cpp | 117 ++++++---- clean/fsr/src/frontend.h | 20 +- clean/fsr/src/fsr30_hook.cpp | 2 +- clean/fsr/src/passthrough_d3d12.cpp | 100 --------- clean/fsr/src/passthrough_d3d12.h | 12 - clean/fsr/src/win_util.h | 11 - clean/fsr/tests/test_frontend.cpp | 220 ++++++++++++------- clean/fsr/tests/test_refusal_integration.cpp | 173 ++++++++++++--- clean/runtime/interop/backend.cpp | 37 +++- 12 files changed, 427 insertions(+), 300 deletions(-) delete mode 100644 clean/fsr/src/passthrough_d3d12.cpp delete mode 100644 clean/fsr/src/passthrough_d3d12.h diff --git a/clean/fsr/CMakeLists.txt b/clean/fsr/CMakeLists.txt index bbb7690e..0f5af475 100644 --- a/clean/fsr/CMakeLists.txt +++ b/clean/fsr/CMakeLists.txt @@ -172,7 +172,7 @@ if(WIN32) endif() # Windows parts shared by the three DLLs: settings, loading AMD's originals, D3D12 queries, the stand-in. - add_library(wg_fsr_win STATIC src/win_util.cpp src/standin_d3d12.cpp src/passthrough_d3d12.cpp src/d3d12_hooks.cpp src/statistics_query.cpp src/split_progress.cpp src/overlay.cpp src/asi_bridge.cpp + add_library(wg_fsr_win STATIC src/win_util.cpp src/standin_d3d12.cpp src/d3d12_hooks.cpp src/statistics_query.cpp src/split_progress.cpp src/overlay.cpp src/asi_bridge.cpp src/settings_bridge.cpp) if(WG_SPLIT_PROGRESS_QA) target_compile_definitions(wg_fsr_win PRIVATE WRONGGPU_SPLIT_PROGRESS_QA=1) diff --git a/clean/fsr/README.md b/clean/fsr/README.md index 18f99bce..77f67e9c 100644 --- a/clean/fsr/README.md +++ b/clean/fsr/README.md @@ -271,15 +271,20 @@ OptiScaler folder ships `amd_fidelityfx_upscaler_dx12.dll`; OptiScaler.ini `[Lib AMD's FSR at once; without AMD's FSR the stand-in upscales such frames. This is one contract for every model (K refused frames take exactly model M's path), and what a frame gets is explicit (B8): WrongGPU's upscaler, then the stand-in, then AMD's FSR, and last, - when none of them could upscale it (the stand-in cannot be made or fails, AMD's FSR is missing or its dispatch fails), the - game's own colour is copied into the output unscaled (`passthrough_d3d12.cpp`: the active region, cut to both textures, at - the output's origin; the same format family is needed) with one warning line, and the game gets `FFX_API_RETURN_OK`, never - an error for a frame whose textures can be copied. When even that is impossible (no command list, another format family) - the error goes back with one line saying why, as before; in OptiScaler's custom slot the error always goes back (its host - upscales). `tests/test_frontend.cpp` covers each failure case for models M, K and L; `tests/test_refusal_integration.cpp` - drives refused frames through the real network backend (the runtime DLL's `Context`, with the scripted executor - `executor=dx12-test`) and the real front end on a D3D12 device (WARP is enough), with and without AMD's FSR, the stand-in - working and not, checks the copied pixels, and that no HIP runtime is ever loaded. + when none of them could upscale it (the stand-in cannot be made or fails, AMD's FSR is missing, cannot be created or its + dispatch fails), the backend's own bilinear upscale of the game's colour: the front end asks the upscaler for it with + `WG_FRAME_BILINEAR` (`WG_BACKEND_BILINEAR_FRAME` says a backend answers it), and the runtime records the Converter's + existing fallback pass (format aware, the full output size, no HIP). The game gets `FFX_API_RETURN_OK` and one warning + line per context; the counts are logged when the context is destroyed. When even that is impossible (no upscaler for the + context, the output texture unusable) the error goes back and the reason is logged for the first such frame, also after + earlier successes; in OptiScaler's custom slot the error always goes back (its host upscales). AMD's failures are logged + once per context and counted. A frame the game flags as non-linear (sRGB / PQ) is not a refused frame: it goes to AMD's FSR + and, when that is missing or fails, gets the same last resort. `tests/test_frontend.cpp` covers each failure case for + models M, K and L over a long run; `tests/test_refusal_integration.cpp` drives refused frames through the real network + backend (the runtime DLL's `Context`, with the scripted executor `executor=dx12-test`) and the real front end on a D3D12 + device (WARP is enough), with and without AMD's FSR, the stand-in working and not, checks every pixel of the backend's + bilinear output for consecutive frames, and that no HIP executor was ever made (`wgDiagHipExecutorsMade`). It is not in the + CI (it needs a runtime DLL) and fails without one: a release gate runs it with the DLL of the build. - **Model location:** the front end looks for the converted model (`model.wgcm`, Model K in `K\`) in `[fsr] model_dir` of `wronggpu.ini` (relative: from the data folder), then `\WrongGPU\model`, and passes the first folder that has it to the runtime as `model_dir=`; otherwise the runtime's own default (`%LOCALAPPDATA%\WrongGPU\model`, diff --git a/clean/fsr/include/wronggpu_upscaler.h b/clean/fsr/include/wronggpu_upscaler.h index 966b9190..5c63ab82 100644 --- a/clean/fsr/include/wronggpu_upscaler.h +++ b/clean/fsr/include/wronggpu_upscaler.h @@ -146,8 +146,17 @@ typedef struct WgFrame { end's ExecuteCommandLists hook), or null; informational: the split needs no queue from the backend */ uint32_t command_list_type; /* D3D12_COMMAND_LIST_TYPE of command_list (0 = DIRECT, 2 = COMPUTE) */ + + /* version 2, after the first release: a front end that cannot know whether the backend reads this sets + * struct_size = sizeof(WgFrame) with flags = 0; a backend reads flags only when struct_size covers it. */ + uint32_t flags; /* WG_FRAME_* */ } WgFrame; +/* WgFrame::flags. */ +#define WG_FRAME_BILINEAR (1u << 0) /* do not run the network: record the backend's own bilinear upscale of the color into + the output texture (the last resort of the front end for a frame that nothing else + could upscale). Only for a backend that sets WG_BACKEND_BILINEAR_FRAME. */ + /* Version 2: same-frame execution through an "ordered split" of the game's command list. * * The backend, inside dispatch, on the game's recording thread: @@ -199,6 +208,7 @@ typedef struct WgUpscaler WgUpscaler; /* opaque, owned by the implementation */ /* Backend flags (version 2). */ #define WG_BACKEND_NEEDS_SPLIT (1u << 0) /* the backend calls split_command_list: the front end installs its D3D12 command-list hooks when the backend is loaded (d3d12_hooks = auto) */ +#define WG_BACKEND_BILINEAR_FRAME (1u << 1) /* the backend answers WG_FRAME_BILINEAR (see WgFrame::flags) */ /* The implementation's entry points. */ typedef struct WgUpscalerBackend { diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index 232f8437..94d34f5a 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -58,7 +58,11 @@ struct FrontEnd::UpscaleContext { bool amdLast = false; // the last frame was one of AMD's FSR for such a frame (AMD's history continues) bool broken = false; // the upscaler failed for good: it is not parked uint64_t brokenFrames = 0; // bug hunt F1: frames since the upscaler failed for good (it is not called again) - uint64_t passThroughFrames = 0; // B8: frames of this context that were passed through unscaled (nothing could upscale them) + uint64_t lastResortFrames = 0; // B8: frames of this context the backend's bilinear upscale wrote (nothing else could) + uint64_t lastResortFailures = 0; // B8: frames for which even that could not be recorded + uint64_t amdFailures = 0; // B8: AMD FSR dispatches of this context that failed (logged once, counted) + uint64_t mapFailures = 0; // B8: frames of a context handed to AMD that could not be mapped for the fallback + uint64_t amdCreateTries = 0; // B8: per-frame attempts to make AMD's context for a bad frame (made at 1, 2, 3, 10, 100 ...) uint32_t resizes = 0; // bug hunt H: upscalers created again for the frames' output size (Config::maxOutputResizes) bool resizeFailed = false; // ... and such a create failed: no more attempts for this context // Issue #58: upscalers and stand-ins a resize replaced. Command lists the game recorded before may still use them @@ -949,49 +953,63 @@ bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend return false; } +// B8: AMD's failures are logged once per context (the first, with its reason) and counted; the count is logged when the +// context is destroyed. +void FrontEnd::NoteAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, ffxReturnCode_t rc) { + if (++u.amdFailures == 1) + Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": AMD FSR dispatch failed (" + + RcName(rc) + "); this context's frames get the stand-in or the backend's bilinear upscale; its later AMD failures are counted, not logged"); +} + // B8: the last step of the refused-frame contract. Nothing upscaled this frame (the upscaler refused it, the stand-in could -// not be made or failed, AMD's FSR is missing or failed): the game's own colour is copied into the output unscaled -// (Platform::passThrough) and the game gets FFX_API_RETURN_OK with one warning line (LogPoint counts), instead of an error and -// an output nobody wrote. False when that is impossible too (the reason is logged), or in OptiScaler's custom slot, whose -// host upscales a frame the upscaler answers an error for. -bool FrontEnd::PassThroughFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what) { +// not be made or failed, AMD's FSR is missing or failed): the backend writes the output itself, its own bilinear upscale of +// the game's colour (WG_FRAME_BILINEAR: format aware, the full output size, no HIP, the Converter pass the backend uses for +// a frame whose network failed), and the game gets FFX_API_RETURN_OK with one warning line per context (the count at the +// end). False when that cannot be done (the reason is logged for the first such frame, whatever came before: a failure after +// earlier successes is reported too) and in OptiScaler's custom slot, whose host upscales a frame the upscaler fails. +bool FrontEnd::LastResortFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what) { if (config_.customSlot) return false; std::string why; bool ok = false; - uint32_t w = 0, h = 0; if (!frame) { - why = "the frame's inputs could not be read"; - } else if (!platform_.passThrough) { - why = "this platform has no pass-through"; + why = "the frame's inputs could not be mapped"; + } else if (!u.backend || !u.upscaler) { + why = "WrongGPU's upscaler is not available for this context"; + } else if (!(BackendFlags(u.backend) & WG_BACKEND_BILINEAR_FRAME)) { + why = "the upscaler cannot write a frame without the network"; } else { WgFrame f = *frame; if (!UsableForStandIn(f)) { why = "the frame has no command list, colour texture or output texture"; } else { - w = f.render_width < f.output_width ? f.render_width : f.output_width; - h = f.render_height < f.output_height ? f.render_height : f.output_height; - ok = platform_.passThrough(f, &why); + f.flags = WG_FRAME_BILINEAR; + AdaptFrame(u.backend, f); + const WgResult r = u.backend->dispatch(u.upscaler, &f); + ok = r == WG_OK; + if (!ok) why = std::string("the backend's bilinear upscale answered ") + WgResultText(r); } } - const uint64_t n = ++u.passThroughFrames; if (ok) { - if ((n == 1 || n >= 10) && LogPoint(n)) // one line, then at 10, 100, ... + if (++u.lastResortFrames == 1) Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + - "; nothing upscaled it: the game's own colour is passed through to the output unscaled (" + std::to_string(w) + "x" + - std::to_string(h) + ", " + std::to_string(n) + " such frame(s) in this context)"); - Report(u, UpscaleState::Failed, frame, "frame passed through unscaled: " + what); + "; nothing upscaled it: the backend's bilinear upscale of the game's colour wrote the output (later such frames of this " + "context are counted, not logged)"); + Report(u, UpscaleState::Failed, frame, "frame upscaled bilinearly by the backend, nothing else could: " + what); return true; } - if ((n == 1 || n >= 10) && LogPoint(n)) // one line, then at 10, 100, ... + const uint64_t n = ++u.lastResortFailures; + if (n == 1 || ((n >= 10) && LogPoint(n))) Log(tag + " ERROR U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + - "; nothing upscaled it and it cannot be passed through (" + why + ")"); + "; nothing upscaled it and the backend's bilinear upscale is not possible (" + why + "), " + std::to_string(n) + + " such frame(s) in this context"); return false; } -// B8: AMD's FSR was asked for this frame and its dispatch failed (rc). The stand-in is tried, then the pass-through; if both +// B8: AMD's FSR was asked for this frame and its dispatch failed (rc). The stand-in is tried, then the last resort; if both // fail (or in a custom slot) AMD's own error goes back, as before. ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc) { - const std::string what = "AMD FSR dispatch failed (" + std::string(RcName(rc)) + ")"; + NoteAmdFailure(u, tag, frameIndex, rc); + const std::string what = "AMD FSR failed (" + std::string(RcName(rc)) + ")"; if (frame && !config_.customSlot) { WgFrame f = *frame; if (UsableForStandIn(f)) { @@ -1004,7 +1022,6 @@ ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& } AdaptFrame(u.fallbackBackend, f); if (u.fallback && u.fallbackBackend->dispatch(u.fallback, &f) == WG_OK) { - Log(tag + " note U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + "; the stand-in upscales it"); u.resetNext = true; if (platform_.afterDispatch) platform_.afterDispatch(f, true); Report(u, UpscaleState::StandIn, &f); @@ -1013,8 +1030,8 @@ ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& } } u.resetNext = true; - if (PassThroughFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; } + if (LastResortFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; return rc; } @@ -1043,7 +1060,7 @@ ffxReturnCode_t FrontEnd::BrokenFrame(UpscaleContext& u, WgFrame& frame, const s } } } - if (PassThroughFrame(u, tag, frameIndex, &frame, what)) return FFX_API_RETURN_OK; // B8: never no output + if (LastResortFrame(u, tag, frameIndex, &frame, what)) return FFX_API_RETURN_OK; // B8: never no output if (LogPoint(n)) Log(tag + " ERROR U" + std::to_string(u.id) + ": " + what + " -> ERROR_RUNTIME_ERROR"); Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); return FFX_API_RETURN_ERROR_RUNTIME_ERROR; @@ -1263,6 +1280,10 @@ ffxReturnCode_t FrontEnd::DestroyContext(ffxContext* context, const ffxAllocatio if (park) u->amd = nullptr; } } + if (u->lastResortFrames || u->lastResortFailures || u->amdFailures || u->mapFailures) + Log(tag + " note U" + std::to_string(u->id) + ": fallback counts: the backend's bilinear upscale wrote " + std::to_string(u->lastResortFrames) + + " frame(s) as the last resort, " + std::to_string(u->lastResortFailures) + " frame(s) had no last resort, AMD FSR failed " + + std::to_string(u->amdFailures) + " time(s), " + std::to_string(u->mapFailures) + " frame(s) could not be mapped for the fallback"); Log(tag + " -> " + RcName(rc) + " (U" + std::to_string(u->id) + " destroyed after " + std::to_string(u->dispatches) + " dispatches" + (pending && !pending->Done() ? "; its upscaler is still starting and is destroyed when it has" : "") + (park ? "; its upscaler is parked for " + std::to_string(config_.contextParkMs) + @@ -1623,13 +1644,19 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe const std::string tag = "#" + std::to_string(call); const uint64_t frameIndex = u.dispatches++; const bool log = ShouldLogDispatch(frameIndex); - WgFrame frame; + WgFrame frame{}; std::string problem, notes; if (d.flags & (FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB | FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_PQ)) { // Perceptual input goes to AMD's FSR (spec 20, ANSWERS item 5): this frame, and the context for good when the // game keeps flagging it (kBadFrameRun). + // B8: the frame is mapped for the last resort (the stand-in is skipped for perceptual input, the backend's bilinear + // upscale is colour-space neutral), so that an unavailable or failing AMD FSR does not leave the frame without output + WgFrame resortFrame; + std::string resortProblem, resortNotes; + const bool resortMapped = + MapDispatch(d, u.create, config_, platform_.resourceInfo, u.map, frameIndex, resortFrame, resortProblem, resortNotes); return BadFrame(u, d, call, frameIndex, "non-linear (sRGB/PQ) colour flagged by the game: AMD FSR handles it", nullptr, true, - WG_ERROR_UNSUPPORTED); + WG_ERROR_UNSUPPORTED, resortMapped ? &resortFrame : nullptr); } const bool mapped = MapDispatch(d, u.create, config_, platform_.resourceInfo, u.map, frameIndex, frame, problem, notes); const bool resetAsked = frame.reset != 0; @@ -1754,7 +1781,7 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe } return AfterAmdFailure(u, tag, frameIndex, mapped ? &frame : nullptr, rc); // B8 } - if (mapped && PassThroughFrame(u, tag, frameIndex, &frame, "WrongGPU's upscaler failed (" + u.failReason + ") and AMD FSR is not available")) + if (mapped && LastResortFrame(u, tag, frameIndex, &frame, "WrongGPU's upscaler failed (" + u.failReason + ") and AMD FSR is not available")) return FFX_API_RETURN_OK; // B8: never no output Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); Log(tag + " -> ERROR_RUNTIME_ERROR"); @@ -1762,9 +1789,11 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe } ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpscale& d, uint64_t call, uint64_t frameIndex, - const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result) { + const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result, + WgFrame* lastResortFrame) { const std::string tag = "#" + std::to_string(call); const std::string what = "frame " + std::to_string(frameIndex) + ": " + problem; + WgFrame* const resort = frame ? frame : lastResortFrame; // B8: a frame the last resort can use const uint32_t run = ++u.badRun; if (!frame && d.commandList && platform_.noteDispatch) platform_.noteDispatch(d.commandList, nullptr); if (run == kBadFrameRun) { @@ -1807,12 +1836,14 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca } } // 2. AMD's FSR, for this frame only: the context made from the saved create parameters, kept for later ones. - if (config_.fallbackToAmd && CreateAmdFromSaved(u, call, false) == FFX_API_RETURN_OK) { + if (config_.fallbackToAmd && (u.amd || LogPoint(++u.amdCreateTries)) && CreateAmdFromSaved(u, call, false) == FFX_API_RETURN_OK) { ffxDispatchDescUpscale amd = d; if (!u.amdLast) amd.reset = true; // AMD's history is old, or never started u.amdLast = true; const ffxReturnCode_t rc = u.amdApi->dispatch(&u.amd, &amd.header); - if (run == 1 || rc != FFX_API_RETURN_OK) + if (rc != FFX_API_RETURN_OK) + NoteAmdFailure(u, tag, frameIndex, rc); // B8: once per context, counted + else if (run == 1) Log(tag + " note U" + std::to_string(u.id) + ": " + what + ": AMD FSR upscales this frame -> " + RcName(rc) + "; the context stays WrongGPU's (AMD FSR takes it over after " + std::to_string(kBadFrameRun) + " such frames in a row)"); if (rc == FFX_API_RETURN_OK) { @@ -1820,13 +1851,13 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca return rc; } u.amdLast = false; - if (PassThroughFrame(u, tag, frameIndex, frame, what + "; AMD FSR dispatch failed (" + RcName(rc) + ")")) - return FFX_API_RETURN_OK; // B8: the stand-in was tried first (step 1), now the frame passes through + if (LastResortFrame(u, tag, frameIndex, resort, what + "; AMD FSR failed (" + RcName(rc) + ")")) + return FFX_API_RETURN_OK; // B8: the stand-in was tried first (step 1), now the backend's bilinear upscale Report(u, UpscaleState::Failed, nullptr, what + "; AMD FSR dispatch failed: " + RcName(rc), what); return rc; } - // 3. Nobody could upscale it: the game's own colour is passed through unscaled (B8), else the frame fails, the context stays. - if (PassThroughFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; + // 3. Nobody could upscale it: the backend's bilinear upscale of the game's colour (B8), else the frame fails, the context stays. + if (LastResortFrame(u, tag, frameIndex, resort, what)) return FFX_API_RETURN_OK; if (run == 1 || ShouldLogDispatch(frameIndex)) Log(tag + (amdOnly ? " note U" : " ERROR U") + std::to_string(u.id) + ": " + what + ": no upscaler for this frame (" + (config_.fallbackToAmd ? "AMD FSR is not available" : "fallback_to_amd = 0") + ") -> " + @@ -1962,17 +1993,23 @@ ffxReturnCode_t FrontEnd::Dispatch(ffxContext* context, const ffxDispatchDescHea std::lock_guard lock(u->mutex); ++u->dispatches; const ffxReturnCode_t rc = original->dispatch(&u->amd, desc); - if (log || rc != FFX_API_RETURN_OK) Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); + const bool takenOver = u->upscaler != nullptr; // WrongGPU's upscaler is kept, unused: the context was handed to AMD + if (log || (rc != FFX_API_RETURN_OK && !takenOver)) Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); if (desc->type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE) { - if (rc != FFX_API_RETURN_OK && u->upscaler) { - // B8: a context WrongGPU handed to AMD's FSR (its upscaler is kept, unused) whose AMD dispatch fails: the stand-in, then the - // pass-through (a context that was AMD's from the start is the game's own FSR and keeps AMD's answer) - WgFrame frame; + if (rc != FFX_API_RETURN_OK && takenOver) { + // B8: a context WrongGPU handed to AMD's FSR whose AMD dispatch fails: the stand-in, then the backend's bilinear + // upscale (a context that was AMD's from the start is the game's own FSR and keeps AMD's answer). The failure is + // logged once per context (NoteAmdFailure), a frame that cannot be mapped for the fallback says why, once + WgFrame frame{}; std::string problem, notes; const uint64_t frameIndex = u->dispatches - 1; if (MapDispatch(*reinterpret_cast(desc), u->create, config_, platform_.resourceInfo, u->map, frameIndex, frame, problem, notes)) return AfterAmdFailure(*u, tag, frameIndex, &frame, rc); + NoteAmdFailure(*u, tag, frameIndex, rc); + if (++u->mapFailures == 1) + Log(tag + " ERROR U" + std::to_string(u->id) + ": frame " + std::to_string(frameIndex) + + ": AMD FSR failed and the frame cannot be mapped for the fallback (" + problem + "); the error goes back to the game"); } Report(*u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); diff --git a/clean/fsr/src/frontend.h b/clean/fsr/src/frontend.h index 2f910635..b8949bb5 100644 --- a/clean/fsr/src/frontend.h +++ b/clean/fsr/src/frontend.h @@ -70,11 +70,6 @@ struct Platform { std::function diagnosticFailure; std::function diagnosticResult; std::function standIn; - // The last resort for a frame nothing could upscale (B8): records into frame.command_list a copy of the game's own colour - // into the output texture, unscaled (the active region, cut to both textures, at the output's origin). False with the - // reason in *why when it cannot (another format family, no list); the frame then has no output and the front end says so. - // May be empty (no pass-through on this platform). - std::function passThrough; // Every upscale dispatch WrongGPU's upscaler recorded (WG_OK), with its frame (frame capture, capture.h); standIn: // the one-frame stand-in upscaled it. May be empty. std::function afterDispatch; @@ -182,7 +177,8 @@ class FrontEnd { // One frame WrongGPU's upscaler cannot take (kBadFrameRun): the stand-in upscales it (`frame` usable) or AMD's FSR // does, and the context stays WrongGPU's; `amdOnly`: never the stand-in (perceptual colour). ffxReturnCode_t BadFrame(UpscaleContext& u, const ffxDispatchDescUpscale& d, uint64_t call, uint64_t frameIndex, - const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result); + const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result, + WgFrame* lastResortFrame = nullptr); // B8: the mapped frame for the last resort when `frame` is null UpscaleContext* FindOwn(ffxContext* context); std::string Name(ffxContext* context); // "U1(standin)", "amd:0x..." for logs void Log(const std::string& line); @@ -225,12 +221,14 @@ class FrontEnd { void ResizeForFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag); // bug hunt H ffxReturnCode_t BrokenFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag, uint64_t frameIndex); // bug hunt F1 // B8, the refused-frame contract: what a frame gets is explicit. Order: WrongGPU's upscaler, the stand-in, AMD's FSR, and - // last the game's own colour passed through unscaled (Platform::passThrough) with one warning line; the game is never - // answered with an error for a frame whose textures could be copied (a custom slot excepted: its host upscales on an - // error). PassThroughFrame: the last step (true: the frame has an output). AfterAmdFailure: AMD's dispatch failed for this - // frame (rc): the stand-in, then the pass-through; else rc. - bool PassThroughFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what); + // last the backend's own bilinear upscale of the game's colour (WG_FRAME_BILINEAR: the Converter's fallback pass, format + // aware, the full output, no HIP), with one warning line per context; the game is answered an error only when even that + // cannot be recorded (the reason is logged), and in an OptiScaler custom slot, whose host upscales on an error. + // LastResortFrame: the last step (true: the frame has an output). AfterAmdFailure: AMD's dispatch failed for this frame + // (rc): the stand-in, then the last resort; else rc. NoteAmdFailure: AMD's failures are logged once per context, counted. + bool LastResortFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what); ffxReturnCode_t AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc); + void NoteAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, ffxReturnCode_t rc); void Fail(UpscaleContext& u, const std::string& why, uint64_t call, bool error = true); // Platform::status for one upscale dispatch of `u` (frame: the mapped frame when WrongGPU upscaled it, else null). // amdReason: why AMD's FSR upscaled this one frame of a context that stays WrongGPU's (state Amd). diff --git a/clean/fsr/src/fsr30_hook.cpp b/clean/fsr/src/fsr30_hook.cpp index e6d70306..8aecd8d7 100644 --- a/clean/fsr/src/fsr30_hook.cpp +++ b/clean/fsr/src/fsr30_hook.cpp @@ -244,7 +244,7 @@ bool Hook::RunStandIn(Context& c, const ffxDispatchDescUpscale& dispatch, const } c.backend = backend; } - WgFrame frame; + WgFrame frame{}; std::string problem, notes; const uint64_t index = c.frames; const bool mapped = MapDispatch(dispatch, c.create, config_, platform_.resourceInfo, c.map, index, frame, problem, notes); diff --git a/clean/fsr/src/passthrough_d3d12.cpp b/clean/fsr/src/passthrough_d3d12.cpp deleted file mode 100644 index 3ca4cc9a..00000000 --- a/clean/fsr/src/passthrough_d3d12.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-License-Identifier: MIT -// The last resort of the front end's refused-frame contract (B8, frontend.h Platform::passThrough): when nothing could -// upscale a frame, the game's own colour is copied into the output texture, unscaled, so that the game gets an image and an -// answer it can use instead of an error and an output nobody wrote. WrongGPU's own code. -#include "passthrough_d3d12.h" - -#define WIN32_LEAN_AND_MEAN -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#include - -#include -#include -#include - -namespace wgfsr { - -namespace { - -// The typeless group of a format: CopyTextureRegion needs both textures in the same one. -DXGI_FORMAT TypelessGroup(DXGI_FORMAT f) { - switch (f) { - case DXGI_FORMAT_R32G32B32A32_TYPELESS: case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32A32_UINT: - case DXGI_FORMAT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_TYPELESS; - case DXGI_FORMAT_R16G16B16A16_TYPELESS: case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16B16A16_UNORM: - case DXGI_FORMAT_R16G16B16A16_UINT: case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16B16A16_SINT: - return DXGI_FORMAT_R16G16B16A16_TYPELESS; - case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R10G10B10A2_UNORM: case DXGI_FORMAT_R10G10B10A2_UINT: - return DXGI_FORMAT_R10G10B10A2_TYPELESS; - case DXGI_FORMAT_R8G8B8A8_TYPELESS: case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - case DXGI_FORMAT_R8G8B8A8_UINT: case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8B8A8_SINT: - return DXGI_FORMAT_R8G8B8A8_TYPELESS; - case DXGI_FORMAT_B8G8R8A8_TYPELESS: case DXGI_FORMAT_B8G8R8A8_UNORM: case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - return DXGI_FORMAT_B8G8R8A8_TYPELESS; - default: return f; - } -} - -D3D12_RESOURCE_BARRIER Transition(ID3D12Resource* r, D3D12_RESOURCE_STATES from, D3D12_RESOURCE_STATES to) { - D3D12_RESOURCE_BARRIER b = {}; - b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - b.Transition.pResource = r; - b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - b.Transition.StateBefore = from; - b.Transition.StateAfter = to; - return b; -} - -} // namespace - -bool CopyColorToOutput(const WgFrame& f, std::string* why) { - auto fail = [&](const char* m) { - if (why) *why = m; - return false; - }; - auto* list = static_cast(f.command_list); - auto* src = static_cast(f.color.resource); - auto* dst = static_cast(f.output.resource); - if (!list || !src || !dst) return fail("no command list, colour or output texture"); - const D3D12_RESOURCE_DESC sd = src->GetDesc(), dd = dst->GetDesc(); - if (sd.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || dd.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) - return fail("the colour or the output is not a 2D texture"); - if (sd.SampleDesc.Count != 1 || dd.SampleDesc.Count != 1) return fail("a multisampled texture cannot be copied"); - if (TypelessGroup(sd.Format) != TypelessGroup(dd.Format)) - return fail("the colour and the output texture are in different format families"); - const uint32_t x = f.render_x, y = f.render_y; - if (x >= sd.Width || y >= sd.Height) return fail("the active region lies outside the colour texture"); - const uint32_t w = (uint32_t)std::min({f.render_width ? f.render_width : sd.Width, sd.Width - x, dd.Width}); - const uint32_t h = (uint32_t)std::min({f.render_height ? f.render_height : sd.Height, sd.Height - y, dd.Height}); - if (!w || !h) return fail("an empty region"); - const D3D12_RESOURCE_STATES from_src = static_cast(f.color.state); - const D3D12_RESOURCE_STATES from_dst = static_cast(f.output.state); - - D3D12_RESOURCE_BARRIER before[2], after[2]; - UINT nb = 0, na = 0; - if (from_src != D3D12_RESOURCE_STATE_COPY_SOURCE) { - before[nb++] = Transition(src, from_src, D3D12_RESOURCE_STATE_COPY_SOURCE); - after[na++] = Transition(src, D3D12_RESOURCE_STATE_COPY_SOURCE, from_src); - } - if (from_dst != D3D12_RESOURCE_STATE_COPY_DEST) { - before[nb++] = Transition(dst, from_dst, D3D12_RESOURCE_STATE_COPY_DEST); - after[na++] = Transition(dst, D3D12_RESOURCE_STATE_COPY_DEST, from_dst); - } - if (nb) list->ResourceBarrier(nb, before); - D3D12_TEXTURE_COPY_LOCATION s = {}, d = {}; - s.pResource = src; - s.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - s.SubresourceIndex = 0; - d.pResource = dst; - d.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - d.SubresourceIndex = 0; - D3D12_BOX box = {x, y, 0, x + w, y + h, 1}; - list->CopyTextureRegion(&d, 0, 0, 0, &s, &box); - if (na) list->ResourceBarrier(na, after); - return true; -} - -} // namespace wgfsr diff --git a/clean/fsr/src/passthrough_d3d12.h b/clean/fsr/src/passthrough_d3d12.h deleted file mode 100644 index a2b3c72b..00000000 --- a/clean/fsr/src/passthrough_d3d12.h +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: MIT -#pragma once -// The last resort of the front end's refused-frame contract (B8): the game's own colour copied into the output texture, -// unscaled. Records into frame.command_list (D3D12 CopyTextureRegion with the transitions the textures' states ask for, and -// back); false with the reason in *why when it cannot (no list, another format family, a multisampled texture, an empty region). -#include - -#include "../include/wronggpu_upscaler.h" - -namespace wgfsr { -bool CopyColorToOutput(const WgFrame& frame, std::string* why); -} diff --git a/clean/fsr/src/win_util.h b/clean/fsr/src/win_util.h index b3f71f2c..0e72e086 100644 --- a/clean/fsr/src/win_util.h +++ b/clean/fsr/src/win_util.h @@ -14,7 +14,6 @@ #include "d3d12_hooks.h" #include "overlay.h" #include "param_map.h" -#include "passthrough_d3d12.h" namespace wgwin { @@ -78,15 +77,6 @@ const wgfsr::OriginalApi* CompareApi(const std::string& path); // detail: why not, for the log. wgfsr::ProbeResult CheckProviderModule(HMODULE m, const std::wstring& requested, std::string& detail); -// B8: the front end's Platform has a pass-through (the game's colour copied into the output, the last resort for a frame -// nothing could upscale); another platform type (the FSR 3.0 hook's) has none and is left as it is. -template -auto SetPassThrough(PlatformT& p, int) -> decltype(p.passThrough = &wgfsr::CopyColorToOutput, void()) { - p.passThrough = &wgfsr::CopyColorToOutput; -} -template -void SetPassThrough(PlatformT&, long) {} - // Interface version 2 services of a front end's platform (FrontEnd or fsr30::Hook): the split service, the dispatch // notes for the submission trace, the one-frame stand-in, the overlay's status. Also passes this DLL's settings to // the D3D12 hooks and the overlay. @@ -119,7 +109,6 @@ void AddSplitServices(PlatformT& p, const wgfsr::Config& config) { p.services = &SplitServices; p.noteDispatch = &NoteDispatch; p.standIn = &StandInForFallback; - SetPassThrough(p, 0); // the last resort of the refused-frame contract (frontend.h), where the platform has it } bool D3D12ResourceInfo(void* resource, wgfsr::ResourceInfo* out); diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 402f36d4..7208a563 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -157,6 +157,8 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) +static bool g_bilinearFails = false; // B8: the backend's bilinear last resort (WG_FRAME_BILINEAR) fails +static std::vector g_bilinearFrames; // the frames it was asked for static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { ++g_createCalls; g_createInfo = *info; @@ -170,6 +172,10 @@ static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { return WG_OK; } static WgResult FakeDispatch(WgUpscaler*, const WgFrame* frame) { + if (frame->struct_size >= sizeof(WgFrame) && (frame->flags & WG_FRAME_BILINEAR)) { // B8: no network, the last resort + g_bilinearFrames.push_back(*frame); + return g_bilinearFails ? WG_ERROR_DEVICE : WG_OK; + } g_frames.push_back(*frame); if (int(g_frames.size()) - 1 == g_parameterErrorAt) return WG_ERROR_PARAMETER; if (g_unsupportedFrom >= 0 && int(g_frames.size()) - 1 >= g_unsupportedFrom) return WG_ERROR_UNSUPPORTED; @@ -187,7 +193,10 @@ static void FakeDestroy(WgUpscaler* u) { } static uint64_t FakeMemory(WgUpscaler*) { return 12345; } static const WgUpscalerBackend g_backend{sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "fake upscaler", - FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT}; + FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME}; +// A backend that cannot write a frame without the network (no WG_BACKEND_BILINEAR_FRAME) +static const WgUpscalerBackend g_backendNoBilinear{sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "fake upscaler (no bilinear)", + FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT}; // The same backend as a version 1 DLL would return it (struct without backend_flags). static const WgUpscalerBackend g_backendV1{offsetof(WgUpscalerBackend, backend_flags), 1, "fake upscaler v1", FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, 0xFFFFFFFFu}; @@ -199,10 +208,6 @@ static WgCreateInfo g_standInCreate{}; static int g_standInDestroyed = 0; static bool g_standInCreateFails = false; // B8: the stand-in cannot be made static bool g_standInDispatchFails = false; // B8: the stand-in's dispatch fails -static bool g_passThroughOn = false; // B8: Platform::passThrough exists -static bool g_passThroughOk = true; // ... and succeeds -static std::vector g_passFrames; // the frames it was given -static std::function g_passThroughReal; // test_refusal_integration.cpp: the real copy static WgResult StandInCreate(const WgCreateInfo* info, WgUpscaler** out) { g_standInCreate = *info; if (g_standInCreateFails) return WG_ERROR_DEVICE; @@ -313,16 +318,6 @@ static std::unique_ptr MakeFrontEnd(const Config& config) { if (frame) frame->command_list_type = 2; // as the D3D12 side would fill it in }; p.standIn = [](const Config&) -> const WgUpscalerBackend* { return &g_standIn; }; - if (g_passThroughOn) - p.passThrough = [](const WgFrame& f, std::string* why) { - g_passFrames.push_back(f); - if (g_passThroughReal) return g_passThroughReal(f, why); - if (!g_passThroughOk) { - if (why) *why = "the fake pass-through refuses"; - return false; - } - return true; - }; p.splitBlocked = [](void*) -> const char* { ++g_splitBlockedAsked; return g_splitBlocked; @@ -379,10 +374,8 @@ static void Reset() { g_useBackend = &g_backend; g_standInFrames.clear(); g_standInCreateFails = g_standInDispatchFails = false; - g_passThroughOn = false; - g_passThroughOk = true; - g_passFrames.clear(); - g_passThroughReal = nullptr; + g_bilinearFails = false; + g_bilinearFrames.clear(); g_standInCreate = WgCreateInfo{}; g_standInDestroyed = 0; g_servicesAsked.clear(); @@ -1410,7 +1403,7 @@ static void TestInterfaceVersions() { CHECK(fe1->CreateContext(&ctx, &c.upscale.header, nullptr) == FFX_API_RETURN_OK); CHECK(g_createInfo.interface_version == 1 && g_createInfo.struct_size == offsetof(WgCreateInfo, services)); CHECK(g_createInfo.services == nullptr && g_servicesAsked.size() == 1); - CHECK(BackendFlags(&g_backendV1) == 0 && BackendVersion(&g_backendV1) == 1 && BackendFlags(&g_backend) == WG_BACKEND_NEEDS_SPLIT); + CHECK(BackendFlags(&g_backendV1) == 0 && BackendVersion(&g_backendV1) == 1 && BackendFlags(&g_backend) == (WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME)); d = MakeDispatch(); CHECK(fe1->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); CHECK(g_frames.size() == 1 && g_frames[0].struct_size == offsetof(WgFrame, command_queue)); @@ -1902,19 +1895,19 @@ static void TestFailedFrameProviderTruth() { if (failure == 2) g_amdDispatchResult = FFX_API_RETURN_ERROR_RUNTIME_ERROR; auto dispatch = MakeDispatch(); if (failure == 3) dispatch.flags = FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB; - if (failure == 2) { - // B8: AMD's dispatch fails after the upscaler failed: the stand-in upscales the frame (it was an error before) - CHECK(fe->Dispatch(&ctx, &dispatch.header) == FFX_API_RETURN_OK); - CHECK(!g_statuses.empty() && g_statuses.back().state == UpscaleState::StandIn); - } else { - CHECK(fe->Dispatch(&ctx, &dispatch.header) != FFX_API_RETURN_OK); + // B8: nothing upscales the frame, as before, but the answer is explicit: AMD's dispatch failing after the upscaler failed + // is a stand-in frame (failure 2); without AMD (failures 0, 1: no AMD, AMD cannot be created; failure 3: a non-linear frame) + // the backend's bilinear upscale writes it and the status says so. All of them used to be errors. + CHECK(fe->Dispatch(&ctx, &dispatch.header) == FFX_API_RETURN_OK); CHECK(!g_statuses.empty()); if (!g_statuses.empty()) { const auto& status = g_statuses.back(); - CHECK(status.state != UpscaleState::Amd && status.state != UpscaleState::Network && - status.state != UpscaleState::StandIn && status.state != UpscaleState::Compare); - CHECK(!status.reason.empty()); - } + if (failure == 2) { + CHECK(status.state == UpscaleState::StandIn); + } else { + CHECK(status.state == UpscaleState::Failed && status.reason.find("bilinearly") != std::string::npos); + CHECK(g_bilinearFrames.size() == 1); + } } CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } @@ -2447,7 +2440,7 @@ static void TestRefusedFrames() { for (int i = 0; i < 8; ++i) CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); // every frame has an upscaler CHECK(g_frames.size() == 2 && g_standInFrames.empty()); // frame 0 the network's, frame 1 refused: AMD from there on CHECK(!g_amd.empty() && g_amd.back().fn == "dispatch" && g_statuses.back().state == UpscaleState::Amd); - CHECK(CountLog("HIP") == 0); // no HIP runtime on the way + CHECK(CountLog("about to start the HIP runtime") == 0); // no HIP runtime on the way CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); // without AMD's FSR: each refused frame goes to the stand-in (five in a row, then a taken frame, then two more @@ -2468,48 +2461,54 @@ static void TestRefusedFrames() { CHECK(g_statuses.back().state == want[i]); } CHECK(g_frames.size() == want.size() && g_standInFrames.size() == 7 && g_amd.empty()); - CHECK(CountLog("HIP") == 0); + CHECK(CountLog("about to start the HIP runtime") == 0); CHECK(CountLog("AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take") == 1); CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } } -// B8 (REVIEW-215d P1): what a refused frame gets is explicit. The upscaler answers WG_ERROR_UNSUPPORTED for frames 1 .. 3; the -// stand-in cannot be made, or fails, AMD's FSR is missing or fails: the game's own colour is passed through unscaled with -// one warning line and the answer is OK, never an error for a frame whose textures can be copied. Every model (the contract is -// shared); a custom slot keeps returning the error (its host upscales). +// B8 (REVIEW-215d P1, REVIEW-228): what a refused frame gets is explicit. The upscaler answers WG_ERROR_UNSUPPORTED for frames +// 1 .. 3; the stand-in cannot be made, or fails, AMD's FSR is missing, cannot be created or fails: the backend's own bilinear +// upscale of the game's colour (WG_FRAME_BILINEAR) writes the output with one warning line per context and the answer is OK, +// never an error for a frame whose resources can be used. Every model (the contract is shared); a custom slot keeps getting +// the error (its host upscales); when the last resort is impossible the error goes back with the reason logged, also after an +// earlier success; AMD's failures are logged once per context, however long the run. static void TestRefusedFrameContract() { const uint64_t models[] = {kWrongGpuProviderVersionId, kWrongGpuKProviderVersionId, kWrongGpuLProviderVersionId}; for (const uint64_t model : models) { - // setup: no AMD / AMD with this dispatch result; stand-in made and working / create fails / dispatch fails; - // pass-through absent / working / refusing; custom slot struct Case { const char* name; bool amd; ffxReturnCode_t amdResult; - bool standInCreateFails, standInDispatchFails, passThrough, passOk, customSlot; + ffxReturnCode_t amdCreate; + bool standInCreateFails, standInDispatchFails, bilinearFails, backendHasBilinear, customSlot; }; const ffxReturnCode_t amdBad = FFX_API_RETURN_ERROR_RUNTIME_ERROR; + const ffxReturnCode_t ok = FFX_API_RETURN_OK; const Case cases[] = { - {"no AMD, stand-in create fails, pass-through ok", false, FFX_API_RETURN_OK, true, false, true, true, false}, - {"no AMD, stand-in dispatch fails, pass-through ok", false, FFX_API_RETURN_OK, false, true, true, true, false}, - {"no AMD, stand-in fails, pass-through refuses", false, FFX_API_RETURN_OK, true, false, true, false, false}, - {"no AMD, stand-in fails, no pass-through", false, FFX_API_RETURN_OK, true, false, false, true, false}, - {"AMD dispatch fails, stand-in ok", true, amdBad, false, false, true, true, false}, - {"AMD dispatch fails, stand-in create fails, pass-through ok", true, amdBad, true, false, true, true, false}, - {"AMD dispatch fails, stand-in dispatch fails, pass-through ok", true, amdBad, false, true, true, true, false}, - {"AMD dispatch fails, stand-in fails, pass-through refuses", true, amdBad, true, false, true, false, false}, - {"custom slot, no AMD, stand-in fails", false, FFX_API_RETURN_OK, true, false, true, true, true}, + {"no AMD, stand-in create fails", false, ok, ok, true, false, false, true, false}, + {"no AMD, stand-in dispatch fails", false, ok, ok, false, true, false, true, false}, + {"no AMD, stand-in fails, bilinear fails", false, ok, ok, true, false, true, true, false}, + {"no AMD, stand-in fails, the backend has no bilinear", false, ok, ok, true, false, false, false, false}, + {"AMD create fails, stand-in ok", true, ok, FFX_API_RETURN_NO_PROVIDER, false, false, false, true, false}, + {"AMD create fails, stand-in fails", true, ok, FFX_API_RETURN_NO_PROVIDER, true, false, false, true, false}, + {"AMD dispatch fails, stand-in ok", true, amdBad, ok, false, false, false, true, false}, + {"AMD dispatch fails, stand-in create fails", true, amdBad, ok, true, false, false, true, false}, + {"AMD dispatch fails, stand-in dispatch fails", true, amdBad, ok, false, true, false, true, false}, + {"AMD dispatch fails, stand-in fails, bilinear fails", true, amdBad, ok, true, false, true, true, false}, + {"custom slot, no AMD, stand-in fails", false, ok, ok, true, false, false, true, true}, }; for (const Case& c : cases) { + const int failuresBefore = g_failures; Reset(); g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; g_originalAvailable = c.amd; g_amdDispatchResult = c.amdResult; + g_amdCreateResult = c.amdCreate; g_standInCreateFails = c.standInCreateFails; g_standInDispatchFails = c.standInDispatchFails; - g_passThroughOn = c.passThrough; - g_passThroughOk = c.passOk; + g_bilinearFails = c.bilinearFails; + g_useBackend = c.backendHasBilinear ? &g_backend : &g_backendNoBilinear; Config config; config.hosted = true; config.customSlot = c.customSlot; @@ -2520,47 +2519,98 @@ static void TestRefusedFrameContract() { CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK && fe->OwnContextCount() == 1); ffxDispatchDescUpscale d = MakeDispatch(); CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && g_statuses.back().state == UpscaleState::Network); - g_unsupportedAt = {1, 2, 3}; + const int kFrames = 300; // a long run: the logs must not grow with it + std::set refused; + for (int i = 1; i <= kFrames; ++i) refused.insert(i); + g_unsupportedAt = refused; std::vector rcs; - for (int i = 0; i < 3; ++i) rcs.push_back(fe->Dispatch(&ctx, &d.header)); + for (int i = 0; i < kFrames; ++i) rcs.push_back(fe->Dispatch(&ctx, &d.header)); const bool standInWorks = !c.standInCreateFails && !c.standInDispatchFails; - const bool passes = c.passThrough && c.passOk && !c.customSlot; - // the first refused frame goes to AMD when it exists (the context is AMD's from then on, and AMD's dispatch fails for - // every frame): each frame has the stand-in, else the pass-through, else AMD's own error - if (c.amd && c.amdResult != FFX_API_RETURN_OK) { - for (ffxReturnCode_t rc : rcs) CHECK(rc == (standInWorks || passes ? FFX_API_RETURN_OK : amdBad)); - if (standInWorks) { - CHECK(g_standInFrames.size() == 3 && g_passFrames.empty()); - } else if (passes) { - CHECK(g_passFrames.size() == 3 && CountLog("the game's own colour is passed through to the output unscaled") == 1); - } else { - CHECK(g_passFrames.size() == (c.passThrough ? 3u : 0u)); - CHECK(CountLog("cannot be passed through") == 1); - } - CHECK(CountLog("HIP") == 0); - } else if (!c.amd) { - for (ffxReturnCode_t rc : rcs) CHECK(rc == (standInWorks || passes ? FFX_API_RETURN_OK : FFX_API_RETURN_ERROR_RUNTIME_ERROR)); - if (!standInWorks) { - CHECK(g_passFrames.size() == (c.passThrough && !c.customSlot ? 3u : 0u)); - if (passes) { - CHECK(g_statuses.back().state == UpscaleState::Failed && - g_statuses.back().reason.find("passed through unscaled") != std::string::npos); - CHECK(CountLog("the game's own colour is passed through to the output unscaled") == 1); // one line, not one a frame - for (const WgFrame& f : g_passFrames) CHECK(f.command_list && f.color.resource && f.output.resource); - } else if (!c.customSlot) { - CHECK(CountLog("cannot be passed through") == 1); - CHECK(g_statuses.back().state == UpscaleState::Failed); - } else { - CHECK(g_passFrames.empty()); // a custom slot's host upscales on the error - } - } else { - CHECK(g_passFrames.empty() && g_standInFrames.size() == 3); - } - CHECK(CountLog("HIP") == 0); + const bool lastResort = c.backendHasBilinear && !c.bilinearFails && !c.customSlot; + const bool amdFailing = c.amd && (c.amdResult != ok); + const bool answered = standInWorks || lastResort; // every frame has an output + // with a working AMD (or none that fails) the first refused frame is AMD's / the stand-in's; the cases here are + // those where AMD is absent, cannot be created, or fails + for (ffxReturnCode_t rc : rcs) CHECK(rc == (answered ? FFX_API_RETURN_OK : (amdFailing ? amdBad : FFX_API_RETURN_ERROR_RUNTIME_ERROR))); + if (answered && standInWorks) { + CHECK(g_standInFrames.size() == (size_t)kFrames && g_bilinearFrames.empty()); + } else if (answered) { + CHECK(g_bilinearFrames.size() == (size_t)kFrames); + CHECK(g_statuses.back().state == UpscaleState::Failed && + g_statuses.back().reason.find("bilinearly") != std::string::npos); + for (const WgFrame& f : g_bilinearFrames) + CHECK((f.flags & WG_FRAME_BILINEAR) && f.command_list && f.color.resource && f.output.resource); + CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); // one line, not one a frame + } else if (c.customSlot) { + CHECK(g_bilinearFrames.empty()); // a custom slot's host upscales on the error + } else { + CHECK(CountLog("the backend's bilinear upscale is not possible") >= 1); + CHECK(CountLog("the backend's bilinear upscale is not possible") <= 4); // the first, then at 10, 100 + } + // logs do not grow with the run: AMD's failure and the stand-in's notes at most once per context + CHECK(CountLog("AMD FSR dispatch failed (") <= 1); + CHECK(CountLog("about to start the HIP runtime") == 0); + CHECK(g_log.size() < 60); + if (g_failures != failuresBefore) { // the log of a failed case + std::printf("case: %s (%zu log lines)\n", c.name, g_log.size()); + for (size_t k = 0; k < g_log.size() && k < 70; ++k) std::printf(" log: %.220s\n", g_log[k].c_str()); } CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + if (!c.customSlot && !answered) CHECK(CountLog("fallback counts:") == 1); } } + + // a failure after an earlier success is reported too: the stand-in cannot be made, the bilinear upscale writes frames 1-2, then + // a frame whose output texture is missing has no last resort: its reason is logged although an earlier frame succeeded + { + Reset(); + g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_originalAvailable = false; + g_standInCreateFails = true; + Config config; + config.hosted = true; + auto fe = MakeFrontEnd(config); + UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); + own.version.versionId = kWrongGpuProviderVersionId; + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK); + ffxDispatchDescUpscale d = MakeDispatch(); + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); + g_unsupportedAt = {1, 2, 3}; + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); + CHECK(g_bilinearFrames.size() == 2 && CountLog("the backend's bilinear upscale is not possible") == 0); + ffxDispatchDescUpscale bad = d; + bad.output.resource = nullptr; + CHECK(fe->Dispatch(&ctx, &bad.header) != FFX_API_RETURN_OK); + CHECK(CountLog("the backend's bilinear upscale is not possible") == 1); // the first failure, with its reason, after two successes + CHECK(CountLog("the frame has no command list, colour texture or output texture") + CountLog("the frame's inputs could not be mapped") == 1); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + + // a frame the game flags as non-linear (sRGB / PQ) is not a refused frame: it goes to AMD's FSR, and when AMD is missing or + // fails the mapped frame still has the backend's bilinear upscale (colour-space neutral) instead of an error + for (const bool amd : {false, true}) { + Reset(); + g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_originalAvailable = amd; + g_amdDispatchResult = amd ? FFX_API_RETURN_ERROR_RUNTIME_ERROR : FFX_API_RETURN_OK; + Config config; + config.hosted = true; + auto fe = MakeFrontEnd(config); + UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); + own.version.versionId = kWrongGpuProviderVersionId; + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK); + ffxDispatchDescUpscale d = MakeDispatch(); + d.flags |= FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB; + for (int i = 0; i < 5; ++i) CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); + CHECK(g_bilinearFrames.size() == 5 && g_standInFrames.empty()); // no stand-in for perceptual input + for (const WgFrame& f : g_bilinearFrames) CHECK(f.color.resource && f.output.resource && f.command_list); + CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); + CHECK(CountLog("AMD FSR dispatch failed (") <= 1 && CountLog("about to start the HIP runtime") == 0); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + g_useBackend = &g_backend; } static void TestSplitBlocked() { diff --git a/clean/fsr/tests/test_refusal_integration.cpp b/clean/fsr/tests/test_refusal_integration.cpp index b663b2d1..6bfcea6c 100644 --- a/clean/fsr/tests/test_refusal_integration.cpp +++ b/clean/fsr/tests/test_refusal_integration.cpp @@ -2,8 +2,10 @@ // B8 (REVIEW-215d P2): the front end and the REAL network backend (the runtime DLL's Context, the same code a game runs) with // a controllable executor (executor=dx12-test: the D3D12 route, scripted frame by frame), driving refused frames for model K // and, as the control, model M; with and without AMD's FSR; repeated; with the stand-in working and failing; and with the -// real last resort (passthrough_d3d12.cpp) copying the game's colour into the output, checked on the output's pixels. HIP is -// never started: no amdhip64 module is loaded in this process and the backend never logs the HIP runtime's start. +// real last resort (the backend's own bilinear output pass, requested with WG_FRAME_BILINEAR) writing the output, checked on +// EVERY pixel of the output (a linear ramp as the colour, so the bilinear result is known) for consecutive frames, each after +// the output was filled with a sentinel. HIP is never started: the runtime DLL's counter of HIP executors made stays 0 +// (wgDiagHipExecutorsMade), no amdhip64 module is loaded in this process, the backend never logs the HIP runtime's start. // // Windows, a D3D12 device (WARP is enough, no GPU slot needed; a GPU through gpu_slot also works) and the runtime DLL of a build // (python clean/runner/build.py --rocm --out --runtime-only). Not part of the CI (no runtime DLL there); the @@ -14,18 +16,21 @@ // clean/fsr/src/{frontend,param_map,ffx_describe,config,fsr30_hook,fsr30_map,amd_compare,async_create}.cpp // -ld3d12 -ldxgi -o test_refusal_integration.exe // test_refusal_integration.exe \wronggpu_runtime.dll +// Without the DLL it FAILS (exit 2): a gate that runs it cannot pass by skipping; --skip-if-missing is for a developer's loop. #define main wg_frontend_unit_main #include "test_frontend.cpp" #undef main +#define NOMINMAX #include #include #include +#include +#include #include #include -#include "../src/passthrough_d3d12.h" namespace { @@ -100,8 +105,32 @@ void Begin(Gpu& g) { g.list->Reset(g.alloc, nullptr); } -// The colour texture's pixel (x, y): RGBA16F, a pattern the output's copy can be checked against -uint16_t Pixel(UINT x, UINT y, UINT channel) { return (uint16_t)(0x3400 + ((x * 7 + y * 13 + channel * 101) & 0x3FF)); } +// FP32 -> FP16 bits (round to nearest even), for values in [0, 1] +uint16_t Half(float f) { + uint32_t x; + std::memcpy(&x, &f, 4); + const int e = (int)((x >> 23) & 255) - 112; + uint32_t m = x & 0x7fffff; + if (f == 0.0f) return 0; + if (e <= 0) return 0; // (the ramp's values are not that small except 0) + uint32_t r = ((uint32_t)e << 10) | (m >> 13); + const uint32_t rem = m & 0x1fff; + if (rem > 0x1000 || (rem == 0x1000 && (r & 1))) ++r; + return (uint16_t)r; +} +float FromHalf(uint16_t h) { + const uint32_t e = (h >> 10) & 31, m = h & 1023; + if (e == 0) return (float)m / 16777216.0f * (h & 0x8000 ? -1.0f : 1.0f); + uint32_t x = ((uint32_t)(h & 0x8000) << 16) | ((e + 112) << 23) | (m << 13); + float f; + std::memcpy(&f, &x, 4); + return f; +} +// The colour texture's pixel (x, y), channel c: R = x / 1705, G = y / 959, B = 0.5, A = 0.25 (a linear ramp: the bilinear +// upscale of it is the ramp again, so that every output pixel has a known value) +uint16_t Pixel(UINT x, UINT y, UINT channel) { + return Half(channel == 0 ? (float)x / (float)(kRenderW - 1) : channel == 1 ? (float)y / (float)(kRenderH - 1) : channel == 2 ? 0.5f : 0.25f); +} bool MakeGpu(Gpu& g) { IDXGIFactory4* f = nullptr; @@ -164,8 +193,48 @@ bool MakeGpu(Gpu& g) { return true; } -// Row 0 of the output texture, the first `pixels` pixels as RGBA16F halves -bool ReadOutputRow0(Gpu& g, UINT pixels, std::vector* out) { +// Fills the output texture with a sentinel (0.123 in every channel), through an upload buffer, so that a pixel the frame does +// not write stays visible +bool FillOutputSentinel(Gpu& g) { + D3D12_RESOURCE_DESC od = g.output->GetDesc(); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; + UINT rows = 0; + UINT64 rowBytes = 0, total = 0; + g.device->GetCopyableFootprints(&od, 0, 1, 0, &fp, &rows, &rowBytes, &total); + ID3D12Resource* up = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); + if (!up) return false; + uint8_t* map = nullptr; + up->Map(0, nullptr, reinterpret_cast(&map)); + const uint16_t v = Half(0.123f); + for (UINT y = 0; y < rows; ++y) { + auto* row = reinterpret_cast(map + (size_t)fp.Footprint.RowPitch * y); + for (UINT x = 0; x < kOutW * 4; ++x) row[x] = v; + } + up->Unmap(0, nullptr); + D3D12_RESOURCE_BARRIER b = {}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition.pResource = g.output; + b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + b.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; + g.list->ResourceBarrier(1, &b); + D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {}; + dst.pResource = g.output; + dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + src.pResource = up; + src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + src.PlacedFootprint = fp; + g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + std::swap(b.Transition.StateBefore, b.Transition.StateAfter); + g.list->ResourceBarrier(1, &b); + Submit(g); + Begin(g); + up->Release(); + return true; +} + +// The whole output texture as RGBA16F halves, row by row (kOutW * 4 per row) +bool ReadOutput(Gpu& g, std::vector* out) { D3D12_RESOURCE_DESC od = g.output->GetDesc(); D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; UINT rows = 0; @@ -173,6 +242,11 @@ bool ReadOutputRow0(Gpu& g, UINT pixels, std::vector* out) { g.device->GetCopyableFootprints(&od, 0, 1, 0, &fp, &rows, &rowBytes, &total); ID3D12Resource* rb = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); if (!rb) return false; + g.list->Close(); + ID3D12CommandList* l[] = {g.list}; + g.queue->ExecuteCommandLists(1, l); + Wait(g); + g.device->GetDeviceRemovedReason(); Begin(g); D3D12_RESOURCE_BARRIER b = {}; b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; @@ -193,12 +267,37 @@ bool ReadOutputRow0(Gpu& g, UINT pixels, std::vector* out) { Submit(g); uint8_t* map = nullptr; rb->Map(0, nullptr, reinterpret_cast(&map)); - out->assign(reinterpret_cast(map), reinterpret_cast(map) + (size_t)pixels * 4); + out->resize((size_t)kOutW * kOutH * 4); + for (UINT y = 0; y < kOutH; ++y) + std::memcpy(out->data() + (size_t)y * kOutW * 4, map + (size_t)fp.Footprint.RowPitch * y, (size_t)kOutW * 8); rb->Unmap(0, nullptr); rb->Release(); + Begin(g); return true; } +// Every output pixel against the converter's bilinear upscale of the ramp (convert.cpp PASS_FALLBACK: the sample position +// (o + 0.5) * R / O - 0.5, the taps clamped to the render region; alpha 1, or the colour's alpha for model K) +size_t BadPixels(const std::vector& px, bool model_k, float* worst) { + size_t bad = 0; + *worst = 0; + for (UINT oy = 0; oy < kOutH; ++oy) { + const float sy = std::min(std::max(((float)oy + 0.5f) * kRenderH / kOutH - 0.5f, 0.0f), (float)(kRenderH - 1)); + for (UINT ox = 0; ox < kOutW; ++ox) { + const float sx = std::min(std::max(((float)ox + 0.5f) * kRenderW / kOutW - 0.5f, 0.0f), (float)(kRenderW - 1)); + const float want[4] = {sx / (float)(kRenderW - 1), sy / (float)(kRenderH - 1), 0.5f, model_k ? 0.25f : 1.0f}; + bool ok = true; + for (int c = 0; c < 4; ++c) { + const float d = std::fabs(FromHalf(px[((size_t)oy * kOutW + ox) * 4 + c]) - want[c]); + *worst = std::max(*worst, d); + ok = ok && d <= 3e-3f; + } + if (!ok) ++bad; + } + } + return bad; +} + void RealRefusals(const char* dllPath) { HMODULE dll = LoadLibraryA(dllPath); std::printf("runtime DLL %s\n", dll ? "loaded" : "NOT loaded"); @@ -217,18 +316,21 @@ void RealRefusals(const char* dllPath) { std::fflush(stdout); if (!g.output) return; CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); + using HipMadeFn = uint32_t (*)(); + const auto hipMade = reinterpret_cast(reinterpret_cast(GetProcAddress(dll, "wgDiagHipExecutorsMade"))); + CHECK(hipMade != nullptr); // the runtime DLL counts the HIP executors it makes struct Scenario { const char* name; - bool amd, standInCreateFails, realPassThrough; + bool amd, standInCreateFails; const char* script; int frames; }; // frame 0 is taken; the refused frames follow; 'o' after them is taken again (the context stays usable, no counter) const Scenario scenarios[] = { - {"AMD available", true, false, false, "orrrrr", 6}, - {"no AMD, stand-in works, five refusals in a row then taken", false, false, false, "orrrrroo", 8}, - {"no AMD, stand-in cannot be made: the game's own colour is passed through", false, true, true, "orrr", 4}, + {"AMD available", true, false, "orrrrr", 6}, + {"no AMD, stand-in works, five refusals in a row then taken", false, false, "orrrrroo", 8}, + {"no AMD, stand-in cannot be made: the backend's bilinear output pass writes the frame", false, true, "orrr", 4}, }; for (const bool model_k : {true, false}) { // model K, and model M as the control for (const Scenario& sc : scenarios) { @@ -238,8 +340,6 @@ void RealRefusals(const char* dllPath) { Reset(); g_originalAvailable = sc.amd; g_standInCreateFails = sc.standInCreateFails; - g_passThroughOn = true; - if (sc.realPassThrough) g_passThroughReal = [](const WgFrame& f, std::string* why) { return wgfsr::CopyColorToOutput(f, why); }; g_useBackend = real; g_resources[g.color] = {dxgi::R16G16B16A16_FLOAT, kRenderW, kRenderH}; g_resources[g.depth] = {dxgi::R32_FLOAT, kRenderW, kRenderH}; @@ -268,9 +368,24 @@ void RealRefusals(const char* dllPath) { Begin(g); std::vector rc; std::vector state; + std::vector bad; // scenario 3: the output pixels that are not the bilinear upscale, per frame + float worst = 0; for (int i = 0; i < sc.frames; ++i) { + if (sc.standInCreateFails && i > 0) CHECK(FillOutputSentinel(g)); // each refused frame writes the whole output itself + if (sc.standInCreateFails && i == 1 && model_k) { // negative control: an output nobody wrote is every pixel wrong + std::vector unwritten; + float w = 0; + CHECK(ReadOutput(g, &unwritten) && BadPixels(unwritten, model_k, &w) == (size_t)kOutW * kOutH); + } rc.push_back(fe->Dispatch(&ctx, &d.header)); state.push_back(g_statuses.empty() ? UpscaleState::Failed : g_statuses.back().state); + if (sc.standInCreateFails && i > 0) { + std::vector px; + CHECK(ReadOutput(g, &px)); + float w = 0; + bad.push_back(BadPixels(px, model_k, &w)); + worst = std::max(worst, w); + } } Submit(g); // the game's list, with whatever the front end recorded in it, runs CHECK(g.device->GetDeviceRemovedReason() == S_OK); @@ -290,24 +405,24 @@ void RealRefusals(const char* dllPath) { // frames after the refusals are the real backend's again for (int i = 1; i <= 5; ++i) CHECK(state[i] == UpscaleState::StandIn); CHECK(state[6] == UpscaleState::Network && state[7] == UpscaleState::Network); - CHECK(g_standInFrames.size() == 5 && g_amd.empty() && g_passFrames.empty()); + CHECK(g_standInFrames.size() == 5 && g_amd.empty()); CHECK(CountLog("AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take") == 1); } else { - // no stand-in: the game's colour is copied into the output by the real last resort, checked on the pixels + // no stand-in, no AMD: the REAL backend's bilinear output pass wrote each refused frame (WG_FRAME_BILINEAR through + // the front end's last resort), every pixel of the output, for consecutive frames for (int i = 1; i < sc.frames; ++i) - CHECK(state[i] == UpscaleState::Failed && g_statuses.back().reason.find("passed through unscaled") != std::string::npos); - CHECK(g_passFrames.size() == 3 && g_amd.empty()); - CHECK(CountLog("the game's own colour is passed through to the output unscaled") == 1); - std::vector px; - CHECK(ReadOutputRow0(g, 8, &px) && px.size() == 32); - bool same = px.size() == 32; - for (UINT x = 0; same && x < 8; ++x) - for (UINT c = 0; c < 4; ++c) same = same && px[x * 4 + c] == Pixel(x, 0, c); - CHECK(same); // the output's first pixels are the colour's + CHECK(state[i] == UpscaleState::Failed && g_statuses.back().reason.find("bilinearly") != std::string::npos); + CHECK(g_amd.empty() && g_standInFrames.empty()); + CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); + CHECK(bad.size() == (size_t)(sc.frames - 1)); + for (size_t b : bad) CHECK(b == 0); // no pixel left at the sentinel or off the bilinear value + std::printf(" output checked on every pixel for %zu frame(s): worst difference %.5f\n", bad.size(), worst); + CHECK(worst <= 3e-3f); } // HIP never started: no HIP runtime line, no amdhip64 module CHECK(CountLog("about to start the HIP runtime") == 0); CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); + CHECK(hipMade && hipMade() == 0); // no HIP executor was ever constructed by the backend CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); if (g_failures != failuresBefore) { // the log of a failed scenario std::lock_guard lock(g_logMutex); @@ -316,7 +431,6 @@ void RealRefusals(const char* dllPath) { std::printf(" %s: states", tag.c_str()); for (UpscaleState s : state) std::printf(" %d", (int)s); std::printf(", checks so far %d, failures %d\n", g_checks, g_failures); - g_passThroughReal = nullptr; } } _putenv_s("WG_RUNTIME_OPTIONS", ""); @@ -329,10 +443,11 @@ void RealRefusals(const char* dllPath) { } // namespace int main(int argc, char** argv) { - const char* dll = argc > 1 ? argv[1] : std::getenv("WG_TEST_RUNTIME_DLL"); + const char* dll = argc > 1 && std::strcmp(argv[1], "--skip-if-missing") != 0 ? argv[1] : std::getenv("WG_TEST_RUNTIME_DLL"); if (!dll || !*dll) { - std::printf("SKIP: no runtime DLL (argument or WG_TEST_RUNTIME_DLL)\n"); - return 0; + const bool skip = argc > 1 && std::strcmp(argv[1], "--skip-if-missing") == 0; + std::printf("%s: no runtime DLL (argument or WG_TEST_RUNTIME_DLL)\n", skip ? "SKIP" : "FAIL"); + return skip ? 0 : 2; } RealRefusals(dll); std::printf("%d checks, %d failures\n", g_checks, g_failures); diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 51dae459..452bdf77 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -44,6 +44,10 @@ struct WgUpscaler; namespace wgi { +// HIP executors made by this process's contexts (wgDiagHipExecutorsMade): the integration test of the refused-frame contract +// checks that none was made. +std::atomic g_hip_executors_made{0}; + namespace { // the converter maps and model K's folder, from the model table (clean/runtime/model_select.h) @@ -653,6 +657,7 @@ class Context { #ifndef WG_NO_MODEL_K model_k_ = test_model_k; #endif + conv_.set_model_k(model_k_); } else if (o.executor == "hip" || o.executor == "dx12") { if (!configure_hip(o, &err)) return fail(WG_ERROR, err); } else { @@ -697,6 +702,7 @@ class Context { } if (!dx12 && !exec_) { if (!split) return fail(WG_ERROR_UNSUPPORTED, "the front end offers no command-list split (interface version 2)"); + ++g_hip_executors_made; exec_ = make_hip_executor(rt_cfg_, adapter_); } if (!dx12) { @@ -869,7 +875,30 @@ class Context { return r; } + // B8 (WG_FRAME_BILINEAR): the front end's last resort for a frame that nothing else could upscale: no network, no executor, the + // existing bilinear output pass (Converter::record_output without a result: format aware, the full output size, its own + // barrier handling) from the game's colour into the output texture. It does not touch the context's state: a failed context + // can still write such a frame, and an answer other than WG_OK never fails the context. + WgResult dispatch_bilinear(const WgFrame& f) { + auto refuse = [&](WgResult r, const std::string& why) { + if (bilinear_refusals_++ == 0) say(WG_LOG_WARN, "bilinear last-resort frame refused: " + why); + return r; + }; + if (!f.command_list || !f.color.resource || !f.color.format || !f.output.resource || !f.output.format) + return refuse(WG_ERROR_PARAMETER, "no command list, colour or output texture"); + if (!f.render_width || !f.render_height || f.output_width != ow_ || f.output_height != oh_) + return refuse(WG_ERROR_PARAMETER, "the render region is empty or the output size differs from the context's"); + const std::string skip = skip_reason(f); + if (!skip.empty()) return refuse(WG_ERROR_PARAMETER, skip); + const std::string out = output_refusal(f); + if (!out.empty()) return refuse(WG_ERROR_INPUT, out); + conv_.record_output(static_cast(f.command_list), f, BufferRange()); + note_path(&output_path_, "output: bilinear (the front end's last resort: nothing else upscaled this frame)"); + return WG_OK; + } + WgResult dispatch_impl(const WgFrame& f) { + if (f.struct_size >= sizeof(WgFrame) && (f.flags & WG_FRAME_BILINEAR)) return dispatch_bilinear(f); std::string why; if (!valid(f, &why)) return fail_frame(WG_ERROR_PARAMETER, why); if (failed_) return WG_ERROR; @@ -1214,6 +1243,7 @@ class Context { if (!split_) { err = "the front end offers no command-list split (interface version 2)"; } else { + ++g_hip_executors_made; hip = make_hip_executor(rt_cfg_, adapter_); hip->set_log_sink([this](bool warning, const std::string& m) { say(warning ? WG_LOG_WARN : WG_LOG_INFO, "destroy: " + m); @@ -2159,6 +2189,7 @@ class Context { bool dx12_default_ = false; bool hip_switch_ = kHipSwitchDefault; // refused_frame_policy (option hip_switch; clean/fe-wrapped-list) bool no_switch_said_ = false; // the hip_switch=off line was logged + uint64_t bilinear_refusals_ = 0; // WG_FRAME_BILINEAR requests this context could not record (logged once) bool split_ = false; std::string share_path_opt_ = "auto"; bool input_copy_opt_ = false; @@ -2221,10 +2252,14 @@ void wg_destroy(WgUpscaler* u) { uint64_t wg_memory(WgUpscaler* u) { return u ? u->ctx.gpu_memory() : 0; } const WgUpscalerBackend kBackend = {sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "WrongGPU network", - &wg_create, &wg_dispatch, &wg_destroy, &wg_memory, WG_BACKEND_NEEDS_SPLIT}; + &wg_create, &wg_dispatch, &wg_destroy, &wg_memory, WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME}; } // namespace +// A diagnostic for tests of the refused-frame contract: how many HIP executors this process's contexts have made (none in a +// game: HIP is an explicit diagnostic only). +extern "C" __declspec(dllexport) uint32_t wgDiagHipExecutorsMade() { return wgi::g_hip_executors_made.load(); } + // Interface version 2 only: the backend needs the front end's command-list split. extern "C" __declspec(dllexport) const WgUpscalerBackend* wgGetUpscalerBackend(uint32_t interface_version) { return interface_version == WG_UPSCALER_INTERFACE_VERSION ? &kBackend : nullptr; From ede789488342c2e47c72904b9f1bf7a9a2b3be54 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:57:44 -0500 Subject: [PATCH 3/4] B8: the alpha source pin counts the scripted executor's set_model_k call Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/k/tests/test_k_alpha.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clean/k/tests/test_k_alpha.py b/clean/k/tests/test_k_alpha.py index 62ed38d0..c8d1d226 100644 --- a/clean/k/tests/test_k_alpha.py +++ b/clean/k/tests/test_k_alpha.py @@ -307,7 +307,8 @@ def test_interop(self): self.assertIn("d.Buffer.NumElements = (model_k_ ? 4 : 3) * f.output_width * f.output_height;", c) self.assertIn("void set_model_k(bool on) { model_k_ = on; }", ch) self.assertIn("bool model_k_ = false;", ch) # model M (and every other Converter user): as before - self.assertEqual(b.count("conv_.set_model_k("), 1) + # configure_hip (every real executor), and the scripted executor=dx12-test branch of create (tests of the backend) + self.assertEqual(b.count("conv_.set_model_k("), 2) self.assertIn("conv_.set_model_k(model_k_);", b) self.assertIn("job.out_rgba32f = model_k_ && !halfOut;", b) self.assertIn("sizes[4] = std::max(O * (model_k_ ? 16 : 12), po * oh_);", b) From 8c726538d590c94666c97a59932ba99ed6d90368 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:18:16 -0500 Subject: [PATCH 4/4] B8 shrunk: when AMD's FSR and the stand-in both fail, one explicit line; no ABI change (REVIEW-228b) Drop the frame flag, the backend flag and the bilinear last resort: no change to wronggpu_upscaler.h, none of the backend's frame path. The contract that stays: when AMD's FSR and the stand-in have both failed for a frame, the error goes back with ONE line naming both failures per context (also after an earlier success or a takeover) and a count at the context's end. A failing AMD takeover now tries the stand-in before the error. A non-linear (sRGB / PQ) frame never reaches the stand-in on any path, the takeover and a context already handed to AMD included. AMD's failures are logged once per context; AMD's per-frame create is retried at the 1st, 2nd, 3rd, 10th ... frame. Tests: test_frontend.cpp (every failure case for models M, K and L over 300 frames, success then failure, sRGB and PQ on four paths). test_refusal_integration.cpp, a release check built from source by the release script, drives the real backend through the scripted executor=dx12-test; the runtime DLL's wgDiagHipExecutorsMade (not in a public header) stays 0. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/README.md | 28 +- clean/fsr/include/wronggpu_upscaler.h | 10 - clean/fsr/src/frontend.cpp | 229 ++++++------- clean/fsr/src/frontend.h | 22 +- clean/fsr/src/fsr30_hook.cpp | 2 +- clean/fsr/tests/test_frontend.cpp | 199 ++++++------ clean/fsr/tests/test_refusal_integration.cpp | 318 +++---------------- clean/k/tests/test_k_alpha.py | 3 +- clean/runtime/interop/backend.cpp | 27 +- 9 files changed, 251 insertions(+), 587 deletions(-) diff --git a/clean/fsr/README.md b/clean/fsr/README.md index 77f67e9c..ab693ab7 100644 --- a/clean/fsr/README.md +++ b/clean/fsr/README.md @@ -270,21 +270,19 @@ OptiScaler folder ships `amd_fidelityfx_upscaler_dx12.dll`; OptiScaler.ini `[Lib `hip_switch=off`, its default since 2026-11-04: frames above the render size checked at create) hands the context to AMD's FSR at once; without AMD's FSR the stand-in upscales such frames. This is one contract for every model (K refused frames take exactly - model M's path), and what a frame gets is explicit (B8): WrongGPU's upscaler, then the stand-in, then AMD's FSR, and last, - when none of them could upscale it (the stand-in cannot be made or fails, AMD's FSR is missing, cannot be created or its - dispatch fails), the backend's own bilinear upscale of the game's colour: the front end asks the upscaler for it with - `WG_FRAME_BILINEAR` (`WG_BACKEND_BILINEAR_FRAME` says a backend answers it), and the runtime records the Converter's - existing fallback pass (format aware, the full output size, no HIP). The game gets `FFX_API_RETURN_OK` and one warning - line per context; the counts are logged when the context is destroyed. When even that is impossible (no upscaler for the - context, the output texture unusable) the error goes back and the reason is logged for the first such frame, also after - earlier successes; in OptiScaler's custom slot the error always goes back (its host upscales). AMD's failures are logged - once per context and counted. A frame the game flags as non-linear (sRGB / PQ) is not a refused frame: it goes to AMD's FSR - and, when that is missing or fails, gets the same last resort. `tests/test_frontend.cpp` covers each failure case for - models M, K and L over a long run; `tests/test_refusal_integration.cpp` drives refused frames through the real network - backend (the runtime DLL's `Context`, with the scripted executor `executor=dx12-test`) and the real front end on a D3D12 - device (WARP is enough), with and without AMD's FSR, the stand-in working and not, checks every pixel of the backend's - bilinear output for consecutive frames, and that no HIP executor was ever made (`wgDiagHipExecutorsMade`). It is not in the - CI (it needs a runtime DLL) and fails without one: a release gate runs it with the DLL of the build. + model M's path), and what a frame gets is explicit (B8): when AMD's FSR (missing, not created, or its dispatch failed) and + the stand-in (not made, or its dispatch failed) have both failed, the error goes back to the game with ONE line naming both + failures per context (also after an earlier success or a takeover); the count is logged when the context is destroyed. AMD's + own failures are logged once per context and counted, and AMD's per-frame context create for a bad frame is retried at the + 1st, 2nd, 3rd, 10th, 100th ... frame. A frame the game flags as non-linear (sRGB / PQ) is AMD's alone: it never reaches the + stand-in, on any path (AMD missing, failing, the takeover at the bad-frame threshold, a context already handed to AMD). + `tests/test_frontend.cpp` covers each failure case for models M, K and L over a long run (CI). + `tests/test_refusal_integration.cpp` is a release check: it drives refused frames through the real network backend (the + runtime DLL's `Context`, with the scripted executor `executor=dx12-test`) and the real front end on a D3D12 device (WARP is + enough), with and without AMD's FSR, the stand-in working and not, for K and M, and checks that no HIP executor was ever + made (`wgDiagHipExecutorsMade`, an export for that test only). It needs the runtime DLL of a build (so it is not in the CI), + and fails without one; its build command is in the file's header, and the release script under `tools/release` builds it + from that source. - **Model location:** the front end looks for the converted model (`model.wgcm`, Model K in `K\`) in `[fsr] model_dir` of `wronggpu.ini` (relative: from the data folder), then `\WrongGPU\model`, and passes the first folder that has it to the runtime as `model_dir=`; otherwise the runtime's own default (`%LOCALAPPDATA%\WrongGPU\model`, diff --git a/clean/fsr/include/wronggpu_upscaler.h b/clean/fsr/include/wronggpu_upscaler.h index 5c63ab82..966b9190 100644 --- a/clean/fsr/include/wronggpu_upscaler.h +++ b/clean/fsr/include/wronggpu_upscaler.h @@ -146,17 +146,8 @@ typedef struct WgFrame { end's ExecuteCommandLists hook), or null; informational: the split needs no queue from the backend */ uint32_t command_list_type; /* D3D12_COMMAND_LIST_TYPE of command_list (0 = DIRECT, 2 = COMPUTE) */ - - /* version 2, after the first release: a front end that cannot know whether the backend reads this sets - * struct_size = sizeof(WgFrame) with flags = 0; a backend reads flags only when struct_size covers it. */ - uint32_t flags; /* WG_FRAME_* */ } WgFrame; -/* WgFrame::flags. */ -#define WG_FRAME_BILINEAR (1u << 0) /* do not run the network: record the backend's own bilinear upscale of the color into - the output texture (the last resort of the front end for a frame that nothing else - could upscale). Only for a backend that sets WG_BACKEND_BILINEAR_FRAME. */ - /* Version 2: same-frame execution through an "ordered split" of the game's command list. * * The backend, inside dispatch, on the game's recording thread: @@ -208,7 +199,6 @@ typedef struct WgUpscaler WgUpscaler; /* opaque, owned by the implementation */ /* Backend flags (version 2). */ #define WG_BACKEND_NEEDS_SPLIT (1u << 0) /* the backend calls split_command_list: the front end installs its D3D12 command-list hooks when the backend is loaded (d3d12_hooks = auto) */ -#define WG_BACKEND_BILINEAR_FRAME (1u << 1) /* the backend answers WG_FRAME_BILINEAR (see WgFrame::flags) */ /* The implementation's entry points. */ typedef struct WgUpscalerBackend { diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index 94d34f5a..84de5585 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -58,11 +58,9 @@ struct FrontEnd::UpscaleContext { bool amdLast = false; // the last frame was one of AMD's FSR for such a frame (AMD's history continues) bool broken = false; // the upscaler failed for good: it is not parked uint64_t brokenFrames = 0; // bug hunt F1: frames since the upscaler failed for good (it is not called again) - uint64_t lastResortFrames = 0; // B8: frames of this context the backend's bilinear upscale wrote (nothing else could) - uint64_t lastResortFailures = 0; // B8: frames for which even that could not be recorded - uint64_t amdFailures = 0; // B8: AMD FSR dispatches of this context that failed (logged once, counted) - uint64_t mapFailures = 0; // B8: frames of a context handed to AMD that could not be mapped for the fallback - uint64_t amdCreateTries = 0; // B8: per-frame attempts to make AMD's context for a bad frame (made at 1, 2, 3, 10, 100 ...) + uint64_t amdFailures = 0; // B8: AMD FSR dispatches of this context that failed (logged once, counted) + uint64_t bothFailed = 0; // B8: frames that neither AMD's FSR nor the stand-in could upscale (logged once, counted) + uint64_t amdCreateTries = 0; // B8: per-frame attempts to make AMD's context for a bad frame (made at the 1st, 2nd, 3rd, 10th ...) uint32_t resizes = 0; // bug hunt H: upscalers created again for the frames' output size (Config::maxOutputResizes) bool resizeFailed = false; // ... and such a create failed: no more attempts for this context // Issue #58: upscalers and stand-ins a resize replaced. Command lists the game recorded before may still use them @@ -953,85 +951,66 @@ bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend return false; } -// B8: AMD's failures are logged once per context (the first, with its reason) and counted; the count is logged when the -// context is destroyed. +// B8: AMD's failures are logged once per context (the first), counted; the counts are logged when the context is destroyed. void FrontEnd::NoteAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, ffxReturnCode_t rc) { if (++u.amdFailures == 1) - Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": AMD FSR dispatch failed (" + - RcName(rc) + "); this context's frames get the stand-in or the backend's bilinear upscale; its later AMD failures are counted, not logged"); + Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": AMD FSR dispatch failed (" + RcName(rc) + + "); its later failures in this context are counted, not logged"); } -// B8: the last step of the refused-frame contract. Nothing upscaled this frame (the upscaler refused it, the stand-in could -// not be made or failed, AMD's FSR is missing or failed): the backend writes the output itself, its own bilinear upscale of -// the game's colour (WG_FRAME_BILINEAR: format aware, the full output size, no HIP, the Converter pass the backend uses for -// a frame whose network failed), and the game gets FFX_API_RETURN_OK with one warning line per context (the count at the -// end). False when that cannot be done (the reason is logged for the first such frame, whatever came before: a failure after -// earlier successes is reported too) and in OptiScaler's custom slot, whose host upscales a frame the upscaler fails. -bool FrontEnd::LastResortFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what) { - if (config_.customSlot) return false; - std::string why; - bool ok = false; - if (!frame) { - why = "the frame's inputs could not be mapped"; - } else if (!u.backend || !u.upscaler) { - why = "WrongGPU's upscaler is not available for this context"; - } else if (!(BackendFlags(u.backend) & WG_BACKEND_BILINEAR_FRAME)) { - why = "the upscaler cannot write a frame without the network"; - } else { - WgFrame f = *frame; - if (!UsableForStandIn(f)) { - why = "the frame has no command list, colour texture or output texture"; - } else { - f.flags = WG_FRAME_BILINEAR; - AdaptFrame(u.backend, f); - const WgResult r = u.backend->dispatch(u.upscaler, &f); - ok = r == WG_OK; - if (!ok) why = std::string("the backend's bilinear upscale answered ") + WgResultText(r); +// B8: the one line when neither AMD's FSR nor the stand-in could upscale a frame: it names both failures; the error goes back to +// the game for this frame and the later such frames of the context (counted, the count is logged at the context's end). +void FrontEnd::NoteBothFailed(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, const std::string& amdWhy, + const std::string& standInWhy) { + if (++u.bothFailed == 1) + Log(tag + " ERROR U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": no upscaler could take this frame: AMD FSR " + + amdWhy + "; the stand-in " + standInWhy + + "; the error goes back to the game for this frame and the later such frames of this context (counted, logged once)"); +} + +// B8: the stand-in upscales `frame` (cut to its textures); false with the reason in *why. +bool FrontEnd::StandInFrame(UpscaleContext& u, WgFrame& frame, std::string* why) { + if (!UsableForStandIn(frame)) { + *why = "cannot take this frame (no command list, colour texture or output texture)"; + return false; + } + if (!u.fallbackBackend && platform_.standIn) u.fallbackBackend = platform_.standIn(config_); + if (!u.fallbackBackend || u.fallbackBackend == u.backend) { + *why = "is not available"; + return false; + } + if (!u.fallback) { + WgCreateInfo info = u.createInfo; + AdaptCreateInfo(u.fallbackBackend, nullptr, info); + if (u.fallbackBackend->create(&info, &u.fallback) != WG_OK) { + u.fallback = nullptr; + *why = "could not be created"; + return false; } } - if (ok) { - if (++u.lastResortFrames == 1) - Log(tag + " WARNING U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + - "; nothing upscaled it: the backend's bilinear upscale of the game's colour wrote the output (later such frames of this " - "context are counted, not logged)"); - Report(u, UpscaleState::Failed, frame, "frame upscaled bilinearly by the backend, nothing else could: " + what); - return true; + AdaptFrame(u.fallbackBackend, frame); + const WgResult r = u.fallbackBackend->dispatch(u.fallback, &frame); + if (r != WG_OK) { + *why = std::string("dispatch failed (") + WgResultText(r) + ")"; + return false; } - const uint64_t n = ++u.lastResortFailures; - if (n == 1 || ((n >= 10) && LogPoint(n))) - Log(tag + " ERROR U" + std::to_string(u.id) + ": frame " + std::to_string(frameIndex) + ": " + what + - "; nothing upscaled it and the backend's bilinear upscale is not possible (" + why + "), " + std::to_string(n) + - " such frame(s) in this context"); - return false; + u.resetNext = true; + if (platform_.afterDispatch) platform_.afterDispatch(frame, true); + Report(u, UpscaleState::StandIn, &frame); + return true; } -// B8: AMD's FSR was asked for this frame and its dispatch failed (rc). The stand-in is tried, then the last resort; if both -// fail (or in a custom slot) AMD's own error goes back, as before. -ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc) { +// B8: AMD's FSR was asked for this frame and its dispatch failed (rc). +ffxReturnCode_t FrontEnd::AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc, + bool perceptual, const std::string& noFrameWhy) { NoteAmdFailure(u, tag, frameIndex, rc); - const std::string what = "AMD FSR failed (" + std::string(RcName(rc)) + ")"; - if (frame && !config_.customSlot) { - WgFrame f = *frame; - if (UsableForStandIn(f)) { - if (!u.fallbackBackend && platform_.standIn) u.fallbackBackend = platform_.standIn(config_); - if (u.fallbackBackend && u.fallbackBackend != u.backend) { - if (!u.fallback) { - WgCreateInfo info = u.createInfo; - AdaptCreateInfo(u.fallbackBackend, nullptr, info); - if (u.fallbackBackend->create(&info, &u.fallback) != WG_OK) u.fallback = nullptr; - } - AdaptFrame(u.fallbackBackend, f); - if (u.fallback && u.fallbackBackend->dispatch(u.fallback, &f) == WG_OK) { - u.resetNext = true; - if (platform_.afterDispatch) platform_.afterDispatch(f, true); - Report(u, UpscaleState::StandIn, &f); - return FFX_API_RETURN_OK; - } - } - } - u.resetNext = true; - } - if (LastResortFrame(u, tag, frameIndex, frame, what)) return FFX_API_RETURN_OK; + if (config_.customSlot) return rc; // the host upscales on the error + std::string why; + if (perceptual) why = "is not used for non-linear (sRGB / PQ) input"; + else if (!frame) why = noFrameWhy.empty() ? "has no mapped frame" : "has no mapped frame (" + noFrameWhy + ")"; + else if (StandInFrame(u, *frame, &why)) return FFX_API_RETURN_OK; + NoteBothFailed(u, tag, frameIndex, "dispatch failed (" + std::string(RcName(rc)) + ")", why); + Report(u, UpscaleState::Failed, nullptr, "AMD FSR dispatch failed (" + std::string(RcName(rc)) + "); the stand-in " + why); return rc; } @@ -1060,7 +1039,6 @@ ffxReturnCode_t FrontEnd::BrokenFrame(UpscaleContext& u, WgFrame& frame, const s } } } - if (LastResortFrame(u, tag, frameIndex, &frame, what)) return FFX_API_RETURN_OK; // B8: never no output if (LogPoint(n)) Log(tag + " ERROR U" + std::to_string(u.id) + ": " + what + " -> ERROR_RUNTIME_ERROR"); Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); return FFX_API_RETURN_ERROR_RUNTIME_ERROR; @@ -1280,10 +1258,9 @@ ffxReturnCode_t FrontEnd::DestroyContext(ffxContext* context, const ffxAllocatio if (park) u->amd = nullptr; } } - if (u->lastResortFrames || u->lastResortFailures || u->amdFailures || u->mapFailures) - Log(tag + " note U" + std::to_string(u->id) + ": fallback counts: the backend's bilinear upscale wrote " + std::to_string(u->lastResortFrames) + - " frame(s) as the last resort, " + std::to_string(u->lastResortFailures) + " frame(s) had no last resort, AMD FSR failed " + - std::to_string(u->amdFailures) + " time(s), " + std::to_string(u->mapFailures) + " frame(s) could not be mapped for the fallback"); + if (u->bothFailed || u->amdFailures) + Log(tag + " note U" + std::to_string(u->id) + ": fallback counts: AMD FSR failed " + std::to_string(u->amdFailures) + " time(s), " + + std::to_string(u->bothFailed) + " frame(s) could be upscaled by neither AMD FSR nor the stand-in (the error went back to the game)"); Log(tag + " -> " + RcName(rc) + " (U" + std::to_string(u->id) + " destroyed after " + std::to_string(u->dispatches) + " dispatches" + (pending && !pending->Done() ? "; its upscaler is still starting and is destroyed when it has" : "") + (park ? "; its upscaler is parked for " + std::to_string(config_.contextParkMs) + @@ -1644,19 +1621,13 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe const std::string tag = "#" + std::to_string(call); const uint64_t frameIndex = u.dispatches++; const bool log = ShouldLogDispatch(frameIndex); - WgFrame frame{}; + WgFrame frame; std::string problem, notes; if (d.flags & (FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB | FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_PQ)) { // Perceptual input goes to AMD's FSR (spec 20, ANSWERS item 5): this frame, and the context for good when the // game keeps flagging it (kBadFrameRun). - // B8: the frame is mapped for the last resort (the stand-in is skipped for perceptual input, the backend's bilinear - // upscale is colour-space neutral), so that an unavailable or failing AMD FSR does not leave the frame without output - WgFrame resortFrame; - std::string resortProblem, resortNotes; - const bool resortMapped = - MapDispatch(d, u.create, config_, platform_.resourceInfo, u.map, frameIndex, resortFrame, resortProblem, resortNotes); return BadFrame(u, d, call, frameIndex, "non-linear (sRGB/PQ) colour flagged by the game: AMD FSR handles it", nullptr, true, - WG_ERROR_UNSUPPORTED, resortMapped ? &resortFrame : nullptr); + WG_ERROR_UNSUPPORTED); } const bool mapped = MapDispatch(d, u.create, config_, platform_.resourceInfo, u.map, frameIndex, frame, problem, notes); const bool resetAsked = frame.reset != 0; @@ -1684,7 +1655,7 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe Report(u, UpscaleState::Amd, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); return rc; } - return AfterAmdFailure(u, tag, frameIndex, &frame, rc); // B8: the stand-in, then the pass-through + return AfterAmdFailure(u, tag, frameIndex, &frame, rc, false); // B8 } Log(tag + " note U" + std::to_string(u.id) + ": AMD FSR is not available for this context; the stand-in upscales its frames"); } @@ -1735,7 +1706,7 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe Report(u, UpscaleState::Amd, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); return rc; } - return AfterAmdFailure(u, tag, frameIndex, &frame, rc); // B8: the stand-in, then the pass-through + return AfterAmdFailure(u, tag, frameIndex, &frame, rc, false); // B8 } Log(tag + " note U" + std::to_string(u.id) + ": AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take"); } @@ -1779,21 +1750,17 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe Report(u, UpscaleState::Amd, nullptr, u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); return rc; } - return AfterAmdFailure(u, tag, frameIndex, mapped ? &frame : nullptr, rc); // B8 + return AfterAmdFailure(u, tag, frameIndex, mapped ? &frame : nullptr, rc, false, mapped ? std::string() : problem); // B8 } - if (mapped && LastResortFrame(u, tag, frameIndex, &frame, "WrongGPU's upscaler failed (" + u.failReason + ") and AMD FSR is not available")) - return FFX_API_RETURN_OK; // B8: never no output Report(u, UpscaleState::Failed, nullptr, u.failReason + "; AMD fallback is unavailable"); Log(tag + " -> ERROR_RUNTIME_ERROR"); return r == WG_ERROR_PARAMETER ? FFX_API_RETURN_ERROR_PARAMETER : FFX_API_RETURN_ERROR_RUNTIME_ERROR; } ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpscale& d, uint64_t call, uint64_t frameIndex, - const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result, - WgFrame* lastResortFrame) { + const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result) { const std::string tag = "#" + std::to_string(call); const std::string what = "frame " + std::to_string(frameIndex) + ": " + problem; - WgFrame* const resort = frame ? frame : lastResortFrame; // B8: a frame the last resort can use const uint32_t run = ++u.badRun; if (!frame && d.commandList && platform_.noteDispatch) platform_.noteDispatch(d.commandList, nullptr); if (run == kBadFrameRun) { @@ -1809,30 +1776,20 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca Report(u, UpscaleState::Amd, nullptr, u.failReason + "; AMD FSR dispatch failed: " + RcName(rc)); return rc; } - return AfterAmdFailure(u, tag, frameIndex, frame, rc); // B8 + return AfterAmdFailure(u, tag, frameIndex, frame, rc, amdOnly); // B8: a perceptual frame never reaches the stand-in } } u.resetNext = true; // this frame goes past the upscaler: its next one starts without history - // 1. The stand-in, on the frame as it is or cut to its textures. - if (!amdOnly && frame && UsableForStandIn(*frame)) { - if (!u.fallbackBackend && platform_.standIn) u.fallbackBackend = platform_.standIn(config_); - if (u.fallbackBackend && u.fallbackBackend != u.backend) { - if (!u.fallback) { - WgCreateInfo info = u.createInfo; - AdaptCreateInfo(u.fallbackBackend, nullptr, info); - if (u.fallbackBackend->create(&info, &u.fallback) != WG_OK) u.fallback = nullptr; - } - AdaptFrame(u.fallbackBackend, *frame); - if (u.fallback && u.fallbackBackend->dispatch(u.fallback, frame) == WG_OK) { - if (run == 1) - Log(tag + " note U" + std::to_string(u.id) + ": " + what + ": the stand-in upscales this frame (" + - std::to_string(frame->render_width) + "x" + std::to_string(frame->render_height) + "); the context stays WrongGPU's (AMD FSR takes it over after " + - std::to_string(kBadFrameRun) + " such frames in a row)"); - u.amdLast = false; - if (platform_.afterDispatch) platform_.afterDispatch(*frame, true); - Report(u, UpscaleState::StandIn, frame); - return FFX_API_RETURN_OK; - } + // 1. The stand-in, on the frame as it is or cut to its textures (not for non-linear input: that is AMD's alone). + std::string standWhy = amdOnly ? "is not used for non-linear (sRGB / PQ) input" : "has no mapped frame"; + if (!amdOnly && frame) { + if (StandInFrame(u, *frame, &standWhy)) { + if (run == 1) + Log(tag + " note U" + std::to_string(u.id) + ": " + what + ": the stand-in upscales this frame (" + + std::to_string(frame->render_width) + "x" + std::to_string(frame->render_height) + "); the context stays WrongGPU's (AMD FSR takes it over after " + + std::to_string(kBadFrameRun) + " such frames in a row)"); + u.amdLast = false; + return FFX_API_RETURN_OK; } } // 2. AMD's FSR, for this frame only: the context made from the saved create parameters, kept for later ones. @@ -1846,22 +1803,16 @@ ffxReturnCode_t FrontEnd::BadFrame(UpscaleContext& u, const ffxDispatchDescUpsca else if (run == 1) Log(tag + " note U" + std::to_string(u.id) + ": " + what + ": AMD FSR upscales this frame -> " + RcName(rc) + "; the context stays WrongGPU's (AMD FSR takes it over after " + std::to_string(kBadFrameRun) + " such frames in a row)"); - if (rc == FFX_API_RETURN_OK) { - Report(u, UpscaleState::Amd, nullptr, what + "; AMD FSR dispatch failed: " + RcName(rc), what); - return rc; + if (rc != FFX_API_RETURN_OK) { + u.amdLast = false; + NoteBothFailed(u, tag, frameIndex, "dispatch failed (" + std::string(RcName(rc)) + ")", standWhy); // B8: the stand-in came first } - u.amdLast = false; - if (LastResortFrame(u, tag, frameIndex, resort, what + "; AMD FSR failed (" + RcName(rc) + ")")) - return FFX_API_RETURN_OK; // B8: the stand-in was tried first (step 1), now the backend's bilinear upscale - Report(u, UpscaleState::Failed, nullptr, what + "; AMD FSR dispatch failed: " + RcName(rc), what); + Report(u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, + what + "; AMD FSR dispatch failed: " + RcName(rc), what); return rc; } - // 3. Nobody could upscale it: the backend's bilinear upscale of the game's colour (B8), else the frame fails, the context stays. - if (LastResortFrame(u, tag, frameIndex, resort, what)) return FFX_API_RETURN_OK; - if (run == 1 || ShouldLogDispatch(frameIndex)) - Log(tag + (amdOnly ? " note U" : " ERROR U") + std::to_string(u.id) + ": " + what + ": no upscaler for this frame (" + - (config_.fallbackToAmd ? "AMD FSR is not available" : "fallback_to_amd = 0") + ") -> " + - (result == WG_ERROR_PARAMETER ? "ERROR_PARAMETER" : "ERROR_RUNTIME_ERROR")); + // 3. Nobody: the frame fails, the context stays. B8: one line naming both failures (AMD's FSR was never reached here). + NoteBothFailed(u, tag, frameIndex, config_.fallbackToAmd ? "is not available" : "is off (fallback_to_amd = 0)", standWhy); Report(u, UpscaleState::Failed, nullptr, what + "; AMD fallback is unavailable"); return result == WG_ERROR_PARAMETER ? FFX_API_RETURN_ERROR_PARAMETER : FFX_API_RETURN_ERROR_RUNTIME_ERROR; } @@ -1997,19 +1948,17 @@ ffxReturnCode_t FrontEnd::Dispatch(ffxContext* context, const ffxDispatchDescHea if (log || (rc != FFX_API_RETURN_OK && !takenOver)) Log(tag + " -> " + RcName(rc) + " (forwarded to AMD)"); if (desc->type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE) { if (rc != FFX_API_RETURN_OK && takenOver) { - // B8: a context WrongGPU handed to AMD's FSR whose AMD dispatch fails: the stand-in, then the backend's bilinear - // upscale (a context that was AMD's from the start is the game's own FSR and keeps AMD's answer). The failure is - // logged once per context (NoteAmdFailure), a frame that cannot be mapped for the fallback says why, once + // B8: a context WrongGPU handed to AMD's FSR whose AMD dispatch fails: the stand-in for an ordinary frame, never for + // a non-linear (sRGB / PQ) one; both failing is the one line naming both (a context that was AMD's from the start + // is the game's own FSR and keeps AMD's answer) + const auto& ud = *reinterpret_cast(desc); + const bool perceptual = (ud.flags & (FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB | FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_PQ)) != 0; + const uint64_t frameIndex = u->dispatches - 1; WgFrame frame{}; std::string problem, notes; - const uint64_t frameIndex = u->dispatches - 1; - if (MapDispatch(*reinterpret_cast(desc), u->create, config_, platform_.resourceInfo, - u->map, frameIndex, frame, problem, notes)) - return AfterAmdFailure(*u, tag, frameIndex, &frame, rc); - NoteAmdFailure(*u, tag, frameIndex, rc); - if (++u->mapFailures == 1) - Log(tag + " ERROR U" + std::to_string(u->id) + ": frame " + std::to_string(frameIndex) + - ": AMD FSR failed and the frame cannot be mapped for the fallback (" + problem + "); the error goes back to the game"); + const bool mapped = !perceptual && MapDispatch(ud, u->create, config_, platform_.resourceInfo, u->map, frameIndex, frame, + problem, notes); + return AfterAmdFailure(*u, tag, frameIndex, mapped ? &frame : nullptr, rc, perceptual, mapped ? std::string() : problem); } Report(*u, rc == FFX_API_RETURN_OK ? UpscaleState::Amd : UpscaleState::Failed, nullptr, "AMD FSR dispatch failed: " + std::string(RcName(rc))); diff --git a/clean/fsr/src/frontend.h b/clean/fsr/src/frontend.h index b8949bb5..322a4667 100644 --- a/clean/fsr/src/frontend.h +++ b/clean/fsr/src/frontend.h @@ -177,8 +177,7 @@ class FrontEnd { // One frame WrongGPU's upscaler cannot take (kBadFrameRun): the stand-in upscales it (`frame` usable) or AMD's FSR // does, and the context stays WrongGPU's; `amdOnly`: never the stand-in (perceptual colour). ffxReturnCode_t BadFrame(UpscaleContext& u, const ffxDispatchDescUpscale& d, uint64_t call, uint64_t frameIndex, - const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result, - WgFrame* lastResortFrame = nullptr); // B8: the mapped frame for the last resort when `frame` is null + const std::string& problem, WgFrame* frame, bool amdOnly, WgResult result); UpscaleContext* FindOwn(ffxContext* context); std::string Name(ffxContext* context); // "U1(standin)", "amd:0x..." for logs void Log(const std::string& line); @@ -220,15 +219,18 @@ class FrontEnd { std::string FailureKey(const WgUpscalerBackend* backend, const UpscaleContext& u) const; void ResizeForFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag); // bug hunt H ffxReturnCode_t BrokenFrame(UpscaleContext& u, WgFrame& frame, const std::string& tag, uint64_t frameIndex); // bug hunt F1 - // B8, the refused-frame contract: what a frame gets is explicit. Order: WrongGPU's upscaler, the stand-in, AMD's FSR, and - // last the backend's own bilinear upscale of the game's colour (WG_FRAME_BILINEAR: the Converter's fallback pass, format - // aware, the full output, no HIP), with one warning line per context; the game is answered an error only when even that - // cannot be recorded (the reason is logged), and in an OptiScaler custom slot, whose host upscales on an error. - // LastResortFrame: the last step (true: the frame has an output). AfterAmdFailure: AMD's dispatch failed for this frame - // (rc): the stand-in, then the last resort; else rc. NoteAmdFailure: AMD's failures are logged once per context, counted. - bool LastResortFrame(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, const std::string& what); - ffxReturnCode_t AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, ffxReturnCode_t rc); + // B8, the refused-frame contract: what a frame gets is explicit. When AMD's FSR and the stand-in have both failed for a frame, + // the error goes back with ONE line naming both failures (per context, also after an earlier success or a takeover; the count + // is logged when the context is destroyed), never silently. A non-linear sRGB / PQ frame is AMD's alone: it never reaches the + // stand-in, on any path. NoteAmdFailure: AMD's failures, logged once per context, counted. NoteBothFailed: the one line. + // StandInFrame: the stand-in upscales `frame` (false: why not, in *why). AfterAmdFailure: AMD's dispatch failed for this frame + // (rc): the stand-in (unless `perceptual`, or in OptiScaler's custom slot, whose host upscales on an error), else rc. void NoteAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, ffxReturnCode_t rc); + void NoteBothFailed(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, const std::string& amdWhy, + const std::string& standInWhy); + bool StandInFrame(UpscaleContext& u, WgFrame& frame, std::string* why); + ffxReturnCode_t AfterAmdFailure(UpscaleContext& u, const std::string& tag, uint64_t frameIndex, WgFrame* frame, + ffxReturnCode_t rc, bool perceptual, const std::string& noFrameWhy = std::string()); void Fail(UpscaleContext& u, const std::string& why, uint64_t call, bool error = true); // Platform::status for one upscale dispatch of `u` (frame: the mapped frame when WrongGPU upscaled it, else null). // amdReason: why AMD's FSR upscaled this one frame of a context that stays WrongGPU's (state Amd). diff --git a/clean/fsr/src/fsr30_hook.cpp b/clean/fsr/src/fsr30_hook.cpp index 8aecd8d7..e6d70306 100644 --- a/clean/fsr/src/fsr30_hook.cpp +++ b/clean/fsr/src/fsr30_hook.cpp @@ -244,7 +244,7 @@ bool Hook::RunStandIn(Context& c, const ffxDispatchDescUpscale& dispatch, const } c.backend = backend; } - WgFrame frame{}; + WgFrame frame; std::string problem, notes; const uint64_t index = c.frames; const bool mapped = MapDispatch(dispatch, c.create, config_, platform_.resourceInfo, c.map, index, frame, problem, notes); diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 7208a563..d750421a 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -157,8 +157,6 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) -static bool g_bilinearFails = false; // B8: the backend's bilinear last resort (WG_FRAME_BILINEAR) fails -static std::vector g_bilinearFrames; // the frames it was asked for static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { ++g_createCalls; g_createInfo = *info; @@ -172,10 +170,6 @@ static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { return WG_OK; } static WgResult FakeDispatch(WgUpscaler*, const WgFrame* frame) { - if (frame->struct_size >= sizeof(WgFrame) && (frame->flags & WG_FRAME_BILINEAR)) { // B8: no network, the last resort - g_bilinearFrames.push_back(*frame); - return g_bilinearFails ? WG_ERROR_DEVICE : WG_OK; - } g_frames.push_back(*frame); if (int(g_frames.size()) - 1 == g_parameterErrorAt) return WG_ERROR_PARAMETER; if (g_unsupportedFrom >= 0 && int(g_frames.size()) - 1 >= g_unsupportedFrom) return WG_ERROR_UNSUPPORTED; @@ -193,10 +187,7 @@ static void FakeDestroy(WgUpscaler* u) { } static uint64_t FakeMemory(WgUpscaler*) { return 12345; } static const WgUpscalerBackend g_backend{sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "fake upscaler", - FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME}; -// A backend that cannot write a frame without the network (no WG_BACKEND_BILINEAR_FRAME) -static const WgUpscalerBackend g_backendNoBilinear{sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "fake upscaler (no bilinear)", - FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT}; + FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, WG_BACKEND_NEEDS_SPLIT}; // The same backend as a version 1 DLL would return it (struct without backend_flags). static const WgUpscalerBackend g_backendV1{offsetof(WgUpscalerBackend, backend_flags), 1, "fake upscaler v1", FakeCreate, FakeDispatch, FakeDestroy, FakeMemory, 0xFFFFFFFFu}; @@ -374,8 +365,6 @@ static void Reset() { g_useBackend = &g_backend; g_standInFrames.clear(); g_standInCreateFails = g_standInDispatchFails = false; - g_bilinearFails = false; - g_bilinearFrames.clear(); g_standInCreate = WgCreateInfo{}; g_standInDestroyed = 0; g_servicesAsked.clear(); @@ -1403,7 +1392,7 @@ static void TestInterfaceVersions() { CHECK(fe1->CreateContext(&ctx, &c.upscale.header, nullptr) == FFX_API_RETURN_OK); CHECK(g_createInfo.interface_version == 1 && g_createInfo.struct_size == offsetof(WgCreateInfo, services)); CHECK(g_createInfo.services == nullptr && g_servicesAsked.size() == 1); - CHECK(BackendFlags(&g_backendV1) == 0 && BackendVersion(&g_backendV1) == 1 && BackendFlags(&g_backend) == (WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME)); + CHECK(BackendFlags(&g_backendV1) == 0 && BackendVersion(&g_backendV1) == 1 && BackendFlags(&g_backend) == WG_BACKEND_NEEDS_SPLIT); d = MakeDispatch(); CHECK(fe1->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); CHECK(g_frames.size() == 1 && g_frames[0].struct_size == offsetof(WgFrame, command_queue)); @@ -1895,19 +1884,19 @@ static void TestFailedFrameProviderTruth() { if (failure == 2) g_amdDispatchResult = FFX_API_RETURN_ERROR_RUNTIME_ERROR; auto dispatch = MakeDispatch(); if (failure == 3) dispatch.flags = FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB; - // B8: nothing upscales the frame, as before, but the answer is explicit: AMD's dispatch failing after the upscaler failed - // is a stand-in frame (failure 2); without AMD (failures 0, 1: no AMD, AMD cannot be created; failure 3: a non-linear frame) - // the backend's bilinear upscale writes it and the status says so. All of them used to be errors. - CHECK(fe->Dispatch(&ctx, &dispatch.header) == FFX_API_RETURN_OK); + if (failure == 2) { + // B8: AMD's dispatch fails after the upscaler failed: the stand-in upscales the frame (it was an error before) + CHECK(fe->Dispatch(&ctx, &dispatch.header) == FFX_API_RETURN_OK); + CHECK(!g_statuses.empty() && g_statuses.back().state == UpscaleState::StandIn); + } else { + CHECK(fe->Dispatch(&ctx, &dispatch.header) != FFX_API_RETURN_OK); CHECK(!g_statuses.empty()); if (!g_statuses.empty()) { const auto& status = g_statuses.back(); - if (failure == 2) { - CHECK(status.state == UpscaleState::StandIn); - } else { - CHECK(status.state == UpscaleState::Failed && status.reason.find("bilinearly") != std::string::npos); - CHECK(g_bilinearFrames.size() == 1); - } + CHECK(status.state != UpscaleState::Amd && status.state != UpscaleState::Network && + status.state != UpscaleState::StandIn && status.state != UpscaleState::Compare); + CHECK(!status.reason.empty()); + } } CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } @@ -2440,7 +2429,7 @@ static void TestRefusedFrames() { for (int i = 0; i < 8; ++i) CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); // every frame has an upscaler CHECK(g_frames.size() == 2 && g_standInFrames.empty()); // frame 0 the network's, frame 1 refused: AMD from there on CHECK(!g_amd.empty() && g_amd.back().fn == "dispatch" && g_statuses.back().state == UpscaleState::Amd); - CHECK(CountLog("about to start the HIP runtime") == 0); // no HIP runtime on the way + CHECK(CountLog("HIP") == 0); // no HIP runtime on the way CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); // without AMD's FSR: each refused frame goes to the stand-in (five in a row, then a taken frame, then two more @@ -2461,45 +2450,41 @@ static void TestRefusedFrames() { CHECK(g_statuses.back().state == want[i]); } CHECK(g_frames.size() == want.size() && g_standInFrames.size() == 7 && g_amd.empty()); - CHECK(CountLog("about to start the HIP runtime") == 0); + CHECK(CountLog("HIP") == 0); CHECK(CountLog("AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take") == 1); CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } } -// B8 (REVIEW-215d P1, REVIEW-228): what a refused frame gets is explicit. The upscaler answers WG_ERROR_UNSUPPORTED for frames -// 1 .. 3; the stand-in cannot be made, or fails, AMD's FSR is missing, cannot be created or fails: the backend's own bilinear -// upscale of the game's colour (WG_FRAME_BILINEAR) writes the output with one warning line per context and the answer is OK, -// never an error for a frame whose resources can be used. Every model (the contract is shared); a custom slot keeps getting -// the error (its host upscales); when the last resort is impossible the error goes back with the reason logged, also after an -// earlier success; AMD's failures are logged once per context, however long the run. +// B8 (REVIEW-215d P1, shrunk by REVIEW-228b): what a frame the upscaler refuses gets is explicit. The upscaler answers +// WG_ERROR_UNSUPPORTED for frames 1 .. 300; AMD's FSR is missing, cannot be created or fails; the stand-in cannot be made or +// fails: the frame returns the error with ONE line naming both failures (per context, not per frame), the count is logged when the +// context is destroyed. Every model (the contract is shared). An answer another upscaler can give stays an OK frame. static void TestRefusedFrameContract() { const uint64_t models[] = {kWrongGpuProviderVersionId, kWrongGpuKProviderVersionId, kWrongGpuLProviderVersionId}; + const ffxReturnCode_t amdBad = FFX_API_RETURN_ERROR_RUNTIME_ERROR; + const ffxReturnCode_t ok = FFX_API_RETURN_OK; for (const uint64_t model : models) { struct Case { const char* name; bool amd; ffxReturnCode_t amdResult; ffxReturnCode_t amdCreate; - bool standInCreateFails, standInDispatchFails, bilinearFails, backendHasBilinear, customSlot; + bool standInCreateFails, standInDispatchFails, customSlot; + const char* amdWhy; // what the one line says about AMD + const char* standInWhy; // ... and about the stand-in }; - const ffxReturnCode_t amdBad = FFX_API_RETURN_ERROR_RUNTIME_ERROR; - const ffxReturnCode_t ok = FFX_API_RETURN_OK; const Case cases[] = { - {"no AMD, stand-in create fails", false, ok, ok, true, false, false, true, false}, - {"no AMD, stand-in dispatch fails", false, ok, ok, false, true, false, true, false}, - {"no AMD, stand-in fails, bilinear fails", false, ok, ok, true, false, true, true, false}, - {"no AMD, stand-in fails, the backend has no bilinear", false, ok, ok, true, false, false, false, false}, - {"AMD create fails, stand-in ok", true, ok, FFX_API_RETURN_NO_PROVIDER, false, false, false, true, false}, - {"AMD create fails, stand-in fails", true, ok, FFX_API_RETURN_NO_PROVIDER, true, false, false, true, false}, - {"AMD dispatch fails, stand-in ok", true, amdBad, ok, false, false, false, true, false}, - {"AMD dispatch fails, stand-in create fails", true, amdBad, ok, true, false, false, true, false}, - {"AMD dispatch fails, stand-in dispatch fails", true, amdBad, ok, false, true, false, true, false}, - {"AMD dispatch fails, stand-in fails, bilinear fails", true, amdBad, ok, true, false, true, true, false}, - {"custom slot, no AMD, stand-in fails", false, ok, ok, true, false, false, true, true}, + {"no AMD, stand-in create fails", false, ok, ok, true, false, false, "is not available", "could not be created"}, + {"no AMD, stand-in dispatch fails", false, ok, ok, false, true, false, "is not available", "dispatch failed"}, + {"AMD create fails, stand-in ok", true, ok, FFX_API_RETURN_NO_PROVIDER, false, false, false, nullptr, nullptr}, + {"AMD create fails, stand-in fails", true, ok, FFX_API_RETURN_NO_PROVIDER, true, false, false, "is not available", "could not be created"}, + {"AMD dispatch fails, stand-in ok", true, amdBad, ok, false, false, false, nullptr, nullptr}, + {"AMD dispatch fails, stand-in create fails", true, amdBad, ok, true, false, false, "dispatch failed (ERROR_RUNTIME_ERROR)", "could not be created"}, + {"AMD dispatch fails, stand-in dispatch fails", true, amdBad, ok, false, true, false, "dispatch failed (ERROR_RUNTIME_ERROR)", "dispatch failed"}, + {"custom slot, no AMD, stand-in fails", false, ok, ok, true, false, true, "is not available", "could not be created"}, }; for (const Case& c : cases) { - const int failuresBefore = g_failures; Reset(); g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; g_originalAvailable = c.amd; @@ -2507,8 +2492,6 @@ static void TestRefusedFrameContract() { g_amdCreateResult = c.amdCreate; g_standInCreateFails = c.standInCreateFails; g_standInDispatchFails = c.standInDispatchFails; - g_bilinearFails = c.bilinearFails; - g_useBackend = c.backendHasBilinear ? &g_backend : &g_backendNoBilinear; Config config; config.hosted = true; config.customSlot = c.customSlot; @@ -2525,48 +2508,35 @@ static void TestRefusedFrameContract() { g_unsupportedAt = refused; std::vector rcs; for (int i = 0; i < kFrames; ++i) rcs.push_back(fe->Dispatch(&ctx, &d.header)); - const bool standInWorks = !c.standInCreateFails && !c.standInDispatchFails; - const bool lastResort = c.backendHasBilinear && !c.bilinearFails && !c.customSlot; - const bool amdFailing = c.amd && (c.amdResult != ok); - const bool answered = standInWorks || lastResort; // every frame has an output - // with a working AMD (or none that fails) the first refused frame is AMD's / the stand-in's; the cases here are - // those where AMD is absent, cannot be created, or fails - for (ffxReturnCode_t rc : rcs) CHECK(rc == (answered ? FFX_API_RETURN_OK : (amdFailing ? amdBad : FFX_API_RETURN_ERROR_RUNTIME_ERROR))); - if (answered && standInWorks) { - CHECK(g_standInFrames.size() == (size_t)kFrames && g_bilinearFrames.empty()); - } else if (answered) { - CHECK(g_bilinearFrames.size() == (size_t)kFrames); - CHECK(g_statuses.back().state == UpscaleState::Failed && - g_statuses.back().reason.find("bilinearly") != std::string::npos); - for (const WgFrame& f : g_bilinearFrames) - CHECK((f.flags & WG_FRAME_BILINEAR) && f.command_list && f.color.resource && f.output.resource); - CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); // one line, not one a frame - } else if (c.customSlot) { - CHECK(g_bilinearFrames.empty()); // a custom slot's host upscales on the error + const bool answered = !c.standInCreateFails && !c.standInDispatchFails; // the stand-in took every frame + const bool amdFailing = c.amd && c.amdResult != ok; + for (ffxReturnCode_t rc : rcs) CHECK(rc == (answered ? ok : (amdFailing ? amdBad : FFX_API_RETURN_ERROR_RUNTIME_ERROR))); + if (answered) { + CHECK(g_standInFrames.size() == (size_t)kFrames); + CHECK(CountLog("no upscaler could take this frame") == 0); } else { - CHECK(CountLog("the backend's bilinear upscale is not possible") >= 1); - CHECK(CountLog("the backend's bilinear upscale is not possible") <= 4); // the first, then at 10, 100 + // one line naming both failures, not one a frame + CHECK(CountLog("no upscaler could take this frame") == 1); + CHECK(CountLog(std::string("AMD FSR ").append(c.amdWhy).append("; the stand-in ").append(c.standInWhy).c_str()) == 1); } - // logs do not grow with the run: AMD's failure and the stand-in's notes at most once per context - CHECK(CountLog("AMD FSR dispatch failed (") <= 1); - CHECK(CountLog("about to start the HIP runtime") == 0); - CHECK(g_log.size() < 60); - if (g_failures != failuresBefore) { // the log of a failed case + CHECK(CountLog("its later failures in this context are counted") <= 1); // AMD's failure: once per context + CHECK(g_log.size() < 60); // the logs do not grow with the run + const size_t lines = g_log.size(); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + if (!answered || amdFailing) CHECK(CountLog("fallback counts:") == 1 && g_log.size() > lines); // the count, logged at the context's end + if (g_failures) { std::printf("case: %s (%zu log lines)\n", c.name, g_log.size()); - for (size_t k = 0; k < g_log.size() && k < 70; ++k) std::printf(" log: %.220s\n", g_log[k].c_str()); + for (size_t k = 0; k < g_log.size() && k < 60; ++k) std::printf(" log: %.200s\n", g_log[k].c_str()); + return; } - CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); - if (!c.customSlot && !answered) CHECK(CountLog("fallback counts:") == 1); } } - // a failure after an earlier success is reported too: the stand-in cannot be made, the bilinear upscale writes frames 1-2, then - // a frame whose output texture is missing has no last resort: its reason is logged although an earlier frame succeeded + // a failure after an earlier success is reported too: no AMD, the stand-in takes frames 1-2, then it fails { Reset(); g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; g_originalAvailable = false; - g_standInCreateFails = true; Config config; config.hosted = true; auto fe = MakeFrontEnd(config); @@ -2576,41 +2546,52 @@ static void TestRefusedFrameContract() { CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK); ffxDispatchDescUpscale d = MakeDispatch(); CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); - g_unsupportedAt = {1, 2, 3}; + g_unsupportedAt = {1, 2, 3, 4}; CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); - CHECK(g_bilinearFrames.size() == 2 && CountLog("the backend's bilinear upscale is not possible") == 0); - ffxDispatchDescUpscale bad = d; - bad.output.resource = nullptr; - CHECK(fe->Dispatch(&ctx, &bad.header) != FFX_API_RETURN_OK); - CHECK(CountLog("the backend's bilinear upscale is not possible") == 1); // the first failure, with its reason, after two successes - CHECK(CountLog("the frame has no command list, colour texture or output texture") + CountLog("the frame's inputs could not be mapped") == 1); + CHECK(g_standInFrames.size() == 2 && CountLog("no upscaler could take this frame") == 0); + g_standInDispatchFails = true; + CHECK(fe->Dispatch(&ctx, &d.header) != FFX_API_RETURN_OK); + CHECK(CountLog("no upscaler could take this frame") == 1 && CountLog("the stand-in dispatch failed") == 1); // after two successes + CHECK(fe->Dispatch(&ctx, &d.header) != FFX_API_RETURN_OK && CountLog("no upscaler could take this frame") == 1); CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } - // a frame the game flags as non-linear (sRGB / PQ) is not a refused frame: it goes to AMD's FSR, and when AMD is missing or - // fails the mapped frame still has the backend's bilinear upscale (colour-space neutral) instead of an error - for (const bool amd : {false, true}) { - Reset(); - g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; - g_originalAvailable = amd; - g_amdDispatchResult = amd ? FFX_API_RETURN_ERROR_RUNTIME_ERROR : FFX_API_RETURN_OK; - Config config; - config.hosted = true; - auto fe = MakeFrontEnd(config); - UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); - own.version.versionId = kWrongGpuProviderVersionId; - ffxContext ctx = nullptr; - CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK); - ffxDispatchDescUpscale d = MakeDispatch(); - d.flags |= FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB; - for (int i = 0; i < 5; ++i) CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); - CHECK(g_bilinearFrames.size() == 5 && g_standInFrames.empty()); // no stand-in for perceptual input - for (const WgFrame& f : g_bilinearFrames) CHECK(f.color.resource && f.output.resource && f.command_list); - CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); - CHECK(CountLog("AMD FSR dispatch failed (") <= 1 && CountLog("about to start the HIP runtime") == 0); - CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + // a frame the game flags as non-linear (sRGB / PQ) is not a refused frame: it is AMD's alone and never reaches the stand-in, + // on any path: AMD missing, AMD failing from the start, the takeover at the bad-frame threshold, and a context already handed + // to AMD whose AMD dispatch starts failing + const uint32_t flags[] = {FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB, FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_PQ}; + for (const uint32_t flag : flags) { + for (const int path : {0, 1, 2}) { // 0 AMD missing, 1 AMD failing from the start (40 frames: the takeover threshold too) + Reset(); + g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_originalAvailable = path != 0; + g_amdDispatchResult = path == 1 ? FFX_API_RETURN_ERROR_RUNTIME_ERROR : FFX_API_RETURN_OK; + Config config; + config.hosted = true; + auto fe = MakeFrontEnd(config); + UpscaleCreate own(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true); + own.version.versionId = kWrongGpuProviderVersionId; + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &own.upscale.header, kMemCb) == FFX_API_RETURN_OK); + ffxDispatchDescUpscale d = MakeDispatch(); + if (path == 2) { + // an ordinary refused frame hands the context to AMD (its dispatch works), then AMD starts failing + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); + g_unsupportedAt = {1}; + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && g_statuses.back().state == UpscaleState::Amd); + g_amdDispatchResult = FFX_API_RETURN_ERROR_RUNTIME_ERROR; + } + ffxDispatchDescUpscale p = d; + p.flags |= flag; + for (int i = 0; i < 40; ++i) CHECK(fe->Dispatch(&ctx, &p.header) != FFX_API_RETURN_OK); + CHECK(g_standInFrames.empty()); // perceptual input never reaches the stand-in + CHECK(CountLog("no upscaler could take this frame") == 1 && CountLog("the stand-in is not used for non-linear (sRGB / PQ) input") == 1); + if (path == 2) { // and an ordinary frame of the same context still gets the stand-in + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && g_standInFrames.size() == 1); + } + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } } - g_useBackend = &g_backend; } static void TestSplitBlocked() { diff --git a/clean/fsr/tests/test_refusal_integration.cpp b/clean/fsr/tests/test_refusal_integration.cpp index 6bfcea6c..38781bda 100644 --- a/clean/fsr/tests/test_refusal_integration.cpp +++ b/clean/fsr/tests/test_refusal_integration.cpp @@ -1,22 +1,23 @@ // SPDX-License-Identifier: MIT -// B8 (REVIEW-215d P2): the front end and the REAL network backend (the runtime DLL's Context, the same code a game runs) with -// a controllable executor (executor=dx12-test: the D3D12 route, scripted frame by frame), driving refused frames for model K -// and, as the control, model M; with and without AMD's FSR; repeated; with the stand-in working and failing; and with the -// real last resort (the backend's own bilinear output pass, requested with WG_FRAME_BILINEAR) writing the output, checked on -// EVERY pixel of the output (a linear ramp as the colour, so the bilinear result is known) for consecutive frames, each after -// the output was filled with a sentinel. HIP is never started: the runtime DLL's counter of HIP executors made stays 0 -// (wgDiagHipExecutorsMade), no amdhip64 module is loaded in this process, the backend never logs the HIP runtime's start. +// B8 (REVIEW-215d P2): the front end and the REAL network backend (the runtime DLL's Context, the same code a game runs) with a +// controllable executor (executor=dx12-test: the D3D12 route, scripted frame by frame), driving refused frames for model K and, as +// the control, model M; with and without AMD's FSR; repeated; with the stand-in working and with it failing. In every scenario +// the refusal comes from the backend's own code path (backend.cpp dispatch_record, refused_frame_action), never a counter, and +// HIP is never started: the runtime DLL's counter of HIP executors made stays 0 (wgDiagHipExecutorsMade, exported for this test +// only, not part of the public header), no amdhip64 module is loaded in this process, and the backend never logs the HIP runtime's +// start. // -// Windows, a D3D12 device (WARP is enough, no GPU slot needed; a GPU through gpu_slot also works) and the runtime DLL of a build -// (python clean/runner/build.py --rocm --out --runtime-only). Not part of the CI (no runtime DLL there); the -// front end's fixtures are test_frontend.cpp's, included below. From the repository root, with the registry header generated -// (python clean/wgshared/tools/gen_registry.py --out-dir ): +// Windows, a D3D12 device (WARP is enough, no GPU slot needed; a GPU through gpu_slot also works) and the runtime DLL of a build. +// It is a release check, not a CI test (CI has no runtime DLL): the release lead's script under tools/release builds it from this +// source and runs it with the DLL of the build; without the DLL it FAILS (exit 2), a gate that runs it cannot pass by skipping +// (--skip-if-missing is for a developer's loop). The front end's fixtures are test_frontend.cpp's, included below. Build, from +// the repository root, with the registry header generated (python clean/wgshared/tools/gen_registry.py --out-dir ) and the +// runtime DLL built (python clean/runner/build.py --rocm --out --runtime-only): // clang++ -std=c++17 -O1 -D_CRT_SECURE_NO_WARNINGS -I /include -I clean/wgshared/include -I clean/fsr/include -// -I clean/third_party/fidelityfx-sdk-1.1.4 clean/fsr/tests/test_refusal_integration.cpp clean/fsr/src/passthrough_d3d12.cpp +// -I clean/third_party/fidelityfx-sdk-1.1.4 clean/fsr/tests/test_refusal_integration.cpp // clean/fsr/src/{frontend,param_map,ffx_describe,config,fsr30_hook,fsr30_map,amd_compare,async_create}.cpp // -ld3d12 -ldxgi -o test_refusal_integration.exe -// test_refusal_integration.exe \wronggpu_runtime.dll -// Without the DLL it FAILS (exit 2): a gate that runs it cannot pass by skipping; --skip-if-missing is for a developer's loop. +// test_refusal_integration.exe /wronggpu_runtime.dll #define main wg_frontend_unit_main #include "test_frontend.cpp" #undef main @@ -26,12 +27,9 @@ #include #include -#include -#include #include #include - namespace { template @@ -45,9 +43,6 @@ struct Gpu { ID3D12CommandQueue* queue = nullptr; ID3D12CommandAllocator* alloc = nullptr; ID3D12GraphicsCommandList* list = nullptr; - ID3D12Fence* fence = nullptr; - uint64_t fenceValue = 0; - HANDLE event = nullptr; ID3D12Resource *color = nullptr, *depth = nullptr, *motion = nullptr, *output = nullptr; }; @@ -71,67 +66,6 @@ ID3D12Resource* MakeTexture(ID3D12Device* dev, DXGI_FORMAT fmt, UINT w, UINT h, return r; } -ID3D12Resource* MakeBuffer(ID3D12Device* dev, UINT64 bytes, D3D12_HEAP_TYPE type, D3D12_RESOURCE_STATES state) { - D3D12_HEAP_PROPERTIES hp = {}; - hp.Type = type; - D3D12_RESOURCE_DESC d = {}; - d.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; - d.Width = bytes; - d.Height = d.DepthOrArraySize = d.MipLevels = 1; - d.SampleDesc.Count = 1; - d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - ID3D12Resource* r = nullptr; - if (FAILED(dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &d, state, nullptr, IID_PPV_ARGS(&r)))) return nullptr; - return r; -} - -void Wait(Gpu& g) { - g.queue->Signal(g.fence, ++g.fenceValue); - if (g.fence->GetCompletedValue() < g.fenceValue) { - g.fence->SetEventOnCompletion(g.fenceValue, g.event); - WaitForSingleObject(g.event, 60000); - } -} - -void Submit(Gpu& g) { - g.list->Close(); - ID3D12CommandList* l[] = {g.list}; - g.queue->ExecuteCommandLists(1, l); - Wait(g); -} - -void Begin(Gpu& g) { - g.alloc->Reset(); - g.list->Reset(g.alloc, nullptr); -} - -// FP32 -> FP16 bits (round to nearest even), for values in [0, 1] -uint16_t Half(float f) { - uint32_t x; - std::memcpy(&x, &f, 4); - const int e = (int)((x >> 23) & 255) - 112; - uint32_t m = x & 0x7fffff; - if (f == 0.0f) return 0; - if (e <= 0) return 0; // (the ramp's values are not that small except 0) - uint32_t r = ((uint32_t)e << 10) | (m >> 13); - const uint32_t rem = m & 0x1fff; - if (rem > 0x1000 || (rem == 0x1000 && (r & 1))) ++r; - return (uint16_t)r; -} -float FromHalf(uint16_t h) { - const uint32_t e = (h >> 10) & 31, m = h & 1023; - if (e == 0) return (float)m / 16777216.0f * (h & 0x8000 ? -1.0f : 1.0f); - uint32_t x = ((uint32_t)(h & 0x8000) << 16) | ((e + 112) << 23) | (m << 13); - float f; - std::memcpy(&f, &x, 4); - return f; -} -// The colour texture's pixel (x, y), channel c: R = x / 1705, G = y / 959, B = 0.5, A = 0.25 (a linear ramp: the bilinear -// upscale of it is the ramp again, so that every output pixel has a known value) -uint16_t Pixel(UINT x, UINT y, UINT channel) { - return Half(channel == 0 ? (float)x / (float)(kRenderW - 1) : channel == 1 ? (float)y / (float)(kRenderH - 1) : channel == 2 ? 0.5f : 0.25f); -} - bool MakeGpu(Gpu& g) { IDXGIFactory4* f = nullptr; IDXGIAdapter* warp = nullptr; @@ -144,158 +78,16 @@ bool MakeGpu(Gpu& g) { qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; if (FAILED(g.device->CreateCommandQueue(&qd, IID_PPV_ARGS(&g.queue))) || FAILED(g.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g.alloc))) || - FAILED(g.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g.alloc, nullptr, IID_PPV_ARGS(&g.list))) || - FAILED(g.device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g.fence)))) + FAILED(g.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g.alloc, nullptr, IID_PPV_ARGS(&g.list)))) return false; - g.event = CreateEventW(nullptr, FALSE, FALSE, nullptr); const D3D12_RESOURCE_STATES srv = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; - g.color = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, - D3D12_RESOURCE_STATE_COPY_DEST); + g.color = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, srv); g.depth = MakeTexture(g.device, DXGI_FORMAT_R32_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, srv); g.motion = MakeTexture(g.device, DXGI_FORMAT_R16G16_FLOAT, kRenderW, kRenderH, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | srv); - g.output = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kOutW, kOutH, - D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - if (!g.color || !g.depth || !g.motion || !g.output) return false; - // the colour's pattern, through an upload buffer - D3D12_RESOURCE_DESC cd = g.color->GetDesc(); - D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; - UINT rows = 0; - UINT64 rowBytes = 0, total = 0; - g.device->GetCopyableFootprints(&cd, 0, 1, 0, &fp, &rows, &rowBytes, &total); - ID3D12Resource* up = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); - if (!up) return false; - uint8_t* map = nullptr; - up->Map(0, nullptr, reinterpret_cast(&map)); - for (UINT y = 0; y < rows; ++y) { - auto* row = reinterpret_cast(map + fp.Footprint.RowPitch * (size_t)y); - for (UINT x = 0; x < kRenderW; ++x) - for (UINT c = 0; c < 4; ++c) row[x * 4 + c] = Pixel(x, y, c); - } - up->Unmap(0, nullptr); - Begin(g); - D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {}; - dst.pResource = g.color; - dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - src.pResource = up; - src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; - src.PlacedFootprint = fp; - g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); - D3D12_RESOURCE_BARRIER b = {}; - b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - b.Transition.pResource = g.color; - b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - b.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; - b.Transition.StateAfter = srv; - g.list->ResourceBarrier(1, &b); - Submit(g); - up->Release(); - return true; -} - -// Fills the output texture with a sentinel (0.123 in every channel), through an upload buffer, so that a pixel the frame does -// not write stays visible -bool FillOutputSentinel(Gpu& g) { - D3D12_RESOURCE_DESC od = g.output->GetDesc(); - D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; - UINT rows = 0; - UINT64 rowBytes = 0, total = 0; - g.device->GetCopyableFootprints(&od, 0, 1, 0, &fp, &rows, &rowBytes, &total); - ID3D12Resource* up = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); - if (!up) return false; - uint8_t* map = nullptr; - up->Map(0, nullptr, reinterpret_cast(&map)); - const uint16_t v = Half(0.123f); - for (UINT y = 0; y < rows; ++y) { - auto* row = reinterpret_cast(map + (size_t)fp.Footprint.RowPitch * y); - for (UINT x = 0; x < kOutW * 4; ++x) row[x] = v; - } - up->Unmap(0, nullptr); - D3D12_RESOURCE_BARRIER b = {}; - b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - b.Transition.pResource = g.output; - b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - b.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; - b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; - g.list->ResourceBarrier(1, &b); - D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {}; - dst.pResource = g.output; - dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - src.pResource = up; - src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; - src.PlacedFootprint = fp; - g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); - std::swap(b.Transition.StateBefore, b.Transition.StateAfter); - g.list->ResourceBarrier(1, &b); - Submit(g); - Begin(g); - up->Release(); - return true; -} - -// The whole output texture as RGBA16F halves, row by row (kOutW * 4 per row) -bool ReadOutput(Gpu& g, std::vector* out) { - D3D12_RESOURCE_DESC od = g.output->GetDesc(); - D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; - UINT rows = 0; - UINT64 rowBytes = 0, total = 0; - g.device->GetCopyableFootprints(&od, 0, 1, 0, &fp, &rows, &rowBytes, &total); - ID3D12Resource* rb = MakeBuffer(g.device, total, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); - if (!rb) return false; - g.list->Close(); - ID3D12CommandList* l[] = {g.list}; - g.queue->ExecuteCommandLists(1, l); - Wait(g); - g.device->GetDeviceRemovedReason(); - Begin(g); - D3D12_RESOURCE_BARRIER b = {}; - b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - b.Transition.pResource = g.output; - b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - b.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; - b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; - g.list->ResourceBarrier(1, &b); - D3D12_TEXTURE_COPY_LOCATION src = {}, dst = {}; - src.pResource = g.output; - src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - dst.pResource = rb; - dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; - dst.PlacedFootprint = fp; - g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); - std::swap(b.Transition.StateBefore, b.Transition.StateAfter); - g.list->ResourceBarrier(1, &b); - Submit(g); - uint8_t* map = nullptr; - rb->Map(0, nullptr, reinterpret_cast(&map)); - out->resize((size_t)kOutW * kOutH * 4); - for (UINT y = 0; y < kOutH; ++y) - std::memcpy(out->data() + (size_t)y * kOutW * 4, map + (size_t)fp.Footprint.RowPitch * y, (size_t)kOutW * 8); - rb->Unmap(0, nullptr); - rb->Release(); - Begin(g); - return true; -} - -// Every output pixel against the converter's bilinear upscale of the ramp (convert.cpp PASS_FALLBACK: the sample position -// (o + 0.5) * R / O - 0.5, the taps clamped to the render region; alpha 1, or the colour's alpha for model K) -size_t BadPixels(const std::vector& px, bool model_k, float* worst) { - size_t bad = 0; - *worst = 0; - for (UINT oy = 0; oy < kOutH; ++oy) { - const float sy = std::min(std::max(((float)oy + 0.5f) * kRenderH / kOutH - 0.5f, 0.0f), (float)(kRenderH - 1)); - for (UINT ox = 0; ox < kOutW; ++ox) { - const float sx = std::min(std::max(((float)ox + 0.5f) * kRenderW / kOutW - 0.5f, 0.0f), (float)(kRenderW - 1)); - const float want[4] = {sx / (float)(kRenderW - 1), sy / (float)(kRenderH - 1), 0.5f, model_k ? 0.25f : 1.0f}; - bool ok = true; - for (int c = 0; c < 4; ++c) { - const float d = std::fabs(FromHalf(px[((size_t)oy * kOutW + ox) * 4 + c]) - want[c]); - *worst = std::max(*worst, d); - ok = ok && d <= 3e-3f; - } - if (!ok) ++bad; - } - } - return bad; + g.output = MakeTexture(g.device, DXGI_FORMAT_R16G16B16A16_FLOAT, kOutW, kOutH, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + return g.color && g.depth && g.motion && g.output; } void RealRefusals(const char* dllPath) { @@ -308,17 +100,15 @@ void RealRefusals(const char* dllPath) { const WgUpscalerBackend* real = get ? get(WG_UPSCALER_INTERFACE_VERSION) : nullptr; CHECK(real != nullptr); if (!real) return; - std::printf("backend %p\n", (const void*)real); - std::fflush(stdout); Gpu g; CHECK(MakeGpu(g)); std::printf("WARP device and textures: %s\n", g.output ? "ready" : "FAILED"); std::fflush(stdout); if (!g.output) return; - CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); using HipMadeFn = uint32_t (*)(); const auto hipMade = reinterpret_cast(reinterpret_cast(GetProcAddress(dll, "wgDiagHipExecutorsMade"))); - CHECK(hipMade != nullptr); // the runtime DLL counts the HIP executors it makes + CHECK(hipMade != nullptr); // the runtime DLL counts the HIP executors it makes (a diagnostic export) + CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); struct Scenario { const char* name; @@ -330,7 +120,7 @@ void RealRefusals(const char* dllPath) { const Scenario scenarios[] = { {"AMD available", true, false, "orrrrr", 6}, {"no AMD, stand-in works, five refusals in a row then taken", false, false, "orrrrroo", 8}, - {"no AMD, stand-in cannot be made: the backend's bilinear output pass writes the frame", false, true, "orrr", 4}, + {"no AMD, stand-in cannot be made: AMD and the stand-in both failed, the error goes back", false, true, "orrroo", 6}, }; for (const bool model_k : {true, false}) { // model K, and model M as the control for (const Scenario& sc : scenarios) { @@ -365,69 +155,49 @@ void RealRefusals(const char* dllPath) { d.output = Res(g.output, FFX_API_SURFACE_FORMAT_R16G16B16A16_FLOAT, kOutW, kOutH, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS); d.renderSize = {kRenderW, kRenderH}; d.upscaleSize = {kOutW, kOutH}; - Begin(g); + g.alloc->Reset(); + g.list->Reset(g.alloc, nullptr); std::vector rc; std::vector state; - std::vector bad; // scenario 3: the output pixels that are not the bilinear upscale, per frame - float worst = 0; for (int i = 0; i < sc.frames; ++i) { - if (sc.standInCreateFails && i > 0) CHECK(FillOutputSentinel(g)); // each refused frame writes the whole output itself - if (sc.standInCreateFails && i == 1 && model_k) { // negative control: an output nobody wrote is every pixel wrong - std::vector unwritten; - float w = 0; - CHECK(ReadOutput(g, &unwritten) && BadPixels(unwritten, model_k, &w) == (size_t)kOutW * kOutH); - } rc.push_back(fe->Dispatch(&ctx, &d.header)); state.push_back(g_statuses.empty() ? UpscaleState::Failed : g_statuses.back().state); - if (sc.standInCreateFails && i > 0) { - std::vector px; - CHECK(ReadOutput(g, &px)); - float w = 0; - bad.push_back(BadPixels(px, model_k, &w)); - worst = std::max(worst, w); - } } - Submit(g); // the game's list, with whatever the front end recorded in it, runs - CHECK(g.device->GetDeviceRemovedReason() == S_OK); - for (ffxReturnCode_t r : rc) CHECK(r == FFX_API_RETURN_OK); // every frame has an upscaler, whatever the refusals - CHECK(state[0] == UpscaleState::Network); // frame 0 is the real backend's - // the refusals came from the real backend's code path (backend.cpp dispatch_record), one line, not a counter + g.list->Close(); + CHECK(rc[0] == FFX_API_RETURN_OK && state[0] == UpscaleState::Network); // frame 0 is the real backend's + // the refusals came from the real backend's code path (dispatch_record): K's and M's own line, once, not a counter CHECK(CountLog(model_k ? "model K: the D3D12 executor does not take this frame" : "executor dx12 (default on RDNA 4) does not take this frame") == 1); - CHECK(CountLog("ERROR_RUNTIME_ERROR") == 0); if (sc.amd) { // the first refused frame hands the context to AMD's FSR for good: the rest are AMD's + for (int i = 0; i < sc.frames; ++i) CHECK(rc[i] == FFX_API_RETURN_OK); CHECK(state[1] == UpscaleState::Amd && !g_amd.empty() && g_amd.back().fn == "dispatch"); for (int i = 2; i < sc.frames; ++i) CHECK(state[i] == UpscaleState::Amd); CHECK(CountLog("WrongGPU frame: frame=") == 2 && g_standInFrames.empty()); // the backend was asked for frames 0 and 1 only } else if (!sc.standInCreateFails) { - // the stand-in takes each refused frame (five in a row included); the context stays WrongGPU's: the taken - // frames after the refusals are the real backend's again + // the stand-in takes each refused frame (five in a row included); the context stays WrongGPU's: the taken frames + // after the refusals are the real backend's again + for (int i = 0; i < sc.frames; ++i) CHECK(rc[i] == FFX_API_RETURN_OK); for (int i = 1; i <= 5; ++i) CHECK(state[i] == UpscaleState::StandIn); CHECK(state[6] == UpscaleState::Network && state[7] == UpscaleState::Network); CHECK(g_standInFrames.size() == 5 && g_amd.empty()); - CHECK(CountLog("AMD FSR is not available for this context; the stand-in upscales the frames the upscaler does not take") == 1); } else { - // no stand-in, no AMD: the REAL backend's bilinear output pass wrote each refused frame (WG_FRAME_BILINEAR through - // the front end's last resort), every pixel of the output, for consecutive frames - for (int i = 1; i < sc.frames; ++i) - CHECK(state[i] == UpscaleState::Failed && g_statuses.back().reason.find("bilinearly") != std::string::npos); + // neither AMD nor the stand-in: the refused frames (1-3) return the error with ONE line naming both failures; the + // frames the backend takes afterwards (4, 5) are fine again + for (int i = 1; i <= 3; ++i) CHECK(rc[i] != FFX_API_RETURN_OK && state[i] == UpscaleState::Failed); + CHECK(rc[4] == FFX_API_RETURN_OK && rc[5] == FFX_API_RETURN_OK); + CHECK(CountLog("no upscaler could take this frame: AMD FSR is not available; the stand-in could not be created") == 1); CHECK(g_amd.empty() && g_standInFrames.empty()); - CHECK(CountLog("the backend's bilinear upscale of the game's colour wrote the output") == 1); - CHECK(bad.size() == (size_t)(sc.frames - 1)); - for (size_t b : bad) CHECK(b == 0); // no pixel left at the sentinel or off the bilinear value - std::printf(" output checked on every pixel for %zu frame(s): worst difference %.5f\n", bad.size(), worst); - CHECK(worst <= 3e-3f); } - // HIP never started: no HIP runtime line, no amdhip64 module + // HIP never started: no HIP runtime line, no amdhip64 module, no HIP executor constructed CHECK(CountLog("about to start the HIP runtime") == 0); CHECK(GetModuleHandleA("amdhip64_7.dll") == nullptr && GetModuleHandleA("amdhip64.dll") == nullptr); - CHECK(hipMade && hipMade() == 0); // no HIP executor was ever constructed by the backend - CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + CHECK(hipMade && hipMade() == 0); if (g_failures != failuresBefore) { // the log of a failed scenario std::lock_guard lock(g_logMutex); for (const std::string& line : g_log) std::printf(" log: %s\n", line.c_str()); } + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); std::printf(" %s: states", tag.c_str()); for (UpscaleState s : state) std::printf(" %d", (int)s); std::printf(", checks so far %d, failures %d\n", g_checks, g_failures); @@ -443,11 +213,11 @@ void RealRefusals(const char* dllPath) { } // namespace int main(int argc, char** argv) { - const char* dll = argc > 1 && std::strcmp(argv[1], "--skip-if-missing") != 0 ? argv[1] : std::getenv("WG_TEST_RUNTIME_DLL"); + const bool skipMissing = argc > 1 && std::strcmp(argv[1], "--skip-if-missing") == 0; + const char* dll = argc > 1 && !skipMissing ? argv[1] : std::getenv("WG_TEST_RUNTIME_DLL"); if (!dll || !*dll) { - const bool skip = argc > 1 && std::strcmp(argv[1], "--skip-if-missing") == 0; - std::printf("%s: no runtime DLL (argument or WG_TEST_RUNTIME_DLL)\n", skip ? "SKIP" : "FAIL"); - return skip ? 0 : 2; + std::printf("%s: no runtime DLL (argument or WG_TEST_RUNTIME_DLL)\n", skipMissing ? "SKIP" : "FAIL"); + return skipMissing ? 0 : 2; } RealRefusals(dll); std::printf("%d checks, %d failures\n", g_checks, g_failures); diff --git a/clean/k/tests/test_k_alpha.py b/clean/k/tests/test_k_alpha.py index c8d1d226..62ed38d0 100644 --- a/clean/k/tests/test_k_alpha.py +++ b/clean/k/tests/test_k_alpha.py @@ -307,8 +307,7 @@ def test_interop(self): self.assertIn("d.Buffer.NumElements = (model_k_ ? 4 : 3) * f.output_width * f.output_height;", c) self.assertIn("void set_model_k(bool on) { model_k_ = on; }", ch) self.assertIn("bool model_k_ = false;", ch) # model M (and every other Converter user): as before - # configure_hip (every real executor), and the scripted executor=dx12-test branch of create (tests of the backend) - self.assertEqual(b.count("conv_.set_model_k("), 2) + self.assertEqual(b.count("conv_.set_model_k("), 1) self.assertIn("conv_.set_model_k(model_k_);", b) self.assertIn("job.out_rgba32f = model_k_ && !halfOut;", b) self.assertIn("sizes[4] = std::max(O * (model_k_ ? 16 : 12), po * oh_);", b) diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 452bdf77..37ed0f99 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -657,7 +657,6 @@ class Context { #ifndef WG_NO_MODEL_K model_k_ = test_model_k; #endif - conv_.set_model_k(model_k_); } else if (o.executor == "hip" || o.executor == "dx12") { if (!configure_hip(o, &err)) return fail(WG_ERROR, err); } else { @@ -875,30 +874,7 @@ class Context { return r; } - // B8 (WG_FRAME_BILINEAR): the front end's last resort for a frame that nothing else could upscale: no network, no executor, the - // existing bilinear output pass (Converter::record_output without a result: format aware, the full output size, its own - // barrier handling) from the game's colour into the output texture. It does not touch the context's state: a failed context - // can still write such a frame, and an answer other than WG_OK never fails the context. - WgResult dispatch_bilinear(const WgFrame& f) { - auto refuse = [&](WgResult r, const std::string& why) { - if (bilinear_refusals_++ == 0) say(WG_LOG_WARN, "bilinear last-resort frame refused: " + why); - return r; - }; - if (!f.command_list || !f.color.resource || !f.color.format || !f.output.resource || !f.output.format) - return refuse(WG_ERROR_PARAMETER, "no command list, colour or output texture"); - if (!f.render_width || !f.render_height || f.output_width != ow_ || f.output_height != oh_) - return refuse(WG_ERROR_PARAMETER, "the render region is empty or the output size differs from the context's"); - const std::string skip = skip_reason(f); - if (!skip.empty()) return refuse(WG_ERROR_PARAMETER, skip); - const std::string out = output_refusal(f); - if (!out.empty()) return refuse(WG_ERROR_INPUT, out); - conv_.record_output(static_cast(f.command_list), f, BufferRange()); - note_path(&output_path_, "output: bilinear (the front end's last resort: nothing else upscaled this frame)"); - return WG_OK; - } - WgResult dispatch_impl(const WgFrame& f) { - if (f.struct_size >= sizeof(WgFrame) && (f.flags & WG_FRAME_BILINEAR)) return dispatch_bilinear(f); std::string why; if (!valid(f, &why)) return fail_frame(WG_ERROR_PARAMETER, why); if (failed_) return WG_ERROR; @@ -2189,7 +2165,6 @@ class Context { bool dx12_default_ = false; bool hip_switch_ = kHipSwitchDefault; // refused_frame_policy (option hip_switch; clean/fe-wrapped-list) bool no_switch_said_ = false; // the hip_switch=off line was logged - uint64_t bilinear_refusals_ = 0; // WG_FRAME_BILINEAR requests this context could not record (logged once) bool split_ = false; std::string share_path_opt_ = "auto"; bool input_copy_opt_ = false; @@ -2252,7 +2227,7 @@ void wg_destroy(WgUpscaler* u) { uint64_t wg_memory(WgUpscaler* u) { return u ? u->ctx.gpu_memory() : 0; } const WgUpscalerBackend kBackend = {sizeof(WgUpscalerBackend), WG_UPSCALER_INTERFACE_VERSION, "WrongGPU network", - &wg_create, &wg_dispatch, &wg_destroy, &wg_memory, WG_BACKEND_NEEDS_SPLIT | WG_BACKEND_BILINEAR_FRAME}; + &wg_create, &wg_dispatch, &wg_destroy, &wg_memory, WG_BACKEND_NEEDS_SPLIT}; } // namespace