llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Farzon Lotfi (farzonl) <details> <summary>Changes</summary> fixes https://github.com/llvm/llvm-project/issues/179834 Change defines Matrix alignment as buffer row length (16). Same as arrays and structs. Change also adds tests for matrix, matrix in structs, & arrays. --- Full diff: https://github.com/llvm/llvm-project/pull/179836.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaHLSL.cpp (+2-2) - (added) clang/test/CodeGenHLSL/resources/cbuffer_matrix_align.hlsl (+71) ``````````diff diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 3e99a8f7d89d1..7dc8a4c7437e3 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -219,8 +219,8 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer, static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context, QualType T) { - // Arrays and Structs are always aligned to new buffer rows - if (T->isArrayType() || T->isStructureType()) + // Arrays, Matrices, and Structs are always aligned to new buffer rows + if (T->isArrayType() || T->isStructureType() || T->isConstantMatrixType()) return 16; // Vectors are aligned to the type they contain diff --git a/clang/test/CodeGenHLSL/resources/cbuffer_matrix_align.hlsl b/clang/test/CodeGenHLSL/resources/cbuffer_matrix_align.hlsl new file mode 100644 index 0000000000000..ff4ce0f104f44 --- /dev/null +++ b/clang/test/CodeGenHLSL/resources/cbuffer_matrix_align.hlsl @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fsyntax-only -verify -verify-ignore-unexpected=warning + +cbuffer MatArr0Pass { + float2x4 A0p[2] : packoffset(c0.x); + float a0tail : packoffset(c4.x); +} + +cbuffer MatArr0Fail { + float2x4 A0f[2] : packoffset(c0.x); + float a0bad : packoffset(c1.w); + // expected-error@-1 {{packoffset overlap between 'a0bad', 'A0f'}} +} + +// Struct containing a matrix. + +struct MS0 { + float2x4 M; + float2 V; +}; + +cbuffer MatStruct0Pass { + MS0 s0p : packoffset(c0.x); + float s0tail: packoffset(c5.x); +} + +cbuffer MatStruct0Fail { + MS0 s0f : packoffset(c0.x); + float s0bad : packoffset(c0.y); + // expected-error@-1 {{packoffset overlap between 's0bad', 's0f'}} +} + +// Nested struct containing a matrix. +struct Inner0 { + float2x4 M; + float F; +}; + +struct Outer0 { + float2 Head; + Inner0 I; + float2 Tail; +}; + +cbuffer MatNested0Pass { + Outer0 o0p : packoffset(c0.x); + float o0tail: packoffset(c8.x); +} + +cbuffer MatNested0Fail { + Outer0 o0f : packoffset(c0.x); + float o0bad: packoffset(c3.y); + // expected-error@-1 {{packoffset overlap between 'o0bad', 'o0f'}} +} + +// Array-of-struct where struct contains a matrix. + +struct AMS0 { + float2x4 M; + float2 V; +}; + +cbuffer MatArrStruct0Pass { + AMS0 as0p[2] : packoffset(c0.x); + float as0tail : packoffset(c10.x); +} + +cbuffer MatArrStruct0Fail { + AMS0 as0f[2] : packoffset(c0.x); + float as0bad : packoffset(c4.z); + // expected-error@-1 {{packoffset overlap between 'as0bad', 'as0f'}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/179836 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
