Skip to content

Commit b3c0e96

Browse files
committed
Updates
1 parent 22d2c63 commit b3c0e96

File tree

6 files changed

+45
-33
lines changed

6 files changed

+45
-33
lines changed

Samples/WinMLSamplesGallery/WinMLSamplesGallery/SampleMetadata/SampleMetadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
"Description": "The sample showcases how to create and bind OrtValue objects from ID3D12 Resources using the ONNX Runtime C-API.",
9090
"Icon": "\uE155",
9191
"Tag": "DXResourceBindingORT",
92-
"XAMLGithubLink": "https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/AdapterSelection/AdapterSelection.xaml",
93-
"CSharpGithubLink": "https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/AdapterSelection/AdapterSelection.xaml.cs",
92+
"XAMLGithubLink": "https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/DXResourceBindingORT/DXResourceBindingORT.xaml",
93+
"CSharpGithubLink": "https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/DXResourceBindingORT/DXResourceBindingORT.xaml.cs",
9494
"Docs": [],
9595
"IsRecentlyAdded": true
9696
}

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/D3D12Quad.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void D3D12Quad::OnInit()
3838
updateCounter = 0;
3939
LoadPipeline();
4040
LoadAssets();
41-
is_initialized = true;
41+
initializationSemaphore.release();
4242
copy_texture = false;
4343
}
4444

