[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)

Tex Riddell via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 10:22:03 PST 2025


================
@@ -172,6 +172,23 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
   return Result;
 }
 
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+                                                 QualType T) {
+  // Arrays and Structs are always aligned to new buffer rows
+  if (T->isArrayType() || T->isStructureType())
+    return 16;
+
+  // Vectors are aligned to the type they contain
+  if (const VectorType *VT = T->getAs<VectorType>())
+    return calculateLegacyCbufferFieldAlign(Context, VT->getElementType());
----------------
tex3d wrote:

This test would have had no difference with the change you made.  It would have looked the same as two 64-bit values, with the same locations.  I think you'll need something like this:

```hlsl
struct S6 {
  float a;
  float2 b;
};

cbuffer CB6Pass {
  S6 s6p : packoffset(c0.x);
  float f6p : packoffset(c0.w);
}
```

https://github.com/llvm/llvm-project/pull/128086


More information about the cfe-commits mailing list