diff --git a/tools/clang/.clang-tidy b/tools/clang/.clang-tidy index 3186da43d4..dfd628a6b5 100644 --- a/tools/clang/.clang-tidy +++ b/tools/clang/.clang-tidy @@ -1 +1 @@ -Checks: '-*,clang-diagnostic-*,llvm-*,misc-*' +Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-use-anonymous-namespace' diff --git a/tools/clang/test/taef_exec/lit.cfg b/tools/clang/test/taef_exec/lit.cfg index 9685da6711..af52cd8867 100644 --- a/tools/clang/test/taef_exec/lit.cfg +++ b/tools/clang/test/taef_exec/lit.cfg @@ -69,6 +69,9 @@ if config.unsupported == False: if agility_sdk: extra_params.append('/p:') extra_params.append('D3D12SDKVersion=1') + extra_params.append('/p:') + extra_params.append('D3D12SDKPath=' + agility_sdk) + print(f"Using Agility SDK from {agility_sdk}") warp_dll = getattr(config, 'warp_dll', None) if warp_dll: diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 68ee4692a6..5b589d8d03 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -417,6 +417,7 @@ class ExecutionTest { dxc::DxCompilerDllLoader m_support; + std::optional D3D12SDK; bool m_D3DInitCompleted = false; bool m_ExperimentalModeEnabled = false; bool m_AgilitySDKEnabled = false; @@ -428,46 +429,21 @@ class ExecutionTest { if (!m_D3DInitCompleted) { m_D3DInitCompleted = true; - HMODULE hRuntime = LoadLibraryW(L"d3d12.dll"); - if (hRuntime == NULL) + D3D12SDK = D3D12SDK::create(); + if (!D3D12SDK) return false; - // Do not: FreeLibrary(hRuntime); - // If we actually free the library, it defeats the purpose of - // enableAgilitySDK and enableExperimentalMode. - - HRESULT hr; - hr = enableAgilitySDK(hRuntime); - if (FAILED(hr)) { - LogCommentFmt(L"Unable to enable Agility SDK - 0x%08x.", hr); - } else if (hr == S_FALSE) { - LogCommentFmt(L"Agility SDK not enabled."); - } else { - LogCommentFmt(L"Agility SDK enabled."); - } - - hr = enableExperimentalMode(hRuntime); - if (FAILED(hr)) { - LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", - hr); - } else if (hr == S_FALSE) { - LogCommentFmt(L"Experimental mode not enabled."); - } else { - LogCommentFmt(L"Experimental mode enabled."); - } - - hr = enableDebugLayer(); - if (FAILED(hr)) { - LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr); - } else if (hr == S_FALSE) { - LogCommentFmt(L"Debug layer not enabled."); - } else { - LogCommentFmt(L"Debug layer enabled."); - } } return true; } + bool createDevice(ID3D12Device **D3DDevice, + ExecTestUtils::D3D_SHADER_MODEL TestModel = + ExecTestUtils::D3D_SHADER_MODEL_6_0, + bool SkipUnsupported = true) { + return D3D12SDK->createDevice(D3DDevice, TestModel, SkipUnsupported); + } + std::wstring DxcBlobToWide(IDxcBlob *pBlob) { if (!pBlob) return std::wstring(); @@ -12423,7 +12399,9 @@ static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest, // It's exclusive with the use of the DLL as a TAEF target. extern "C" { __declspec(dllexport) HRESULT WINAPI - InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) { + InitializeOpTests([[maybe_unused]] void *pStrCtx, + [[maybe_unused]] st::OutputStringFn pOutputStrFn) { +#ifdef _FORCE_EXPERIMENTAL_SHADERS HMODULE Runtime = LoadLibraryW(L"d3d12.dll"); if (Runtime == NULL) @@ -12434,6 +12412,7 @@ __declspec(dllexport) HRESULT WINAPI if (FAILED(hr)) { pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n."); } +#endif return S_OK; } diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 093575a73d..daeca99258 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -1,7 +1,6 @@ #include "HlslExecTestUtils.h" #include "ShaderOpTest.h" -#include "dxc/Support/Global.h" #include "dxc/Support/dxcapi.use.h" #include "HlslTestUtils.h" @@ -10,6 +9,8 @@ #include #include #include +#include +#include static bool useDebugIfaces() { return true; } @@ -39,7 +40,10 @@ static std::wstring getModuleName() { return std::wstring(ModuleName, Length); } -static std::wstring computeSDKFullPath(std::wstring SDKPath) { +static std::wstring computeSDKFullPath(const std::wstring &SDKPath) { + if (std::filesystem::path(SDKPath).is_absolute()) + return SDKPath; + std::wstring ModulePath = getModuleName(); const size_t Pos = ModulePath.rfind('\\'); @@ -53,6 +57,8 @@ static std::wstring computeSDKFullPath(std::wstring SDKPath) { } static UINT getD3D12SDKVersion(std::wstring SDKPath) { + using namespace hlsl_test; + // Try to automatically get the D3D12SDKVersion from the DLL UINT SDKVersion = 0; std::wstring D3DCorePath = computeSDKFullPath(SDKPath); @@ -63,13 +69,21 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { (UINT *)GetProcAddress(D3DCore, "D3D12SDKVersion")) SDKVersion = *SDKVersionOut; FreeModule(D3DCore); + LogCommentFmt(L"%s - D3D12SDKVersion is %d", D3DCorePath.c_str(), + SDKVersion); + } else { + LogCommentFmt(L"%s - unable to load", D3DCorePath.c_str()); } return SDKVersion; } -bool createDevice(ID3D12Device **D3DDevice, - ExecTestUtils::D3D_SHADER_MODEL TestModel, - bool SkipUnsupported) { +static bool createDevice( + ID3D12Device **D3DDevice, ExecTestUtils::D3D_SHADER_MODEL TestModel, + bool SkipUnsupported, + std::function + CreateDevice + +) { if (TestModel > ExecTestUtils::D3D_HIGHEST_SHADER_MODEL) { const UINT Minor = (UINT)TestModel & 0x0f; hlsl_test::LogCommentFmt(L"Installed SDK does not support " @@ -93,7 +107,7 @@ bool createDevice(ID3D12Device **D3DDevice, // before attempting to create the device. struct WarpDll { - HMODULE Module = NULL; + HMODULE Module = NULL; // NOLINT ~WarpDll() { Close(); } @@ -118,8 +132,8 @@ bool createDevice(ID3D12Device **D3DDevice, // Create the WARP device CComPtr WarpAdapter; VERIFY_SUCCEEDED(DXGIFactory->EnumWarpAdapter(IID_PPV_ARGS(&WarpAdapter))); - HRESULT CreateHR = D3D12CreateDevice(WarpAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(&D3DDeviceCom)); + HRESULT CreateHR = CreateDevice(WarpAdapter, D3D_FEATURE_LEVEL_11_0, + IID_PPV_ARGS(&D3DDeviceCom)); if (FAILED(CreateHR)) { hlsl_test::LogCommentFmt( L"The available version of WARP does not support d3d12."); @@ -155,8 +169,8 @@ bool createDevice(ID3D12Device **D3DDevice, WEX::Logging::Log::Comment( L"Using default hardware adapter with D3D12 support."); - VERIFY_SUCCEEDED(D3D12CreateDevice(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, - IID_PPV_ARGS(&D3DDeviceCom))); + VERIFY_SUCCEEDED(CreateDevice(HardwareAdapter, D3D_FEATURE_LEVEL_11_0, + IID_PPV_ARGS(&D3DDeviceCom))); } // retrieve adapter information const LUID AdapterID = D3DDeviceCom->GetAdapterLuid(); @@ -183,8 +197,8 @@ bool createDevice(ID3D12Device **D3DDevice, SMData.HighestShaderModel < TestModel) { const UINT Minor = (UINT)TestModel & 0x0f; hlsl_test::LogCommentFmt(L"The selected device does not support " - L"shader model 6.%1u", - Minor); + L"shader model 6.%1u (highest is 6.%1u)", + Minor, SMData.HighestShaderModel & 0x0f); if (SkipUnsupported) WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped); @@ -218,14 +232,95 @@ void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream, *Stream = StreamCom.Detach(); } -static HRESULT enableAgilitySDK(HMODULE Runtime, UINT SDKVersion, - LPCWSTR SDKPath) { - auto GetInterfaceFunc = reinterpret_cast( - GetProcAddress(Runtime, "D3D12GetInterface")); - CComPtr D3D12SDKConfiguration; - IFR(GetInterfaceFunc(CLSID_D3D12SDKConfiguration, - IID_PPV_ARGS(&D3D12SDKConfiguration))); - IFR(D3D12SDKConfiguration->SetSDKVersion(SDKVersion, CW2A(SDKPath))); +static bool enableDebugLayer() { + using namespace hlsl_test; + + CComPtr DebugController; + HRESULT HR; + if (FAILED(HR = D3D12GetDebugInterface(IID_PPV_ARGS(&DebugController)))) { + LogErrorFmt(L"Failed to get ID3D12Debug: 0x%08x", HR); + return false; + } + + DebugController->EnableDebugLayer(); + return true; +} + +struct AgilitySDKConfiguration { + WEX::Common::String SDKPath; + UINT SDKVersion = 0; + bool MustFind = false; +}; + +static std::optional getAgilitySDKConfiguration() { + using hlsl_test::LogErrorFmt; + using WEX::TestExecution::RuntimeParameters; + + AgilitySDKConfiguration C; + + // For global configuration, D3D12SDKPath must be relative path from .exe, + // which means relative to TE.exe location, and must start with ".\\", such as + // with the default: ".\\D3D12\\". + // + // For ID3D12DeviceFactory-style configuration, D3D12SDKPath can be an + // absolute path. + if (SUCCEEDED(RuntimeParameters::TryGetValue(L"D3D12SDKPath", C.SDKPath))) { + // Make sure path ends in backslash + if (!C.SDKPath.IsEmpty() && C.SDKPath.Right(1) != "\\") + C.SDKPath.Append("\\"); + } + + if (C.SDKPath.IsEmpty()) + C.SDKPath = L".\\D3D12\\"; + + // D3D12SDKVersion > 1 will use provided version, otherwise, auto-detect. + // D3D12SDKVersion == 1 means fail if we can't auto-detect. + RuntimeParameters::TryGetValue(L"D3D12SDKVersion", C.SDKVersion); + + C.MustFind = C.SDKVersion >= 1; + + if (C.SDKVersion <= 1) { + // Use the version supported by the SDK in the path. + C.SDKVersion = getD3D12SDKVersion(std::wstring(C.SDKPath)); + if (C.SDKVersion == 0) { + if (C.MustFind) { + LogErrorFmt(L"Agility SDK not found in relative path: %s", + static_cast(C.SDKPath)); + return std::nullopt; + } + + // No AgilitySDK found, caller indicated that they just want to use the + // inbox D3D12 in this case. + return AgilitySDKConfiguration{}; + } + } + + return C; +} + +static bool +enableGlobalAgilitySDK(const std::optional &C) { + using namespace hlsl_test; + + if (!C) + return false; + + if (C->SDKVersion == 0) + return false; + + CComPtr SDKConfig; + HRESULT HR; + if (FAILED(HR = D3D12GetInterface(CLSID_D3D12SDKConfiguration, + IID_PPV_ARGS(&SDKConfig)))) { + LogErrorFmt(L"Failed to get ID3D12SDKConfiguration instance: 0x%08x", HR); + return !C->MustFind; + } + + if (FAILED(HR = SDKConfig->SetSDKVersion(C->SDKVersion, CW2A(C->SDKPath)))) { + LogErrorFmt(L"SetSDKVersion(%d, %s) failed: 0x%08x", C->SDKVersion, + static_cast(C->SDKPath), HR); + return !C->MustFind; + } // Currently, it appears that the SetSDKVersion will succeed even when // D3D12Core is not found, or its version doesn't match. When that's the @@ -234,133 +329,159 @@ static HRESULT enableAgilitySDK(HMODULE Runtime, UINT SDKVersion, // features next, which is a valid use case and a no-op at this point. This // requires D3D12Core to be loaded. If this fails, we know the AgilitySDK // setting actually failed. - auto ExperimentalFeaturesFunc = - reinterpret_cast( - GetProcAddress(Runtime, "D3D12EnableExperimentalFeatures")); - if (ExperimentalFeaturesFunc == nullptr) - // If this failed, D3D12 must be too old for AgilitySDK. But if that's - // the case, creating D3D12SDKConfiguration should have failed. So while - // this case shouldn't be hit, fail if it is. - return HRESULT_FROM_WIN32(GetLastError()); - - return ExperimentalFeaturesFunc(0, nullptr, nullptr, nullptr); + if (FAILED( + HR = D3D12EnableExperimentalFeatures(0, nullptr, nullptr, nullptr))) { + LogWarningFmt(L"D3D12EnableExperimentalFeatures(0...) failed: 0x%08x", HR); + return !C->MustFind; + } + + return true; } -static HRESULT -enableExperimentalShaderModels(HMODULE hRuntime, - UUID AdditionalFeatures[] = nullptr, - size_t NumAdditionalFeatures = 0) { - auto ExperimentalFeaturesFunc = - reinterpret_cast( - GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures")); - if (ExperimentalFeaturesFunc == nullptr) - return HRESULT_FROM_WIN32(GetLastError()); +static bool isExperimentalShadersEnabled() { + return hlsl_test::GetTestParamBool(L"ExperimentalShaders"); +} - std::vector Features; +static bool enableGlobalExperimentalMode() { + using namespace hlsl_test; - Features.push_back(D3D12ExperimentalShaderModels); + if (!isExperimentalShadersEnabled()) + return false; - if (AdditionalFeatures != nullptr && NumAdditionalFeatures > 0) - Features.insert(Features.end(), AdditionalFeatures, - AdditionalFeatures + NumAdditionalFeatures); + HRESULT HR; + if (FAILED(HR = D3D12EnableExperimentalFeatures( + 1, &D3D12ExperimentalShaderModels, nullptr, nullptr))) { + LogWarningFmt(L"D3D12EnableExperimentalFeatures(" + L"D3D12ExperimentalShaderModels) failed: 0x%08x", + HR); + return false; + } - return ExperimentalFeaturesFunc((UINT)Features.size(), Features.data(), - nullptr, nullptr); + return true; } -static HRESULT -enableExperimentalShaderModels(UUID AdditionalFeatures[] = nullptr, - size_t NumAdditionalFeatures = 0) { - HMODULE Runtime = LoadLibraryW(L"d3d12.dll"); - if (Runtime == NULL) - return E_FAIL; - return enableExperimentalShaderModels(Runtime, AdditionalFeatures, - NumAdditionalFeatures); +static void +setGlobalConfiguration(const std::optional &C) { + using namespace hlsl_test; + + if (enableGlobalAgilitySDK(C)) + LogCommentFmt(L"Agility SDK enabled."); + else + LogCommentFmt(L"Agility SDK not enabled."); + + if (enableGlobalExperimentalMode()) + LogCommentFmt(L"Experimental mode enabled."); + else + LogCommentFmt(L"Experimental mode not enabled."); } -HRESULT enableAgilitySDK(HMODULE Runtime) { - // D3D12SDKVersion > 1 will use provided version, otherwise, auto-detect. - // D3D12SDKVersion == 1 means fail if we can't auto-detect. - UINT SDKVersion = 0; - WEX::TestExecution::RuntimeParameters::TryGetValue(L"D3D12SDKVersion", - SDKVersion); +static bool enableExperimentalMode(ID3D12DeviceFactory *DeviceFactory) { + using namespace hlsl_test; - // SDKPath must be relative path from .exe, which means relative to - // TE.exe location, and must start with ".\\", such as with the - // default: ".\\D3D12\\" - WEX::Common::String SDKPath; - if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( - L"D3D12SDKPath", SDKPath))) { - // Make sure path ends in backslash - if (!SDKPath.IsEmpty() && SDKPath.Right(1) != "\\") - SDKPath.Append("\\"); + if (!isExperimentalShadersEnabled()) + return false; + + HRESULT HR; + if (FAILED(HR = DeviceFactory->EnableExperimentalFeatures( + 1, &D3D12ExperimentalShaderModels, nullptr, nullptr))) { + LogWarningFmt(L"EnableExperimentalFeature(D3D12ExperimentalShaderModels) " + L"failed: 0x%08x", + HR); + return false; } - if (SDKPath.IsEmpty()) - SDKPath = L".\\D3D12\\"; - - const bool MustFind = SDKVersion > 0; - if (SDKVersion <= 1) { - // lookup version from D3D12Core.dll - SDKVersion = getD3D12SDKVersion((LPCWSTR)SDKPath); - if (MustFind && SDKVersion == 0) { - hlsl_test::LogErrorFmt(L"Agility SDK not found in relative path: %s", - (LPCWSTR)SDKPath); - return E_FAIL; - } + return true; +} + +static CComPtr +createDeviceFactorySDK(const AgilitySDKConfiguration &C) { + using namespace hlsl_test; + + HRESULT HR; + + CComPtr SDKConfig; + if (FAILED(HR = D3D12GetInterface(CLSID_D3D12SDKConfiguration, + IID_PPV_ARGS(&SDKConfig)))) { + LogCommentFmt(L"Failed to get ID3D12SDKConfiguration1 interface: 0x%08x", + HR); + return nullptr; } - // Not found, not asked for. - if (SDKVersion == 0) - return S_FALSE; - - HRESULT HR = enableAgilitySDK(Runtime, SDKVersion, (LPCWSTR)SDKPath); - if (FAILED(HR)) { - // If SDKVersion provided, fail if not successful. - // 1 means we should find it, and fill in the version automatically. - if (MustFind) { - hlsl_test::LogErrorFmt( - L"Failed to set Agility SDK version %d at path: %s", SDKVersion, - (LPCWSTR)SDKPath); - return HR; - } - return S_FALSE; + CComPtr DeviceFactory; + if (FAILED( + HR = SDKConfig->CreateDeviceFactory(C.SDKVersion, CW2A(C.SDKPath), + IID_PPV_ARGS(&DeviceFactory)))) { + LogCommentFmt(L"CreateDeviceFactory(%d, '%s', ...) failed: 0x%08x", + C.SDKVersion, static_cast(C.SDKPath), HR); + return nullptr; } - if (HR == S_OK) - hlsl_test::LogCommentFmt(L"Agility SDK version set to: %d", SDKVersion); - return HR; + LogCommentFmt(L"Using DeviceFactory for SDKVersion %d, SDKPath %s", + C.SDKVersion, static_cast(C.SDKPath)); + + if (enableExperimentalMode(DeviceFactory)) + LogCommentFmt(L"Experimental mode enabled."); + else + LogCommentFmt(L"Experimental mode not enabled."); + + return DeviceFactory; } -HRESULT enableExperimentalMode(HMODULE Runtime) { -#ifdef _FORCE_EXPERIMENTAL_SHADERS - bool ExperimentalShaderModels = true; -#else - bool ExperimentalShaderModels = - hlsl_test::GetTestParamBool(L"ExperimentalShaders"); -#endif // _FORCE_EXPERIMENTAL_SHADERS +std::optional D3D12SDK::create() { + using namespace hlsl_test; - HRESULT HR = S_FALSE; - if (ExperimentalShaderModels) { - HR = enableExperimentalShaderModels(Runtime); - if (SUCCEEDED(HR)) - WEX::Logging::Log::Comment(L"Experimental shader models enabled."); + if (enableDebugLayer()) + LogCommentFmt(L"Debug layer enabled"); + else + LogCommentFmt(L"Debug layer not enabled"); + + std::optional C = getAgilitySDKConfiguration(); + + if (C && C->SDKVersion > 0) { + CComPtr DeviceFactory = createDeviceFactorySDK(*C); + if (DeviceFactory) + return D3D12SDK(DeviceFactory); } - return HR; + setGlobalConfiguration(C); + return D3D12SDK(nullptr); } -HRESULT enableDebugLayer() { - // The debug layer does net yet validate DXIL programs that require - // rewriting, but basic logging should work properly. - HRESULT HR = S_FALSE; - if (useDebugIfaces()) { - CComPtr DebugController; - HR = D3D12GetDebugInterface(IID_PPV_ARGS(&DebugController)); - if (SUCCEEDED(HR)) { - DebugController->EnableDebugLayer(); - HR = S_OK; +D3D12SDK::D3D12SDK(CComPtr DeviceFactory) + : DeviceFactory(std::move(DeviceFactory)) {} + +D3D12SDK::~D3D12SDK() { + using namespace hlsl_test; + + if (DeviceFactory) { + DeviceFactory.Release(); + + HRESULT HR; + CComPtr SDKConfig; + if (FAILED(HR = D3D12GetInterface(CLSID_D3D12SDKConfiguration, + IID_PPV_ARGS(&SDKConfig)))) { + LogCommentFmt(L"Failed to get ID3D12SDKConfiguration1 interface: 0x%08x", + HR); + return; } + + SDKConfig->FreeUnusedSDKs(); } - return HR; } + +bool D3D12SDK::createDevice(ID3D12Device **D3DDevice, + ExecTestUtils::D3D_SHADER_MODEL TestModel, + bool SkipUnsupported) { + + if (DeviceFactory) { + hlsl_test::LogCommentFmt(L"Creating device using DeviceFactory"); + return ::createDevice( + D3DDevice, TestModel, SkipUnsupported, + [&](IUnknown *A, D3D_FEATURE_LEVEL FL, REFIID R, void **P) { + return DeviceFactory->CreateDevice(A, FL, R, P); + }); + } + + return ::createDevice(D3DDevice, TestModel, SkipUnsupported, + D3D12CreateDevice); +} \ No newline at end of file diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index c9e24b9c3b..bc76cbbd1e 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -1,7 +1,9 @@ #ifndef HLSLEXECTESTUTILS_H #define HLSLEXECTESTUTILS_H +#include #include +#include #include #include "dxc/Support/dxcapi.use.h" @@ -26,13 +28,39 @@ typedef enum D3D_SHADER_MODEL { } // namespace ExecTestUtils bool useDxbc(); -HRESULT enableDebugLayer(); -HRESULT enableExperimentalMode(HMODULE Runtime); -HRESULT enableAgilitySDK(HMODULE Runtime); -bool createDevice(ID3D12Device **D3DDevice, - ExecTestUtils::D3D_SHADER_MODEL TestModel = - ExecTestUtils::D3D_SHADER_MODEL_6_0, - bool SkipUnsupported = true); + +/// Manages D3D12 (Agility) SDK selection +/// +/// Based on TAEF runtime parameters, this picks an appropriate D3D12 SDK. +/// +/// TAEF parameters: +/// +/// D3D12SDKPath: relative or absolute path to the D3D12 Agility SDK bin +/// directory. Absolute path is only supported on OS's that support +/// ID3D12DeviceFactory. +/// +/// D3D12SDKVersion: requested SDK version +/// +/// 0: auto-detect (quietly fallback to inbox version) +/// +/// 1: auto-detect (fail if unable to use the auto-detected version) +/// +/// >1: use specified version +class D3D12SDK { + CComPtr DeviceFactory; + +public: + static std::optional create(); + ~D3D12SDK(); + + bool createDevice(ID3D12Device **D3DDevice, + ExecTestUtils::D3D_SHADER_MODEL TestModel = + ExecTestUtils::D3D_SHADER_MODEL_6_0, + bool SkipUnsupported = true); + +private: + D3D12SDK(CComPtr DeviceFactory); +}; void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream, dxc::SpecificDllLoader &Support); diff --git a/tools/clang/unittests/HLSLExec/LongVectors.cpp b/tools/clang/unittests/HLSLExec/LongVectors.cpp index 109bec6954..afb9b4c7e4 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -1642,37 +1642,9 @@ class DxilConf_SM69_Vectorized { if (!Initialized) { Initialized = true; - HMODULE Runtime = LoadLibraryW(L"d3d12.dll"); - if (Runtime == NULL) + D3D12SDK = D3D12SDK::create(); + if (!D3D12SDK) return false; - // Do not: FreeLibrary(hRuntime); - // If we actually free the library, it defeats the purpose of - // enableAgilitySDK and enableExperimentalMode. - - HRESULT HR; - HR = enableAgilitySDK(Runtime); - - if (FAILED(HR)) - hlsl_test::LogCommentFmt(L"Unable to enable Agility SDK - 0x%08x.", HR); - else if (HR == S_FALSE) - hlsl_test::LogCommentFmt(L"Agility SDK not enabled."); - else - hlsl_test::LogCommentFmt(L"Agility SDK enabled."); - - HR = enableExperimentalMode(Runtime); - if (FAILED(HR)) - hlsl_test::LogCommentFmt( - L"Unable to enable shader experimental mode - 0x%08x.", HR); - else if (HR == S_FALSE) - hlsl_test::LogCommentFmt(L"Experimental mode not enabled."); - - HR = enableDebugLayer(); - if (FAILED(HR)) - hlsl_test::LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", HR); - else if (HR == S_FALSE) - hlsl_test::LogCommentFmt(L"Debug layer not enabled."); - else - hlsl_test::LogCommentFmt(L"Debug layer enabled."); WEX::TestExecution::RuntimeParameters::TryGetValue(L"VerboseLogging", VerboseLogging); @@ -1709,8 +1681,8 @@ class DxilConf_SM69_Vectorized { L"FailIfRequirementsNotMet", FailIfRequirementsNotMet); const bool SkipUnsupported = !FailIfRequirementsNotMet; - createDevice(&D3DDevice, ExecTestUtils::D3D_SHADER_MODEL_6_9, - SkipUnsupported); + D3D12SDK->createDevice(&D3DDevice, ExecTestUtils::D3D_SHADER_MODEL_6_9, + SkipUnsupported); } return true; @@ -1722,8 +1694,8 @@ class DxilConf_SM69_Vectorized { if (!D3DDevice || D3DDevice->GetDeviceRemovedReason() != S_OK) { hlsl_test::LogCommentFmt( L"Device was lost: Attempting to create a new D3D12 device."); - VERIFY_IS_TRUE( - createDevice(&D3DDevice, ExecTestUtils::D3D_SHADER_MODEL_6_9, false)); + VERIFY_IS_TRUE(D3D12SDK->createDevice( + &D3DDevice, ExecTestUtils::D3D_SHADER_MODEL_6_9, false)); } return true; @@ -2490,6 +2462,7 @@ class DxilConf_SM69_Vectorized { private: bool Initialized = false; + std::optional D3D12SDK; bool VerboseLogging = false; size_t OverrideInputSize = 0; UINT OverrideWaveLaneCount = 0;