Skip to content

Commit

Permalink
[d3d9] Round MipmapLodBias to .5 to avoid sampler leakage
Browse files Browse the repository at this point in the history
Fixes sampler leakage in Borderlands 2
Not the best solution but it's the best we have right now
  • Loading branch information
misyltoad committed Jul 1, 2019
1 parent e14be20 commit a0bfc93
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/d3d9/d3d9_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ namespace dxvk {
// Games also pass NAN/INF here, this accounts for that.
if (unlikely(std::isnan(key.MipmapLodBias)))
key.MipmapLodBias = 0.0f;

// Clamp between -15.0f and 15.0f, matching mip limits of d3d9.
key.MipmapLodBias = std::clamp(key.MipmapLodBias, -15.0f, 15.0f);

// Round to the nearest .5
// Fixes sampler leaks in UE3 games w/ mip streaming
// eg. Borderlands 2
key.MipmapLodBias = std::round(key.MipmapLodBias * 2.0f) / 2.0f;
}

// This is not implemented in the backend
Expand Down

3 comments on commit a0bfc93

@rkanati
Copy link

Choose a reason for hiding this comment

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

Note to maintainer: this might fix #170

@K0bin
Copy link
Contributor

@K0bin K0bin commented on a0bfc93 Jul 31, 2019

Choose a reason for hiding this comment

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

Unlikely. Yes samplers take up some memory and it's not great to have hundreds of them but 32 bit games running out of address space is an old problem with DXVK/D9VK.

@rkanati
Copy link

Choose a reason for hiding this comment

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

@K0bin Played around a bit, and you're right. Pity.

Please sign in to comment.