CGHLSLRootSignature.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===----- CGHLSLRootSignature.cpp - Compile root signature---------------===//
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // CGHLSLRootSignature.cpp //
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. // This file is distributed under the University of Illinois Open Source //
  7. // License. See LICENSE.TXT for details. //
  8. // //
  9. // This provides clang::CompileRootSignature. //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include "clang/Basic/SourceLocation.h"
  13. #include "llvm/ADT/StringRef.h"
  14. #include "llvm/Support/raw_ostream.h"
  15. #include "dxc/DXIL/DxilConstants.h"
  16. #include "dxc/DxilRootSignature/DxilRootSignature.h"
  17. #include "dxc/Support/WinIncludes.h" // stream support
  18. #include "dxc/dxcapi.h" // stream support
  19. #include "clang/Parse/ParseHLSL.h" // root sig would be in Parser if part of lang
  20. #include "dxc/dxcapi.h"
  21. using namespace llvm;
  22. void clang::CompileRootSignature(
  23. StringRef rootSigStr, DiagnosticsEngine &Diags, SourceLocation SLoc,
  24. hlsl::DxilRootSignatureVersion rootSigVer,
  25. hlsl::DxilRootSignatureCompilationFlags flags,
  26. hlsl::RootSignatureHandle *pRootSigHandle) {
  27. std::string OSStr;
  28. llvm::raw_string_ostream OS(OSStr);
  29. hlsl::DxilVersionedRootSignatureDesc *D = nullptr;
  30. if (ParseHLSLRootSignature(rootSigStr.data(), rootSigStr.size(), rootSigVer,
  31. flags, &D, SLoc, Diags)) {
  32. CComPtr<IDxcBlob> pSignature;
  33. CComPtr<IDxcBlobEncoding> pErrors;
  34. hlsl::SerializeRootSignature(D, &pSignature, &pErrors, false);
  35. if (pSignature == nullptr) {
  36. assert(pErrors != nullptr && "else serialize failed with no msg");
  37. ReportHLSLRootSigError(Diags, SLoc, (char *)pErrors->GetBufferPointer(),
  38. pErrors->GetBufferSize());
  39. hlsl::DeleteRootSignature(D);
  40. } else {
  41. pRootSigHandle->Assign(D, pSignature);
  42. }
  43. }
  44. }