From d447e8d5c7c89e8969f2e74c649cb802cf4f4216 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Tue, 10 Jul 2018 19:08:27 +0200 Subject: [PATCH] nv2a: Add ARL-bias to work around OpenGL float behaviour --- hw/xbox/nv2a/nv2a_vsh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/xbox/nv2a/nv2a_vsh.c b/hw/xbox/nv2a/nv2a_vsh.c index c413fe5de9..97ccb58101 100644 --- a/hw/xbox/nv2a/nv2a_vsh.c +++ b/hw/xbox/nv2a/nv2a_vsh.c @@ -627,7 +627,16 @@ static const char* vsh_header = "#define ARL(dest, src) dest = _ARL(_in(src).x)\n" "int _ARL(float src)\n" "{\n" - " return int(floor(src));\n" + " /* Xbox GPU does specify rounding, OpenGL doesn't; so we need a bias.\n" + " * Example: We probably want to floor 16.99.. to 17, not 16.\n" + " * Source of error (why we get 16.99.. instead of 17.0) is typically\n" + " * vertex-attributes being normalized from a byte value to float:\n" + " * 17 / 255 = 0.06666.. so is this 0.06667 (ceil) or 0.06666 (floor)?\n" + " * Which value we get depends on the host GPU.\n" + " * If we multiply these rounded values by 255 later, we get:\n" + " * 17.00 (ARL result = 17) or 16.99 (ARL result = 16).\n" + " * We assume the intend was to get 17, so we add our bias to fix it. */\n" + " return int(floor(src + 0.001));\n" "}\n" "\n" "#define SGE(dest, mask, src0, src1) dest.mask = _SGE(_in(src0), _in(src1)).mask\n"