Commit 7ce4a151 by Jamie Madill Committed by Commit Bot

Add support for uint8_t and uint16_t bitsets.

These pack very well in some structs. Support is required so the templates work as expected. Also packs the Shader map into 8 bits. This includes a workaround for an unusual warning generated by MSVC. Bug: angleproject:2462 Change-Id: I804d1b9370b3951343718385210dec7d37700d73 Reviewed-on: https://chromium-review.googlesource.com/1091135 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent aaca96ee
......@@ -129,8 +129,8 @@ class PackedEnumMap
// PackedEnumBitSetE> is like an std::bitset<E::EnumCount> but is indexed with enum values. It
// implements the std::bitset interface except with enum values instead of indices.
template <typename E>
using PackedEnumBitSet = BitSetT<EnumSize<E>(), uint32_t, E>;
template <typename E, typename DataT = uint32_t>
using PackedEnumBitSet = BitSetT<EnumSize<E>(), DataT, E>;
} // namespace angle
......@@ -179,7 +179,8 @@ constexpr size_t kGraphicsShaderCount = static_cast<size_t>(ShaderType::EnumCoun
constexpr std::array<ShaderType, kGraphicsShaderCount> kAllGraphicsShaderTypes = {
ShaderType::Vertex, ShaderType::Geometry, ShaderType::Fragment};
using ShaderBitSet = angle::PackedEnumBitSet<ShaderType>;
using ShaderBitSet = angle::PackedEnumBitSet<ShaderType, uint8_t>;
static_assert(sizeof(ShaderBitSet) == sizeof(uint8_t), "Unexpected size");
template <typename T>
using ShaderMap = angle::PackedEnumMap<ShaderType, T>;
......
......@@ -956,6 +956,16 @@ inline int BitCount(uint64_t bits)
#endif // defined(ANGLE_IS_64_BIT_CPU)
#endif // defined(ANGLE_PLATFORM_POSIX)
inline int BitCount(uint8_t bits)
{
return BitCount(static_cast<uint32_t>(bits));
}
inline int BitCount(uint16_t bits)
{
return BitCount(static_cast<uint32_t>(bits));
}
#if defined(ANGLE_PLATFORM_WINDOWS)
// Return the index of the least significant bit set. Indexing is such that bit 0 is the least
// significant bit. Implemented for different bit widths on different platforms.
......@@ -996,6 +1006,16 @@ inline unsigned long ScanForward(uint64_t bits)
#endif // defined(ANGLE_IS_64_BIT_CPU)
#endif // defined(ANGLE_PLATFORM_POSIX)
inline unsigned long ScanForward(uint8_t bits)
{
return ScanForward(static_cast<uint32_t>(bits));
}
inline unsigned long ScanForward(uint16_t bits)
{
return ScanForward(static_cast<uint32_t>(bits));
}
// Return the index of the most significant bit set. Indexing is such that bit 0 is the least
// significant bit.
inline unsigned long ScanReverse(unsigned long bits)
......
......@@ -431,7 +431,7 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
static_assert(static_cast<unsigned long>(ShaderType::EnumCount) <= sizeof(unsigned long) * 8,
"Too many shader types");
state->mLinkedShaderStages = stream.readInt<gl::ShaderBitSet>();
state->mLinkedShaderStages = ShaderBitSet(stream.readInt<uint8_t>());
state->updateTransformFeedbackStrides();
......
......@@ -43,7 +43,7 @@ void ActiveVariable::unionReferencesWith(const ActiveVariable &other)
ShaderType ActiveVariable::getFirstShaderTypeWhereActive() const
{
return static_cast<ShaderType>(gl::ScanForward(mActiveUseBits.bits()));
return static_cast<ShaderType>(ScanForward(mActiveUseBits.bits()));
}
GLuint ActiveVariable::activeShaderCount() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment