Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[D3D9] Implement Clamp Negative LOD-Bias #2779

Closed
ViNi-Arco opened this issue Aug 2, 2022 · 18 comments
Closed

[D3D9] Implement Clamp Negative LOD-Bias #2779

ViNi-Arco opened this issue Aug 2, 2022 · 18 comments

Comments

@ViNi-Arco
Copy link

Hello, I was always afraid to ask if it would be possible to implement a way to Clamp the Lod, because I thought it would be something impossible to implement in DXVK, but this recent commit from Mr. Philip showed me that it might be possible.

Clamp Negative LOD-Bias (which would prevent using negative LOD values for texture filtering and replace them with 0.0)

It would help a lot to fix the texture shimmering in old games.

Here are images and mentions of what I mean if it was not very clear, sorry for my bad English.
https://www.bsimracing.com/nvidia-image-quality-lower-on-newer-cards/
https://linustechtips.com/topic/499767-low-image-quality-on-newer-gpus/page/2/#comment-6675744

@lextra2
Copy link

lextra2 commented Aug 2, 2022

If a game has texture shimmering, it probably means it isn't using mipmaps in the first place, which means you also cannot clamp them with dxvk

On the commit, I don't get why it uses float instead of an integer value? And while I personally have not tested it, I hope the
Clamp LOD bias so that people don't abuse this in unintended ways
does not mean it prevents games from having no textures at all (in case of using a high positive offset).

@doitsujin
Copy link
Owner

doitsujin commented Aug 2, 2022

On the commit, I don't get why it uses float instead of an integer value?

Because the LOD bias is not an integer property, it's a float property, and values like -0.5 are rather common.

The motivation for that particular commit was that Nioh 2 does not use a negative LOD bias when DLSS enabled, which leads to blurry textures.

does not mean it prevents games from having no textures at all (in case of using a high positive offset).

It prevents you from putting a very high number into a config file and do things like this. The option does not affect how any game works by default. The clamp is only for the config option, not for the value that the sampler is created with.

@lextra2
Copy link

lextra2 commented Aug 2, 2022

Because the LOD bias is not an integer property, it's a float property, and values like -0.5 are rather common.

Yeah. I expected this answer. Actually, I mistook MeshLODbias for MipMapLODbias. My bad.

It prevents you from putting a very high number into a config file and do things like this. The option does not affect how any game works by default. The clamp is only for the config option, not for the value that the sampler is created with.

And yes. That is exactly what I'm talking about. IMHO a blacklist for games that ban for this would be a better approach (Or at least a way to overwrite the clamping limit "at your own risk" kind of thing)

@doitsujin
Copy link
Owner

doitsujin commented Aug 2, 2022

And yes. That is exactly what I'm talking about. IMHO a blacklist for games that ban for this would be a better approach (Or at least a way to overwrite the clamping limit "at your own risk" kind of thing)

I assume you're going to maintain an exhaustive list of all potentially affected online games then, and implement a solution to restrict it for future games as well?

The intended use case for this option is to allow people to improve visuals in some circumstances, not to mess around with games in unintended ways, and most certainly not to trivialize cheating. If you want to do either of those things anyway, go ahead, modify the code, build it yourself, we can't and won't stop you. But the limitation will stay, end of discussion.

@HunterCZ122
Copy link

Good alternative is to use libstrangle which has env vars to adjust picmip and texture filtering. Beware this will not fix the shimmering in old games without mipmaps.

@pchome
Copy link
Contributor

pchome commented Aug 2, 2022

For e.g. FSR they recommend to add -log2(OutHeight/InHeight), so -2 should be enough for scaling 720 -> 5K, but for Performance profiles this values will be small (-0.38 or so for Ultra)

For 1080p -> 1440p upscaling AMD recommends a negative bias between 0.38 and 0.58

Try this with gamescope or GE FSR with Performance profiles and see if this improve something.

libstrangle should implement += mode too, because it much friendly to AF than replacing everything (LodBias) with fixed values, in most cases. Try to force LodBias=-1 and AF=16 and then AF=0 with libstrangle to see the difference.

EDIT: 0.58 for Performance profile, e.g. 720 -> 1080
log2 it's log(OutHeight/InHeight)/log(2), in case no log2 in your favorite Calc program.

@ViNi-Arco
Copy link
Author

If a game has texture shimmering, it probably means it isn't using mipmaps in the first place

Hi there, it's not about mipmap, the problem is that game developers are forcing a negative value in their games this leaves fences and power wires all broken, the option in the Nvidia driver is for this, any negative sharpness like -1 or -2 in the game is forced to 0, you could look at the links I provided

@lextra2
Copy link

lextra2 commented Aug 2, 2022

Hi there, it's not about mipmap, the problem is that game developers are forcing a negative value in their games

Oh ok. Fair enough.

@pchome
Copy link
Contributor

pchome commented Aug 3, 2022

d3d11.samplerLodBias=1 will lower quality a bit but also should help a little in racing games. I tested this and result rather ok.
If you need Clamping for some games try to patch libstrangle to do this, or try to create your own vulkan layer with e.g. vkroots

@ViNi-Arco
Copy link
Author

What's Up pchome
I've tried Libstrangle and even your VkGHL, but there is a problem, they blur the whole game, I'm not looking for that, I'm talking about a way to block any negative LOD value, like Nvidia's Clamp Negative LOD-Bias, for example the game developer passes a negative value of -1 in a specific texture, the Clamp Negative LOD-Bias transforms it into 0.0 instead of blurring the whole game, it takes away this excessive sharpness only from that texture..

Standard game:
Standard game

Game with Clamp Negative LOD-Bias:
 Game with Clamp Negative LOD-Bias

In this image you can see that the shimmering of the fence disappears completely, and the wires of the electric poles too.

