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
4 changes: 1 addition & 3 deletions include/dxc/DxilContainer/DxcContainerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class DxcContainerBuilder : public IDxcContainerBuilder {
return DoBasicQueryInterface<IDxcContainerBuilder>(this, riid, ppvObject);
}

void Init(const char *warning = nullptr) {
m_warning = warning;
void Init() {
m_RequireValidation = false;
m_HasPrivateData = false;
m_HashFunction = nullptr;
Expand All @@ -67,7 +66,6 @@ class DxcContainerBuilder : public IDxcContainerBuilder {

PartList m_parts;
CComPtr<IDxcBlob> m_pContainer;
const char *m_warning;
bool m_RequireValidation;
bool m_HasPrivateData;
// Function to compute hash when valid dxil container is built
Expand Down
9 changes: 0 additions & 9 deletions include/dxc/Support/HLSLOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ struct RewriterOpts {
bool DeclGlobalCB = false; // OPT_rw_decl_global_cb
};

enum class ValidatorSelection : int {
Auto, // Force internal validator (even if DXIL.dll is present)
Internal, // Force internal validator (even if DXIL.dll is present)
External, // Use DXIL.dll, failing compilation if not available
Invalid = -1 // Invalid
};

/// Use this class to capture all options.
class DxcOpts {
public:
Expand Down Expand Up @@ -225,8 +218,6 @@ class DxcOpts {
bool ResMayAlias = false; // OPT_res_may_alias
unsigned long ValVerMajor = UINT_MAX,
ValVerMinor = UINT_MAX; // OPT_validator_version
ValidatorSelection SelectValidator =
ValidatorSelection::Auto; // OPT_select_validator
unsigned ScanLimit = 0; // OPT_memdep_block_scan_limit
bool ForceZeroStoreLifetimes = false; // OPT_force_zero_store_lifetimes
bool EnableLifetimeMarkers = false; // OPT_enable_lifetime_markers
Expand Down
12 changes: 4 additions & 8 deletions lib/DxilContainer/DxcContainerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,14 @@ DxcContainerBuilder::SerializeContainer(IDxcOperationResult **ppResult) {
// Combine existing warnings and errors from validation
CComPtr<IDxcBlobEncoding> pErrorBlob;
CDxcMallocHeapPtr<char> errorHeap(m_pMalloc);
SIZE_T warningLength = m_warning ? strlen(m_warning) : 0;
SIZE_T valErrorLength =
SIZE_T totalErrorLength =
pValErrorUtf8 ? pValErrorUtf8->GetStringLength() : 0;
SIZE_T totalErrorLength = warningLength + valErrorLength;
if (totalErrorLength) {
SIZE_T errorSizeInBytes = totalErrorLength + 1;
errorHeap.AllocateBytes(errorSizeInBytes);
if (warningLength)
memcpy(errorHeap.m_pData, m_warning, warningLength);
if (valErrorLength)
memcpy(errorHeap.m_pData + warningLength,
pValErrorUtf8->GetStringPointer(), valErrorLength);

memcpy(errorHeap.m_pData, pValErrorUtf8->GetStringPointer(),
totalErrorLength);
errorHeap.m_pData[totalErrorLength] = L'\0';
IFT(hlsl::DxcCreateBlobWithEncodingOnMalloc(errorHeap.m_pData, m_pMalloc,
errorSizeInBytes, DXC_CP_UTF8,
Expand Down
2 changes: 0 additions & 2 deletions tools/clang/tools/dxcompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ set(SOURCES
DXCompiler.rc
DXCompiler.def
dxcfilesystem.cpp
dxillib.cpp
dxcutil.cpp
dxcdisassembler.cpp
dxcpdbutils.cpp
Expand All @@ -75,7 +74,6 @@ set(SOURCES
dxcutil.cpp
dxcdisassembler.cpp
dxcpdbutils.cpp
dxillib.cpp
dxcvalidator.cpp
dxclinker.cpp
dxcshadersourceinfo.cpp
Expand Down
8 changes: 0 additions & 8 deletions tools/clang/tools/dxcompiler/DXCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifdef LLVM_ON_WIN32
#include "dxcetw.h"
#endif
#include "dxillib.h"

namespace hlsl {
HRESULT SetupRegistryPassForHLSL();
Expand Down Expand Up @@ -65,7 +64,6 @@ static HRESULT InitMaybeFail() throw() {
fsSetup = true;
IFC(hlsl::SetupRegistryPassForHLSL());
IFC(hlsl::SetupRegistryPassForPIX());
IFC(DxilLibInitialize());
if (hlsl::options::initHlslOptTable()) {
hr = E_FAIL;
goto Cleanup;
Expand Down Expand Up @@ -110,12 +108,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID reserved) {
::hlsl::options::cleanupHlslOptTable();
::llvm::sys::fs::CleanupPerThreadFileSystem();
::llvm::llvm_shutdown();
if (reserved ==
NULL) { // FreeLibrary has been called or the DLL load failed
DxilLibCleanup(DxilLibCleanUpType::UnloadLibrary);
} else { // Process termination. We should not call FreeLibrary()
DxilLibCleanup(DxilLibCleanUpType::ProcessTermination);
}
DxcClearThreadMalloc();
DxcCleanupThreadMalloc();
DxcEtw_DXCompilerShutdown_Stop(S_OK);
Expand Down
12 changes: 1 addition & 11 deletions tools/clang/tools/dxcompiler/dxcapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "dxcetw.h"
#endif
#include "dxc/DxilContainer/DxcContainerBuilder.h"
#include "dxillib.h"
#include <memory>

HRESULT CreateDxcCompiler(REFIID riid, _Out_ LPVOID *ppv);
Expand Down Expand Up @@ -59,20 +58,11 @@ HRESULT CreateDxcContainerReflection(REFIID riid, _Out_ LPVOID *ppv) {
HRESULT CreateDxcContainerBuilder(REFIID riid, _Out_ LPVOID *ppv) {
// Call dxil.dll's containerbuilder
*ppv = nullptr;
const char *warning;
HRESULT hr = DxilLibCreateInstance(CLSID_DxcContainerBuilder,
(IDxcContainerBuilder **)ppv);
if (FAILED(hr)) {
warning = "Unable to create container builder from dxil.dll. Resulting "
"container will not be signed.\n";
} else {
return hr;
}

CComPtr<DxcContainerBuilder> Result =
DxcContainerBuilder::Alloc(DxcGetThreadMallocNoRef());
IFROOM(Result.p);
Result->Init(warning);
Result->Init();
return Result->QueryInterface(riid, ppv);
}

Expand Down
1 change: 0 additions & 1 deletion tools/clang/tools/dxcompiler/dxcassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "dxc/Support/dxcfilesystem.h"
#include "dxc/Support/microcom.h"
#include "dxcutil.h"
#include "dxillib.h"

#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LLVMContext.h"
Expand Down
1 change: 0 additions & 1 deletion tools/clang/tools/dxcompiler/dxclinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "dxc/Support/dxcapi.impl.h"
#include "dxc/Support/microcom.h"
#include "dxc/dxcapi.h"
#include "dxillib.h"

#include "llvm/ADT/SmallVector.h"
#include <algorithm>
Expand Down
20 changes: 4 additions & 16 deletions tools/clang/tools/dxcompiler/dxcompilerobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include "dxcompileradapter.h"
#include "dxcshadersourceinfo.h"
#include "dxcversion.inc"
#include "dxillib.h"
#include <algorithm>
#include <cfloat>

Expand Down Expand Up @@ -850,11 +849,9 @@ class DxcCompiler : public IDxcCompiler3,
compiler.getCodeGenOpts().HLSLValidatorMajorVer = opts.ValVerMajor;
compiler.getCodeGenOpts().HLSLValidatorMinorVer = opts.ValVerMinor;
} else {
// Version from dxil.dll, or internal validator if unavailable
dxcutil::GetValidatorVersion(
&compiler.getCodeGenOpts().HLSLValidatorMajorVer,
&compiler.getCodeGenOpts().HLSLValidatorMinorVer,
opts.SelectValidator);
&compiler.getCodeGenOpts().HLSLValidatorMinorVer);
}

// Root signature-only container validation is only supported on 1.5 and
Expand Down Expand Up @@ -934,7 +931,7 @@ class DxcCompiler : public IDxcCompiler3,
CComPtr<IDxcBlobEncoding> pValErrors;
// Validation failure communicated through diagnostic error
dxcutil::ValidateRootSignatureInContainer(
pOutputBlob, &compiler.getDiagnostics(), opts.SelectValidator);
pOutputBlob, &compiler.getDiagnostics());
}
}
} else if (opts.VerifyDiagnostics) {
Expand Down Expand Up @@ -1054,8 +1051,7 @@ class DxcCompiler : public IDxcCompiler3,
std::move(serializeModule), pOutputBlob, m_pMalloc,
SerializeFlags, pOutputStream, 0, opts.GetPDBName(),
&compiler.getDiagnostics(), &ShaderHashContent, pReflectionStream,
pRootSigStream, pRootSignatureBlob, pPrivateBlob,
opts.SelectValidator);
pRootSigStream, pRootSignatureBlob, pPrivateBlob);

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

Expand Down Expand Up @@ -1108,8 +1104,7 @@ class DxcCompiler : public IDxcCompiler3,
CComPtr<IDxcBlobEncoding> pValErrors;
// Validation failure communicated through diagnostic error
dxcutil::ValidateRootSignatureInContainer(
pRootSignature, &compiler.getDiagnostics(),
opts.SelectValidator);
pRootSignature, &compiler.getDiagnostics());
}
IFT(pResult->SetOutputObject(DXC_OUT_ROOT_SIGNATURE,
pRootSignature));
Expand Down Expand Up @@ -1324,13 +1319,6 @@ class DxcCompiler : public IDxcCompiler3,
CComPtr<IDxcResult> pResult;
hr = e.hr;
std::string msg("Internal Compiler error: ");
switch (hr) {
case DXC_E_VALIDATOR_MISSING:
msg = "Error: external validator selected, but DXIL.dll not found.";
break;
default:
break;
}
msg += e.msg;
if (SUCCEEDED(DxcResult::Create(
e.hr, DXC_OUT_NONE,
Expand Down
116 changes: 15 additions & 101 deletions tools/clang/tools/dxcompiler/dxcutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "dxc/Support/WinIncludes.h"
#include "dxc/Support/dxcapi.impl.h"
#include "dxc/dxcapi.h"
#include "dxillib.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/DebugInfo.h"
Expand Down Expand Up @@ -50,32 +49,8 @@ namespace {
// AssembleToContainer helper functions.

// return true if the internal validator was used, false otherwise
bool CreateValidator(CComPtr<IDxcValidator> &pValidator,
hlsl::options::ValidatorSelection SelectValidator =
hlsl::options::ValidatorSelection::Auto) {
bool bInternal =
SelectValidator == hlsl::options::ValidatorSelection::Internal;
bool bExternal =
SelectValidator == hlsl::options::ValidatorSelection::External;
bool bAuto = SelectValidator == hlsl::options::ValidatorSelection::Auto;

// default behavior uses internal validator, as well as
// explicitly specifying internal
if (bInternal || bAuto) {
IFT(CreateDxcValidator(IID_PPV_ARGS(&pValidator)));
return true;
}

if (bExternal) {
// if external was explicitly specified, but no
// external validator could be found (no DXIL.dll), then error
IFTBOOL(DxilLibIsEnabled(), DXC_E_VALIDATOR_MISSING);
IFT(DxilLibCreateInstance(CLSID_DxcValidator, &pValidator));

return false;
}

return false;
void CreateValidator(CComPtr<IDxcValidator> &pValidator) {
IFT(CreateDxcValidator(IID_PPV_ARGS(&pValidator)));
}

} // namespace
Expand All @@ -89,23 +64,20 @@ AssembleInputs::AssembleInputs(
uint32_t ValidationFlags, llvm::StringRef DebugName,
clang::DiagnosticsEngine *pDiag, hlsl::DxilShaderHash *pShaderHashOut,
AbstractMemoryStream *pReflectionOut, AbstractMemoryStream *pRootSigOut,
CComPtr<IDxcBlob> pRootSigBlob, CComPtr<IDxcBlob> pPrivateBlob,
hlsl::options::ValidatorSelection SelectValidator)
CComPtr<IDxcBlob> pRootSigBlob, CComPtr<IDxcBlob> pPrivateBlob)
: pM(std::move(pM)), pOutputContainerBlob(pOutputContainerBlob),
pMalloc(pMalloc), SerializeFlags(SerializeFlags),
ValidationFlags(ValidationFlags), pModuleBitcode(pModuleBitcode),
DebugName(DebugName), pDiag(pDiag), pShaderHashOut(pShaderHashOut),
pReflectionOut(pReflectionOut), pRootSigOut(pRootSigOut),
pRootSigBlob(pRootSigBlob), pPrivateBlob(pPrivateBlob),
SelectValidator(SelectValidator) {}
pRootSigBlob(pRootSigBlob), pPrivateBlob(pPrivateBlob) {}

void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor,
hlsl::options::ValidatorSelection SelectValidator) {
void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor) {
if (pMajor == nullptr || pMinor == nullptr)
return;

CComPtr<IDxcValidator> pValidator;
CreateValidator(pValidator, SelectValidator);
CreateValidator(pValidator);

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

CComPtr<IDxcValidator> pValidator;
bool bInternalValidator = CreateValidator(pValidator, inputs.SelectValidator);
// Warning on internal Validator

CComPtr<IDxcValidator2> pValidator2;
if (!bInternalValidator) {
pValidator.QueryInterface(&pValidator2);
}

if (bInternalValidator || pValidator2) {
// If using the internal validator or external validator supports
// IDxcValidator2, we'll use the modules directly. In this case, we'll want
// to make a clone to avoid SerializeDxilContainerForModule stripping all
// the debug info. The debug info will be stripped from the orginal module,
// but preserved in the cloned module.
if (llvm::getDebugMetadataVersionFromModule(*inputs.pM) != 0) {
llvmModuleWithDebugInfo.reset(llvm::CloneModule(inputs.pM.get()));
}
}
CreateValidator(pValidator);

// Verify validator version can validate this module
CComPtr<IDxcVersionInfo> pValidatorVersion;
IFT(pValidator->QueryInterface(&pValidatorVersion));
UINT32 ValMajor, ValMinor;
IFT(pValidatorVersion->GetVersion(&ValMajor, &ValMinor));
DxilModule &DM = inputs.pM.get()->GetOrCreateDxilModule();
unsigned ReqValMajor, ReqValMinor;
DM.GetValidatorVersion(ReqValMajor, ReqValMinor);
if (DXIL::CompareVersions(ValMajor, ValMinor, ReqValMajor, ReqValMinor) < 0) {
// Module is expecting to be validated by a newer validator.
if (inputs.pDiag) {
unsigned diagID = inputs.pDiag->getCustomDiagID(
clang::DiagnosticsEngine::Level::Error,
"The module cannot be validated by the version of the validator "
"currently attached.");
inputs.pDiag->Report(diagID);
}
return E_FAIL;
}
if (llvm::getDebugMetadataVersionFromModule(*inputs.pM) != 0)
llvmModuleWithDebugInfo.reset(llvm::CloneModule(inputs.pM.get()));

AssembleToContainer(inputs);

CComPtr<IDxcOperationResult> pValResult;
// Important: in-place edit is required so the blob is reused and thus
// dxil.dll can be released.
// In-place edit to avoid an extra copy
inputs.ValidationFlags |= DxcValidatorFlags_InPlaceEdit;
if (bInternalValidator) {
IFT(RunInternalValidator(pValidator, llvmModuleWithDebugInfo.get(),
inputs.pOutputContainerBlob,
inputs.ValidationFlags, &pValResult));
} else {
if (pValidator2 && llvmModuleWithDebugInfo) {
// If metadata was stripped, re-serialize the input module.
CComPtr<AbstractMemoryStream> pDebugModuleStream;
IFT(CreateMemoryStream(DxcGetThreadMallocNoRef(), &pDebugModuleStream));
raw_stream_ostream outStream(pDebugModuleStream.p);
WriteBitcodeToFile(llvmModuleWithDebugInfo.get(), outStream, true);
outStream.flush();

DxcBuffer debugModule = {};
debugModule.Ptr = pDebugModuleStream->GetPtr();
debugModule.Size = pDebugModuleStream->GetPtrSize();

IFT(pValidator2->ValidateWithDebug(inputs.pOutputContainerBlob,
inputs.ValidationFlags, &debugModule,
&pValResult));
} else {
IFT(pValidator->Validate(inputs.pOutputContainerBlob,
inputs.ValidationFlags, &pValResult));
}
}
IFT(RunInternalValidator(pValidator, llvmModuleWithDebugInfo.get(),
inputs.pOutputContainerBlob, inputs.ValidationFlags,
&pValResult));
IFT(pValResult->GetStatus(&valHR));
if (inputs.pDiag) {
if (FAILED(valHR)) {
Expand All @@ -271,9 +186,8 @@ HRESULT ValidateAndAssembleToContainer(AssembleInputs &inputs) {
return valHR;
}

HRESULT ValidateRootSignatureInContainer(
IDxcBlob *pRootSigContainer, clang::DiagnosticsEngine *pDiag,
hlsl::options::ValidatorSelection SelectValidator) {
HRESULT ValidateRootSignatureInContainer(IDxcBlob *pRootSigContainer,
clang::DiagnosticsEngine *pDiag) {
HRESULT valHR = S_OK;
CComPtr<IDxcValidator> pValidator;
CComPtr<IDxcOperationResult> pValResult;
Expand Down
Loading