oo.class.method.hlsl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Run: %dxc -T vs_6_0 -E main
  2. class 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. class T {
  31. S s;
  32. // Calling method in nested class
  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. // CHECK: [[ft_f32:%\d+]] = OpTypeFunction %float
  50. // CHECK: [[ft_S:%\d+]] = OpTypeFunction %float %_ptr_Function_S
  51. // CHECK: [[ft_S_f32:%\d+]] = OpTypeFunction %float %_ptr_Function_S %_ptr_Function_float
  52. // CHECK: [[ft_T:%\d+]] = OpTypeFunction %float %_ptr_Function_T
  53. // CHECK: [[fooFnType:%\d+]] = OpTypeFunction %T
  54. // CHECK: [[getSFntype:%\d+]] = OpTypeFunction %S %_ptr_Function_T
  55. float main() : A {
  56. // CHECK-LABEL: %src_main = OpFunction
  57. // CHECK-NEXT: %bb_entry = OpLabel
  58. // CHECK-NEXT: %s = OpVariable %_ptr_Function_S Function
  59. // CHECK-NEXT: %t = OpVariable %_ptr_Function_T Function
  60. // CHECK-NEXT: %f1 = OpVariable %_ptr_Function_float Function
  61. // CHECK-NEXT: %param_var_c = OpVariable %_ptr_Function_float Function
  62. // CHECK-NEXT: %f2 = OpVariable %_ptr_Function_float Function
  63. // CHECK-NEXT: %temp_var_T = OpVariable %_ptr_Function_T Function
  64. // CHECK-NEXT: %temp_var_S = OpVariable %_ptr_Function_S Function
  65. S s;
  66. T t;
  67. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_no_ref %s
  68. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_ref %s
  69. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_call %s %param_var_c
  70. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_nested %t
  71. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_static
  72. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_static
  73. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_static
  74. // CHECK: {{%\d+}} = OpFunctionCall %float %T_fn_static
  75. float f1 = s.fn_no_ref() + s.fn_ref() + s.fn_call(5.0) + t.fn_nested() +
  76. s.fn_static() + t.fn_static() + S::fn_static() + T::fn_static();
  77. // CHECK: [[temp_T:%\d+]] = OpFunctionCall %T %foo
  78. // CHECK-NEXT: OpStore %temp_var_T [[temp_T]]
  79. // CHECK-NEXT: [[temp_S:%\d+]] = OpFunctionCall %S %T_get_S %temp_var_T
  80. // CHECK-NEXT: OpStore %temp_var_S [[temp_S]]
  81. // CHECK-NEXT: {{%\d+}} = OpFunctionCall %float %S_fn_ref %temp_var_S
  82. float f2 = foo().get_S().fn_ref();
  83. return f1;
  84. // CHECK: OpFunctionEnd
  85. }
  86. // CHECK: %S_fn_no_ref = OpFunction %float None [[ft_S]]
  87. // CHECK-NEXT: %param_this = OpFunctionParameter %_ptr_Function_S
  88. // CHECK-NEXT: %bb_entry_0 = OpLabel
  89. // CHECK: OpFunctionEnd
  90. // CHECK: %S_fn_ref = OpFunction %float None [[ft_S]]
  91. // CHECK-NEXT: %param_this_0 = OpFunctionParameter %_ptr_Function_S
  92. // CHECK-NEXT: %bb_entry_1 = OpLabel
  93. // CHECK: {{%\d+}} = OpAccessChain %_ptr_Function_float %param_this_0 %int_0
  94. // CHECK: {{%\d+}} = OpAccessChain %_ptr_Function_float %param_this_0 %int_1 %uint_0
  95. // CHECK: OpFunctionEnd
  96. // CHECK: %S_fn_call = OpFunction %float None [[ft_S_f32]]
  97. // CHECK-NEXT: %param_this_1 = OpFunctionParameter %_ptr_Function_S
  98. // CHECK-NEXT: %c = OpFunctionParameter %_ptr_Function_float
  99. // CHECK-NEXT: %bb_entry_2 = OpLabel
  100. // CHECK-NEXT: %param_var_c_0 = OpVariable %_ptr_Function_float Function
  101. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_param %param_this_1 %param_var_c_0
  102. // CHECK: OpFunctionEnd
  103. // CHECK: %T_fn_nested = OpFunction %float None [[ft_T]]
  104. // CHECK-NEXT: %param_this_2 = OpFunctionParameter %_ptr_Function_T
  105. // CHECK-NEXT: %bb_entry_3 = OpLabel
  106. // CHECK: [[t_s:%\d+]] = OpAccessChain %_ptr_Function_S %param_this_2 %int_0
  107. // CHECK: {{%\d+}} = OpFunctionCall %float %S_fn_ref [[t_s]]
  108. // CHECK: OpFunctionEnd
  109. // CHECK: %S_fn_static = OpFunction %float None [[ft_f32]]
  110. // CHECK-NEXT: %bb_entry_4 = OpLabel
  111. // CHECK: OpFunctionEnd
  112. // CHECK: %T_fn_static = OpFunction %float None [[ft_f32]]
  113. // CHECK-NEXT: %bb_entry_5 = OpLabel
  114. // CHECK: OpFunctionEnd
  115. // CHECK: %foo = OpFunction %T None [[fooFnType]]
  116. // CHECK-NEXT: %bb_entry_6 = OpLabel
  117. // CHECK: OpFunctionEnd
  118. // CHECK: %T_get_S = OpFunction %S None [[getSFntype]]
  119. // CHECK-NEXT: %param_this_3 = OpFunctionParameter %_ptr_Function_T
  120. // CHECK-NEXT: %bb_entry_7 = OpLabel
  121. // CHECK: OpFunctionEnd
  122. // CHECK: %S_fn_param = OpFunction %float None [[ft_S_f32]]
  123. // CHECK-NEXT: %param_this_4 = OpFunctionParameter %_ptr_Function_S
  124. // CHECK-NEXT: %c_0 = OpFunctionParameter %_ptr_Function_float
  125. // CHECK-NEXT: %bb_entry_8 = OpLabel
  126. // CHECK: {{%\d+}} = OpAccessChain %_ptr_Function_float %param_this_4 %int_0
  127. // CHECK: OpFunctionEnd