Skip to content

anv,driconf: Add sampler coordinate precision workaround for AoE 4

Sviatoslav Peleshko requested to merge GL/mesa:fix_aoe4_bug into main

The Age of Empires IV has a visual glitch because at one point it samples the texture using NEAREST mode and coordinates that point right between texels, and the HW sampler precision seems to be not enough to produce the expected results.

More specifically, it uses the compute shader invocation coordinates multiplied by the inverse of the texture size, and expects to get the same texel as gl_GlobalInvocationID.xy points to. While in reality, sampler usually returns texel at gl_GlobalInvocationID.xy - (1, 1). This would've already resulted in wrongly calculated (much brighter) lighting. But even worse thing is that sometimes sampler actually gives the "expected" texel, which due to the logic of the shader it results in these highly contrast stripes.

The thing is, with the coordinates passed to the sampler, and texture size, the coordinates would point to the correct texel if the sampler used the regular full-precision IEEE float multiplication internally. But PRMs don't really specify anything about its implementation, nor does the Vulkan spec has any demands about that, if I understand correctly. I've implemented a simple repro, in case anyone wants to look into this further, but it seems that there's not a lot we can do.

Meanwhile, I've found the workaround - to always enable SAMPLER_STATE::U/V/R Address Min/Mag Filter Rounding Enable. This commit adds a driconf option for that and enables it for the game. This fixes the stripes on the screen, and as far as I can see doesn't break anything else.

Closes: #9864 (closed) cc: @llandwerlin

Merge request reports