Edit

kc3-lang/angle/src/libANGLE/ResourceMap_unittest.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2018-09-17 17:18:43
    Hash : 0fdb956d
    Message : 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>

  • src/libANGLE/ResourceMap_unittest.cpp
  • //
    // 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