joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.77k stars 381 forks source link

Demoscene testing: "Explora" exhibits 3D rendering artifacts (lack of FPU precision) #999

Closed joncampbell123 closed 5 years ago

joncampbell123 commented 5 years ago

Describe the bug The 3D rasterization of the demo has overlarge or missing scan lines on the edges of 3D geometry.

To Reproduce Steps to reproduce the behavior:

  1. Run "Explora" in DOSBox-X
  2. Observe glitches on the edges of some 3D geometry

Demo download link:

http://files.scene.org/get:nl-http/mirrors/hornet/demos/1996/e/explora.zip

joncampbell123 commented 5 years ago

Another demo by the same group "Eden" does not exhibit the same artifacts.

joncampbell123 commented 5 years ago

explora_000 avi

joncampbell123 commented 5 years ago

The demo run in DOSBox SVN does not have these artifacts and rasterization errors.

joncampbell123 commented 5 years ago

It doesn't seem to matter which core is used in DOSBox-X (on x86_64 Linux).

An initial analysis shows a lot of 32-bit and 64-bit float FLD and FST use. The proportions seem to imply the vertices use 64-bit float and the texture mapping uses 32-bit float.

joncampbell123 commented 5 years ago

If I cannot determine the problem through the debugger I will have to tackle the problem by writing FPU test programs in DOSLIB to run through possible combinations of math and/or conversions from float to int that may be involved.

joncampbell123 commented 5 years ago

I just incorporated the x86 FPU support (fpu_instructions_x86.h) from DOSBox SVN which seems to fix the glitches.

So it's a precision issue. Something about the demo's rendering code needs the full 80-bit precision. The non-x86 emulation uses "double" which does NOT provide that precision.

The best way to fix the issue entirely for non-x86 targets is to change the non-x86 emulation to use "long double" instead of "double" which on most targets enables the full 80-bit precision, except on Microsoft's C++ compiler where long double is the same as double. However Microsoft C++ is only supported with this code for x86 and x86_64 targets anyway, so fpu_instructions_x86.h will fill that gap.

joncampbell123 commented 5 years ago

https://code.woboq.org/userspace/glibc/sysdeps/x86/fpu_control.h.html

joncampbell123 commented 5 years ago

Demo requires full 80-bit precision, seems dependent on that with FMUL and FDIV.

Using the long double core on x86 and the x86 core fixes that.

The normal non-x86 core isn't going to provide enough precision to emulate it properly.