Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/clang/unittests/HLSLExec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_clang_library(ExecHLSLTests SHARED
ShaderOpTest.cpp
TableParameterHandler.cpp
LongVectors.cpp
HlslExecTestUtils.cpp
ExecHLSLTests.rc
)

Expand Down
179 changes: 7 additions & 172 deletions tools/clang/unittests/HLSLExec/ExecutionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,177 +1483,6 @@ class ExecutionTest {
}
#endif

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<ID3D12Debug> debugController;
hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
if (SUCCEEDED(hr)) {
debugController->EnableDebugLayer();
hr = S_OK;
}
}
return hr;
}

static std::wstring GetModuleName() {
wchar_t moduleName[MAX_PATH + 1] = {0};
DWORD length = GetModuleFileNameW(NULL, moduleName, MAX_PATH);
if (length == 0 || length == MAX_PATH) {
return std::wstring(); // Error condition
}
return std::wstring(moduleName, length);
}

static std::wstring ComputeSDKFullPath(std::wstring SDKPath) {
std::wstring modulePath = GetModuleName();
size_t pos = modulePath.rfind('\\');
if (pos == std::wstring::npos)
return SDKPath;
if (SDKPath.substr(0, 2) != L".\\")
return SDKPath;
return modulePath.substr(0, pos) + SDKPath.substr(1);
}

static UINT GetD3D12SDKVersion(std::wstring SDKPath) {
// Try to automatically get the D3D12SDKVersion from the DLL
UINT SDKVersion = 0;
std::wstring D3DCorePath = ComputeSDKFullPath(SDKPath);
D3DCorePath.append(L"D3D12Core.dll");
HMODULE hCore = LoadLibraryW(D3DCorePath.c_str());
if (hCore) {
if (UINT *pSDKVersion = (UINT *)GetProcAddress(hCore, "D3D12SDKVersion"))
SDKVersion = *pSDKVersion;
FreeModule(hCore);
}
return SDKVersion;
}

static HRESULT EnableAgilitySDK(HMODULE hRuntime, UINT SDKVersion,
LPCWSTR SDKPath) {
D3D12GetInterfaceFn pD3D12GetInterface =
(D3D12GetInterfaceFn)GetProcAddress(hRuntime, "D3D12GetInterface");
CComPtr<ID3D12SDKConfiguration> pD3D12SDKConfiguration;
IFR(pD3D12GetInterface(CLSID_D3D12SDKConfiguration,
IID_PPV_ARGS(&pD3D12SDKConfiguration)));
IFR(pD3D12SDKConfiguration->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.
D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
(D3D12EnableExperimentalFeaturesFn)GetProcAddress(
hRuntime, "D3D12EnableExperimentalFeatures");
if (pD3D12EnableExperimentalFeatures == 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 pD3D12EnableExperimentalFeatures(0, nullptr, nullptr, nullptr);
}

static HRESULT EnableExperimentalShaderModels(HMODULE hRuntime) {
D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
(D3D12EnableExperimentalFeaturesFn)GetProcAddress(
hRuntime, "D3D12EnableExperimentalFeatures");
if (pD3D12EnableExperimentalFeatures == nullptr) {
return HRESULT_FROM_WIN32(GetLastError());
}
return pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID,
nullptr, nullptr);
}

static HRESULT EnableExperimentalShaderModels() {
HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
if (hRuntime == NULL)
return E_FAIL;
return EnableExperimentalShaderModels(hRuntime);
}

HRESULT EnableAgilitySDK(HMODULE hRuntime) {
// 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\\";
}

bool mustFind = SDKVersion > 0;
if (SDKVersion <= 1) {
// lookup version from D3D12Core.dll
SDKVersion = GetD3D12SDKVersion((LPCWSTR)SDKPath);
if (mustFind && SDKVersion == 0) {
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(hRuntime, 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) {
LogErrorFmt(L"Failed to set Agility SDK version %d at path: %s",
SDKVersion, (LPCWSTR)SDKPath);
return hr;
}
return S_FALSE;
}
if (hr == S_OK) {
LogCommentFmt(L"Agility SDK version set to: %d", SDKVersion);
m_AgilitySDKEnabled = true;
}
return hr;
}

HRESULT EnableExperimentalMode(HMODULE hRuntime) {
if (m_ExperimentalModeEnabled) {
return S_OK;
}

#ifdef _FORCE_EXPERIMENTAL_SHADERS
bool bExperimentalShaderModels = true;
#else
bool bExperimentalShaderModels = GetTestParamBool(L"ExperimentalShaders");
#endif // _FORCE_EXPERIMENTAL_SHADERS

HRESULT hr = S_FALSE;
if (bExperimentalShaderModels) {
hr = EnableExperimentalShaderModels(hRuntime);
if (SUCCEEDED(hr)) {
m_ExperimentalModeEnabled = true;
}
}

return hr;
}

struct FenceObj {
HANDLE m_fenceEvent = NULL;
CComPtr<ID3D12Fence> m_fence;
Expand Down Expand Up @@ -12699,7 +12528,13 @@ static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
extern "C" {
__declspec(dllexport) HRESULT WINAPI
InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
HRESULT hr = ExecutionTest::EnableExperimentalShaderModels();
HMODULE Runtime = LoadLibraryW(L"d3d12.dll");

if (Runtime == NULL)
return E_FAIL;

HRESULT hr = enableExperimentalMode(Runtime);

if (FAILED(hr)) {
pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
}
Expand Down
Loading