Describe the bug
MAME shows palette problems when used in conjunction with BGFX and shaders.
This is a well known problem, caused by the loss of precision on the shaders, documented as an issue on the MAME issues here:
mamedev/mame#14022 (comment)
To Reproduce
Steps to reproduce the behavior:
- Configure MAME to use the BGFX Video Mode
- Start cninja with mame cninja
- Play and observe the game.
Expected behavior
The game should not have palette problems.
Screenshots
MAME running Caveman Ninja with BGFX shaders, showing palette problems:
MAME running Caveman Ninja without BGFX shaders, showing correct colors:
Additional context
The problem comes from how BGFX handles precision. MESA does the right thing.
From the MESA developers:
If the application depends on high precision it should set high precision. Saying "but it works on other implementations and so should work on mesa" completely misses the point.
Optimisations are done on shaders based on the information provided by the shader, if the shader says its safe to lose precision then compilers will take advantage of that fact. Just because Mesa results in less precision for this shader and other drivers don't doesn't mean there aren't shaders where the opposite happens i.e. mesa retains precision and other drivers don't. Each compiler has different optimisations and different ordering of optimisations. Trying to match the behaviour of other drivers optimisations is a fool's errand.
And just in case I'm not completely clear here. Let's say we were able to force mesa to behave the same as other drivers here, there is nothing stopping all those other drivers to change their behaviour as their optimisations are updated in future. Which means now mesa is again out of sync and Mame now fails on those drivers also.
Here's the thread on the MESA repository where this was discussed:
https://gitlab.freedesktop.org/mesa/mesa/-/work_items/13555#note_3057209
Describe the bug
MAME shows palette problems when used in conjunction with BGFX and shaders.
This is a well known problem, caused by the loss of precision on the shaders, documented as an issue on the MAME issues here:
mamedev/mame#14022 (comment)
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The game should not have palette problems.
Screenshots
MAME running Caveman Ninja with BGFX shaders, showing palette problems:
MAME running Caveman Ninja without BGFX shaders, showing correct colors:
Additional context
The problem comes from how BGFX handles precision. MESA does the right thing.
From the MESA developers:
Here's the thread on the MESA repository where this was discussed:
https://gitlab.freedesktop.org/mesa/mesa/-/work_items/13555#note_3057209