From 0679776a4ba2b3ad342491bd9812e0ebe4ef3701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 1 Dec 2015 22:45:22 -0800 Subject: [PATCH] D3D11: Fixed invalid blend state cache hash value. --- src/renderer_d3d.h | 4 ++++ src/renderer_d3d11.cpp | 42 +++++++++++++++++------------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index 56cb88c63..795b02ef8 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -104,6 +104,10 @@ namespace bgfx { invalidate(_key); m_hashMap.insert(stl::make_pair(_key, _value) ); + BX_CHECK(1 == getRefCount(_value), "Interface ref count %d, hash %" PRIx64 "." + , getRefCount(_value) + , _key + ); } Ty* find(uint64_t _key) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 01ce3fa15..70c95912a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2485,31 +2485,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { _state &= BGFX_D3D11_BLEND_STATE_MASK; - bx::HashMurmur2A murmur; - murmur.begin(); - murmur.add(_state); - - const uint64_t f0 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR); - const uint64_t f1 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_INV_FACTOR, BGFX_STATE_BLEND_INV_FACTOR); - bool hasFactor = f0 == (_state & f0) - || f1 == (_state & f1) - ; - - float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - if (hasFactor) - { - blendFactor[0] = ( (_rgba>>24) )/255.0f; - blendFactor[1] = ( (_rgba>>16)&0xff)/255.0f; - blendFactor[2] = ( (_rgba>> 8)&0xff)/255.0f; - blendFactor[3] = ( (_rgba )&0xff)/255.0f; - } - else - { - murmur.add(_rgba); - } - - uint32_t hash = murmur.end(); - + const uint64_t hash = _state; ID3D11BlendState* bs = m_blendStateCache.find(hash); if (NULL == bs) { @@ -2587,6 +2563,22 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_blendStateCache.add(hash, bs); } + const uint64_t f0 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR); + const uint64_t f1 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_INV_FACTOR, BGFX_STATE_BLEND_INV_FACTOR); + bool hasFactor = false + || f0 == (_state & f0) + || f1 == (_state & f1) + ; + + float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + if (hasFactor) + { + blendFactor[0] = ( (_rgba>>24) )/255.0f; + blendFactor[1] = ( (_rgba>>16)&0xff)/255.0f; + blendFactor[2] = ( (_rgba>> 8)&0xff)/255.0f; + blendFactor[3] = ( (_rgba )&0xff)/255.0f; + } + m_deviceCtx->OMSetBlendState(bs, blendFactor, 0xffffffff); }