<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99150>99150</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Implement the `ProcessTriTessFactorsMin` HLSL Function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            metabug,
            backend:DirectX,
            HLSL,
            bot:HLSL
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          farzonl
      </td>
    </tr>
</table>

<pre>
    - [ ] Implement `ProcessTriTessFactorsMin` clang builtin,
- [ ] Link `ProcessTriTessFactorsMin` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `ProcessTriTessFactorsMin` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `ProcessTriTessFactorsMin` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/ProcessTriTessFactorsMin.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/ProcessTriTessFactorsMin-errors.hlsl`
- [ ] Create the `int_dx_ProcessTriTessFactorsMin` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_ProcessTriTessFactorsMin` to  `106` in `DXIL.td`
- [ ] Create the  `ProcessTriTessFactorsMin.ll` and `ProcessTriTessFactorsMin_errors.ll` tests in `llvm/test/CodeGen/DirectX/`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 106 | StorePatchConstant | 6.0 | ('hull',) |

## SPIR-V

There is no support for `ProcessTriTessFactorsMin` when targeting SPIR-V.

## Test Case(s)

 
 ### Example 1
```hlsl
//dxc ProcessTriTessFactorsMin_test.hlsl -T hs_6_8 -enable-16bit-types -O0

struct HSPerPatchData
{
        float edges[ 3 ] : SV_TessFactor;
        float inside : SV_InsideTessFactor;
};
struct PSSceneIn {
        float4 pos : SV_Position;
        float2 tex : TEXCOORD0;
        float3 norm : NORMAL;
};
struct HSPerVertexData {
        PSSceneIn v;
};

export HSPerPatchData fn( const InputPatch< PSSceneIn, 3 > points ) {
        HSPerPatchData d;
        float4 edgeFactor;
        float2 insideFactor;float3 p1;
float p2;
float3 p3;
float p4;
float p5;
ProcessTriTessFactorsMin(p1, p2, p3, p4, p5);

        d.edges[0]=edgeFactor.x;
        d.edges[1]=edgeFactor.y;
        d.edges[2]=edgeFactor.z + edgeFactor.w;
        d.inside = insideFactor.x + insideFactor.y;
        return d;
}

[domain("tri")]
[outputtopology("triangle_cw")]
[patchconstantfunc("fn")]
[outputcontrolpoints(3)]
[partitioning("pow2")]
HSPerVertexData main( const uint id : SV_OutputControlPointID,const InputPatch< PSSceneIn, 3 > points ) {

        HSPerVertexData v;
        v.v = points[ id ];
        return v;
}
```
## HLSL:

Generates the corrected tessellation factors for a tri patch.

## Syntax

``` syntax
void ProcessTriTessFactorsMin(
  in  float3 RawEdgeFactors,
  in  float InsideScale,
  out float3 RoundedEdgeTessFactors,
  out float RoundedInsideTessFactors,
  out float UnroundedInsideTessFactors
);
```

## Parameters

<dl> <dt>

*RawEdgeFactors* \[in\]
</dt> <dd>

Type: **float3**

The edge tessellation factors, passed into the tessellator stage.

</dd> <dt>

*InsideScale* \[in\]
</dt> <dd>

Type: **float**

The scale factor applied to the UV tessellation factors computed by the tessellation stage. The allowable range for InsideScale is 0.0 to 1.0.

</dd> <dt>

*RoundedEdgeTessFactors* \[out\]
</dt> <dd>

Type: **float3**

The rounded edge-tessellation factors calculated by the tessellator stage.

</dd> <dt>

*RoundedInsideTessFactors* \[out\]
</dt> <dd>

Type: **float**

The rounded tessellation factors calculated by the tessellator stage for inside edges.

</dd> <dt>

*UnroundedInsideTessFactors* \[out\]
</dt> <dd>

Type: **float**

The tessellation factors calculated by the tessellator stage for inside edges.

</dd> </dl>

## Return value

This function does not return a value.

## Remarks

Generates the corrected tessellation factors for a tri patch, computing the inside tessellation factor as the minimum of the edge tessellation factors, which is then scaled by InsideScale. The result is then rounded based on the partitioning mode, but the unrounded results are available using the UnroundedInsideTessFactor parameter.

### Minimum Shader Model

This function is supported in the following shader models.



| Shader Model                                                                | Supported |
|-----------------------------------------------------------------------------|-----------|
| [Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md) and higher shader models | yes       |



 

This function is supported in the following types of shaders:



| Vertex | Hull | Domain | Geometry | Pixel | Compute |
|--------|------|--------|----------|-------|---------|
|        | x    |        |          |       |         |



 

## See also

<dl> <dt>

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

[Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWV1z4rjS_jXKjQrKyBjIBRcEwmyqJpvUkJ3au5SwGtA7suSS5ITsr3-rJdvgBJiZnTmnDpUQS271x9OPWh_hzsmtBpiS7IZkiyte-Z2x0w23_xitrtZGvE17lGQ3lGQLeleUCgrQnpJR8mhNDs49WfkEzi157o1191KTUUJzxfWWriupvNSEzUkyO2j5LPW3n1JAX6Xf4YidcupZam-ldjJ3_R0ZJR3VMyGog4LTfAf5N0c3xn7PkjcoMUf5Pz6vPt9Ek8tK514aPedKoZTUKLWCggdJqbf9vCxPmc-NgC3oHzd9W0h_ZPl2X9qDxfmnuvt75jw472qNATzClthH2HJuBHwCjTYIW9aYOsKW53zrI85nob1gCfGpzQS37y6a6YG1xrqT1uYWuAfqd4BmpPbPYv98CcuWFTVwdy1LFtJC7v_ue3HZyOLvu88P5T0vS6m3qNJsftC2NxQlB8nokDjUdtnkJXb0I-u4FpeknmsAo3DMS7Su1Evx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