llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Implement the `pack_clamp_s8` HLSL Function

Open farzonl opened this issue 2 years ago • 1 comments

  • [ ] Implement pack_clamp_s8 clang builtin,
  • [ ] Link pack_clamp_s8 clang builtin with hlsl_intrinsics.h
  • [ ] Add sema checks for pack_clamp_s8 to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • [ ] Add codegen for pack_clamp_s8 to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • [ ] Add codegen tests to clang/test/CodeGenHLSL/builtins/pack_clamp_s8.hlsl
  • [ ] Add sema tests to clang/test/SemaHLSL/BuiltIns/pack_clamp_s8-errors.hlsl
  • [ ] Create the int_dx_pack_clamp_s8 intrinsic in IntrinsicsDirectX.td
  • [ ] Create the DXILOpMapping of int_dx_pack_clamp_s8 to 220 in DXIL.td
  • [ ] Create the pack_clamp_s8.ll and pack_clamp_s8_errors.ll tests in llvm/test/CodeGen/DirectX/
  • [ ] Create the int_spv_pack_clamp_s8 intrinsic in IntrinsicsSPIRV.td
  • [ ] In SPIRVInstructionSelector.cpp create the pack_clamp_s8 lowering and map it to int_spv_pack_clamp_s8 in SPIRVInstructionSelector::selectIntrinsic.
  • [ ] Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/pack_clamp_s8.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
220 Pack4x8 6.6 ()

SPIR-V

SClamp:

Description:

SClamp

Result is min(max(x, minVal), maxVal), where x, minVal and maxVal are interpreted as signed integers. Result is undefined if minVal > maxVal.

Result Type and the type of the operands must both be integer scalar or integer vector types. Result Type and operand types must have the same number of components with the same component width. Results are computed per component.

Number Operand 1 Operand 2 Operand 3 Operand 4

45

<id>
x

<id>
minVal

<id>
maxVal

Test Case(s)

Example 1

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

export int8_t4_packed fn(int4 p1) {
    return pack_clamp_s8(p1);
}

HLSL:

Syntax

p32i8 pack_clamp_s8(sint16or32_only<4> v);

Type Description

Name Template Type Component Type Size
ret scalar int8_t4_packed 1
v vector int or int16_t 4

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 6.6 and higher shader models yes

Shader Stages

See also

farzonl avatar Jul 16 '24 20:07 farzonl

I don't have the permissions to self assign this, but I can pick it up along with the other pack and unpack tasks.

Alexander-Johnston avatar Aug 17 '26 12:08 Alexander-Johnston