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] Reapply Move length support out of the DirectX Backend (#121611) #122337

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Jan 9, 2025

  • attribute keeps getting deleted on bad rebases

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Jan 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-backend-x86

Author: Farzon Lotfi (farzonl)

Changes
  • attribute keeps getting deleted on bad rebases

Full diff: https://github.com/llvm/llvm-project/pull/122337.diff

1 Files Affected:

  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+2)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index cf287e598f76ba..7105d83078a9d7 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
 ///
 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 template <int N> const inline half length(vector<half, N> X) {
   return __detail::length_vec_impl(X);
 }

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)

Changes
  • attribute keeps getting deleted on bad rebases

Full diff: https://github.com/llvm/llvm-project/pull/122337.diff

1 Files Affected:

  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+2)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index cf287e598f76ba..7105d83078a9d7 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
 ///
 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 template <int N> const inline half length(vector<half, N> X) {
   return __detail::length_vec_impl(X);
 }

Copy link
Contributor

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix a test failure?

Copy link
Contributor

@inbelic inbelic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming we don't need the other availability denoted

@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
///
/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).

_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half length(half X) { return __detail::length_impl(X); }
const inline float length(float X) { return __detail::length_impl(X); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need _HLSL_AVAILABILITY(shadermodel, 6.2) on the none half variants?

@farzonl
Copy link
Member Author

farzonl commented Jan 9, 2025

Does this fix a test failure?

No failures. We would need to have tests for all intrinsics that if its not SM 6.2 or greater uses of half would error, but we never did that for any of the other intrinsics so we should probably discuss what the test coverage should be and apply it broadly.

## Changes
- Delete DirectX length intrinsic
- Delete HLSL length lang builtin
- Implement length algorithm entirely in the header.

## History
- In the past if an HLSL intrinsic lowered to either a spirv op code or
a DXIL opcode we represented it with intrinsics

## Why we are moving away?
- To make HLSL apis more portable the team decided that it makes sense
for some intrinsics to be defined only in the header.
- Since there tends to be more SPIRV opcodes than DXIL opcodes the plan
is to support SPIRV opcodes either with target specific builtins or via
pattern matching.
@farzonl farzonl force-pushed the fix-length-half-availability branch from 0f0b75d to 6f2da80 Compare January 9, 2025 21:24
@llvmbot llvmbot added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen backend:DirectX HLSL HLSL Language Support llvm:ir labels Jan 9, 2025
@farzonl farzonl changed the title [HLSL] Add 6.2 SM on half availability for length intrinsic [HLSL] Reapply Move length support out of the DirectX Backend (llvm#121611) Jan 9, 2025
@farzonl farzonl changed the title [HLSL] Reapply Move length support out of the DirectX Backend (llvm#121611) [HLSL] Reapply Move length support out of the DirectX Backend (#121611) Jan 9, 2025
- attribute keeps getting deleted on bad rebases
@farzonl farzonl force-pushed the fix-length-half-availability branch from 6f2da80 to 7173a48 Compare January 9, 2025 21:57
Copy link

github-actions bot commented Jan 9, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff d01ae567742c4d83b67483e15eb74c0ecd2e8270 7173a486d82a3959fc6157a58488b10ece492821 --extensions cpp,h -- clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/Headers/hlsl/hlsl_detail.h clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/lib/Sema/SemaHLSL.cpp llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
View the diff from clang-format here.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index f4470d5de6..e5ff7531d2 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1301,7 +1301,7 @@ _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
-template <int N> 
+template <int N>
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(vector<half, N> X) {
   return __detail::length_vec_impl(X);

@llvm-beanz
Copy link
Collaborator

No failures. We would need to have tests for all intrinsics that if its not SM 6.2 or greater uses of half would error, but we never did that for any of the other intrinsics so we should probably discuss what the test coverage should be and apply it broadly.

In practice these are pretty tricky to test on just Clang because the 6.2 attribute only applies when -enable-16bit-types is set, which requires shader model 6.2 or greater. So you shouldn't actually be able to make the compiler fail this.

The point of the attribute is really just for header completeness so that we can drive documentation and LSP tooling from it.

@farzonl
Copy link
Member Author

farzonl commented Jan 10, 2025

@llvm-beanz I'm really confused what is going on here
The length test case passes in the github action: https://github.com/llvm/llvm-project/actions/runs/12699150463?pr=122337
It passes locally on:

  1. MacOS Intel (Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz)
  2. MacOS Apple M3 Max 12 core
  3. Ubuntu 22.04 AMD Ryzen Threadripper PRO 5975WX 32-Cores
  4. Windows AMD Ryzen 9 5900X

BUT its failing in buildkite and on other llvm builders. I'm not sure what could do this.
https://buildkite.com/llvm-project/github-pull-requests/builds/135222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:X86 clang:codegen clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category HLSL HLSL Language Support llvm:ir
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants