From 5d134b877a87c3b5e7f06300ee6724d0f53287cf Mon Sep 17 00:00:00 2001 From: Lilium <19245343+EndlesslyFlowering@users.noreply.github.com> Date: Sat, 20 May 2023 13:47:10 +0200 Subject: [PATCH] [d3d9] implement 'samplerLodBias' as a conf option --- dxvk.conf | 2 +- src/d3d9/d3d9_device.cpp | 2 +- src/d3d9/d3d9_options.cpp | 6 ++++++ src/d3d9/d3d9_options.h | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dxvk.conf b/dxvk.conf index b46e4b8b..bde5a7e4 100644 --- a/dxvk.conf +++ b/dxvk.conf @@ -189,7 +189,7 @@ # Supported values: Any number between -2.0 and 1.0 # d3d11.samplerLodBias = 0.0 - +# d3d9.samplerLodBias = 0.0 # Declares vertex positions as invariant in order to solve # potential Z-fighting issues at a small performance cost. diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 7edb25fd..1dd5bbd7 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -6243,7 +6243,7 @@ namespace dxvk { info.mipmapMode = mipFilter.MipFilter; info.maxAnisotropy = float(cKey.MaxAnisotropy); info.useAnisotropy = cKey.MaxAnisotropy > 1; - info.mipmapLodBias = cKey.MipmapLodBias; + info.mipmapLodBias = cKey.MipmapLodBias + m_d3d9Options.samplerLodBias; info.mipmapLodMin = mipFilter.MipsEnabled ? float(cKey.MaxMipLevel) : 0; info.mipmapLodMax = mipFilter.MipsEnabled ? FLT_MAX : 0; info.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; diff --git a/src/d3d9/d3d9_options.cpp b/src/d3d9/d3d9_options.cpp index 4518094f..61a817b8 100644 --- a/src/d3d9/d3d9_options.cpp +++ b/src/d3d9/d3d9_options.cpp @@ -1,3 +1,5 @@ +#include "../util/util_math.h" + #include "d3d9_options.h" #include "d3d9_caps.h" @@ -72,6 +74,10 @@ namespace dxvk { this->seamlessCubes = config.getOption ("d3d9.seamlessCubes", false); this->textureMemory = config.getOption ("d3d9.textureMemory", 100) << 20; this->deviceLossOnFocusLoss = config.getOption ("d3d9.deviceLossOnFocusLoss", false); + this->samplerLodBias = config.getOption ("d3d9.samplerLodBias", 0.0f); + + // Clamp LOD bias so that people don't abuse this in unintended ways + this->samplerLodBias = dxvk::fclamp(this->samplerLodBias, -2.0f, 1.0f); std::string floatEmulation = Config::toLower(config.getOption("d3d9.floatEmulation", "auto")); if (floatEmulation == "strict") { diff --git a/src/d3d9/d3d9_options.h b/src/d3d9/d3d9_options.h index 89e46b81..3984d0b1 100644 --- a/src/d3d9/d3d9_options.h +++ b/src/d3d9/d3d9_options.h @@ -136,6 +136,11 @@ namespace dxvk { /// Don't use non seamless cube maps bool seamlessCubes; + /// Mipmap LOD bias + /// + /// Enforces the given LOD bias for all samplers. + float samplerLodBias; + /// How much virtual memory will be used for textures (in MB). int32_t textureMemory;