DxilShaderModel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilShaderModel.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 shader models. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/DXIL/DxilConstants.h"
  13. #include <string>
  14. namespace hlsl {
  15. class Semantic;
  16. /// <summary>
  17. /// Use this class to represent HLSL shader model.
  18. /// </summary>
  19. class ShaderModel {
  20. public:
  21. using Kind = DXIL::ShaderKind;
  22. // Major/Minor version of highest shader model
  23. /* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_highest_shader_model()</py>*/
  24. // VALRULE-TEXT:BEGIN
  25. static const unsigned kHighestMajor = 6;
  26. static const unsigned kHighestMinor = 6;
  27. // VALRULE-TEXT:END
  28. static const unsigned kOfflineMinor = 0xF;
  29. bool IsPS() const { return m_Kind == Kind::Pixel; }
  30. bool IsVS() const { return m_Kind == Kind::Vertex; }
  31. bool IsGS() const { return m_Kind == Kind::Geometry; }
  32. bool IsHS() const { return m_Kind == Kind::Hull; }
  33. bool IsDS() const { return m_Kind == Kind::Domain; }
  34. bool IsCS() const { return m_Kind == Kind::Compute; }
  35. bool IsLib() const { return m_Kind == Kind::Library; }
  36. bool IsRay() const { return m_Kind >= Kind::RayGeneration && m_Kind <= Kind::Callable; }
  37. bool IsMS() const { return m_Kind == Kind::Mesh; }
  38. bool IsAS() const { return m_Kind == Kind::Amplification; }
  39. bool IsValid() const;
  40. bool IsValidForDxil() const;
  41. bool IsValidForModule() const;
  42. Kind GetKind() const { return m_Kind; }
  43. unsigned GetMajor() const { return m_Major; }
  44. unsigned GetMinor() const { return m_Minor; }
  45. void GetDxilVersion(unsigned &DxilMajor, unsigned &DxilMinor) const;
  46. void GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
  47. bool IsSMAtLeast(unsigned Major, unsigned Minor) const {
  48. return m_Major > Major || (m_Major == Major && m_Minor >= Minor);
  49. }
  50. bool IsSM50Plus() const { return IsSMAtLeast(5, 0); }
  51. bool IsSM51Plus() const { return IsSMAtLeast(5, 1); }
  52. /* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_is_shader_model_plus()</py>*/
  53. // VALRULE-TEXT:BEGIN
  54. bool IsSM60Plus() const { return IsSMAtLeast(6, 0); }
  55. bool IsSM61Plus() const { return IsSMAtLeast(6, 1); }
  56. bool IsSM62Plus() const { return IsSMAtLeast(6, 2); }
  57. bool IsSM63Plus() const { return IsSMAtLeast(6, 3); }
  58. bool IsSM64Plus() const { return IsSMAtLeast(6, 4); }
  59. bool IsSM65Plus() const { return IsSMAtLeast(6, 5); }
  60. bool IsSM66Plus() const { return IsSMAtLeast(6, 6); }
  61. // VALRULE-TEXT:END
  62. const char *GetName() const { return m_pszName; }
  63. const char *GetKindName() const;
  64. DXIL::PackingStrategy GetDefaultPackingStrategy() const { return DXIL::PackingStrategy::PrefixStable; }
  65. static const ShaderModel *Get(Kind Kind, unsigned Major, unsigned Minor);
  66. static const ShaderModel *GetByName(const char *pszName);
  67. static const char *GetKindName(Kind kind);
  68. bool operator==(const ShaderModel &other) const;
  69. bool operator!=(const ShaderModel &other) const { return !(*this == other); }
  70. private:
  71. Kind m_Kind;
  72. unsigned m_Major;
  73. unsigned m_Minor;
  74. const char *m_pszName;
  75. unsigned m_NumInputRegs;
  76. unsigned m_NumOutputRegs;
  77. bool m_bUAVs;
  78. bool m_bTypedUavs;
  79. unsigned m_NumUAVRegs;
  80. ShaderModel() = delete;
  81. ShaderModel(Kind Kind, unsigned Major, unsigned Minor, const char *pszName,
  82. unsigned m_NumInputRegs, unsigned m_NumOutputRegs,
  83. bool m_bUAVs, bool m_bTypedUavs, unsigned m_UAVRegsLim);
  84. /* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_num_shader_models()</py>*/
  85. // VALRULE-TEXT:BEGIN
  86. static const unsigned kNumShaderModels = 74;
  87. // VALRULE-TEXT:END
  88. static const ShaderModel ms_ShaderModels[kNumShaderModels];
  89. static const ShaderModel *GetInvalid();
  90. };
  91. } // namespace hlsl