protonscr

Support for optimized mapping of min16float to SPV_AMD_gpu_shader_half_float..

dxvkclosed wontfix
doitsujin/dxvk#571 · opened 2018-08-17 by oscarbg · updated 2019-07-05 · 2 comments · github
1 matching comments, n / p to jump
Ooscarbg 2018-08-17 github

Hi,
seeing double precision done, just thought I had a Mandelbrot sample using HLSL min16float extensions..
this allows DX drivers &GPUs supporting it to see a perf. gain of near 2x..
Download Program-->
reprosend.zip

currently tested working on Intel HD 530 and AMD Vega GPUs..
of course this useful for games as Far Cry5 already uses it:
https://www.overclock3d.net/news/software/ubisoft_details_their_use_of_fp16_compute_rapid_packed_math_in_far_cry_5/1
https://twvideo01.ubm-us.net/o1/vault/gdc2018/presentations/Grujic_Branislav_WaterRenderingFarCry5.pdf
altough much marketing goes in AMD advantage this is exploitable also on Intel iGPUs and possibly Nvidia GPUs once they enable in their DX11 driver (Turing?)
In Vulkan currently half precision only is enabled on AMD driver (closed one) by using SPV_AMD_gpu_shader_half_float..
but at Siggraph Khronos Vulkan group has shared they are working on reduced precision support so seems a KHR ext is coming soon..
but SPIR-V already is ready for it in fact using
OpTypeFloat 16
in HLSL basically changing some variables to min16float does the trick..
once using it manifests in fxc disasm as:

// Note: shader requires additional functionality:
// Minimum-precision data types

and things like:
dtof r2.xy {min16f}, CB0[0][2].xyzw {def32 as min16f}
movc r2.xy {min16f}, CB0[0][3].yyyy, r2.xyxx {min16f}, r0.yzyy {def32 as min16f}
mad r2.w {min16f}, r2.y {min16f}, r2.y {min16f}, r2.x {min16f}

currently DXC allows generating SPIR-V code using SPV_AMD_gpu_shader_half_float for HLSL using min16float:
dxc mandel.hlsl -T cs_6_2 -E CSMandelJulia_scalarFloat -enable-16bit-types -spirv -O0 -Fc dxcscalar.txt
the DXC output contains:
OpExtension "SPV_AMD_gpu_shader_half_float"
%half = OpTypeFloat 16
and
%172 = OpLoad %half %v
%173 = OpFMul %half %171 %172
%174 = OpFAdd %half %170 %173

I attach the program to test mandel.exe that uses mandel.hlsl..
in "out" folder I captured(with DXVK_SHADER_DUMP_PATH) your spv shaders for confirming you don't
use any half support..
in "txt" you see dxc and fxc txt disassembled output I comment..

note as said DXVK already works but ignoring {def32 as min16f},{min16f} tags in DXBC..
the idea should be DXVK to use OpExtension "SPV_AMD_gpu_shader_half_float" if avaiable and generate "%half = OpTypeFloat 16" and "half" math ops..
As said can test on a Vega GPU on Far Cry 5 to see if there are speedups..

as said your effort will pay off in the near future for possibly also Nvidia GPUs using
"OpCapability Float16"(?) in case standarized

Ddoitsujin maintainer 2018-08-17 github

There is basically no documentation for the min16 hints.

I suspect that this would be extremely hard to implement because DXBC registers are not typed, and if this is as bad as the rest of DXBC, it may require implicit conversion between 16 and 32 bit floats for every single instruction. I have no intention to support this because DXVK lacks the required compiler infrastructure.

Second problem is that I have absolutely zero test cases for this kind of stuff - it's only really beneficial on Vega and Far Cry 5 is the only game that uses it. Closing as #wontfix.

Ooscarbg 2019-07-05 github

just updating the issue saying we have now half cross vendor support:

*VK_KHR_shader_float16_int8

that is supported everywhere (NV,AMDVLK,Mesa RADV,Mesa ANV,Intel&AMD Win drivers):

*Nvidia: Turing & Volta should be fast (Pascal too?))
*Intel: Skylake and higher should be fast too..
*Vega &upcoming Navi..

and also another game possibly uses it: Far Cry New Dawn (?)

Launch options