NVIDIAGameWorks / RayTracingDenoiser

NVIDIA Ray Tracing Denoiser
Other
504 stars 46 forks source link

Compilation problem with HLSL 2021 #42

Closed JiayinCao closed 2 years ago

JiayinCao commented 2 years ago

Hi,

It recently comes to my attention that the NRD.hlsli has these two lines

float2 octWrap = ( 1.0 - abs( v.yx ) ) * ( v.xy >= 0.0 ? 1.0 : -1.0 );

line 233

n.xy += n.xy >= 0.0 ? -t : t;

line 246

It would be nice if the header file could add a macro to identify the HLSL version as in HLSL 2021 as these two lines won't compile. https://github.com/microsoft/DirectXShaderCompiler/wiki/HLSL-2021#logical-operation-short-circuiting-for-scalars

So for project with HLSL 2021 setup, they would have to adjust the code manually to workaround the issue. Ideally, this could be skipped by asking the user to define something like NRD_HLSL_2021

And do something like this

#if NRD_HLSL_2021
    float2 octWrap = (1.0 - abs(v.yx)) * select(v.xy >= 0., 1., -1.);
#else
    float2 octWrap = ( 1.0 - abs( v.yx ) ) * ( v.xy >= 0.0 ? 1.0 : -1.0 );
#endif

This way, the users of the denoiser would not need to touch the code inside the header to fix the compiling issue.

Thanks Jiayin

dzhdanNV commented 2 years ago

Thanks. I have fixed this issue in a simple and portable way. Currently I did it only for NRD.hlsli, but sooner rather than later I will ensure that all shader code is HLSL 2021 compatible. I will update the repo tomorrow.

dzhdanNV commented 2 years ago

Fixed.