Search Issue Tracker
Won't Fix
Won't Fix in 2023.3.X
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 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!
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
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.
Resolution Note (2023.3.X):
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.