[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
Justin Bogner via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 18 09:45:29 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.
----------------
bogner wrote:
I can't really find good documentation on what element types are really supposed to be allowed for resources, and dxc doesn't do a great job of diagnosing these things. However, it doesn't look like matrix types are supported here, at least in practice: https://hlsl.godbolt.org/z/aaze4ceYs
https://github.com/llvm/llvm-project/pull/75674
More information about the cfe-commits
mailing list