Issue 97624
Summary Implement the `InstanceID` HLSL Function
Labels backend:DirectX, HLSL, backend:SPIR-V, HLSL_Bot
Assignees
Reporter farzonl
    - [ ] Implement `InstanceID` clang builtin,
- [ ] Link `InstanceID` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `InstanceID` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `InstanceID` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/InstanceID.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/InstanceID-errors.hlsl`
- [ ] Create the `int_dx_InstanceID` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_InstanceID` to  `141` in `DXIL.td`
- [ ] Create the  `InstanceID.ll` and `InstanceID_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_InstanceID` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `InstanceID` lowering and map  it to `int_spv_InstanceID` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/InstanceID.ll`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 141 | InstanceID | 6.3 | ('library', 'intersection', 'anyhit', 'closesthit') |

## SPIR-V

See https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/InstanceCustomIndexKHR.html

## Test Case(s)

 
 ### Example 1
```hlsl
//dxc InstanceID_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint fn() {
    return InstanceID();
}
```
 ### SPIRV Example(s):

 ### Example 2
```hlsl
//dxc InstanceID_spirv_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

[shader("intersection")]
void fn() {
uint 	ret = InstanceID();
}
```
## HLSL:

The user-provided identifier for the instance on the bottom-level acceleration structure instance within the top-level structure.

## Syntax

```
uint InstanceID();

```



## Remarks

This function can be called from the following raytracing shader types:

* [**Any Hit Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3d12/any-hit-shader.md)
* [**Closest Hit Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3d12/closest-hit-shader.md)
* [**Intersection Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3d12/intersection-shader.md)







## See also

<dl> <dt>

[Direct3D 12 Raytracing HLSL Reference](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3d12/direct3d-12-raytracing-hlsl-reference.md)
</dt> </dl>
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to