I'm experimenting with ComputeSharp (https://github.com/apothecarius/ComputeSharpTestbed) and am trying to control flow by using Barriers:
ReadWriteBuffer<int> bufferA;
ReadWriteBuffer<int> bufferB;
ReadWriteBuffer<bool> bufferC;
using (ComputeContext ctx = GraphicsDevice.GetDefault().CreateComputeContext())
{
bufferA = ctx.GraphicsDevice.AllocateReadWriteBuffer<int>(quarterOfNums*4);
bufferB = ctx.GraphicsDevice.AllocateReadWriteBuffer<int>(quarterOfNums);
bufferC = ctx.GraphicsDevice.AllocateReadWriteBuffer<bool>(quarterOfNums);
ctx.For(quarterOfNums*4,new SetterKernel1(bufferA));
ctx.Barrier(bufferA);
ctx.For(quarterOfNums*4,new MultiplierKernel2(bufferA));
ctx.Barrier(bufferA);
ctx.For(quarterOfNums*4,new AddThreadIdKernel3(bufferA));
ctx.Barrier(bufferA);
ctx.For(quarterOfNums,new CollectFourKernel4(bufferA,bufferB));
ctx.Barrier(bufferA);
ctx.Barrier(bufferB);
ctx.For(quarterOfNums,new VerificationKernel5(bufferB,bufferC));
ctx.Barrier(bufferC);
}
bool[] downloadedResults = new bool[quarterOfNums];
bufferC.CopyTo(downloadedResults);
trues = downloadedResults.Count(x => x);
Basically it goes through 3 buffers and 5 computing kernels and it should write only true into the final buffer. But the count of "true" in it is not stable from one execution to another. It appears that the barriers are not having an effect.
Am I using Barriers correctly? I cannot find it mentioned in the wiki and in the samples they seem to be used similarly. The samples use [AutoConstructor] decorators extensively, but I can't deduce whether they hide some special effects.
I'm experimenting with ComputeSharp (https://github.com/apothecarius/ComputeSharpTestbed) and am trying to control flow by using Barriers:
Basically it goes through 3 buffers and 5 computing kernels and it should write only true into the final buffer. But the count of "true" in it is not stable from one execution to another. It appears that the barriers are not having an effect.
Am I using Barriers correctly? I cannot find it mentioned in the wiki and in the samples they seem to be used similarly. The samples use [AutoConstructor] decorators extensively, but I can't deduce whether they hide some special effects.