Common: Move BitSet helper functions into the Common namespace

This commit is contained in:
Lioncash 2018-04-22 23:45:02 -04:00
parent 2ce0f42c14
commit d68f437e67
2 changed files with 9 additions and 9 deletions

View File

@ -7,12 +7,12 @@
#include <type_traits> #include <type_traits>
#include "CommonTypes.h" #include "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,8 +85,6 @@ inline int LeastSignificantSetBit(u64 val)
} }
#endif #endif
namespace Common
{
// 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:

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);
} }