[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
David Peixotto via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 16:59:59 PST 2023
================
@@ -216,15 +214,62 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
assert(false && "Unsupported buffer type!");
return;
}
-
assert(ResourceMD != nullptr &&
"ResourceMD must have been set by the switch above.");
llvm::hlsl::FrontendResource Res(
- GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+ GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
ResourceMD->addOperand(Res.getMetadata());
}
+static llvm::hlsl::ElementType
+calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) {
+ using llvm::hlsl::ElementType;
+
+ // TODO: We may need to update this when we add things like ByteAddressBuffer
+ // that don't have a template parameter (or, indeed, an element type).
+ const auto *TST = ResourceTy->getAs<TemplateSpecializationType>();
+ assert(TST && "Resource types must be template specializations");
+ ArrayRef<TemplateArgument> Args = TST->template_arguments();
+ assert(!Args.empty() && "Resource has no element type");
+
+ // At this point we have a resource with an element type, so we can assume
+ // that it's valid or we would have diagnosed the error earlier.
+ QualType ElTy = Args[0].getAsType();
+
+ // We should either have a basic type or a vector of a basic type.
----------------
dmpots wrote:
What about matrix types? Do we need to handle them here as well?
https://github.com/llvm/llvm-project/pull/75674
More information about the llvm-commits
mailing list