HLSignatureLower.h 3.5 KB

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