From 080672478d2170c8b467f254a92723099cab78b8 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Fri, 28 Feb 2025 13:25:21 -0300 Subject: [PATCH] tests/hlsl: Test integer modulus with big integers. Note that in d3dbc target profiles it gives different results when this operation is constant folded compared to when it is not. This suggests that whatever pass lowers the modulus operation to d3dbc operations doesn't do it before constant folding. Also note that when constant folded, d3dbc results differ from tpf results for negative operands, because of the loss of precision that happens when NEG is constant folded. So the same integer modulus expression can have 3 different results depending on the context. --- tests/hlsl/arithmetic-int-uniform.shader_test | 17 +++++++++++++++++ tests/hlsl/arithmetic-int.shader_test | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tests/hlsl/arithmetic-int-uniform.shader_test b/tests/hlsl/arithmetic-int-uniform.shader_test index 05605a36..dc15850b 100644 --- a/tests/hlsl/arithmetic-int-uniform.shader_test +++ b/tests/hlsl/arithmetic-int-uniform.shader_test @@ -120,6 +120,23 @@ uniform 4 float4 3.0 8.0 2.0 5.0 todo(sm<4 | glsl | msl) draw quad probe (0, 0) rgba (9.0, 5.0, 1.0, 3.0) +[pixel shader todo(sm<4)] +float f; + +float4 main() : sv_target +{ + int a = 16777217; // This rounds down to 16777216 when converted to float. + int b = f; + + return float4(a % b, a % (-b), (-a) % b, (-a) % (-b)); +} + +[test] +uniform 0 float 10.0 +todo(sm<4 | glsl | msl) draw quad +if(sm<4) probe (0, 0) rgba(6, 6, -6, -6) +if(sm>=4) probe (0, 0) rgba(7, 7, -7, -7) + [require] shader model >= 6.0 int64 diff --git a/tests/hlsl/arithmetic-int.shader_test b/tests/hlsl/arithmetic-int.shader_test index 84edb276..8bff402f 100644 --- a/tests/hlsl/arithmetic-int.shader_test +++ b/tests/hlsl/arithmetic-int.shader_test @@ -165,3 +165,17 @@ float4 main() : sv_target draw quad todo if(sm<4) probe (0, 0) rgba(16782202, 16782200, 0, 0) if(sm>=4) probe (0, 0) rgba(16782202, 16782202, 0, 0) + +[pixel shader] +float4 main() : sv_target +{ + int a = 16777217; // This rounds down to 16777216 when converted to float. + int b = 10; + + return float4(a % b, a % (-b), (-a) % b, (-a) % (-b)); +} + +[test] +draw quad +todo if(sm<4) probe (0, 0) rgba(7, 7, -6, -6) +if(sm>=4) probe (0, 0) rgba(7, 7, -7, -7)