From 4c76c65b379fe33be2edab8c7d6c1c7464e6bc53 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:48:38 -0800 Subject: [PATCH 01/13] Factor out createWARPDevice and add RAII wrapper for WARP dll. --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 127 ++++++++++-------- 1 file changed, 72 insertions(+), 55 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 7c50c07943..6aea766fa0 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -77,6 +77,76 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { return SDKVersion; } +// RAII wrapper for WARP DLL loading +class WarpDllLoader { +public: + WarpDllLoader() = default; + + ~WarpDllLoader() { + Close(); + } + + // Non-copyable + WarpDllLoader(const WarpDllLoader&) = delete; + WarpDllLoader& operator=(const WarpDllLoader&) = delete; + + void LoadWarpDll() { + WEX::Common::String WarpDllPath; + if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( + L"WARP_DLL", WarpDllPath))) { + LogCommentFmt(L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath); + Module = LoadLibraryExW(WarpDllPath, NULL, 0); + VERIFY_WIN32_BOOL_SUCCEEDED(!!Module); + } + } + + void Close() { + if (Module) { + FreeLibrary(Module); + Module = NULL; + } + } + +private: + HMODULE Module = NULL; +}; + +// Helper function to create WARP device with proper DLL management +static bool createWARPDevice( + IDXGIFactory4* DXGIFactory, + std::function CreateDeviceFn, + ID3D12Device** D3DDeviceCom, + bool SkipUnsupported) { + + // Load WARP DLL if specified + WarpDllLoader warpLoader; + warpLoader.LoadWarpDll(); + + // Create the WARP device + CComPtr WarpAdapter; + VERIFY_SUCCEEDED(DXGIFactory->EnumWarpAdapter(IID_PPV_ARGS(&WarpAdapter))); + HRESULT CreateHR = CreateDeviceFn(WarpAdapter, D3D_FEATURE_LEVEL_11_0, + IID_PPV_ARGS(D3DDeviceCom)); + if (FAILED(CreateHR)) { + LogCommentFmt(L"Failed to create WARP device: 0x%08x", CreateHR); + + if (SkipUnsupported) + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped); + + return false; + } + + // Log the actual version of WARP that's loaded + if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { + WCHAR FullModuleFilePath[MAX_PATH] = L""; + GetModuleFileNameW(GetModuleHandleW(L"d3d10warp.dll"), FullModuleFilePath, + sizeof(FullModuleFilePath)); + LogCommentFmt(L"WARP driver loaded from: %ls", FullModuleFilePath); + } + + return true; +} + static bool createDevice( ID3D12Device **D3DDevice, D3D_SHADER_MODEL TestModel, bool SkipUnsupported, std::function @@ -104,61 +174,9 @@ static bool createDevice( VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); if (GetTestParamUseWARP(useWarpByDefault())) { - // The WARP_DLL runtime parameter can be used to specify a specific DLL to - // load. To force this to be used, we make sure that this DLL is loaded - // before attempting to create the device. - - struct WarpDll { - HMODULE Module = NULL; // NOLINT - - ~WarpDll() { Close(); } - - void Close() { - if (Module) { - FreeLibrary(Module); - Module = NULL; - } - } - }; - - WarpDll ExplicitlyLoadedWarpDll; - WEX::Common::String WarpDllPath; - if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( - L"WARP_DLL", WarpDllPath))) { - WEX::Logging::Log::Comment(WEX::Common::String().Format( - L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath)); - ExplicitlyLoadedWarpDll.Module = LoadLibraryExW(WarpDllPath, NULL, 0); - VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll.Module); - } - - // Create the WARP device - CComPtr WarpAdapter; - VERIFY_SUCCEEDED(DXGIFactory->EnumWarpAdapter(IID_PPV_ARGS(&WarpAdapter))); - HRESULT CreateHR = CreateDeviceFn(WarpAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(&D3DDeviceCom)); - if (FAILED(CreateHR)) { - LogCommentFmt(L"Failed to create WARP device: 0x%08x", CreateHR); - - if (SkipUnsupported) - WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped); - + if (!createWARPDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported)) { return false; } - - // Now that the WARP device is created we can release our reference to the - // warp dll. - ExplicitlyLoadedWarpDll.Close(); - - // Log the actual version of WARP that's loaded so we can be sure that - // we're using the version we think. - if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { - WCHAR FullModuleFilePath[MAX_PATH] = L""; - GetModuleFileNameW(GetModuleHandleW(L"d3d10warp.dll"), FullModuleFilePath, - sizeof(FullModuleFilePath)); - WEX::Logging::Log::Comment(WEX::Common::String().Format( - L"WARP driver loaded from: %ls", FullModuleFilePath)); - } - } else { CComPtr HardwareAdapter; WEX::Common::String AdapterValue; @@ -167,8 +185,7 @@ static bool createDevice( if (SUCCEEDED(HR)) st::GetHardwareAdapter(DXGIFactory, AdapterValue, &HardwareAdapter); else - WEX::Logging::Log::Comment( - L"Using default hardware adapter with D3D12 support."); + LogCommentFmt(L"Using default hardware adapter with D3D12 support."); VERIFY_SUCCEEDED(CreateDeviceFn(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&D3DDeviceCom))); From dbef8435ebbc9766925066dd00fa7bb64ccd5b73 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:51:12 -0800 Subject: [PATCH 02/13] formatting --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 6aea766fa0..d9e644cff8 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -81,15 +81,13 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { class WarpDllLoader { public: WarpDllLoader() = default; - - ~WarpDllLoader() { - Close(); - } - + + ~WarpDllLoader() { Close(); } + // Non-copyable - WarpDllLoader(const WarpDllLoader&) = delete; - WarpDllLoader& operator=(const WarpDllLoader&) = delete; - + WarpDllLoader(const WarpDllLoader &) = delete; + WarpDllLoader &operator=(const WarpDllLoader &) = delete; + void LoadWarpDll() { WEX::Common::String WarpDllPath; if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( @@ -99,29 +97,29 @@ class WarpDllLoader { VERIFY_WIN32_BOOL_SUCCEEDED(!!Module); } } - + void Close() { if (Module) { FreeLibrary(Module); Module = NULL; } } - + private: HMODULE Module = NULL; }; // Helper function to create WARP device with proper DLL management static bool createWARPDevice( - IDXGIFactory4* DXGIFactory, - std::function CreateDeviceFn, - ID3D12Device** D3DDeviceCom, - bool SkipUnsupported) { - + IDXGIFactory4 *DXGIFactory, + std::function + CreateDeviceFn, + ID3D12Device **D3DDeviceCom, bool SkipUnsupported) { + // Load WARP DLL if specified WarpDllLoader warpLoader; warpLoader.LoadWarpDll(); - + // Create the WARP device CComPtr WarpAdapter; VERIFY_SUCCEEDED(DXGIFactory->EnumWarpAdapter(IID_PPV_ARGS(&WarpAdapter))); @@ -135,7 +133,7 @@ static bool createWARPDevice( return false; } - + // Log the actual version of WARP that's loaded if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { WCHAR FullModuleFilePath[MAX_PATH] = L""; @@ -143,7 +141,7 @@ static bool createWARPDevice( sizeof(FullModuleFilePath)); LogCommentFmt(L"WARP driver loaded from: %ls", FullModuleFilePath); } - + return true; } @@ -174,7 +172,8 @@ static bool createDevice( VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); if (GetTestParamUseWARP(useWarpByDefault())) { - if (!createWARPDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported)) { + if (!createWARPDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, + SkipUnsupported)) { return false; } } else { From 93b89b72949bccf529ddbccf9efc1b1c152a1499 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:54:42 -0800 Subject: [PATCH 03/13] A little more cleanup --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index d9e644cff8..078173a04f 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -110,7 +110,7 @@ class WarpDllLoader { }; // Helper function to create WARP device with proper DLL management -static bool createWARPDevice( +static bool createWarpDevice( IDXGIFactory4 *DXGIFactory, std::function CreateDeviceFn, @@ -171,11 +171,11 @@ static bool createDevice( *D3DDevice = nullptr; VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); - if (GetTestParamUseWARP(useWarpByDefault())) { - if (!createWARPDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, - SkipUnsupported)) { - return false; - } + + const bool UseWarp = GetTestParamUseWARP(useWarpByDefault()); + if (UseWarp && !createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, + SkipUnsupported)) + return false; } else { CComPtr HardwareAdapter; WEX::Common::String AdapterValue; From e68145fe7294ab69668828705131b1a1528d2699 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:57:06 -0800 Subject: [PATCH 04/13] logAdapter helper --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 078173a04f..04455246f2 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -145,6 +145,16 @@ static bool createWarpDevice( return true; } +static void logAdapter(IDXGIFactory4 *DXGIFactory, ID3D12Device *D3DDevice) { + CComPtr DXGIAdapter; + const LUID AdapterID = D3DDevice->GetAdapterLuid(); + VERIFY_SUCCEEDED( + DXGIFactory->EnumAdapterByLuid(AdapterID, IID_PPV_ARGS(&DXGIAdapter))); + DXGI_ADAPTER_DESC AdapterDesc; + VERIFY_SUCCEEDED(DXGIAdapter->GetDesc(&AdapterDesc)); + LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description); +} + static bool createDevice( ID3D12Device **D3DDevice, D3D_SHADER_MODEL TestModel, bool SkipUnsupported, std::function @@ -189,13 +199,8 @@ static bool createDevice( VERIFY_SUCCEEDED(CreateDeviceFn(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&D3DDeviceCom))); } - // retrieve adapter information - const LUID AdapterID = D3DDeviceCom->GetAdapterLuid(); - CComPtr DXGIAdapter; - DXGIFactory->EnumAdapterByLuid(AdapterID, IID_PPV_ARGS(&DXGIAdapter)); - DXGI_ADAPTER_DESC AdapterDesc; - VERIFY_SUCCEEDED(DXGIAdapter->GetDesc(&AdapterDesc)); - LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description); + + logAdapter(DXGIFactory, D3DDeviceCom); if (D3DDeviceCom == nullptr) return false; From ab84cc8e8bab07b92333686ae8afb586f50b2c7a Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:58:47 -0800 Subject: [PATCH 05/13] Formatting again --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 04455246f2..6f75bc32c3 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -184,7 +184,7 @@ static bool createDevice( const bool UseWarp = GetTestParamUseWARP(useWarpByDefault()); if (UseWarp && !createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, - SkipUnsupported)) + SkipUnsupported)) { return false; } else { CComPtr HardwareAdapter; From fda1eb37c849ddc275dba1e9e5bbd32a94cd7c49 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 12:45:09 -0800 Subject: [PATCH 06/13] Fix if --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 6f75bc32c3..dfc3e6a7a7 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -183,9 +183,10 @@ static bool createDevice( VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); const bool UseWarp = GetTestParamUseWARP(useWarpByDefault()); - if (UseWarp && !createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, - SkipUnsupported)) { - return false; + if (UseWarp) { + if (!createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, + SkipUnsupported)) + return false; } else { CComPtr HardwareAdapter; WEX::Common::String AdapterValue; From 198b9f33fcd073f34d5570b9e5661126a393eade Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 12:51:06 -0800 Subject: [PATCH 07/13] make createWarpDevice return void --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index dfc3e6a7a7..3eb94f72b6 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -110,7 +110,7 @@ class WarpDllLoader { }; // Helper function to create WARP device with proper DLL management -static bool createWarpDevice( +static void createWarpDevice( IDXGIFactory4 *DXGIFactory, std::function CreateDeviceFn, @@ -131,7 +131,8 @@ static bool createWarpDevice( if (SkipUnsupported) WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped); - return false; + D3DDeviceCom = nullptr; + return; } // Log the actual version of WARP that's loaded @@ -141,8 +142,6 @@ static bool createWarpDevice( sizeof(FullModuleFilePath)); LogCommentFmt(L"WARP driver loaded from: %ls", FullModuleFilePath); } - - return true; } static void logAdapter(IDXGIFactory4 *DXGIFactory, ID3D12Device *D3DDevice) { @@ -184,9 +183,8 @@ static bool createDevice( const bool UseWarp = GetTestParamUseWARP(useWarpByDefault()); if (UseWarp) { - if (!createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, - SkipUnsupported)) - return false; + createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, + SkipUnsupported); } else { CComPtr HardwareAdapter; WEX::Common::String AdapterValue; From e79ebddd87e9347f49ac1a1eaf12cfe42bc181d5 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:08:10 -0800 Subject: [PATCH 08/13] Comments --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 3eb94f72b6..42a979421f 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -77,7 +77,8 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { return SDKVersion; } -// RAII wrapper for WARP DLL loading +// RAII wrapper for WARP DLL loading to ensure it is unloaded when the use of +// this wrapper goes out of scope. class WarpDllLoader { public: WarpDllLoader() = default; @@ -89,6 +90,9 @@ class WarpDllLoader { WarpDllLoader &operator=(const WarpDllLoader &) = delete; void LoadWarpDll() { + // The WARP_DLL runtime parameter can be used to specify a specific DLL to + // load. To force this to be used, we make sure that this DLL is loaded + // before attempting to create the device. WEX::Common::String WarpDllPath; if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( L"WARP_DLL", WarpDllPath))) { @@ -116,7 +120,8 @@ static void createWarpDevice( CreateDeviceFn, ID3D12Device **D3DDeviceCom, bool SkipUnsupported) { - // Load WARP DLL if specified + // Load WARP DLL if specified. The WARP_DLL runtime parameter can be used to + // specify a specific DLL to load. WarpDllLoader warpLoader; warpLoader.LoadWarpDll(); @@ -135,7 +140,8 @@ static void createWarpDevice( return; } - // Log the actual version of WARP that's loaded + // Log the actual version of WARP that's loaded so we can be sure that we're + // using the version that we think. if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { WCHAR FullModuleFilePath[MAX_PATH] = L""; GetModuleFileNameW(GetModuleHandleW(L"d3d10warp.dll"), FullModuleFilePath, From e2231fa65453083c88b3a2d6e1a812a090432f4b Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:22:16 -0800 Subject: [PATCH 09/13] Move dll loader back to inline --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 83 ++++++++----------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 42a979421f..f0ae01bc36 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -77,69 +77,59 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { return SDKVersion; } -// RAII wrapper for WARP DLL loading to ensure it is unloaded when the use of -// this wrapper goes out of scope. -class WarpDllLoader { -public: - WarpDllLoader() = default; - - ~WarpDllLoader() { Close(); } - - // Non-copyable - WarpDllLoader(const WarpDllLoader &) = delete; - WarpDllLoader &operator=(const WarpDllLoader &) = delete; - - void LoadWarpDll() { - // The WARP_DLL runtime parameter can be used to specify a specific DLL to - // load. To force this to be used, we make sure that this DLL is loaded - // before attempting to create the device. - WEX::Common::String WarpDllPath; - if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( - L"WARP_DLL", WarpDllPath))) { - LogCommentFmt(L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath); - Module = LoadLibraryExW(WarpDllPath, NULL, 0); - VERIFY_WIN32_BOOL_SUCCEEDED(!!Module); - } - } +// Helper function to create WARP device with proper DLL management +static void createWarpDevice( + IDXGIFactory4 *DXGIFactory, + std::function + CreateDeviceFn, + ID3D12Device **D3DDevice, bool SkipUnsupported) { - void Close() { - if (Module) { - FreeLibrary(Module); - Module = NULL; - } - } + // The WARP_DLL runtime parameter can be used to specify a specific DLL to + // load. To force this to be used, we make sure that this DLL is loaded + // before attempting to create the device. -private: - HMODULE Module = NULL; -}; + struct WarpDll { + HMODULE Module = NULL; // NOLINT -// Helper function to create WARP device with proper DLL management -static void createWarpDevice( - IDXGIFactory4 *DXGIFactory, - std::function - CreateDeviceFn, - ID3D12Device **D3DDeviceCom, bool SkipUnsupported) { + ~WarpDll() { Close(); } - // Load WARP DLL if specified. The WARP_DLL runtime parameter can be used to - // specify a specific DLL to load. - WarpDllLoader warpLoader; - warpLoader.LoadWarpDll(); + void Close() { + if (Module) { + FreeLibrary(Module); + Module = NULL; + } + } + }; + + WarpDll ExplicitlyLoadedWarpDll; + WEX::Common::String WarpDllPath; + if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( + L"WARP_DLL", WarpDllPath))) { + WEX::Logging::Log::Comment(WEX::Common::String().Format( + L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath)); + ExplicitlyLoadedWarpDll.Module = LoadLibraryExW(WarpDllPath, NULL, 0); + VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll.Module); + } // Create the WARP device CComPtr WarpAdapter; VERIFY_SUCCEEDED(DXGIFactory->EnumWarpAdapter(IID_PPV_ARGS(&WarpAdapter))); HRESULT CreateHR = CreateDeviceFn(WarpAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(D3DDeviceCom)); + IID_PPV_ARGS(D3DDevice)); if (FAILED(CreateHR)) { LogCommentFmt(L"Failed to create WARP device: 0x%08x", CreateHR); if (SkipUnsupported) WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped); - D3DDeviceCom = nullptr; + D3DDevice = nullptr; return; } + // Now that the WARP device is created we can release our reference to the + // warp dll. + ExplicitlyLoadedWarpDll.Close(); + // Log the actual version of WARP that's loaded so we can be sure that we're // using the version that we think. if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { @@ -187,8 +177,7 @@ static bool createDevice( VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); - const bool UseWarp = GetTestParamUseWARP(useWarpByDefault()); - if (UseWarp) { + if (GetTestParamUseWARP(useWarpByDefault())) { createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported); } else { From ce77e614937e92abd3847d5812622417842d1a28 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:22:29 -0800 Subject: [PATCH 10/13] Clang format --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index f0ae01bc36..c213883dfd 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -79,10 +79,10 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { // Helper function to create WARP device with proper DLL management static void createWarpDevice( - IDXGIFactory4 *DXGIFactory, - std::function - CreateDeviceFn, - ID3D12Device **D3DDevice, bool SkipUnsupported) { + IDXGIFactory4 *DXGIFactory, + std::function + CreateDeviceFn, + ID3D12Device **D3DDevice, bool SkipUnsupported) { // The WARP_DLL runtime parameter can be used to specify a specific DLL to // load. To force this to be used, we make sure that this DLL is loaded From c687290bfa02641e6f733151840c09ddc40f2826 Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:23:30 -0800 Subject: [PATCH 11/13] Some formatting and remove a stale comment --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index c213883dfd..2325a9a322 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -176,7 +176,6 @@ static bool createDevice( *D3DDevice = nullptr; VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); - if (GetTestParamUseWARP(useWarpByDefault())) { createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported); From 1dd271e18346f784dfa5b915456a7e66d125f8ae Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 14:23:53 -0800 Subject: [PATCH 12/13] add createHardwareDevice --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 2325a9a322..e8f1e47ab3 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -77,7 +77,6 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { return SDKVersion; } -// Helper function to create WARP device with proper DLL management static void createWarpDevice( IDXGIFactory4 *DXGIFactory, std::function @@ -140,6 +139,25 @@ static void createWarpDevice( } } +static void createHardwareDevice( + IDXGIFactory4 *DXGIFactory, + std::function + CreateDeviceFn, + ID3D12Device **D3DDevice, bool SkipUnsupported) { + + CComPtr HardwareAdapter; + WEX::Common::String AdapterValue; + HRESULT HR = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter", + AdapterValue); + if (SUCCEEDED(HR)) + st::GetHardwareAdapter(DXGIFactory, AdapterValue, &HardwareAdapter); + else + LogCommentFmt(L"Using default hardware adapter with D3D12 support."); + + VERIFY_SUCCEEDED(CreateDeviceFn(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, + IID_PPV_ARGS(&D3DDevice))); +} + static void logAdapter(IDXGIFactory4 *DXGIFactory, ID3D12Device *D3DDevice) { CComPtr DXGIAdapter; const LUID AdapterID = D3DDevice->GetAdapterLuid(); @@ -176,22 +194,12 @@ static bool createDevice( *D3DDevice = nullptr; VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&DXGIFactory))); - if (GetTestParamUseWARP(useWarpByDefault())) { + if (GetTestParamUseWARP(useWarpByDefault())) createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported); - } else { - CComPtr HardwareAdapter; - WEX::Common::String AdapterValue; - HRESULT HR = WEX::TestExecution::RuntimeParameters::TryGetValue( - L"Adapter", AdapterValue); - if (SUCCEEDED(HR)) - st::GetHardwareAdapter(DXGIFactory, AdapterValue, &HardwareAdapter); - else - LogCommentFmt(L"Using default hardware adapter with D3D12 support."); - - VERIFY_SUCCEEDED(CreateDeviceFn(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(&D3DDeviceCom))); - } + else + createHardwareDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, + SkipUnsupported); logAdapter(DXGIFactory, D3DDeviceCom); From a43b082cfcd382bc4933e2e050e6b8893c1249ed Mon Sep 17 00:00:00 2001 From: Alex Sepkowski <5620315+alsepkow@users.noreply.github.com> Date: Mon, 8 Dec 2025 14:34:42 -0800 Subject: [PATCH 13/13] Fix createHardwareDevice --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index e8f1e47ab3..8865864a60 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -143,7 +143,7 @@ static void createHardwareDevice( IDXGIFactory4 *DXGIFactory, std::function CreateDeviceFn, - ID3D12Device **D3DDevice, bool SkipUnsupported) { + ID3D12Device **D3DDevice) { CComPtr HardwareAdapter; WEX::Common::String AdapterValue; @@ -155,7 +155,7 @@ static void createHardwareDevice( LogCommentFmt(L"Using default hardware adapter with D3D12 support."); VERIFY_SUCCEEDED(CreateDeviceFn(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(&D3DDevice))); + IID_PPV_ARGS(D3DDevice))); } static void logAdapter(IDXGIFactory4 *DXGIFactory, ID3D12Device *D3DDevice) { @@ -198,8 +198,7 @@ static bool createDevice( createWarpDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, SkipUnsupported); else - createHardwareDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom, - SkipUnsupported); + createHardwareDevice(DXGIFactory, CreateDeviceFn, &D3DDeviceCom); logAdapter(DXGIFactory, D3DDeviceCom);