Skip to content

Commit c570e09

Browse files
Front end: reactive-mask generation reaches AMD's context when one exists
A dispatch of type GENERATEREACTIVEMASK on a WrongGPU context returned OK and recorded nothing. Some frames of such a context still go to AMD's upscaler with the game's reactive resource (frames WrongGPU cannot take, the player's comparison), and those frames read a mask that was not written this frame. With an AMD context at hand (the comparison context while comparing, else the context made for an earlier frame) the call is now sent to it. Without one it stays OK with nothing recorded; the first frame of a run needs no change. Fixes #59 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
1 parent 234515a commit c570e09

2 files changed

Lines changed: 86 additions & 2 deletions

File tree

‎clean/fsr/src/frontend.cpp‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,26 @@ ffxReturnCode_t FrontEnd::Dispatch(ffxContext* context, const ffxDispatchDescHea
17691769
return DispatchUpscale(*u, d, call);
17701770
}
17711771
if (desc->type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE_GENERATEREACTIVEMASK) {
1772-
// The reactive mask only feeds AMD's upscaler; WrongGPU's does not read it.
1773-
if (log) Log(tag + " -> OK (WrongGPU: reactive mask not needed, nothing recorded)");
1772+
// The reactive mask only feeds AMD's upscaler; WrongGPU's does not read it. But some frames of this context
1773+
// still go to AMD's upscaler (frames WrongGPU cannot take, the player's comparison) with the game's own
1774+
// reactive resource, which then needs this frame's mask: with an AMD context at hand the call goes to it
1775+
// (the generation does not depend on which context runs it). Issue #59.
1776+
const bool comparing = !config_.customSlot && platform_.compareAmd && platform_.compareAmd();
1777+
const OriginalApi* api = nullptr;
1778+
ffxContext* target = nullptr;
1779+
const char* what = "";
1780+
if (comparing && u->comparison.context && u->comparison.api) {
1781+
api = u->comparison.api, target = &u->comparison.context, what = "comparison";
1782+
} else if (u->amd && u->amdApi) {
1783+
api = u->amdApi, target = &u->amd, what = "AMD";
1784+
}
1785+
if (api && target) {
1786+
const ffxReturnCode_t rc = api->dispatch(target, desc);
1787+
if (log || rc != FFX_API_RETURN_OK)
1788+
Log(tag + " -> " + RcName(rc) + " (reactive mask forwarded to AMD's context, " + what + ")");
1789+
return rc;
1790+
}
1791+
if (log) Log(tag + " -> OK (WrongGPU: reactive mask not needed, nothing recorded: no AMD context yet)");
17741792
return FFX_API_RETURN_OK;
17751793
}
17761794
Log(tag + " -> ERROR_UNKNOWN_DESCTYPE (WrongGPU)");

‎clean/fsr/tests/test_frontend.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,71 @@ static void TestCompare() {
11871187
CHECK(g_amd.back().fn == "destroy" && g_amd.back().memCb == nullptr);
11881188
}
11891189

1190+
// Issue #59: the reactive-mask generation call of a WrongGPU context goes to AMD's context when one exists (frames of
1191+
// the context that went to AMD with the game's own reactive resource need this frame's mask): in a comparison and
1192+
// after a frame the stand-in could not take. Without an AMD context there is nothing to send it to (OK, nothing
1193+
// recorded, as before). A failure of AMD's call is the call's result.
1194+
static void TestReactiveMaskForwarded() {
1195+
auto maskCalls = [] {
1196+
size_t n = 0;
1197+
for (const AmdCall& c : g_amd) n += c.fn == "dispatch" && c.type == FFX_API_DISPATCH_DESC_TYPE_UPSCALE_GENERATEREACTIVEMASK;
1198+
return n;
1199+
};
1200+
ffxDispatchDescUpscaleGenerateReactiveMask mask{};
1201+
mask.header.type = FFX_API_DISPATCH_DESC_TYPE_UPSCALE_GENERATEREACTIVEMASK;
1202+
1203+
// Comparison.
1204+
Reset();
1205+
g_resources[kColor] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440};
1206+
g_resources[kDepth] = {dxgi::R32_FLOAT, 2560, 1440};
1207+
g_resources[kMotion] = {dxgi::R16G16_FLOAT, 2560, 1440};
1208+
g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440};
1209+
{
1210+
auto fe = MakeFrontEnd(Config{});
1211+
UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE, /*withOverride=*/true);
1212+
ffxContext ctx = nullptr;
1213+
CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK);
1214+
ffxDispatchDescUpscale d = MakeDispatch();
1215+
CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); // WrongGPU
1216+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_OK && g_amd.empty()); // no AMD context yet
1217+
g_compare = true;
1218+
CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); // AMD's context is made and dispatched
1219+
CHECK(g_amd.size() == 3 && maskCalls() == 0);
1220+
const size_t before = g_amd.size();
1221+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_OK);
1222+
CHECK(g_amd.size() == before + 1 && maskCalls() == 1 && g_amd.back().context == g_amd[0].context);
1223+
g_amdDispatchResult = FFX_API_RETURN_ERROR_RUNTIME_ERROR;
1224+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_ERROR_RUNTIME_ERROR && maskCalls() == 2);
1225+
g_amdDispatchResult = FFX_API_RETURN_OK;
1226+
g_compare = false; // back to WrongGPU: AMD's context still exists, the call still reaches it (next frames may go to AMD)
1227+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_OK && maskCalls() == 3);
1228+
CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK);
1229+
}
1230+
1231+
// A frame the stand-in cannot take (no output): AMD's context is made from the saved create parameters.
1232+
Reset();
1233+
g_resources[kColor] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440};
1234+
g_resources[kDepth] = {dxgi::R32_FLOAT, 2560, 1440};
1235+
g_resources[kMotion] = {dxgi::R16G16_FLOAT, 2560, 1440};
1236+
g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440};
1237+
{
1238+
auto fe = MakeFrontEnd(Config{});
1239+
UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE);
1240+
ffxContext ctx = nullptr;
1241+
CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK);
1242+
ffxDispatchDescUpscale good = MakeDispatch();
1243+
CHECK(fe->Dispatch(&ctx, &good.header) == FFX_API_RETURN_OK);
1244+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_OK && g_amd.empty()); // no AMD context yet
1245+
ffxDispatchDescUpscale bad = MakeDispatch();
1246+
bad.output.resource = nullptr;
1247+
CHECK(fe->Dispatch(&ctx, &bad.header) == FFX_API_RETURN_OK);
1248+
CHECK(g_amd.size() == 2 && g_amd[0].fn == "create" && g_amd[1].fn == "dispatch" && maskCalls() == 0);
1249+
CHECK(fe->Dispatch(&ctx, &mask.header) == FFX_API_RETURN_OK);
1250+
CHECK(g_amd.size() == 3 && maskCalls() == 1 && g_amd.back().context == g_amd[0].context);
1251+
CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK);
1252+
}
1253+
}
1254+
11901255
// Interface version 2: a version 2 backend gets the services and the version 2 frame; a version 1 backend gets the
11911256
// version 1 structures; WG_ERROR_NOT_READY runs the stand-in for that frame only and keeps the context on the backend.
11921257
static void TestInterfaceVersions() {
@@ -3110,6 +3175,7 @@ int main() {
31103175
TestParkedContexts();
31113176
TestHostedSwitchNotParked();
31123177
TestCompare();
3178+
TestReactiveMaskForwarded();
31133179
TestSlowCreate();
31143180
TestInterfaceVersions();
31153181
TestAmdMode();

0 commit comments

Comments
 (0)