Browse Source

Add DxcValidatorFlags_RootSignatureOnly.

Tex Riddell 8 years ago
parent
commit
2444ae3b10

+ 0 - 4
include/dxc/HLSL/DxilValidation.h

@@ -239,10 +239,6 @@ bool VerifySignatureMatches(_In_ llvm::Module *pModule,
                             _In_reads_bytes_(SigSize) void *pSigData,
                             _In_ unsigned SigSize);
 
-//bool VerifyRootSignatureMatches(_In_ llvm::Module *pModule,
-//                                  _In_reads_bytes_(RSSize) void *pRSData,
-//                                  _In_ unsigned RSSize);
-
 // PSV = data for Pipeline State Validation
 bool VerifyPSVMatches(_In_ llvm::Module *pModule,
                       _In_reads_bytes_(PSVSize) void *pPSVData,

+ 2 - 1
include/dxc/dxcapi.h

@@ -163,7 +163,8 @@ IDxcCompiler : public IUnknown {
 
 static const UINT32 DxcValidatorFlags_Default = 0;
 static const UINT32 DxcValidatorFlags_InPlaceEdit = 1;  // Validator is allowed to update shader blob in-place.
-static const UINT32 DxcValidatorFlags_ValidMask = 0x1;
+static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;
+static const UINT32 DxcValidatorFlags_ValidMask = 0x3;
 
 struct __declspec(uuid("A6E82BD2-1FD7-4826-9811-2857E797F49A"))
 IDxcValidator : public IUnknown {

+ 0 - 24
lib/HLSL/DxilValidation.cpp

@@ -34,7 +34,6 @@
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/ADT/BitVector.h"
-#include <winerror.h>
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -4105,29 +4104,6 @@ bool VerifySignatureMatches(llvm::Module *pModule,
   return !ValCtx.Failed;
 }
 
-//static void VerifyRootSignatureMatches(_In_ ValidationContext &ValCtx,
-//                                             _In_reads_bytes_(RSSize) const void *pRSData,
-//                                             _In_ unsigned RSSize) {
-//  // Write root signature from module and memcmp
-//  unique_ptr<DxilPartWriter> pWriter(NewRootSignatureWriter(ValCtx.DxilMod.GetRootSignature()));
-//  VerifyBlobPartMatches(ValCtx, "Root Signature", pWriter.get(), pRSData, RSSize);
-//}
-//
-//_Use_decl_annotations_
-//bool VerifyRootSignatureMatches(llvm::Module *pModule,
-//                                const void *pRSData,
-//                                unsigned RSSize) {
-//  std::string diagStr;
-//  raw_string_ostream diagStream(diagStr);
-//  DiagnosticPrinterRawOStream DiagPrinter(diagStream);
-//  ValidationContext ValCtx(*pModule, nullptr, pModule->GetOrCreateDxilModule(), DiagPrinter);
-//  VerifyRootSignatureMatches(ValCtx, pRSData, RSSize);
-//  if (ValCtx.Failed) {
-//    emitDxilDiag(pModule->getContext(), diagStream.str().c_str());
-//  }
-//  return !ValCtx.Failed;
-//}
-
 static void VerifyPSVMatches(_In_ ValidationContext &ValCtx,
                              _In_reads_bytes_(PSVSize) const void *pPSVData,
                              _In_ unsigned PSVSize) {

+ 42 - 1
tools/clang/tools/dxcompiler/dxcvalidator.cpp

@@ -23,6 +23,7 @@
 #include "dxc/Support/microcom.h"
 #include "dxc/Support/FileIOHelper.h"
 #include "dxc/Support/dxcapi.impl.h"
+#include "dxc/HLSL/DxilRootSignature.h"
 #include "dxcetw.h"
 
 using namespace llvm;
@@ -87,6 +88,10 @@ private:
     _In_ llvm::Module *pDebugModule,              // Debug module to validate, if available
     _In_ AbstractMemoryStream *pDiagStream);
 
+  HRESULT RunRootSignatureValidation(
+    _In_ IDxcBlob *pShader,                       // Shader to validate.
+    _In_ AbstractMemoryStream *pDiagStream);
+
 public:
   DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef)
   DxcValidator() : m_dwRef(0) {}
@@ -146,7 +151,11 @@ HRESULT DxcValidator::ValidateWithOptModules(
 
     // Run validation may throw, but that indicates an inability to validate,
     // not that the validation failed (eg out of memory).
-    validationStatus = RunValidation(pShader, pModule, pDebugModule, pDiagStream);
+    if (Flags & DxcValidatorFlags_RootSignatureOnly) {
+      validationStatus = RunRootSignatureValidation(pShader, pDiagStream);
+    } else {
+      validationStatus = RunValidation(pShader, pModule, pDebugModule, pDiagStream);
+    }
 
     // Assemble the result object.
     CComPtr<IDxcBlob> pDiagBlob;
@@ -216,6 +225,38 @@ HRESULT DxcValidator::RunValidation(
   return S_OK;
 }
 
+HRESULT DxcValidator::RunRootSignatureValidation(
+  _In_ IDxcBlob *pShader,
+  _In_ AbstractMemoryStream *pDiagStream) {
+
+  const DxilContainerHeader *pDxilContainer = IsDxilContainerLike(
+    pShader->GetBufferPointer(), pShader->GetBufferSize());
+  if (!pDxilContainer) {
+    return DXC_E_IR_VERIFICATION_FAILED;
+  }
+
+  const DxilProgramHeader *pProgramHeader = GetDxilProgramHeader(pDxilContainer, DFCC_DXIL);
+  const DxilPartHeader *pPSVPart = GetDxilPartByType(pDxilContainer, DFCC_PipelineStateValidation);
+  const DxilPartHeader *pRSPart = GetDxilPartByType(pDxilContainer, DFCC_RootSignature);
+  IFRBOOL(!pPSVPart || !pRSPart, DXC_E_MISSING_PART);
+  try {
+    RootSignatureHandle RSH;
+    RSH.LoadSerialized((const uint8_t*)GetDxilPartData(pRSPart), pRSPart->PartSize);
+    RSH.Deserialize();
+    raw_stream_ostream DiagStream(pDiagStream);
+    IFRBOOL(VerifyRootSignatureWithShaderPSV(RSH.GetDesc(),
+                                             GetVersionShaderType(pProgramHeader->ProgramVersion),
+                                             GetDxilPartData(pPSVPart),
+                                             pPSVPart->PartSize,
+                                             DiagStream),
+      DXC_E_INCORRECT_ROOT_SIGNATURE);
+  } catch(...) {
+    return DXC_E_IR_VERIFICATION_FAILED;
+  }
+
+  return S_OK;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 HRESULT RunInternalValidator(_In_ IDxcValidator *pValidator,