Skip to content

Commit 848105e

Browse files
clean up Evals when switching between cpu/gpu
1 parent 4e305fb commit 848105e

File tree

5 files changed

+19
-49
lines changed

5 files changed

+19
-49
lines changed

Samples/StyleTransfer/StyleTransfer.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
<Version>2.4.2</Version>
222222
</PackageReference>
223223
<PackageReference Include="Microsoft.Windows.CppWinRT">
224-
<Version>2.0.200703.9</Version>
224+
<Version>2.0.200729.8</Version>
225225
</PackageReference>
226226
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
227227
<Version>2.0.1</Version>
@@ -241,10 +241,10 @@
241241
<None Include="StyleTransfer_TemporaryKey.pfx" />
242242
</ItemGroup>
243243
<ItemGroup>
244-
<ProjectReference Include="VideoEffect\StyleTransferEffectCpp\StyleTransferEffectCpp.vcxproj">
245-
<Project>{05dffb01-62c4-458c-be13-7a97e8583e43}</Project>
246-
<Name>StyleTransferEffectCpp</Name>
247-
</ProjectReference>
244+
<Reference Include="StyleTransferEffectCpp, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
245+
<SpecificVersion>False</SpecificVersion>
246+
<HintPath>VideoEffect\StyleTransferEffectCpp\x64\Debug\StyleTransferEffectCpp\StyleTransferEffectCpp.winmd</HintPath>
247+
</Reference>
248248
</ItemGroup>
249249
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
250250
<VisualStudioVersion>14.0</VisualStudioVersion>

Samples/StyleTransfer/StyleTransfer.sln

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30204.135
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StyleTransfer", "StyleTransfer.csproj", "{9CC66287-64B8-4321-B701-7E52F200A027}"
77
EndProject
8-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StyleTransferEffectCpp", "VideoEffect\StyleTransferEffectCpp\StyleTransferEffectCpp.vcxproj", "{05DFFB01-62C4-458C-BE13-7A97E8583E43}"
9-
EndProject
108
Global
119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1210
Debug|ARM = Debug|ARM
@@ -43,22 +41,6 @@ Global
4341
{9CC66287-64B8-4321-B701-7E52F200A027}.Release|x86.ActiveCfg = Release|x86
4442
{9CC66287-64B8-4321-B701-7E52F200A027}.Release|x86.Build.0 = Release|x86
4543
{9CC66287-64B8-4321-B701-7E52F200A027}.Release|x86.Deploy.0 = Release|x86
46-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|ARM.ActiveCfg = Debug|ARM
47-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|ARM.Build.0 = Debug|ARM
48-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|ARM64.ActiveCfg = Debug|ARM64
49-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|ARM64.Build.0 = Debug|ARM64
50-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x64.ActiveCfg = Debug|x64
51-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x64.Build.0 = Debug|x64
52-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.ActiveCfg = Debug|Win32
53-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.Build.0 = Debug|Win32
54-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM.ActiveCfg = Release|ARM
55-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM.Build.0 = Release|ARM
56-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM64.ActiveCfg = Release|ARM64
57-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM64.Build.0 = Release|ARM64
58-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|x64.ActiveCfg = Release|x64
59-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|x64.Build.0 = Release|x64
60-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|x86.ActiveCfg = Release|Win32
61-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|x86.Build.0 = Release|Win32
6244
EndGlobalSection
6345
GlobalSection(SolutionProperties) = preSolution
6446
HideSolutionNode = FALSE

Samples/StyleTransfer/VideoEffect/StyleTransferEffectCpp/StyleTransferEffect.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

Samples/StyleTransfer/VideoEffect/StyleTransferEffectCpp/StyleTransferEffect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace winrt::StyleTransferEffectCpp::implementation
3636
void ProcessFrame(ProcessVideoFrameContext);
3737
void SetEncodingProperties(VideoEncodingProperties, IDirect3DDevice);
3838
void SetProperties(IPropertySet);
39-
void SubmitEval(int, VideoFrame, VideoFrame);
39+
void SubmitEval(VideoFrame, VideoFrame);
4040

4141
private:
4242
LearningModelSession Session;

Samples/StyleTransfer/VideoEffect/StyleTransferEffectCpp/StyleTransferEffectCpp.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Global
2323
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|ARM64.Build.0 = Debug|ARM64
2424
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x64.ActiveCfg = Debug|x64
2525
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x64.Build.0 = Debug|x64
26-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.ActiveCfg = Debug|Win32
27-
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.Build.0 = Debug|Win32
26+
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.ActiveCfg = Debug|x64
27+
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Debug|x86.Build.0 = Debug|x64
2828
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM.ActiveCfg = Release|ARM
2929
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM.Build.0 = Release|ARM
3030
{05DFFB01-62C4-458C-BE13-7A97E8583E43}.Release|ARM64.ActiveCfg = Release|ARM64

0 commit comments

Comments
 (0)