Search Issue Tracker

Won't Fix

Votes

0

Found in

2023.2.0a16

2023.3.0a3

Issue ID

UUM-35652

Regression

No

Cannot bind same structured buffer to 2 fragment shaders in Windows Editor

--

-

h2. Reproduction Steps
* Open repro-project [https://github.com/Wilfrid-Unity/test-unity-structuredbuffers-in-fragmentshaders] in Unity Windows Editor
* Open SampleScene
* Rename mentions of "UNITY_EDITOR" in the 2 scripts, to something like "UNITY_EDITOR_DISABLED_CODE"
* Press "Play"

h2. Expected Outcome

In Windows Editor, the same GraphicsBuffer can be bound to two different shader fragment (one "write" pass, one "read" pass).

 

As a result, the quad on the right can use data from the structured buffer written during rendering of the quad on the left:

!image-2023-05-15-16-21-27-377.png!
h2.  
h2. Actual Outcome

In Windows Editor, the same GraphicsBuffer cannot be bound to two different shader fragments, when the quad on the right tries to read from the StructuredBuffer, it only gets (0,0,0) values (or debug colors in DX12 Editor):

!image-2023-05-15-16-24-41-541.png!
h2.  
h2. Additional Information
 
h3. Specs
 
[GraphicsFence manual page|https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rendering.GraphicsFence.html] says:
You don't need to use a graphics fence to synchronise a GPU task writing to a resource and another GPU task reading the resource.
Unity handles these resource dependencies automatically.
 
So this case should work, according to our documentation.
 
h3. Results on Other platforms

This case works on other platform that I tested (Nitendo Switch), using only a single buffer and no GPU copy (I verified in graphics debugger that the correct GPU barriers were inserted between the "write" and "read" draws):

!image-2023-05-15-16-28-33-761.png!

 

 

 

  1. Resolution Note:

    The issue is due to incorrect usage of the Unity C# API. The primary way to bind and unbind UAVs is via Graphics.SetRandomWriteTarget() and Graphics.ClearRandomWriteTargets() but for some reason on Switch the UAVs can also be set implicitly by calling Material.SetBuffer(). Relying on the implicit binding of UAVs is not in accordance with Unity C# API design.

Add comment

Log in to post comment