- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
          [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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      78ac1bc
              
                [HLSL] Implement `SpirvType` and `SpirvOpaqueType`
              
              
                cassiebeckley 7bdc924
              
                Fix formatting; remove unused code
              
              
                cassiebeckley ca2ad04
              
                Fix tests on Linux
              
              
                cassiebeckley 34aad15
              
                Merge remote-tracking branch 'upstream/main' into hlsl-spirv-type
              
              
                cassiebeckley 2ff6f95
              
                Fix canonicalization and alignment after merge
              
              
                cassiebeckley 5dd5db9
              
                Coding style fixes and remove invalid assert
              
              
                cassiebeckley decfbb0
              
                Test fixes and reorganization
              
              
                cassiebeckley 0938b19
              
                Merge remote-tracking branch 'upstream/main' into hlsl-spirv-type
              
              
                cassiebeckley 5a74592
              
                Update AST test with changes to canonicalization and type printing
              
              
                cassiebeckley 62b8888
              
                Fix ASan failures by manually calling SpirvOperand constructor
              
              
                cassiebeckley 2094ec7
              
                Merge remote-tracking branch 'upstream/main' into hlsl-spirv-type
              
              
                cassiebeckley 7d8e369
              
                Remove unneeded variable and fix Windows failure
              
              
                cassiebeckley 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 | 
|---|---|---|
|  | @@ -2688,6 +2688,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) | ||
|  | @@ -6361,6 +6362,143 @@ 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 { | ||
| Invalid, ///< Uninitialized. | ||
| ConstantId, ///< Integral value to represent as a SPIR-V OpConstant | ||
| ///< instruction ID. | ||
| Literal, ///< Integral value to represent as an immediate literal. | ||
| TypeId, ///< Type to represent as a SPIR-V type ID. | ||
|  | ||
| Max, | ||
| }; | ||
|  | ||
| private: | ||
| SpirvOperandKind Kind = Invalid; | ||
|  | ||
| QualType ResultType; | ||
| llvm::APInt Value; // Signedness of constants is represented by ResultType. | ||
|  | ||
| public: | ||
| SpirvOperand() : Kind(Invalid), ResultType(), Value() {} | ||
|  | ||
| SpirvOperand(SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value) | ||
| : Kind(Kind), ResultType(ResultType), Value(Value) {} | ||
|  | ||
| SpirvOperand(const SpirvOperand &Other) { *this = Other; } | ||
| ~SpirvOperand() {} | ||
| 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. It would have been better to just default this. | ||
|  | ||
| 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 != Invalid && Kind < Max; } | ||
| bool isConstant() const { return Kind == ConstantId; } | ||
| bool isLiteral() const { return Kind == Literal; } | ||
| bool isType() const { return Kind == TypeId; } | ||
|  | ||
| 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(ConstantId, ResultType, Val); | ||
| } | ||
|  | ||
| static SpirvOperand createLiteral(llvm::APInt Val) { | ||
| return SpirvOperand(Literal, QualType(), Val); | ||
| } | ||
|  | ||
| static SpirvOperand createType(QualType T) { | ||
| return SpirvOperand(TypeId, 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++) { | ||
| // Since Operands are stored as a trailing object, they have not been | ||
| // initialized yet. Call the constructor manually. | ||
| auto *Operand = | ||
| new (&getTrailingObjects<SpirvOperand>()[I]) SpirvOperand(); | ||
| *Operand = Operands[I]; | ||
| } | ||
| } | ||
|  | ||
| 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); | ||
| } | ||
|  | ||
| static bool classof(const Type *T) { | ||
| return T->getTypeClass() == HLSLInlineSpirv; | ||
| } | ||
| }; | ||
|  | ||
| class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { | ||
| friend class ASTContext; // ASTContext creates these | ||
|  | ||
|  | @@ -8486,13 +8624,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.
Seems like we could have just defaulted this