Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HLSL] Compatibility overloads for integer operations #128229

Closed
llvm-beanz opened this issue Feb 21, 2025 · 0 comments · Fixed by #133162
Closed

[HLSL] Compatibility overloads for integer operations #128229

llvm-beanz opened this issue Feb 21, 2025 · 0 comments · Fixed by #133162
Assignees
Labels
HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

Many HLSL shaders call unary math operations with integers. To minimize disruptions at the source level we should implement additional integer overloads for unary floating-point math operations that take integers and explicitly convert them to float.

These should be enabled in HLSL 202x, but we should consider disabling them in 202y.

Some macros:

#define DXC_COMPAT_UNARY_INTEGER_OVERLOAD(fn)                                  \
  float fn(int V) { return fn((float)V); }                                     \
  float2 fn(int2 V) { return fn((float2)V); }                                  \
  float3 fn(int3 V) { return fn((float3)V); }                                  \
  float4 fn(int4 V) { return fn((float4)V); }                                  \
  float fn(uint V) { return fn((float)V); }                                    \
  float2 fn(uint2 V) { return fn((float2)V); }                                 \
  float3 fn(uint3 V) { return fn((float3)V); }                                 \
  float4 fn(uint4 V) { return fn((float4)V); }                                 \
  float fn(int64_t V) { return fn((float)V); }                                 \
  float2 fn(int64_t2 V) { return fn((float2)V); }                              \
  float3 fn(int64_t3 V) { return fn((float3)V); }                              \
  float4 fn(int64_t4 V) { return fn((float4)V); }                              \
  float fn(uint64_t V) { return fn((float)V); }                                \
  float2 fn(uint64_t2 V) { return fn((float2)V); }                             \
  float3 fn(uint64_t3 V) { return fn((float3)V); }                             \
  float4 fn(uint64_t4 V) { return fn((float4)V); }

#define DXC_COMPAT_BINARY_INTEGER_OVERLOAD(fn)                                 \
  float fn(int V1, int V2) { return fn((float)V1, (float)V2); }                \
  float2 fn(int2 V1, int2 V2) { return fn((float2)V1, (float2)V2); }           \
  float3 fn(int3 V1, int3 V2) { return fn((float3)V1, (float3)V2); }           \
  float4 fn(int4 V1, int4 V2) { return fn((float4)V1, (float4)V2); }           \
  float fn(uint V1, uint V2) { return fn((float)V1, (float)V2); }              \
  float2 fn(uint2 V1, uint2 V2) { return fn((float2)V1, (float2)V2); }         \
  float3 fn(uint3 V1, uint3 V2) { return fn((float3)V1, (float3)V2); }         \
  float4 fn(uint4 V1, uint4 V2) { return fn((float4)V1, (float4)V2); }         \
  float fn(int64_t V1, int64_t V2) { return fn((float)V1, (float)V2); }        \
  float2 fn(int64_t2 V1, int64_t2 V2) { return fn((float2)V1, (float2)V2); }   \
  float3 fn(int64_t3 V1, int64_t3 V2) { return fn((float3)V1, (float3)V2); }   \
  float4 fn(int64_t4 V1, int64_t4 V2) { return fn((float4)V1, (float4)V2); }   \
  float fn(uint64_t V1, uint64_t V2) { return fn((float)V1, (float)V2); }      \
  float2 fn(uint64_t2 V1, uint64_t2 V2) { return fn((float2)V1, (float2)V2); } \
  float3 fn(uint64_t3 V1, uint64_t3 V2) { return fn((float3)V1, (float3)V2); } \
  float4 fn(uint64_t4 V1, uint64_t4 V2) { return fn((float4)V1, (float4)V2); }
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Feb 21, 2025
@llvm-beanz llvm-beanz moved this to Planning in HLSL Support Feb 21, 2025
@damyanp damyanp moved this from Planning to Ready in HLSL Support Feb 27, 2025
@spall spall self-assigned this Mar 25, 2025
@spall spall moved this from Ready to Active in HLSL Support Mar 25, 2025
spall added a commit that referenced this issue Mar 27, 2025
Add int overloads which cast the various ints to a float and call the
float builtin.
These overloads are conditional on hlsl version 202x or earlier.
Add tests and puts tests in own files, including some of the tests added
for double overloads.
Closes #128229
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLSL HLSL Language Support
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

2 participants