Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

[d3d9] Added functionality to empty WaitForVBlank function.#2925

Open
kdobrowo wants to merge 1 commit intodoitsujin:masterfrom
kdobrowo:tasks/Task-389-DXVK-WLK-tests-waitvbl
Open

[d3d9] Added functionality to empty WaitForVBlank function.#2925
kdobrowo wants to merge 1 commit intodoitsujin:masterfrom
kdobrowo:tasks/Task-389-DXVK-WLK-tests-waitvbl

Conversation

Copy link
Contributor

kdobrowo commented Sep 15, 2022

No description provided.

Copy link
Contributor Author

kdobrowo commented Sep 15, 2022

This code change fixes WaitForVbl WHQL test (d3d9).

Copy link
Collaborator

misyltoad commented Sep 15, 2022

I imagine it is due to the test being broken that it fixes the test?

It is not possible for us to implement this properly without present timing maybe (or doing something hacky with present wait).

Copy link
Contributor Author

kdobrowo commented Sep 15, 2022

The test:

  1. calls present
  2. calls WaitForVBlank which should "Suspend execution of the calling thread until the next vertical blank signal." (https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-waitforvblank)
  3. measures time between presents

This is why SyncFrameLatency was added there.

Isn't it good enough solution?

Copy link
Collaborator

misyltoad commented Sep 15, 2022 *
edited
Loading

No for two reasons:

  • Our frame latency implementation does not use present wait right now. (It is triggered on the present thread when we call queuepresent, not on vblank or TTL)
  • The call you are using waits for up to the Max frame latency, not 1.

Copy link
Owner

doitsujin commented Sep 15, 2022 *
edited
Loading

If the docs are anything to go by, this function doesn't really interact with presents anyway, so even present_wait wouldn't really help. We can't really implement this correctly.

The main problem with this particular implementation is that we'll return immediately if

  • the app is CPU-bound
  • there is any sort of GPU->CPU sync point between frames (e.g. occlusion queries)
  • no presents are queued between calls

I think there's a way to come somewhat close to expected behaviour if we store a CPU-side timer somewhere and do something like this (pseudocode):

auto now = dxvk::high_resolution_clock::now();
auto refreshPeriod = getDisplayRefreshPeriod();
auto vblankCount = (now - m_startTime) / refreshPeriod;
auto target = m_startTime + (vblankCount + 1) * refreshPeriod;
sleep_until(target);

This is going to need some preliminary work though, and may behave weirdly in VRR scenarios.

Copy link
Owner

doitsujin commented Sep 15, 2022 *
edited
Loading

I made a proof-of-concept implementation in this branch, this can be ported to d3d9 fairly easily.

Copy link
Collaborator

Blisto91 commented Mar 9, 2023

@kdobrowo Friendly ping. What is the status of this?

doitsujin force-pushed the master branch from c860fda to 990c7f5 Compare October 17, 2024 12:27
Blisto91 added the d3d9 label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants