History

Move Hide/Show local voxels to a dedicated thread so that it doesn't slow performance of voxel packet processing

ZappoMan committed 12 years ago

Commit 76b3bd41 parent 14129cd7 files · +128 −66Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 7 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+37−64
@@ -592,14 +592,15 @@ float VoxelSystem::getVoxelsBytesReadPerSecondAverage() { · 591 unmodified lines
592}592}
593 593
594int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {594int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
595 bool showTimingDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
596 PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData()",showTimingDetails);
595 597
596 unsigned char command = *sourceBuffer;598 unsigned char command = *sourceBuffer;
597 int numBytesPacketHeader = numBytesForPacketHeader(sourceBuffer);599 int numBytesPacketHeader = numBytesForPacketHeader(sourceBuffer);
598 switch(command) {600 switch(command) {
599 case PACKET_TYPE_VOXEL_DATA: {601 case PACKET_TYPE_VOXEL_DATA: {
600 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),602 PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData() PACKET_TYPE_VOXEL_DATA part...",showTimingDetails);
601 "readBitstreamToTree()");603
602
603 unsigned char* dataAt = sourceBuffer + numBytesPacketHeader;604 unsigned char* dataAt = sourceBuffer + numBytesPacketHeader;
604 605
605 VOXEL_PACKET_FLAGS flags = (*(VOXEL_PACKET_FLAGS*)(dataAt));606 VOXEL_PACKET_FLAGS flags = (*(VOXEL_PACKET_FLAGS*)(dataAt));
@@ -641,7 +642,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 35 unmodified lines
641 VoxelPacketData packetData(packetIsCompressed);642 VoxelPacketData packetData(packetIsCompressed);
642 packetData.loadFinalizedContent(dataAt, sectionLength);643 packetData.loadFinalizedContent(dataAt, sectionLength);
643 if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) {644 if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) {
644 qDebug("Got Packet color:%s compressed:%s sequence: %u flight:%d usec size:%d data:%d"645 qDebug("VoxelSystem::parseData() ... Got Packet Section"
646 " color:%s compressed:%s sequence: %u flight:%d usec size:%d data:%d"
645 " subsection:%d sectionLength:%d uncompressed:%d\n",647 " subsection:%d sectionLength:%d uncompressed:%d\n",
646 debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed), 648 debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
647 sequence, flightTime, numBytes, dataBytes, subsection, sectionLength, packetData.getUncompressedSize());649 sequence, flightTime, numBytes, dataBytes, subsection, sectionLength, packetData.getUncompressedSize());
@@ -657,12 +659,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 9 unmodified lines
657 }659 }
658 break;660 break;
659 }661 }
660
661
662 if (!_useFastVoxelPipeline || _writeRenderFullVBO) {662 if (!_useFastVoxelPipeline || _writeRenderFullVBO) {
663 setupNewVoxelsForDrawing();663 setupNewVoxelsForDrawing();
664 } else {664 } else {
665 checkForCulling();
666 setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);665 setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);
667 }666 }
668 667
@@ -689,8 +688,6 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 20 unmodified lines
689 688
690 _inSetupNewVoxelsForDrawing = true;689 _inSetupNewVoxelsForDrawing = true;
691 690
692 checkForCulling(); // check for out of view and deleted voxels...
693
694 bool didWriteFullVBO = _writeRenderFullVBO;691 bool didWriteFullVBO = _writeRenderFullVBO;
695 if (_tree->isDirty()) {692 if (_tree->isDirty()) {
696 static char buffer[64] = { 0 };693 static char buffer[64] = { 0 };
@@ -776,68 +773,44 @@ void VoxelSystem::checkForCulling() { · 79 unmodified lines
776 773
777 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()");774 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()");
778 uint64_t start = usecTimestampNow();775 uint64_t start = usecTimestampNow();
779 uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
780 776
781 // These items used to be menu options, we are not defaulting to and only supporting these modes.
782 bool constantCulling = true;
783 bool performHideOutOfViewLogic = true;
784 bool performRemoveOutOfViewLogic = false;
785 777
786 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view778 // track how long its been since we were last moving. If we have recently moved then only use delta frustums, if
787 if (constantCulling || (779 // it's been a long time since we last moved, then go ahead and do a full frustum cull.
788 (sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))780 if (isViewChanging()) {
789 && !isViewChanging()781 _lastViewIsChanging = start;
790 )782 }
791 ) {783 uint64_t sinceLastMoving = (start - _lastViewIsChanging) / 1000;
792 // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove
793 // them from tree, this makes our tree caclulations faster, but doesn't require us to fully rebuild the VBOs (which
794 // can be expensive).
795 if (performHideOutOfViewLogic) {
796
797 // track how long its been since we were last moving. If we have recently moved then only use delta frustums, if
798 // it's been a long time since we last moved, then go ahead and do a full frustum cull.
799 if (isViewChanging()) {
800 _lastViewIsChanging = start;
801 }
802 uint64_t sinceLastMoving = (start - _lastViewIsChanging) / 1000;
803 784
804 bool enoughTime = (sinceLastMoving >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS));785 bool enoughTime = (sinceLastMoving >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS));
805 786
806 // These has changed events will occur before we stop. So we need to remember this for when we finally have stopped787 // These has changed events will occur before we stop. So we need to remember this for when we finally have stopped
807 // moving long enough to be enoughTime 788 // moving long enough to be enoughTime
808 if (hasViewChanged()) {789 if (hasViewChanged()) {
809 _hasRecentlyChanged = true;790 _hasRecentlyChanged = true;
810 }791 }
811
812 // If we have recently changed, but it's been enough time since we last moved, then we will do a full frustum
813 // hide/show culling pass
814 bool forceFullFrustum = enoughTime && _hasRecentlyChanged;
815
816 // in hide mode, we only track the full frustum culls, because we don't care about the partials.
817 if (forceFullFrustum) {
818 _lastViewCulling = start;
819 _hasRecentlyChanged = false;
820 }
821
822 hideOutOfView(forceFullFrustum);
823 792
824 if (forceFullFrustum) { 793 // If we have recently changed, but it's been enough time since we last moved, then we will do a full frustum
825 uint64_t endViewCulling = usecTimestampNow();794 // hide/show culling pass
826 _lastViewCullingElapsed = (endViewCulling - start) / 1000;795 bool forceFullFrustum = enoughTime && _hasRecentlyChanged;
827 }
828 796
829 } else if (performRemoveOutOfViewLogic) {797 // in hide mode, we only track the full frustum culls, because we don't care about the partials.
830 _lastViewCulling = start;798 if (forceFullFrustum) {
831 removeOutOfView();799 _lastViewCulling = start;
832 uint64_t endViewCulling = usecTimestampNow();800 _hasRecentlyChanged = false;
833 _lastViewCullingElapsed = (endViewCulling - start) / 1000;
834 }
835
836 // Once we call cleanupRemovedVoxels() we do need to rebuild our VBOs (if anything was actually removed). So,
837 // we should consider putting this someplace else... as this might be able to occur less frequently, and save us on
838 // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
839 cleanupRemovedVoxels();
840 }801 }
802
803 hideOutOfView(forceFullFrustum);
804
805 if (forceFullFrustum) {
806 uint64_t endViewCulling = usecTimestampNow();
807 _lastViewCullingElapsed = (endViewCulling - start) / 1000;
808 }
809
810 // Once we call cleanupRemovedVoxels() we do need to rebuild our VBOs (if anything was actually removed). So,
811 // we should consider putting this someplace else... as this might be able to occur less frequently, and save us on
812 // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
813 cleanupRemovedVoxels();
841 814
842 uint64_t sinceLastAudit = (start - _lastAudit) / 1000;815 uint64_t sinceLastAudit = (start - _lastAudit) / 1000;
843 816