@@ -19,7 +19,9 @@ void LatencyFlex::lfx_sleep(uint64_t reflex_frame_id) {
1919 eepy (200000000ULL );
2020 frame_id = 1 ;
2121 needs_reset = false ;
22- ctx->Reset ();
22+
23+ if (ctx)
24+ ctx->Reset ();
2325 }
2426
2527 uint64_t current_timestamp = get_timestamp ();
@@ -33,7 +35,8 @@ void LatencyFlex::lfx_sleep(uint64_t reflex_frame_id) {
3335 mutex.lock ();
3436 auto local_frame_id = lfx_mode == LFXMode::ReflexIDs ? reflex_frame_id : this ->frame_id + 1 ;
3537 // log_event("lfx_get_wait_target", "{}", frame_id);
36- target = ctx->GetWaitTarget (local_frame_id);
38+ if (ctx)
39+ target = ctx->GetWaitTarget (local_frame_id);
3740 mutex.unlock ();
3841
3942 if (target > current_timestamp) {
@@ -55,10 +58,13 @@ void LatencyFlex::lfx_sleep(uint64_t reflex_frame_id) {
5558 timestamp = current_timestamp;
5659 }
5760
61+ spdlog::trace (" LatencyFlex Call Spot: {}" , current_call_spot == CallSpot::SimulationStart ? " SimulationStart" : " SleepCall" );
62+
5863 mutex.lock ();
5964 this ->frame_id ++;
6065 // log_event("lfx_beginframe", "{}", frame_id);
61- ctx->BeginFrame (local_frame_id, target, timestamp);
66+ if (ctx)
67+ ctx->BeginFrame (local_frame_id, target, timestamp);
6268 mutex.unlock ();
6369}
6470
@@ -67,7 +73,8 @@ void LatencyFlex::lfx_end_frame(uint64_t reflex_frame_id) {
6773 mutex.lock ();
6874 auto frame_id = Config::get ().get_latencyflex_mode () == LFXMode::ReflexIDs ? reflex_frame_id : this ->frame_id ;
6975 // log_event("lfx_endframe", "{}", frame_id);
70- ctx->EndFrame (frame_id, current_timestamp, &latency, &frame_time);
76+ if (ctx)
77+ ctx->EndFrame (frame_id, current_timestamp, &latency, &frame_time);
7178 mutex.unlock ();
7279 spdlog::trace (" LFX latency: {}, frame_time: {}, current_timestamp: {}" , latency, frame_time, current_timestamp);
7380}
@@ -112,13 +119,24 @@ void LatencyFlex::set_sleep_mode(SleepMode* sleep_mode) {
112119};
113120
114121void LatencyFlex::sleep () {
115- if (current_call_spot == CallSpot::SleepCall && Config::get ().get_latencyflex_mode () != LFXMode::ReflexIDs)
116- lfx_sleep (INVALID_ID);
122+ if (Config::get ().get_latencyflex_mode () != LFXMode::ReflexIDs) {
123+ last_sleep_framecount = simulation_framecount;
124+
125+ if (current_call_spot == CallSpot::SleepCall)
126+ lfx_sleep (INVALID_ID);
127+ }
117128};
118129
119130void LatencyFlex::set_marker (IUnknown* pDevice, MarkerParams* marker_params) {
120131 switch (marker_params->marker_type ) {
121132 case MarkerType::SIMULATION_START:
133+ simulation_framecount++;
134+
135+ if (last_sleep_framecount + call_spot_switch_threshold < simulation_framecount)
136+ current_call_spot = CallSpot::SimulationStart;
137+ else
138+ current_call_spot = CallSpot::SleepCall;
139+
122140 if (current_call_spot == CallSpot::SimulationStart)
123141 lfx_sleep (marker_params->frame_id );
124142 break ;
0 commit comments