Skip to content

[DirectX] Move ResourceClass enum into DXILABI. NFC #96335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
// possible values, and a list of enumerators to map them to.
class EnumArgument<string name, string type, bit is_string, list<string> values,
list<string> enums, bit opt = 0, bit fake = 0,
bit isExternalType = 0>
bit isExternalType = 0, bit isCovered = 1>
: Argument<name, opt, fake> {
string Type = type;
// When true, the argument will be parsed as an unevaluated string literal
Expand All @@ -296,13 +296,16 @@ class EnumArgument<string name, string type, bit is_string, list<string> values,
list<string> Values = values;
list<string> Enums = enums;
bit IsExternalType = isExternalType;
// We need to know whether an external enum is fully covered by the options
// in order to decide whether to emit unreachable default labels in a switch.
bit IsCovered = isCovered;
}

// FIXME: There should be a VariadicArgument type that takes any other type
// of argument and generates the appropriate type.
class VariadicEnumArgument<string name, string type, bit is_string,
list<string> values, list<string> enums,
bit isExternalType = 0>
bit isExternalType = 0, bit isCovered = 1>
: Argument<name, 1> {
string Type = type;
// When true, the argument will be parsed as an unevaluated string literal
Expand All @@ -311,6 +314,9 @@ class VariadicEnumArgument<string name, string type, bit is_string,
list<string> Values = values;
list<string> Enums = enums;
bit IsExternalType = isExternalType;
// We need to know whether an external enum is fully covered by the options
// in order to decide whether to emit unreachable default labels in a switch.
bit IsCovered = isCovered;
}

// Represents an attribute wrapped by another attribute.
Expand Down Expand Up @@ -2913,7 +2919,7 @@ def CodeModel : InheritableAttr, TargetSpecificAttr<TargetLoongArch> {
let Spellings = [GCC<"model">];
let Args = [EnumArgument<"Model", "llvm::CodeModel::Model", /*is_string=*/1,
["normal", "medium", "extreme"], ["Small", "Medium", "Large"],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>];
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>];
let Subjects = SubjectList<[NonTLSGlobalVar], ErrorDiag>;
let Documentation = [CodeModelDocs];
}
Expand Down Expand Up @@ -4472,7 +4478,7 @@ def HLSLShader : InheritableAttr {
["Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
"RayGeneration", "Intersection", "AnyHit", "ClosestHit",
"Miss", "Callable", "Mesh", "Amplification"],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>
];
let Documentation = [HLSLSV_ShaderTypeAttrDocs];
let AdditionalMembers =
Expand All @@ -4487,30 +4493,31 @@ def HLSLResource : InheritableAttr {
let Spellings = [];
let Subjects = SubjectList<[Struct]>;
let LangOpts = [HLSL];
let Args = [EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
/*is_string=*/0,
["SRV", "UAV", "CBuffer", "Sampler"],
["SRV", "UAV", "CBuffer", "Sampler"],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>,
EnumArgument<"ResourceKind", "llvm::hlsl::ResourceKind",
/*is_string=*/0,
["Texture1D", "Texture2D", "Texture2DMS",
"Texture3D", "TextureCube", "Texture1DArray",
"Texture2DArray", "Texture2DMSArray",
"TextureCubeArray", "TypedBuffer", "RawBuffer",
"StructuredBuffer", "CBuffer", "Sampler",
"TBuffer", "RTAccelerationStructure",
"FeedbackTexture2D", "FeedbackTexture2DArray"],
["Texture1D", "Texture2D", "Texture2DMS",
"Texture3D", "TextureCube", "Texture1DArray",
"Texture2DArray", "Texture2DMSArray",
"TextureCubeArray", "TypedBuffer", "RawBuffer",
"StructuredBuffer", "CBuffer", "Sampler",
"TBuffer", "RTAccelerationStructure",
"FeedbackTexture2D", "FeedbackTexture2DArray"],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>,
DefaultBoolArgument<"isROV", /*default=*/0>
];
let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
/*is_string=*/0, ["SRV", "UAV", "CBuffer", "Sampler"],
["SRV", "UAV", "CBuffer", "Sampler"],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>,
EnumArgument<
"ResourceKind", "llvm::hlsl::ResourceKind",
/*is_string=*/0,
[
"Texture1D", "Texture2D", "Texture2DMS", "Texture3D", "TextureCube",
"Texture1DArray", "Texture2DArray", "Texture2DMSArray",
"TextureCubeArray", "TypedBuffer", "RawBuffer", "StructuredBuffer",
"CBuffer", "Sampler", "TBuffer", "RTAccelerationStructure",
"FeedbackTexture2D", "FeedbackTexture2DArray"
],
[
"Texture1D", "Texture2D", "Texture2DMS", "Texture3D", "TextureCube",
"Texture1DArray", "Texture2DArray", "Texture2DMSArray",
"TextureCubeArray", "TypedBuffer", "RawBuffer", "StructuredBuffer",
"CBuffer", "Sampler", "TBuffer", "RTAccelerationStructure",
"FeedbackTexture2D", "FeedbackTexture2DArray"
],
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>,
DefaultBoolArgument<"isROV", /*default=*/0>
];
let Documentation = [InternalOnly];
}

