From 931c6cd3ec7d819bbb18d552e16466fadb4f6bf3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 25 Mar 2015 16:40:05 +0100 Subject: [PATCH] Added tests for chunk performance. --- tests/testvolume.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++- tests/testvolume.h | 8 ++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 27d10a57..aa7658bb 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -30,6 +30,8 @@ freely, subject to the following restrictions: #include #include +#include + using namespace PolyVox; // This is used to compute a value from a list of integers. We use it to @@ -249,7 +251,7 @@ TestVolume::TestVolume() //Create the volumes m_pRawVolume = new RawVolume(m_regVolume); - m_pPagedVolume = new PagedVolume(m_pFilePager, 1 * 1024 * 1024, 32); + m_pPagedVolume = new PagedVolume(m_pFilePager, 1 * 1024 * 1024, m_uChunkSideLength); //Fill the volume with some data for (int z = m_regVolume.getLowerZ(); z <= m_regVolume.getUpperZ(); z++) @@ -264,10 +266,26 @@ TestVolume::TestVolume() } } } + + // Note - We are reusing the FilePager for testing... watch out for conflicts with the main volume. + m_pPagedVolumeChunk = new PagedVolume::Chunk(Vector3DInt32(10000, 10000, 10000), m_uChunkSideLength, m_pFilePager); + int32_t i = 0; + for (uint16_t z = 0; z < m_uChunkSideLength; z++) + { + for (uint16_t y = 0; y < m_uChunkSideLength; y++) + { + for (uint16_t x = 0; x < m_uChunkSideLength; x++) + { + m_pPagedVolumeChunk->setVoxel(x, y, z, ++i); + } + } + } } TestVolume::~TestVolume() { + delete m_pPagedVolumeChunk; + delete m_pRawVolume; delete m_pPagedVolume; @@ -450,4 +468,49 @@ void TestVolume::testPagedVolumeSamplersWithExternalBackwards() QCOMPARE(result, static_cast(-993539594)); } +void TestVolume::testPagedVolumeChunkLocalAccess() +{ + std::mt19937 rng; + int32_t result = 0; + uint16_t x = rng() % m_uChunkSideLength; + uint16_t y = rng() % m_uChunkSideLength; + uint16_t z = rng() % m_uChunkSideLength; + QBENCHMARK + { + for (uint32_t ct = 0; ct < 1000000; ct++) + { + uint16_t xOffset = rng() % 3; + uint16_t yOffset = rng() % 3; + uint16_t zOffset = rng() % 3; + x += xOffset; + y += yOffset; + z += zOffset; + x %= m_uChunkSideLength; + y %= m_uChunkSideLength; + z %= m_uChunkSideLength; + int32_t voxel = m_pPagedVolumeChunk->getVoxel(x, y, z); + result = cantorTupleFunction(result, voxel); + } + } + QCOMPARE(result, static_cast(145244783)); +} + +void TestVolume::testPagedVolumeChunkRandomAccess() +{ + std::mt19937 rng; + int32_t result = 0; + QBENCHMARK + { + for (uint32_t ct = 0; ct < 1000000; ct++) + { + uint16_t x = rng() % m_uChunkSideLength; + uint16_t y = rng() % m_uChunkSideLength; + uint16_t z = rng() % m_uChunkSideLength; + int32_t voxel = m_pPagedVolumeChunk->getVoxel(x, y, z); + result = cantorTupleFunction(result, voxel); + } + } + QCOMPARE(result, static_cast(408757678)); +} + QTEST_MAIN(TestVolume) diff --git a/tests/testvolume.h b/tests/testvolume.h index 79bab98d..e17534dd 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #define __PolyVox_TestVolume_H__ #include "PolyVox/PolyVoxForwardDeclarations.h" +#include "PolyVox/PagedVolume.h" #include "PolyVox/Region.h" #include @@ -56,7 +57,12 @@ private slots: void testPagedVolumeDirectAccessWithExternalBackwards(); void testPagedVolumeSamplersWithExternalBackwards(); + void testPagedVolumeChunkLocalAccess(); + void testPagedVolumeChunkRandomAccess(); + private: + static const uint16_t m_uChunkSideLength = 32; + PolyVox::Region m_regVolume; PolyVox::Region m_regInternal; PolyVox::Region m_regExternal; @@ -64,6 +70,8 @@ private: PolyVox::RawVolume* m_pRawVolume; PolyVox::PagedVolume* m_pPagedVolume; + + PolyVox::PagedVolume::Chunk* m_pPagedVolumeChunk; }; #endif