-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[HLSL] Implement SpirvType
and SpirvOpaqueType
#134034
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
Open
cassiebeckley
wants to merge
3
commits into
llvm:main
Choose a base branch
from
cassiebeckley:hlsl-spirv-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2652,6 +2652,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { | |||||||||||
bool isHLSLSpecificType() const; // Any HLSL specific type | ||||||||||||
bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type | ||||||||||||
bool isHLSLAttributedResourceType() const; | ||||||||||||
bool isHLSLInlineSpirvType() const; | ||||||||||||
bool isHLSLResourceRecord() const; | ||||||||||||
bool isHLSLIntangibleType() | ||||||||||||
const; // Any HLSL intangible type (builtin, array, class) | ||||||||||||
|
@@ -6330,6 +6331,140 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode { | |||||||||||
findHandleTypeOnResource(const Type *RT); | ||||||||||||
}; | ||||||||||||
|
||||||||||||
/// Instances of this class represent operands to a SPIR-V type instruction. | ||||||||||||
class SpirvOperand { | ||||||||||||
public: | ||||||||||||
enum SpirvOperandKind : unsigned char { | ||||||||||||
kInvalid, ///< Uninitialized. | ||||||||||||
kConstantId, ///< Integral value to represent as a SPIR-V OpConstant | ||||||||||||
///< instruction ID. | ||||||||||||
kLiteral, ///< Integral value to represent as an immediate literal. | ||||||||||||
kTypeId, ///< Type to represent as a SPIR-V type ID. | ||||||||||||
|
||||||||||||
kMax, | ||||||||||||
}; | ||||||||||||
|
||||||||||||
private: | ||||||||||||
SpirvOperandKind Kind = kInvalid; | ||||||||||||
|
||||||||||||
QualType ResultType; | ||||||||||||
llvm::APInt Value; // Signedness of constants is represented by ResultType. | ||||||||||||
|
||||||||||||
public: | ||||||||||||
SpirvOperand() : Kind(kInvalid), ResultType() {} | ||||||||||||
|
||||||||||||
SpirvOperand(SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value) | ||||||||||||
: Kind(Kind), ResultType(ResultType), Value(Value) {} | ||||||||||||
|
||||||||||||
SpirvOperand(const SpirvOperand &Other) { *this = Other; } | ||||||||||||
~SpirvOperand() {} | ||||||||||||
|
||||||||||||
SpirvOperand &operator=(const SpirvOperand &Other) { | ||||||||||||
this->Kind = Other.Kind; | ||||||||||||
this->ResultType = Other.ResultType; | ||||||||||||
this->Value = Other.Value; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
bool operator==(const SpirvOperand &Other) const { | ||||||||||||
return Kind == Other.Kind && ResultType == Other.ResultType && | ||||||||||||
Value == Other.Value; | ||||||||||||
} | ||||||||||||
|
||||||||||||
bool operator!=(const SpirvOperand &Other) const { return !(*this == Other); } | ||||||||||||
|
||||||||||||
SpirvOperandKind getKind() const { return Kind; } | ||||||||||||
|
||||||||||||
bool isValid() const { return Kind != kInvalid && Kind < kMax; } | ||||||||||||
bool isConstant() const { return Kind == kConstantId; } | ||||||||||||
bool isLiteral() const { return Kind == kLiteral; } | ||||||||||||
bool isType() const { return Kind == kTypeId; } | ||||||||||||
|
||||||||||||
llvm::APInt getValue() const { | ||||||||||||
assert((isConstant() || isLiteral()) && | ||||||||||||
"This is not an operand with a value!"); | ||||||||||||
return Value; | ||||||||||||
} | ||||||||||||
|
||||||||||||
QualType getResultType() const { | ||||||||||||
assert((isConstant() || isType()) && | ||||||||||||
"This is not an operand with a result type!"); | ||||||||||||
return ResultType; | ||||||||||||
} | ||||||||||||
|
||||||||||||
static SpirvOperand createConstant(QualType ResultType, llvm::APInt Val) { | ||||||||||||
return SpirvOperand(kConstantId, ResultType, Val); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static SpirvOperand createLiteral(llvm::APInt Val) { | ||||||||||||
return SpirvOperand(kLiteral, QualType(), Val); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static SpirvOperand createType(QualType T) { | ||||||||||||
return SpirvOperand(kTypeId, T, llvm::APSInt()); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void Profile(llvm::FoldingSetNodeID &ID) const { | ||||||||||||
ID.AddInteger(Kind); | ||||||||||||
ID.AddPointer(ResultType.getAsOpaquePtr()); | ||||||||||||
Value.Profile(ID); | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
/// Represents an arbitrary, user-specified SPIR-V type instruction. | ||||||||||||
class HLSLInlineSpirvType final | ||||||||||||
: public Type, | ||||||||||||
public llvm::FoldingSetNode, | ||||||||||||
private llvm::TrailingObjects<HLSLInlineSpirvType, SpirvOperand> { | ||||||||||||
friend class ASTContext; // ASTContext creates these | ||||||||||||
friend TrailingObjects; | ||||||||||||
|
||||||||||||
private: | ||||||||||||
uint32_t Opcode; | ||||||||||||
uint32_t Size; | ||||||||||||
uint32_t Alignment; | ||||||||||||
size_t NumOperands; | ||||||||||||
|
||||||||||||
HLSLInlineSpirvType(uint32_t Opcode, uint32_t Size, uint32_t Alignment, | ||||||||||||
ArrayRef<SpirvOperand> Operands) | ||||||||||||
: Type(HLSLInlineSpirv, QualType(), TypeDependence::None), Opcode(Opcode), | ||||||||||||
Size(Size), Alignment(Alignment), NumOperands(Operands.size()) { | ||||||||||||
for (size_t I = 0; I < NumOperands; I++) { | ||||||||||||
getTrailingObjects<SpirvOperand>()[I] = Operands[I]; | ||||||||||||
} | ||||||||||||
Comment on lines
+6432
to
+6434
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
|
||||||||||||
public: | ||||||||||||
uint32_t getOpcode() const { return Opcode; } | ||||||||||||
uint32_t getSize() const { return Size; } | ||||||||||||
uint32_t getAlignment() const { return Alignment; } | ||||||||||||
ArrayRef<SpirvOperand> getOperands() const { | ||||||||||||
return {getTrailingObjects<SpirvOperand>(), NumOperands}; | ||||||||||||
} | ||||||||||||
|
||||||||||||
bool isSugared() const { return false; } | ||||||||||||
QualType desugar() const { return QualType(this, 0); } | ||||||||||||
|
||||||||||||
void Profile(llvm::FoldingSetNodeID &ID) { | ||||||||||||
Profile(ID, Opcode, Size, Alignment, getOperands()); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static void Profile(llvm::FoldingSetNodeID &ID, uint32_t Opcode, | ||||||||||||
uint32_t Size, uint32_t Alignment, | ||||||||||||
ArrayRef<SpirvOperand> Operands) { | ||||||||||||
ID.AddInteger(Opcode); | ||||||||||||
ID.AddInteger(Size); | ||||||||||||
ID.AddInteger(Alignment); | ||||||||||||
for (auto &Operand : Operands) { | ||||||||||||
Operand.Profile(ID); | ||||||||||||
} | ||||||||||||
Comment on lines
+6458
to
+6460
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
|
||||||||||||
static bool classof(const Type *T) { | ||||||||||||
return T->getTypeClass() == HLSLInlineSpirv; | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { | ||||||||||||
friend class ASTContext; // ASTContext creates these | ||||||||||||
|
||||||||||||
|
@@ -8458,13 +8593,18 @@ inline bool Type::isHLSLBuiltinIntangibleType() const { | |||||||||||
} | ||||||||||||
|
||||||||||||
inline bool Type::isHLSLSpecificType() const { | ||||||||||||
return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType(); | ||||||||||||
return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType() || | ||||||||||||
isHLSLInlineSpirvType(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline bool Type::isHLSLAttributedResourceType() const { | ||||||||||||
return isa<HLSLAttributedResourceType>(this); | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline bool Type::isHLSLInlineSpirvType() const { | ||||||||||||
return isa<HLSLInlineSpirvType>(this); | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline bool Type::isTemplateTypeParmType() const { | ||||||||||||
return isa<TemplateTypeParmType>(CanonicalType); | ||||||||||||
} | ||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM does not use Hungarian notation (https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly).