stride3d / stride3d/stride

D3D11: UAV not unbound when binding texture SRV when using texture views

Open
#1,026 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Graphics bug
Dominant language
C#
Stars
7.8k
Forks
1.2k
Avg merge
2d 17h
Merged PRs (30d)
49

Description

Release Type: Official Release

Platform(s): Windows DirectX 11

Describe the bug
A texture view create from a parent texture and bound as a UAV wont unbind when binding the parent texture SRV. This can cause the SRV to not be set as the driver can force it to be null due to being bound as an UAV. This is caused by the Stride D3D implementation (see CommandList.SetUnorderedAccessView/UnsetUnorderedAccessView) viewing them as separate UAV resources even though they share the same native DirectX texture resource.

To Reproduce
Easiest is to use the RadiancePrefilteringGGX class, it creates a texture for the output target and binds it as a UAV. If the output is then used as an SRV in the same frame then the binding can fail as the UAV does not get cleared.

Expected behavior
The UAV should be unbound properly if it references the same resource as the SRV that is being bound.

Work around and solution
Resetting the entire command list state prevents the issue as all active resources are unbound.

using (context.PushRenderTargetsAndRestore())
{
    commandList.ClearState();
}

I have looked at potential solutions and I think the only option is to track the stride graphics resource instead of the SharpDX resource. I have tried using this comparison in UnsetUnorderedAccessView (which does solve the issue) if (unorderedAccessViews[slot]?.Resource.NativePointer == view.Resource.NativePointer), unfortunately SharpDX allocates a new object on each call to .Resource which quickly results in it using up all available memory and even if the memory leak can be prevented, an allocation in such a hot spot is most likely unacceptable.

This issue might low priority though as there is a work around available and it's not a very common situation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Stride D3D implementation in CommandList.SetUnorderedAccessView and UnsetUnorderedAccessView, then reproduce the issue through RadiancePrefilteringGGX. Compare how texture views and their parent texture are tracked when a UAV is followed by an SRV binding. Done means the shared native resource is correctly unbound without relying on CommandList.ClearState, and the reported SRV binding failure no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.