[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 13:13:53 PDT 2024
================
@@ -29,19 +29,40 @@ class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
const Type *Ty) const {
- auto *BuiltinTy = dyn_cast<BuiltinType>(Ty);
- if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+ auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
+ if (!ResType)
return nullptr;
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
- // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x float>,
- // 1, 0, 0) only for now (RWBuffer<float4>); more work us needed to determine
- // the target ext type and its parameters based on the handle type
- // attributes (not yet implemented)
- llvm::FixedVectorType *ElemType =
- llvm::FixedVectorType::get(llvm::Type::getFloatTy(Ctx), 4);
- unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
- return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
+ const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+ switch (ResAttrs.ResourceClass) {
+ case llvm::dxil::ResourceClass::UAV:
+ case llvm::dxil::ResourceClass::SRV: {
+ // TypedBuffer and RawBuffer both need element type
+ QualType ContainedTy = ResType->getContainedType();
+ if (ContainedTy.isNull())
+ return nullptr;
+
+ // convert element type
+ llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
+
+ const char *TypeName =
----------------
llvm-beanz wrote:
nit:
```suggestion
llvm::StringRef TypeName =
```
https://github.com/llvm/llvm-project/pull/110327
More information about the cfe-commits
mailing list