| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s |
| 2 |
|
| 3 |
struct EmptyStruct { |
| 4 |
}; |
| 5 |
|
| 6 |
struct A { |
| 7 |
float a; |
| 8 |
}; |
| 9 |
|
| 10 |
struct B { |
| 11 |
RWBuffer<float> buf; |
| 12 |
EmptyStruct es; |
| 13 |
float ea[0]; |
| 14 |
float a; |
| 15 |
}; |
| 16 |
|
| 17 |
struct C { |
| 18 |
EmptyStruct es; |
| 19 |
}; |
| 20 |
|
| 21 |
typedef B BTypedef; |
| 22 |
typedef C CTypedef; |
| 23 |
|
| 24 |
struct D : B { |
| 25 |
float b; |
| 26 |
}; |
| 27 |
|
| 28 |
struct E : EmptyStruct { |
| 29 |
float c; |
| 30 |
}; |
| 31 |
|
| 32 |
struct F : A { |
| 33 |
int ae[0]; |
| 34 |
}; |
| 35 |
|
| 36 |
typedef float EmptyArrayTypedef[10][0]; |
| 37 |
|
| 38 |
struct OneFloat { |
| 39 |
float a; |
| 40 |
}; |
| 41 |
|
| 42 |
struct TwoFloats { |
| 43 |
float a; |
| 44 |
float b; |
| 45 |
}; |
| 46 |
|
| 47 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 48 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 49 |
cbuffer CB { |
| 50 |
// CHECK: VarDecl {{.*}} used a1 'hlsl_constant float' |
| 51 |
float a1; |
| 52 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB definition |
| 53 |
// CHECK: PackedAttr |
| 54 |
// CHECK-NEXT: FieldDecl {{.*}} a1 'float' |
| 55 |
} |
| 56 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_CB), ""); |
| 57 |
|
| 58 |
// Check that buffer layout struct does not include resources or empty types |
| 59 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 60 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 61 |
cbuffer CB { |
| 62 |
// CHECK: VarDecl {{.*}} used a2 'hlsl_constant float' |
| 63 |
float a2; |
| 64 |
// CHECK: VarDecl {{.*}} b2 'RWBuffer<float>':'hlsl::RWBuffer<float>' |
| 65 |
RWBuffer<float> b2; |
| 66 |
// CHECK: VarDecl {{.*}} c2 'EmptyStruct' |
| 67 |
EmptyStruct c2; |
| 68 |
// CHECK: VarDecl {{.*}} d2 'float[0]' |
| 69 |
float d2[0]; |
| 70 |
// CHECK: VarDecl {{.*}} f2 'RWBuffer<float>[2]' |
| 71 |
RWBuffer<float> f2[2]; |
| 72 |
// CHECK: VarDecl {{.*}} g2 'groupshared float' |
| 73 |
groupshared float g2; |
| 74 |
// CHECK: VarDecl {{.*}} h2 '__hlsl_resource_t' |
| 75 |
__hlsl_resource_t h2; |
| 76 |
// CHECK: VarDecl {{.*}} e2 'hlsl_constant float' |
| 77 |
float e2; |
| 78 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_1 definition |
| 79 |
// CHECK: PackedAttr |
| 80 |
// CHECK-NEXT: FieldDecl {{.*}} a2 'float' |
| 81 |
// CHECK-NEXT: FieldDecl {{.*}} e2 'float' |
| 82 |
} |
| 83 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_CB_1), ""); |
| 84 |
|
| 85 |
// Check that layout struct is created for B and the empty struct C is removed |
| 86 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 87 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 88 |
cbuffer CB { |
| 89 |
// CHECK: VarDecl {{.*}} used s1 'hlsl_constant A' |
| 90 |
A s1; |
| 91 |
// CHECK: VarDecl {{.*}} s2 'hlsl_constant B' |
| 92 |
B s2; |
| 93 |
// CHECK: VarDecl {{.*}} s3 'CTypedef':'C' |
| 94 |
CTypedef s3; |
| 95 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_2 definition |
| 96 |
// CHECK: PackedAttr |
| 97 |
// CHECK-NEXT: FieldDecl {{.*}} s1 'A' |
| 98 |
// CHECK-NEXT: FieldDecl {{.*}} s2 '__cblayout_B' |
| 99 |
} |
| 100 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_B definition |
| 101 |
// CHECK: PackedAttr |
| 102 |
// CHECK-NEXT: FieldDecl {{.*}} a 'float' |
| 103 |
|
| 104 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_B), ""); |
| 105 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_CB_2), ""); |
| 106 |
|
| 107 |
// check that layout struct is created for D because of its base struct |
| 108 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 109 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 110 |
cbuffer CB { |
| 111 |
// CHECK: VarDecl {{.*}} s4 'hlsl_constant D' |
| 112 |
D s4; |
| 113 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_3 definition |
| 114 |
// CHECK: PackedAttr |
| 115 |
// CHECK-NEXT: FieldDecl {{.*}} s4 '__cblayout_D' |
| 116 |
} |
| 117 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_D definition |
| 118 |
// CHECK: public '__cblayout_B' |
| 119 |
// CHECK: PackedAttr |
| 120 |
// CHECK-NEXT: FieldDecl {{.*}} b 'float' |
| 121 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_D), ""); |
| 122 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_CB_3), ""); |
| 123 |
|
| 124 |
// check that layout struct is created for E because because its base struct |
| 125 |
// is empty and should be eliminated, and BTypedef should reuse the previously |
| 126 |
// defined '__cblayout_B' |
| 127 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 128 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 129 |
cbuffer CB { |
| 130 |
// CHECK: VarDecl {{.*}} s5 'hlsl_constant E' |
| 131 |
E s5; |
| 132 |
// CHECK: VarDecl {{.*}} s6 'hlsl_constant BTypedef':'hlsl_constant B' |
| 133 |
BTypedef s6; |
| 134 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_4 definition |
| 135 |
// CHECK: PackedAttr |
| 136 |
// CHECK-NEXT: FieldDecl {{.*}} s5 '__cblayout_E' |
| 137 |
// CHECK-NEXT: FieldDecl {{.*}} s6 '__cblayout_B' |
| 138 |
} |
| 139 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_E definition |
| 140 |
// CHECK: PackedAttr |
| 141 |
// CHECK-NEXT: FieldDecl {{.*}} c 'float' |
| 142 |
// CHECK-NOT: CXXRecordDecl {{.*}} struct __cblayout_B definition |
| 143 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_E), ""); |
| 144 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_CB_4), ""); |
| 145 |
|
| 146 |
// check that this produces empty layout struct |
| 147 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 148 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 149 |
cbuffer CB { |
| 150 |
// CHECK: FunctionDecl {{.*}} f 'void ()' |
| 151 |
void f() {} |
| 152 |
// CHECK: VarDecl {{.*}} SV 'hlsl_private float' static |
| 153 |
static float SV; |
| 154 |
// CHECK: VarDecl {{.*}} s7 'EmptyStruct' callinit |
| 155 |
EmptyStruct s7; |
| 156 |
// CHECK: VarDecl {{.*}} Buf 'RWBuffer<float>':'hlsl::RWBuffer<float>' callinit |
| 157 |
RWBuffer<float> Buf; |
| 158 |
// CHECK: VarDecl {{.*}} ea 'EmptyArrayTypedef':'float[10][0]' |
| 159 |
EmptyArrayTypedef ea; |
| 160 |
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_CB_5 definition |
| 161 |
// CHECK: PackedAttr |
| 162 |
// CHECK-NOT: FieldDecl |
| 163 |
} |
| 164 |
|
| 165 |
// check host layout struct with compatible base struct |
| 166 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 167 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 168 |
cbuffer CB { |
| 169 |
// CHECK: VarDecl {{.*}} s8 'hlsl_constant F' |
| 170 |
F s8; |
| 171 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_6 definition |
| 172 |
// CHECK: PackedAttr |
| 173 |
// CHECK-NEXT: FieldDecl {{.*}} s8 '__cblayout_F' |
| 174 |
} |
| 175 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_F definition |
| 176 |
// CHECK: public 'A' |
| 177 |
// CHECK: PackedAttr |
| 178 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_F), ""); |
| 179 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_CB_6), ""); |
| 180 |
|
| 181 |
// anonymous structs |
| 182 |
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:9 cbuffer CB |
| 183 |
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer |
| 184 |
cbuffer CB { |
| 185 |
// CHECK: CXXRecordDecl {{.*}} struct definition |
| 186 |
struct { |
| 187 |
// CHECK: FieldDecl {{.*}} e 'float' |
| 188 |
float e; |
| 189 |
// CHECK: FieldDecl {{.*}} c 'int[0][1]' |
| 190 |
int c[0][1]; |
| 191 |
// CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>' |
| 192 |
RWBuffer<float> f; |
| 193 |
} s9; |
| 194 |
// CHECK: VarDecl {{.*}} s9 'hlsl_constant struct (unnamed at {{.*}}cbuffer.hlsl:[[# @LINE - 8]]:3 |
| 195 |
// CHECK: CXXRecordDecl {{.*}} struct definition |
| 196 |
struct { |
| 197 |
// CHECK: FieldDecl {{.*}} g 'float' |
| 198 |
float g; |
| 199 |
// CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>' |
| 200 |
RWBuffer<float> f; |
| 201 |
} s10; |
| 202 |
// CHECK: VarDecl {{.*}} s10 'hlsl_constant struct (unnamed at {{.*}}cbuffer.hlsl:[[# @LINE - 6]]:3 |
| 203 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_anon definition |
| 204 |
// CHECK: PackedAttr |
| 205 |
// CHECK-NEXT: FieldDecl {{.*}} e 'float' |
| 206 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_anon_1 definition |
| 207 |
// CHECK: PackedAttr |
| 208 |
// CHECK-NEXT: FieldDecl {{.*}} g 'float' |
| 209 |
// CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB_7 definition |
| 210 |
// CHECK: PackedAttr |
| 211 |
// CHECK-NEXT: FieldDecl {{.*}} s9 '__cblayout_anon' |
| 212 |
// CHECK-NEXT: FieldDecl {{.*}} s10 '__cblayout_anon_1' |
| 213 |
} |
| 214 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_anon), ""); |
| 215 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(OneFloat, __cblayout_anon_1), ""); |
| 216 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(TwoFloats, __cblayout_CB_7), ""); |
| 217 |
|
| 218 |
// Add uses for the constant buffer declarations so they are not optimized away |
| 219 |
export float foo() { |
| 220 |
return a1 + a2 + s1.a + s4.b + s5.c + s8.a + s9.e; |
| 221 |
} |