https://bugs.dolphin-emu.org/https://bugs.dolphin-emu.org/favicon.ico?12020-04-12T19:02:30ZDolphin bug trackerEmulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7388892020-04-12T19:02:30ZJMC4789JMC4789@gmail.com
<ul></ul><p>I believe this is a case of a game using custom mipmaps for a texture, and higher resolution makes it so mipmaps are used at different resolutions. If you dump the texture for this we could be sure.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7402702020-09-12T13:15:13ZJMC4789JMC4789@gmail.com
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Accepted</i></li></ul><p>I tested this and I confirmed it IS NOT arbitrary mipmaps (at least our heuristic doesn't catch it?) and the distance seems to grow based on your resolution.</p>
<p>I do not know what causes this or if we can fix it.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458282023-01-19T12:06:03Zcolorovfire
<ul><li><strong>File</strong> <a href="/attachments/9416">image-2.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/9416/image-2.png">image-2.png</a> added</li></ul><p>JMC4789 wrote in <a href="#note-2">#note-2</a>:</p>
<blockquote>
<p>I tested this and I confirmed it IS NOT arbitrary mipmaps (at least our heuristic doesn't catch it?) and the distance seems to grow based on your resolution.</p>
<p>I do not know what causes this or if we can fix it.</p>
</blockquote>
<p>Arbitrary mipmap threshold isn’t low enough to catch it. I copied over the value I used for F-Zero and it seemed to fix it.</p>
<pre><code>[Video_Enhancements]
ArbitraryMipmapDetectionThreshold = 8.3
</code></pre>
<p>It’s most likely not an optimal value.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458292023-01-19T12:23:05Zcolorovfire
<ul><li><strong>File</strong> <a href="/attachments/9417">Screenshot 2023-01-19 at 7.09.26 AM.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/9417/Screenshot%202023-01-19%20at%207.09.26%20AM.png">Screenshot 2023-01-19 at 7.09.26 AM.png</a> added</li><li><strong>File</strong> <a href="/attachments/9418">Screenshot 2023-01-19 at 7.09.03 AM.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/9418/Screenshot%202023-01-19%20at%207.09.03%20AM.png">Screenshot 2023-01-19 at 7.09.03 AM.png</a> added</li></ul><p>There’s also the lights on the side within the tunne (same map)l. The threshold has to be set to an extremely low value of <code>2.22</code>. It should never be set this low but if anyone creates a texture pack, they can temporarily set it so it’s dumped as an arbitrary mipmap texture. Anyone using the textures wouldn’t have to change ArbitraryMipmapDetectionThreshold at all and have it work correctly.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458322023-01-19T19:33:56Zpokechu22
<ul><li><strong>Subject</strong> changed from <i>Certain light effects are wrong on higher resolutions</i> to <i>Arbitrary mipmap detection fails for certain textures in Toad's Factory</i></li></ul><p>The affected textures are <code>tex1_256x256_m_db626658aab6e356_14.png</code> for the conveyer belt (darkest at its highest resolution, then half-bright at 128 by 128, then full bright at 64 by 64, then half bright at 32 by 32, then like a quarter bright at 16 by 16) and <code>tex1_256x512_m_fc58ac1b2dbeb111_14.png</code> for the walls (brightest at its highest resolution, then half-bright at 128 by 256, then equally dark at 64 by 128, 32 by 64, and 16 by 32).</p>
<p>These are also the whole belt or wall texture, with only a small part changing; it's not a transparent texture that's drawn over another one. Since most of the texture doesn't change, I can see why this would cause problems for the heuristic.</p>
<p>Maybe the heuristic could be modified so that if most of the image matches perfectly but a small portion doesn't, it treats it as non-matching? Though that seems like it would invite a lot more incorrect cases.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458342023-01-19T19:34:05Zpokechu22
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-3 priority-2 priority-default closed" href="/issues/128">Emulator Issues #128</a>: Issue with AMD processors and CPU Detection for SSE2</i> added</li></ul> Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458362023-01-19T19:34:09Zpokechu22
<ul><li><strong>Related to</strong> deleted (<i><a class="issue tracker-1 status-3 priority-2 priority-default closed" href="/issues/128">Emulator Issues #128</a>: Issue with AMD processors and CPU Detection for SSE2</i>)</li></ul> Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458372023-01-19T19:34:12Zpokechu22
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-7 priority-2 priority-default" href="/issues/12942">Emulator Issues #12942</a>: Arbitrary Mipmap Detection fails for water in F-Zero GX</i> added</li></ul> Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458422023-01-20T20:57:02Zcolorovfire
<ul><li><strong>File</strong> <a href="/attachments/9419">MKW Toad_s Factory arbmip min value.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/9419/MKW%20Toad_s%20Factory%20arbmip%20min%20value.png">MKW Toad_s Factory arbmip min value.png</a> added</li></ul><p>pokechu22 wrote in <a href="#note-5">#note-5</a>:</p>
<blockquote>
<p>Maybe the heuristic could be modified so that if most of the image matches perfectly but a small portion doesn't, it treats it as non-matching? Though that seems like it would invite a lot more incorrect cases.</p>
</blockquote>
<p>Current heuristics is a complete mystery to me. The default threshold is 14 but I don’t even know how it scales. The differences on tex1_256x256_m_db626658aab6e356_14 looks like an easy one to catch but it misses it.</p>
<p>Attached a graphic with minimum values for it to flag as arbitrary.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458432023-01-21T06:47:41Zpokechu22
<ul></ul><p>The heuristic is <a href="https://github.com/dolphin-emu/dolphin/blob/c49517c6c9e91b12db890ece5f69cc047df31268/Source/Core/VideoCommon/TextureCacheBase.cpp#L1096-L1223" class="external">this code</a>, which calculates the <a href="https://en.wikipedia.org/wiki/Root-mean-square_deviation" class="external">RMSE</a> for all texels across all levels (the comment says <a href="https://en.wikipedia.org/wiki/Mean_squared_error" class="external">MSE</a>, but it takes a square root). Basically, for each mipmap level, it first computes what the expected downsampled value is (by averaging the 4 corresponding ones), then compares that with the actual downsampeled value, as <code>diff = (old_r - new_r)^2 + (old_g - new_g)^2 + (old_b - new_b)^2 + (old_a - new_a)^2</code>. After, it takes a square root, then divides by the number of pixels times 4 (to account for the 4 channels), then divides by 2.56 (i.e. divides by 256 and multiplies by 100) so that the final value is (theoretically) in the range 0-100. Then, the overall value for the texture is the average for all mipmap levels.</p>
<p>This has a few problems. For one, if the texture doesn't have an alpha channel, the alpha value is 1 for everything, meaning the difference for that is zero. So the highest value possible would be 75% if a texture alternated from fully black to fully white across all mipmaps. Furthermore, averaging across all mipmap levels means that if only one has a significant difference, the overall result is low. And, if only a small part is different, then the overall difference is low too (the light makes up maybe a 24 by 96 area in the 256 by 512 wall texture, so that's 2304/131072 or about 1.75% of the image, and that's assuming a transition from full black to full white).</p>
<p>I <a href="https://gist.github.com/Pokechu22/c8c0e2d5a10db69af3ad264a7fb5494c" class="external">added some logging</a> to get additional information. Here's the output:</p>
<pre><code>Melty molten galaxy lava:
00:39:606 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 0: 9.646446
00:39:606 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 1: 15.235299
00:39:606 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 2: 17.893211
00:39:606 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 3: 23.713253
00:39:606 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 4: 22.17285
Conveyor belts:
01:09:503 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 0: 11.146211
01:09:503 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 1: 23.25801
01:09:503 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 2: 11.902312
01:09:503 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 3: 7.3496165
Walls with lights:
02:27:735 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 0: 1.6436607
02:27:736 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 1: 2.4542139
02:27:736 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 2: 2.7571242
02:27:736 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 3: 2.0296555
</code></pre>
<p>I also tried out a <a href="https://en.wikipedia.org/wiki/Mean_absolute_error" class="external">MEA</a> (i.e. sum <code>abs(expected - actual)</code> instead of <code>(expected - actual)^2</code>), which gave these results (not an improvement):</p>
<pre><code>Melty molten galaxy lava:
04:48:792 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 0: 4.979426
04:48:792 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 1: 8.881092
04:48:793 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 2: 10.592461
04:48:793 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 3: 14.145279
04:48:793 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_efb7885b915ac15a_14 level 4: 13.703918
Conveyor belts:
05:18:107 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 0: 5.4535093
05:18:107 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 1: 11.131406
05:18:107 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 2: 6.4382553
05:18:107 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x256_m_db626658aab6e356_14 level 3: 4.327774
Walls with lights:
05:51:033 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 0: 0.8841753
05:51:033 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 1: 1.4223695
05:51:034 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 2: 1.6636372
05:51:034 VideoCommon\TextureCacheBase.cpp:1134 I[Video]: tex1_256x512_m_fc58ac1b2dbeb111_14 level 3: 1.3334274
</code></pre>
<p>I can't think of a better heuristic, unfortunately.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458442023-01-21T16:50:50Ziwubcode
<ul></ul><p>I've been told of other scenarios where arbitrary mipmap detection produces false positives. My plan is to introduce a graphics mod capability that allows you to explicitly enable (or disable) the feature for specific textures.</p>
Emulator - Emulator Issues #12047: Arbitrary mipmap detection fails for certain textures in Toad's Factoryhttps://bugs.dolphin-emu.org/issues/12047?journal_id=7458542023-01-23T23:50:05Zcolorovfire
<ul></ul><p>pokechu22 wrote in <a href="#note-10">#note-10</a>:</p>
<blockquote>
<p>I can't think of a better heuristic, unfortunately.</p>
</blockquote>
<p>Would it make sense to detect the threshold per mipmap level instead the average across all levels? There’s too much variations where any significant changes can get averaged out.</p>
<p>BTW, that bit of code for arbitrary detection runs even if it’s running at 1x with anisotropic filtering disabled. Nothing need to be detected since the distinction doesn’t matter at that point. It would save some CPU time.</p>