This change drops the use of the "Layout" type and instead uses explicit padding throughout the compiler to represent types in HLSL buffers. There are a few parts to this, though it's difficult to split them up as they're very interdependent: 1. Refactor HLSLBufferLayoutBuilder to allow us to calculate the padding of arbitrary types. 2. Teach Clang CodeGen to use HLSL specific paths for cbuffers when generating aggregate copies, array accesses, and structure accesses. 3. Simplify DXILCBufferAccesses such that it directly replaces accesses with dx.resource.getpointer rather than recalculating the layout. 4. Basic infrastructure for SPIR-V handling, but the implementation itself will need work in follow ups. Fixes several issues, including #138996, #144573, and #156084. Resolves #147352.
46 lines
1.7 KiB
HLSL
46 lines
1.7 KiB
HLSL
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
|
|
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,INLINE
|
|
|
|
int i;
|
|
|
|
__attribute__((constructor)) void call_me_first(void) {
|
|
i = 12;
|
|
}
|
|
|
|
__attribute__((constructor)) void then_call_me(void) {
|
|
i = 13;
|
|
}
|
|
|
|
__attribute__((destructor)) void call_me_last(void) {
|
|
i = 0;
|
|
}
|
|
|
|
[numthreads(1,1,1)]
|
|
void main(unsigned GI : SV_GroupIndex) {}
|
|
|
|
// Make sure global variable for ctors/dtors removed.
|
|
// CHECK-NOT:@llvm.global_ctors
|
|
// CHECK-NOT:@llvm.global_dtors
|
|
|
|
// CHECK: define void @main()
|
|
// CHECK-NEXT: entry:
|
|
// Verify function constructors are emitted
|
|
// NOINLINE-NEXT: call void @_Z13call_me_firstv()
|
|
// NOINLINE-NEXT: call void @_Z12then_call_mev()
|
|
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorFunction.hlsl()
|
|
// NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
|
|
// NOINLINE-NEXT: call void @_Z4mainj(i32 %0)
|
|
// NOINLINE-NEXT: call void @_Z12call_me_lastv(
|
|
// NOINLINE-NEXT: ret void
|
|
|
|
// Verify constructor calls are inlined when AlwaysInline is run
|
|
// INLINE-NEXT: alloca
|
|
// INLINE-NEXT: store i32 12
|
|
// INLINE-NEXT: store i32 13
|
|
// INLINE-NEXT: %[[HANDLE:.*]] = call target("dx.CBuffer", %"__cblayout_$Globals") @"llvm.dx.resource.handlefromimplicitbinding.tdx.CBuffer_s___cblayout_$Globalsst"(i32 0, i32 0, i32 1, i32 0, ptr @"$Globals.str")
|
|
// INLINE-NEXT: store target("dx.CBuffer", %"__cblayout_$Globals") %[[HANDLE]], ptr @"$Globals.cb", align 4
|
|
// INLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
|
|
// INLINE-NEXT: store i32 %
|
|
// INLINE-NEXT: store i32 0
|
|
// INLINE: ret void
|