function-overloading.azsl 747 B

1234567891011121314151617181920212223242526272829
  1. int g_func(int i)
  2. {
  3. return i;
  4. }
  5. float g_func(float f)
  6. {
  7. return f > 0 ? 0 : 1;
  8. }
  9. float4 main() : SV_Target0
  10. {
  11. int i = g_func((int)1); // reference to symbol at line 1
  12. float f = g_func(1.5); // reference to symbol at line 6 (because 1.5 is a float in HLSL)
  13. float f2 = g_func(1.5L); // L is the suffix for double in HLSL. DXC may be able to do the implicit conversion, but AZSLc cannot.
  14. // hence, the reference here will fallback to the overload-set (unsolved symbol representing the g_func family)
  15. return float4(f,0,0,1);
  16. }
  17. void f(int,float);
  18. void f(int);
  19. void g()
  20. {
  21. f(); // fallback
  22. f(1+1); // matches l22 by arity
  23. f(1+1, lerp(0.0, 1.0, 0.5)); // matches l21 by arity
  24. }