GPUOpen-Effects / FidelityFX-FSR

FidelityFX Super Resolution
MIT License
2.03k stars 164 forks source link

FSR code doesn't compile for HLSL 2021 #28

Open zigguratvertigo opened 2 years ago

zigguratvertigo commented 2 years ago

Hi,

Microsoft recently upgraded its DXC compiler with new HLSL features.

In HLSL 2021, int3 Z = X ? 1 : 0; has to be replaced with int3 Z = select(X, 1, 0);:

In the case of FSR, lines 2040-2042 in ffx_a.h:

AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2((AU2_AF2(x)!=AU2_(0))?AU2_(0):AU2_AF2(y));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3((AU3_AF3(x)!=AU3_(0))?AU3_(0):AU3_AF3(y));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4((AU4_AF4(x)!=AU4_(0))?AU4_(0):AU4_AF4(y));}

Gives this error:

ffx_a.h:2040:124: error: condition for short-circuiting ternary operator must be scalar
  float32_t2 AZolZeroPassF2(float32_t2 x,float32_t2 y){return asfloat(uint32_t2((asuint(float32_t2(x))!=AU2_x(uint32_t(0)))?AU2_x(uint32_t(0)):asuint(float32_t2(y))));}

It can be fixed this way:

AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2(select(AU2_AF2(x)!=AU2_(0),AU2_(0),AU2_AF2(y)));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3(select(AU3_AF3(x)!=AU3_(0),AU3_(0),AU3_AF3(y)));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4(select(AU4_AF4(x)!=AU4_(0),AU4_(0),AU4_AF4(y)));}

Alternatively, one can use the __HLSL_VERSION to detect if the shader is being compiled with -HV 2021:

#if __HLSL_VERSION==2021
  AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2(select(AU2_AF2(x)!=AU2_(0),AU2_(0),AU2_AF2(y)));}
  AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3(select(AU3_AF3(x)!=AU3_(0),AU3_(0),AU3_AF3(y)));}
  AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4(select(AU4_AF4(x)!=AU4_(0),AU4_(0),AU4_AF4(y)));}
#else
  AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2((AU2_AF2(x)!=AU2_(0))?AU2_(0):AU2_AF2(y));}
  AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3((AU3_AF3(x)!=AU3_(0))?AU3_(0):AU3_AF3(y));}
  AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4((AU4_AF4(x)!=AU4_(0))?AU4_(0):AU4_AF4(y));}
#endif
rys commented 2 years ago

Thanks Colin, we'll ship that fix in the next FSR point release (hopefully soon). Because ffx_a.h is also shipped by other projects, we'll also take a look at fixes for those too.