DxilResourceBase.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilResourceBase.cpp //
  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. ///////////////////////////////////////////////////////////////////////////////
  9. #include "dxc/DXIL/DxilResourceBase.h"
  10. #include "dxc/Support/Global.h"
  11. namespace hlsl {
  12. //------------------------------------------------------------------------------
  13. //
  14. // ResourceBase methods.
  15. //
  16. DxilResourceBase::DxilResourceBase(Class C)
  17. : m_Class(C)
  18. , m_Kind(Kind::Invalid)
  19. , m_ID(UINT_MAX)
  20. , m_SpaceID(0)
  21. , m_LowerBound(0)
  22. , m_RangeSize(0)
  23. , m_pSymbol(nullptr)
  24. , m_pHandle(nullptr) {
  25. }
  26. DxilResourceBase::Class DxilResourceBase::GetClass() const { return m_Class; }
  27. DxilResourceBase::Kind DxilResourceBase::GetKind() const { return m_Kind; }
  28. void DxilResourceBase::SetKind(DxilResourceBase::Kind ResourceKind) {
  29. DXASSERT(ResourceKind > Kind::Invalid && ResourceKind < Kind::NumEntries, "otherwise the caller passed wrong resource type");
  30. m_Kind = ResourceKind;
  31. }
  32. unsigned DxilResourceBase::GetID() const { return m_ID; }
  33. unsigned DxilResourceBase::GetSpaceID() const { return m_SpaceID; }
  34. unsigned DxilResourceBase::GetLowerBound() const { return m_LowerBound; }
  35. unsigned DxilResourceBase::GetUpperBound() const { return m_RangeSize != UINT_MAX ? m_LowerBound + m_RangeSize - 1 : UINT_MAX; }
  36. unsigned DxilResourceBase::GetRangeSize() const { return m_RangeSize; }
  37. llvm::Constant *DxilResourceBase::GetGlobalSymbol() const { return m_pSymbol; }
  38. const std::string &DxilResourceBase::GetGlobalName() const { return m_Name; }
  39. llvm::Value *DxilResourceBase::GetHandle() const { return m_pHandle; }
  40. bool DxilResourceBase::IsAllocated() const { return m_LowerBound != UINT_MAX; }
  41. bool DxilResourceBase::IsUnbounded() const { return m_RangeSize == UINT_MAX; }
  42. void DxilResourceBase::SetClass(Class C) { m_Class = C; }
  43. void DxilResourceBase::SetID(unsigned ID) { m_ID = ID; }
  44. void DxilResourceBase::SetSpaceID(unsigned SpaceID) { m_SpaceID = SpaceID; }
  45. void DxilResourceBase::SetLowerBound(unsigned LB) { m_LowerBound = LB; }
  46. void DxilResourceBase::SetRangeSize(unsigned RangeSize) { m_RangeSize = RangeSize; }
  47. void DxilResourceBase::SetGlobalSymbol(llvm::Constant *pGV) { m_pSymbol = pGV; }
  48. void DxilResourceBase::SetGlobalName(const std::string &Name) { m_Name = Name; }
  49. void DxilResourceBase::SetHandle(llvm::Value *pHandle) { m_pHandle = pHandle; }
  50. static const char *s_ResourceClassNames[] = {
  51. "texture", "UAV", "cbuffer", "sampler"
  52. };
  53. static_assert(_countof(s_ResourceClassNames) == (unsigned)DxilResourceBase::Class::Invalid,
  54. "Resource class names array must be updated when new resource class enums are added.");
  55. const char *DxilResourceBase::GetResClassName() const {
  56. return s_ResourceClassNames[(unsigned)m_Class];
  57. }
  58. static const char *s_ResourceIDPrefixes[] = {
  59. "T", "U", "CB", "S"
  60. };
  61. static_assert(_countof(s_ResourceIDPrefixes) == (unsigned)DxilResourceBase::Class::Invalid,
  62. "Resource id prefixes array must be updated when new resource class enums are added.");
  63. const char *DxilResourceBase::GetResIDPrefix() const {
  64. return s_ResourceIDPrefixes[(unsigned)m_Class];
  65. }
  66. static const char *s_ResourceBindPrefixes[] = {
  67. "t", "u", "cb", "s"
  68. };
  69. static_assert(_countof(s_ResourceBindPrefixes) == (unsigned)DxilResourceBase::Class::Invalid,
  70. "Resource bind prefixes array must be updated when new resource class enums are added.");
  71. const char *DxilResourceBase::GetResBindPrefix() const {
  72. return s_ResourceBindPrefixes[(unsigned)m_Class];
  73. }
  74. static const char *s_ResourceDimNames[] = {
  75. "invalid", "1d", "2d", "2dMS", "3d",
  76. "cube", "1darray", "2darray", "2darrayMS", "cubearray",
  77. "buf", "rawbuf", "structbuf", "cbuffer", "sampler",
  78. "tbuffer", "ras", "fbtex2d", "fbtex2darray", "structbufwithcounter", "samplercomparison",
  79. };
  80. static_assert(_countof(s_ResourceDimNames) == (unsigned)DxilResourceBase::Kind::NumEntries,
  81. "Resource dim names array must be updated when new resource kind enums are added.");
  82. const char *DxilResourceBase::GetResDimName() const {
  83. return s_ResourceDimNames[(unsigned)m_Kind];
  84. }
  85. static const char *s_ResourceKindNames[] = {
  86. "invalid", "Texture1D", "Texture2D", "Texture2DMS", "Texture3D",
  87. "TextureCube", "Texture1DArray", "Texture2DArray", "Texture2DMSArray", "TextureCubeArray",
  88. "TypedBuffer", "RawBuffer", "StructuredBuffer", "CBuffer", "Sampler",
  89. "TBuffer", "RTAccelerationStructure", "FeedbackTexture2D", "FeedbackTexture2DArray",
  90. "StructuredBufferWithCounter", "SamplerComparison",
  91. };
  92. static_assert(_countof(s_ResourceKindNames) == (unsigned)DxilResourceBase::Kind::NumEntries,
  93. "Resource kind names array must be updated when new resource kind enums are added.");
  94. const char *DxilResourceBase::GetResKindName() const {
  95. return GetResourceKindName(m_Kind);
  96. }
  97. const char *GetResourceKindName(DXIL::ResourceKind K) {
  98. return s_ResourceKindNames[(unsigned)K];
  99. }
  100. } // namespace hlsl