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