llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.43k stars 12.16k forks source link

Implement the `InstanceID` HLSL Function #97624

Open farzonl opened 5 months ago

farzonl commented 5 months ago

DirectX

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

SPIR-V

## Description
` InstanceCustomIndexKHR ` A variable decorated with the ` InstanceCustomIndexKHR ` decoration will contain the application-defined value of the instance that intersects the current ray. This variable contains the value that was specified in [VkAccelerationStructureInstanceKHR](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/None) :: ` instanceCustomIndex ` for the current acceleration structure instance in the lower 24 bits and the upper 8 bits will be zero.
Valid Usage
- VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04251 The ` InstanceCustomIndexKHR ` decoration **must** be used only within the ` IntersectionKHR ` , ` AnyHitKHR ` , or ` ClosestHitKHR ` ` Execution ` ` Model ` - VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04252 The variable decorated with ` InstanceCustomIndexKHR ` **must** be declared using the ` Input ` ` Storage ` ` Class ` - VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04253 The variable decorated with ` InstanceCustomIndexKHR ` **must** be declared as a scalar 32-bit integer value

Test Case(s)

Example 1

//dxc InstanceID_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint fn() {
    return InstanceID();
}

SPIRV Example(s):

Example 2

//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:

See also

[Direct3D 12 Raytracing HLSL Reference](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/direct3d-12-raytracing-hlsl-reference.md)
farzonl commented 5 months ago

@EugeneZelenko These bugs were created via automation. There are going to be about 160+ of these coming in. This first run was just a test. Would you like me to add the metabug label to all the issues created by the bot?

EugeneZelenko commented 5 months ago

@farzonl: metabug label should be used for issues that are used for tracking multiple issues, so bot could apply the label to such issues.

farzonl commented 4 months ago

@EugeneZelenko This is the list of bugs we are going to be adding to llvm-project next week: please let me know if you see something glaring that would be painful for you: https://github.com/farzonl/test_repo/issues/157

EugeneZelenko commented 4 months ago

@farzonl: This is good example of metabug :-) But I did not look on each issue. Some of them may be of metabug kind.