Merge pull request #6691 from lioncash/bs

Common: Move BitSet into the Common namespace
This commit is contained in:
Markus Wick 2018-04-23 08:50:40 +02:00 committed by GitHub
commit 30ab21fdd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 16 deletions

View File

@ -5,14 +5,14 @@
#include <cstddef> #include <cstddef>
#include <initializer_list> #include <initializer_list>
#include <type_traits> #include <type_traits>
#include "CommonTypes.h" #include "Common/CommonTypes.h"
// Helper functions:
#ifdef _WIN32 #ifdef _WIN32
#include <intrin.h> #include <intrin.h>
namespace Common
{
template <typename T> template <typename T>
constexpr int CountSetBits(T v) constexpr int CountSetBits(T v)
{ {
@ -49,6 +49,8 @@ inline int LeastSignificantSetBit(u64 val)
return (int)index; return (int)index;
} }
#else #else
namespace Common
{
constexpr int CountSetBits(u8 val) constexpr int CountSetBits(u8 val)
{ {
return __builtin_popcount(val); return __builtin_popcount(val);
@ -83,9 +85,6 @@ inline int LeastSignificantSetBit(u64 val)
} }
#endif #endif
// namespace avoids conflict with OS X Carbon; don't use BitSet<T> directly
namespace BS
{
// Similar to std::bitset, this is a class which encapsulates a bitset, i.e. // Similar to std::bitset, this is a class which encapsulates a bitset, i.e.
// using the set bits of an integer to represent a set of integers. Like that // using the set bits of an integer to represent a set of integers. Like that
// class, it acts like an array of bools: // class, it acts like an array of bools:
@ -207,9 +206,9 @@ public:
constexpr Iterator end() const { return Iterator(m_val, -1); } constexpr Iterator end() const { return Iterator(m_val, -1); }
IntTy m_val; IntTy m_val;
}; };
} } // namespace Common
typedef BS::BitSet<u8> BitSet8; using BitSet8 = Common::BitSet<u8>;
typedef BS::BitSet<u16> BitSet16; using BitSet16 = Common::BitSet<u16>;
typedef BS::BitSet<u32> BitSet32; using BitSet32 = Common::BitSet<u32>;
typedef BS::BitSet<u64> BitSet64; using BitSet64 = Common::BitSet<u64>;

View File

@ -28,8 +28,8 @@ void StateManager::Apply()
if (!m_dirtyFlags) if (!m_dirtyFlags)
return; return;
int textureMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Texture0); const int textureMaskShift = Common::LeastSignificantSetBit((u32)DirtyFlag_Texture0);
int samplerMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Sampler0); const int samplerMaskShift = Common::LeastSignificantSetBit((u32)DirtyFlag_Sampler0);
u32 dirtyTextures = u32 dirtyTextures =
(m_dirtyFlags & (m_dirtyFlags &
@ -105,7 +105,7 @@ void StateManager::Apply()
while (dirtyTextures) while (dirtyTextures)
{ {
int index = LeastSignificantSetBit(dirtyTextures); const int index = Common::LeastSignificantSetBit(dirtyTextures);
if (m_current.textures[index] != m_pending.textures[index]) if (m_current.textures[index] != m_pending.textures[index])
{ {
D3D::context->PSSetShaderResources(index, 1, &m_pending.textures[index]); D3D::context->PSSetShaderResources(index, 1, &m_pending.textures[index]);
@ -117,7 +117,7 @@ void StateManager::Apply()
while (dirtySamplers) while (dirtySamplers)
{ {
int index = LeastSignificantSetBit(dirtySamplers); const int index = Common::LeastSignificantSetBit(dirtySamplers);
if (m_current.samplers[index] != m_pending.samplers[index]) if (m_current.samplers[index] != m_pending.samplers[index])
{ {
D3D::context->PSSetSamplers(index, 1, &m_pending.samplers[index]); D3D::context->PSSetSamplers(index, 1, &m_pending.samplers[index]);
@ -187,7 +187,7 @@ void StateManager::SetTextureByMask(u32 textureSlotMask, ID3D11ShaderResourceVie
{ {
while (textureSlotMask) while (textureSlotMask)
{ {
int index = LeastSignificantSetBit(textureSlotMask); const int index = Common::LeastSignificantSetBit(textureSlotMask);
SetTexture(index, srv); SetTexture(index, srv);
textureSlotMask &= ~(1 << index); textureSlotMask &= ~(1 << index);
} }