@@ -41,13 +41,18 @@ namespace winrt::StyleTransferEffectCpp::implementation
4141 OutputDebugString (L" Close\n " );
4242 if (Binding != nullptr ) Binding.Clear ();
4343 if (Session != nullptr ) Session.Close ();
44- /* for (int i = 0; i < swapChainEntryCount; i++) {
45- if (bindings[i]->binding != nullptr)
44+ // Make sure evalAsyncs are done before clearing resources
45+ for (int i = 0 ; i < swapChainEntryCount; i++) {
46+ if (bindings[i]->activetask != nullptr &&
47+ bindings[i]->binding != nullptr )
48+ {
49+ bindings[i]->activetask .get ();
4650 bindings[i]->binding .Clear ();
47- }*/
51+ }
52+ }
4853 }
4954
50- void StyleTransferEffect::SubmitEval (int swapchaindex, VideoFrame input, VideoFrame output) {
55+ void StyleTransferEffect::SubmitEval (VideoFrame input, VideoFrame output) {
5156 auto currentBinding = bindings[0 ].get ();
5257 // VideoFrame outputTransformed = cachedOutput;
5358 // Different way of waiting for a swapchain index to finish?
@@ -58,7 +63,7 @@ namespace winrt::StyleTransferEffectCpp::implementation
5863 auto now = std::chrono::high_resolution_clock::now ();
5964 OutputDebugString (L" PF Start new Eval " );
6065 std::wostringstream ss;
61- ss << swapchaindex ;
66+ ss << swapChainIndex ;
6267 OutputDebugString (ss.str ().c_str ());
6368 OutputDebugString (L" | " );
6469
@@ -70,7 +75,6 @@ namespace winrt::StyleTransferEffectCpp::implementation
7075 std::rotate (bindings.begin (), bindings.begin () + 1 , bindings.end ());
7176 finishedIdx = (finishedIdx - 1 + swapChainEntryCount) % swapChainEntryCount;
7277 }
73-
7478 currentBinding->activetask = Session.EvaluateAsync (currentBinding->binding , ss.str ().c_str ());
7579 currentBinding->activetask .Completed ([&, currentBinding, now](auto && asyncInfo, winrt::Windows::Foundation::AsyncStatus const args) {
7680 OutputDebugString (L" PF Eval completed |" );
@@ -110,29 +114,13 @@ namespace winrt::StyleTransferEffectCpp::implementation
110114
111115 void StyleTransferEffect::ProcessFrame (ProcessVideoFrameContext context) {
112116 OutputDebugString (L" PF Start | " );
113- // OutputDebugString(index(thread().get_id()).c_str());
114117 auto now = std::chrono::high_resolution_clock::now ();
115118 VideoFrame inputFrame = context.InputFrame ();
116119 VideoFrame outputFrame = context.OutputFrame ();
117120
118- SubmitEval (swapChainIndex, inputFrame, outputFrame);
119- // Go thorugh swapchain, find most recently completed entry
120- // context.OutputFrame() = bindings[swapChainIndex].outputCache;
121- /* for (int i = 0; i < swapChainEntryCount; i++) {
122- int index = (swapChainIndex - i) % swapChainEntryCount;
123- if (index < 0) index += swapChainEntryCount;
124- if (bindings[index].activetask != NULL) {
125- auto entry = bindings[index].activetask;
126- if (entry.Status() == Windows::Foundation::AsyncStatus::Completed) {
127- OutputDebugString(L"PF Find recent | ");
128- outputFrame = bindings[index].outputCache;
129- }
130- }
131- }*/
121+ SubmitEval (inputFrame, outputFrame);
132122
133123 swapChainIndex = (++swapChainIndex) % swapChainEntryCount; // move on to the next entry after each call to PF.
134- auto timePassed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - now);
135- // Notifier.SetFrameRate(1000.f / timePassed.count()); // Convert to FPS: milli to seconds, invert
136124 }
137125
138126 void StyleTransferEffect::SetEncodingProperties (VideoEncodingProperties props, IDirect3DDevice device) {
0 commit comments