Skip to content

Commit 9800c91

Browse files
committed
address tex, update unit test
1 parent eeb1516 commit 9800c91

File tree

3 files changed

+90
-46
lines changed

3 files changed

+90
-46
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport {
1010

1111
std::string DxilDllPath;
1212

13-
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override;
14-
15-
public:
1613
// override DxcDllSupport's implementation of InitializeInternal,
1714
// adding the environment variable value check for a path to a dxil.dll
15+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override;
1816

17+
public:
1918
std::string GetDxilDllPath() { return DxilDllPath; }
2019
bool DxilDllFailedToLoad() {
2120
return !DxilDllPath.empty() && !DxilSupport.IsEnabled();
@@ -31,4 +30,9 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport {
3130
DxilSupport.Cleanup();
3231
return DxcDllSupport::Detach();
3332
}
33+
34+
HRESULT CreateInstance(REFCLSID clsid, REFIID riid,
35+
IUnknown **pResult) override;
36+
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
37+
IUnknown **pResult) override;
3438
};

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,32 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName,
3535

3636
return S_OK;
3737
}
38+
39+
HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid,
40+
IUnknown **pResult) {
41+
if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator)
42+
return DxilSupport.CreateInstance(clsid, riid, pResult);
43+
44+
if (pResult == nullptr)
45+
return E_POINTER;
46+
if (m_dll == nullptr)
47+
return E_FAIL;
48+
HRESULT hr = m_createFn(clsid, riid, (LPVOID *)pResult);
49+
return hr;
50+
}
51+
52+
HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc,
53+
REFCLSID clsid, REFIID riid,
54+
IUnknown **pResult) {
55+
if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator)
56+
return DxilSupport.CreateInstance2(pMalloc, clsid, riid, pResult);
57+
58+
if (pResult == nullptr)
59+
return E_POINTER;
60+
if (m_dll == nullptr)
61+
return E_FAIL;
62+
if (m_createFn2 == nullptr)
63+
return E_FAIL;
64+
HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID *)pResult);
65+
return hr;
66+
}

