Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: content/common/gpu/gpu_memory_manager_unittest.cc

Issue 12087078: Add unit tests for nonuniform GPU memmgr policy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up private Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/gpu/gpu_memory_allocation.h" 5 #include "content/common/gpu/gpu_memory_allocation.h"
6 #include "content/common/gpu/gpu_memory_manager.h" 6 #include "content/common/gpu/gpu_memory_manager.h"
7 #include "content/common/gpu/gpu_memory_manager_client.h" 7 #include "content/common/gpu/gpu_memory_manager_client.h"
8 #include "content/common/gpu/gpu_memory_tracking.h" 8 #include "content/common/gpu/gpu_memory_tracking.h"
9 #include "ui/gfx/size_conversions.h" 9 #include "ui/gfx/size_conversions.h"
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 }; 158 };
159 159
160 class GpuMemoryManagerTest : public testing::Test { 160 class GpuMemoryManagerTest : public testing::Test {
161 protected: 161 protected:
162 static const uint64 kFrontbufferLimitForTest = 3; 162 static const uint64 kFrontbufferLimitForTest = 3;
163 163
164 GpuMemoryManagerTest() 164 GpuMemoryManagerTest()
165 : memmgr_(0, kFrontbufferLimitForTest) { 165 : memmgr_(0, kFrontbufferLimitForTest) {
166 memmgr_.TestingDisableScheduleManage(); 166 memmgr_.TestingDisableScheduleManage();
167 memmgr_.TestingSetUseNonuniformMemoryPolicy(false);
167 } 168 }
168 169
169 virtual void SetUp() { 170 virtual void SetUp() {
170 } 171 }
171 172
172 static int32 GenerateUniqueSurfaceId() { 173 static int32 GenerateUniqueSurfaceId() {
173 static int32 surface_id_ = 1; 174 static int32 surface_id_ = 1;
174 return surface_id_++; 175 return surface_id_++;
175 } 176 }
176 177
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return memmgr_.GetMaximumClientAllocation(); 244 return memmgr_.GetMaximumClientAllocation();
244 } 245 }
245 246
246 uint64 GetMinimumClientAllocation() { 247 uint64 GetMinimumClientAllocation() {
247 return memmgr_.GetMinimumClientAllocation(); 248 return memmgr_.GetMinimumClientAllocation();
248 } 249 }
249 250
250 GpuMemoryManager memmgr_; 251 GpuMemoryManager memmgr_;
251 }; 252 };
252 253
254 class GpuMemoryManagerTestNonuniform : public GpuMemoryManagerTest {
255 protected:
256 void SetClientStats(
257 FakeClient* client,
258 uint64 required,
259 uint64 nicetohave) {
260 client->SetManagedMemoryStats(
261 GpuManagedMemoryStats(required, nicetohave, 0, false));
262 }
263 };
264
253 // Test GpuMemoryManager::Manage basic functionality. 265 // Test GpuMemoryManager::Manage basic functionality.
254 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer 266 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer
255 // according to visibility and last used time for stubs with surface. 267 // according to visibility and last used time for stubs with surface.
256 // Expect memory allocation to be shared according to share groups for stubs 268 // Expect memory allocation to be shared according to share groups for stubs
257 // without a surface. 269 // without a surface.
258 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { 270 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
259 // Test stubs with surface. 271 // Test stubs with surface.
260 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), 272 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
261 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); 273 stub2(&memmgr_, GenerateUniqueSurfaceId(), false);
262 274
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 stub1.BytesWhenVisible()); 878 stub1.BytesWhenVisible());
867 879
868 // Delete all tracked memory so we don't hit leak checks. 880 // Delete all tracked memory so we don't hit leak checks.
869 memmgr_.TrackMemoryAllocatedChange( 881 memmgr_.TrackMemoryAllocatedChange(
870 stub1.tracking_group_.get(), 882 stub1.tracking_group_.get(),
871 999, 883 999,
872 0, 884 0,
873 gpu::gles2::MemoryTracker::kUnmanaged); 885 gpu::gles2::MemoryTracker::kUnmanaged);
874 } 886 }
875 887
888 // Test nonvisible MRU behavior (the most recently used nonvisible clients
889 // keep their contents).
890 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundMru) {
891 // Set memory manager constants for this test
892 memmgr_.TestingSetUseNonuniformMemoryPolicy(true);
893 memmgr_.TestingSetAvailableGpuMemory(64);
894 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16);
895 memmgr_.TestingSetMinimumClientAllocation(8);
896
897 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true);
898 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true);
899 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true);
900
901 // When all are visible, they should all be allowed to have memory
902 // should they become nonvisible.
903 SetClientStats(&stub1, 6, 23);
904 SetClientStats(&stub2, 6, 23);
905 SetClientStats(&stub3, 6, 23);
906 Manage();
907 EXPECT_GE(stub1.BytesWhenVisible(), 20u);
908 EXPECT_GE(stub2.BytesWhenVisible(), 20u);
909 EXPECT_GE(stub3.BytesWhenVisible(), 20u);
910 EXPECT_LT(stub1.BytesWhenVisible(), 22u);
911 EXPECT_LT(stub2.BytesWhenVisible(), 22u);
912 EXPECT_LT(stub3.BytesWhenVisible(), 22u);
913 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u);
914 EXPECT_GE(stub2.BytesWhenNotVisible(), 6u);
915 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u);
916
917 // Background stubs 1 and 2, and they should fit. All stubs should
918 // have their full nicetohave budget should they become visible.
919 stub2.SetVisible(false);
920 stub1.SetVisible(false);
921 Manage();
922 EXPECT_GE(stub1.BytesWhenVisible(), 23u);
923 EXPECT_GE(stub2.BytesWhenVisible(), 23u);
924 EXPECT_GE(stub3.BytesWhenVisible(), 23u);
925 EXPECT_LT(stub1.BytesWhenVisible(), 32u);
926 EXPECT_LT(stub2.BytesWhenVisible(), 32u);
927 EXPECT_LT(stub3.BytesWhenVisible(), 32u);
928 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u);
929 EXPECT_GE(stub2.BytesWhenNotVisible(), 6u);
930 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u);
931
932 // Now background stub 3, and it should cause stub 2 to be
933 // evicted because it was set non-visible first
934 stub3.SetVisible(false);
935 Manage();
936 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u);
937 EXPECT_EQ(stub2.BytesWhenNotVisible(), 0u);
938 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u);
939 }
940
941 // Test that once a backgrounded client has dropped its resources, it
942 // doesn't get them back until it becomes visible again.
943 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundDiscardPersistent) {
944 // Set memory manager constants for this test
945 memmgr_.TestingSetUseNonuniformMemoryPolicy(true);
946 memmgr_.TestingSetAvailableGpuMemory(64);
947 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16);
948 memmgr_.TestingSetMinimumClientAllocation(8);
949
950 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true);
951 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true);
952
953 // Both clients should be able to keep their contents should one of
954 // them become nonvisible.
955 SetClientStats(&stub1, 10, 20);
956 SetClientStats(&stub2, 10, 20);
957 Manage();
958 EXPECT_GE(stub1.BytesWhenNotVisible(), 10u);
959 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u);
960
961 // If they both go nonvisible, then only the most recently used client
962 // should keep its contents.
963 stub1.SetVisible(false);
964 stub2.SetVisible(false);
965 Manage();
966 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u);
967 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u);
968
969 // When becoming visible, stub 2 should get its contents back, and
970 // retain them next time it is made nonvisible.
971 stub2.SetVisible(true);
972 Manage();
973 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u);
974 stub2.SetVisible(false);
975 Manage();
976 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u);
977 }
978
979 // Test tracking of unmanaged (e.g, WebGL) memory.
980 TEST_F(GpuMemoryManagerTestNonuniform, UnmanagedTracking) {
981 // Set memory manager constants for this test
982 memmgr_.TestingSetUseNonuniformMemoryPolicy(true);
983 memmgr_.TestingSetAvailableGpuMemory(64);
984 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16);
985 memmgr_.TestingSetMinimumClientAllocation(8);
986 memmgr_.TestingSetUnmanagedLimitStep(16);
987
988 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true);
989
990 // Expect that the one stub get its nicetohave level.
991 SetClientStats(&stub1, 16, 32);
992 Manage();
993 EXPECT_GE(stub1.BytesWhenVisible(), 32u);
994
995 // Now allocate some unmanaged memory and make sure the amount
996 // goes down.
997 memmgr_.TrackMemoryAllocatedChange(
998 stub1.tracking_group_.get(),
999 0,
1000 48,
1001 gpu::gles2::MemoryTracker::kUnmanaged);
1002 Manage();
1003 EXPECT_LT(stub1.BytesWhenVisible(), 24u);
1004
1005 // Now allocate the entire FB worth of unmanaged memory, and
1006 // make sure that we stay stuck at the minimum tab allocation.
1007 memmgr_.TrackMemoryAllocatedChange(
1008 stub1.tracking_group_.get(),
1009 48,
1010 64,
1011 gpu::gles2::MemoryTracker::kUnmanaged);
1012 Manage();
1013 EXPECT_EQ(stub1.BytesWhenVisible(), 8u);
1014
1015 // Far-oversubscribe the entire FB, and make sure we stay at
1016 // the minimum allocation, and don't blow up.
1017 memmgr_.TrackMemoryAllocatedChange(
1018 stub1.tracking_group_.get(),
1019 64,
1020 999,
1021 gpu::gles2::MemoryTracker::kUnmanaged);
1022 Manage();
1023 EXPECT_EQ(stub1.BytesWhenVisible(), 8u);
1024
1025 // Delete all tracked memory so we don't hit leak checks.
1026 memmgr_.TrackMemoryAllocatedChange(
1027 stub1.tracking_group_.get(),
1028 999,
1029 0,
1030 gpu::gles2::MemoryTracker::kUnmanaged);
1031 }
1032
1033 // Test the default allocation levels are used.
1034 TEST_F(GpuMemoryManagerTestNonuniform, DefaultAllocation) {
1035 // Set memory manager constants for this test
1036 memmgr_.TestingSetUseNonuniformMemoryPolicy(true);
1037 memmgr_.TestingSetAvailableGpuMemory(64);
1038 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16);
1039 memmgr_.TestingSetMinimumClientAllocation(8);
1040 memmgr_.TestingSetDefaultClientAllocation(16);
1041
1042 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true);
1043
1044 // Expect that a client which has not sent stats receive the
1045 // default allocation.
1046 Manage();
1047 EXPECT_EQ(stub1.BytesWhenVisible(),
1048 memmgr_.GetDefaultClientAllocation());
1049 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u);
1050 }
1051
876 } // namespace content 1052 } // namespace content
OLDNEW
« content/common/gpu/gpu_memory_manager.h ('K') | « content/common/gpu/gpu_memory_manager_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698