| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -verify %s |
| 2 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s |
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
// Case 1: How many ways can I come up with to represent three float values? |
| 6 |
struct ThreeFloats1 { |
| 7 |
float X, Y, Z; |
| 8 |
}; |
| 9 |
|
| 10 |
struct ThreeFloats2 { |
| 11 |
float X[3]; |
| 12 |
}; |
| 13 |
|
| 14 |
struct ThreeFloats3 { |
| 15 |
float3 V; |
| 16 |
}; |
| 17 |
|
| 18 |
struct ThreeFloats4 { |
| 19 |
float2 V; |
| 20 |
float F; |
| 21 |
}; |
| 22 |
|
| 23 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(float3, float[3]), ""); |
| 24 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(float3, ThreeFloats1), ""); |
| 25 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(float3, ThreeFloats2), ""); |
| 26 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(float3, ThreeFloats3), ""); |
| 27 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(float3, ThreeFloats4), ""); |
| 28 |
|
| 29 |
// Case 2: structs and base classes and arrays, oh my! |
| 30 |
struct Dog { |
| 31 |
int Leg[4]; |
| 32 |
bool Tail; |
| 33 |
float Fur; |
| 34 |
}; |
| 35 |
|
| 36 |
struct Shiba { |
| 37 |
int4 StubbyLegs; |
| 38 |
bool CurlyTail; |
| 39 |
struct Coating { |
| 40 |
float Fur; |
| 41 |
} F; |
| 42 |
}; |
| 43 |
|
| 44 |
struct FourLegged { |
| 45 |
int FR, FL, BR, BL; |
| 46 |
}; |
| 47 |
|
| 48 |
struct Doggo : FourLegged { |
| 49 |
bool WaggyBit; |
| 50 |
float Fuzz; |
| 51 |
}; |
| 52 |
|
| 53 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Dog, Shiba), ""); |
| 54 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Dog, Doggo), ""); |
| 55 |
|
| 56 |
// Case 3: Arrays of structs inside structs |
| 57 |
|
| 58 |
struct Cat { |
| 59 |
struct Leg { |
| 60 |
int L; |
| 61 |
} Legs[4]; |
| 62 |
struct Other { |
| 63 |
bool Tail; |
| 64 |
float Furs; |
| 65 |
} Bits; |
| 66 |
}; |
| 67 |
|
| 68 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Dog, Cat), ""); |
| 69 |
|
| 70 |
// case 4: Arrays of structs inside arrays of structs. |
| 71 |
struct Pets { |
| 72 |
Dog Puppers[6]; |
| 73 |
Cat Kitties[4]; |
| 74 |
}; |
| 75 |
|
| 76 |
struct Animals { |
| 77 |
Dog Puppers[2]; |
| 78 |
Cat Kitties[8]; |
| 79 |
}; |
| 80 |
|
| 81 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Pets, Animals), ""); |
| 82 |
|
| 83 |
// Case 5: Turtles all the way down... |
| 84 |
|
| 85 |
typedef int Turtle; |
| 86 |
|
| 87 |
enum Ninja : Turtle { |
| 88 |
Leonardo, |
| 89 |
Donatello, |
| 90 |
Michelangelo, |
| 91 |
Raphael, |
| 92 |
}; |
| 93 |
|
| 94 |
enum NotNinja : Turtle { |
| 95 |
Fred, |
| 96 |
Mikey, |
| 97 |
}; |
| 98 |
|
| 99 |
enum Mammals : uint { |
| 100 |
Dog, |
| 101 |
Cat, |
| 102 |
}; |
| 103 |
|
| 104 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Ninja, NotNinja), ""); |
| 105 |
_Static_assert(!__builtin_hlsl_is_scalarized_layout_compatible(Ninja, Mammals), ""); |
| 106 |
|
| 107 |
// Case 6: Some basic types. |
| 108 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(int, int32_t), ""); |
| 109 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(uint, uint32_t), ""); |
| 110 |
_Static_assert(!__builtin_hlsl_is_scalarized_layout_compatible(int, uint), ""); |
| 111 |
_Static_assert(!__builtin_hlsl_is_scalarized_layout_compatible(int, float), ""); |
| 112 |
|
| 113 |
// Even though half and float may be the same size we don't want them to be |
| 114 |
// layout compatible since they are different types. |
| 115 |
_Static_assert(!__builtin_hlsl_is_scalarized_layout_compatible(half, float), ""); |
| 116 |
|
| 117 |
// Case 6: Empty classes... because they're fun. |
| 118 |
|
| 119 |
struct NotEmpty { int X; }; |
| 120 |
struct Empty {}; |
| 121 |
struct AlsoEmpty {}; |
| 122 |
|
| 123 |
struct DerivedEmpty : Empty {}; |
| 124 |
|
| 125 |
struct DerivedNotEmpty : Empty { int X; }; |
| 126 |
struct DerivedEmptyNotEmptyBase : NotEmpty {}; |
| 127 |
|
| 128 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Empty, AlsoEmpty), ""); |
| 129 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Empty, DerivedEmpty), ""); |
| 130 |
|
| 131 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(NotEmpty, DerivedNotEmpty), ""); |
| 132 |
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(NotEmpty, DerivedEmptyNotEmptyBase), ""); |