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

Lazy binding for D3D11 #4699

Merged
merged 17 commits into from
Feb 23, 2025
Merged

Lazy binding for D3D11 #4699

merged 17 commits into from
Feb 23, 2025

Conversation

doitsujin
Copy link
Owner

@doitsujin doitsujin commented Feb 19, 2025

Based on #4693 because the DXBC bits would otherwise turn into rebase hell, so that needs to land first. Merged.

TL;DR is that we defer forwarding resource bindings (SetShaderResourceViews and friends) to the backend if:

  • None of the active shaders use the binding, or
  • The app sets a null buffer/view/sampler.

These will instead be applied on the next draw or dispatch that are actually known to use the given binding.

The rationale here is that forwarding unused bindings can confuse the backend a little and lead to descriptor set invalidations even if none of the actually used bindings have changed. As for null bindings, these are very rarely actually used in shaders, and instead we can assume that the app will either bind a non-null resource right after or binds a shader which doesn't use the given binding slot.

At the same time, immediately forwarding currently active binding avoids the extra overhead from tracking everything in well-behaved applications, even if this means that some bindings might be redundant (e.g. app binds a shader that doesn't use it right after, or binds two different resources to the same slot back-to-back).

In practice, this improves CPU-bound performance in God of War somewhat, and in Trine 5 this reduces the number of draw calls by ~50% in the menu because our indirect draw batching can now kick in properly. Almost all games run into this in some capacity, so it should be a nice overall improvement.

@doitsujin doitsujin force-pushed the d3d11-lazy-binding branch 2 times, most recently from 7998c02 to 06e8f50 Compare February 19, 2025 21:18
@doitsujin doitsujin marked this pull request as ready for review February 20, 2025 12:31
@doitsujin doitsujin force-pushed the d3d11-lazy-binding branch 2 times, most recently from 126798b to 02d0894 Compare February 20, 2025 16:45
Moderately cursed because PS UAVs are also available to other graphics
stages.
Some games will unconditionally use a high index for UAVStartSlot.
Repository owner deleted a comment from DanielPopRe Feb 20, 2025
Repository owner deleted a comment from Blisto91 Feb 20, 2025
@doitsujin doitsujin merged commit 20dc389 into master Feb 23, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

1 participant