Skip to content

Commit 4a8b666

Browse files
committed
address Tex
1 parent 8dc8a10 commit 4a8b666

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class DxcDllExtValidationLoader : public DllLoader {
1414
dxc::SpecificDllLoader DxCompilerSupport;
1515
dxc::SpecificDllLoader DxilExtValSupport;
1616
std::string DxilDllPath;
17-
enum {
17+
18+
public:
19+
std::string getDxilDllPath() { return DxilDllPath; }
20+
enum InitializationFailures {
1821
FailedNone = 0,
1922
FailedCompilerLoad,
2023
FailedDxilPath,
2124
FailedDxilLoad,
2225
} FailureReason = FailedNone;
23-
24-
public:
25-
std::string getDxilDllPath() { return DxilDllPath; }
26-
int getFailureReason() { return FailureReason; }
26+
InitializationFailures getFailureReason() { return FailureReason; }
2727
bool dxilDllFailedToLoad() {
2828
return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled();
2929
}
@@ -34,6 +34,7 @@ class DxcDllExtValidationLoader : public DllLoader {
3434
IUnknown **pResult) override;
3535

3636
HRESULT initialize();
37+
HRESULT InitializeForDll(LPCSTR dllName, LPCSTR fnName);
3738

3839
bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); }
3940
};

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ HRESULT DxcDllExtValidationLoader::CreateInstance2Impl(
406406
}
407407

408408
HRESULT
409-
DxcDllExtValidationLoader::initialize() {
409+
DxcDllExtValidationLoader::InitializeForDll(LPCSTR dllName, LPCSTR fnName) {
410410
// Load dxcompiler.dll
411411
HRESULT Result =
412412
DxCompilerSupport.InitializeForDll(kDxCompilerLib, "DxcCreateInstance");
@@ -442,4 +442,8 @@ DxcDllExtValidationLoader::initialize() {
442442
return Result;
443443
}
444444

445+
HRESULT DxcDllExtValidationLoader::initialize() {
446+
return InitializeForDll(kDxCompilerLib, "DxcCreateInstance");
447+
}
448+
445449
} // namespace dxc

tools/clang/tools/dxclib/dxc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,16 +1459,16 @@ int dxc::main(int argc, const char **argv_) {
14591459
HRESULT dllResult = dxcSupport.initialize();
14601460
if (DXC_FAILED(dllResult)) {
14611461
switch (dxcSupport.getFailureReason()) {
1462-
case 1: {
1462+
case dxcSupport.FailedCompilerLoad: {
14631463
fprintf(stderr, "dxcompiler.dll failed to load\n");
14641464
break;
14651465
}
1466-
case 2: {
1466+
case dxcSupport.FailedDxilPath: {
14671467
fprintf(stderr, "dxil.dll path %s could not be found",
14681468
dxcSupport.getDxilDllPath().c_str());
14691469
break;
14701470
}
1471-
case 3: {
1471+
case dxcSupport.FailedDxilLoad: {
14721472
fprintf(stderr, "%s failed to load",
14731473
dxcSupport.getDxilDllPath().c_str());
14741474
break;

tools/clang/tools/dxv/dxv.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,29 @@ int main(int argc, const char **argv) {
163163
}
164164

165165
DxcDllExtValidationLoader dxcSupport;
166-
std::string dllLogString;
167-
IFT(dxcSupport.initialize());
166+
HRESULT dllResult = dxcSupport.initialize();
167+
if (DXC_FAILED(dllResult)) {
168+
switch (dxcSupport.getFailureReason()) {
169+
case dxcSupport.InitializationFailures::FailedCompilerLoad: {
170+
fprintf(stderr, "dxcompiler.dll failed to load\n");
171+
break;
172+
}
173+
case dxcSupport.InitializationFailures::FailedDxilPath: {
174+
fprintf(stderr, "dxil.dll path %s could not be found",
175+
dxcSupport.getDxilDllPath().c_str());
176+
break;
177+
}
178+
case dxcSupport.InitializationFailures::FailedDxilLoad: {
179+
fprintf(stderr, "%s failed to load",
180+
dxcSupport.getDxilDllPath().c_str());
181+
break;
182+
}
183+
default: {
184+
llvm_unreachable("unexpected failure reason");
185+
}
186+
}
187+
return dllResult;
188+
}
168189

169190
DxvContext context(dxcSupport);
170191
pStage = "Validation";

tools/clang/unittests/HLSL/ValidationTest.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "dxc/Support/WinIncludes.h"
1414
#include <algorithm>
15+
#include <filesystem>
1516
#include <memory>
1617
#include <string>
1718
#include <vector>
@@ -4221,13 +4222,17 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) {
42214222
_wputenv_s(VarName.c_str(), VarValue.c_str());
42224223
}
42234224

4224-
// For now, 3 things are tested:
4225+
// For now, 4 things are tested:
42254226
// 1. The environment variable is not set. GetDxilDllPath() is empty and
42264227
// DxilDllFailedToLoad() returns false
42274228
// 2. Given a bogus path in the environment variable, and an initialized
42284229
// DxcDllExtValidationSupport object, GetDxilDllPath()
42294230
// retrieves the bogus path despite DxcDllExtValidationSupport failing to load
42304231
// it as a dll, and DxilDllFailedToLoad() returns true.
4232+
// 3. Given a valid path in the environment variable to a non-dll file,
4233+
// and an initialized DxcDllExtValidationSupport object, GetDxilDllPath()
4234+
// retrieves the valid path despite DxcDllExtValidationSupport failing to load
4235+
// it as a dll, and DxilDllFailedToLoad() returns true.
42314236
// 3. CLSID_DxcCompiler, CLSID_DxcLinker, CLSID_DxcValidator
42324237
// may be created through DxcDllExtValidationSupport.
42334238
// This is all to simply test that the new class, DxcDllExtValidationSupport,
@@ -4236,6 +4241,7 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) {
42364241
TEST_F(ValidationTest, UnitTestExtValidationSupport) {
42374242
dxc::DxcDllExtValidationLoader ExtSupportEmpty;
42384243
dxc::DxcDllExtValidationLoader ExtSupportBogus;
4244+
dxc::DxcDllExtValidationLoader ExtSupportValidNonDLLPath;
42394245

42404246
// capture any existing value in the environment variable,
42414247
// so that it can be restored after the test
@@ -4250,23 +4256,41 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) {
42504256
VERIFY_SUCCEEDED(ExtSupportEmpty.initialize());
42514257

42524258
VERIFY_IS_FALSE(ExtSupportEmpty.dxilDllFailedToLoad());
4253-
std::string EmptyPath = ExtSupportBogus.getDxilDllPath();
4259+
std::string EmptyPath = ExtSupportEmpty.getDxilDllPath();
42544260
VERIFY_ARE_EQUAL_STR(EmptyPath.c_str(), "");
42554261

42564262
// 2. Test with a bogus path in the environment variable
42574263
SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus");
42584264

42594265
if (!ExtSupportBogus.IsEnabled()) {
42604266
VERIFY_FAILED(ExtSupportBogus.initialize());
4267+
VERIFY_ARE_EQUAL(ExtSupportBogus.getFailureReason(),
4268+
ExtSupportBogus.FailedDxilPath);
42614269
}
42624270

4263-
// validate that m_dllExtSupport2 was able to capture the environment
4271+
// validate that ExtSupportBogus was able to capture the environment
42644272
// variable's value, and that loading the bogus path was unsuccessful
42654273
std::string BogusPath = ExtSupportBogus.getDxilDllPath();
42664274
VERIFY_ARE_EQUAL_STR(BogusPath.c_str(), "bogus");
42674275
VERIFY_IS_TRUE(ExtSupportBogus.dxilDllFailedToLoad());
42684276

4269-
// 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker,
4277+
// 3. Test with a valid path to this file in the environment variable
4278+
std::filesystem::path p = std::filesystem::absolute(__FILE__);
4279+
SetEnvVarW(L"DXC_DXIL_DLL_PATH", p.wstring());
4280+
4281+
if (!ExtSupportValidNonDLLPath.IsEnabled()) {
4282+
VERIFY_FAILED(ExtSupportValidNonDLLPath.initialize());
4283+
VERIFY_ARE_EQUAL(ExtSupportValidNonDLLPath.getFailureReason(),
4284+
ExtSupportValidNonDLLPath.FailedDxilLoad);
4285+
}
4286+
4287+
// validate that ExtSupportValidNonDLLPath was able to capture the environment
4288+
// variable's value, and that loading the valid non-dll path was unsuccessful
4289+
std::string ValidNonDLLPath = ExtSupportValidNonDLLPath.getDxilDllPath();
4290+
VERIFY_ARE_EQUAL_STR(ValidNonDLLPath.c_str(), __FILE__);
4291+
VERIFY_IS_TRUE(ExtSupportValidNonDLLPath.dxilDllFailedToLoad());
4292+
4293+
// 4. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker,
42704294
// and CLSID_DxcValidator through DxcDllExtValidationSupport.
42714295
CComPtr<IDxcCompiler> Compiler;
42724296
CComPtr<IDxcLinker> Linker;

0 commit comments

Comments
 (0)