Skip to content

Commit

Permalink
[d3d11] Add option to control sampler LOD bias
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Aug 1, 2022
1 parent 9671055 commit 727fd7a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions dxvk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@
# d3d9.samplerAnisotropy = -1


# Changes the mipmap LOD bias for all samplers. The given number will be
# added to the LOD bias provided by the application, rather than replacing
# it entirely. Positive values will reduce texture detail, while negative
# values may increase sharpness at the cost of shimmer.
#
# Supported values: Any number between -2.0 and 1.0

# d3d11.samplerLodBias = 0.0


# Declares vertex positions as invariant in order to solve
# potential Z-fighting issues at a small performance cost.
#
Expand Down
6 changes: 5 additions & 1 deletion src/d3d11/d3d11_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <unordered_map>
#include "../util/util_math.h"

#include "d3d11_options.h"

Expand All @@ -13,6 +13,7 @@ namespace dxvk {
this->ignoreGraphicsBarriers = config.getOption<bool>("d3d11.ignoreGraphicsBarriers", false);
this->maxTessFactor = config.getOption<int32_t>("d3d11.maxTessFactor", 0);
this->samplerAnisotropy = config.getOption<int32_t>("d3d11.samplerAnisotropy", -1);
this->samplerLodBias = config.getOption<float>("d3d11.samplerLodBias", 0.0f);
this->invariantPosition = config.getOption<bool>("d3d11.invariantPosition", true);
this->floatControls = config.getOption<bool>("d3d11.floatControls", true);
this->disableMsaa = config.getOption<bool>("d3d11.disableMsaa", false);
Expand All @@ -23,6 +24,9 @@ namespace dxvk {
this->syncInterval = config.getOption<int32_t>("dxgi.syncInterval", -1);
this->tearFree = config.getOption<Tristate>("dxgi.tearFree", Tristate::Auto);

// Clamp LOD bias so that people don't abuse this in unintended ways
this->samplerLodBias = dxvk::fclamp(this->samplerLodBias, -2.0f, 1.0f);

int32_t maxImplicitDiscardSize = config.getOption<int32_t>("d3d11.maxImplicitDiscardSize", 256);
this->maxImplicitDiscardSize = maxImplicitDiscardSize >= 0
? VkDeviceSize(maxImplicitDiscardSize) << 10
Expand Down
7 changes: 6 additions & 1 deletion src/d3d11/d3d11_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ namespace dxvk {
/// Enforces anisotropic filtering with the
/// given anisotropy value for all samplers.
int32_t samplerAnisotropy;


/// Mipmap LOD bias
///
/// Enforces the given LOD bias for all samplers.
float samplerLodBias;

/// Declare vertex positions in shaders as invariant
bool invariantPosition;

Expand Down
6 changes: 5 additions & 1 deletion src/d3d11/d3d11_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ namespace dxvk {
if (desc.MaxAnisotropy < 1) info.maxAnisotropy = 1.0f;
if (desc.MaxAnisotropy > 16) info.maxAnisotropy = 16.0f;

// Enforce LOD bias specified in the device options
if (info.minFilter == VK_FILTER_LINEAR && info.magFilter == VK_FILTER_LINEAR)
info.mipmapLodBias += device->GetOptions()->samplerLodBias;

// Enforce anisotropy specified in the device options
int32_t samplerAnisotropyOption = device->GetOptions()->samplerAnisotropy;

if (samplerAnisotropyOption >= 0 && info.minFilter == VK_FILTER_LINEAR) {
info.useAnisotropy = samplerAnisotropyOption > 0;
info.maxAnisotropy = float(samplerAnisotropyOption);
}

m_sampler = device->GetDXVKDevice()->createSampler(info);
}

Expand Down

2 comments on commit 727fd7a

@pchome
Copy link
Contributor

@pchome pchome commented on 727fd7a Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) good

@NEOAethyr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dx9/11 specific:
./src/d3d9/d3d9_sampler.h
./src/d3d11/d3d11_sampler.cpp

dx9:
key.MipmapLodBias = -1.2;

For ex..., then comment out up to: if (key.MipFilter == D3DTEXF_NONE) {
You can set it as an option but whatever.
(I used to at one point)
I'd prefer env var tbh.

This controls dx9 and (dx10?) / 11
And works as an env var, a little easier to work with per game/app imo.
Maybe the prefered method ?
But I'm unsure if the code is clean, with those if statements.
I just wanted to catch all use cases.
It should be -15 -> +15.

Doa6 and the forest are interesting tests.
The latter having a hidden bg image on the load screen.
And doa, it would be interesting if it could be tweaked per object or use case.
Like if lod ='s this range, or this range.. do this or that.
But I could never get that to work right, or do much.
It's not like I had a debugger open or anything though.
Other then guesswork lol.

Sorry it's not in legit diff format.

./src/dxvk/dxvk_sampler.cpp

.. -->
.. borderColorInfo.customBorderColor = info.borderColor;
..
std::string dxvk_lodbias = env::getEnvVar("DXVK_dxvk_lodbias");
std::string dxvk_minlod = env::getEnvVar("DXVK_dxvk_minlod");
std::string dxvk_maxlod = env::getEnvVar("DXVK_dxvk_maxlod");
..
.. VkSamplerCreateInfo samplerInfo = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
..
// samplerInfo.minLod = info.mipmapLodMin;
// samplerInfo.maxLod = info.mipmapLodMax;
..
.. samplerInfo.unnormalizedCoordinates = info.usePixelCoord;
..
if (dxvk_lodbias == "")
{
samplerInfo.mipLodBias = info.mipmapLodBias;
}
else
{
float num_dxvk_lodbias = std::stof(dxvk_lodbias);
samplerInfo.mipLodBias = num_dxvk_lodbias;
}
if (dxvk_minlod == "")
{
samplerInfo.minLod = info.mipmapLodMin;
}
else
{
float num_dxvk_minlod = std::stof(dxvk_minlod);
samplerInfo.minLod = num_dxvk_minlod;
}
if (dxvk_maxlod == "")
{
samplerInfo.maxLod = info.mipmapLodMax;
}
else
{
float num_dxvk_maxlod = std::stof(dxvk_maxlod);
samplerInfo.maxLod = num_dxvk_maxlod;
}
..
.. if (!device->features().core.features.samplerAnisotropy)

Please sign in to comment.