@@ -700,102 +700,75 @@ namespace vrperfkit {
700700	}
701701
702702
703- 	void  D3D11PostProcessor::CreateDynamicProfileQueries () {
704- 		for  (auto  &profileQuery : dynamicProfileQueries) {
705- 			D3D11_QUERY_DESC qd;
706- 			qd.Query  = D3D11_QUERY_TIMESTAMP;
707- 			qd.MiscFlags  = 0 ;
708- 			device->CreateQuery (&qd, profileQuery.queryStart .ReleaseAndGetAddressOf ());
709- 			device->CreateQuery (&qd, profileQuery.queryEnd .ReleaseAndGetAddressOf ());
710- 			qd.Query  = D3D11_QUERY_TIMESTAMP_DISJOINT;
711- 			device->CreateQuery (&qd, profileQuery.queryDisjoint .ReleaseAndGetAddressOf ());
712- 		}
713- 	}
714- 
715703	void  D3D11PostProcessor::StartDynamicProfiling () {
716- 		++DynamicSleepCount ;
717- 		if  (DynamicSleepCount  < g_config.dynamicFramesCheck ) {
704+ 		++dynamicSleepCount ;
705+ 		if  (dynamicSleepCount  < g_config.dynamicFramesCheck ) {
718706			return ;
719707		}
720708
721709		is_DynamicProfiling = true ;
722710
723- 		DynamicSleepCount  = 0 ;
711+ 		dynamicSleepCount  = 0 ;
724712
725- 		if  (dynamicProfileQueries[0 ].queryStart  == nullptr ) {
726- 			CreateDynamicProfileQueries ();
727- 		}
728- 
729- 		context->Begin (dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint .Get ());
730- 		context->End (dynamicProfileQueries[DynamicCurrentQuery].queryStart .Get ());
713+     	GetSystemTimePreciseAsFileTime (&ft);
714+ 		dynamicTimeUs = ft.dwLowDateTime ;
731715	}
732716
733717	void  D3D11PostProcessor::EndDynamicProfiling () {
734718		if  (is_DynamicProfiling) {
735- 			context->End (dynamicProfileQueries[DynamicCurrentQuery].queryEnd .Get ());
736- 			context->End (dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint .Get ());
719+ 			GetSystemTimePreciseAsFileTime (&ft);
720+ 			const  unsigned  int  end = ft.dwLowDateTime ;
721+ 			
722+ 			float  frameTime = (end - dynamicTimeUs) / 10000000 .f ;	//  (1000 * 1000 * 10) FrameTime in seconds
737723
738- 			DynamicCurrentQuery = (DynamicCurrentQuery + 1 ) % DYNAMIC_QUERY_COUNT;
739- 			while  (context->GetData (dynamicProfileQueries[0 ].queryDisjoint .Get (), nullptr , 0 , 0 ) == S_FALSE) {
740- 				Sleep (1 );
741- 			}
742- 			D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint;
743- 			HRESULT result = context->GetData (dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint .Get (), &disjoint, sizeof (disjoint), 0 );
744- 			if  (result == S_OK && !disjoint.Disjoint ) {
745- 				UINT64 begin, end;
746- 				context->GetData (dynamicProfileQueries[DynamicCurrentQuery].queryStart .Get (), &begin, sizeof (UINT64), 0 );
747- 				context->GetData (dynamicProfileQueries[DynamicCurrentQuery].queryEnd .Get (), &end, sizeof (UINT64), 0 );
748- 				float  frameTime = (end - begin) / float (disjoint.Frequency );	//  FrameTime in seconds
749- 
750- 				// LOG_INFO << "frameTime: " << std::setprecision(8) << frameTime;
751- 
752- 				//  HRM
753- 				if  (g_config.hiddenMask .dynamic ) {
754- 					if  (frameTime > g_config.hiddenMask .targetFrameTime ) {
755- 						if  (g_config.hiddenMask .dynamicChangeRadius ) {
756- 							if  ((edgeRadius - g_config.hiddenMask .decreaseRadiusStep ) >= g_config.hiddenMask .minRadius ) {
757- 								edgeRadius -= g_config.hiddenMask .decreaseRadiusStep ;
758- 							}
759- 						} else  {
760- 							hiddenMaskApply = true ;
724+ 			// LOG_INFO << "frameTime: " << std::setprecision(8) << frameTime;
725+ 
726+ 			//  HRM
727+ 			if  (g_config.hiddenMask .dynamic ) {
728+ 				if  (frameTime > g_config.hiddenMask .targetFrameTime ) {
729+ 					if  (g_config.hiddenMask .dynamicChangeRadius ) {
730+ 						if  ((edgeRadius - g_config.hiddenMask .decreaseRadiusStep ) >= g_config.hiddenMask .minRadius ) {
731+ 							edgeRadius -= g_config.hiddenMask .decreaseRadiusStep ;
761732						}
762- 					} else  if  (frameTime < g_config. hiddenMask . marginFrameTime )  {
763- 						if  (g_config. hiddenMask . dynamicChangeRadius ) { 
764- 							 if  ((edgeRadius + g_config. hiddenMask . increaseRadiusStep ) <= g_config. hiddenMask . maxRadius ) { 
765- 								edgeRadius +=  g_config.hiddenMask .increaseRadiusStep ; 
766- 							} 
767- 						}  else  {
768- 							hiddenMaskApply =  false ;
733+ 					} else  {
734+ 						hiddenMaskApply =  true ; 
735+ 					} 
736+ 				}  else   if  (frameTime <  g_config.hiddenMask .marginFrameTime ) { 
737+ 					if  (g_config. hiddenMask . dynamicChangeRadius ) { 
738+ 						if  ((edgeRadius + g_config. hiddenMask . increaseRadiusStep ) <= g_config. hiddenMask . maxRadius )  {
739+ 							edgeRadius += g_config. hiddenMask . increaseRadiusStep ;
769740						}
741+ 					} else  {
742+ 						hiddenMaskApply = false ;
770743					}
771744				}
745+ 			}
772746
773- 				//  FFR
774- 				if  (g_config.ffr .dynamic ) {
775- 					if  (frameTime > g_config.ffr .targetFrameTime ) {
776- 						if  (g_config.ffr .dynamicChangeRadius ) {
777- 							if  ((g_config.ffr .innerRadius  - g_config.ffr .decreaseRadiusStep ) >= g_config.ffr .minRadius ) {
778- 								g_config.ffr .innerRadius  -= g_config.ffr .decreaseRadiusStep ;
779- 								g_config.ffr .midRadius  -= g_config.ffr .decreaseRadiusStep ;
780- 								g_config.ffr .outerRadius  -= g_config.ffr .decreaseRadiusStep ;
781- 								g_config.ffr .radiusChanged [0 ] = true ;
782- 								g_config.ffr .radiusChanged [1 ] = true ;
783- 							}
784- 						} else  {
785- 							g_config.ffr .apply  = true ;
747+ 			//  FFR
748+ 			if  (g_config.ffr .dynamic ) {
749+ 				if  (frameTime > g_config.ffr .targetFrameTime ) {
750+ 					if  (g_config.ffr .dynamicChangeRadius ) {
751+ 						if  ((g_config.ffr .innerRadius  - g_config.ffr .decreaseRadiusStep ) >= g_config.ffr .minRadius ) {
752+ 							g_config.ffr .innerRadius  -= g_config.ffr .decreaseRadiusStep ;
753+ 							g_config.ffr .midRadius  -= g_config.ffr .decreaseRadiusStep ;
754+ 							g_config.ffr .outerRadius  -= g_config.ffr .decreaseRadiusStep ;
755+ 							g_config.ffr .radiusChanged [0 ] = true ;
756+ 							g_config.ffr .radiusChanged [1 ] = true ;
786757						}
787- 					} else  if  (frameTime < g_config. ffr . marginFrameTime )  {
788- 						if  ( g_config.ffr .dynamicChangeRadius ) { 
789- 							 if  ((g_config. ffr . innerRadius  + g_config. ffr . increaseRadiusStep ) <= g_config. ffr . maxRadius ) { 
790- 								g_config. ffr . innerRadius  +=  g_config.ffr .increaseRadiusStep ; 
791- 								g_config. ffr . midRadius  +=  g_config.ffr .increaseRadiusStep ; 
792- 								 g_config.ffr .outerRadius  +=  g_config.ffr .increaseRadiusStep ; 
793- 								 g_config.ffr .radiusChanged [ 0 ] =  true ;
794- 								 g_config.ffr .radiusChanged [ 1 ] =  true ;
795- 							} 
796- 						}  else  { 
797- 							g_config.ffr .apply  = false ;
758+ 					} else  {
759+ 						g_config.ffr .apply  =  true ; 
760+ 					} 
761+ 				}  else   if  (frameTime <  g_config.ffr .marginFrameTime ) { 
762+ 					if  ( g_config.ffr .dynamicChangeRadius ) { 
763+ 						if  (( g_config.ffr .innerRadius  +  g_config.ffr .increaseRadiusStep ) <= g_config. ffr . maxRadius ) { 
764+ 							g_config.ffr .innerRadius  += g_config. ffr . increaseRadiusStep ;
765+ 							g_config.ffr .midRadius  += g_config. ffr . increaseRadiusStep ;
766+ 							g_config. ffr . outerRadius  += g_config. ffr . increaseRadiusStep ; 
767+ 							g_config. ffr . radiusChanged [ 0 ] =  true ; 
768+ 							g_config.ffr .radiusChanged [ 1 ]  = true ;
798769						}
770+ 					} else  {
771+ 						g_config.ffr .apply  = false ;
799772					}
800773				}
801774			}
@@ -805,57 +778,4 @@ namespace vrperfkit {
805778
806779		StartDynamicProfiling ();
807780	}
808- 
809- 
810- /* 
811- 	void D3D11PostProcessor::CreateProfileQueries() { 
812- 		for (auto &profileQuery : profileQueries) { 
813- 			D3D11_QUERY_DESC qd; 
814- 			qd.Query = D3D11_QUERY_TIMESTAMP; 
815- 			qd.MiscFlags = 0; 
816- 			device->CreateQuery(&qd, profileQuery.queryStart.ReleaseAndGetAddressOf()); 
817- 			device->CreateQuery(&qd, profileQuery.queryEnd.ReleaseAndGetAddressOf()); 
818- 			qd.Query = D3D11_QUERY_TIMESTAMP_DISJOINT; 
819- 			device->CreateQuery(&qd, profileQuery.queryDisjoint.ReleaseAndGetAddressOf()); 
820- 		} 
821- 	} 
822- 
823- 	void D3D11PostProcessor::StartProfiling() { 
824- 		if (profileQueries[0].queryStart == nullptr) { 
825- 			CreateProfileQueries(); 
826- 		} 
827- 
828- 		context->Begin(profileQueries[currentQuery].queryDisjoint.Get()); 
829- 		context->End(profileQueries[currentQuery].queryStart.Get()); 
830- 	} 
831- 
832- 	void D3D11PostProcessor::EndProfiling() { 
833- 		context->End(profileQueries[currentQuery].queryEnd.Get()); 
834- 		context->End(profileQueries[currentQuery].queryDisjoint.Get()); 
835- 
836- 		currentQuery = (currentQuery + 1) % QUERY_COUNT; 
837- 		while (context->GetData(profileQueries[currentQuery].queryDisjoint.Get(), nullptr, 0, 0) == S_FALSE) { 
838- 			Sleep(1); 
839- 		} 
840- 		D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint; 
841- 		HRESULT result = context->GetData(profileQueries[currentQuery].queryDisjoint.Get(), &disjoint, sizeof(disjoint), 0); 
842- 		if (result == S_OK && !disjoint.Disjoint) { 
843- 			UINT64 begin, end; 
844- 			context->GetData(profileQueries[currentQuery].queryStart.Get(), &begin, sizeof(UINT64), 0); 
845- 			context->GetData(profileQueries[currentQuery].queryEnd.Get(), &end, sizeof(UINT64), 0); 
846- 			float duration = (end - begin) / float(disjoint.Frequency); 
847- 			summedGpuTime += duration; 
848- 			++countedQueries; 
849- 
850- 			if (countedQueries >= 500) { 
851- 				float avgTimeMs = 1000.f / countedQueries * summedGpuTime; 
852- 				// Queries are done per eye, but we want the average for both eyes per frame 
853- 				avgTimeMs *= 2; 
854- 				LOG_INFO << "Average GPU processing time for post-processing: " << avgTimeMs << " ms"; 
855- 				countedQueries = 0; 
856- 				summedGpuTime = 0.f; 
857- 			} 
858- 		} 
859- 	} 
860- */ 
861781}
0 commit comments