Description
- implement
distance
in thehlsl_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 toEmitSPIRVBuiltinExpr
inCGBuiltin.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 inIntrinsicsSPIRV.td
- In SPIRVInstructionSelector.cpp create the
distance
lowering and map it toint_spv_distance
inSPIRVInstructionSelector::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> |
<id> |
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
Metadata
Metadata
Assignees
Type
Projects
Status
Closed