Advertisement
_Dunno_

Untitled

Aug 22nd, 2024 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. public class RaceConditionTest : MonoBehaviour
  2. {
  3.     [SerializeField] private ComputeShader _shader;
  4.     private ComputeBuffer _firstInput;
  5.     private ComputeBuffer _secondInput;
  6.     private ComputeBuffer _output;
  7.  
  8.     private void Start()
  9.     {
  10.         _firstInput = new ComputeBuffer(1, sizeof(int));
  11.         _secondInput = new ComputeBuffer(1, sizeof(int));
  12.         _output = new ComputeBuffer(1, sizeof(int));
  13.         _firstInput.SetData(new[] { 1 });
  14.         _secondInput.SetData(new[] { 2 });
  15.         _shader.SetBuffer(0, "Output", _output);
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         _shader.SetBuffer(0, "Input", _firstInput);
  21.         _shader.Dispatch(0, 1, 1, 1);
  22.        
  23.         _shader.SetBuffer(0, "Input", _secondInput);
  24.         _shader.Dispatch(0, 1, 1, 1);
  25.  
  26.         _output.PrintInt("Output = ");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement