Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marky update loop event handling #1860

Open
wants to merge 10 commits into
base: openxr-experimental
Choose a base branch
from

Conversation

MarkY-LunarG
Copy link
Contributor

No description provided.

Update the logic to skip the unknown event type (which is not valid)
and also use the MAX enum value so it never gets actually hit.
Update the "received_events_" variable to the name of
"previously_received_unhandled_events_" to be clearer.
Update how many events are stripped from the list of previously
received events from 100 to 300 so that we don't keep hitting it as often.
Add the initial framework for tracking events and behaving
differently for different events.
If we fail to encounter an event during a loop, reduce the future
time we wait for it.  But, only if we allow the reduction of that.
Assert on a missed event if we're supposed to, but not if we're
ok with missing the event.
Add some clearer comments and log messages.
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 292992.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5266 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 293015.

We don't want to increase the sleep time.  That would mean we wait
longer than we want for previously missed events.  Only reduce the
retry limit so we don't get the longer sleep times.
@MarkY-LunarG MarkY-LunarG added the openxr-experimental Related to OpenXR experimental support label Nov 1, 2024
@MarkY-LunarG MarkY-LunarG force-pushed the marky-update-loop-event-handling branch from b370cc6 to 0e7d890 Compare November 1, 2024 21:12
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 293060.

@MarkY-LunarG
Copy link
Contributor Author

Accidentally included a submodule update in last run. Fixed.

Copy link
Contributor

@jzulauf-lunarg jzulauf-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer, a couple nits, a functional question, and a storage question or two.

external/Vulkan-Headers Outdated Show resolved Hide resolved
@@ -826,15 +848,15 @@ void OpenXrReplayConsumerBase::Process_xrPollEvent(const ApiCallInfo&
XrEventDataBuffer* capture_event = eventData->GetPointer();

// We received events that haven't been handled yet already, so see if this one is in the list already
for (size_t ii = 0; ii < received_events_.size(); ++ii)
for (size_t ii = 0; ii < previously_received_unhandled_events_.size(); ++ii)
Copy link
Contributor

@jzulauf-lunarg jzulauf-lunarg Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that size and [] are O(1) for std::deque. The erase will be O(n) since you are potentially shuffling within the blocks that.

Linked list std::list would be O(1) per-item inserted/deleted for insert/delete as is size (since '11), but you'd need to use iterators in the for loop.

{
GFXRECON_LOG_WARNING("Previously received event %s (0x%x, %u)",
GFXRECON_LOG_WARNING("Previously received unhandled event %s (0x%x, %u)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO "Using previously received event of type ..." ?

// If we have not previously started tracking the event behavior for this event type, start tracking it.
if (event_behavior_tracking_.find(capture_event->type) == event_behavior_tracking_.end())
{
event_behavior_tracking_[capture_event->type] = EventBehaviorTracking();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::unordered_map::operator[] automatically inserts a default initialized entry, when key is not found. So this block is unneeded.

What would be useful instead is a reference EventBehaviorTracking &behavior_tracking = event_behavior_tracking_[capture_event->type] given that '[]' is best O(1) is worst case O(n). and that same dereference is done many times below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that about the initialize. Thanks.

uint32_t current_reduction = event_behavior_tracking_[capture_event->type].current_timeout_reduction;
if (current_reduction >= retry_limit)
{
retry_limit = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be one, or we won't even look for the event once. We're not going to drop anything, as we save anything other that we get in previously_received_unhandled_events_ (unless we think there's going to be a storm of missing events)

received_events_.push_back(*out_eventData);
// If this was a valid event, but not the one we're interested in, record
// it to a list of received events for us to use later.
previously_received_unhandled_events_.push_back(*out_eventData);
GFXRECON_LOG_WARNING("Recording event for later %s (0x%x, %u)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO

// events to make room for more without bloating the list size.
// TODO: Perhaps do this more elegantly?
if (received_events_.size() > 1000)
if (previously_received_unhandled_events_.size() > 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 and 300 should be const statics of the ReplayConsumer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe like 5000, and 500?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to constants. And I set them to 2000 and 500. I don't like it to get too big because they are large structures.

@@ -484,7 +484,7 @@ class OpenXrReplayConsumerBase : public OpenXrConsumer

VulkanReplayConsumerBase* vulkan_replay_consumer_ = nullptr;

std::vector<XrEventDataBuffer> received_events_;
std::deque<XrEventDataBuffer> previously_received_unhandled_events_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XrEvenDataBuffer are large, and maybe shuffled. Do we want to store a unique_ptr to them instead (or use std::list to ensure no shuffling occurs)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a list now based on your suggestion.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5270 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5270 passed.

Copy link
Contributor

@jzulauf-lunarg jzulauf-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more little nit.

{
// Do we allow the event to waited on less and less each time we fail to
// properly receive the event?
bool allow_timeout_reduction{ true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better packing int, bool, bool

Decoded_XrSessionCreateInfo* decoded_info = createInfo->GetMetaStructPointer();
SessionData& session_data = AddSessionData(*session->GetPointer());
Decoded_XrSessionCreateInfo* decoded_info = createInfo->GetMetaStructPointer();
SessionData& session_data = AddSessionData(*session->GetPointer());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional white space change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I reverted this. My clang changed it. I'll revert again.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 295086.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5284 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 5284 passed.

Copy link
Contributor

@jzulauf-lunarg jzulauf-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openxr-experimental Related to OpenXR experimental support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants