bochs-emu / Bochs

Bochs - Cross Platform x86 Emulator Project
https://bochs.sourceforge.io/
GNU Lesser General Public License v2.1
898 stars 107 forks source link

DAYTONA USA and MotoRacer 2 rendering errors in 3dfx emulation. #269

Open Githubmaniak opened 9 months ago

Githubmaniak commented 9 months ago

lBochs PC Emulator20240213103111 lBochs PC Emulator20240213104516 lBochs PC Emulator20240213105327

In the case of DAYTONA USA, if you turn off all graphic effects, part of the HUD will be displayed, but if you turn them off, part of the HUD will disappear.

In MotoRacer2, increasing the graphics quality does not display landscape/sky textures and does not increase the quality of textures other than motorcycle details.

Tested on lBochs PC Emulator(https://play.google.com/store/apps/details?id=lb.myapp.lbochs) and run in an environment with Intel Pentium MMX 30MIPS (Slowdown), CirrusLogic CL-GD5446, SoundBlaster 16, 3dfx voodoo 1 options and SM-G960N/Samsung Exynos 9810.

Vort commented 9 months ago

I installed Daytona USA, UI looks different. Probably you meant Daytona USA Deluxe. image

Githubmaniak commented 9 months ago

A separate patch is required to run DAYTONA USA in Direct3D rather than software rendering.

2024년 2월 13일 (화) 오후 6:25, Vort @.***>님이 작성:

I installed Daytona USA, UI looks different. Probably you meant Daytona USA Deluxe. image.png (view on web) https://github.com/bochs-emu/Bochs/assets/1242858/ce68f3ea-2e36-49fe-887b-d9e55bac9578

— Reply to this email directly, view it on GitHub https://github.com/bochs-emu/Bochs/issues/269#issuecomment-1940887282, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYUWUKOBAJCMAACAJGFV6ETYTMWPBAVCNFSM6AAAAABDFY4JMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBQHA4DOMRYGI . You are receiving this because you authored the thread.Message ID: @.***>

Vort commented 9 months ago

Applying changes from this commit allows UI in Daytona USA Deluxe to display correctly: bochs_dud

diff --git a/bochs/iodev/display/voodoo_data.h b/bochs/iodev/display/voodoo_data.h
index 3bde87c41..c3dc762a8 100644
--- a/bochs/iodev/display/voodoo_data.h
+++ b/bochs/iodev/display/voodoo_data.h
@@ -2862,7 +2862,7 @@ do
 {                                                                                \
   Bit32s blendr, blendg, blendb, blenda;                                         \
   Bit32s tr, tg, tb, ta;                                                         \
-  Bit32s oow, s, t, lod, ilod;                                                   \
+  Bit32s s, t, lod, ilod;                                                        \
   Bit32s smax, tmax;                                                             \
   Bit32u texbase;                                                                \
   rgb_union c_local;                                                             \
@@ -2870,15 +2870,13 @@ do
   /* determine the S/T/LOD values for this texture */                            \
   if (TEXMODE_ENABLE_PERSPECTIVE(TEXMODE))                                       \
   {                                                                              \
-    oow = fast_reciplog((ITERW), &lod);                                          \
-    s = (Bit32s)((Bit64s)oow * (ITERS) >> 29);                                   \
-    t = (Bit32s)((Bit64s)oow * (ITERT) >> 29);                                   \
+    multi_reciplog(ITERS, ITERT, ITERW, lod, s, t);                              \
     lod += (LODBASE);                                                            \
   }                                                                              \
   else                                                                           \
   {                                                                              \
-    s = (Bit32s)((ITERS) >> 14);                                                 \
-    t = (Bit32s)((ITERT) >> 14);                                                 \
+    s = (Bit32s)((ITERS) >> 24);                                                 \
+    t = (Bit32s)((ITERT) >> 24);                                                 \
     lod = (LODBASE);                                                             \
   }                                                                              \
                                                                                  \
@@ -2916,8 +2914,8 @@ do
     Bit32u texel0;                                                               \
                                                                                  \
     /* adjust S/T for the LOD and strip off the fractions */                     \
-    s >>= ilod + 18;                                                             \
-    t >>= ilod + 18;                                                             \
+    s >>= ilod + 8;                                                              \
+    t >>= ilod + 8;                                                              \
                                                                                  \
     /* clamp/wrap S/T if necessary */                                            \
     if (TEXMODE_CLAMP_S(TEXMODE))                                                \
@@ -2954,8 +2952,8 @@ do
                                                                                  \
     /* adjust S/T for the LOD and strip off all but the low 8 bits of */         \
     /* the fraction */                                                           \
-    s >>= ilod + 10;                                                             \
-    t >>= ilod + 10;                                                             \
+    s >>= ilod;                                                                  \
+    t >>= ilod;                                                                  \
                                                                                  \
     /* also subtract 1/2 texel so that (0.5,0.5) = a full (0,0) texel */         \
     s -= 0x80;                                                                   \
diff --git a/bochs/iodev/display/voodoo_func.h b/bochs/iodev/display/voodoo_func.h
index 4f6dab05d..b87e36407 100644
--- a/bochs/iodev/display/voodoo_func.h
+++ b/bochs/iodev/display/voodoo_func.h
@@ -79,6 +79,37 @@ static Bit8u dither2_lookup[256*16*2];
 /* fast reciprocal+log2 lookup */
 Bit32u voodoo_reciplog[(2 << RECIPLOG_LOOKUP_BITS) + 2];

+// ******************************************************************************************************************************
+// Computes a log2 of a 16.32 value to 2 fractional bits of precision.
+// The return value is coded as a 24.8 value.
+// The maximum error using a 4 bit lookup from the mantissa is 0.0875, which is less than 1/2 lsb (0.125) for 2 bits of fraction.
+// ******************************************************************************************************************************
+INT32 new_log2(double &value)
+{
+   static const INT32 new_log2_table[16] = { 0, 22, 44, 63, 82, 100, 118, 134, 150, 165, 179, 193, 207, 220, 232, 244 };
+   UINT64 ival = *((UINT64 *)&value);
+   // We zero the result if negative so don't worry about the sign bit
+   INT32 exp = (ival >> 52);
+   exp -= 1023 + 32;
+   exp <<= 8;
+   UINT32 addr = (UINT64)(ival >> 48) & 0xf;
+   exp += new_log2_table[addr];
+   // Return 0 if negative
+   return (ival & ((UINT64)1 << 63)) ? 0 : exp;
+}
+
+// Computes A/C and B/C and returns log2 of 1/C
+// A, B and C are 16.32 values.  The results are 24.8.
+void multi_reciplog(INT64 valueA, INT64 valueB, INT64 valueC, INT32 &log, INT32 &resA, INT32 &resB)
+{
+   double recip = double(1ULL << (47 - 39)) / valueC;
+   double resAD = valueA * recip;
+   double resBD = valueB * recip;
+   log = new_log2(recip);
+   log += 56 << 8;
+   resA = resAD;
+   resB = resBD;
+}

 void raster_function(int tmus, void *destbase, Bit32s y, const poly_extent *extent, const void *extradata, int threadid) {
    const poly_extra_data *extra = (const poly_extra_data *) extradata; 

I don't know however if this change is good enough and what consequences it have.