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