@@ -592,22 +592,38 @@ WICPixelFormatGUID D3D12Quad::GetConvertToWICFormat(WICPixelFormatGUID wicFormat
592592
// get the number of bits per pixel for a dxgi format
593593
int D3D12Quad::GetDXGIFormatBitsPerPixel(DXGI_FORMAT dxgiFormat)
594594
{
595-
if (dxgiFormat == DXGI_FORMAT_R32G32B32A32_FLOAT) return 128;
596-
else if (dxgiFormat == DXGI_FORMAT_R16G16B16A16_FLOAT) return 64;
597-
else if (dxgiFormat == DXGI_FORMAT_R16G16B16A16_UNORM) return 64;
598-
else if (dxgiFormat == DXGI_FORMAT_R8G8B8A8_UNORM) return 32;
599-
else if (dxgiFormat == DXGI_FORMAT_B8G8R8A8_UNORM) return 32;
600-
else if (dxgiFormat == DXGI_FORMAT_B8G8R8X8_UNORM) return 32;
601-
else if (dxgiFormat == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM) return 32;
602-
603-
else if (dxgiFormat == DXGI_FORMAT_R10G10B10A2_UNORM) return 32;
604-
else if (dxgiFormat == DXGI_FORMAT_B5G5R5A1_UNORM) return 16;
605-
else if (dxgiFormat == DXGI_FORMAT_B5G6R5_UNORM) return 16;
606-
else if (dxgiFormat == DXGI_FORMAT_R32_FLOAT) return 32;
607-
else if (dxgiFormat == DXGI_FORMAT_R16_FLOAT) return 16;
608-
else if (dxgiFormat == DXGI_FORMAT_R16_UNORM) return 16;
609-
else if (dxgiFormat == DXGI_FORMAT_R8_UNORM) return 8;
610-
else if (dxgiFormat == DXGI_FORMAT_A8_UNORM) return 8;
595+
switch (dxgiFormat) {
596+
case DXGI_FORMAT_R32G32B32A32_FLOAT:
597+
return 128;
598+
case DXGI_FORMAT_R16G16B16A16_FLOAT:
599+
return 64;
600+
case DXGI_FORMAT_R16G16B16A16_UNORM:
601+
return 64;
602+
case DXGI_FORMAT_R8G8B8A8_UNORM:
603+
return 32;
604+
case DXGI_FORMAT_B8G8R8A8_UNORM:
605+
return 32;
606+
case DXGI_FORMAT_B8G8R8X8_UNORM:
607+
return 32;
608+
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
609+
return 32;
610+
case DXGI_FORMAT_R10G10B10A2_UNORM:
611+
return 32;
612+
case DXGI_FORMAT_B5G5R5A1_UNORM:
613+
return 16;
614+
case DXGI_FORMAT_B5G6R5_UNORM:
615+
return 16;
616+
case DXGI_FORMAT_R32_FLOAT:
617+
return 32;
618+
case DXGI_FORMAT_R16_FLOAT:
619+
return 16;
620+
case DXGI_FORMAT_R16_UNORM:
621+
return 16;
622+
case DXGI_FORMAT_R8_UNORM:
623+
return 8;
624+
case DXGI_FORMAT_A8_UNORM:
625+
return 8;
626+
}
611627
}
612628

613629
// load and decode image from file, returning the number of image bytes

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/D3D12Quad.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdexcept>
44
#include <wincodec.h>
5+
#include <semaphore>
56

67
using namespace DirectX;
78
using Microsoft::WRL::ComPtr;
@@ -24,8 +25,7 @@ class D3D12Quad
2425
ComPtr<ID3D12Resource> GetCurrentBuffer();
2526
void ShowNextImage();
2627

27-
bool is_initialized = false;
28-
28+
std::binary_semaphore initializationSemaphore{ 0 };
2929

3030
private:
3131
static const UINT FrameCount = 2;
@@ -76,11 +76,11 @@ class D3D12Quad
7676

7777
ComPtr<ID3D12Resource> textureBuffer; // the resource heap containing our texture
7878

79-
int LoadImageDataFromFile(BYTE** imageData, D3D12_RESOURCE_DESC& resourceDescription, LPCWSTR filename, int& bytesPerRow);
79+
static int LoadImageDataFromFile(BYTE** imageData, D3D12_RESOURCE_DESC& resourceDescription, LPCWSTR filename, int& bytesPerRow);
8080

81-
DXGI_FORMAT GetDXGIFormatFromWICFormat(WICPixelFormatGUID wicFormatGUID);
82-
WICPixelFormatGUID GetConvertToWICFormat(WICPixelFormatGUID wicFormatGUID);
83-
int GetDXGIFormatBitsPerPixel(DXGI_FORMAT dxgiFormat);
81+
static DXGI_FORMAT GetDXGIFormatFromWICFormat(WICPixelFormatGUID wicFormatGUID);
82+
static WICPixelFormatGUID GetConvertToWICFormat(WICPixelFormatGUID wicFormatGUID);
83+
static int GetDXGIFormatBitsPerPixel(DXGI_FORMAT dxgiFormat);
8484
void LoadImageTexture();
8585
void Reset();
8686
void ThrowIfFailed(HRESULT hr);

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/DXResourceBinding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace winrt::WinMLSamplesGalleryNative::implementation
2626
std::jthread d3d_th(Win32Application::Run, &sample, 10);
2727

2828
// Wait until the D3D pipeline finishes
29-
while (!sample.is_initialized) {}
29+
sample.initializationSemaphore.acquire();
3030

3131
// Detach the thread so it doesn't block the UI
3232
d3d_th.detach();

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/Win32Application.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ std::wstring Win32Application::GetAssetPath(LPCWSTR assetName)
148148
UINT modulePathSize = std::size(modulePath);
149149
GetModuleFileName(nullptr, modulePath, modulePathSize);
150150

151-
const wchar_t* gallery = L"WinMLSamplesGallery";
151+
constexpr std::wstring_view gallery = L"WinMLSamplesGallery";
152152
UINT gallerySize = 19; // length of the gallery string
153153

154154
// Erase everything after the first occurence of the gallery string
@@ -157,7 +157,7 @@ std::wstring Win32Application::GetAssetPath(LPCWSTR assetName)
157157
assert(offset != std::string::npos);
158158
path.erase(path.begin() + offset + gallerySize, path.end());
159159

160-
std::wstring native = L"\\WinMLSamplesGalleryNative\\";
161-
path = path + native + assetName;
160+
std::wstring_view galleryPathNative = L"\\WinMLSamplesGalleryNative\\";
161+
path = path + galleryPathNative.data() + assetName;
162162
return path;
163163
}

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/WinMLSamplesGalleryNative.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@
112112
<UseOpenCV>False</UseOpenCV>
113113
<UseOpenCV Condition="Exists('$(OpenCVLibFullPath)')">True</UseOpenCV>
114114
</PropertyGroup>
115-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
116-
<IncludePath>C:\Program Files %28x86%29\Windows Kits\10\Include\10.0.19041.0\um;C:\Program Files %28x86%29\Windows Kits\10\Include\10.0.19041.0\shared;$(IncludePath)</IncludePath>
117-
<LibraryPath>C:\Program Files %28x86%29\Windows Kits\10\Lib\10.0.19041.0\um\x64;$(LibraryPath)</LibraryPath>
118-
</PropertyGroup>
119115
<ItemDefinitionGroup Condition="$(UseOpenCV)">
120116
<ClCompile>
121117
<AdditionalIncludeDirectories>$(SolutionDir)..\..\build\external\opencv\cmake_config\$(PlatformString)\install\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

0 commit comments

Comments
 (0)