@aufkrawall
Copy link

Yes, a clamp (e.g. when setting 0.0?) would be nice, as we don't know what bias a game uses. And it might also apply it only to select textures, so manually setting a positive bias to counter some negative bias of the game itself could blur some textures more than others.

Nvidia driver clamp btw. likely only works with GL.
What's unfortunate is that Nvidia's Vulkan texture filtering also is unnecessarily bad with negative LOD bias: https://forums.developer.nvidia.com/t/bad-texture-filtering-quality-with-negative-lod-bias-on-vulkan/195807

Ping @liam-middlebrook , as hopefully this can get addressed at some point. :(

@pchome
Copy link
Contributor

pchome commented Aug 14, 2022

d3d11-clamp-lod-bias-v2.patch.txt
This patch adds two boolean options: d3d11.clampLodBias and d3d11.useGlFilterModes
For second one I was just curious what the difference, do not use or report if this breaks thing.
I doubt such changes will be accepted upstream or improve things much for you.

@ViNi-Arco
Copy link
Author

ViNi-Arco commented Aug 18, 2022

This patch adds two boolean options: d3d11.clampLodBias and d3d11.useGlFilterModes

Hi man, thanks for taking the time to create this patch,
Sorry for the delay in answering, I was without internet these days.

I tested it on some games I have here, in:
DXVK v1.10.1-603-ga695644f
AMD RADV 22.1.6
Anti-aliasing, DOF, Motion blur disabled in all games (for more clarity and to be able to see any difference).

Dark Souls Remastered (Steam and Proton 7.0-4)
d3d11.clampLodBias FALSE:
Print-01
Print-02
d3d11.clampLodBias TRUE:
Print-01
Print-02

Here in Dark Souls I haven't observed any changes, in general it no has shimmering.

Little Nightmares (Steam and Proton 7.0-4)
d3d11.clampLodBias FALSE:
Print-01
d3d11.clampLodBias TRUE:
Print-01

In Little Nightmares I noticed a change in the texture of the wood, especially when moving.

Far Cry 4 (Ubisoft Connect and Wine)
d3d11.clampLodBias FALSE:
Print-01
d3d11.clampLodBias TRUE:
Print-01

In Far Cry 4, in some foliage I noticed differences, now in the game as a whole no perceptible changes.

GTA Vice City The Definitive Edition (Rockstar Launcher and Wine)
d3d11.clampLodBias FALSE:
Print-01
Print-02
d3d11.clampLodBias TRUE:
Print-01
Print-02

In GTAVC The Definitive Edition, here it is different, some texture get very blurry with Clamp Lod Bias and others stay normal, now in alpha texture like the grids/fences there is no difference.

Edit: Now I see why don't have changes in alpha textures, which is the most important thing to remove Negative Lod Bias, looking more closely your Patch code, you coded for mipmap textures only, and this is probably why there are no changes in grids/fences in GTAVC

@ViNi-Arco
Copy link
Author

I doubt such changes will be accepted upstream or improve things much for you.

All right, this will be a patch that I will keep and use when needed in a game

I've seen some people complain about shimmering in Resident Evil 2 Remake, Assassin's Creed Unity and Battlefield 4, but I don't have them to test.

@aufkrawall
Copy link

I don't think Battlefield 4 uses negative LOD bias, though its terrain mega texture is incompatible with forced AF.
But Battlefield 5 and afair also 1 have super ugly shimmering that might be caused by negative bias (or something else is terribly screwed up, but not related to DXVK).

@pchome
Copy link
Contributor

pchome commented Aug 18, 2022

Yes, ugly wires and fences everywhere. For better fences you may want to do opposite:
d3d11.samplerLodBias = -2
d3d11.samplerAnisotropy = 16
and force AA (e.g. fsaa via vkBasalt if no ingame AA)
But adds a bit more shimmering, but fences not look like random squares.

Also reminds me #1307 (comment)

@pchome
Copy link
Contributor

pchome commented Sep 7, 2022

Try NFAA.fx (Normal Filter Anti Aliasing), even with adjusted LOD bias it makes shimmering much less noticeable and distracting.
Can be found in https://github.com/BlueSkyDefender/AstrayFX

In addition it has HFR_AA = true option, which will ...

This allows most monitors to assist in AA if your FPS is 60 or above and Locked to your monitors refresh-rate.

@ViNi-Arco
Copy link
Author

ViNi-Arco commented Sep 8, 2022

Try NFAA.fx (Normal Filter Anti Aliasing), even with adjusted LOD bias it makes shimmering much less noticeable and distracting.
Can be found in https://github.com/BlueSkyDefender/AstrayFX

In addition it has HFR_AA = true option, which will ...

Hey pchome how is it going, I will try yes, thank you.
you came just when I need some quality anti-aliasing because I'm playing NFS Underground 2 and it eventually crashes for lack of memory, and I have to decrease his anti-aliasing FSAA, the MSAA of DXVK breaks the graphics of NFSU2, I have the game with large address aware and Wine built with large address too, but this is something of old games nowadays unfortunately.

I have been discovering ways to decrease the shimmering in textures, and this time I discovered some very good things, MagicTXD allows you to apply quality mipmap directly in some games, which helps a lot to "hide" the Negative LOD bias, just set Generate mipmaps with Max=11 old GTAVC before and after, and the DXVK-d3d9 own Anisotropic, it decreases the shimmering in textures that don't have any filter, as I observed here, apparently dxvk-d3d9 anisotropic applies to all textures which helps these "broken" games, what the mentioned PR tries to change..

Edit: But there is a catch, using MagicTXD's mipmap at these levels and higher increases the memory usage by 33%, which is bad for older games, so we need something like the Clamp negative lod bias, now what Nvidia does to get whole game lod blocked I want to know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants