From 4781ca5c42c42faec1be7ab0f9d3e3133f4453ff Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 12 Sep 2014 15:36:28 +0200 Subject: [PATCH] Work on removing compression from LargeVolume. --- examples/Paging/main.cpp | 14 +++++------ .../include/PolyVoxCore/FilePager.h | 10 ++++---- .../include/PolyVoxCore/LargeVolume.inl | 24 +++++++++++++------ .../PolyVoxCore/include/PolyVoxCore/Pager.h | 6 ++--- tests/testvolume.cpp | 8 +++---- tests/testvolume.h | 4 ++-- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 58e94b5d..53c3f161 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -91,11 +91,11 @@ public: /// Destructor virtual ~PerlinNoisePager() {}; - virtual void pageIn(const PolyVox::Region& region, CompressedBlock* pBlockData) + virtual void pageIn(const PolyVox::Region& region, UncompressedBlock* pBlockData) { // FIXME - this isn't a great example... it's a shame we have to hard clode the block size and also create/destroy // a compressor each time. These could at least be moved outside somewhere if we can't fix it in a better way... - UncompressedBlock block(256); + //UncompressedBlock block(256); Perlin perlin(2,2,1,234); @@ -133,18 +133,18 @@ public: // Voxel position within a block always start from zero. So if a block represents region (4, 8, 12) to (11, 19, 15) // then the valid block voxels are from (0, 0, 0) to (7, 11, 3). Hence we subtract the lower corner position of the // region from the volume space position in order to get the block space position. - block.setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); + pBlockData->setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); } } } // Now compress the computed data into the provided block. - RLEBlockCompressor* compressor = new RLEBlockCompressor(); - compressor->compress(&block, pBlockData); - delete compressor; + //RLEBlockCompressor* compressor = new RLEBlockCompressor(); + //compressor->compress(&block, pBlockData); + //delete compressor; } - virtual void pageOut(const PolyVox::Region& region, CompressedBlock* /*pBlockData*/) + virtual void pageOut(const PolyVox::Region& region, UncompressedBlock* /*pBlockData*/) { std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 830e0374..5e0a6081 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -68,7 +68,7 @@ namespace PolyVox m_vecCreatedFiles.clear(); } - virtual void pageIn(const Region& region, CompressedBlock* pBlockData) + virtual void pageIn(const Region& region, UncompressedBlock* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); //POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); @@ -88,14 +88,16 @@ namespace PolyVox { POLYVOX_LOG_TRACE("Paging in data for " << region); - fseek(pFile, 0L, SEEK_END); + /*fseek(pFile, 0L, SEEK_END); size_t fileSizeInBytes = ftell(pFile); fseek(pFile, 0L, SEEK_SET); uint8_t* buffer = new uint8_t[fileSizeInBytes]; fread(buffer, sizeof(uint8_t), fileSizeInBytes, pFile); pBlockData->setData(buffer, fileSizeInBytes); - delete[] buffer; + delete[] buffer;*/ + + fread(pBlockData->getData(), sizeof(uint8_t), pBlockData->getDataSizeInBytes(), pFile); if(ferror(pFile)) { @@ -110,7 +112,7 @@ namespace PolyVox } } - virtual void pageOut(const Region& region, CompressedBlock* pBlockData) + virtual void pageOut(const Region& region, UncompressedBlock* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); //POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 8c12aa45..b17eb128 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -571,7 +571,7 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); // Page the data out - m_pPager->pageOut(Region(v3dLower, v3dUpper), pCompressedBlock); + //m_pPager->pageOut(Region(v3dLower, v3dUpper), pCompressedBlock); // The compressed data is no longer modified with respect to the data on disk pCompressedBlock->m_bDataModified = false; @@ -591,7 +591,7 @@ namespace PolyVox // This should never happen as blocks are deleted based on being least recently used. // I the case that we are flushing we delete all blocks, but the flush function will // reset the 'm_pLastAccessedBlock' anyway to prevent it being accidentally reused. - POLYVOX_ASSERT(pUncompressedBlock != m_pLastAccessedBlock, "Attempted to delete last accessed block."); + //POLYVOX_ASSERT(pUncompressedBlock != m_pLastAccessedBlock, "Attempted to delete last accessed block."); // Before deleting the block we may need to recompress its data. We // only do this if the data has been modified since it was decompressed. @@ -599,9 +599,13 @@ namespace PolyVox { // Get the compressed block which we will copy the data back in to. Vector3DInt32 v3dBlockPos = itUncompressedBlock->first; - CompressedBlock* pCompressedBlock = getCompressedBlock(v3dBlockPos.getX(), v3dBlockPos.getY(), v3dBlockPos.getZ()); - m_pBlockCompressor->compress(pUncompressedBlock, pCompressedBlock); + // From the coordinates of the block we deduce the coordinates of the contained voxels. + Vector3DInt32 v3dLower(v3dBlockPos.getX() << m_uBlockSideLengthPower, v3dBlockPos.getY() << m_uBlockSideLengthPower, v3dBlockPos.getZ() << m_uBlockSideLengthPower); + Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength - 1, m_uBlockSideLength - 1, m_uBlockSideLength - 1); + + // Page the data out + m_pPager->pageOut(Region(v3dLower, v3dUpper), itUncompressedBlock->second); // The compressed data has been updated, so the uncompressed data is no longer modified with respect to it. pUncompressedBlock->m_bDataModified = false; @@ -679,13 +683,19 @@ namespace PolyVox // An uncompressed bock is always backed by a compressed one, and this is created by getCompressedBlock() if it doesn't // already exist. If it does already exist and has data then we bring this across into the ucompressed version. - if(getCompressedBlock(uBlockX, uBlockY, uBlockZ)->getData() != 0) + /*if(getCompressedBlock(uBlockX, uBlockY, uBlockZ)->getData() != 0) { // FIXME - multiple getCompressedBlock() calls (including the one above) - CompressedBlock* pBlock = getCompressedBlock(uBlockX, uBlockY, uBlockZ); + CompressedBlock* pBlock = getCompressedBlock(uBlockX, uBlockY, ); m_pBlockCompressor->decompress(pBlock, pUncompressedBlock); - } + }*/ + + // Pass the block to the Pager to give it a chance to initialise it with any data + Vector3DInt32 v3dLower(uBlockX << m_uBlockSideLengthPower, uBlockY << m_uBlockSideLengthPower, uBlockZ << m_uBlockSideLengthPower); + Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength - 1, m_uBlockSideLength - 1, m_uBlockSideLength - 1); + Region reg(v3dLower, v3dUpper); + m_pPager->pageIn(reg, pUncompressedBlock); // Add our new block to the map. m_pUncompressedBlockCache.insert(std::make_pair(v3dBlockPos, pUncompressedBlock)); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index eb37e4f7..c11d8afd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Pager_H__ #define __PolyVox_Pager_H__ -#include "PolyVoxCore/CompressedBlock.h" +#include "PolyVoxCore/UncompressedBlock.h" #include "PolyVoxCore/Impl/TypeDef.h" namespace PolyVox @@ -41,8 +41,8 @@ namespace PolyVox /// Destructor virtual ~Pager() {}; - virtual void pageIn(const Region& region, CompressedBlock* pBlockData) = 0; - virtual void pageOut(const Region& region, CompressedBlock* pBlockData) = 0; + virtual void pageIn(const Region& region, UncompressedBlock* pBlockData) = 0; + virtual void pageOut(const Region& region, UncompressedBlock* pBlockData) = 0; }; } diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index f879f1bf..4a0d65e1 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -313,7 +313,7 @@ TestVolume::~TestVolume() * RawVolume Tests */ -void TestVolume::testRawVolumeDirectAccessAllInternalForwards() +/*void TestVolume::testRawVolumeDirectAccessAllInternalForwards() { int32_t result = 0; @@ -399,13 +399,13 @@ void TestVolume::testRawVolumeSamplersWithExternalBackwards() result = testSamplersWithWrappingBackwards(m_pRawVolume, -1, -3, -2, 2, 5, 4); } QCOMPARE(result, static_cast(-769775893)); -} +}*/ /* * SimpleVolume Tests */ -void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards() +/*void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards() { int32_t result = 0; QBENCHMARK @@ -483,7 +483,7 @@ void TestVolume::testSimpleVolumeSamplersWithExternalBackwards() result = testSamplersWithWrappingBackwards(m_pSimpleVolume, -1, -3, -2, 2, 5, 4); } QCOMPARE(result, static_cast(-769775893)); -} +}*/ /* * LargeVolume Tests diff --git a/tests/testvolume.h b/tests/testvolume.h index 9db5f7a0..57390641 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -37,7 +37,7 @@ public: ~TestVolume(); private slots: - void testRawVolumeDirectAccessAllInternalForwards(); + /*void testRawVolumeDirectAccessAllInternalForwards(); void testRawVolumeSamplersAllInternalForwards(); void testRawVolumeDirectAccessWithExternalForwards(); void testRawVolumeSamplersWithExternalForwards(); @@ -53,7 +53,7 @@ private slots: void testSimpleVolumeDirectAccessAllInternalBackwards(); void testSimpleVolumeSamplersAllInternalBackwards(); void testSimpleVolumeDirectAccessWithExternalBackwards(); - void testSimpleVolumeSamplersWithExternalBackwards(); + void testSimpleVolumeSamplersWithExternalBackwards();*/ void testLargeVolumeDirectAccessAllInternalForwards(); void testLargeVolumeSamplersAllInternalForwards();