Vertical sync doesn't work in my application when there is no event in msg loop; it only works when any event(say mouse move event) is present.

峻魁 张 20 Reputation points
2024-05-13T05:02:33.0933333+00:00

This is code in a production environment, which can be simplified roughly as follows.

Screenshot 2024-05-13 130408

Source codes: https://github.com/JunkuiZhang/zed/tree/test/vsync-dx11

// msg loop
// crates/gpui/src/platform/windows/platform.rs
while GetMessageW(&mut msg, None, 0, 0).as_bool() {
    match msg.message {
        WM_QUIT => break,
        ...
        _ => {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }
}

// WM_PAINT
// crates/gpui/src/platform/windows/events.rs
fn handle_paint_msg(...) {
	// draw codes
    if let Some(mut request_frame) = lock.callbacks.request_frame.take() {
        drop(lock);
        request_frame();
        state_ptr.state.borrow_mut().callbacks.request_frame = Some(request_frame);
    }
    return;
}

// draw
context.ClearRenderTargetView(&self.rtv, &[0.7, 0.5, 0.2, 1.0]);
swap_chain.Present(1, 0).ok().unwrap();
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,625 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.