Skip to content

Commit d997ce4

Browse files
author
REDMOND\jingf
committed
N/A
1 parent d61c5a8 commit d997ce4

File tree

7 files changed

+49
-32
lines changed

7 files changed

+49
-32
lines changed

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/PixRedistMiddleware.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void TryEnsurePIXFunctions()
4040
}
4141

4242
// Intentionally leaked
43-
HMODULE pixRuntime = LoadLibrary(dllPath.c_str());
44-
HMODULE pixGPURuntime = LoadLibrary(L"C:\\Program Files\\Microsoft PIX\\2202.25-GpuTimingDataFix\\WinPixGpuCapturer.dll");
43+
HMODULE pixRuntime = LoadLibrary(dllPath.c_str());
44+
LoadPIXGpuCapturer();
4545
if (pixRuntime != nullptr)
4646
{
4747
g_beginCaptureSingleton = (BeginCapture)GetProcAddress(pixRuntime, "PIXBeginCapture2");
@@ -53,6 +53,39 @@ void TryEnsurePIXFunctions()
5353
}
5454
}
5555

56+
void GetSubdirs(std::vector<std::wstring>& output, const std::wstring& path)
57+
{
58+
WIN32_FIND_DATA findfiledata;
59+
HANDLE hFind = INVALID_HANDLE_VALUE;
60+
61+
hFind = FindFirstFile((path + L"\\*").c_str(), &findfiledata);
62+
if (hFind != INVALID_HANDLE_VALUE)
63+
{
64+
do
65+
{
66+
if ((findfiledata.dwFileAttributes | FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY
67+
&& (findfiledata.cFileName[0] != '.'))
68+
{
69+
output.push_back(findfiledata.cFileName);
70+
}
71+
} while (FindNextFile(hFind, &findfiledata) != 0);
72+
}
73+
}
74+
75+
void LoadPIXGpuCapturer()
76+
{
77+
std::wstring dir = L"C:\\Program Files\\Microsoft PIX\\";
78+
std::vector<std::wstring> subDirs;
79+
GetSubdirs(subDirs, dir);
80+
if (subDirs.size() == 0)
81+
{
82+
printf("Please install PIX for Windows before running this program. (https://devblogs.microsoft.com/pix/download/)\n");
83+
exit(1);
84+
}
85+
dir += subDirs[0] + L"\\WinPixGpuCapturer.dll";
86+
HMODULE pixGPURuntime = LoadLibrary(dir.c_str());
87+
}
88+
5689
void PIXBeginEvent(ID3D12CommandQueue* commandQueue, UINT64 color, _In_ PCSTR string)
5790
{
5891
if (g_beginEventSingleton == nullptr)

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/PixRedistMiddleware.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ static std::mutex g_mutex;
2323

2424
void TryEnsurePIXFunctions();
2525

26+
void GetSubdirs(std::vector<std::wstring>& output, const std::wstring& path);
27+
28+
void LoadPIXGpuCapturer();
29+
2630
void PIXBeginEvent(ID3D12CommandQueue* commandQueue, UINT64 color, _In_ PCSTR string);
2731

2832
void PIXEndEvent(ID3D12CommandQueue* commandQueue);

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/WinMLHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ VideoFrame LoadImageFile(hstring filePath)
2626
try
2727
{
2828
// open the file
29-
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
29+
StorageFile file = StorageFile::GetFileFromPathAsync(dir).get();
3030
// get a stream on it
3131
auto stream = file.OpenAsync(FileAccessMode::Read).get();
3232
// Create the decoder from the stream

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/WinMLHelper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ using namespace winrt::Windows::Storage;
1414
using namespace std;
1515

1616
// Global variables
17-
static hstring modelPath = L"C:\\WinMLPIXSample\\SqueezeNet.onnx";
17+
static hstring modelPath = L".\\Assets\\SqueezeNet.onnx";
1818
static string deviceName = "default";
19-
static hstring imagePath = L"C:\\WinMLPIXSample\\kitten_224.png";
19+
static hstring imagePath = L"\\Assets\\kitten_224.png";
2020
static LearningModel model = nullptr;
2121
static LearningModelSession session = nullptr;
2222
static LearningModelBinding binding = nullptr;
2323
static VideoFrame imageFrame = nullptr;
24-
static string labelsFilePath = "C:\\WinMLPIXSample\\Labels.txt";
24+
static string labelsFilePath = ".\\Assets\\Labels.txt";
2525
static vector<string> labels;
2626

2727
// Forward declarations

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void GetD3D12CommandAssets()
7575
m_d3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence));
7676
}
7777

78-
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue, ID3D12CommandList* commandList, ID3D12Fence* m_fence)
78+
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue)
7979
{
8080
// Setting markers for each step, these markers will split the commands into sections for easier debugging
8181
PIXSetMarker(commandQueue, 0, "Start loading model...");
@@ -109,7 +109,7 @@ void CaptureWithUserSetMarker()
109109
PIXBeginEvent(m_commandQueue, 0, "WinMLPIXSample");
110110

111111
// Do the ML computation
112-
LoadAndEvaluate(m_commandQueue, m_commandList, m_fence);
112+
LoadAndEvaluate(m_commandQueue);
113113

114114
// End PIX event
115115
PIXEndEvent(m_commandQueue);

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<package id="Microsoft.AI.DirectML" version="1.8.0" targetFramework="native" />
44
<package id="Microsoft.AI.MachineLearning" version="1.10.0" targetFramework="native" />
55
<package id="Microsoft.Windows.CppWinRT" version="2.0.220131.2" targetFramework="native" />
6-
<package id="WinPixEventRuntime" version="1.0.220301001" targetFramework="native" />
6+
<package id="WinPixEventRuntime" version="1.0.220124001" targetFramework="native" />
77
</packages>

Samples/Tutorial Samples/WinMLPIXSample/WinMLPIXSample/readme.txt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,9 @@
22
C++/WinRT WinMLPIXSample Project Overview
33
========================================================================
44

5-
This project demonstrates how to get started consuming Windows Runtime
6-
classes directly from standard C++, using platform projection headers
7-
generated from Windows SDK metadata files.
8-
9-
Steps to generate and consume SDK platform projection:
10-
1. Build project initially to generate platform projection headers into
11-
your Generated Files folder.
12-
2. Include a projection namespace header in your pch.h, such as
13-
<winrt/Windows.Foundation.h>.
14-
3. Consume winrt namespace and any Windows Runtime namespaces, such as
15-
winrt::Windows::Foundation, from source code.
16-
4. Initialize apartment via init_apartment() and consume winrt classes.
17-
18-
Steps to generate and consume a projection from third party metadata:
19-
1. Add a WinMD reference by right-clicking the References project node
20-
and selecting "Add Reference...". In the Add References dialog,
21-
browse to the component WinMD you want to consume and add it.
22-
2. Build the project once to generate projection headers for the
23-
referenced WinMD file under the "Generated Files" subfolder.
24-
3. As above, include projection headers in pch or source code
25-
to consume projected Windows Runtime classes.
5+
This project demonstrates how to get started using PIX for windows to do
6+
GPU captures as well as setting markers programmatically
267

278
========================================================================
28-
Learn more about C++/WinRT here:
29-
http://aka.ms/cppwinrt/
9+
3010
========================================================================

0 commit comments

Comments
 (0)