DxilSignatureElement.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilSignatureElement.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. // Representation of HLSL signature element. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "llvm/ADT/StringRef.h"
  13. #include "dxc/HLSL/DxilSemantic.h"
  14. #include "dxc/HLSL/DxilInterpolationMode.h"
  15. #include "dxc/HLSL/DxilCompType.h"
  16. #include "dxc/HLSL/DxilSignatureAllocator.h"
  17. #include <string>
  18. #include <vector>
  19. namespace hlsl {
  20. class ShaderModel;
  21. /// Use this class to represent HLSL signature elements.
  22. class DxilSignatureElement {
  23. friend class DxilSignature;
  24. public:
  25. using Kind = DXIL::SigPointKind;
  26. static const unsigned kUndefinedID = UINT_MAX;
  27. DxilSignatureElement(Kind K);
  28. virtual ~DxilSignatureElement();
  29. void Initialize(llvm::StringRef Name, const CompType &ElementType, const InterpolationMode &InterpMode,
  30. unsigned Rows, unsigned Cols,
  31. int StartRow = Semantic::kUndefinedRow, int StartCol = Semantic::kUndefinedCol,
  32. unsigned ID = kUndefinedID, const std::vector<unsigned> &IndexVector = std::vector<unsigned>());
  33. unsigned GetID() const;
  34. void SetID(unsigned ID);
  35. DXIL::ShaderKind GetShaderKind() const;
  36. DXIL::SigPointKind GetSigPointKind() const;
  37. void SetSigPointKind(DXIL::SigPointKind K);
  38. bool IsInput() const;
  39. bool IsOutput() const;
  40. bool IsPatchConstant() const;
  41. const char *GetName() const;
  42. unsigned GetRows() const;
  43. void SetRows(unsigned Rows);
  44. unsigned GetCols() const;
  45. void SetCols(unsigned Cols);
  46. const InterpolationMode *GetInterpolationMode() const;
  47. CompType GetCompType() const;
  48. unsigned GetOutputStream() const;
  49. void SetOutputStream(unsigned Stream);
  50. // Semantic properties.
  51. const Semantic *GetSemantic() const;
  52. void SetKind(Semantic::Kind kind);
  53. Semantic::Kind GetKind() const;
  54. bool IsArbitrary() const;
  55. bool IsDepth() const;
  56. bool IsDepthLE() const;
  57. bool IsDepthGE() const;
  58. bool IsAnyDepth() const;
  59. DXIL::SemanticInterpretationKind GetInterpretation() const;
  60. llvm::StringRef GetSemanticName() const;
  61. unsigned GetSemanticStartIndex() const;
  62. // Low-level properties.
  63. int GetStartRow() const;
  64. void SetStartRow(int StartRow);
  65. int GetStartCol() const;
  66. void SetStartCol(int Component);
  67. const std::vector<unsigned> &GetSemanticIndexVec() const;
  68. void SetSemanticIndexVec(const std::vector<unsigned> &Vec);
  69. void AppendSemanticIndex(unsigned SemIdx);
  70. void SetCompType(CompType CT);
  71. uint8_t GetColsAsMask() const;
  72. bool IsAllocated() const;
  73. unsigned GetDynIdxCompMask() const;
  74. void SetDynIdxCompMask(unsigned DynIdxCompMask);
  75. protected:
  76. DXIL::SigPointKind m_sigPointKind;
  77. const Semantic *m_pSemantic;
  78. unsigned m_ID;
  79. std::string m_Name;
  80. llvm::StringRef m_SemanticName;
  81. unsigned m_SemanticStartIndex;
  82. CompType m_CompType;
  83. InterpolationMode m_InterpMode;
  84. std::vector<unsigned> m_SemanticIndex;
  85. unsigned m_Rows;
  86. unsigned m_Cols;
  87. int m_StartRow;
  88. int m_StartCol;
  89. unsigned m_OutputStream;
  90. unsigned m_DynIdxCompMask;
  91. };
  92. class DxilPackElement : public DxilSignatureAllocator::PackElement {
  93. DxilSignatureElement *m_pSE;
  94. bool m_bUseMinPrecision;
  95. public:
  96. DxilPackElement(DxilSignatureElement *pSE, bool useMinPrecision) : m_pSE(pSE), m_bUseMinPrecision(useMinPrecision) {}
  97. __override ~DxilPackElement() {}
  98. __override uint32_t GetID() const { return m_pSE->GetID(); }
  99. __override DXIL::SemanticKind GetKind() const { return m_pSE->GetKind(); }
  100. __override DXIL::InterpolationMode GetInterpolationMode() const { return m_pSE->GetInterpolationMode()->GetKind(); }
  101. __override DXIL::SemanticInterpretationKind GetInterpretation() const { return m_pSE->GetInterpretation(); }
  102. __override DXIL::SignatureDataWidth GetDataBitWidth() const {
  103. uint8_t size = m_pSE->GetCompType().GetSizeInBits();
  104. // bool, min precision, or 32 bit types map to 32 bit size.
  105. if (size == 16) {
  106. return m_bUseMinPrecision ? DXIL::SignatureDataWidth::Bits32 : DXIL::SignatureDataWidth::Bits16;
  107. }
  108. else if (size == 1 || size == 32) {
  109. return DXIL::SignatureDataWidth::Bits32;
  110. }
  111. return DXIL::SignatureDataWidth::Undefined;
  112. }
  113. __override uint32_t GetRows() const { return m_pSE->GetRows(); }
  114. __override uint32_t GetCols() const { return m_pSE->GetCols(); }
  115. __override bool IsAllocated() const { return m_pSE->IsAllocated(); }
  116. __override uint32_t GetStartRow() const { return m_pSE->GetStartRow(); }
  117. __override uint32_t GetStartCol() const { return m_pSE->GetStartCol(); }
  118. __override void ClearLocation() {
  119. m_pSE->SetStartRow(-1);
  120. m_pSE->SetStartCol(-1);
  121. }
  122. __override void SetLocation(uint32_t Row, uint32_t Col) {
  123. m_pSE->SetStartRow(Row);
  124. m_pSE->SetStartCol(Col);
  125. }
  126. DxilSignatureElement *Get() { return m_pSE; }
  127. };
  128. } // namespace hlsl