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

Open
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 0 comments
Open
12 tasks
Tracked by #99235

Implement the distance HLSL Function #99107

farzonl opened this issue Jul 16, 2024 · 0 comments
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 clang builtin,
  • Link distance clang builtin with hlsl_intrinsics.h
  • Add sema checks for distance to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for distance to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/distance.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
  • Create the int_dx_distance intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_distance to 24 in DXIL.td
  • Create the distance.ll and distance_errors.ll tests in llvm/test/CodeGen/DirectX/
  • 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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
24 Sqrt 6.0 ()

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
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: No status
Development

No branches or pull requests

1 participant