-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement the reflect
HLSL Function
#99152
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
Comments
Hello, is anyone currently working on this issue? If not, I’d like to take it on. |
@jerryyiransun we are redesigning how we are going to do some of these intrinsics to be header only implementations. I’m on vacation right now. Give me two weeks and i’ll rewrite this ticket to match our expectations. |
@farzonl Thank you for the update, I'll wait for the updated ticket and proceed based on the revised expectations. Enjoy your vacation! |
This ticket is ready for planning. |
I will be working on this issue, if you don't mind @jerryyiransun |
@Icohedron of course, please go ahead. |
Fixes #99152 Tasks completed: - Implement `reflect` in `clang/lib/Headers/hlsl/hlsl_intrinsics.h` - Implement the `reflect` SPIR-V target built-in in `clang/include/clang/Basic/BuiltinsSPIRV.td` - Add a SPIR-V fast path in `clang/lib/Headers/hlsl/hlsl_detail.h` in the form ```c++ #if (__has_builtin(__builtin_spirv_reflect)) return __builtin_spirv_reflect(...); #else return ...; // regular behavior #endif ``` - Add codegen for the SPIR-V `reflect` built-in to `EmitSPIRVBuiltinExpr` in `clang/lib/CodeGen/CGBuiltin.cpp` - Add HLSL codegen tests to `clang/test/CodeGenHLSL/builtins/reflect.hlsl` - Add SPIR-V built-in codegen tests to `clang/test/CodeGenSPIRV/Builtins/reflect.c` - Add sema tests to `clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl` - Add SPIR-V sema tests to `clang/test/CodeGenSPIRV/Builtins/reflect-errors.c` - Create the `int_spv_reflect` intrinsic in `llvm/include/llvm/IR/IntrinsicsSPIRV.td` - In `llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp` create the `reflect` lowering and map it to `int_spv_reflect` in `SPIRVInstructionSelector::selectIntrinsic` - Create a SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll` Additional tasks completed: - Implement sema check for the `reflect` SPIR-V built-in in `clang/lib/Sema/SemaSPIRV.cpp` - Required for HLSL codegen to work via the SPIR-V fast path, because the types defined in `clang/include/clang/Basic/BuiltinsSPIRV.td` are being overridden - Create SPIR-V backend error test case in `llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll` - Since `reflect` is only available in the GLSL extended instruction set, using it in OpenCL should result in an error Incomplete tasks: - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/opencl/reflect.ll` - An OpenCL test is not applicable in this case because the [OpenCL SPIR-V extended instruction set](https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html) does not include a `reflect` function
Blocked on #124045 |
Closed since the PR has been relanded. (#125599) |
reflect
in thehlsl_intrinsics.h
clang/include/clang/Basic/BuiltinsSPIRV.td
hlsl_detail.h
in the formreflect
builtin toEmitSPIRVBuiltinExpr
inCGBuiltin.cpp
clang/test/CodeGenHLSL/builtins/reflect.hlsl
clang/test/CodeGenSPIRV/Builtins/reflect.c
clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
clang/test/CodeGenSPIRV/Builtins/reflect-errors.c
int_spv_reflect
intrinsic inIntrinsicsSPIRV.td
reflect
lowering and map it toint_spv_reflect
inSPIRVInstructionSelector::selectIntrinsic
.llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
llvm/test/CodeGen/SPIRV/opencl/reflect.ll
DirectX
There were no DXIL opcodes found for
reflect
. That should make it easy to do entirely in the frontend.In DXC it was done via emitting llvmir. We do not want to do that in upstream.
SPIR-V
Reflect:
Description:
Reflect
For the incident vector I and surface orientation N, the result is
the reflection direction:
I - 2 * dot(N, I) * N
N must already be normalized in order to achieve the desired result.
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.
71
<id>
I
<id>
N
Test Case(s)
Example 1
HLSL:
Returns a reflection vector using an incident ray and a surface normal.
Parameters
Return Value
A floating-point, reflection vector.
Remarks
This function calculates the reflection vector using the following formula: v = i - 2 * n * dot(i n) .
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: