TileAllocator.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <Tests/Framework/Framework.h>
  6. #include <AnKi/Renderer/TileAllocator.h>
  7. ANKI_TEST(Renderer, TileAllocator)
  8. {
  9. HeapAllocator<U8> alloc(allocAligned, nullptr);
  10. TileAllocator talloc;
  11. talloc.init(alloc, 8, 8, 3, true);
  12. Array<U32, 4> viewport;
  13. TileAllocatorResult res;
  14. const U lightUuid = 1;
  15. const U dcCount = 666;
  16. Timestamp crntTimestamp = 1;
  17. Timestamp lightTimestamp = 1;
  18. // Allocate 1 med
  19. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 0, dcCount, 1, viewport);
  20. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  21. // Allocate 3 big
  22. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 2, 0, dcCount, 2, viewport);
  23. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  24. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 3, 0, dcCount, 2, viewport);
  25. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  26. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 4, 0, dcCount, 2, viewport);
  27. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  28. // Fail to allocate 1 big
  29. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 5, 0, dcCount, 2, viewport);
  30. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_FAILED);
  31. // Allocate 3 med
  32. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 1, dcCount, 1, viewport);
  33. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  34. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 2, dcCount, 1, viewport);
  35. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  36. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 3, dcCount, 1, viewport);
  37. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  38. // Fail to allocate a small
  39. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 6, 0, dcCount, 0, viewport);
  40. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_FAILED);
  41. // New frame
  42. ++crntTimestamp;
  43. // Allocate 3 big again
  44. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 2, 0, dcCount + 1, 2, viewport);
  45. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  46. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 3, 0, dcCount, 2, viewport);
  47. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::CACHED);
  48. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 4, 0, dcCount + 1, 2, viewport);
  49. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  50. // Allocate 16 small
  51. for(U i = 0; i < 16; ++i)
  52. {
  53. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 6 + i, 0, dcCount, 0, viewport);
  54. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::ALLOCATION_SUCCEEDED);
  55. }
  56. }