[clang] [HLSL] Implement Texture2D::mips[][] (PR #186143)
Nathan Gauër via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 06:47:18 PDT 2026
================
@@ -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);
----------------
Keenuts wrote:
Those can all be chained
```suggestion
BuiltinTypeDeclBuilder MipSliceBuilder(SemaRef, MipSliceRecord)
.addDefaultHandleConstructor(AccessSpecifier::AS_protected)
.addCopyConstructor(AccessSpecifier::AS_protected)
.addCopyAssignmentOperator(AccessSpecifier::AS_protected);
.addFriend(Record);
.addHandleMember(getResourceAttrs().ResourceClass, Dim,
getResourceAttrs().IsROV, false, ReturnType,
AccessSpecifier::AS_public);
.addMemberVariable("__level", IntTy, {}, AccessSpecifier::AS_public);
```
https://github.com/llvm/llvm-project/pull/186143
More information about the cfe-commits
mailing list