Skip to content

Commit 77b2ff6

Browse files
NFC: remove dead external validation code paths from dxcompiler (#7451)
DXC has now been changed to use the internal validator (loaded by dxcompiler.dll) by default. This PR removes the ability for dxc.exe to load dxil.dll in preparation for a series of changes to fix external validation handling. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 77dcbb6 commit 77b2ff6

File tree

14 files changed

+39
-303
lines changed

14 files changed

+39
-303
lines changed

include/dxc/DxilContainer/DxcContainerBuilder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class DxcContainerBuilder : public IDxcContainerBuilder {
4545
return DoBasicQueryInterface<IDxcContainerBuilder>(this, riid, ppvObject);
4646
}
4747

48-
void Init(const char *warning = nullptr) {
49-
m_warning = warning;
48+
void Init() {
5049
m_RequireValidation = false;
5150
m_HasPrivateData = false;
5251
m_HashFunction = nullptr;
@@ -67,7 +66,6 @@ class DxcContainerBuilder : public IDxcContainerBuilder {
6766

6867
PartList m_parts;
6968
CComPtr<IDxcBlob> m_pContainer;
70-
const char *m_warning;
7169
bool m_RequireValidation;
7270
bool m_HasPrivateData;
7371
// Function to compute hash when valid dxil container is built

include/dxc/Support/HLSLOptions.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ struct RewriterOpts {
114114
bool DeclGlobalCB = false; // OPT_rw_decl_global_cb
115115
};
116116

117-
enum class ValidatorSelection : int {
118-
Auto, // Force internal validator (even if DXIL.dll is present)
119-
Internal, // Force internal validator (even if DXIL.dll is present)
120-
External, // Use DXIL.dll, failing compilation if not available
121-
Invalid = -1 // Invalid
122-
};
123-
124117
/// Use this class to capture all options.
125118
class DxcOpts {
126119
public:
@@ -225,8 +218,6 @@ class DxcOpts {
225218
bool ResMayAlias = false; // OPT_res_may_alias
226219
unsigned long ValVerMajor = UINT_MAX,
227220
ValVerMinor = UINT_MAX; // OPT_validator_version
228-
ValidatorSelection SelectValidator =
229-
ValidatorSelection::Auto; // OPT_select_validator
230221
unsigned ScanLimit = 0; // OPT_memdep_block_scan_limit
231222
bool ForceZeroStoreLifetimes = false; // OPT_force_zero_store_lifetimes
232223
bool EnableLifetimeMarkers = false; // OPT_enable_lifetime_markers

lib/DxilContainer/DxcContainerBuilder.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,14 @@ DxcContainerBuilder::SerializeContainer(IDxcOperationResult **ppResult) {
146146
// Combine existing warnings and errors from validation
147147
CComPtr<IDxcBlobEncoding> pErrorBlob;
148148
CDxcMallocHeapPtr<char> errorHeap(m_pMalloc);
149-
SIZE_T warningLength = m_warning ? strlen(m_warning) : 0;
150-
SIZE_T valErrorLength =
149+
SIZE_T totalErrorLength =
151150
pValErrorUtf8 ? pValErrorUtf8->GetStringLength() : 0;
152-
SIZE_T totalErrorLength = warningLength + valErrorLength;
153151
if (totalErrorLength) {
154152
SIZE_T errorSizeInBytes = totalErrorLength + 1;
155153
errorHeap.AllocateBytes(errorSizeInBytes);
156-
if (warningLength)
157-
memcpy(errorHeap.m_pData, m_warning, warningLength);
158-
if (valErrorLength)
159-
memcpy(errorHeap.m_pData + warningLength,
160-
pValErrorUtf8->GetStringPointer(), valErrorLength);
154+
155+
memcpy(errorHeap.m_pData, pValErrorUtf8->GetStringPointer(),
156+
totalErrorLength);
161157
errorHeap.m_pData[totalErrorLength] = L'\0';
162158
IFT(hlsl::DxcCreateBlobWithEncodingOnMalloc(errorHeap.m_pData, m_pMalloc,
163159
errorSizeInBytes, DXC_CP_UTF8,

tools/clang/tools/dxcompiler/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ set(SOURCES
5757
DXCompiler.rc
5858
DXCompiler.def
5959
dxcfilesystem.cpp
60-
dxillib.cpp
6160
dxcutil.cpp
6261
dxcdisassembler.cpp
6362
dxcpdbutils.cpp
@@ -75,7 +74,6 @@ set(SOURCES
7574
dxcutil.cpp
7675
dxcdisassembler.cpp
7776
dxcpdbutils.cpp
78-
dxillib.cpp
7977
dxcvalidator.cpp
8078
dxclinker.cpp
8179
dxcshadersourceinfo.cpp

tools/clang/tools/dxcompiler/DXCompiler.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifdef LLVM_ON_WIN32
2020
#include "dxcetw.h"
2121
#endif
22-
#include "dxillib.h"
2322

2423
namespace hlsl {
2524
HRESULT SetupRegistryPassForHLSL();
@@ -65,7 +64,6 @@ static HRESULT InitMaybeFail() throw() {
6564
fsSetup = true;
6665
IFC(hlsl::SetupRegistryPassForHLSL());
6766
IFC(hlsl::SetupRegistryPassForPIX());
68-
IFC(DxilLibInitialize());
6967
if (hlsl::options::initHlslOptTable()) {
7068
hr = E_FAIL;
7169
goto Cleanup;
@@ -110,12 +108,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID reserved) {
110108
::hlsl::options::cleanupHlslOptTable();
111109
::llvm::sys::fs::CleanupPerThreadFileSystem();
112110
::llvm::llvm_shutdown();
113-
if (reserved ==
114-
NULL) { // FreeLibrary has been called or the DLL load failed
115-
DxilLibCleanup(DxilLibCleanUpType::UnloadLibrary);
116-
} else { // Process termination. We should not call FreeLibrary()
117-
DxilLibCleanup(DxilLibCleanUpType::ProcessTermination);
118-
}
119111
DxcClearThreadMalloc();
120112
DxcCleanupThreadMalloc();
121113
DxcEtw_DXCompilerShutdown_Stop(S_OK);

tools/clang/tools/dxcompiler/dxcapi.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "dxcetw.h"
2626
#endif
2727
#include "dxc/DxilContainer/DxcContainerBuilder.h"
28-
#include "dxillib.h"
2928
#include <memory>
3029

3130
HRESULT CreateDxcCompiler(REFIID riid, _Out_ LPVOID *ppv);
@@ -59,20 +58,11 @@ HRESULT CreateDxcContainerReflection(REFIID riid, _Out_ LPVOID *ppv) {
5958
HRESULT CreateDxcContainerBuilder(REFIID riid, _Out_ LPVOID *ppv) {
6059
// Call dxil.dll's containerbuilder
6160
*ppv = nullptr;
62-
const char *warning;
63-
HRESULT hr = DxilLibCreateInstance(CLSID_DxcContainerBuilder,
64-
(IDxcContainerBuilder **)ppv);
65-
if (FAILED(hr)) {
66-
warning = "Unable to create container builder from dxil.dll. Resulting "
67-
"container will not be signed.\n";
68-
} else {
69-
return hr;
70-
}
7161

7262
CComPtr<DxcContainerBuilder> Result =
7363
DxcContainerBuilder::Alloc(DxcGetThreadMallocNoRef());
7464
IFROOM(Result.p);
75-
Result->Init(warning);
65+
Result->Init();
7666
return Result->QueryInterface(riid, ppv);
7767
}
7868

tools/clang/tools/dxcompiler/dxcassembler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "dxc/Support/dxcfilesystem.h"
2020
#include "dxc/Support/microcom.h"
2121
#include "dxcutil.h"
22-
#include "dxillib.h"
2322

2423
#include "llvm/Bitcode/ReaderWriter.h"
2524
#include "llvm/IR/LLVMContext.h"

tools/clang/tools/dxcompiler/dxclinker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "dxc/Support/dxcapi.impl.h"
1919
#include "dxc/Support/microcom.h"
2020
#include "dxc/dxcapi.h"
21-
#include "dxillib.h"
2221

2322
#include "llvm/ADT/SmallVector.h"
2423
#include <algorithm>

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include "dxcompileradapter.h"
5757
#include "dxcshadersourceinfo.h"
5858
#include "dxcversion.inc"
59-
#include "dxillib.h"
6059
#include <algorithm>
6160
#include <cfloat>
6261

@@ -850,11 +849,9 @@ class DxcCompiler : public IDxcCompiler3,
850849
compiler.getCodeGenOpts().HLSLValidatorMajorVer = opts.ValVerMajor;
851850
compiler.getCodeGenOpts().HLSLValidatorMinorVer = opts.ValVerMinor;
852851
} else {
853-
// Version from dxil.dll, or internal validator if unavailable
854852
dxcutil::GetValidatorVersion(
855853
&compiler.getCodeGenOpts().HLSLValidatorMajorVer,
856-
&compiler.getCodeGenOpts().HLSLValidatorMinorVer,
857-
opts.SelectValidator);
854+
&compiler.getCodeGenOpts().HLSLValidatorMinorVer);
858855
}
859856

860857
// Root signature-only container validation is only supported on 1.5 and
@@ -934,7 +931,7 @@ class DxcCompiler : public IDxcCompiler3,
934931
CComPtr<IDxcBlobEncoding> pValErrors;
935932
// Validation failure communicated through diagnostic error
936933
dxcutil::ValidateRootSignatureInContainer(
937-
pOutputBlob, &compiler.getDiagnostics(), opts.SelectValidator);
934+
pOutputBlob, &compiler.getDiagnostics());
938935
}
939936
}
940937
} else if (opts.VerifyDiagnostics) {
@@ -1054,8 +1051,7 @@ class DxcCompiler : public IDxcCompiler3,
10541051
std::move(serializeModule), pOutputBlob, m_pMalloc,
10551052
SerializeFlags, pOutputStream, 0, opts.GetPDBName(),
10561053
&compiler.getDiagnostics(), &ShaderHashContent, pReflectionStream,
1057-
pRootSigStream, pRootSignatureBlob, pPrivateBlob,
1058-
opts.SelectValidator);
1054+
pRootSigStream, pRootSignatureBlob, pPrivateBlob);
10591055

10601056
inputs.pVersionInfo = static_cast<IDxcVersionInfo *>(this);
10611057

@@ -1108,8 +1104,7 @@ class DxcCompiler : public IDxcCompiler3,
11081104
CComPtr<IDxcBlobEncoding> pValErrors;
11091105
// Validation failure communicated through diagnostic error
11101106
dxcutil::ValidateRootSignatureInContainer(
1111-
pRootSignature, &compiler.getDiagnostics(),
1112-
opts.SelectValidator);
1107+
pRootSignature, &compiler.getDiagnostics());
11131108
}
11141109
IFT(pResult->SetOutputObject(DXC_OUT_ROOT_SIGNATURE,
11151110
pRootSignature));
@@ -1324,13 +1319,6 @@ class DxcCompiler : public IDxcCompiler3,
13241319
CComPtr<IDxcResult> pResult;
13251320
hr = e.hr;
13261321
std::string msg("Internal Compiler error: ");
1327-
switch (hr) {
1328-
case DXC_E_VALIDATOR_MISSING:
1329-
msg = "Error: external validator selected, but DXIL.dll not found.";
1330-
break;
1331-
default:
1332-
break;
1333-
}
13341322
msg += e.msg;
13351323
if (SUCCEEDED(DxcResult::Create(
13361324
e.hr, DXC_OUT_NONE,

tools/clang/tools/dxcompiler/dxcutil.cpp

Lines changed: 15 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "dxc/Support/WinIncludes.h"
2020
#include "dxc/Support/dxcapi.impl.h"
2121
#include "dxc/dxcapi.h"
22-
#include "dxillib.h"
2322
#include "clang/Basic/Diagnostic.h"
2423
#include "llvm/Bitcode/ReaderWriter.h"
2524
#include "llvm/IR/DebugInfo.h"
@@ -50,32 +49,8 @@ namespace {
5049
// AssembleToContainer helper functions.
5150

5251
// return true if the internal validator was used, false otherwise
53-
bool CreateValidator(CComPtr<IDxcValidator> &pValidator,
54-
hlsl::options::ValidatorSelection SelectValidator =
55-
hlsl::options::ValidatorSelection::Auto) {
56-
bool bInternal =
57-
SelectValidator == hlsl::options::ValidatorSelection::Internal;
58-
bool bExternal =
59-
SelectValidator == hlsl::options::ValidatorSelection::External;
60-
bool bAuto = SelectValidator == hlsl::options::ValidatorSelection::Auto;
61-
62-
// default behavior uses internal validator, as well as
63-
// explicitly specifying internal
64-
if (bInternal || bAuto) {
65-
IFT(CreateDxcValidator(IID_PPV_ARGS(&pValidator)));
66-
return true;
67-
}
68-
69-
if (bExternal) {
70-
// if external was explicitly specified, but no
71-
// external validator could be found (no DXIL.dll), then error
72-
IFTBOOL(DxilLibIsEnabled(), DXC_E_VALIDATOR_MISSING);
73-
IFT(DxilLibCreateInstance(CLSID_DxcValidator, &pValidator));
74-
75-
return false;
76-
}
77-
78-
return false;
52+
void CreateValidator(CComPtr<IDxcValidator> &pValidator) {
53+
IFT(CreateDxcValidator(IID_PPV_ARGS(&pValidator)));
7954
}
8055

8156
} // namespace
@@ -89,23 +64,20 @@ AssembleInputs::AssembleInputs(
8964
uint32_t ValidationFlags, llvm::StringRef DebugName,
9065
clang::DiagnosticsEngine *pDiag, hlsl::DxilShaderHash *pShaderHashOut,
9166
AbstractMemoryStream *pReflectionOut, AbstractMemoryStream *pRootSigOut,
92-
CComPtr<IDxcBlob> pRootSigBlob, CComPtr<IDxcBlob> pPrivateBlob,
93-
hlsl::options::ValidatorSelection SelectValidator)
67+
CComPtr<IDxcBlob> pRootSigBlob, CComPtr<IDxcBlob> pPrivateBlob)
9468
: pM(std::move(pM)), pOutputContainerBlob(pOutputContainerBlob),
9569
pMalloc(pMalloc), SerializeFlags(SerializeFlags),
9670
ValidationFlags(ValidationFlags), pModuleBitcode(pModuleBitcode),
9771
DebugName(DebugName), pDiag(pDiag), pShaderHashOut(pShaderHashOut),
9872
pReflectionOut(pReflectionOut), pRootSigOut(pRootSigOut),
99-
pRootSigBlob(pRootSigBlob), pPrivateBlob(pPrivateBlob),
100-
SelectValidator(SelectValidator) {}
73+
pRootSigBlob(pRootSigBlob), pPrivateBlob(pPrivateBlob) {}
10174

102-
void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor,
103-
hlsl::options::ValidatorSelection SelectValidator) {
75+
void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor) {
10476
if (pMajor == nullptr || pMinor == nullptr)
10577
return;
10678

10779
CComPtr<IDxcValidator> pValidator;
108-
CreateValidator(pValidator, SelectValidator);
80+
CreateValidator(pValidator);
10981

11082
CComPtr<IDxcVersionInfo> pVersionInfo;
11183
if (SUCCEEDED(pValidator.QueryInterface(&pVersionInfo))) {
@@ -177,76 +149,19 @@ HRESULT ValidateAndAssembleToContainer(AssembleInputs &inputs) {
177149
std::unique_ptr<llvm::Module> llvmModuleWithDebugInfo;
178150

179151
CComPtr<IDxcValidator> pValidator;
180-
bool bInternalValidator = CreateValidator(pValidator, inputs.SelectValidator);
181-
// Warning on internal Validator
182-
183-
CComPtr<IDxcValidator2> pValidator2;
184-
if (!bInternalValidator) {
185-
pValidator.QueryInterface(&pValidator2);
186-
}
187-
188-
if (bInternalValidator || pValidator2) {
189-
// If using the internal validator or external validator supports
190-
// IDxcValidator2, we'll use the modules directly. In this case, we'll want
191-
// to make a clone to avoid SerializeDxilContainerForModule stripping all
192-
// the debug info. The debug info will be stripped from the orginal module,
193-
// but preserved in the cloned module.
194-
if (llvm::getDebugMetadataVersionFromModule(*inputs.pM) != 0) {
195-
llvmModuleWithDebugInfo.reset(llvm::CloneModule(inputs.pM.get()));
196-
}
197-
}
152+
CreateValidator(pValidator);
198153

199-
// Verify validator version can validate this module
200-
CComPtr<IDxcVersionInfo> pValidatorVersion;
201-
IFT(pValidator->QueryInterface(&pValidatorVersion));
202-
UINT32 ValMajor, ValMinor;
203-
IFT(pValidatorVersion->GetVersion(&ValMajor, &ValMinor));
204-
DxilModule &DM = inputs.pM.get()->GetOrCreateDxilModule();
205-
unsigned ReqValMajor, ReqValMinor;
206-
DM.GetValidatorVersion(ReqValMajor, ReqValMinor);
207-
if (DXIL::CompareVersions(ValMajor, ValMinor, ReqValMajor, ReqValMinor) < 0) {
208-
// Module is expecting to be validated by a newer validator.
209-
if (inputs.pDiag) {
210-
unsigned diagID = inputs.pDiag->getCustomDiagID(
211-
clang::DiagnosticsEngine::Level::Error,
212-
"The module cannot be validated by the version of the validator "
213-
"currently attached.");
214-
inputs.pDiag->Report(diagID);
215-
}
216-
return E_FAIL;
217-
}
154+
if (llvm::getDebugMetadataVersionFromModule(*inputs.pM) != 0)
155+
llvmModuleWithDebugInfo.reset(llvm::CloneModule(inputs.pM.get()));
218156

219157
AssembleToContainer(inputs);
220158

221159
CComPtr<IDxcOperationResult> pValResult;
222-
// Important: in-place edit is required so the blob is reused and thus
223-
// dxil.dll can be released.
160+
// In-place edit to avoid an extra copy
224161
inputs.ValidationFlags |= DxcValidatorFlags_InPlaceEdit;
225-
if (bInternalValidator) {
226-
IFT(RunInternalValidator(pValidator, llvmModuleWithDebugInfo.get(),
227-
inputs.pOutputContainerBlob,
228-
inputs.ValidationFlags, &pValResult));
229-
} else {
230-
if (pValidator2 && llvmModuleWithDebugInfo) {
231-
// If metadata was stripped, re-serialize the input module.
232-
CComPtr<AbstractMemoryStream> pDebugModuleStream;
233-
IFT(CreateMemoryStream(DxcGetThreadMallocNoRef(), &pDebugModuleStream));
234-
raw_stream_ostream outStream(pDebugModuleStream.p);
235-
WriteBitcodeToFile(llvmModuleWithDebugInfo.get(), outStream, true);
236-
outStream.flush();
237-
238-
DxcBuffer debugModule = {};
239-
debugModule.Ptr = pDebugModuleStream->GetPtr();
240-
debugModule.Size = pDebugModuleStream->GetPtrSize();
241-
242-
IFT(pValidator2->ValidateWithDebug(inputs.pOutputContainerBlob,
243-
inputs.ValidationFlags, &debugModule,
244-
&pValResult));
245-
} else {
246-
IFT(pValidator->Validate(inputs.pOutputContainerBlob,
247-
inputs.ValidationFlags, &pValResult));
248-
}
249-
}
162+
IFT(RunInternalValidator(pValidator, llvmModuleWithDebugInfo.get(),
163+
inputs.pOutputContainerBlob, inputs.ValidationFlags,
164+
&pValResult));
250165
IFT(pValResult->GetStatus(&valHR));
251166
if (inputs.pDiag) {
252167
if (FAILED(valHR)) {
@@ -271,9 +186,8 @@ HRESULT ValidateAndAssembleToContainer(AssembleInputs &inputs) {
271186
return valHR;
272187
}
273188

274-
HRESULT ValidateRootSignatureInContainer(
275-
IDxcBlob *pRootSigContainer, clang::DiagnosticsEngine *pDiag,
276-
hlsl::options::ValidatorSelection SelectValidator) {
189+
HRESULT ValidateRootSignatureInContainer(IDxcBlob *pRootSigContainer,
190+
clang::DiagnosticsEngine *pDiag) {
277191
HRESULT valHR = S_OK;
278192
CComPtr<IDxcValidator> pValidator;
279193
CComPtr<IDxcOperationResult> pValResult;

0 commit comments

Comments
 (0)