HLSignatureLower.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLSignatureLower.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Lower signatures of entry function to DXIL LoadInput/StoreOutput. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include <unordered_set>
  13. #include <unordered_map>
  14. namespace llvm {
  15. class Value;
  16. class Argument;
  17. class Function;
  18. class StringRef;
  19. } // namespace llvm
  20. namespace hlsl {
  21. class HLModule;
  22. struct DxilEntrySignature;
  23. class DxilFunctionAnnotation;
  24. class ShaderModel;
  25. struct DxilFunctionProps;
  26. class DxilSignatureElement;
  27. class DxilParameterAnnotation;
  28. class SigPoint;
  29. class HLSignatureLower {
  30. public:
  31. HLSignatureLower(llvm::Function *F, HLModule &M, DxilEntrySignature &Sig)
  32. : Entry(F), HLM(M), EntrySig(Sig) {}
  33. void Run();
  34. private:
  35. // Create signatures.
  36. void ProcessArgument(llvm::Function *func,
  37. DxilFunctionAnnotation *EntryAnnotation,
  38. llvm::Argument &arg, DxilFunctionProps &props,
  39. const ShaderModel *pSM, bool isPatchConstantFunction,
  40. bool forceOut, bool &hasClipPlane);
  41. void CreateDxilSignatures();
  42. // Allocate DXIL input/output.
  43. void AllocateDxilInputOutputs();
  44. // Generate DXIL input load, output store
  45. void GenerateDxilInputs();
  46. void GenerateDxilOutputs();
  47. void GenerateDxilInputsOutputs(bool bInput);
  48. void GenerateDxilCSInputs();
  49. void GenerateDxilPatchConstantLdSt();
  50. void GenerateDxilPatchConstantFunctionInputs();
  51. void GenerateClipPlanesForVS(llvm::Value *outPosition);
  52. bool HasClipPlanes();
  53. // Generate DXIL stream output operation.
  54. void GenerateStreamOutputOperation(llvm::Value *streamVal, unsigned streamID);
  55. // Generate DXIL stream output operations.
  56. void GenerateStreamOutputOperations();
  57. private:
  58. llvm::Function *Entry;
  59. HLModule &HLM;
  60. DxilEntrySignature &EntrySig;
  61. // For validation
  62. std::unordered_map<unsigned, std::unordered_set<unsigned>>
  63. m_InputSemanticsUsed, m_OutputSemanticsUsed[4],
  64. m_PatchConstantSemanticsUsed, m_OtherSemanticsUsed;
  65. // SignatureElement to Value map for GenerateDxilInputsOutputs.
  66. std::unordered_map<DxilSignatureElement *, llvm::Value *> m_sigValueMap;
  67. // Patch constant function inputs to signature element map for
  68. // GenerateDxilPatchConstantFunctionInputs.
  69. std::unordered_map<unsigned, DxilSignatureElement *>
  70. m_patchConstantInputsSigMap;
  71. // Set to save inout arguments for GenerateDxilInputsOutputs.
  72. std::unordered_set<llvm::Value *> m_inoutArgSet;
  73. // SignatureElement which has precise attribute for GenerateDxilInputsOutputs.
  74. std::unordered_set<DxilSignatureElement *> m_preciseSigSet;
  75. };
  76. } // namespace hlsl