<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99149>99149</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `ProcessTriTessFactorsMax` 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 `ProcessTriTessFactorsMax` clang builtin,
- [ ] Link `ProcessTriTessFactorsMax` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `ProcessTriTessFactorsMax` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `ProcessTriTessFactorsMax` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/ProcessTriTessFactorsMax.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/ProcessTriTessFactorsMax-errors.hlsl`
- [ ] Create the `int_dx_ProcessTriTessFactorsMax` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_ProcessTriTessFactorsMax` to `106` in `DXIL.td`
- [ ] Create the `ProcessTriTessFactorsMax.ll` and `ProcessTriTessFactorsMax_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 `ProcessTriTessFactorsMax` when targeting SPIR-V.
## Test Case(s)
### Example 1
```hlsl
//dxc ProcessTriTessFactorsMax_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;
ProcessTriTessFactorsMax(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 ProcessTriTessFactorsMax(
in float3 RawEdgeFactors,
in float InsideScale,
out float3 RoundedEdgeTessFactors,
out float RoundedInsideTessFactor,
out float UnroundedInsideTessFactor
);
```
## 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>
*RoundedInsideTessFactor* \[out\]
</dt> <dd>
Type: **float**
The tessellation factors calculated by the tessellator stage, and rounded.
</dd> <dt>
*UnroundedInsideTessFactor* \[out\]
</dt> <dd>
Type: **float**
The original, unrounded, UV tessellation factors computed by the tessellation stage.
</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 maximum 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/eJzMWV9z2roS_zTKiwaPkTGBBx4IhDYzzUmm5HT6lhH2ArqVJY8kJ-R8-jsr2cZOCG1POncuk4Ilr_a3f35a_Sm3VuwUwIykVyRdXvDK7bWZbbn5Ryt5sdH5y2xASXpFSbqkN0UpoQDlKBnH90ZnYO2DEQ9g7YpnTht7yw9kHNNMcrWjm0pIJxRhCxLPj1q-CPXjtxTQZ-H2OGIvrXwUyhmhrMhstCfjuKd6nufUQsFptofsh6VbbX6G5DRKLFD-85f1l6sAuapU5oRWCy4lSgmFUmsouJcUahdlZXkKPtM57ED9OvR1IVwH-fpQmiPi4lPd_TM4B9bZWqMPHmEr7CNstdA5fAKFGISt6phawlbv2RZhnN8N7RkkjE8N482-OQszAGO0sSfRFga4A-r2gDBCucf88Hguli0r6sDdtCxZCgOZ-x65_DzI8vvNl7vylpelUDtUqbe_iO00RclhPD4mDrWdhzzHjiiwjqv8nNRjHcAgHPIS0KV8Kt4QgLBVHQvCVsEw_GMJYQlt3oS-ywVFB-hdifyinfZfvAjt9Z7nYOitzkF2O9aO78BiT61ocPzQn7T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