HLSignatureLower.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. } // namespace llvm
  19. namespace hlsl {
  20. class HLModule;
  21. struct DxilEntrySignature;
  22. class DxilFunctionAnnotation;
  23. class ShaderModel;
  24. struct DxilFunctionProps;
  25. class DxilSignatureElement;
  26. class HLSignatureLower {
  27. public:
  28. HLSignatureLower(llvm::Function *F, HLModule &M, DxilEntrySignature &Sig)
  29. : Entry(F), HLM(M), EntrySig(Sig) {}
  30. void Run();
  31. private:
  32. // Create signatures.
  33. void ProcessArgument(llvm::Function *func,
  34. DxilFunctionAnnotation *EntryAnnotation,
  35. llvm::Argument &arg, DxilFunctionProps &props,
  36. const ShaderModel *pSM, bool isPatchConstantFunction,
  37. bool forceOut, bool &hasClipPlane);
  38. void CreateDxilSignatures();
  39. // Allocate DXIL input/output.
  40. void AllocateDxilInputOutputs();
  41. // Generate DXIL input load, output store
  42. void GenerateDxilInputs();
  43. void GenerateDxilOutputs();
  44. void GenerateDxilInputsOutputs(bool bInput);
  45. void GenerateDxilCSInputs();
  46. void GenerateDxilPatchConstantLdSt();
  47. void GenerateDxilPatchConstantFunctionInputs();
  48. void GenerateClipPlanesForVS(llvm::Value *outPosition);
  49. bool HasClipPlanes();
  50. // Generate DXIL stream output operation.
  51. void GenerateStreamOutputOperation(llvm::Value *streamVal, unsigned streamID);
  52. // Generate DXIL stream output operations.
  53. void GenerateStreamOutputOperations();
  54. private:
  55. llvm::Function *Entry;
  56. HLModule &HLM;
  57. DxilEntrySignature &EntrySig;
  58. // For validation
  59. std::unordered_map<unsigned, std::unordered_set<unsigned>>
  60. m_InputSemanticsUsed, m_OutputSemanticsUsed[4],
  61. m_PatchConstantSemanticsUsed, m_OtherSemanticsUsed;
  62. // SignatureElement to Value map for GenerateDxilInputsOutputs.
  63. std::unordered_map<DxilSignatureElement *, llvm::Value *> m_sigValueMap;
  64. // Patch constant function inputs to signature element map for
  65. // GenerateDxilPatchConstantFunctionInputs.
  66. std::unordered_map<unsigned, DxilSignatureElement *>
  67. m_patchConstantInputsSigMap;
  68. // Set to save inout arguments for GenerateDxilInputsOutputs.
  69. std::unordered_set<llvm::Value *> m_inoutArgSet;
  70. // SignatureElement which has precise attribute for GenerateDxilInputsOutputs.
  71. std::unordered_set<DxilSignatureElement *> m_preciseSigSet;
  72. };
  73. } // namespace hlsl