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 lit HLSL Function #99135

Open
5 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 1 comment
Open
5 tasks
Tracked by #99235

Implement the lit HLSL Function #99135

farzonl opened this issue Jul 16, 2024 · 1 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.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Write implementation in hlsl_intrinsics.h
  • Add sema checks for lit to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/lit.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/lit.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
23 Log 6.0 ()

SPIR-V

FMax:

Description:

FMax

Result is y if x < y; otherwise result is x. Which operand is
the result is undefined if one of the operands is a NaN.

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.
Results are computed per component.

Number Operand 1 Operand 2 Operand 3 Operand 4

40

<id>
x

<id>
y

Test Case(s)

Example 1

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

export float4 fn(float p1, float p2, float p3) {
    return lit(p1, p2, p3);
}

HLSL:

Returns a lighting coefficient vector.

ret lit(n_dot_l, n_dot_h, m)

This function returns a lighting coefficient vector (ambient, diffuse, specular, 1) where:

  • ambient = 1
  • diffuse = n · l < 0 ? 0 : n · l
  • specular = n · l < 0 || n · h < 0 ? 0 : (n · h) ^ m

Where the vector n is the normal vector, l is the direction to light and h is the half vector.

Parameters

Item Description
n_dot_l
[in] The dot product of the normalized surface normal and the light vector.
n_dot_h
[in] The dot product of the half-angle vector and the surface normal.
m
[in] A specular exponent.

Return Value

The lighting coefficient vector.

Type Description

Name Template Type Component Type Size
n_dot_l scalar float 1
n_dot_h scalar float 1
m scalar float 1
ret vector float 4

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) yes (vs_1_1 only)

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
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@farzonl
Copy link
Member Author

farzonl commented Nov 19, 2024

Do this one all in the header. @farzonl clean the body up

@pow2clk pow2clk moved this from Planning to Ready in HLSL Support Nov 19, 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: Ready
Development

No branches or pull requests

1 participant