Skip to content

Implement the reflect HLSL Function #99152

Closed
@farzonl

Description

@farzonl
  • implement reflect in the hlsl_intrinsics.h
    Implement reflect 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_reflect))
  return __builtin_spirv_reflect(...);
#else
  return ...; // regular behavior
#endif
  • Add codegen for spirv reflect builtin to EmitSPIRVBuiltinExpr in CGBuiltin.cpp
    Add HLSL codegen tests to clang/test/CodeGenHLSL/builtins/reflect.hlsl
    Add SPIRV builtin codegen tests to clang/test/CodeGenSPIRV/Builtins/reflect.c
    Add sema tests to clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
    Add spirv sema tests to clang/test/CodeGenSPIRV/Builtins/reflect-errors.c
    Create the int_spv_reflect intrinsic in IntrinsicsSPIRV.td
    In SPIRVInstructionSelector.cpp create the reflect lowering and map it to int_spv_reflect in SPIRVInstructionSelector::selectIntrinsic.
    Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
    Create SPIR-V backend test case in 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.

Number Operand 1 Operand 2 Operand 3 Operand 4

71

<id>
I

<id>
N

Test Case(s)

Example 1

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

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

HLSL:

Returns a reflection vector using an incident ray and a surface normal.

ret reflect(i, n)

Parameters

Item Description
i
[in] A floating-point, incident vector.
n
[in] A floating-point, normal vector.

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

Name Template Type Component Type Size
i vector float any
n vector float same dimension(s) as input i
ret vector float same dimension(s) as input i

Minimum Shader Model

This function is supported in the following shader models.

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

See also

Intrinsic Functions (DirectX HLSL)

Activity

moved this to Ready in HLSL Supporton Oct 30, 2024
moved this from Ready to Planning in HLSL Supporton Oct 30, 2024
moved this from Planning to Designing in HLSL Supporton Nov 19, 2024
jerryyiransun

jerryyiransun commented on Dec 6, 2024

@jerryyiransun
Contributor

Hello, is anyone currently working on this issue? If not, I’d like to take it on.

farzonl

farzonl commented on Dec 6, 2024

@farzonl
MemberAuthor

@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.

jerryyiransun

jerryyiransun commented on Dec 6, 2024

@jerryyiransun
Contributor

@farzonl Thank you for the update, I'll wait for the updated ticket and proceed based on the revised expectations. Enjoy your vacation!

19 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Closed

Milestone

No milestone

Development

Participants

@farzonl@Icohedron@damyanp@jerryyiransun

Issue actions

    Implement the `reflect` HLSL Function · Issue #99152 · llvm/llvm-project