DxilResourceBase.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilResourceBase.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. // Base class to represent DXIL SRVs, UAVs, CBuffers, and Samplers. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include <string>
  13. #include "DxilConstants.h"
  14. namespace llvm {
  15. class Value;
  16. class Constant;
  17. class Type;
  18. }
  19. namespace hlsl {
  20. /// Base class to represent HLSL SRVs, UAVs, CBuffers, and Samplers.
  21. class DxilResourceBase {
  22. public:
  23. using Class = DXIL::ResourceClass;
  24. using Kind = DXIL::ResourceKind;
  25. public:
  26. DxilResourceBase(Class C);
  27. virtual ~DxilResourceBase() {}
  28. Class GetClass() const;
  29. DxilResourceBase::Kind GetKind() const;
  30. unsigned GetID() const;
  31. unsigned GetSpaceID() const;
  32. unsigned GetLowerBound() const;
  33. unsigned GetUpperBound() const;
  34. unsigned GetRangeSize() const;
  35. llvm::Constant *GetGlobalSymbol() const;
  36. llvm::Type *GetHLSLType() const;
  37. const std::string &GetGlobalName() const;
  38. llvm::Value *GetHandle() const;
  39. bool IsAllocated() const;
  40. bool IsUnbounded() const;
  41. void SetKind(DxilResourceBase::Kind ResourceKind);
  42. void SetSpaceID(unsigned SpaceID);
  43. void SetLowerBound(unsigned LB);
  44. void SetRangeSize(unsigned RangeSize);
  45. void SetGlobalSymbol(llvm::Constant *pGV);
  46. void SetGlobalName(const std::string &Name);
  47. void SetHandle(llvm::Value *pHandle);
  48. void SetHLSLType(llvm::Type *Ty);
  49. // TODO: check whether we can make this a protected method.
  50. void SetID(unsigned ID);
  51. const char *GetResClassName() const;
  52. const char *GetResDimName() const;
  53. const char *GetResIDPrefix() const;
  54. const char *GetResBindPrefix() const;
  55. const char *GetResKindName() const;
  56. protected:
  57. void SetClass(Class C);
  58. private:
  59. Class m_Class; // Resource class (SRV, UAV, CBuffer, Sampler).
  60. Kind m_Kind; // Detail resource kind( texture2D...).
  61. unsigned m_ID; // Unique ID within the class.
  62. unsigned m_SpaceID; // Root signature space.
  63. unsigned m_LowerBound; // Range lower bound.
  64. unsigned m_RangeSize; // Range size in entries.
  65. llvm::Constant *m_pSymbol; // Global variable.
  66. std::string m_Name; // Unmangled name of the global variable.
  67. llvm::Value *m_pHandle; // Cached resource handle for SM5.0- (and maybe SM5.1).
  68. llvm::Type *m_pHLSLTy; // The original hlsl type for reflection.
  69. };
  70. const char *GetResourceKindName(DXIL::ResourceKind K);
  71. } // namespace hlsl