Hash :
0cc11c68
Author :
Date :
2018-10-12T18:07:18
StateManagerGL: Remove setGenericShaderState. We can mutate the BitSetIterator as it clears dirty bits. This removes the risk of doing a double state update. Improves the proformance of the GL back-end state update. Also do an early-out before calling syncDrawArraysState. Bug: angleproject:2763 Change-Id: Idd25bdd67a6aceff05529a533260b661b07c2928 Reviewed-on: https://chromium-review.googlesource.com/c/1262740 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// bitset_utils_unittest:
// Tests bitset helpers and custom classes.
//
#include <gtest/gtest.h>
#include "common/bitset_utils.h"
using namespace angle;
namespace
{
class BitSetIteratorTest : public testing::Test
{
protected:
BitSet<40> mStateBits;
};
// Simple iterator test.
TEST_F(BitSetIteratorTest, Iterator)
{
std::set<size_t> originalValues;
originalValues.insert(2);
originalValues.insert(6);
originalValues.insert(8);
originalValues.insert(35);
for (size_t value : originalValues)
{
mStateBits.set(value);
}
std::set<size_t> readValues;
for (size_t bit : mStateBits)
{
EXPECT_EQ(1u, originalValues.count(bit));
EXPECT_EQ(0u, readValues.count(bit));
readValues.insert(bit);
}
EXPECT_EQ(originalValues.size(), readValues.size());
}
// Test an empty iterator.
TEST_F(BitSetIteratorTest, EmptySet)
{
// We don't use the FAIL gtest macro here since it returns immediately,
// causing an unreachable code warning in MSVS
bool sawBit = false;
for (size_t bit : mStateBits)
{
sawBit = true;
ANGLE_UNUSED_VARIABLE(bit);
}
EXPECT_FALSE(sawBit);
}
// Test iterating a result of combining two bitsets.
TEST_F(BitSetIteratorTest, NonLValueBitset)
{
BitSet<40> otherBits;
mStateBits.set(1);
mStateBits.set(2);
mStateBits.set(3);
mStateBits.set(4);
otherBits.set(0);
otherBits.set(1);
otherBits.set(3);
otherBits.set(5);
std::set<size_t> seenBits;
angle::BitSet<40> maskedBits = (mStateBits & otherBits);
for (size_t bit : maskedBits)
{
EXPECT_EQ(0u, seenBits.count(bit));
seenBits.insert(bit);
EXPECT_TRUE(mStateBits[bit]);
EXPECT_TRUE(otherBits[bit]);
}
EXPECT_EQ((mStateBits & otherBits).count(), seenBits.size());
}
// Test bit assignments.
TEST_F(BitSetIteratorTest, BitAssignment)
{
std::set<size_t> originalValues;
originalValues.insert(2);
originalValues.insert(6);
originalValues.insert(8);
originalValues.insert(35);
for (size_t value : originalValues)
{
(mStateBits[value] = false) = true;
}
for (size_t value : originalValues)
{
EXPECT_TRUE(mStateBits.test(value));
}
}
// Tests adding bits to the iterator during iteration.
TEST_F(BitSetIteratorTest, SetLaterBit)
{
std::set<size_t> expectedValues = {1, 3, 5, 7, 9};
mStateBits.set(1);
std::set<size_t> actualValues;
for (auto iter = mStateBits.begin(), end = mStateBits.end(); iter != end; ++iter)
{
if (*iter == 1)
{
iter.setLaterBit(3);
iter.setLaterBit(5);
iter.setLaterBit(7);
iter.setLaterBit(9);
}
actualValues.insert(*iter);
}
EXPECT_EQ(expectedValues, actualValues);
}
// Tests removing bits from the iterator during iteration.
TEST_F(BitSetIteratorTest, ResetLaterBit)
{
std::set<size_t> expectedValues = {1, 3, 5, 7, 9};
for (size_t index = 1; index <= 9; ++index)
mStateBits.set(index);
std::set<size_t> actualValues;
for (auto iter = mStateBits.begin(), end = mStateBits.end(); iter != end; ++iter)
{
if (*iter == 1)
{
iter.resetLaterBit(2);
iter.resetLaterBit(4);
iter.resetLaterBit(6);
iter.resetLaterBit(8);
}
actualValues.insert(*iter);
}
EXPECT_EQ(expectedValues, actualValues);
}
} // anonymous namespace