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

Implement the distance HLSL Function #99107

Closed
12 tasks done
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #121598 or #122357
Closed
12 tasks done
Tracked by #99235

Implement the distance HLSL Function #99107

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #121598 or #122357
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • implement distance in the hlsl_intrinsics.h
  • Implement distance spirv target builtin in clang/include/clang/Basic/BuiltinsSPIRV.td
  • Add a spirv fast path in hlsl_detail.h in the form
#if (__has_builtin(__builtin_spirv_distance))
  return __builtin_spirv_distance(...);
#else
  return ...; // regular behavior
#endif
  • Add codegen for spirv distance builtin to EmitSPIRVBuiltinExpr in CGBuiltin.cpp
  • Add HLSL codegen tests to clang/test/CodeGenHLSL/builtins/distance.hlsl
  • Add SPIRV builtin codegen tests to clang/test/CodeGenSPIRV/Builtins/distance.c
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
  • Add spirv sema tests to clang/test/CodeGenSPIRV/Builtins/distance-errors.c
  • Create the int_spv_distance intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the distance lowering and map it to int_spv_distance in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/distance.ll
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/opencl/distance.ll

DirectX

There are no DXIL opcodes found for distance.

SPIR-V

Distance:

Description:

Distance

Result is the distance between p0 and p1, i.e., length(p0 -
p1).

The operands must all be a scalar or vector whose component type is
floating-point.

Result Type must be a scalar of the same type as the component type of
the operands.

Number Operand 1 Operand 2 Operand 3 Operand 4

67

<id>
p0

<id>
p1

Test Case(s)

Example 1

//dxc distance_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export float fn(float4 p1, float4 p2) {
    return distance(p1, p2);
}

HLSL:

Returns a distance scalar between two vectors.

ret distance(x, y)

Parameters

Item Description
x
[in] The first floating-point vector to compare.
y
[in] The second floating-point vector to compare.

Return Value

A floating-point, scalar value that represents the distance between the x parameter and the y parameter.

Type Description

Name Template Type Component Type Size
x vector float any
y vector float same dimension(s) as input x
ret scalar float 1

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) vs_1_1

See also

Intrinsic Functions (DirectX HLSL)

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@davidcook-msft davidcook-msft moved this from Planning to Designing in HLSL Support Nov 12, 2024
@damyanp
Copy link
Contributor

damyanp commented Nov 12, 2024

@farzonl - please rework issue to describe it being fully implemented in the header.

farzonl added a commit that referenced this issue Jan 6, 2025
- Update pr labeler so new SPIRV files get properly labeled.
- Add distance target builtin to BuiltinsSPIRV.td.
- Update TargetBuiltins.h to account for spirv builtins.
- Update clang basic CMakeLists.txt to build spirv builtin tablegen.
- Hook up sema for SPIRV in Sema.h|cpp, SemaSPIRV.h|cpp, and
SemaChecking.cpp.
- Hookup sprv target builtins to SPIR.h|SPIR.cpp target.
- Update GBuiltin.cpp to emit spirv intrinsics when we get the expected
spirv target builtin.

Consensus was reach in this RFC to add both target builtins and pattern
matching:
https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329.

pattern matching will come in a separate pr this one just sets up the
groundwork to do target builtins for spirv.

partially resolves
[#99107](#99107)
@github-project-automation github-project-automation bot moved this from Designing to Closed in HLSL Support Jan 6, 2025
@farzonl farzonl reopened this Jan 6, 2025
github-actions bot pushed a commit to arm/arm-toolchain that referenced this issue Jan 10, 2025
…le (#121598)

- Update pr labeler so new SPIRV files get properly labeled.
- Add distance target builtin to BuiltinsSPIRV.td.
- Update TargetBuiltins.h to account for spirv builtins.
- Update clang basic CMakeLists.txt to build spirv builtin tablegen.
- Hook up sema for SPIRV in Sema.h|cpp, SemaSPIRV.h|cpp, and
SemaChecking.cpp.
- Hookup sprv target builtins to SPIR.h|SPIR.cpp target.
- Update GBuiltin.cpp to emit spirv intrinsics when we get the expected
spirv target builtin.

Consensus was reach in this RFC to add both target builtins and pattern
matching:
https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329.

pattern matching will come in a separate pr this one just sets up the
groundwork to do target builtins for spirv.

partially resolves
[#99107](llvm/llvm-project#99107)
@farzonl
Copy link
Member Author

farzonl commented Jan 10, 2025

fixed by #122357

@farzonl farzonl closed this as completed Jan 10, 2025
@farzonl farzonl linked a pull request Jan 10, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
2 participants