oo.struct.method.hlsl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Run: %dxc -T vs_6_0 -E main
  2. struct S {
  3. float a;
  4. float3 b;
  5. // Not referencing members
  6. float fn_no_ref() {
  7. return 4.2;
  8. }
  9. // Referencing members
  10. float fn_ref() {
  11. return a + this.b[0];
  12. }
  13. // Calling a method defined later
  14. float fn_call(float c) {
  15. return fn_param(c);
  16. }
  17. // Passing in parameters
  18. float fn_param(float c) {
  19. return a + c;
  20. }
  21. // Unused method
  22. float fn_unused() {
  23. return 2.4;
  24. }
  25. // Static method
  26. static float fn_static() {
  27. return 3.5;
  28. }
  29. };
  30. struct T {
  31. S s;
  32. // Calling method in nested struct
  33. float fn_nested() {
  34. return s.fn_ref();
  35. }
  36. // Static method with the same name as S
  37. static float fn_static() {
  38. return 6.7;
  39. }
  40. // Get inner object
  41. S get_S() {
  42. return s;
  43. }
  44. };
  45. T foo() {
  46. T t;
  47. return t;
  48. }
  49. struct R {
  50. int a;
  51. void incr() { ++a; }
  52. };
  53. RWStructuredBuffer<R> rwsb;
  54. // CHECK: [[ft_f32:%\d+]] = OpTypeFunction %float
  55. // CHECK: [[ft_S:%\d+]] = OpTypeFunction %float %_ptr_Function_S
  56. // CHECK: [[ft_S_f32:%\d+]] = OpTypeFunction %float %_ptr_Function_S %_ptr_Function_float
  57. // CHECK: [[ft_T:%\d+]] = OpTypeFunction %float %_ptr_Function_T
  58. // CHECK: [[fooFnType:%\d+]] = OpTypeFunction %T
  59. // CHECK: [[getSFntype:%\d+]] = OpTypeFunction %S %_ptr_Function_T
  60. float main() : A {
  61. // CHECK-LABEL: %src_main = OpFunction
  62. // CHECK-NEXT: %bb_entry = OpLabel
  63. // CHECK-NEXT: %s = OpVariable %_ptr_Function_S Function
  64. // CHECK-NEXT: %t = OpVariable %_ptr_Function_T Function
  65. // CHECK-NEXT: %f1 = OpVariable %_ptr_Function_float Function
  66. // CHECK-NEXT: %param_var_c = OpVariable %_ptr_Function_float Function
  67. // CHECK-NEXT: %f2 = OpVariable %_ptr_Function_float Function
  68. // CHECK-NEXT: %temp_var_T = OpVariable %_ptr_Function_T Function
  69. // CHECK-NEXT: %temp_var_S = OpVariable %_ptr_Function_S Function
  70. S s;
  71. T t;
  72. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_no_ref %s
  73. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_ref %s
  74. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_call %s %param_var_c
  75. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_nested %t
  76. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_static
  77. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_static
  78. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_static
  79. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_static
  80. float f1 = s.fn_no_ref() + s.fn_ref() + s.fn_call(5.0) + t.fn_nested() +
  81. s.fn_static() + t.fn_static() + S::fn_static() + T::fn_static();
  82. // CHECK: [[temp_T:%\d+]] = OpFunctionCall %T %foo
  83. // CHECK-NEXT: OpStore %temp_var_T [[temp_T]]
  84. // CHECK-NEXT: [[temp_S:%\d+]] = OpFunctionCall %S %T_get_S %temp_var_T
  85. // CHECK-NEXT: OpStore %temp_var_S [[temp_S]]
  86. // CHECK-NEXT: {{%\d+}} = OpFunctionCall %float %S_fn_ref %temp_var_S
  87. float f2 = foo().get_S().fn_ref();
  88. // CHECK: [[uniformPtr:%\d+]] = OpAccessChain %_ptr_Uniform_R %rwsb %int_0 %uint_0
  89. // CHECK-NEXT: [[originalObj:%\d+]] = OpLoad %R [[uniformPtr]]
  90. // CHECK-NEXT: [[member:%\d+]] = OpCompositeExtract %int [[originalObj]] 0
  91. // CHECK-NEXT: [[tempVar:%\d+]] = OpCompositeConstruct %R_0 [[member]]
  92. // CHECK-NEXT: OpStore %temp_var_R [[tempVar]]
  93. // CHECK-NEXT: OpFunctionCall %void %R_incr %temp_var_R
  94. // CHECK-NEXT: [[tempVar:%\d+]] = OpLoad %R_0 %temp_var_R
  95. // CHECK-NEXT: [[tempVarMember:%\d+]] = OpCompositeExtract %int [[tempVar]] 0
  96. // CHECK-NEXT: [[newR:%\d+]] = OpCompositeConstruct %R [[tempVarMember]]
  97. // CHECK-NEXT: OpStore [[uniformPtr]] [[newR]]
  98. rwsb[0].incr();
  99. return f1;
  100. // CHECK: OpFunctionEnd
  101. }
  102. // CHECK: %S_fn_no_ref = OpFunction %float None [[ft_S]]
  103. // CHECK-NEXT: %param_this = OpFunctionParameter %_ptr_Function_S
  104. // CHECK-NEXT: %bb_entry_0 = OpLabel
  105. // CHECK: OpFunctionEnd
  106. // CHECK: %S_fn_ref = OpFunction %float None [[ft_S]]
  107. // CHECK-NEXT: %param_this_0 = OpFunctionParameter %_ptr_Function_S
  108. // CHECK-NEXT: %bb_entry_1 = OpLabel
  109. // CHECK: {{%\d+}} = OpAccessChain %_ptr_Function_float %param_this_0 %int_0
  110. // CHECK: {{%\d+}} = OpAccessChain %_ptr_Function_float %param_this_0 %int_1 %uint_0
  111. // CHECK: OpFunctionEnd
  112. // CHECK: %S_fn_call = OpFunction %float None [[ft_S_f32]]
  113. // CHECK-NEXT: %param_this_1 = OpFunctionParameter %_ptr_Function_S
  114. // CHECK-NEXT: %c = OpFunctionParameter %_ptr_Function_float
  115. // CHECK-NEXT: %bb_entry_2 = OpLabel
  116. // CHECK-NEXT: %param_var_c_0 = OpVariable %_ptr_Function_float Function
  117. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_param %param_this_1 %param_var_c_0
  118. // CHECK: OpFunctionEnd
  119. // CHECK: %T_fn_nested = OpFunction %float None [[ft_T]]
  120. // CHECK-NEXT: %param_this_2 = OpFunctionParameter %_ptr_Function_T
  121. // CHECK-NEXT: %bb_entry_3 = OpLabel
  122. // CHECK: [[t_s:%\d+]] = OpAccessChain %_ptr_Function_S %param_this_2 %int_0
  123. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_ref [[t_s]]
  124. // CHECK: OpFunctionEnd
  125. // CHECK: %S_fn_static = OpFunction %float None [[ft_f32]]
  126. // CHECK-NEXT: %bb_entry_4 = OpLabel
  127. // CHECK: OpFunctionEnd
  128. // CHECK: %T_fn_static = OpFunction %float None [[ft_f32]]
  129. // CHECK-NEXT: %bb_entry_5 = OpLabel
  130. // CHECK: OpFunctionEnd
  131. // CHECK: %foo = OpFunction %T None [[fooFnType]]
  132. // CHECK-NEXT: %bb_entry_6 = OpLabel
  133. // CHECK: OpFunctionEnd
  134. // CHECK: %T_get_S = OpFunction %S None [[getSFntype]]
  135. // CHECK-NEXT: %param_this_3 = OpFunctionParameter %_ptr_Function_T
  136. // CHECK-NEXT: %bb_entry_7 = OpLabel
  137. // CHECK: OpFunctionEnd
  138. // CHECK: %S_fn_param = OpFunction %float None [[ft_S_f32]]
  139. // CHECK-NEXT: %param_this_5 = OpFunctionParameter %_ptr_Function_S
  140. // CHECK-NEXT: %c_0 = OpFunctionParameter %_ptr_Function_float
  141. // CHECK-NEXT: OpLabel
  142. // CHECK: OpAccessChain %_ptr_Function_float %param_this_5 %int_0
  143. // CHECK: OpFunctionEnd