DxilShaderModel.h 3.8 KB

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