vk.layout.rwstructuredbuffer.boolean.hlsl 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Run: %dxc -T vs_6_0 -E main
  2. // CHECK: %T = OpTypeStruct %_arr_uint_uint_1
  3. struct T {
  4. bool boolArray[1];
  5. };
  6. // CHECK: %S = OpTypeStruct %uint %v3uint %_arr_v3uint_uint_2 %T
  7. struct S
  8. {
  9. bool boolScalar;
  10. bool3 boolVec;
  11. row_major bool2x3 boolMat;
  12. T t;
  13. };
  14. RWStructuredBuffer<S> values;
  15. // CHECK: [[v3uint1:%\d+]] = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
  16. // CHECK: [[v3uint0:%\d+]] = OpConstantComposite %v3uint %uint_0 %uint_0 %uint_0
  17. // These are the types that hold SPIR-V booleans, rather than Uints.
  18. // CHECK: %T_0 = OpTypeStruct %_arr_bool_uint_1
  19. // CHECK: %S_0 = OpTypeStruct %bool %v3bool %_arr_v3bool_uint_2 %T_0
  20. void main()
  21. {
  22. bool3 boolVecVar;
  23. bool2 boolVecVar2;
  24. row_major bool2x3 boolMatVar;
  25. // CHECK: [[uintPtr:%\d+]] = OpAccessChain %_ptr_Uniform_uint %values %int_0 %uint_0 %int_0
  26. // CHECK-NEXT: [[convertTrueToUint:%\d+]] = OpSelect %uint %true %uint_1 %uint_0
  27. // CHECK-NEXT: OpStore [[uintPtr]] [[convertTrueToUint]]
  28. values[0].boolScalar = true;
  29. // CHECK: [[boolVecVar:%\d+]] = OpLoad %v3bool %boolVecVar
  30. // CHECK-NEXT: [[uintVecPtr:%\d+]] = OpAccessChain %_ptr_Uniform_v3uint %values %int_0 %uint_1 %int_1
  31. // CHECK-NEXT: [[uintVecVar:%\d+]] = OpSelect %v3uint [[boolVecVar]] [[v3uint1]] [[v3uint0]]
  32. // CHECK-NEXT: OpStore [[uintVecPtr]] [[uintVecVar]]
  33. values[1].boolVec = boolVecVar;
  34. // TODO: In the following cases, OpAccessChain runs into type mismatch issues due to decoration differences.
  35. // values[2].boolMat = boolMatVar;
  36. // values[0].boolVec.yzx = boolVecVar;
  37. // values[0].boolMat._m12_m11 = boolVecVar2;
  38. // CHECK: [[sPtr:%\d+]] = OpAccessChain %_ptr_Uniform_S %values %int_0 %uint_0
  39. // CHECK-NEXT: [[s:%\d+]] = OpLoad %S [[sPtr]]
  40. // CHECK-NEXT: [[s0:%\d+]] = OpCompositeExtract %uint [[s]] 0
  41. // CHECK-NEXT: [[s0_bool:%\d+]] = OpINotEqual %bool [[s0]] %uint_0
  42. // CHECK-NEXT: [[s1:%\d+]] = OpCompositeExtract %v3uint [[s]] 1
  43. // CHECK-NEXT: [[s1_bool:%\d+]] = OpINotEqual %v3bool [[s1]] [[v3uint0]]
  44. // CHECK-NEXT: [[s2:%\d+]] = OpCompositeExtract %_arr_v3uint_uint_2 [[s]] 2
  45. // CHECK-NEXT: [[s2_row0:%\d+]] = OpCompositeExtract %v3uint [[s2]] 0
  46. // CHECK-NEXT: [[s2_row0_bool:%\d+]] = OpINotEqual %v3bool [[s2_row0]] [[v3uint0]]
  47. // CHECK-NEXT: [[s2_row1:%\d+]] = OpCompositeExtract %v3uint [[s2]] 1
  48. // CHECK-NEXT: [[s2_row1_bool:%\d+]] = OpINotEqual %v3bool [[s2_row1]] [[v3uint0]]
  49. // CHECK-NEXT: [[s2_bool:%\d+]] = OpCompositeConstruct %_arr_v3bool_uint_2 [[s2_row0_bool]] [[s2_row1_bool]]
  50. // CHECK-NEXT: [[t:%\d+]] = OpCompositeExtract %T [[s]] 3
  51. // CHECK-NEXT: [[t0_uint_arr:%\d+]] = OpCompositeExtract %_arr_uint_uint_1 [[t]] 0
  52. // CHECK-NEXT: [[t0_0_uint:%\d+]] = OpCompositeExtract %uint [[t0_uint_arr]] 0
  53. // CHECK-NEXT: [[t0_0_bool:%\d+]] = OpINotEqual %bool [[t0_0_uint]] %uint_0
  54. // CHECK-NEXT: [[t0_bool:%\d+]] = OpCompositeConstruct %_arr_bool_uint_1 [[t0_0_bool]]
  55. // CHECK-NEXT: [[t_bool:%\d+]] = OpCompositeConstruct %T_0 [[t0_bool]]
  56. // CHECK-NEXT: [[s_bool:%\d+]] = OpCompositeConstruct %S_0 [[s0_bool]] [[s1_bool]] [[s2_bool]] [[t_bool]]
  57. // CHECK-NEXT: OpStore %s [[s_bool]]
  58. S s = values[0];
  59. // CHECK: [[s:%\d+]] = OpLoad %S_0 %s
  60. // CHECK-NEXT: [[resultPtr:%\d+]] = OpAccessChain %_ptr_Uniform_S %values %int_0 %uint_1
  61. // CHECK-NEXT: [[s0_bool:%\d+]] = OpCompositeExtract %bool [[s]] 0
  62. // CHECK-NEXT: [[s0_uint:%\d+]] = OpSelect %uint [[s0_bool]] %uint_1 %uint_0
  63. // CHECK-NEXT: [[s1_boolVec:%\d+]] = OpCompositeExtract %v3bool [[s]] 1
  64. // CHECK-NEXT: [[s1_uintVec:%\d+]] = OpSelect %v3uint [[s1_boolVec]]
  65. // CHECK-NEXT: [[s2_boolMat:%\d+]] = OpCompositeExtract %_arr_v3bool_uint_2 [[s]] 2
  66. // CHECK-NEXT: [[s2_boolMat_row0:%\d+]] = OpCompositeExtract %v3bool [[s2_boolMat]] 0
  67. // CHECK-NEXT: [[s2_boolMat_row0_uint:%\d+]] = OpSelect %v3uint [[s2_boolMat_row0]]
  68. // CHECK-NEXT: [[s2_boolMat_row1:%\d+]] = OpCompositeExtract %v3bool [[s2_boolMat]] 1
  69. // CHECK-NEXT: [[s2_boolMat_row1_uint:%\d+]] = OpSelect %v3uint [[s2_boolMat_row1]]
  70. // CHECK-NEXT: [[s2_uintMat:%\d+]] = OpCompositeConstruct %_arr_v3uint_uint_2 [[s2_boolMat_row0_uint]] [[s2_boolMat_row1_uint]]
  71. // CHECK-NEXT: [[t:%\d+]] = OpCompositeExtract %T_0 [[s]] 3
  72. // CHECK-NEXT: [[t0_bool_arr:%\d+]] = OpCompositeExtract %_arr_bool_uint_1 [[t]] 0
  73. // CHECK-NEXT: [[t0_bool_arr_0:%\d+]] = OpCompositeExtract %bool [[t0_bool_arr]] 0
  74. // CHECK-NEXT: [[t0_bool_arr_0_uint:%\d+]] = OpSelect %uint [[t0_bool_arr_0]] %uint_1 %uint_0
  75. // CHECK-NEXT: [[t0_uint_arr:%\d+]] = OpCompositeConstruct %_arr_uint_uint_1 [[t0_bool_arr_0_uint]]
  76. // CHECK-NEXT: [[t_uint:%\d+]] = OpCompositeConstruct %T [[t0_uint_arr]]
  77. // CHECK-NEXT: [[s_uint:%\d+]] = OpCompositeConstruct %S [[s0_uint]] [[s1_uintVec]] [[s2_uintMat]] [[t_uint]]
  78. // CHECK-NEXT: OpStore [[resultPtr:%\d+]] [[s_uint]]
  79. values[1] = s;
  80. }