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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3d9/d3d11] add samplerLodBias to d3d9 and clampNegativeLodBias for both d3d9 and d3d11 #3435

Merged
merged 3 commits into from
Jun 14, 2023

Conversation

EndlesslyFlowering
Copy link
Contributor

@EndlesslyFlowering EndlesslyFlowering commented May 20, 2023

d3d9.clampNegativeLodBias addresses #2779

a negative lod bias can help for some d3d9 games to look better
while clamping the negative load bias can also help some other games too 馃槃

Thanks to @Kaldaien for giving me the code for clamping in D3D9!

@ViNi-Arco
Copy link

Oh my god, I can't believe there is any progress happening on this issue! for years we have shimmering in old games on modern video cards, and the only solutions was to use old Windows with outdated drivers or use an old 2008~2009 video card with NegativeLodBias "clamp" for example 8800 gt, gtx 285... Thanks Lilium and Andon M. Coleman for taking the time to create a solution

@ViNi-Arco
Copy link

But unfortunately something is wrong, I tested it on GTA Vice City and it didn't solve his shimmering:

ClampLodBiasNotWork

as you can see where I marked in red, the game still applies a very high negative Lod

@lextra2
Copy link

lextra2 commented May 20, 2023

@ViNi-Arco what value did you use? I think positive values are less sharp, so you'd want to use that.

@Blisto91
Copy link
Contributor

Blisto91 commented May 20, 2023

Vice city is d3d8 馃
Or are you using d3d8to9

@EndlesslyFlowering
Copy link
Contributor Author

But unfortunately something is wrong, I tested it on GTA Vice City and it didn't solve his shimmering:

ClampLodBiasNotWork

as you can see where I marked in red, the game still applies a very high negative Lod

I used this anisotropic filtering and lod bias tester to verify that it is indeed working:
https://www.3dcenter.org/download/d3d-af-tester

