From 918b111eb59d6c9cb4f278ee5014fe85da5e523b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 5 Mar 2015 21:11:44 -0800 Subject: [PATCH] Cleanup. Added state cache. --- src/bgfx.cpp | 14 +++++++++----- src/renderer_d3d.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/renderer_vk.cpp | 1 + 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 709622ae..7ac7060e 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -972,16 +972,16 @@ namespace bgfx m_viewRemap[ii] = ii; } - memset(m_fb, 0xff, sizeof(m_fb) ); - memset(m_clear, 0, sizeof(m_clear) ); - memset(m_rect, 0, sizeof(m_rect) ); + memset(m_fb, 0xff, sizeof(m_fb) ); + memset(m_clear, 0, sizeof(m_clear) ); + memset(m_rect, 0, sizeof(m_rect) ); memset(m_scissor, 0, sizeof(m_scissor) ); - memset(m_seq, 0, sizeof(m_seq) ); + memset(m_seq, 0, sizeof(m_seq) ); memset(m_seqMask, 0, sizeof(m_seqMask) ); for (uint32_t ii = 0; ii < BX_COUNTOF(m_rect); ++ii) { - m_rect[ii].m_width = 1; + m_rect[ii].m_width = 1; m_rect[ii].m_height = 1; } @@ -1450,6 +1450,10 @@ again: { _type = RendererType::OpenGLES; } + else if (s_rendererCreator[RendererType::Vulkan].supported) + { + _type = RendererType::Vulkan; + } } else if (BX_ENABLED(0 || BX_PLATFORM_ANDROID diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index 1df0e3a7..eed41026 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -138,6 +138,50 @@ namespace bgfx HashMap m_hashMap; }; + class StateCache + { + public: + void add(uint64_t _id, uint16_t _item) + { + invalidate(_id); + m_hashMap.insert(stl::make_pair(_id, _item)); + } + + uint16_t find(uint64_t _id) + { + HashMap::iterator it = m_hashMap.find(_id); + if (it != m_hashMap.end()) + { + return it->second; + } + + return UINT16_MAX; + } + + void invalidate(uint64_t _id) + { + HashMap::iterator it = m_hashMap.find(_id); + if (it != m_hashMap.end()) + { + m_hashMap.erase(it); + } + } + + void invalidate() + { + m_hashMap.clear(); + } + + uint32_t getCount() const + { + return uint32_t(m_hashMap.size()); + } + + private: + typedef stl::unordered_map HashMap; + HashMap m_hashMap; + }; + } // namespace bgfx #endif // BGFX_RENDERER_D3D_H_HEADER_GUARD diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index b9977c53..809a0c8e 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -14,6 +14,7 @@ namespace bgfx { return NULL; } + void rendererDestroyVK() { }