Expand Down
19 changes: 15 additions & 4 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,15 @@ namespace {
StringRef shortType;
std::vector<StringRef> values, enums, uniques;
bool isExternal;
bool isCovered;

public:
EnumArgument(const Record &Arg, StringRef Attr)
: Argument(Arg, Attr), values(Arg.getValueAsListOfStrings("Values")),
enums(Arg.getValueAsListOfStrings("Enums")),
uniques(uniqueEnumsInOrder(enums)),
isExternal(Arg.getValueAsBit("IsExternalType")) {
isExternal(Arg.getValueAsBit("IsExternalType")),
isCovered(Arg.getValueAsBit("IsCovered")) {
StringRef Type = Arg.getValueAsString("Type");
shortType = isExternal ? Type.rsplit("::").second : Type;
// If shortType didn't contain :: at all rsplit will give us an empty
Expand Down Expand Up @@ -993,7 +995,7 @@ namespace {
OS << " OS << \" " << I << "\";\n";
OS << " break;\n";
}
if (isExternal) {
if (!isCovered) {
OS << " default:\n";
OS << " llvm_unreachable(\"Invalid attribute value\");\n";
}
Expand Down Expand Up @@ -1036,7 +1038,7 @@ namespace {
OS << " case " << fullType << "::" << enums[I] << ": return \""
<< values[I] << "\";\n";
}
if (isExternal) {
if (!isCovered) {
OS << " default: llvm_unreachable(\"Invalid attribute value\");\n";
}
OS << " }\n"
Expand All @@ -1050,6 +1052,7 @@ namespace {
StringRef shortType;
std::vector<StringRef> values, enums, uniques;
bool isExternal;
bool isCovered;

protected:
void writeValueImpl(raw_ostream &OS) const override {
Expand All @@ -1068,7 +1071,8 @@ namespace {
values(Arg.getValueAsListOfStrings("Values")),
enums(Arg.getValueAsListOfStrings("Enums")),
uniques(uniqueEnumsInOrder(enums)),
isExternal(Arg.getValueAsBit("IsExternalType")) {
isExternal(Arg.getValueAsBit("IsExternalType")),
isCovered(Arg.getValueAsBit("IsCovered")) {
StringRef Type = Arg.getValueAsString("Type");
shortType = isExternal ? Type.rsplit("::").second : Type;
// If shortType didn't contain :: at all rsplit will give us an empty
Expand Down Expand Up @@ -1111,6 +1115,10 @@ namespace {
OS << " OS << \" " << UI << "\";\n";
OS << " break;\n";
}
if (!isCovered) {
OS << " default:\n";
OS << " llvm_unreachable(\"Invalid attribute value\");\n";
}
OS << " }\n";
OS << " }\n";
}
Expand Down Expand Up @@ -1168,6 +1176,9 @@ namespace {
OS << " case " << fullType << "::" << enums[I] << ": return \""
<< values[I] << "\";\n";
}
if (!isCovered) {
OS << " default: llvm_unreachable(\"Invalid attribute value\");\n";
}
OS << " }\n"
<< " llvm_unreachable(\"No enumerator with that value\");\n"
<< "}\n";
Expand Down
10 changes: 1 addition & 9 deletions llvm/include/llvm/Frontend/HLSL/HLSLResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ class GlobalVariable;

namespace hlsl {

enum class ResourceClass : uint8_t {
SRV = 0,
UAV,
CBuffer,
Sampler,
Invalid,
NumClasses = Invalid,
};

// For now we use DXIL ABI enum values directly. This may change in the future.
using dxil::ResourceClass;
using dxil::ElementType;
using dxil::ResourceKind;

Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/Support/DXILABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ enum class ParameterKind : uint8_t {
DXILHandle,
};

enum class ResourceClass : uint8_t {
SRV = 0,
UAV,
CBuffer,
Sampler,
};

/// The kind of resource for an SRV or UAV resource. Sometimes referred to as
/// "Shape" in the DXIL docs.
enum class ResourceKind : uint32_t {
Expand Down
Loading