================
@@ -1269,6 +1418,124 @@ BuiltinTypeDeclBuilder
&BuiltinTypeDeclBuilder::addLoadMethods() {
return *this;
}
+CXXRecordDecl *BuiltinTypeDeclBuilder::addMipsSliceType(ResourceDimension Dim,
+ QualType ReturnType) {
+ ASTContext &AST = Record->getASTContext();
+ uint32_t VecSize = getResourceDimensions(Dim);
+ QualType IntTy = AST.IntTy;
+ QualType IndexTy = VecSize > 1 ? AST.getExtVectorType(IntTy, VecSize) :
IntTy;
+ QualType Int3Ty = AST.getExtVectorType(IntTy, VecSize + 1);
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+ // Define the mips_slice_type which is returned by mips_type::operator[].
+ // It holds the resource handle and the mip level. It has an operator[]
+ // that takes the coordinate and performs the actual resource load.
+ CXXRecordDecl *MipSliceRecord = nullptr;
+ addPrivateNestedRecord("mips_slice_type", MipSliceRecord);
+ BuiltinTypeDeclBuilder MipSliceBuilder(SemaRef, MipSliceRecord);
+ MipSliceBuilder.addFriend(Record);
+ MipSliceBuilder.addHandleMember(getResourceAttrs().ResourceClass, Dim,
+ getResourceAttrs().IsROV, false, ReturnType,
+ AccessSpecifier::AS_public);
+ MipSliceBuilder.addMemberVariable("__level", IntTy, {},
+ AccessSpecifier::AS_public);
+
+ MipSliceBuilder.addDefaultHandleConstructor(AccessSpecifier::AS_protected)
+ .addCopyConstructor(AccessSpecifier::AS_protected)
+ .addCopyAssignmentOperator(AccessSpecifier::AS_protected);
+
+ FieldDecl *LevelField = MipSliceBuilder.Fields["__level"];
+ assert(LevelField && "Could not find the level field.\n");
+
+ DeclarationName SubscriptName =
+ AST.DeclarationNames.getCXXOperatorName(OO_Subscript);
+
+ // operator[](intN coord) on mips_slice_type
+ BuiltinTypeMethodBuilder(MipSliceBuilder, SubscriptName, ReturnType,
+ /*IsConst=*/true)
+ .addParam("Coord", IndexTy)
+ .accessFieldOnResource(PH::This, LevelField)
+ .concat(PH::_0, PH::LastStmt, Int3Ty)
+ .callBuiltin("__builtin_hlsl_resource_load_level", ReturnType,
PH::Handle,
+ PH::LastStmt)
+ .finalize();
+
+ MipSliceBuilder.completeDefinition();
+ return MipSliceRecord;
+}
+
+CXXRecordDecl *BuiltinTypeDeclBuilder::addMipsType(ResourceDimension Dim,
+ QualType ReturnType) {
+ ASTContext &AST = Record->getASTContext();
+ QualType IntTy = AST.IntTy;
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+ // First, define the mips_slice_type that will be returned by our operator[].
+ CXXRecordDecl *MipSliceRecord = addMipsSliceType(Dim, ReturnType);
+
+ // Define the mips_type, which provides the syntax `Resource.mips[level]`.
+ // It only holds the handle, and its operator[] returns a mips_slice_type
+ // initialized with the handle and the requested mip level.
+ CXXRecordDecl *MipRecord = nullptr;
+ addPrivateNestedRecord("mips_type", MipRecord);
+ BuiltinTypeDeclBuilder MipBuilder(SemaRef, MipRecord);
+ MipBuilder.addFriend(Record);
+ MipBuilder.addHandleMember(getResourceAttrs().ResourceClass, Dim,
+ getResourceAttrs().IsROV, false, ReturnType,
+ AccessSpecifier::AS_public);
+
+ MipBuilder.addDefaultHandleConstructor(AccessSpecifier::AS_protected)
+ .addCopyConstructor(AccessSpecifier::AS_protected)
+ .addCopyAssignmentOperator(AccessSpecifier::AS_protected);
----------------
Keenuts wrote:
If you chain above, chain here too
https://github.com/llvm/llvm-project/pull/186143
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits