var.init.struct.hlsl 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Run: %dxc -T vs_6_0 -E main
  2. struct S {
  3. int3 a;
  4. uint b;
  5. float2x2 c;
  6. };
  7. struct T {
  8. // Same fields as S
  9. int3 h;
  10. uint i;
  11. float2x2 j;
  12. // Additional field
  13. bool2 k;
  14. // Embedded S
  15. S l;
  16. // Similar to S but need some casts
  17. float3 m;
  18. int n;
  19. float2x2 o;
  20. };
  21. struct O {
  22. int x;
  23. };
  24. struct P {
  25. O y;
  26. float z;
  27. };
  28. void main() {
  29. // CHECK-LABEL: %bb_entry = OpLabel
  30. // Flat initializer list
  31. // CHECK: [[a:%\d+]] = OpCompositeConstruct %v3int %int_1 %int_2 %int_3
  32. // CHECK-NEXT: [[c0:%\d+]] = OpCompositeConstruct %v2float %float_1 %float_2
  33. // CHECK-NEXT: [[c1:%\d+]] = OpCompositeConstruct %v2float %float_3 %float_4
  34. // CHECK-NEXT: [[c:%\d+]] = OpCompositeConstruct %mat2v2float [[c0]] [[c1]]
  35. // CHECK-NEXT: {{%\d+}} = OpCompositeConstruct %S [[a]] %uint_42 [[c]]
  36. S s1 = {1, 2, 3, 42, 1., 2., 3., 4.};
  37. // Random parentheses
  38. // CHECK: [[a:%\d+]] = OpCompositeConstruct %v3int %int_1 %int_2 %int_3
  39. // CHECK-NEXT: [[c0:%\d+]] = OpCompositeConstruct %v2float %float_1 %float_2
  40. // CHECK-NEXT: [[c1:%\d+]] = OpCompositeConstruct %v2float %float_3 %float_4
  41. // CHECK-NEXT: [[c:%\d+]] = OpCompositeConstruct %mat2v2float [[c0]] [[c1]]
  42. // CHECK-NEXT: {{%\d+}} = OpCompositeConstruct %S [[a]] %uint_42 [[c]]
  43. S s2 = {{1, 2}, 3, {{42}, {{1.}}}, {2., {3., 4.}}};
  44. // Flat initalizer list for nested structs
  45. // CHECK: [[y:%\d+]] = OpCompositeConstruct %O %int_1
  46. // CHECK-NEXT: {{%\d+}} = OpCompositeConstruct %P [[y]] %float_2
  47. P p = {1, 2.};
  48. // Mixed case: use struct as a whole, decomposing struct, type casting
  49. // CHECK: [[s1a:%\d+]] = OpAccessChain %_ptr_Function_v3int %s1 %int_0
  50. // CHECK-NEXT: [[h:%\d+]] = OpLoad %v3int [[s1a]]
  51. // CHECK-NEXT: [[s1b:%\d+]] = OpAccessChain %_ptr_Function_uint %s1 %int_1
  52. // CHECK-NEXT: [[i:%\d+]] = OpLoad %uint [[s1b]]
  53. // CHECK-NEXT: [[s1c:%\d+]] = OpAccessChain %_ptr_Function_mat2v2float %s1 %int_2
  54. // CHECK-NEXT: [[j:%\d+]] = OpLoad %mat2v2float [[s1c]]
  55. // CHECK-NEXT: [[k:%\d+]] = OpCompositeConstruct %v2bool %true %false
  56. // CHECK-NEXT: [[l:%\d+]] = OpLoad %S %s2
  57. // CHECK-NEXT: [[s2a:%\d+]] = OpAccessChain %_ptr_Function_v3int %s2 %int_0
  58. // CHECK-NEXT: [[s2av:%\d+]] = OpLoad %v3int [[s2a]]
  59. // CHECK-NEXT: [[m:%\d+]] = OpConvertSToF %v3float [[s2av]]
  60. // CHECK-NEXT: [[s2b:%\d+]] = OpAccessChain %_ptr_Function_uint %s2 %int_1
  61. // CHECK-NEXT: [[s2bv:%\d+]] = OpLoad %uint [[s2b]]
  62. // CHECK-NEXT: [[n:%\d+]] = OpBitcast %int [[s2bv]]
  63. // CHECK-NEXT: [[s2c:%\d+]] = OpAccessChain %_ptr_Function_mat2v2float %s2 %int_2
  64. // CHECK-NEXT: [[o:%\d+]] = OpLoad %mat2v2float [[s2c]]
  65. // CHECK-NEXT: {{%\d+}} = OpCompositeConstruct %T [[h]] [[i]] [[j]] [[k]] [[l]] [[m]] [[n]] [[o]]
  66. T t = {s1, // Decomposing struct
  67. true, false, // constructing field from scalar
  68. s2, // Embedded struct
  69. s2 // Decomposing struct + type casting
  70. };
  71. }