While also trying a few games where it applied correctly too.
Not sure what the issue with Vice City is :(

@ViNi-Arco
Copy link

Vice city is d3d8 thinking
Or are you using d3d8to9

Sup Blisto, I always use D3D8to9 because of Skygfx and rwd3d9 and other mods..

what value did you use? I think positive values are less sharp, so you'd want to use that.

I do not understand what you want to know, you speak of lod bias?
I do not use anything, standard that the game apply Lod.

@ViNi-Arco
Copy link

I used this anisotropic filtering and lod bias tester to verify that it is indeed working:
https://www.3dcenter.org/download/d3d-af-tester

While also trying a few games where it applied correctly too.
Not sure what the issue with Vice City is :(

Hello dear, I will test in more games to see how lod behaves in them

@EndlesslyFlowering
Copy link
Contributor Author

I used this anisotropic filtering and lod bias tester to verify that it is indeed working:
https://www.3dcenter.org/download/d3d-af-tester

While also trying a few games where it applied correctly too.
Not sure what the issue with Vice City is :(

Hello dear, I will test in more games to see how lod behaves in them

I wrote a quick logger for the lod bias the game supplies and the one you overwrite with the conf options:
https://github.com/EndlesslyFlowering/dxvk/tree/lod-stuff-logger
d3d9.logLodBias = true

looks like this:

info:  old lod bias: -3 new: 0
info:  old lod bias: -6.5 new: 0
info:  old lod bias: -6 new: 0
info:  old lod bias: -5.5 new: 0
info:  old lod bias: -5 new: 0
info:  old lod bias: -4.5 new: 0
info:  old lod bias: -4 new: 0
info:  old lod bias: -3.5 new: 0
info:  old lod bias: -2.5 new: 0
info:  old lod bias: -2 new: 0
info:  old lod bias: -1.5 new: 0
info:  old lod bias: -1 new: 0
info:  old lod bias: -0.5 new: 0

@ViNi-Arco
Copy link

The GTA VC log, reports a single line:
info: old lod bias: 0 new: 0

It says the lod is already at 0
melting-face

@ViNi-Arco
Copy link

ViNi-Arco commented May 21, 2023

I tested it on the NFS Carbon, and it doesn't seem to be able to identify the lods of the games, look at the log:

   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0
   info:  old lod bias: 0 new: 0

Reports as 0 on all

Edit: I will test more d3d9 games, especially those from 2004 or older, to see if the log reports anything

@aufkrawall
Copy link

The clamp option doesn't work for me in Filter Tester, negative LOD still can be used:
https://www.3dcenter.org/dateien/dateien/3DCenterFilterTesterSetup%201.1.exe

It's D3D10 32 bit and you need a Wine version with Vulkan child window support.
d3d11.samplerLodBias = -2 works. I also tested d3d9.samplerLodBias = -1.5 in Mirror's Edge and that worked too.

Perhaps it would also be possible to offer more control for the clamp:
d3d11/9.clampLodBias = positive/negative/both
?

@pchome
Copy link
Contributor

pchome commented May 21, 2023

So, any real example where the clamp helps?

@aufkrawall
Copy link

So, any real example where the clamp helps?

Well, if the clamp doesn't work (i.e. if the Filter Tester case above applies in general), it can't be demonstrated.

@pchome
Copy link
Contributor

pchome commented May 21, 2023

@aufkrawall
There is difference in d3d11 part:

if (info.minFilter == VK_FILTER_LINEAR && info.magFilter == VK_FILTER_LINEAR)

@EndlesslyFlowering
Copy link
Contributor Author

@aufkrawall There is difference in d3d11 part:

if (info.minFilter == VK_FILTER_LINEAR && info.magFilter == VK_FILTER_LINEAR)

I am following the previous work for applying a lod bias by @doitsujin here

@EndlesslyFlowering
Copy link
Contributor Author

So, any real example where the clamp helps?

I guess not? 馃槄
people really wanted it in the mentioned issue so I added it for them :D
seems like the Nvidia's driver back then did something else too?

@EndlesslyFlowering
Copy link
Contributor Author

EndlesslyFlowering commented May 21, 2023

@ViNi-Arco
looking at this article here it seems Nvidia forcefully created mip maps for it seems every (?) texture when enabling "clamp negative lod bias".

iirc there is a option in D3D9 to automatically create mip maps for textures that don't have any.
I'll look into that :)

@ViNi-Arco
Copy link

looking at this article here it seems Nvidia forcefully created mip maps for it seems every (?) texture when enabling "clamp negative lod bias".

iirc there is a option in D3D9 to automatically create mip maps for textures that don't have any.
I'll look into that :)

Wow, so Nvidia's "Negative LOD Bias" option did a lot more under the hood. Thank you very much for looking into this

@EndlesslyFlowering
Copy link
Contributor Author

looking at this article here it seems Nvidia forcefully created mip maps for it seems every (?) texture when enabling "clamp negative lod bias".
iirc there is a option in D3D9 to automatically create mip maps for textures that don't have any.
I'll look into that :)

Wow, so Nvidia's "Negative LOD Bias" option did a lot more under the hood. Thank you very much for looking into this

Honestly I am not quite sure if it is automatically created mip map levels.
I just compared the findings of the article with your own findings of creating mip map levels yourself here.

@ViNi-Arco
Copy link

ViNi-Arco commented May 22, 2023

Honestly I am not quite sure if it is automatically created mip map levels.
I just compared the findings of the article with your own findings of creating mip map levels yourself here.

Ah yes, the Magic.TXD, but just applying mipmap even at maximum texture levels, which is what I'm using in GTA SA, doesn't totally solve the shimmering problem, the game applies a negative Lod yet:

SAmipmap1

SAmipmap2

Even with mipmap it has shimmering..

Edit: I tested it now and the d3d9.logLodBias = True with d3d9.clampNegativeLodBias = True reports a single line in GTA SA:

  info:  old lod bias: 0 new: 0

@EndlesslyFlowering
Copy link
Contributor Author

looking at this article here it seems Nvidia forcefully created mip maps for it seems every (?) texture when enabling "clamp negative lod bias".
iirc there is a option in D3D9 to automatically create mip maps for textures that don't have any.
I'll look into that :)

Wow, so Nvidia's "Negative LOD Bias" option did a lot more under the hood. Thank you very much for looking into this

ok some more guesses:
the older Nvidia driver may have forced another mip map filter type. D3D9 supports quite a bit of those:

typedef enum _D3DTEXTUREFILTERTYPE {
    D3DTEXF_NONE            = 0,
    D3DTEXF_POINT           = 1,
    D3DTEXF_LINEAR          = 2,
    D3DTEXF_ANISOTROPIC     = 3,
    D3DTEXF_FLATCUBIC       = 4,
    D3DTEXF_GAUSSIANCUBIC   = 5,
    D3DTEXF_PYRAMIDALQUAD   = 6,
    D3DTEXF_GAUSSIANQUAD    = 7,
#ifndef D3D_DISABLE_9EX
    D3DTEXF_CONVOLUTIONMONO = 8,
#endif
    D3DTEXF_FORCE_DWORD     = 0x7fffffff
} D3DTEXTUREFILTERTYPE;

source

while Vulkan only supports linear and point (= nearest in Vulkan) and dxvk does too.
while cubic does also exist. it doesn't seem like Nvidia or AMD are supporting it? Maybe on linux one of them does support it (currently too lazy to check).

@EndlesslyFlowering
Copy link
Contributor Author

EndlesslyFlowering commented May 22, 2023

Honestly I am not quite sure if it is automatically created mip map levels.
I just compared the findings of the article with your own findings of creating mip map levels yourself here.

Ah yes, the Magic.TXD, but just applying mipmap even at maximum texture levels, which is what I'm using in GTA SA, doesn't totally solve the shimmering problem, the game applies a negative Lod yet:

SAmipmap1

SAmipmap2

Even with mipmap it has shimmering..

Edit: The d3d9.logLodBias = True with d3d9.clampNegativeLodBias = True reports a single line in GTA SA:

  info:  old lod bias: 0 new: 0

the shimmering comes from dxvk/Vulkan only supporting nearest or linear filtering and not from the lod bias.
the best you can do is force linear filtering on everything. maybe AMD will support cubic filtering in the future.
or I am not even sure if cubic filtering will solve that, sorry :/

edit:
this should hopefully clear this up as not being a lod bias issue!

@ViNi-Arco
Copy link

ViNi-Arco commented May 22, 2023

the shimmering comes from dxvk/Vulkan only supporting nearest or linear filtering and not from the lod bias.
the best you can do is force linear filtering on everything. maybe AMD will support cubic filtering in the future.
or I am not even sure if cubic filtering will solve that, sorry :/

edit:
this should hopefully clear this up as not being a lod bias issue!

The case here with games that support mipmap is the filtering problem not just the lod itself, there are ways to force these filters on games on Linux, I will test some to see how they affect the appearance here..

ok some more guesses:
the older Nvidia driver may have forced another mip map filter type. D3D9 supports quite a bit of those:

typedef enum _D3DTEXTUREFILTERTYPE {
    D3DTEXF_NONE            = 0,
    D3DTEXF_POINT           = 1,
    D3DTEXF_LINEAR          = 2,
    D3DTEXF_ANISOTROPIC     = 3,
    D3DTEXF_FLATCUBIC       = 4,
    D3DTEXF_GAUSSIANCUBIC   = 5,
    D3DTEXF_PYRAMIDALQUAD   = 6,
    D3DTEXF_GAUSSIANQUAD    = 7,
#ifndef D3D_DISABLE_9EX
    D3DTEXF_CONVOLUTIONMONO = 8,
#endif
    D3DTEXF_FORCE_DWORD     = 0x7fffffff
} D3DTEXTUREFILTERTYPE;

What about games that don't have a mipmap or have a way to inject mipmap as is possible with Magic TXD, these filters would be the only option?

@EndlesslyFlowering
Copy link
Contributor Author

the shimmering comes from dxvk/Vulkan only supporting nearest or linear filtering and not from the lod bias.
the best you can do is force linear filtering on everything. maybe AMD will support cubic filtering in the future.
or I am not even sure if cubic filtering will solve that, sorry :/
edit:
this should hopefully clear this up as not being a lod bias issue!

The case here with games that support mipmap is the filtering problem not just the lod itself, there are ways to force these filters on games on Linux, I will test some to see how they affect the appearance here..

ok some more guesses:
the older Nvidia driver may have forced another mip map filter type. D3D9 supports quite a bit of those:

typedef enum _D3DTEXTUREFILTERTYPE {
    D3DTEXF_NONE            = 0,
    D3DTEXF_POINT           = 1,
    D3DTEXF_LINEAR          = 2,
    D3DTEXF_ANISOTROPIC     = 3,
    D3DTEXF_FLATCUBIC       = 4,
    D3DTEXF_GAUSSIANCUBIC   = 5,
    D3DTEXF_PYRAMIDALQUAD   = 6,
    D3DTEXF_GAUSSIANQUAD    = 7,
#ifndef D3D_DISABLE_9EX
    D3DTEXF_CONVOLUTIONMONO = 8,
#endif
    D3DTEXF_FORCE_DWORD     = 0x7fffffff
} D3DTEXTUREFILTERTYPE;

What about games that don't have a mipmap or have a way to inject mipmap as is possible with Magic TXD, these filters would be the only option?

only 0-3 are supported in Vulkan and therefore dxvk. the others all get mapped to linear because there is no equivalent.
most games let d3d9 create the mip maps so dxvk is stuck with linear at best.
Nothing can be done from the dxvk side here!
the only way to get the old behaviour back is move to a GTX285 and use Windows it seems.

Please stop posting about this here since it has nothing to do with this PR anymore. Thank you!
we can discuss this further on the Linux Gaming Dev discord if you want.

@EndlesslyFlowering
Copy link
Contributor Author

EndlesslyFlowering commented May 22, 2023

The clamp option doesn't work for me in Filter Tester, negative LOD still can be used: https://www.3dcenter.org/dateien/dateien/3DCenterFilterTesterSetup%201.1.exe

It's D3D10 32 bit and you need a Wine version with Vulkan child window support. d3d11.samplerLodBias = -2 works. I also tested d3d9.samplerLodBias = -1.5 in Mirror's Edge and that worked too.

Perhaps it would also be possible to offer more control for the clamp: d3d11/9.clampLodBias = positive/negative/both ?

I am not sure if clamping a positive lod bias makes sense since you would get shimmering on those textures then.

the lod bias option seems to make the most sense with older games at higher resolutions.

I am not sure if clamping the negative lod bias was ever something that brought a positive outcome unless for that NV driver hack.

I will convert this to a draft and get some more opinions to see what is the best to do here :)

@EndlesslyFlowering EndlesslyFlowering marked this pull request as draft May 22, 2023 03:22
@aufkrawall
Copy link

Perhaps only c0ed265 can be merged in the meantime? It makes sense to set a negative LOD bias with d3d9.forceSampleRateShading , as SSAA avoids the shimmering.

@pchome
Copy link
Contributor

pchome commented May 22, 2023

I noticed there is Fetch4 hack which relay on lod bias value, worth to check if it will not break with d3d9.samplerLodBias
https://github.com/doitsujin/dxvk/search?q=D3DSAMP_MIPMAPLODBIAS

@EndlesslyFlowering
Copy link
Contributor Author

EndlesslyFlowering commented May 24, 2023

I noticed there is Fetch4 hack which relay on lod bias value, worth to check if it will not break with d3d9.samplerLodBias https://github.com/doitsujin/dxvk/search?q=D3DSAMP_MIPMAPLODBIAS

as I understand the code this should not cause any issues with this PR.

the only thing I could maybe do is only apply the lod bias on linear filtered textures like it's done in d3d11 as fetch4 checks if the texture magFilter is point

edit:
also after thinking about the PR some more:
I am going to leave it as is. If there is a d3d9/d3d11 game with negative LOD bias you can now clamp it.
and the lod bias obviously is a nice addition.

@EndlesslyFlowering EndlesslyFlowering marked this pull request as ready for review May 25, 2023 23:58
@EndlesslyFlowering
Copy link
Contributor Author

nothing really changed with 51cb45c except to match the styling of everything else

@EndlesslyFlowering
Copy link
Contributor Author

all the merge issues are resolved :)

@Joshua-Ashton Joshua-Ashton merged commit bd575a4 into doitsujin:master Jun 14, 2023
3 checks passed
@ViNi-Arco
Copy link

Thank you very much @EndlesslyFlowering @Kaldaien I wish you all the best

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

Successfully merging this pull request may close these issues.

None yet

7 participants