DxilShaderModel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/HLSL/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. static const unsigned kHighestMajor = 6;
  24. static const unsigned kHighestMinor = 3;
  25. static const unsigned kOfflineMinor = 0xF;
  26. bool IsPS() const { return m_Kind == Kind::Pixel; }
  27. bool IsVS() const { return m_Kind == Kind::Vertex; }
  28. bool IsGS() const { return m_Kind == Kind::Geometry; }
  29. bool IsHS() const { return m_Kind == Kind::Hull; }
  30. bool IsDS() const { return m_Kind == Kind::Domain; }
  31. bool IsCS() const { return m_Kind == Kind::Compute; }
  32. bool IsLib() const { return m_Kind == Kind::Library; }
  33. bool IsRay() const { return m_Kind >= Kind::RayGeneration && m_Kind <= Kind::Callable; }
  34. bool IsValid() const;
  35. bool IsValidForDxil() const;
  36. bool IsValidForModule() const;
  37. Kind GetKind() const { return m_Kind; }
  38. unsigned GetMajor() const { return m_Major; }
  39. unsigned GetMinor() const { return m_Minor; }
  40. void GetDxilVersion(unsigned &DxilMajor, unsigned &DxilMinor) const;
  41. void GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
  42. bool IsSMAtLeast(unsigned Major, unsigned Minor) const {
  43. return m_Major > Major || (m_Major == Major && m_Minor >= Minor);
  44. }
  45. bool IsSM50Plus() const { return IsSMAtLeast(5, 0); }
  46. bool IsSM51Plus() const { return IsSMAtLeast(5, 1); }
  47. bool IsSM60Plus() const { return IsSMAtLeast(6, 0); }
  48. bool IsSM61Plus() const { return IsSMAtLeast(6, 1); }
  49. bool IsSM62Plus() const { return IsSMAtLeast(6, 2); }
  50. bool IsSM63Plus() const { return IsSMAtLeast(6, 3); }
  51. const char *GetName() const { return m_pszName; }
  52. const char *GetKindName() const;
  53. unsigned GetNumTempRegs() const { return DXIL::kMaxTempRegCount; }
  54. unsigned GetNumInputRegs() const { return m_NumInputRegs; }
  55. unsigned GetNumOutputRegs() const { return m_NumOutputRegs; }
  56. unsigned GetCBufferSize() const { return DXIL::kMaxCBufferSize; }
  57. unsigned SupportsUAV() const { return m_bUAVs; }
  58. unsigned SupportsTypedUAVs() const { return m_bTypedUavs; }
  59. unsigned GetUAVRegLimit() const { return m_NumUAVRegs; }
  60. DXIL::PackingStrategy GetDefaultPackingStrategy() const { return DXIL::PackingStrategy::PrefixStable; }
  61. static unsigned Count() { return kNumShaderModels - 1; }
  62. static const ShaderModel *Get(unsigned Idx);
  63. static const ShaderModel *Get(Kind Kind, unsigned Major, unsigned Minor);
  64. static const ShaderModel *GetByName(const char *pszName);
  65. static const char *GetKindName(Kind kind);
  66. bool operator==(const ShaderModel &other) const;
  67. bool operator!=(const ShaderModel &other) const { return !(*this == other); }
  68. private:
  69. Kind m_Kind;
  70. unsigned m_Major;
  71. unsigned m_Minor;
  72. const char *m_pszName;
  73. unsigned m_NumInputRegs;
  74. unsigned m_NumOutputRegs;
  75. bool m_bUAVs;
  76. bool m_bTypedUavs;
  77. unsigned m_NumUAVRegs;
  78. ShaderModel() = delete;
  79. ShaderModel(Kind Kind, unsigned Major, unsigned Minor, const char *pszName,
  80. unsigned m_NumInputRegs, unsigned m_NumOutputRegs,
  81. bool m_bUAVs, bool m_bTypedUavs, unsigned m_UAVRegsLim);
  82. static const unsigned kNumShaderModels = 49;
  83. static const ShaderModel ms_ShaderModels[kNumShaderModels];
  84. static const ShaderModel *GetInvalid();
  85. };
  86. } // namespace hlsl