From 47c93e7ebf82568e5b9be87dd3b83be7a27a5080 Mon Sep 17 00:00:00 2001 From: Damyan Pepper Date: Wed, 5 Nov 2025 21:42:18 -0800 Subject: [PATCH 01/15] wip - proof of concept --- .../unittests/HLSLExec/ExecutionTest.cpp | 55 ++---- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 180 ++++++++++++++++-- .../unittests/HLSLExec/HlslExecTestUtils.h | 25 ++- .../clang/unittests/HLSLExec/LongVectors.cpp | 37 +--- 4 files changed, 209 insertions(+), 88 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 61dc855387..8d59003353 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -464,6 +464,7 @@ class ExecutionTest { dxc::DxCompilerDllLoader m_support; + std::optional D3D12SDK; bool m_D3DInitCompleted = false; bool m_ExperimentalModeEnabled = false; bool m_AgilitySDKEnabled = false; @@ -475,46 +476,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(); @@ -12527,7 +12503,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) @@ -12538,13 +12516,14 @@ __declspec(dllexport) HRESULT WINAPI if (FAILED(hr)) { pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n."); } +#endif return S_OK; } __declspec(dllexport) HRESULT WINAPI - RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText, - ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue, - ID3D12Resource *pRenderTarget, char **pReadBackDump) { +RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText, + ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue, + ID3D12Resource *pRenderTarget, char **pReadBackDump) { HRESULT hr; if (pReadBackDump) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 4354f1feea..563c858a31 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -8,6 +8,7 @@ #include #include #include +#include static bool useDebugIfaces() { return true; } @@ -319,6 +320,7 @@ enableExperimentalShaderModels(UUID AdditionalFeatures[] = nullptr, } 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; @@ -390,17 +392,173 @@ HRESULT enableExperimentalMode(HMODULE Runtime) { return HR; } -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; +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 HR; + + return C; +} + +static bool enableGlobalAgilitySDK() { + using namespace hlsl_test; + + std::optional C = getAgilitySDKConfiguration(); + if (!C) + return false; + + if (C->SDKVersion == 0) + return true; + + 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 + // case, will cause a failure in the very next thing that actually requires + // D3D12Core.dll to be loaded instead. So, we attempt to clear experimental + // 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. + if (FAILED( + HR = D3D12EnableExperimentalFeatures(0, nullptr, nullptr, nullptr))) { + LogErrorFmt(L"D3D12EnableExperimentalFeatures(0...) failed: 0x%08x", HR); + return !C->MustFind; + } + + return true; } + +static bool enableGlobalExperimentalMode() { + using namespace hlsl_test; + + const bool ExperimentalShaders = GetTestParamBool(L"ExperimentalShaders"); + + if (!ExperimentalShaders) + return false; + + HRESULT HR; + if (FAILED(HR = D3D12EnableExperimentalFeatures( + 1, &D3D12ExperimentalShaderModels, nullptr, nullptr))) { + LogErrorFmt(L"D3D12EnableExperimentalFeatures(" + L"D3D12ExperimentalShaderModels) failed: 0x%08x", + HR); + return false; + } + + return true; +} + +static void setGlobalConfiguration() { + using namespace hlsl_test; + + if (enableGlobalAgilitySDK()) + 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."); +} + +std::optional D3D12SDK::create() { + using namespace hlsl_test; + + if (enableDebugLayer()) + LogCommentFmt(L"Debug layer enabled"); + else + LogCommentFmt(L"Debug layer not enabled"); + + // CComPtr Config1; + // if (FAILED(D3D12GetInterface(CLSID_D3D12SDKConfiguration, + // IID_PPV_ARGS(&Config1)))) + { return D3D12SDK(nullptr); } + + CComPtr DeviceFactory; + + // ... + + return D3D12SDK(DeviceFactory); +} + +D3D12SDK::D3D12SDK(CComPtr DeviceFactory) + : DeviceFactory(std::move(DeviceFactory)) {} + +D3D12SDK::~D3D12SDK() = default; + +bool D3D12SDK::createDevice(ID3D12Device **D3DDevice, + ExecTestUtils::D3D_SHADER_MODEL TestModel, + bool SkipUnsupported) { + return ::createDevice(D3DDevice, TestModel, SkipUnsupported); +} \ No newline at end of file diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index c9e24b9c3b..79cdc73880 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,22 @@ 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); + +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 88b531bb46..b0421b30a1 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -1512,37 +1512,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); @@ -1579,8 +1551,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; @@ -2284,6 +2256,7 @@ class DxilConf_SM69_Vectorized { private: bool Initialized = false; + std::optional D3D12SDK; bool VerboseLogging = false; size_t OverrideInputSize = 0; UINT OverrideWaveLaneCount = 0; From 6b3b30bc2f9d00b625d814c84036ee9351b4398c Mon Sep 17 00:00:00 2001 From: Damyan Pepper Date: Thu, 6 Nov 2025 21:17:02 -0800 Subject: [PATCH 02/15] Hook up ID3D12DeviceFactory-style --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 153 ++++++++++++++---- 1 file changed, 125 insertions(+), 28 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 563c858a31..caa080566b 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include static bool useDebugIfaces() { return true; } @@ -80,7 +81,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('\\'); @@ -94,6 +98,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); @@ -104,13 +110,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) { +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 " @@ -159,8 +173,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."); @@ -196,8 +210,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(); @@ -224,8 +238,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); @@ -458,15 +472,15 @@ static std::optional getAgilitySDKConfiguration() { return C; } -static bool enableGlobalAgilitySDK() { +static bool +enableGlobalAgilitySDK(const std::optional &C) { using namespace hlsl_test; - std::optional C = getAgilitySDKConfiguration(); if (!C) return false; if (C->SDKVersion == 0) - return true; + return false; CComPtr SDKConfig; HRESULT HR; @@ -498,12 +512,14 @@ static bool enableGlobalAgilitySDK() { return true; } +static bool isExperimentalShadersEnabled() { + return hlsl_test::GetTestParamBool(L"ExperimentalShaders"); +} + static bool enableGlobalExperimentalMode() { using namespace hlsl_test; - const bool ExperimentalShaders = GetTestParamBool(L"ExperimentalShaders"); - - if (!ExperimentalShaders) + if (!isExperimentalShadersEnabled()) return false; HRESULT HR; @@ -518,10 +534,11 @@ static bool enableGlobalExperimentalMode() { return true; } -static void setGlobalConfiguration() { +static void +setGlobalConfiguration(const std::optional &C) { using namespace hlsl_test; - if (enableGlobalAgilitySDK()) + if (enableGlobalAgilitySDK(C)) LogCommentFmt(L"Agility SDK enabled."); else LogCommentFmt(L"Agility SDK not enabled."); @@ -532,6 +549,58 @@ static void setGlobalConfiguration() { LogCommentFmt(L"Experimental mode not enabled."); } +static bool enableExperimentalMode(ID3D12DeviceFactory *DeviceFactory) { + using namespace hlsl_test; + + 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; + } + + 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; + } + + 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; + } + + 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; +} + std::optional D3D12SDK::create() { using namespace hlsl_test; @@ -540,25 +609,53 @@ std::optional D3D12SDK::create() { else LogCommentFmt(L"Debug layer not enabled"); - // CComPtr Config1; - // if (FAILED(D3D12GetInterface(CLSID_D3D12SDKConfiguration, - // IID_PPV_ARGS(&Config1)))) - { return D3D12SDK(nullptr); } - - CComPtr DeviceFactory; + std::optional C = getAgilitySDKConfiguration(); - // ... + if (C && C->SDKVersion > 0) { + CComPtr DeviceFactory = createDeviceFactorySDK(*C); + if (DeviceFactory) + return D3D12SDK(DeviceFactory); + } - return D3D12SDK(DeviceFactory); + setGlobalConfiguration(C); + return D3D12SDK(nullptr); } D3D12SDK::D3D12SDK(CComPtr DeviceFactory) : DeviceFactory(std::move(DeviceFactory)) {} -D3D12SDK::~D3D12SDK() = default; +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(); + } +} bool D3D12SDK::createDevice(ID3D12Device **D3DDevice, ExecTestUtils::D3D_SHADER_MODEL TestModel, bool SkipUnsupported) { - return ::createDevice(D3DDevice, TestModel, 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 From 90810effd83743aa85bd31def72619b6e72ae3b3 Mon Sep 17 00:00:00 2001 From: Damyan Pepper Date: Thu, 6 Nov 2025 21:28:02 -0800 Subject: [PATCH 03/15] lit.cfg passes agility_sdk as a path through to the taef test --- tools/clang/test/taef_exec/lit.cfg | 3 +++ 1 file changed, 3 insertions(+) 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: From f500294e63fc050a5e91f37585444f98f62b5c6b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 7 Nov 2025 05:31:15 +0000 Subject: [PATCH 04/15] chore: autopublish 2025-11-07T05:31:15Z --- tools/clang/unittests/HLSLExec/ExecutionTest.cpp | 10 +++++----- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 8d59003353..e94f6bba70 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -12503,8 +12503,8 @@ 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([[maybe_unused]] void *pStrCtx, - [[maybe_unused]] st::OutputStringFn pOutputStrFn) { + InitializeOpTests([[maybe_unused]] void *pStrCtx, + [[maybe_unused]] st::OutputStringFn pOutputStrFn) { #ifdef _FORCE_EXPERIMENTAL_SHADERS HMODULE Runtime = LoadLibraryW(L"d3d12.dll"); @@ -12521,9 +12521,9 @@ InitializeOpTests([[maybe_unused]] void *pStrCtx, } __declspec(dllexport) HRESULT WINAPI -RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText, - ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue, - ID3D12Resource *pRenderTarget, char **pReadBackDump) { + RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText, + ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue, + ID3D12Resource *pRenderTarget, char **pReadBackDump) { HRESULT hr; if (pReadBackDump) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index caa080566b..209b3400f7 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -559,8 +559,8 @@ static bool enableExperimentalMode(ID3D12DeviceFactory *DeviceFactory) { if (FAILED(HR = DeviceFactory->EnableExperimentalFeatures( 1, &D3D12ExperimentalShaderModels, nullptr, nullptr))) { LogWarningFmt(L"EnableExperimentalFeature(D3D12ExperimentalShaderModels) " - L"failed: 0x%08x", - HR); + L"failed: 0x%08x", + HR); return false; } From 31c4aaa6f2ba66a9885be72c286bb010baa3e932 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Wed, 12 Nov 2025 16:31:11 -0800 Subject: [PATCH 05/15] Fixup LongVectors.cpp --- tools/clang/unittests/HLSLExec/LongVectors.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/LongVectors.cpp b/tools/clang/unittests/HLSLExec/LongVectors.cpp index b0421b30a1..2da7a1a371 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -1564,8 +1564,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; From e96bb07cbb6f3d30f1378ab273f2d39c0c687fac Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Thu, 13 Nov 2025 14:03:21 -0800 Subject: [PATCH 06/15] Use d3d12.h from DirectX-Headers rather than whatever happens to be in the SDK installed on the machine --- CMakeLists.txt | 6 +++++- external/CMakeLists.txt | 12 +++++------- external/DirectX-Headers | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5210718005..1473f8aa99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,7 +682,11 @@ add_subdirectory(utils/hct) if(EXISTS "${LLVM_MAIN_SRC_DIR}/external") add_subdirectory(external) # SPIRV change endif() -include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs) +include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx) + +if( NOT WIN32) + include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs) +endif() # HLSL - Change End diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index a8b2638e3d..b56bc1d2ab 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -9,13 +9,11 @@ endif (NOT HLSL_ENABLE_DEBUG_ITERATORS) # Need DirectX-Headers module if not on windows if (NOT DIRECTX_HEADER_INCLUDE_DIR) - if (NOT WIN32) - if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers") - set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE) - else() - message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers") - endif() - endif (NOT WIN32) + if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers") + set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE) + else() + message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers") + endif() endif(NOT DIRECTX_HEADER_INCLUDE_DIR) # Enabling SPIR-V codegen requires SPIRV-Headers for spirv.hpp and diff --git a/external/DirectX-Headers b/external/DirectX-Headers index 980971e835..18d5bfe964 160000 --- a/external/DirectX-Headers +++ b/external/DirectX-Headers @@ -1 +1 @@ -Subproject commit 980971e835876dc0cde415e8f9bc646e64667bf7 +Subproject commit 18d5bfe96452667b201fd26aa25c6c305ae57e07 From 498bced0c52955e3b500b77f489b12874b2e9430 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Thu, 13 Nov 2025 14:47:56 -0800 Subject: [PATCH 07/15] Revert "Use d3d12.h from DirectX-Headers rather than whatever happens to be in the SDK installed on the machine" This reverts commit e96bb07cbb6f3d30f1378ab273f2d39c0c687fac. --- CMakeLists.txt | 6 +----- external/CMakeLists.txt | 12 +++++++----- external/DirectX-Headers | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1473f8aa99..5210718005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,11 +682,7 @@ add_subdirectory(utils/hct) if(EXISTS "${LLVM_MAIN_SRC_DIR}/external") add_subdirectory(external) # SPIRV change endif() -include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx) - -if( NOT WIN32) - include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs) -endif() +include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs) # HLSL - Change End diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index b56bc1d2ab..a8b2638e3d 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -9,11 +9,13 @@ endif (NOT HLSL_ENABLE_DEBUG_ITERATORS) # Need DirectX-Headers module if not on windows if (NOT DIRECTX_HEADER_INCLUDE_DIR) - if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers") - set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE) - else() - message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers") - endif() + if (NOT WIN32) + if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers") + set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE) + else() + message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers") + endif() + endif (NOT WIN32) endif(NOT DIRECTX_HEADER_INCLUDE_DIR) # Enabling SPIR-V codegen requires SPIRV-Headers for spirv.hpp and diff --git a/external/DirectX-Headers b/external/DirectX-Headers index 18d5bfe964..980971e835 160000 --- a/external/DirectX-Headers +++ b/external/DirectX-Headers @@ -1 +1 @@ -Subproject commit 18d5bfe96452667b201fd26aa25c6c305ae57e07 +Subproject commit 980971e835876dc0cde415e8f9bc646e64667bf7 From 0d75a3ccd00be680d4652925d128e4658b1fde93 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 14 Nov 2025 15:39:30 -0800 Subject: [PATCH 08/15] Work with older SDKs --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 62 +++++++++++++++++-- .../unittests/HLSLExec/HlslExecTestUtils.h | 13 ++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 209b3400f7..450fb32a5d 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -46,11 +46,11 @@ static const GUID D3D12ExperimentalShaderModelsID = typedef HRESULT(WINAPI *D3D12GetInterfaceFn)(REFCLSID Rclsid, REFIID Riid, void **Debug); -#ifndef __ID3D12SDKConfiguration_INTERFACE_DEFINED__ - -// Copied from AgilitySDK D3D12.h to programmatically enable when in developer -// mode. -#define __ID3D12SDKConfiguration_INTERFACE_DEFINED__ +// +// BEGIN: Copied from AgilitySDK D3D12.h. +// +// See defines in header to prevent any system +// version of these interfaces from being defined. EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12SDKConfiguration = { 0xe9eb5314, @@ -69,7 +69,57 @@ ID3D12SDKConfiguration : public IUnknown { virtual HRESULT STDMETHODCALLTYPE SetSDKVersion(UINT SDKVersion, LPCSTR SDKPath) = 0; }; -#endif /* __ID3D12SDKConfiguration_INTERFACE_DEFINED__ */ + +EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12DeviceFactory = { + 0x61f307d3, + 0xd34e, + 0x4e7c, + {0x83, 0x74, 0x3b, 0xa4, 0xde, 0x23, 0xcc, 0xcb}}; + +MIDL_INTERFACE("61f307d3-d34e-4e7c-8374-3ba4de23cccb") +ID3D12DeviceFactory : public IUnknown { +public: + virtual HRESULT STDMETHODCALLTYPE InitializeFromGlobalState(void) = 0; + + virtual HRESULT STDMETHODCALLTYPE ApplyToGlobalState(void) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetFlags( + D3D12_DEVICE_FACTORY_FLAGS flags) = 0; + + virtual D3D12_DEVICE_FACTORY_FLAGS STDMETHODCALLTYPE GetFlags(void) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetConfigurationInterface( + REFCLSID clsid, REFIID iid, _COM_Outptr_ void **ppv) = 0; + + virtual HRESULT STDMETHODCALLTYPE EnableExperimentalFeatures( + UINT NumFeatures, _In_reads_(NumFeatures) const IID *pIIDs, + _In_reads_opt_(NumFeatures) void *pConfigurationStructs, + _In_reads_opt_(NumFeatures) UINT *pConfigurationStructSizes) = 0; + + virtual HRESULT STDMETHODCALLTYPE CreateDevice( + _In_opt_ IUnknown * adapter, D3D_FEATURE_LEVEL FeatureLevel, REFIID riid, + _COM_Outptr_opt_ void **ppvDevice) = 0; +}; + +EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12SDKConfiguration1 = { + 0x8aaf9303, + 0xad25, + 0x48b9, + {0x9a, 0x57, 0xd9, 0xc3, 0x7e, 0x00, 0x9d, 0x9f}}; + +MIDL_INTERFACE("8aaf9303-ad25-48b9-9a57-d9c37e009d9f") +ID3D12SDKConfiguration1 : public ID3D12SDKConfiguration { +public: + virtual HRESULT STDMETHODCALLTYPE CreateDeviceFactory( + UINT SDKVersion, _In_ LPCSTR SDKPath, REFIID riid, + _COM_Outptr_ void **ppvFactory) = 0; + + virtual void STDMETHODCALLTYPE FreeUnusedSDKs(void) = 0; +}; + +// +// END: Copied from AgilitySDK D3D12.h. +// static std::wstring getModuleName() { wchar_t ModuleName[MAX_PATH + 1] = {0}; diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index 79cdc73880..c992890d2a 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -1,6 +1,19 @@ #ifndef HLSLEXECTESTUTILS_H #define HLSLEXECTESTUTILS_H +// Until we start using an AgilitySDK, we need to be able to build on agents +// that haven't got updated SDKs on them. For these, we'll always use our own +// definitions of these interfaces, so that we can be consistent between local +// and cloud builds. +#define __ID3D12DeviceFactory_FWD_DEFINED__ +#define __ID3D12DeviceFactory_INTERFACE_DEFINED__ +#define __ID3D12SDKConfiguration_FWD_DEFINED__ +#define __ID3D12SDKConfiguration_INTERFACE_DEFINED__ +#define __ID3D12SDKConfiguration1_FWD_DEFINED__ +#define __ID3D12SDKConfiguration1_INTERFACE_DEFINED__ + +struct ID3D12DeviceFactory; + #include #include #include From 42886f83f55d39abfd87e56901d9b09d3a4ac38e Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 14 Nov 2025 15:48:20 -0800 Subject: [PATCH 09/15] Formatting --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 450fb32a5d..2482226a48 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -47,7 +47,7 @@ typedef HRESULT(WINAPI *D3D12GetInterfaceFn)(REFCLSID Rclsid, REFIID Riid, void **Debug); // -// BEGIN: Copied from AgilitySDK D3D12.h. +// BEGIN: Copied from AgilitySDK D3D12.h. // // See defines in header to prevent any system // version of these interfaces from being defined. @@ -118,7 +118,7 @@ ID3D12SDKConfiguration1 : public ID3D12SDKConfiguration { }; // -// END: Copied from AgilitySDK D3D12.h. +// END: Copied from AgilitySDK D3D12.h. // static std::wstring getModuleName() { From 64559341f9b7660f05cd31e1a37d268786724297 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 14 Nov 2025 16:46:04 -0800 Subject: [PATCH 10/15] Revert "Formatting" This reverts commit 42886f83f55d39abfd87e56901d9b09d3a4ac38e. --- tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 2482226a48..450fb32a5d 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -47,7 +47,7 @@ typedef HRESULT(WINAPI *D3D12GetInterfaceFn)(REFCLSID Rclsid, REFIID Riid, void **Debug); // -// BEGIN: Copied from AgilitySDK D3D12.h. +// BEGIN: Copied from AgilitySDK D3D12.h. // // See defines in header to prevent any system // version of these interfaces from being defined. @@ -118,7 +118,7 @@ ID3D12SDKConfiguration1 : public ID3D12SDKConfiguration { }; // -// END: Copied from AgilitySDK D3D12.h. +// END: Copied from AgilitySDK D3D12.h. // static std::wstring getModuleName() { From bb9a8422f3dee4599f583cf99ac95b45acfdf78e Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 14 Nov 2025 16:46:08 -0800 Subject: [PATCH 11/15] Revert "Work with older SDKs" This reverts commit 0d75a3ccd00be680d4652925d128e4658b1fde93. --- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 62 ++----------------- .../unittests/HLSLExec/HlslExecTestUtils.h | 13 ---- 2 files changed, 6 insertions(+), 69 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 450fb32a5d..209b3400f7 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -46,11 +46,11 @@ static const GUID D3D12ExperimentalShaderModelsID = typedef HRESULT(WINAPI *D3D12GetInterfaceFn)(REFCLSID Rclsid, REFIID Riid, void **Debug); -// -// BEGIN: Copied from AgilitySDK D3D12.h. -// -// See defines in header to prevent any system -// version of these interfaces from being defined. +#ifndef __ID3D12SDKConfiguration_INTERFACE_DEFINED__ + +// Copied from AgilitySDK D3D12.h to programmatically enable when in developer +// mode. +#define __ID3D12SDKConfiguration_INTERFACE_DEFINED__ EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12SDKConfiguration = { 0xe9eb5314, @@ -69,57 +69,7 @@ ID3D12SDKConfiguration : public IUnknown { virtual HRESULT STDMETHODCALLTYPE SetSDKVersion(UINT SDKVersion, LPCSTR SDKPath) = 0; }; - -EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12DeviceFactory = { - 0x61f307d3, - 0xd34e, - 0x4e7c, - {0x83, 0x74, 0x3b, 0xa4, 0xde, 0x23, 0xcc, 0xcb}}; - -MIDL_INTERFACE("61f307d3-d34e-4e7c-8374-3ba4de23cccb") -ID3D12DeviceFactory : public IUnknown { -public: - virtual HRESULT STDMETHODCALLTYPE InitializeFromGlobalState(void) = 0; - - virtual HRESULT STDMETHODCALLTYPE ApplyToGlobalState(void) = 0; - - virtual HRESULT STDMETHODCALLTYPE SetFlags( - D3D12_DEVICE_FACTORY_FLAGS flags) = 0; - - virtual D3D12_DEVICE_FACTORY_FLAGS STDMETHODCALLTYPE GetFlags(void) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetConfigurationInterface( - REFCLSID clsid, REFIID iid, _COM_Outptr_ void **ppv) = 0; - - virtual HRESULT STDMETHODCALLTYPE EnableExperimentalFeatures( - UINT NumFeatures, _In_reads_(NumFeatures) const IID *pIIDs, - _In_reads_opt_(NumFeatures) void *pConfigurationStructs, - _In_reads_opt_(NumFeatures) UINT *pConfigurationStructSizes) = 0; - - virtual HRESULT STDMETHODCALLTYPE CreateDevice( - _In_opt_ IUnknown * adapter, D3D_FEATURE_LEVEL FeatureLevel, REFIID riid, - _COM_Outptr_opt_ void **ppvDevice) = 0; -}; - -EXTERN_C const GUID DECLSPEC_SELECTANY IID_ID3D12SDKConfiguration1 = { - 0x8aaf9303, - 0xad25, - 0x48b9, - {0x9a, 0x57, 0xd9, 0xc3, 0x7e, 0x00, 0x9d, 0x9f}}; - -MIDL_INTERFACE("8aaf9303-ad25-48b9-9a57-d9c37e009d9f") -ID3D12SDKConfiguration1 : public ID3D12SDKConfiguration { -public: - virtual HRESULT STDMETHODCALLTYPE CreateDeviceFactory( - UINT SDKVersion, _In_ LPCSTR SDKPath, REFIID riid, - _COM_Outptr_ void **ppvFactory) = 0; - - virtual void STDMETHODCALLTYPE FreeUnusedSDKs(void) = 0; -}; - -// -// END: Copied from AgilitySDK D3D12.h. -// +#endif /* __ID3D12SDKConfiguration_INTERFACE_DEFINED__ */ static std::wstring getModuleName() { wchar_t ModuleName[MAX_PATH + 1] = {0}; diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index c992890d2a..79cdc73880 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -1,19 +1,6 @@ #ifndef HLSLEXECTESTUTILS_H #define HLSLEXECTESTUTILS_H -// Until we start using an AgilitySDK, we need to be able to build on agents -// that haven't got updated SDKs on them. For these, we'll always use our own -// definitions of these interfaces, so that we can be consistent between local -// and cloud builds. -#define __ID3D12DeviceFactory_FWD_DEFINED__ -#define __ID3D12DeviceFactory_INTERFACE_DEFINED__ -#define __ID3D12SDKConfiguration_FWD_DEFINED__ -#define __ID3D12SDKConfiguration_INTERFACE_DEFINED__ -#define __ID3D12SDKConfiguration1_FWD_DEFINED__ -#define __ID3D12SDKConfiguration1_INTERFACE_DEFINED__ - -struct ID3D12DeviceFactory; - #include #include #include From 84720e3b059bff67323398660d372ef6799e360d Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 14 Nov 2025 16:47:33 -0800 Subject: [PATCH 12/15] Set WINSDK_MIN_VERSION to supported version https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ --- utils/hct/hctbuild.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hct/hctbuild.cmd b/utils/hct/hctbuild.cmd index 87f19581f7..4567fa1bba 100644 --- a/utils/hct/hctbuild.cmd +++ b/utils/hct/hctbuild.cmd @@ -42,7 +42,7 @@ set SPV_TEST=OFF set DXILCONV=ON set DXC_CMAKE_SYSTEM_VERSION= set SHOW_CMAKE_LOG=0 -set WINSDK_MIN_VERSION=10.0.17763.0 +set WINSDK_MIN_VERSION=10.0.26100.0 set INSTALL_DIR= set DEFAULT_EXEC_ADAPTER=-DTAEF_EXEC_ADAPTER= set LIT_ARGS= From 980909dec71e6a81bc58983948c079113b5c4705 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 21 Nov 2025 13:03:41 -0800 Subject: [PATCH 13/15] Docs --- .../unittests/HLSLExec/HlslExecTestUtils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index 79cdc73880..bc76cbbd1e 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -29,6 +29,23 @@ typedef enum D3D_SHADER_MODEL { bool useDxbc(); +/// 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; From a82a6e026e2df525d08f10a5312ca5482439e4b7 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 21 Nov 2025 13:27:08 -0800 Subject: [PATCH 14/15] Remove dead code --- tools/clang/.clang-tidy | 2 +- .../unittests/HLSLExec/HlslExecTestUtils.cpp | 138 +----------------- 2 files changed, 3 insertions(+), 137 deletions(-) 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/unittests/HLSLExec/HlslExecTestUtils.cpp b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp index 5bd03afdbf..a61818fc4c 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" @@ -78,7 +77,7 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) { return SDKVersion; } -bool createDevice( +static bool createDevice( ID3D12Device **D3DDevice, ExecTestUtils::D3D_SHADER_MODEL TestModel, bool SkipUnsupported, std::function @@ -108,7 +107,7 @@ bool createDevice( // before attempting to create the device. struct WarpDll { - HMODULE Module = NULL; + HMODULE Module = NULL; // NOLINT ~WarpDll() { Close(); } @@ -233,139 +232,6 @@ 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))); - - // Currently, it appears that the SetSDKVersion will succeed even when - // D3D12Core is not found, or its version doesn't match. When that's the - // case, will cause a failure in the very next thing that actually requires - // D3D12Core.dll to be loaded instead. So, we attempt to clear experimental - // 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); -} - -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()); - - std::vector Features; - - Features.push_back(D3D12ExperimentalShaderModels); - - if (AdditionalFeatures != nullptr && NumAdditionalFeatures > 0) - Features.insert(Features.end(), AdditionalFeatures, - AdditionalFeatures + NumAdditionalFeatures); - - return ExperimentalFeaturesFunc((UINT)Features.size(), Features.data(), - nullptr, nullptr); -} - -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); -} - -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); - - // 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 (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; - } - } - - // 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; - } - if (HR == S_OK) - hlsl_test::LogCommentFmt(L"Agility SDK version set to: %d", SDKVersion); - - return HR; -} - -HRESULT enableExperimentalMode(HMODULE Runtime) { -#ifdef _FORCE_EXPERIMENTAL_SHADERS - bool ExperimentalShaderModels = true; -#else - bool ExperimentalShaderModels = - hlsl_test::GetTestParamBool(L"ExperimentalShaders"); -#endif // _FORCE_EXPERIMENTAL_SHADERS - - HRESULT HR = S_FALSE; - if (ExperimentalShaderModels) { - HR = enableExperimentalShaderModels(Runtime); - if (SUCCEEDED(HR)) - WEX::Logging::Log::Comment(L"Experimental shader models enabled."); - } - - return HR; -} - static bool enableDebugLayer() { using namespace hlsl_test; From f40b3fddc773a956ade735242882aa002d99c3e7 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 21 Nov 2025 13:53:15 -0800 Subject: [PATCH 15/15] use warnings rather than errors for non-fatal logging messages --- 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 a61818fc4c..daeca99258 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp @@ -331,7 +331,7 @@ enableGlobalAgilitySDK(const std::optional &C) { // setting actually failed. if (FAILED( HR = D3D12EnableExperimentalFeatures(0, nullptr, nullptr, nullptr))) { - LogErrorFmt(L"D3D12EnableExperimentalFeatures(0...) failed: 0x%08x", HR); + LogWarningFmt(L"D3D12EnableExperimentalFeatures(0...) failed: 0x%08x", HR); return !C->MustFind; } @@ -351,9 +351,9 @@ static bool enableGlobalExperimentalMode() { HRESULT HR; if (FAILED(HR = D3D12EnableExperimentalFeatures( 1, &D3D12ExperimentalShaderModels, nullptr, nullptr))) { - LogErrorFmt(L"D3D12EnableExperimentalFeatures(" - L"D3D12ExperimentalShaderModels) failed: 0x%08x", - HR); + LogWarningFmt(L"D3D12EnableExperimentalFeatures(" + L"D3D12ExperimentalShaderModels) failed: 0x%08x", + HR); return false; }