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!
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
- Generate outline toggle is inactive in the Sprite Editor when only one sprite is selected
- The MustDisposeResource attribute is missing when using the Unity JetBrains.Annotations library subset
- [iOS] Error "RenderPass: Attachment 0 was created with 4 samples but 1 samples were requested. " is thrown when using UIToolkit and URP RenderGraph on iOS device
- The "INSTANCING_ON" shader variant is getting stripped when building the AssetBundle with the shader variant collection and the Instancing Variants set to Strip Unused
- [iOS] Building a project for iOS with 'Launch Screen' set to 'Custom Storyboard' fails if only iPhone storyboard was setup
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.