================ @@ -323,6 +327,83 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getOpenCLType(CodeGenModule &CGM, return nullptr; } +llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM, + const Type *Ty) const { + auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty); + if (!ResType) + return nullptr; + + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + 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; + + assert(!ResAttrs.RawBuffer && + "Raw buffers handles are not implemented for SPIR-V yet"); + assert(!ResAttrs.IsROV && + "Rasterizer order views not implemented for SPIR-V yet"); + + // convert element type + llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy); + return getSPIRVImageTypeFromHLSLResource(ResAttrs, ElemType, Ctx); + } + case llvm::dxil::ResourceClass::CBuffer: + llvm_unreachable("CBuffer handles are not implemented for SPIR-V yet"); + break; + case llvm::dxil::ResourceClass::Sampler: + return llvm::TargetExtType::get(Ctx, "spirv.Sampler"); + } + return nullptr; +} + +llvm::Type *CommonSPIRTargetCodeGenInfo::getSPIRVImageTypeFromHLSLResource( + const HLSLAttributedResourceType::Attributes &attributes, + llvm::Type *ElementType, llvm::LLVMContext &Ctx) const { + + if (ElementType->isVectorTy()) { + ElementType = ElementType->getScalarType(); + } + + if (!ElementType->isIntegerTy() && !ElementType->isFloatingPointTy()) { + // TODO: Should there be an error message? + ElementType->dump(); + assert(false && "Bad element type"); + return nullptr; + } + + // For HLSL types, the depth is always 2. + SmallVector<unsigned, 6> IntParams = {0, 2, 0, 0, 1, 0}; ---------------- Keenuts wrote:
Since those are written just below, I'd just set this to `= { 0 }` instead, and then explain each bit as you do. In addition, maybe a comment saying those are listed in https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypeImage ? https://github.com/llvm/llvm-project/pull/114273 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits