diff options
author | Joshua Batista <jbatista@microsoft.com> | 2024-07-12 13:10:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-12 13:10:34 -0700 |
commit | 5dc371e289584928345f74f560a18a805226b5f8 (patch) | |
tree | 7640d9ee590a268b941573d8ca6a93a51f911b08 /clang/lib/Sema | |
parent | eb27256850ad792a287a8547c88410b7cf1bcb42 (diff) | |
download | llvm-5dc371e289584928345f74f560a18a805226b5f8.zip llvm-5dc371e289584928345f74f560a18a805226b5f8.tar.gz llvm-5dc371e289584928345f74f560a18a805226b5f8.tar.bz2 |
[HLSL] Split out resource class data from resource attribute (#98419)
The ability to spell out and specify the resource class is necessary for
testing various resource binding behaviors. Though it is not intended
for users to use this in customized HLSL source code, the ability to
specify the resource class via an attribute is immensely helpful for
writing thorough tests.
This PR introduces a new attribute, hlsl::resource_attribute, that can
only be applied on structs. This attribute only has 1 required argument,
and must be one of:
```
SRV
UAV
CBuffer
Sampler
```
By applying this attribute to a struct, the struct will have the
`HLSLResourceClassAttr` attribute attached to it in the AST
representation, which provides information on the type of resource class
the struct is meant to be.
The resource class data that was originally contained within the
`HLSLResourceAttr` attribute has been removed in favor of this new
attribute, and so certain ast-dump tests need to be modified so that the
same information can be represented via 2 attributes instead of one.
Fixes #98193
---------
Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/HLSLExternalSemaSource.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaHLSL.cpp | 22 |
3 files changed, 32 insertions, 6 deletions
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index a2b29a7..7fcf575 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -115,12 +115,14 @@ struct BuiltinTypeDeclBuilder { return addMemberVariable("h", Ty, Access); } - BuiltinTypeDeclBuilder &annotateResourceClass(ResourceClass RC, - ResourceKind RK, bool IsROV) { + BuiltinTypeDeclBuilder &annotateHLSLResource(ResourceClass RC, + ResourceKind RK, bool IsROV) { if (Record->isCompleteDefinition()) return *this; - Record->addAttr(HLSLResourceAttr::CreateImplicit(Record->getASTContext(), - RC, RK, IsROV)); + Record->addAttr( + HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC)); + Record->addAttr( + HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RK, IsROV)); return *this; } @@ -171,7 +173,6 @@ struct BuiltinTypeDeclBuilder { DeclRefExpr *Fn = lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle"); - Expr *RCExpr = emitResourceClassExpr(AST, RC); Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue, SourceLocation(), FPOptionsOverride()); @@ -496,7 +497,7 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, return BuiltinTypeDeclBuilder(Decl) .addHandleMember() .addDefaultHandleConstructor(S, RC) - .annotateResourceClass(RC, RK, IsROV); + .annotateHLSLResource(RC, RK, IsROV); } void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index f2cd46d..20f46c0 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7053,6 +7053,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLResourceBinding: S.HLSL().handleResourceBindingAttr(D, AL); break; + case ParsedAttr::AT_HLSLResourceClass: + S.HLSL().handleResourceClassAttr(D, AL); + break; case ParsedAttr::AT_HLSLParamModifier: S.HLSL().handleParamModifierAttr(D, AL); break; diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index babb984..9940bc5 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -437,6 +437,28 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr &AL) { D->addAttr(NewAttr); } +void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) { + if (!AL.isArgIdent(0)) { + Diag(AL.getLoc(), diag::err_attribute_argument_type) + << AL << AANT_ArgumentIdentifier; + return; + } + + IdentifierLoc *Loc = AL.getArgAsIdent(0); + StringRef Identifier = Loc->Ident->getName(); + SourceLocation ArgLoc = Loc->Loc; + + // Validate. + llvm::dxil::ResourceClass RC; + if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) { + Diag(ArgLoc, diag::warn_attribute_type_not_supported) + << "ResourceClass" << Identifier; + return; + } + + D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc)); +} + void SemaHLSL::handleResourceBindingAttr(Decl *D, const ParsedAttr &AL) { StringRef Space = "space0"; StringRef Slot = ""; |