Skip to content
Open
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
39 changes: 7 additions & 32 deletions clang/include/clang/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,44 +233,19 @@ class HLSLAnnotationAttr : public InheritableAttr {
}
};

class HLSLSemanticAttr : public HLSLAnnotationAttr {
unsigned SemanticIndex = 0;
LLVM_PREFERRED_TYPE(bool)
unsigned SemanticIndexable : 1;
LLVM_PREFERRED_TYPE(bool)
unsigned SemanticExplicitIndex : 1;

Decl *TargetDecl = nullptr;

class HLSLSemanticBaseAttr : public HLSLAnnotationAttr {
protected:
HLSLSemanticAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
attr::Kind AK, bool IsLateParsed,
bool InheritEvenIfAlreadyPresent, bool SemanticIndexable)
HLSLSemanticBaseAttr(ASTContext &Context,
const AttributeCommonInfo &CommonInfo, attr::Kind AK,
bool IsLateParsed, bool InheritEvenIfAlreadyPresent)
: HLSLAnnotationAttr(Context, CommonInfo, AK, IsLateParsed,
InheritEvenIfAlreadyPresent) {
this->SemanticIndexable = SemanticIndexable;
this->SemanticExplicitIndex = false;
}
InheritEvenIfAlreadyPresent) {}

public:
bool isSemanticIndexable() const { return SemanticIndexable; }

void setSemanticIndex(unsigned SemanticIndex) {
this->SemanticIndex = SemanticIndex;
this->SemanticExplicitIndex = true;
}

unsigned getSemanticIndex() const { return SemanticIndex; }

bool isSemanticIndexExplicit() const { return SemanticExplicitIndex; }

void setTargetDecl(Decl *D) { TargetDecl = D; }
Decl *getTargetDecl() const { return TargetDecl; }

// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() >= attr::FirstHLSLSemanticAttr &&
A->getKind() <= attr::LastHLSLSemanticAttr;
return A->getKind() >= attr::FirstHLSLSemanticBaseAttr &&
A->getKind() <= attr::LastHLSLSemanticBaseAttr;
}
};

Expand Down
44 changes: 17 additions & 27 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -779,18 +779,6 @@ class DeclOrStmtAttr : InheritableAttr;
/// An attribute class for HLSL Annotations.
class HLSLAnnotationAttr : InheritableAttr;

class HLSLSemanticAttr<bit Indexable> : HLSLAnnotationAttr {
bit SemanticIndexable = Indexable;
int SemanticIndex = 0;
bit SemanticExplicitIndex = 0;

let Spellings = [];
let Subjects = SubjectList<[ParmVar, Field, Function]>;
let LangOpts = [HLSL];
let Args = [DeclArgument<Named, "Target">, IntArgument<"SemanticIndex">,
BoolArgument<"SemanticExplicitIndex">];
}

/// A target-specific attribute. This class is meant to be used as a mixin
/// with InheritableAttr or Attr depending on the attribute's needs.
class TargetSpecificAttr<TargetSpec target> {
Expand Down Expand Up @@ -5017,28 +5005,30 @@ def HLSLUnparsedSemantic : HLSLAnnotationAttr {
let Documentation = [InternalOnly];
}

def HLSLUserSemantic : HLSLSemanticAttr</* Indexable= */ 1> {
let Documentation = [InternalOnly];
}
class HLSLSemanticBaseAttr : HLSLAnnotationAttr {
int SemanticIndex = 0;

def HLSLSV_Position : HLSLSemanticAttr</* Indexable= */ 1> {
let Documentation = [HLSLSV_PositionDocs];
let Spellings = [];
let Subjects = SubjectList<[ParmVar, Field, Function]>;
let LangOpts = [HLSL];
}

def HLSLSV_GroupThreadID : HLSLSemanticAttr</* Indexable= */ 0> {
let Documentation = [HLSLSV_GroupThreadIDDocs];
}
def HLSLParsedSemantic : HLSLSemanticBaseAttr {
let Spellings = [];
let Subjects = SubjectList<[ParmVar, Field, Function]>;
let LangOpts = [HLSL];
let Documentation = [InternalOnly];

def HLSLSV_GroupID : HLSLSemanticAttr</* Indexable= */ 0> {
let Documentation = [HLSLSV_GroupIDDocs];
let Args = [StringArgument<"SemanticName">, IntArgument<"SemanticIndex">];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the inheritance works, but could this be part of the base class? Both children of the base class have the same arguments.

}

def HLSLSV_GroupIndex : HLSLSemanticAttr</* Indexable= */ 0> {
let Documentation = [HLSLSV_GroupIndexDocs];
}
def HLSLAppliedSemantic : HLSLSemanticBaseAttr {
let Spellings = [];
let Subjects = SubjectList<[ParmVar, Field, Function]>;
let LangOpts = [HLSL];
let Documentation = [InternalOnly];

def HLSLSV_DispatchThreadID : HLSLSemanticAttr</* Indexable= */ 0> {
let Documentation = [HLSLSV_DispatchThreadIDDocs];
let Args = [StringArgument<"SemanticName">, IntArgument<"SemanticIndex">];
}

def HLSLPackOffset: HLSLAnnotationAttr {
Expand Down
61 changes: 0 additions & 61 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -8672,38 +8672,6 @@ randomized.
}];
}

def HLSLSV_GroupThreadIDDocs : Documentation {
let Category = DocHLSLSemantics;
let Content = [{
The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which
individual thread within a thread group is executing in. This attribute is
only supported in compute shaders.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid
}];
}

def HLSLSV_GroupIDDocs : Documentation {
let Category = DocHLSLSemantics;
let Content = [{
The ``SV_GroupID`` semantic, when applied to an input parameter, specifies which
thread group a shader is executing in. This attribute is only supported in compute shaders.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid
}];
}

def HLSLSV_GroupIndexDocs : Documentation {
let Category = DocHLSLSemantics;
let Content = [{
The ``SV_GroupIndex`` semantic, when applied to an input parameter, specifies a
data binding to map the group index to the specified parameter. This attribute
is only supported in compute shaders.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupindex
}];
}

def HLSLResourceBindingDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Expand Down Expand Up @@ -8750,35 +8718,6 @@ The full documentation is available here: https://learn.microsoft.com/en-us/wind
}];
}