tools/clang/unittests/HLSL/ValidationTest.cpp

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ class ValidationTest : public ::testing::Test {
300300
TEST_METHOD(ValidatePrintfNotAllowed)
301301

302302
TEST_METHOD(ValidateWithHash)
303-
TEST_METHOD(ValidateWithExternalValidator)
304303
TEST_METHOD(ValidateVersionNotAllowed)
305304
TEST_METHOD(ValidatePreviewBypassHash)
306305
TEST_METHOD(ValidateProgramVersionAgainstDxilModule)
@@ -325,12 +324,12 @@ class ValidationTest : public ::testing::Test {
325324
TEST_METHOD(PSVContentValidationCS)
326325
TEST_METHOD(PSVContentValidationMS)
327326
TEST_METHOD(PSVContentValidationAS)
327+
TEST_METHOD(UnitTestExtValidationSupport)
328328
TEST_METHOD(WrongPSVSize)
329329
TEST_METHOD(WrongPSVSizeOnZeros)
330330
TEST_METHOD(WrongPSVVersion)
331331

332332
dxc::DxcDllSupport m_dllSupport;
333-
DxcDllExtValidationSupport m_dllExtSupport;
334333
VersionSupportInfo m_ver;
335334

336335
void TestCheck(LPCWSTR name) {
@@ -4210,55 +4209,67 @@ TEST_F(ValidationTest, ValidateWithHash) {
42104209
VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0);
42114210
}
42124211

4213-
TEST_F(ValidationTest, ValidateWithExternalValidator) {
4214-
/*
4215-
// The below part of the test was run on a local machine,
4216-
// but shouldn't be run yet in automated scenarios, since
4217-
// the DXC repo does not yet have a checked-in dxil.dll.
4218-
4219-
// set the environment variable that stores the path to the extenral
4220-
// dxil.dll
4221-
SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH",
4222-
L"D:\\hlsl.bin\\Debug\\bin\\dxil.dll");
4212+
// For now, 3 things are tested:
4213+
// 1. The environment variable is not set. GetDxilDllPath() is empty and
4214+
// DxilDllFailedToLoad() returns false
4215+
// 2. Given a bogus path in the environment variable, GetDxilDllPath()
4216+
// retrieves the path but fails to load it as a dll, and returns true
4217+
// for DxilDllFailedToLoad()
4218+
// 3. CLSID_DxcCompiler, CLSID_DxcLinker, CLSID_DxcValidator
4219+
// may be created through DxcDllExtValidationSupport.
4220+
// This is all to simply test that the new class, DxcDllExtValidationSupport,
4221+
// works as intended.
4222+
4223+
TEST_F(ValidationTest, UnitTestExtValidationSupport) {
4224+
DxcDllExtValidationSupport m_dllExtSupport1;
4225+
DxcDllExtValidationSupport m_dllExtSupport2;
4226+
4227+
// 1. with no env var set, test GetDxilDllPath() and DxilDllFailedToLoad()
4228+
m_dllExtSupport1.Initialize();
4229+
VERIFY_IS_FALSE(m_dllExtSupport1.DxilDllFailedToLoad());
4230+
VERIFY_ARE_EQUAL(m_dllExtSupport1.GetDxilDllPath(), "");
4231+
4232+
// 2. Test with a bogus path in the environment variable
4233+
SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", L"bogus");
42234234
// also update the CRT environment
4224-
_putenv_s("DXC_DXIL_DLL_PATH", "D:\\hlsl.bin\\Debug\\bin\\dxil.dll");
4225-
*/
4235+
_putenv_s("DXC_DXIL_DLL_PATH", "bogus");
42264236

4227-
if (!m_dllExtSupport.IsEnabled()) {
4228-
VERIFY_SUCCEEDED(m_dllExtSupport.Initialize());
4237+
if (!m_dllExtSupport2.IsEnabled()) {
4238+
VERIFY_SUCCEEDED(m_dllExtSupport2.Initialize());
42294239
}
42304240

4231-
if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestReleasedMinor))
4232-
return;
4233-
CComPtr<IDxcBlob> pProgram;
4234-
CompileSource("float4 main(float a:A, float b:B) : SV_Target { return 1; }",
4235-
"ps_6_0", &pProgram);
4241+
// validate that m_dllExtSupport2 was able to capture the environment
4242+
// variable's value, and that loading the bogus path was unsuccessful
4243+
std::string extPath("bogus");
4244+
VERIFY_ARE_EQUAL(m_dllExtSupport2.GetDxilDllPath(), extPath);
4245+
VERIFY_IS_TRUE(m_dllExtSupport2.DxilDllFailedToLoad());
42364246

4247+
// 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker,
4248+
// and CLSID_DxcValidator through DxcDllExtValidationSupport.
4249+
CComPtr<IDxcCompiler> pCompiler;
4250+
CComPtr<IDxcLinker> pLinker;
42374251
CComPtr<IDxcValidator> pValidator;
42384252
CComPtr<IDxcOperationResult> pResult;
4239-
unsigned Flags = 0;
4240-
VERIFY_SUCCEEDED(
4241-
m_dllExtSupport.CreateInstance(CLSID_DxcValidator, &pValidator));
4242-
// With hash.
4243-
VERIFY_SUCCEEDED(pValidator->Validate(pProgram, Flags, &pResult));
4244-
// Make sure the validation was successful.
4245-
HRESULT status;
4246-
VERIFY_IS_NOT_NULL(pResult);
4247-
CComPtr<IDxcBlob> pValidationOutput;
4248-
pResult->GetStatus(&status);
4249-
VERIFY_SUCCEEDED(status);
4250-
pResult->GetResult(&pValidationOutput);
4251-
4252-
/*
4253-
// as described above, this should only be tested in local scenarios,
4254-
// until dxil.dll is checked into the dxc repo
42554253

4256-
// validate that m_dllExtSupport was able to capture the environment
4257-
// variable's value, and that loading the external validator was successful
4258-
VERIFY_IS_TRUE(!m_dllExtSupport.DxilDllFailedToLoad());
4259-
std::string extPath("D:\\hlsl.bin\\Debug\\bin\\dxil.dll");
4260-
VERIFY_ARE_EQUAL(m_dllExtSupport.GetDxilDllPath(), extPath);
4261-
*/
4254+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance(
4255+
CLSID_DxcCompiler, __uuidof(IDxcCompiler), (IUnknown **)&pCompiler));
4256+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance(
4257+
CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker));
4258+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance(
4259+
CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&pValidator));
4260+
CComPtr<IMalloc> pMalloc;
4261+
CComPtr<IDxcCompiler2> pCompiler2;
4262+
pLinker.Release();
4263+
pValidator.Release();
4264+
VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &pMalloc));
4265+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcCompiler,
4266+
__uuidof(IDxcCompiler),
4267+
(IUnknown **)&pCompiler2));
4268+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(
4269+
pMalloc, CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker));
4270+
VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcValidator,
4271+
__uuidof(IDxcValidator),
4272+
(IUnknown **)&pValidator));
42624273
}
42634274

42644275
TEST_F(ValidationTest, ValidatePreviewBypassHash) {

0 commit comments

Comments
 (0)