-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[HLSL] GetDimensions methods for buffer resources #161929
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
Changes from all commits
8ba74ce
d42f931
c237571
3750123
e509189
2fd9c3a
135a858
c8f1da3
0add2b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,29 @@ CXXConstructorDecl *lookupCopyConstructor(QualType ResTy) { | |
| return CD; | ||
| return nullptr; | ||
| } | ||
|
|
||
| ParameterABI | ||
| convertParamModifierToParamABI(HLSLParamModifierAttr::Spelling Modifier) { | ||
| assert(Modifier != HLSLParamModifierAttr::Spelling::Keyword_in && | ||
| "HLSL 'in' parameters modifier cannot be converted to ParameterABI"); | ||
| switch (Modifier) { | ||
| case HLSLParamModifierAttr::Spelling::Keyword_out: | ||
| return ParameterABI::HLSLOut; | ||
| case HLSLParamModifierAttr::Spelling::Keyword_inout: | ||
| return ParameterABI::HLSLInOut; | ||
| default: | ||
| llvm_unreachable("Invalid HLSL parameter modifier"); | ||
| } | ||
| } | ||
|
|
||
| QualType getInoutParameterType(ASTContext &AST, QualType Ty) { | ||
| assert(!Ty->isReferenceType() && | ||
| "Pointer and reference types cannot be inout or out parameters"); | ||
| Ty = AST.getLValueReferenceType(Ty); | ||
| Ty.addRestrict(); | ||
| return Ty; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // Builder for template arguments of builtin types. Used internally | ||
|
|
@@ -430,19 +453,36 @@ BuiltinTypeMethodBuilder::addParam(StringRef Name, QualType Ty, | |
| void BuiltinTypeMethodBuilder::createDecl() { | ||
| assert(Method == nullptr && "Method or constructor is already created"); | ||
|
|
||
| // create method or constructor type | ||
| // create function prototype | ||
| ASTContext &AST = DeclBuilder.SemaRef.getASTContext(); | ||
| SmallVector<QualType> ParamTypes; | ||
| for (Param &MP : Params) | ||
| SmallVector<FunctionType::ExtParameterInfo> ParamExtInfos(Params.size()); | ||
| uint32_t ArgIndex = 0; | ||
|
|
||
| // Create function prototype. | ||
| bool UseParamExtInfo = false; | ||
| for (Param &MP : Params) { | ||
| if (MP.Modifier != HLSLParamModifierAttr::Keyword_in) { | ||
| UseParamExtInfo = true; | ||
| FunctionType::ExtParameterInfo &PI = ParamExtInfos[ArgIndex]; | ||
| ParamExtInfos[ArgIndex] = | ||
| PI.withABI(convertParamModifierToParamABI(MP.Modifier)); | ||
| if (!MP.Ty->isDependentType()) | ||
| MP.Ty = getInoutParameterType(AST, MP.Ty); | ||
| } | ||
| ParamTypes.emplace_back(MP.Ty); | ||
| ++ArgIndex; | ||
| } | ||
|
Collaborator
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. Instead of doing this on the params here, could put the attributes on the ParmVarDecls in the loop over Params below? At a minimum that would ensure that the AST for these functions matches the AST for user-written code, but it may also remove the need for the
Member
Author
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. I tried different combinations of the https://godbolt.org/z/dKn1r4v4E I'll file an issue #163648. We'll need to fix this bug first before revisiting this.
Member
Author
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. Bug fix in review: #163832 I have updated I also had a bug in how the ABI params were set (or not set, actually), which is why the function prototype string did not include the |
||
|
|
||
| FunctionProtoType::ExtProtoInfo ExtInfo; | ||
| if (UseParamExtInfo) | ||
| ExtInfo.ExtParameterInfos = ParamExtInfos.data(); | ||
| if (IsConst) | ||
| ExtInfo.TypeQuals.addConst(); | ||
|
|
||
| QualType FuncTy = AST.getFunctionType(ReturnTy, ParamTypes, ExtInfo); | ||
|
|
||
| // create method or constructor decl | ||
| // Create method or constructor declaration. | ||
| auto *TSInfo = AST.getTrivialTypeSourceInfo(FuncTy, SourceLocation()); | ||
| DeclarationNameInfo NameInfo = DeclarationNameInfo(Name, SourceLocation()); | ||
| if (IsCtor) | ||
|
|
@@ -455,7 +495,7 @@ void BuiltinTypeMethodBuilder::createDecl() { | |
| AST, DeclBuilder.Record, SourceLocation(), NameInfo, FuncTy, TSInfo, SC, | ||
| false, false, ConstexprSpecKind::Unspecified, SourceLocation()); | ||
|
|
||
| // create params & set them to the function prototype | ||
| // Create params & set them to the method/constructor and function prototype. | ||
| SmallVector<ParmVarDecl *> ParmDecls; | ||
| unsigned CurScopeDepth = DeclBuilder.SemaRef.getCurScope()->getDepth(); | ||
| auto FnProtoLoc = | ||
|
|
@@ -1258,5 +1298,37 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addConsumeMethod() { | |
| .finalize(); | ||
| } | ||
|
|
||
| BuiltinTypeDeclBuilder & | ||
| BuiltinTypeDeclBuilder::addGetDimensionsMethodForBuffer() { | ||
| using PH = BuiltinTypeMethodBuilder::PlaceHolder; | ||
| ASTContext &AST = SemaRef.getASTContext(); | ||
| QualType UIntTy = AST.UnsignedIntTy; | ||
|
|
||
| QualType HandleTy = getResourceHandleField()->getType(); | ||
| auto *AttrResTy = cast<HLSLAttributedResourceType>(HandleTy.getTypePtr()); | ||
|
|
||
| // Structured buffers except {RW}ByteAddressBuffer have overload | ||
| // GetDimensions(out uint numStructs, out uint stride). | ||
| if (AttrResTy->getAttrs().RawBuffer && | ||
| AttrResTy->getContainedType() != AST.Char8Ty) { | ||
| return BuiltinTypeMethodBuilder(*this, "GetDimensions", AST.VoidTy) | ||
| .addParam("numStructs", UIntTy, HLSLParamModifierAttr::Keyword_out) | ||
| .addParam("stride", UIntTy, HLSLParamModifierAttr::Keyword_out) | ||
| .callBuiltin("__builtin_hlsl_resource_getdimensions_x", QualType(), | ||
| PH::Handle, PH::_0) | ||
| .callBuiltin("__builtin_hlsl_resource_getstride", QualType(), | ||
| PH::Handle, PH::_1) | ||
| .finalize(); | ||
| } | ||
|
|
||
| // Typed buffers and {RW}ByteAddressBuffer have overload | ||
| // GetDimensions(out uint dim). | ||
| return BuiltinTypeMethodBuilder(*this, "GetDimensions", AST.VoidTy) | ||
| .addParam("dim", UIntTy, HLSLParamModifierAttr::Keyword_out) | ||
| .callBuiltin("__builtin_hlsl_resource_getdimensions_x", QualType(), | ||
| PH::Handle, PH::_0) | ||
| .finalize(); | ||
| } | ||
|
|
||
| } // namespace hlsl | ||
| } // namespace clang | ||
Uh oh!
There was an error while loading. Please reload this page.