<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99140>99140</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `printf` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
HLSL,
backend:SPIR-V,
bot:HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
- [ ] Implement `printf` clang builtin,
- [ ] Link `printf` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `printf` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `printf` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/printf.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/printf-errors.hlsl`
- [ ] Create the `int_spv_printf` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `printf` lowering and map it to `int_spv_printf` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/printf.ll`
## DirectX
There is no support for `printf` when targeting DirectX.
## SPIR-V
See "Using Debug Printf in HLSL Shaders" in https://vulkan.lunarg.com/doc/sdk/1.3.283.0/windows/debug_printf.html
## Test Case(s)
### Example 1
```hlsl
//dxc printf_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export void fn(string p1) {
return printf(p1);
}
```
## HLSL:
Submits a custom shader message to the information queue.
## Syntax
``` syntax
void printf(
string format,
argument ...
);
```
## Parameters
<dl> <dt>
*format*
</dt> <dd>
The format string.
</dd> <dt>
*argument ...*
</dt> <dd>
Optional arguments.
</dd> </dl>
## Return value
This function does not return a value.
## Remarks
This operation does nothing on devices that do not support it.
### Minimum Shader Model
This function is supported in the following shader models.
| Shader Model | Supported |
|---------------------------------------------------------------------|-----------|
| [Shader Model 4 (DirectX HLSL) or later.](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm3.md) | yes |
## See also
<dl> <dt>
[Intrinsic Functions](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVltv27gS_jX0y0CCTPn64AfHiXsCtGjR5BTnLaDFscQTitSSVC776xdDXRw3bgosFthAASxy9H0z31xI4b0qDeKGza_Y_Hoi2lBZtzkK96c1enKw8nWTAJtfAZtfw23daKzRBGCLrHHKhCNbZFBoYUo4tEoHZRjfsWx7-uazMo8fmMOzChXtV9rrB2WCU8arwqcVW2RnQFspwWMtoKiwePRwtO4cN1h639Hufz7ffb7qCPatKYKyZie0JitlyOoOaxEtlSnTomkukRVWYonmV0Q3tQpveG5eGnfC333ql38HHtAH3yNGYRjf0xrj-52V-AkNcTC-7_XyjO87T1JS7JcifYBLsfeg0cnbN6AJOmedv4i9cygCQqiQQJUJD755ejjJMiav1-B2TObdt9vvP9Igf0a8NRC3bo0Pro1pukONRbCOdIPijPHEpO0zOmVKEEZCLRoAFfpYL7kVE_4LHpZvWb718W10mC2y9FLoBJL8gIMoHtHIqDEUwmPPofVT_S59JDhxM74nUZNTiZ8yqXut6eE54zlcK4dF-F-3dl-hQ1AejAXfNo114X1RPldUTcKVGEiZHiA9Q-3875buEIFx_l8frfHQlvAtglEwVB5wVwmJzjPOaakKofGkFt8zvn9q9aMwqW6NcGVaWIpb2oLxvZePjO-naZ7yVZ5mjO-flZH2mcKVRPMwlG-o9Zl39yTnTnhkfOUZX3ebEP-jBRndvAgaQjCl3UXWPbFas941-VJAR_FAmYilDMk9aHV4WDysIEEjDhqT6eKgQhJeG_SQfO3lx5eo7pNVEo6GHAmx0Jop42tgyyvyBgAchtaZnofxVdxn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