@@ -55,36 +55,36 @@ namespace winrt::StyleTransferEffectCpp::implementation
5555 OutputDebugString (L" PF Start new Eval " );
5656 std::wostringstream ss;
5757 ss << swapchaindex;
58- auto idx = ss.str ().c_str ();
59- OutputDebugString (idx);
58+ OutputDebugString (ss.str ().c_str ());
6059 OutputDebugString (L" | " );
6160
6261 // bind the input and the output buffers by name
6362 bindings[swapchaindex].binding .Bind (InputImageDescription, input);
6463 // submit an eval and wait for it to finish submitting work
6564 std::lock_guard<mutex> guard{ Processing }; // Is this still happening inside of Complete?
6665 bindings[swapchaindex].activetask = Session.EvaluateAsync (bindings[swapchaindex].binding , ss.str ().c_str ());
67- bindings[swapchaindex].activetask .Completed ([&](auto && asyncInfo, winrt::Windows::Foundation::AsyncStatus const args) {
68- OutputDebugString (L" PF Eval completed | " );
66+ bindings[swapchaindex].activetask .Completed ([&, swapchaindex ](auto && asyncInfo, winrt::Windows::Foundation::AsyncStatus const args) {
67+ OutputDebugString (L" PF Eval completed |" );
6968 VideoFrame evalOutput = asyncInfo.GetResults ().Outputs ().Lookup (OutputImageDescription).try_as <VideoFrame>();
7069 // second lock to protect shared resource of cachedOutputCopy ?
7170 {
72- std::lock_guard<mutex> guard{ Copy };
71+ // std::lock_guard<mutex> guard{ Copy };
7372 OutputDebugString (L" PF Copy | " );
74- evalOutput.CopyToAsync (cachedOutputCopy). get ( );
73+ evalOutput.CopyToAsync (bindings[swapchaindex]. outputCache );
7574 }
76- cachedOutput = cachedOutputCopy ;
77-
75+ // cachedOutput = bindings[swapchaindex].outputCache ;
76+ finishedIdx = swapchaindex;
7877 OutputDebugString (L" PF End " );
79- // OutputDebugString(ss.str().c_str());
80- // OutputDebugString(L"\n");
8178 });
8279 }
83- if (cachedOutput != nullptr ) {
80+ if (bindings[finishedIdx].outputCache != nullptr ) {
81+ std::wostringstream ss;
82+ ss << finishedIdx;
8483 std::lock_guard<mutex> guard{ Copy };
85- OutputDebugString (L" \n Start CopyAsync | " );
86- cachedOutput.CopyToAsync (output).get ();
87- OutputDebugString (L" Stop CopyAsync\n " );
84+ OutputDebugString (L" \n Start CopyAsync " );
85+ OutputDebugString (ss.str ().c_str ());
86+ bindings[finishedIdx].outputCache .CopyToAsync (output).get ();
87+ OutputDebugString (L" | Stop CopyAsync\n " );
8888 }
8989 // return without waiting for the submit to finish, setup the completion handler
9090 }
@@ -97,6 +97,19 @@ namespace winrt::StyleTransferEffectCpp::implementation
9797 VideoFrame outputFrame = context.OutputFrame ();
9898
9999 SubmitEval (swapChainIndex, inputFrame, outputFrame);
100+ // Go thorugh swapchain, find most recently completed entry
101+ // context.OutputFrame() = bindings[swapChainIndex].outputCache;
102+ /* for (int i = 0; i < swapChainEntryCount; i++) {
103+ int index = (swapChainIndex - i) % swapChainEntryCount;
104+ if (index < 0) index += swapChainEntryCount;
105+ if (bindings[index].activetask != NULL) {
106+ auto entry = bindings[index].activetask;
107+ if (entry.Status() == Windows::Foundation::AsyncStatus::Completed) {
108+ OutputDebugString(L"PF Find recent | ");
109+ outputFrame = bindings[index].outputCache;
110+ }
111+ }
112+ }*/
100113
101114 swapChainIndex = (++swapChainIndex) % swapChainEntryCount; // move on to the next entry after each call to PF.
102115 auto timePassed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - now);
0 commit comments