Hash :
0fdb956d
Author :
Date :
2018-09-17T17:18:43
Re-land "Inline and micro-optimize more for perf tests."" Re-land fixes memory leaks. Using a custom array instead of std::vector speeds up the resource manager. One reason is because calls to size() are implemented in many implementations as a difference between two pointers. This sub size implementations are slower than storing a simple size variable in a custom class. Also includes more inlining of hot spots functions. Also includes a small unit test class for ResourceMap. And an unrelated but small test fix for TextureLimisTest. Also a small unrelated fix for a Transform Feedback test. Increase the scores of the draw call perf test with texture and buffer bindings and the buffer binding perf test. Bug: angleproject:2763 Change-Id: Ic2f0f689107b2bf05c63da2ed6bbc9f0feea63f7 Reviewed-on: https://chromium-review.googlesource.com/1229033 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@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
//
// Copyright 2018 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.
//
// ResourceMap_unittest:
// Unit tests for the ResourceMap template class.
//
#include <gtest/gtest.h>
#include "libANGLE/ResourceMap.h"
using namespace gl;
namespace
{
// Tests assigning slots in the map and then deleting elements.
TEST(ResourceMapTest, AssignAndErase)
{
constexpr size_t kSize = 64;
ResourceMap<size_t> resourceMap;
std::vector<size_t> objects(kSize, 1);
for (size_t index = 0; index < kSize; ++index)
{
resourceMap.assign(index + 1, &objects[index]);
}
for (size_t index = 0; index < kSize; ++index)
{
size_t *found = nullptr;
ASSERT_TRUE(resourceMap.erase(index + 1, &found));
ASSERT_EQ(&objects[index], found);
}
ASSERT_TRUE(resourceMap.empty());
}
// Tests assigning slots in the map and then using clear() to free it.
TEST(ResourceMapTest, AssignAndClear)
{
constexpr size_t kSize = 64;
ResourceMap<size_t> resourceMap;
std::vector<size_t> objects(kSize, 1);
for (size_t index = 0; index < kSize; ++index)
{
resourceMap.assign(index + 1, &objects[index]);
}
resourceMap.clear();
ASSERT_TRUE(resourceMap.empty());
}
// Tests growing a map more than double the size.
TEST(ResourceMapTest, BigGrowth)
{
constexpr size_t kSize = 8;
ResourceMap<size_t> resourceMap;
std::vector<size_t> objects;
for (size_t index = 0; index < kSize; ++index)
{
objects.push_back(index);
}
// Assign a large value.
constexpr size_t kLargeIndex = 128;
objects.push_back(kLargeIndex);
for (size_t &object : objects)
{
resourceMap.assign(object, &object);
}
for (size_t object : objects)
{
size_t *found = nullptr;
ASSERT_TRUE(resourceMap.erase(object, &found));
ASSERT_EQ(object, *found);
}
ASSERT_TRUE(resourceMap.empty());
}
// Tests querying unassigned or erased values.
TEST(ResourceMapTest, QueryUnassigned)
{
constexpr size_t kSize = 8;
ResourceMap<size_t> resourceMap;
std::vector<size_t> objects;
for (size_t index = 0; index < kSize; ++index)
{
objects.push_back(index);
}
ASSERT_FALSE(resourceMap.contains(0));
ASSERT_EQ(nullptr, resourceMap.query(0));
ASSERT_FALSE(resourceMap.contains(100));
ASSERT_EQ(nullptr, resourceMap.query(100));
for (size_t &object : objects)
{
resourceMap.assign(object, &object);
}
ASSERT_FALSE(resourceMap.empty());
for (size_t &object : objects)
{
ASSERT_TRUE(resourceMap.contains(object));
ASSERT_EQ(&object, resourceMap.query(object));
}
ASSERT_FALSE(resourceMap.contains(10));
ASSERT_EQ(nullptr, resourceMap.query(10));
ASSERT_FALSE(resourceMap.contains(100));
ASSERT_EQ(nullptr, resourceMap.query(100));
for (size_t object : objects)
{
size_t *found = nullptr;
ASSERT_TRUE(resourceMap.erase(object, &found));
ASSERT_EQ(object, *found);
}
ASSERT_TRUE(resourceMap.empty());
ASSERT_FALSE(resourceMap.contains(0));
ASSERT_EQ(nullptr, resourceMap.query(0));
ASSERT_FALSE(resourceMap.contains(100));
ASSERT_EQ(nullptr, resourceMap.query(100));
}
} // anonymous namespace