@@ -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.
11921257static 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