================
@@ -1165,6 +1209,72 @@ BuiltinTypeDeclBuilder
&BuiltinTypeDeclBuilder::addLoadMethods() {
return *this;
}
+BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addSampleMethods() {
+ assert(!Record->isCompleteDefinition() && "record is already complete");
+
+ ASTContext &AST = Record->getASTContext();
+ QualType ReturnType = getFirstTemplateTypeParam();
+
+ // Look up SamplerState
+ IdentifierInfo &SamplerStateII = AST.Idents.get("SamplerState");
+ LookupResult Result(SemaRef, &SamplerStateII, SourceLocation(),
+ Sema::LookupTagName);
+ SemaRef.LookupQualifiedName(Result, Record->getDeclContext());
+ assert(!Result.empty() && "SamplerState not found");
+ QualType SamplerStateType =
+ AST.getTypeDeclType(Result.getAsSingle<TypeDecl>());
+ SemaRef.RequireCompleteType(SourceLocation(), SamplerStateType,
+ diag::err_tentative_def_incomplete_type);
+
+ // TODO: The location type depends on the texture dimension.
+ // For Texture2D it is float2.
+ QualType FloatTy = AST.FloatTy;
+ QualType Float2Ty = AST.getExtVectorType(FloatTy, 2);
+
+ QualType IntTy = AST.IntTy;
+ QualType Int2Ty = AST.getExtVectorType(IntTy, 2);
+
+ auto *RT = SamplerStateType->getAsCXXRecordDecl();
+ assert(RT);
+ assert(!RT->field_empty());
+ FieldDecl *SamplerHandleField = *RT->field_begin();
+
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+ // T Sample(SamplerState s, float2 location)
+ BuiltinTypeMethodBuilder(*this, "Sample", ReturnType)
+ .addParam("Sampler", SamplerStateType)
+ .addParam("Location", Float2Ty)
+ .accessFieldOnResource(PH::_0, SamplerHandleField)
----------------
s-perron wrote:
I should also mention I tried changing the implementation of
accessHandleFieldOnResource to look for the __handle field on the type of the
way I do in accessFieldOnResource, but that does not work when the resource
type is the same as the one being built.
That is why I ended up with two.
However, after thinking it over, I could have two cases in
.accessHandleFieldOnResource. If the assert would have triggered, then get the
field another way. I'll try doing that.
https://github.com/llvm/llvm-project/pull/177240
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits