[clang] [llvm] [HLSL][Clang][SPIRV] Improve handling of raw buffers (PR #245703)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 3 10:45:54 PST 2026
================
@@ -704,6 +704,94 @@ static llvm::Type *getAggregateType(llvm::Type *ScalarTy, QualType ArgTy) {
return ScalarTy;
}
+static Align getRawBufferAlignment(const DataLayout &DL, llvm::Type *Ty) {
+ // HLSL records are packed, so Ty's alignment is potentially bad.
+ // Instead use the guarantee that structs are aligned to that of the largest
+ // scalar element type (of vectors, arrays, or scalars themselves)
+ if (auto *ST = dyn_cast<llvm::StructType>(Ty)) {
+ Align Alignment(1);
+ for (llvm::Type *ElementTy : ST->elements())
+ Alignment = std::max(Alignment, getRawBufferAlignment(DL, ElementTy));
+ return Alignment;
+ }
+ if (auto *AT = dyn_cast<llvm::ArrayType>(Ty))
+ return getRawBufferAlignment(DL, AT->getElementType());
+ return DL.getABITypeAlign(Ty->getScalarType());
----------------
rj123-nv wrote:
This also says offset must be 8B aligned for uint64_t:
https://microsoft.github.io/hlsl-specs/proposals/0051-byte-address-buffer-alignment/
https://github.com/llvm/llvm-project/pull/245703
More information about the cfe-commits
mailing list