TileAllocator.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2009-2023, 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. TileAllocator talloc;
  10. talloc.init(8, 8, 3, true);
  11. Array<U32, 4> viewport;
  12. TileAllocatorResult res;
  13. const U lightUuid = 1;
  14. const U dcCount = 666;
  15. Timestamp crntTimestamp = 1;
  16. Timestamp lightTimestamp = 1;
  17. // Allocate 1 med
  18. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 0, dcCount, 1, viewport);
  19. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  20. // Allocate 3 big
  21. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 2, 0, dcCount, 2, viewport);
  22. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  23. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 3, 0, dcCount, 2, viewport);
  24. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  25. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 4, 0, dcCount, 2, viewport);
  26. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  27. // Fail to allocate 1 big
  28. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 5, 0, dcCount, 2, viewport);
  29. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationFailed);
  30. // Allocate 3 med
  31. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 1, dcCount, 1, viewport);
  32. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  33. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 2, dcCount, 1, viewport);
  34. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  35. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 1, 3, dcCount, 1, viewport);
  36. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  37. // Fail to allocate a small
  38. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 6, 0, dcCount, 0, viewport);
  39. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationFailed);
  40. // New frame
  41. ++crntTimestamp;
  42. // Allocate 3 big again
  43. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 2, 0, dcCount + 1, 2, viewport);
  44. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  45. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 3, 0, dcCount, 2, viewport);
  46. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kCached);
  47. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 4, 0, dcCount + 1, 2, viewport);
  48. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  49. // Allocate 16 small
  50. for(U i = 0; i < 16; ++i)
  51. {
  52. res = talloc.allocate(crntTimestamp, lightTimestamp, lightUuid + 6 + i, 0, dcCount, 0, viewport);
  53. ANKI_TEST_EXPECT_EQ(res, TileAllocatorResult::kAllocationSucceded);
  54. }
  55. }