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

[MiniEngine] Sequential Events in CommandQueue #897

Open
JayNakum opened this issue Dec 16, 2024 · 1 comment
Open

[MiniEngine] Sequential Events in CommandQueue #897

JayNakum opened this issue Dec 16, 2024 · 1 comment

Comments

@JayNakum
Copy link

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.

@GameDreamByHuo
Copy link

GameDreamByHuo commented Dec 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants