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
592592 }
593593
594594 int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
595+ bool showTimingDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
596+ PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData()",showTimingDetails);
595597
596598 unsigned char command = *sourceBuffer;
597599 int numBytesPacketHeader = numBytesForPacketHeader(sourceBuffer);
598600 switch(command) {
599601 case PACKET_TYPE_VOXEL_DATA: {
600− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
601− "readBitstreamToTree()");
602−
602+ PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData() PACKET_TYPE_VOXEL_DATA part...",showTimingDetails);
603+
603604 unsigned char* dataAt = sourceBuffer + numBytesPacketHeader;
604605
605606 VOXEL_PACKET_FLAGS flags = (*(VOXEL_PACKET_FLAGS*)(dataAt));
@@ -641,7 +642,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 35 unmodified lines
641642 VoxelPacketData packetData(packetIsCompressed);
642643 packetData.loadFinalizedContent(dataAt, sectionLength);
643644 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"
645647 " subsection:%d sectionLength:%d uncompressed:%d\n",
646648 debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
647649 sequence, flightTime, numBytes, dataBytes, subsection, sectionLength, packetData.getUncompressedSize());
@@ -657,12 +659,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 9 unmodified lines
657659 }
658660 break;
659661 }
660−
661−
662662 if (!_useFastVoxelPipeline || _writeRenderFullVBO) {
663663 setupNewVoxelsForDrawing();
664664 } else {
665− checkForCulling();
666665 setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);
667666 }
668667
@@ -689,8 +688,6 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 20 unmodified lines
689688
690689 _inSetupNewVoxelsForDrawing = true;
691690
692− checkForCulling(); // check for out of view and deleted voxels...
693−
694691 bool didWriteFullVBO = _writeRenderFullVBO;
695692 if (_tree->isDirty()) {
696693 static char buffer[64] = { 0 };
@@ -776,68 +773,44 @@ void VoxelSystem::checkForCulling() { · 79 unmodified lines
776773
777774 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()");
778775 uint64_t start = usecTimestampNow();
779− uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
780776
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;
785777
786− // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view
787− if (constantCulling || (
788− (sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
789− && !isViewChanging()
790− )
791− ) {
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;
778+ // track how long its been since we were last moving. If we have recently moved then only use delta frustums, if
779+ // it's been a long time since we last moved, then go ahead and do a full frustum cull.
780+ if (isViewChanging()) {
781+ _lastViewIsChanging = start;
782+ }
783+ uint64_t sinceLastMoving = (start - _lastViewIsChanging) / 1000;
803784
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));
805786
806− // 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
808− if (hasViewChanged()) {
809− _hasRecentlyChanged = true;
810− }
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);
787+ // These has changed events will occur before we stop. So we need to remember this for when we finally have stopped
788+ // moving long enough to be enoughTime
789+ if (hasViewChanged()) {
790+ _hasRecentlyChanged = true;
791+ }
823792
824− if (forceFullFrustum) {
825− uint64_t endViewCulling = usecTimestampNow();
826− _lastViewCullingElapsed = (endViewCulling - start) / 1000;
827− }
793+ // If we have recently changed, but it's been enough time since we last moved, then we will do a full frustum
794+ // hide/show culling pass
795+ bool forceFullFrustum = enoughTime && _hasRecentlyChanged;
828796
829− } else if (performRemoveOutOfViewLogic) {
830− _lastViewCulling = start;
831− removeOutOfView();
832− uint64_t endViewCulling = usecTimestampNow();
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();
797+ // in hide mode, we only track the full frustum culls, because we don't care about the partials.
798+ if (forceFullFrustum) {
799+ _lastViewCulling = start;
800+ _hasRecentlyChanged = false;
840801 }
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();
841814
842815 uint64_t sinceLastAudit = (start - _lastAudit) / 1000;
843816