DxilCompType.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilCompType.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. // Represenation of HLSL component type. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "DxilConstants.h"
  13. namespace llvm {
  14. class Type;
  15. class PointerType;
  16. class LLVMContext;
  17. }
  18. namespace hlsl {
  19. /// Use this class to represent HLSL component/element types.
  20. class CompType {
  21. public:
  22. using Kind = DXIL::ComponentType;
  23. CompType();
  24. CompType(Kind K);
  25. CompType(unsigned int K);
  26. bool operator==(const CompType &o) const;
  27. Kind GetKind() const;
  28. uint8_t GetSizeInBits() const;
  29. static CompType getInvalid();
  30. static CompType getF16();
  31. static CompType getF32();
  32. static CompType getF64();
  33. static CompType getI16();
  34. static CompType getI32();
  35. static CompType getI64();
  36. static CompType getU16();
  37. static CompType getU32();
  38. static CompType getU64();
  39. static CompType getI1();
  40. static CompType getSNormF16();
  41. static CompType getUNormF16();
  42. static CompType getSNormF32();
  43. static CompType getUNormF32();
  44. static CompType getSNormF64();
  45. static CompType getUNormF64();
  46. bool IsInvalid() const;
  47. bool IsFloatTy() const;
  48. bool IsIntTy() const;
  49. bool IsSIntTy() const;
  50. bool IsUIntTy() const;
  51. bool IsBoolTy() const;
  52. bool IsSNorm() const;
  53. bool IsUNorm() const;
  54. bool Is64Bit() const;
  55. bool Is16Bit() const;
  56. /// For min-precision types, returns upconverted (base) type.
  57. CompType GetBaseCompType() const;
  58. bool HasMinPrec() const;
  59. llvm::Type *GetLLVMType(llvm::LLVMContext &Ctx) const;
  60. llvm::PointerType *GetLLVMPtrType(llvm::LLVMContext &Ctx, const unsigned AddrSpace = 0) const;
  61. llvm::Type *GetLLVMBaseType(llvm::LLVMContext &Ctx) const;
  62. /// Get the component type for a given llvm type.
  63. ///
  64. /// LLVM types do not hold sign information so there is no 1-1
  65. /// correspondence between llvm types and component types.
  66. /// This method returns the signed version for all integer
  67. /// types.
  68. ///
  69. /// TODO: decide if we should distinguish between signed
  70. /// and unsigned types in this api.
  71. static CompType GetCompType(llvm::Type * type);
  72. const char *GetName() const;
  73. const char *GetHLSLName(bool MinPrecision) const;
  74. private:
  75. Kind m_Kind;
  76. };
  77. } // namespace hlsl