llvm / llvm/llvm-project

[Matrix] Implement matrix support for the `clamp` HLSL Function

Open
#184,498 0 comments 0 reactions 0 assignees View on GitHub
bot:HLSL HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

> Note: This issue tracks matrix support for `clamp`. The original implementation issue is [here](https://github.com/llvm/llvm-project/issues/70071).

Matrix requirements:
- [ ] https://github.com/llvm/wg-hlsl/issues/387

## HLSL:
Clamps the specified value to the specified minimum and maximum range.

## Parameters

| Item | Description |
|--------------------------------------------------------------|------------------------------------------------|
| *x*
| \[in\] A value to clamp.
|
| *min*
| \[in\] The specified minimum range.
|
| *max*
| \[in\] The specified maximum range.
|

## Return Value

The clamped value for the *x* parameter.

## Remarks

For values of -INF or INF, clamp will behave as expected. However for values of NaN, the results are undefined.

## Type Description

| Name | [**Template Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md) | [**Component Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md) | Size |
|-------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|--------------------------------|
| *x* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md), **vector**, or **matrix** | [**float**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md), [**int**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md) | any |
| *min* | same as input *x* | [**float**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md), [**int**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md) | same dimension(s) as input *x* |
| *max* | same as input *x* | [**float**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md), [**int**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md) | same dimension(s) as input *x* |
| *ret* | same as input *x* | [**float**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md), [**int**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/WinProg/windows-data-types.md) | same dimension(s) as input *x* |

## Minimum Shader Model

This function is supported in the following shader models.

| Shader Model | Supported |
|------------------------------------------------------------------------------------|-----------------------|
| [Shader Model 2 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-sm2.md) and higher shader models | yes |
| [Shader Model 1 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-sm1.md) | vs\_1\_1 and ps\_1\_4 |

## See also

[**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)

Contributor guide

Open the contributing guide

Research direction

Start with the original implementation issue #70071 and review the linked matrix requirement in wg-hlsl issue #387. Use the HLSL clamp type table in this issue to define the supported matrix cases; done means matrix inputs, minimums, maximums, and return values are supported consistently with the stated dimensions.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.