Skip to content

[MiniEngine] Sequential Events in CommandQueue #897

@JayNakum

Description

@JayNakum

In the CommandListManager.cpp there is a TODO that mentions a small optimization regarding sequential events

// TODO: Think about how this might affect a multi-threaded situation. Suppose thread A
// wants to wait for fence 100, then thread B comes along and wants to wait for 99. If
// the fence can only have one event set on completion, then thread B has to wait for
// 100 before it knows 99 is ready. Maybe insert sequential events?

I think I have a solution in mind using std::unordered_map<uint64_t, HANDLE> m_FenceEventMap;

We should be able to remove the m_FenceEventHandle and manage a hashmap with respect to the fence value.
And in CommandQueue::WaitForFence() creating an event will be handled like so

// Create an event for the specified fence value if it doesn't exist
if (m_FenceEventMap.find(FenceValue) == m_FenceEventMap.end()) {
    // Create a new event for the fence value
    HANDLE newEventHandle = CreateEvent(nullptr, false, false, nullptr);
    ASSERT(newEventHandle != NULL);
    m_FenceEventMap[FenceValue] = newEventHandle;
}
// Wait on the event associated with the specified fence value
HANDLE eventHandle = m_FenceEventMap[FenceValue];
m_pFence->SetEventOnCompletion(FenceValue, eventHandle);
WaitForSingleObject(eventHandle, INFINITE);

// Update the last completed fence value
m_LastCompletedFenceValue = FenceValue;

I can raise a PR with the change implemented, but I think this needs to be discussed before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions