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

d3d11: samplerstate hashing fix #2500

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions src/renderer_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2978,17 +2978,32 @@ namespace bgfx { namespace d3d11

// Force both min+max anisotropic, can't be set individually.
_flags |= 0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) )
? BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC
: 0
;
? BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC
: 0
;

const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
const uint8_t minFilter = s_textureFilter[0][(_flags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT];
const uint8_t magFilter = s_textureFilter[1][(_flags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT];
const uint8_t mipFilter = s_textureFilter[2][(_flags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT];
const uint8_t filter = 0 == cmpFunc ? 0 : D3D11_COMPARISON_FILTERING_BIT;
const D3D11_FILTER d3dFilter = (D3D11_FILTER)(filter|minFilter|magFilter|mipFilter);
const D3D11_TEXTURE_ADDRESS_MODE addrU = s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT];
const D3D11_TEXTURE_ADDRESS_MODE addrV = s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT];
const D3D11_TEXTURE_ADDRESS_MODE addrW = s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT];
const D3D11_COMPARISON_FUNC d3dCmpFunc = (0 == cmpFunc ? D3D11_COMPARISON_NEVER : s_cmpFunc[cmpFunc]);

uint32_t hash;
ID3D11SamplerState* sampler;
if (!needBorderColor(_flags) )
{
bx::HashMurmur2A murmur;
murmur.begin();
murmur.add(_flags);
murmur.add(d3dFilter);
murmur.add(addrU);
murmur.add(addrV);
murmur.add(addrW);
murmur.add(d3dCmpFunc);
murmur.add(-1);
hash = murmur.end();
_rgba = s_zero.m_zerof;
Expand All @@ -2999,8 +3014,12 @@ namespace bgfx { namespace d3d11
{
bx::HashMurmur2A murmur;
murmur.begin();
murmur.add(_flags);
murmur.add(d3dFilter);
murmur.add(addrU);
murmur.add(addrV);
murmur.add(addrW);
murmur.add(index);
murmur.add(d3dCmpFunc);
hash = murmur.end();
_rgba = NULL == _rgba ? s_zero.m_zerof : _rgba;

Expand All @@ -3020,20 +3039,14 @@ namespace bgfx { namespace d3d11

if (NULL == sampler)
{
const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
const uint8_t minFilter = s_textureFilter[0][(_flags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT];
const uint8_t magFilter = s_textureFilter[1][(_flags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT];
const uint8_t mipFilter = s_textureFilter[2][(_flags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT];
const uint8_t filter = 0 == cmpFunc ? 0 : D3D11_COMPARISON_FILTERING_BIT;

D3D11_SAMPLER_DESC sd;
sd.Filter = (D3D11_FILTER)(filter|minFilter|magFilter|mipFilter);
sd.AddressU = s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT];
sd.AddressV = s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT];
sd.AddressW = s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT];
sd.Filter = d3dFilter;
sd.AddressU = addrU;
sd.AddressV = addrV;
sd.AddressW = addrW;
sd.MipLODBias = float(BGFX_CONFIG_MIP_LOD_BIAS);
sd.MaxAnisotropy = m_maxAnisotropy;
sd.ComparisonFunc = 0 == cmpFunc ? D3D11_COMPARISON_NEVER : s_cmpFunc[cmpFunc];
sd.ComparisonFunc = d3dCmpFunc;
sd.BorderColor[0] = _rgba[0];
sd.BorderColor[1] = _rgba[1];
sd.BorderColor[2] = _rgba[2];
Expand Down