[llvm-branch-commits] [llvm] [DirectX] Move DXIL ResourceKind and ElementType to DXILABI.h. NFC (PR #78225)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 15 18:36:34 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
Author: Justin Bogner (bogner)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/78225.diff
4 Files Affected:
- (modified) llvm/include/llvm/Frontend/HLSL/HLSLResource.h (+4-48)
- (modified) llvm/include/llvm/Support/DXILABI.h (+48)
- (modified) llvm/lib/Target/DirectX/DXILResource.cpp (+46-46)
- (modified) llvm/lib/Target/DirectX/DXILResource.h (+11-10)
``````````diff
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index 068b4c66711e467..dcf78ec856a9d64 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -14,6 +14,7 @@
#define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
#include "llvm/IR/Metadata.h"
+#include "llvm/Support/DXILABI.h"
namespace llvm {
class GlobalVariable;
@@ -29,54 +30,9 @@ enum class ResourceClass : uint8_t {
NumClasses = Invalid,
};
-// The value ordering of this enumeration is part of the DXIL ABI. Elements
-// can only be added to the end, and not removed.
-enum class ResourceKind : uint32_t {
- Invalid = 0,
- Texture1D,
- Texture2D,
- Texture2DMS,
- Texture3D,
- TextureCube,
- Texture1DArray,
- Texture2DArray,
- Texture2DMSArray,
- TextureCubeArray,
- TypedBuffer,
- RawBuffer,
- StructuredBuffer,
- CBuffer,
- Sampler,
- TBuffer,
- RTAccelerationStructure,
- FeedbackTexture2D,
- FeedbackTexture2DArray,
- NumEntries,
-};
-
-// The value ordering of this enumeration is part of the DXIL ABI. Elements
-// can only be added to the end, and not removed.
-enum class ElementType : uint32_t {
- Invalid = 0,
- I1,
- I16,
- U16,
- I32,
- U32,
- I64,
- U64,
- F16,
- F32,
- F64,
- SNormF16,
- UNormF16,
- SNormF32,
- UNormF32,
- SNormF64,
- UNormF64,
- PackedS8x32,
- PackedU8x32,
-};
+// For now we use DXIL ABI enum values directly. This may change in the future.
+using dxil::ResourceKind;
+using dxil::ElementType;
class FrontendResource {
MDNode *Entry;
diff --git a/llvm/include/llvm/Support/DXILABI.h b/llvm/include/llvm/Support/DXILABI.h
index e2a8fbad16bb3f7..c1d81775b6711e3 100644
--- a/llvm/include/llvm/Support/DXILABI.h
+++ b/llvm/include/llvm/Support/DXILABI.h
@@ -39,6 +39,54 @@ enum class ParameterKind : uint8_t {
DXIL_HANDLE,
};
+/// The kind of resource for an SRV or UAV resource. Sometimes referred to as
+/// "Shape" in the DXIL docs.
+enum class ResourceKind : uint32_t {
+ Invalid = 0,
+ Texture1D,
+ Texture2D,
+ Texture2DMS,
+ Texture3D,
+ TextureCube,
+ Texture1DArray,
+ Texture2DArray,
+ Texture2DMSArray,
+ TextureCubeArray,
+ TypedBuffer,
+ RawBuffer,
+ StructuredBuffer,
+ CBuffer,
+ Sampler,
+ TBuffer,
+ RTAccelerationStructure,
+ FeedbackTexture2D,
+ FeedbackTexture2DArray,
+ NumEntries,
+};
+
+/// The element type of an SRV or UAV resource.
+enum class ElementType : uint32_t {
+ Invalid = 0,
+ I1,
+ I16,
+ U16,
+ I32,
+ U32,
+ I64,
+ U64,
+ F16,
+ F32,
+ F64,
+ SNormF16,
+ UNormF16,
+ SNormF32,
+ UNormF32,
+ SNormF64,
+ UNormF64,
+ PackedS8x32,
+ PackedU8x32,
+};
+
} // namespace dxil
} // namespace llvm
diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp b/llvm/lib/Target/DirectX/DXILResource.cpp
index 621852f2453ff51..8e5b9867e6661bf 100644
--- a/llvm/lib/Target/DirectX/DXILResource.cpp
+++ b/llvm/lib/Target/DirectX/DXILResource.cpp
@@ -21,7 +21,6 @@
using namespace llvm;
using namespace llvm::dxil;
-using namespace llvm::hlsl;
template <typename T> void ResourceTable<T>::collect(Module &M) {
NamedMDNode *Entry = M.getNamedMetadata(MDName);
@@ -30,7 +29,7 @@ template <typename T> void ResourceTable<T>::collect(Module &M) {
uint32_t Counter = 0;
for (auto *Res : Entry->operands()) {
- Data.push_back(T(Counter++, FrontendResource(cast<MDNode>(Res))));
+ Data.push_back(T(Counter++, hlsl::FrontendResource(cast<MDNode>(Res))));
}
}
@@ -42,7 +41,7 @@ template <> void ResourceTable<ConstantBuffer>::collect(Module &M) {
uint32_t Counter = 0;
for (auto *Res : Entry->operands()) {
Data.push_back(
- ConstantBuffer(Counter++, FrontendResource(cast<MDNode>(Res))));
+ ConstantBuffer(Counter++, hlsl::FrontendResource(cast<MDNode>(Res))));
}
// FIXME: share CBufferDataLayout with CBuffer load lowering.
// See https://github.com/llvm/llvm-project/issues/58381
@@ -56,7 +55,7 @@ void Resources::collect(Module &M) {
CBuffers.collect(M);
}
-ResourceBase::ResourceBase(uint32_t I, FrontendResource R)
+ResourceBase::ResourceBase(uint32_t I, hlsl::FrontendResource R)
: ID(I), GV(R.getGlobalVariable()), Name(""), Space(R.getSpace()),
LowerBound(R.getResourceIndex()), RangeSize(1) {
if (auto *ArrTy = dyn_cast<ArrayType>(GV->getValueType()))
@@ -107,83 +106,84 @@ StringRef ResourceBase::getElementTypeName(ElementType ElTy) {
llvm_unreachable("All ElementType enums are handled in switch");
}
-void ResourceBase::printElementType(Kinds Kind, ElementType ElTy,
+void ResourceBase::printElementType(ResourceKind Kind, ElementType ElTy,
unsigned Alignment, raw_ostream &OS) {
switch (Kind) {
default:
// TODO: add vector size.
OS << right_justify(getElementTypeName(ElTy), Alignment);
break;
- case Kinds::RawBuffer:
+ case ResourceKind::RawBuffer:
OS << right_justify("byte", Alignment);
break;
- case Kinds::StructuredBuffer:
+ case ResourceKind::StructuredBuffer:
OS << right_justify("struct", Alignment);
break;
- case Kinds::CBuffer:
- case Kinds::Sampler:
+ case ResourceKind::CBuffer:
+ case ResourceKind::Sampler:
OS << right_justify("NA", Alignment);
break;
- case Kinds::Invalid:
- case Kinds::NumEntries:
+ case ResourceKind::Invalid:
+ case ResourceKind::NumEntries:
break;
}
}
-StringRef ResourceBase::getKindName(Kinds Kind) {
+StringRef ResourceBase::getKindName(ResourceKind Kind) {
switch (Kind) {
- case Kinds::NumEntries:
- case Kinds::Invalid:
+ case ResourceKind::NumEntries:
+ case ResourceKind::Invalid:
return "invalid";
- case Kinds::Texture1D:
+ case ResourceKind::Texture1D:
return "1d";
- case Kinds::Texture2D:
+ case ResourceKind::Texture2D:
return "2d";
- case Kinds::Texture2DMS:
+ case ResourceKind::Texture2DMS:
return "2dMS";
- case Kinds::Texture3D:
+ case ResourceKind::Texture3D:
return "3d";
- case Kinds::TextureCube:
+ case ResourceKind::TextureCube:
return "cube";
- case Kinds::Texture1DArray:
+ case ResourceKind::Texture1DArray:
return "1darray";
- case Kinds::Texture2DArray:
+ case ResourceKind::Texture2DArray:
return "2darray";
- case Kinds::Texture2DMSArray:
+ case ResourceKind::Texture2DMSArray:
return "2darrayMS";
- case Kinds::TextureCubeArray:
+ case ResourceKind::TextureCubeArray:
return "cubearray";
- case Kinds::TypedBuffer:
+ case ResourceKind::TypedBuffer:
return "buf";
- case Kinds::RawBuffer:
+ case ResourceKind::RawBuffer:
return "rawbuf";
- case Kinds::StructuredBuffer:
+ case ResourceKind::StructuredBuffer:
return "structbuf";
- case Kinds::CBuffer:
+ case ResourceKind::CBuffer:
return "cbuffer";
- case Kinds::Sampler:
+ case ResourceKind::Sampler:
return "sampler";
- case Kinds::TBuffer:
+ case ResourceKind::TBuffer:
return "tbuffer";
- case Kinds::RTAccelerationStructure:
+ case ResourceKind::RTAccelerationStructure:
return "ras";
- case Kinds::FeedbackTexture2D:
+ case ResourceKind::FeedbackTexture2D:
return "fbtex2d";
- case Kinds::FeedbackTexture2DArray:
+ case ResourceKind::FeedbackTexture2DArray:
return "fbtex2darray";
}
- llvm_unreachable("All Kinds enums are handled in switch");
+ llvm_unreachable("All ResourceKind enums are handled in switch");
}
-void ResourceBase::printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS,
- bool SRV, bool HasCounter, uint32_t SampleCount) {
+void ResourceBase::printKind(ResourceKind Kind, unsigned Alignment,
+ raw_ostream &OS, bool SRV, bool HasCounter,
+ uint32_t SampleCount) {
switch (Kind) {
default:
OS << right_justify(getKindName(Kind), Alignment);
break;
- case Kinds::RawBuffer:
- case Kinds::StructuredBuffer:
+ case ResourceKind::RawBuffer:
+ case ResourceKind::StructuredBuffer:
if (SRV)
OS << right_justify("r/o", Alignment);
else {
@@ -193,22 +193,22 @@ void ResourceBase::printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS,
OS << right_justify("r/w+cnt", Alignment);
}
break;
- case Kinds::TypedBuffer:
+ case ResourceKind::TypedBuffer:
OS << right_justify("buf", Alignment);
break;
- case Kinds::Texture2DMS:
- case Kinds::Texture2DMSArray: {
+ case ResourceKind::Texture2DMS:
+ case ResourceKind::Texture2DMSArray: {
std::string DimName = getKindName(Kind).str();
if (SampleCount)
DimName += std::to_string(SampleCount);
OS << right_justify(DimName, Alignment);
} break;
- case Kinds::CBuffer:
- case Kinds::Sampler:
+ case ResourceKind::CBuffer:
+ case ResourceKind::Sampler:
OS << right_justify("NA", Alignment);
break;
- case Kinds::Invalid:
- case Kinds::NumEntries:
+ case ResourceKind::Invalid:
+ case ResourceKind::NumEntries:
break;
}
}
@@ -258,9 +258,9 @@ void ConstantBuffer::print(raw_ostream &OS) const {
OS << right_justify("cbuffer", 10);
- printElementType(Kinds::CBuffer, ElementType::Invalid, 8, OS);
+ printElementType(ResourceKind::CBuffer, ElementType::Invalid, 8, OS);
- printKind(Kinds::CBuffer, 12, OS, /*SRV*/ false, /*HasCounter*/ false);
+ printKind(ResourceKind::CBuffer, 12, OS, /*SRV*/ false, /*HasCounter*/ false);
// Print the binding part.
ResourceBase::print(OS, "CB", "cb");
}
diff --git a/llvm/lib/Target/DirectX/DXILResource.h b/llvm/lib/Target/DirectX/DXILResource.h
index 5f8b0badd145c1e..06902fe2b87b0ca 100644
--- a/llvm/lib/Target/DirectX/DXILResource.h
+++ b/llvm/lib/Target/DirectX/DXILResource.h
@@ -18,6 +18,7 @@
#include "llvm/Frontend/HLSL/HLSLResource.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/DXILABI.h"
#include <cstdint>
namespace llvm {
@@ -40,19 +41,19 @@ class ResourceBase {
void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;
void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const;
- using Kinds = hlsl::ResourceKind;
- static StringRef getKindName(Kinds Kind);
- static void printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS,
- bool SRV = false, bool HasCounter = false,
- uint32_t SampleCount = 0);
+ static StringRef getKindName(dxil::ResourceKind Kind);
+ static void printKind(dxil::ResourceKind Kind, unsigned Alignment,
+ raw_ostream &OS, bool SRV = false,
+ bool HasCounter = false, uint32_t SampleCount = 0);
- static StringRef getElementTypeName(hlsl::ElementType CompType);
- static void printElementType(Kinds Kind, hlsl::ElementType CompType,
- unsigned Alignment, raw_ostream &OS);
+ static StringRef getElementTypeName(dxil::ElementType CompType);
+ static void printElementType(dxil::ResourceKind Kind,
+ dxil::ElementType CompType, unsigned Alignment,
+ raw_ostream &OS);
public:
struct ExtendedProperties {
- std::optional<hlsl::ElementType> ElementType;
+ std::optional<dxil::ElementType> ElementType;
// The value ordering of this enumeration is part of the DXIL ABI. Elements
// can only be added to the end, and not removed.
@@ -68,7 +69,7 @@ class ResourceBase {
};
class UAVResource : public ResourceBase {
- ResourceBase::Kinds Shape;
+ dxil::ResourceKind Shape;
bool GloballyCoherent;
bool HasCounter;
bool IsROV;
``````````
</details>
https://github.com/llvm/llvm-project/pull/78225
More information about the llvm-branch-commits
mailing list