DxilCompType.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. static CompType getInvalid();
  29. static CompType getF16();
  30. static CompType getF32();
  31. static CompType getF64();
  32. static CompType getI16();
  33. static CompType getI32();
  34. static CompType getI64();
  35. static CompType getU16();
  36. static CompType getU32();
  37. static CompType getU64();
  38. static CompType getI1();
  39. static CompType getSNormF16();
  40. static CompType getUNormF16();
  41. static CompType getSNormF32();
  42. static CompType getUNormF32();
  43. static CompType getSNormF64();
  44. static CompType getUNormF64();
  45. bool IsInvalid() const;
  46. bool IsFloatTy() const;
  47. bool IsIntTy() const;
  48. bool IsSIntTy() const;
  49. bool IsUIntTy() const;
  50. bool IsBoolTy() const;
  51. bool IsSNorm() const;
  52. bool IsUNorm() const;
  53. bool Is64Bit() const;
  54. /// For min-precision types, returns upconverted (base) type.
  55. CompType GetBaseCompType() const;
  56. bool HasMinPrec() const;
  57. llvm::Type *GetLLVMType(llvm::LLVMContext &Ctx) const;
  58. llvm::PointerType *GetLLVMPtrType(llvm::LLVMContext &Ctx, const unsigned AddrSpace = 0) const;
  59. llvm::Type *GetLLVMBaseType(llvm::LLVMContext &Ctx) const;
  60. /// Get the component type for a given llvm type.
  61. ///
  62. /// LLVM types do not hold sign information so there is no 1-1
  63. /// correspondence between llvm types and component types.
  64. /// This method returns the signed version for all integer
  65. /// types.
  66. ///
  67. /// TODO: decide if we should distinguish between signed
  68. /// and unsigned types in this api.
  69. static CompType GetCompType(llvm::Type * type);
  70. const char *GetName() const;
  71. const char *GetHLSLName() const;
  72. private:
  73. Kind m_Kind;
  74. };
  75. } // namespace hlsl