-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement the faceforward
HLSL Function
#99114
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
Labels
backend:SPIR-V
bot:HLSL
HLSL
HLSL Language Support
metabug
Issue to collect references to a group of similar or related issues.
Comments
@farzonl to update this item outlining the difference between the DirectX impl and the SPIR-V impl |
@farzonl - update to mention pattern matching implementation option |
I'll take this. |
I can take this |
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this issue
May 6, 2025
Resolves llvm#99114. Tasks completed: - Implement `faceforward` in `hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h` - Implement `faceforward` SPIR-V target builtin in `clang/include/clang/Basic/BuiltinsSPIRV.td` - Add a SPIR-V fast path in `hlsl_intrinsic_helpers.h` - Add sema checks for `faceforward` to `CheckSPIRVBuiltinFunctionCall` in `clang/lib/Sema/SemaSPIRV.cpp` - Add codegen for SPIR-V `faceforward` builtin to `EmitSPIRVBuiltinExpr` in `SPIR.cpp` - Add HLSL codegen tests to `clang/test/CodeGenHLSL/builtins/faceforward.hlsl` - Add SPIRV builtin codegen tests to `clang/test/CodeGenSPIRV/Builtins/faceforward.c` - Add sema tests to `clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl` - Add spirv sema tests to `clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c` - Create the `int_spv_faceforward` intrinsic in `IntrinsicsSPIRV.td` - In `SPIRVInstructionSelector.cpp` create the `faceforward` lowering and map it to `int_spv_faceforward` in `SPIRVInstructionSelector::selectIntrinsic` - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll` Incomplete tasks: - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/opencl/faceforward.ll` - Not applicable because the OpenCL SPIR-V extended instruction set does not include a `faceforward` function Follow-up tasks: - Implement pattern matching for `faceforward` in `SPIRVCombine.td` and `SPIRVPreLegalizerCombiner.cpp` - In `faceforward.ll`, change `--target-env spv1.4` to `vulkan1.3` and update the test accordingly once [llvm#136344](llvm#136344) has been resolved
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this issue
May 6, 2025
Resolves llvm#99114. Tasks completed: - Implement `faceforward` in `hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h` - Implement `faceforward` SPIR-V target builtin in `clang/include/clang/Basic/BuiltinsSPIRV.td` - Add a SPIR-V fast path in `hlsl_intrinsic_helpers.h` - Add sema checks for `faceforward` to `CheckSPIRVBuiltinFunctionCall` in `clang/lib/Sema/SemaSPIRV.cpp` - Add codegen for SPIR-V `faceforward` builtin to `EmitSPIRVBuiltinExpr` in `SPIR.cpp` - Add HLSL codegen tests to `clang/test/CodeGenHLSL/builtins/faceforward.hlsl` - Add SPIRV builtin codegen tests to `clang/test/CodeGenSPIRV/Builtins/faceforward.c` - Add sema tests to `clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl` - Add spirv sema tests to `clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c` - Create the `int_spv_faceforward` intrinsic in `IntrinsicsSPIRV.td` - In `SPIRVInstructionSelector.cpp` create the `faceforward` lowering and map it to `int_spv_faceforward` in `SPIRVInstructionSelector::selectIntrinsic` - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll` Incomplete tasks: - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/opencl/faceforward.ll` - Not applicable because the OpenCL SPIR-V extended instruction set does not include a `faceforward` function Follow-up tasks: - Implement pattern matching for `faceforward` in `SPIRVCombine.td` and `SPIRVPreLegalizerCombiner.cpp` - In `faceforward.ll`, change `--target-env spv1.4` to `vulkan1.3` and update the test accordingly once [llvm#136344](llvm#136344) has been resolved
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this issue
May 6, 2025
Resolves llvm#99114. Tasks completed: - Implement `faceforward` in `hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h` - Implement `faceforward` SPIR-V target builtin in `clang/include/clang/Basic/BuiltinsSPIRV.td` - Add a SPIR-V fast path in `hlsl_intrinsic_helpers.h` - Add sema checks for `faceforward` to `CheckSPIRVBuiltinFunctionCall` in `clang/lib/Sema/SemaSPIRV.cpp` - Add codegen for SPIR-V `faceforward` builtin to `EmitSPIRVBuiltinExpr` in `SPIR.cpp` - Add HLSL codegen tests to `clang/test/CodeGenHLSL/builtins/faceforward.hlsl` - Add SPIRV builtin codegen tests to `clang/test/CodeGenSPIRV/Builtins/faceforward.c` - Add sema tests to `clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl` - Add spirv sema tests to `clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c` - Create the `int_spv_faceforward` intrinsic in `IntrinsicsSPIRV.td` - In `SPIRVInstructionSelector.cpp` create the `faceforward` lowering and map it to `int_spv_faceforward` in `SPIRVInstructionSelector::selectIntrinsic` - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll` Incomplete tasks: - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/opencl/faceforward.ll` - Not applicable because the OpenCL SPIR-V extended instruction set does not include a `faceforward` function Follow-up tasks: - Implement pattern matching for `faceforward` in `SPIRVCombine.td` and `SPIRVPreLegalizerCombiner.cpp` - In `faceforward.ll`, change `--target-env spv1.4` to `vulkan1.3` and update the test accordingly once [llvm#136344](llvm#136344) has been resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backend:SPIR-V
bot:HLSL
HLSL
HLSL Language Support
metabug
Issue to collect references to a group of similar or related issues.
faceforward
in thehlsl_intrinsics.h
clang/include/clang/Basic/BuiltinsSPIRV.td
hlsl_detail.h
in the formAn alternative to doing a built-in here would be to do pattern matching. Say we have code like this
We would expect the code gen to look something like this
that means we could pattern match in
SPIRVCombine.td
andSPIRVPreLegalizerCombiner.cpp
tofaceforward
builtin toEmitSPIRVBuiltinExpr
inSPIR.cpp
clang/test/CodeGenHLSL/builtins/faceforward.hlsl
clang/test/CodeGenSPIRV/Builtins/faceforward.c
clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl
clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c
int_spv_faceforward
intrinsic inIntrinsicsSPIRV.td
faceforward
lowering and map it toint_spv_faceforward
inSPIRVInstructionSelector::selectIntrinsic
.llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll
llvm/test/CodeGen/SPIRV/opencl/faceforward.ll
DirectX
No DXIL Opcodes were found.
SPIR-V
FaceForward:
Description:
FaceForward
If the dot product of Nref and I is negative, the result is N,
otherwise it is -N.
The operands must all be a scalar or vector whose component type is
floating-point.
Result Type and the type of all operands must be the same type.
70
<id>
N
<id>
I
<id>
Nref
Test Case(s)
Example 1
HLSL:
Flips the surface-normal (if needed) to face in a direction opposite to i; returns the result in n.
This function uses the following formula: -n sign(dot(i, ng)).
Parameters
Return Value
A floating-point, surface normal vector that is facing the view direction.
Type Description
Minimum Shader Model
This function is supported in the following shader models.
See also
Intrinsic Functions (DirectX HLSL)
The text was updated successfully, but these errors were encountered: