|
@@ -252,39 +252,6 @@ const char *hlsl::GetValidationRuleText(ValidationRule value) {
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
|
-class PrintDiagnosticContext {
|
|
|
|
-private:
|
|
|
|
- DiagnosticPrinter &m_Printer;
|
|
|
|
- bool m_errorsFound;
|
|
|
|
- bool m_warningsFound;
|
|
|
|
-public:
|
|
|
|
- PrintDiagnosticContext(DiagnosticPrinter &printer)
|
|
|
|
- : m_Printer(printer), m_errorsFound(false), m_warningsFound(false) {}
|
|
|
|
-
|
|
|
|
- bool HasErrors() const {
|
|
|
|
- return m_errorsFound;
|
|
|
|
- }
|
|
|
|
- bool HasWarnings() const {
|
|
|
|
- return m_warningsFound;
|
|
|
|
- }
|
|
|
|
- void Handle(const DiagnosticInfo &DI) {
|
|
|
|
- DI.print(m_Printer);
|
|
|
|
- switch (DI.getSeverity()) {
|
|
|
|
- case llvm::DiagnosticSeverity::DS_Error:
|
|
|
|
- m_errorsFound = true;
|
|
|
|
- break;
|
|
|
|
- case llvm::DiagnosticSeverity::DS_Warning:
|
|
|
|
- m_warningsFound = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- m_Printer << "\n";
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-static void PrintDiagnosticHandler(const DiagnosticInfo &DI, void *Context) {
|
|
|
|
- reinterpret_cast<PrintDiagnosticContext *>(Context)->Handle(DI);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// Utility class for setting and restoring the diagnostic context so we may capture errors/warnings
|
|
// Utility class for setting and restoring the diagnostic context so we may capture errors/warnings
|
|
struct DiagRestore {
|
|
struct DiagRestore {
|
|
LLVMContext &Ctx;
|
|
LLVMContext &Ctx;
|
|
@@ -294,7 +261,8 @@ struct DiagRestore {
|
|
DiagRestore(llvm::LLVMContext &Ctx, void *DiagContext) : Ctx(Ctx) {
|
|
DiagRestore(llvm::LLVMContext &Ctx, void *DiagContext) : Ctx(Ctx) {
|
|
OrigHandler = Ctx.getDiagnosticHandler();
|
|
OrigHandler = Ctx.getDiagnosticHandler();
|
|
OrigDiagContext = Ctx.getDiagnosticContext();
|
|
OrigDiagContext = Ctx.getDiagnosticContext();
|
|
- Ctx.setDiagnosticHandler(PrintDiagnosticHandler, DiagContext);
|
|
|
|
|
|
+ Ctx.setDiagnosticHandler(
|
|
|
|
+ hlsl::PrintDiagnosticContext::PrintDiagnosticHandler, DiagContext);
|
|
}
|
|
}
|
|
~DiagRestore() {
|
|
~DiagRestore() {
|
|
Ctx.setDiagnosticHandler(OrigHandler, OrigDiagContext);
|
|
Ctx.setDiagnosticHandler(OrigHandler, OrigDiagContext);
|
|
@@ -333,6 +301,29 @@ static inline DiagnosticPrinter &operator<<(DiagnosticPrinter &OS, Type &T) {
|
|
|
|
|
|
namespace hlsl {
|
|
namespace hlsl {
|
|
|
|
|
|
|
|
+// PrintDiagnosticContext methods.
|
|
|
|
+PrintDiagnosticContext::PrintDiagnosticContext(DiagnosticPrinter &printer)
|
|
|
|
+ : m_Printer(printer), m_errorsFound(false), m_warningsFound(false) {}
|
|
|
|
+
|
|
|
|
+bool PrintDiagnosticContext::HasErrors() const { return m_errorsFound; }
|
|
|
|
+bool PrintDiagnosticContext::HasWarnings() const { return m_warningsFound; }
|
|
|
|
+void PrintDiagnosticContext::Handle(const DiagnosticInfo &DI) {
|
|
|
|
+ DI.print(m_Printer);
|
|
|
|
+ switch (DI.getSeverity()) {
|
|
|
|
+ case llvm::DiagnosticSeverity::DS_Error:
|
|
|
|
+ m_errorsFound = true;
|
|
|
|
+ break;
|
|
|
|
+ case llvm::DiagnosticSeverity::DS_Warning:
|
|
|
|
+ m_warningsFound = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ m_Printer << "\n";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void PrintDiagnosticContext::PrintDiagnosticHandler(const DiagnosticInfo &DI, void *Context) {
|
|
|
|
+ reinterpret_cast<hlsl::PrintDiagnosticContext *>(Context)->Handle(DI);
|
|
|
|
+}
|
|
|
|
+
|
|
struct PSExecutionInfo {
|
|
struct PSExecutionInfo {
|
|
bool SuperSampling = false;
|
|
bool SuperSampling = false;
|
|
DXIL::SemanticKind OutputDepthKind = DXIL::SemanticKind::Invalid;
|
|
DXIL::SemanticKind OutputDepthKind = DXIL::SemanticKind::Invalid;
|
|
@@ -4499,7 +4490,8 @@ HRESULT ValidateDxilBitcode(
|
|
|
|
|
|
llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream);
|
|
llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream);
|
|
PrintDiagnosticContext DiagContext(DiagPrinter);
|
|
PrintDiagnosticContext DiagContext(DiagPrinter);
|
|
- Ctx.setDiagnosticHandler(PrintDiagnosticHandler, &DiagContext, true);
|
|
|
|
|
|
+ Ctx.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler,
|
|
|
|
+ &DiagContext, true);
|
|
|
|
|
|
HRESULT hr;
|
|
HRESULT hr;
|
|
if (FAILED(hr = ValidateLoadModule(pIL, ILLength, pModule, Ctx, DiagStream)))
|
|
if (FAILED(hr = ValidateLoadModule(pIL, ILLength, pModule, Ctx, DiagStream)))
|
|
@@ -4545,45 +4537,66 @@ HRESULT ValidateDxilBitcode(
|
|
}
|
|
}
|
|
|
|
|
|
_Use_decl_annotations_
|
|
_Use_decl_annotations_
|
|
-HRESULT ValidateDxilContainer(const void *pContainer,
|
|
|
|
- uint32_t ContainerSize,
|
|
|
|
- llvm::raw_ostream &DiagStream) {
|
|
|
|
-
|
|
|
|
- LLVMContext Ctx, DbgCtx;
|
|
|
|
- std::unique_ptr<llvm::Module> pModule, pDebugModule;
|
|
|
|
-
|
|
|
|
|
|
+HRESULT ValidateLoadModuleFromContainer(
|
|
|
|
+ _In_reads_bytes_(ILLength) const void *pContainer,
|
|
|
|
+ _In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
|
|
|
|
+ _In_ std::unique_ptr<llvm::Module> &pDebugModule,
|
|
|
|
+ _In_ llvm::LLVMContext &Ctx, LLVMContext &DbgCtx,
|
|
|
|
+ _In_ llvm::raw_ostream &DiagStream) {
|
|
llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream);
|
|
llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream);
|
|
PrintDiagnosticContext DiagContext(DiagPrinter);
|
|
PrintDiagnosticContext DiagContext(DiagPrinter);
|
|
- Ctx.setDiagnosticHandler(PrintDiagnosticHandler, &DiagContext, true);
|
|
|
|
- DbgCtx.setDiagnosticHandler(PrintDiagnosticHandler, &DiagContext, true);
|
|
|
|
|
|
+ DiagRestore DR(Ctx, &DiagContext);
|
|
|
|
+ DiagRestore DR2(DbgCtx, &DiagContext);
|
|
|
|
|
|
- HRESULT hr;
|
|
|
|
const DxilPartHeader *pPart = nullptr;
|
|
const DxilPartHeader *pPart = nullptr;
|
|
IFR(FindDxilPart(pContainer, ContainerSize, DFCC_DXIL, &pPart));
|
|
IFR(FindDxilPart(pContainer, ContainerSize, DFCC_DXIL, &pPart));
|
|
|
|
|
|
const char *pIL = nullptr;
|
|
const char *pIL = nullptr;
|
|
uint32_t ILLength = 0;
|
|
uint32_t ILLength = 0;
|
|
GetDxilProgramBitcode(
|
|
GetDxilProgramBitcode(
|
|
- reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(pPart)),
|
|
|
|
- &pIL, &ILLength);
|
|
|
|
|
|
+ reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(pPart)), &pIL,
|
|
|
|
+ &ILLength);
|
|
|
|
|
|
IFR(ValidateLoadModule(pIL, ILLength, pModule, Ctx, DiagStream));
|
|
IFR(ValidateLoadModule(pIL, ILLength, pModule, Ctx, DiagStream));
|
|
|
|
|
|
|
|
+ HRESULT hr;
|
|
const DxilPartHeader *pDbgPart = nullptr;
|
|
const DxilPartHeader *pDbgPart = nullptr;
|
|
- if (FAILED(hr = FindDxilPart(pContainer, ContainerSize, DFCC_ShaderDebugInfoDXIL, &pDbgPart)) &&
|
|
|
|
|
|
+ if (FAILED(hr = FindDxilPart(pContainer, ContainerSize,
|
|
|
|
+ DFCC_ShaderDebugInfoDXIL, &pDbgPart)) &&
|
|
hr != DXC_E_CONTAINER_MISSING_DXIL) {
|
|
hr != DXC_E_CONTAINER_MISSING_DXIL) {
|
|
return hr;
|
|
return hr;
|
|
}
|
|
}
|
|
|
|
|
|
if (pDbgPart) {
|
|
if (pDbgPart) {
|
|
GetDxilProgramBitcode(
|
|
GetDxilProgramBitcode(
|
|
- reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(pDbgPart)),
|
|
|
|
- &pIL, &ILLength);
|
|
|
|
- if (FAILED(hr = ValidateLoadModule(pIL, ILLength, pDebugModule, DbgCtx, DiagStream))) {
|
|
|
|
|
|
+ reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(pDbgPart)),
|
|
|
|
+ &pIL, &ILLength);
|
|
|
|
+ if (FAILED(hr = ValidateLoadModule(pIL, ILLength, pDebugModule, DbgCtx,
|
|
|
|
+ DiagStream))) {
|
|
return hr;
|
|
return hr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ return S_OK;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+_Use_decl_annotations_
|
|
|
|
+HRESULT ValidateDxilContainer(const void *pContainer,
|
|
|
|
+ uint32_t ContainerSize,
|
|
|
|
+ llvm::raw_ostream &DiagStream) {
|
|
|
|
+ LLVMContext Ctx, DbgCtx;
|
|
|
|
+ std::unique_ptr<llvm::Module> pModule, pDebugModule;
|
|
|
|
+
|
|
|
|
+ llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream);
|
|
|
|
+ PrintDiagnosticContext DiagContext(DiagPrinter);
|
|
|
|
+ Ctx.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler,
|
|
|
|
+ &DiagContext, true);
|
|
|
|
+ DbgCtx.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler,
|
|
|
|
+ &DiagContext, true);
|
|
|
|
+
|
|
|
|
+ IFR(ValidateLoadModuleFromContainer(pContainer, ContainerSize, pModule, pDebugModule,
|
|
|
|
+ Ctx, DbgCtx, DiagStream));
|
|
|
|
+
|
|
// Validate DXIL Module
|
|
// Validate DXIL Module
|
|
IFR(ValidateDxilModule(pModule.get(), pDebugModule.get()));
|
|
IFR(ValidateDxilModule(pModule.get(), pDebugModule.get()));
|
|
|
|
|