llvm / llvm-project

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

[HLSL] Implement derivative intrinsics #88820

Open hekota opened 4 months ago

hekota commented 4 months ago

Implement HLSL derivative intrinsics ddx, ddx_fine, ddx_coarse, ddy , ddy_fine and ddy_coarse.

https://godbolt.org/z/1Ej8514MY

The ddx and ddy intrinsic were initially introduced in Shader Model 2.1 for pixel shaders: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-ddx https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-ddy

Shader Model 5.0 added ddx_fine, ddx_coarse, ddy_fine and ddy_coarse, also just for pixel shaders: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddx-fine https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddx-coarse https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddy-fine https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddy-coarse

In DirectX the ddx and ddy functions default to coarse behavior - ddx is the same as ddx_coarse and ddy is the same as ddy_coarse.

In Shader model 6.6 the derivative intrinsics support was extended to compute, mesh and amplification shaders: https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Derivatives.html

davidcook-msft commented 4 months ago

Need an additional discussion on if we are using the rich availability diagnostics to also validate the numthreads on shaders using derivative intrinsics.

Conversation around if the availability diagnostics should be used for larger analysis should happen on the diagnostics spec.