def HLSLSV_DispatchThreadIDDocs : Documentation {
let Category = DocHLSLSemantics;
let Content = [{
The ``SV_DispatchThreadID`` semantic, when applied to an input parameter,
specifies a data binding to map the global thread offset within the Dispatch
call (per dimension of the group) to the specified parameter.
When applied to a field of a struct, the data binding is specified to the field
when the struct is used as a parameter type.
The semantic on the field is ignored when not used as a parameter.
This attribute is only supported in compute shaders.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-dispatchthreadid
}];
}

def HLSLSV_PositionDocs : Documentation {
let Category = DocHLSLSemantics;
let Content = [{
The ``SV_Position`` semantic, when applied to an input parameter in a pixel
shader, contains the location of the pixel center (x, y) in screen space.
This semantic can be applied to the parameter, or a field in a struct used
as an input parameter.
This attribute is supported as an input in pixel, hull, domain and mesh shaders.
This attribute is supported as an output in vertex, geometry and domain shaders.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
}];
}

def HLSLGroupSharedAddressSpaceDocs : Documentation {
let Category = DocCatVariable;
let Content = [{
Expand Down
29 changes: 11 additions & 18 deletions clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,11 @@ class SemaHLSL : public SemaBase {
bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL);

template <typename T>
T *createSemanticAttr(const AttributeCommonInfo &ACI, NamedDecl *TargetDecl,
T *createSemanticAttr(const AttributeCommonInfo &ACI,
std::optional<unsigned> Location) {
T *Attr =
::new (getASTContext()) T(getASTContext(), ACI, TargetDecl,
Location.value_or(0), Location.has_value());

if (!Attr->isSemanticIndexable() && Location.has_value()) {
Diag(Attr->getLocation(), diag::err_hlsl_semantic_indexing_not_supported)
<< Attr->getAttrName()->getName();
return nullptr;
}
return Attr;
return ::new (getASTContext())
T(getASTContext(), ACI, ACI.getAttrName()->getName(),
Location.value_or(0));
}

void diagnoseSystemSemanticAttr(Decl *D, const ParsedAttr &AL,
Expand Down Expand Up @@ -247,7 +240,7 @@ class SemaHLSL : public SemaBase {
IdentifierInfo *RootSigOverrideIdent = nullptr;

struct SemanticInfo {
HLSLSemanticAttr *Semantic;
HLSLParsedSemanticAttr *Semantic;
std::optional<uint32_t> Index;
};

Expand All @@ -257,14 +250,14 @@ class SemaHLSL : public SemaBase {
const RecordType *RT);

void checkSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
const HLSLSemanticAttr *SemanticAttr);
HLSLSemanticAttr *createSemantic(const SemanticInfo &Semantic,
DeclaratorDecl *TargetDecl);
bool determineActiveSemanticOnScalar(FunctionDecl *FD, DeclaratorDecl *D,
const HLSLAppliedSemanticAttr *SemanticAttr);
bool determineActiveSemanticOnScalar(FunctionDecl *FD,
DeclaratorDecl *OutputDecl,
DeclaratorDecl *D,
SemanticInfo &ActiveSemantic,
llvm::StringSet<> &ActiveInputSemantics);
bool determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
SemanticInfo &ActiveSemantic,
bool determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *OutputDecl,
DeclaratorDecl *D, SemanticInfo &ActiveSemantic,
llvm::StringSet<> &ActiveInputSemantics);

void processExplicitBindingsOnDecl(VarDecl *D);
Expand Down
Loading