From 5eddc26850072042a87e1f0b87a2adef207d5ea1 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 26 Sep 2023 17:05:21 +0200 Subject: [PATCH] dx11: work around some float literal precision issue with the compiler For some reason the directx compiler doesn't convert float literal in a deterministic way (!). A difference of one ulp can be seen between different compilation of the same code. This causes an issue with the rounding of the alpha value for PT polys. Issue #1207 --- core/rend/dx11/dx11_shaders.cpp | 2 +- core/rend/dx11/oit/dx11_oitshaders.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/rend/dx11/dx11_shaders.cpp b/core/rend/dx11/dx11_shaders.cpp index 31150fde9..92f8cf236 100644 --- a/core/rend/dx11/dx11_shaders.cpp +++ b/core/rend/dx11/dx11_shaders.cpp @@ -295,7 +295,7 @@ PSO main(in Pixel inpix) #endif #if cp_AlphaTest == 1 - color.a = round(color.a * 255.0f) / 255.0f; + color.a = round(color.a * 255.0f) * 0.0039215688593685626983642578125; // 1 / 255 if (alphaTestValue > color.a) discard; color.a = 1.0f; diff --git a/core/rend/dx11/oit/dx11_oitshaders.cpp b/core/rend/dx11/oit/dx11_oitshaders.cpp index b6e3bd9f8..89df0409b 100644 --- a/core/rend/dx11/oit/dx11_oitshaders.cpp +++ b/core/rend/dx11/oit/dx11_oitshaders.cpp @@ -521,7 +521,7 @@ PSO main(in VertexIn inpix) color *= trilinearAlpha; #if cp_AlphaTest == 1 - color.a = round(color.a * 255.0f) / 255.0f; + color.a = round(color.a * 255.0f) * 0.0039215688593685626983642578125; // 1 / 255 if (alphaTestValue > color.a) discard; color.a = 1.0f;