Issue 128228
Summary [HLSL] hlsl202x `double` compatability overloads
Labels HLSL
Assignees
Reporter llvm-beanz
    Lots of HLSL builtin functions that operate on floating point elements do not have `double` overloads. In most cases DXC successfully resolves those overloads to `float` but does not emit conversion diagnostics.

In Clang we should provide wrapper overloads that call the `float` overloads and produce conversion diagnostics. We should use the C preprocessor to define these overloads and have them conditional on HLSL 202x.

Some macros I've been playing with:

```hlsl
#define DXC_COMPAT_UNARY_DOUBLE_OVERLOAD(fn) \
  float fn(double V) { return fn((float)V); } \
  float2 fn(double2 V) { return fn((float2)V); }                               \
  float3 fn(double3 V) { return fn((float3)V); }                               \
  float4 fn(double4 V) { return fn((float4)V); }

#define DXC_COMPAT_BINARY_DOUBLE_OVERLOAD(fn) \
  float fn(double V1, double V2) { return fn((float)V1, (float)V2); }          \
  float2 fn(double2 V1, double2 V2) { return fn((float2)V1, (float2)V2); }     \
  float3 fn(double3 V1, double3 V2) { return fn((float3)V1, (float3)V2); }     \
 float4 fn(double4 V1, double4 V2) { return fn((float4)V1, (float4)V2); }

#define DXC_COMPAT_BINARY_TERNARY_OVERLOAD(fn) \
  float fn(double V1, double V2, double V3) { \
    return fn((float)V1, (float)V1, (float)V3); \
  } \
  float2 fn(double2 V1, double2 V2, double2 V3) { \
    return fn((float2)V1, (float2)V2, (float2)V3);                             \
  } \
  float3 fn(double3 V1, double3 V2, double3 V3) {                              \
    return fn((float3)V1, (float3)V2, (float3)V3);                             \
  } \
 float4 fn(double4 V1, double4 V2, double4 V3) { \
    return fn((float4)V1, (float4)V2, (float4)V3); \
  }
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to