This commit is contained in:
REDMOND\jingf 2022-03-03 15:47:01 -08:00
Родитель 85e35c3c7f
Коммит 5fe0e0694a
3 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -48,18 +48,23 @@ VideoFrame LoadImageFile(hstring filePath)
return imageFrame;
}
void BindModel(ID3D12CommandQueue* commandQueue)
void CreateSession(ID3D12CommandQueue* commandQueue)
{
printf("Binding the model...\n");
DWORD ticks = GetTickCount();
winrt::com_ptr<::IUnknown> spUnk;
auto factory = winrt::get_activation_factory<LearningModelDevice, ILearningModelDeviceFactoryNative>();
factory->CreateFromD3D12CommandQueue(commandQueue, spUnk.put());
LearningModelDevice dmlDeviceCustom = spUnk.as<LearningModelDevice>();
// now create a session and binding
// now create a session
session = LearningModelSession{ model, dmlDeviceCustom };
}
void BindModel(ID3D12CommandQueue* commandQueue)
{
printf("Binding the model...\n");
DWORD ticks = GetTickCount();
binding = LearningModelBinding{ session };
// bind the intput image
binding.Bind(L"data_0", ImageFeatureValue::CreateFromVideoFrame(imageFrame));

Просмотреть файл

@ -27,6 +27,7 @@ static vector<string> labels;
// Forward declarations
void LoadModel();
VideoFrame LoadImageFile(hstring filePath);
void CreateSession(ID3D12CommandQueue* commandQueue);
void BindModel(ID3D12CommandQueue* commandQueue);
void EvaluateModel();
void PrintResults(IVectorView<float> results);

Просмотреть файл

@ -16,6 +16,7 @@ static hstring pixCaptureFilePath = L".\\PIXCapture\\capture.wpix";
ID3D12Device* m_d3d12Device;
ID3D12CommandList* m_commandList;
ID3D12CommandQueue* m_commandQueue;
UINT m_color = PIX_COLOR(255, 0, 0);
void GetHardwareAdapter(IDXGIFactory4* pFactory, IDXGIAdapter1** ppAdapter)
{
@ -75,16 +76,19 @@ void GetD3D12CommandAssets()
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue)
{
// Setting markers for each step, these markers will split the commands into sections for easier debugging
PIXSetMarker(commandQueue, 0, "Start loading model...");
PIXSetMarker(commandQueue, m_color, "Start loading model...");
LoadModel();
PIXSetMarker(commandQueue, 0, "Start loading image...");
PIXSetMarker(commandQueue, m_color, "Start loading image...");
LoadImageFile(imagePath);
PIXSetMarker(commandQueue, 0, "Start binding model...");
PIXSetMarker(commandQueue, m_color, "Start creating session...");
CreateSession(commandQueue);
PIXSetMarker(commandQueue, m_color, "Start binding model...");
BindModel(commandQueue);
PIXSetMarker(commandQueue, 0, "Start evaluating model...");
PIXSetMarker(commandQueue, m_color, "Start evaluating model...");
EvaluateModel();
}
@ -103,7 +107,7 @@ void CaptureWithUserSetMarker()
PIXBeginCaptureRedist(PIX_CAPTURE_GPU, &capParams);
// Start PIX event, markers can only be set within Being and End event sections
PIXBeginEvent(m_commandQueue, 0, "WinMLPIXSample");
PIXBeginEvent(m_commandQueue, m_color, "WinMLPIXSample");
// Do the ML computation
LoadAndEvaluate(m_commandQueue);