diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index 0f0df0c1..cecc387a 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -249,7 +249,7 @@ namespace PolyVox public: /// Constructor for creating a fixed size volume. - PagedVolume(Pager* pPager = nullptr, uint32_t uTargetMemoryUsageInBytes = 256 * 1024 * 1024, uint16_t uChunkSideLength = 32); + PagedVolume(Pager* pPager, uint32_t uTargetMemoryUsageInBytes = 256 * 1024 * 1024, uint16_t uChunkSideLength = 32); /// Destructor ~PagedVolume(); @@ -319,7 +319,7 @@ namespace PolyVox uint8_t m_uChunkSideLengthPower; int32_t m_iChunkMask; - Pager* m_pPager; + Pager* m_pPager = nullptr; }; } diff --git a/include/PolyVox/PagedVolume.inl b/include/PolyVox/PagedVolume.inl index d3eb8764..50841c48 100644 --- a/include/PolyVox/PagedVolume.inl +++ b/include/PolyVox/PagedVolume.inl @@ -41,6 +41,7 @@ namespace PolyVox , m_uChunkSideLength(uChunkSideLength) { // Validation of parameters + POLYVOX_THROW_IF(!pPager, std::invalid_argument, "You must provide a valid pager when constructing a PagedVolume"); POLYVOX_THROW_IF(uTargetMemoryUsageInBytes < 1 * 1024 * 1024, std::invalid_argument, "Target memory usage is too small to be practical"); POLYVOX_THROW_IF(m_uChunkSideLength == 0, std::invalid_argument, "Chunk side length cannot be zero."); POLYVOX_THROW_IF(m_uChunkSideLength > 256, std::invalid_argument, "Chunk size is too large to be practical."); @@ -191,7 +192,7 @@ namespace PolyVox // Ensure we don't page in more chunks than the volume can hold. Region region(v3dStart, v3dEnd); uint32_t uNoOfChunks = static_cast(region.getWidthInVoxels() * region.getHeightInVoxels() * region.getDepthInVoxels()); - POLYVOX_LOG_WARNING_IF(uNoOfChunks > m_uChunkCountLimit, "Attempting to prefetch more than the maximum number of chunks."); + POLYVOX_LOG_WARNING_IF(uNoOfChunks > m_uChunkCountLimit, "Attempting to prefetch more than the maximum number of chunks (this will cause thrashing)."); uNoOfChunks = (std::min)(uNoOfChunks, m_uChunkCountLimit); // Loops over the specified positions and touch the corresponding chunks. @@ -213,8 +214,6 @@ namespace PolyVox template void PagedVolume::flushAll() { - POLYVOX_LOG_WARNING_IF(!m_pPager, "Data discarded by flush operation as no pager is attached."); - // Clear this pointer so it doesn't hang on to any chunks. m_pLastAccessedChunk = nullptr; @@ -234,8 +233,6 @@ namespace PolyVox template void PagedVolume::flush(Region regFlush) { - POLYVOX_LOG_WARNING_IF(!m_pPager, "Data discarded by flush operation as no pager is attached."); - // Clear this pointer so it doesn't hang on to any chunks. m_pLastAccessedChunk = nullptr; @@ -329,10 +326,6 @@ namespace PolyVox bool erasedChunk = false; while (m_pRecentlyUsedChunks.size() + 1 > m_uChunkCountLimit) // +1 ready for new chunk we will add next. { - // This should never hit, because it should not have been possible for - // the user to limit the number of chunks if they did not provide a pager. - POLYVOX_ASSERT(m_pPager, "A valid pager is required to limit number of chunks"); - // Find the least recently used chunk. Hopefully this isn't too slow. typename SharedPtrChunkMap::iterator itUnloadChunk = m_pRecentlyUsedChunks.begin(); for (typename SharedPtrChunkMap::iterator i = m_pRecentlyUsedChunks.begin(); i != m_pRecentlyUsedChunks.end(); i++) diff --git a/include/PolyVox/PagedVolumeChunk.inl b/include/PolyVox/PagedVolumeChunk.inl index 5a9a24d3..b21ca9f1 100644 --- a/include/PolyVox/PagedVolumeChunk.inl +++ b/include/PolyVox/PagedVolumeChunk.inl @@ -35,6 +35,8 @@ namespace PolyVox ,m_pPager(pPager) ,m_v3dChunkSpacePosition(v3dPosition) { + POLYVOX_ASSERT(m_pPager, "No valid pager supplied to chunk constructor."); + // Compute the side length m_uSideLength = uSideLength; m_uSideLengthPower = logBase2(uSideLength); @@ -44,21 +46,13 @@ namespace PolyVox m_tData = new VoxelType[uNoOfVoxels]; // Pass the chunk to the Pager to give it a chance to initialise it with any data - if (m_pPager) - { - // From the coordinates of the chunk we deduce the coordinates of the contained voxels. - Vector3DInt32 v3dLower = m_v3dChunkSpacePosition * static_cast(m_uSideLength); - Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1); - Region reg(v3dLower, v3dUpper); + // From the coordinates of the chunk we deduce the coordinates of the contained voxels. + Vector3DInt32 v3dLower = m_v3dChunkSpacePosition * static_cast(m_uSideLength); + Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1); + Region reg(v3dLower, v3dUpper); - // Page the data in - m_pPager->pageIn(reg, this); - } - else - { - // Just fill with zeros - std::fill(m_tData, m_tData + uNoOfVoxels, VoxelType()); - } + // Page the data in + m_pPager->pageIn(reg, this); // We'll use this later to decide if data needs to be paged out again. m_bDataModified = false; @@ -67,7 +61,7 @@ namespace PolyVox template PagedVolume::Chunk::~Chunk() { - if (m_pPager && m_bDataModified) + if (m_bDataModified) { // From the coordinates of the chunk we deduce the coordinates of the contained voxels. Vector3DInt32 v3dLower = m_v3dChunkSpacePosition * static_cast(m_uSideLength); diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 563effb2..a38b5326 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #include "TestCubicSurfaceExtractor.h" #include "PolyVox/Density.h" +#include "PolyVox/FilePager.h" #include "PolyVox/Material.h" #include "PolyVox/MaterialDensityPair.h" #include "PolyVox/RawVolume.h" @@ -95,7 +96,8 @@ template VolumeType* createAndFillVolumeRealistic(int32_t iVolumeSideLength) { //Create empty volume - VolumeType* volData = new VolumeType; + FilePager* filePager = new FilePager(); + VolumeType* volData = new VolumeType(filePager); //Fill the volume with data for (int32_t z = 0; z < iVolumeSideLength; z++) @@ -158,7 +160,8 @@ void TestCubicSurfaceExtractor::testBehaviour() void TestCubicSurfaceExtractor::testEmptyVolumePerformance() { - PagedVolume emptyVol; + FilePager* filePager = new FilePager(); + PagedVolume emptyVol(filePager); createAndFillVolumeWithNoise(emptyVol, 128, 0, 0); Mesh< CubicVertex< uint32_t >, uint16_t > emptyMesh; QBENCHMARK{ extractCubicMeshCustom(&emptyVol, Region(32, 32, 32, 63, 63, 63), &emptyMesh); } @@ -175,7 +178,8 @@ void TestCubicSurfaceExtractor::testRealisticVolumePerformance() void TestCubicSurfaceExtractor::testNoiseVolumePerformance() { - PagedVolume noiseVol; + FilePager* filePager = new FilePager(); + PagedVolume noiseVol(filePager); createAndFillVolumeWithNoise(noiseVol, 128, 0, 2); Mesh< CubicVertex< uint32_t >, uint16_t > noiseMesh; QBENCHMARK{ extractCubicMeshCustom(&noiseVol, Region(32, 32, 32, 63, 63, 63), &noiseMesh); }