I have a RWStructuredBuffer that I'm writing to with InterlockedAdd, and it appears that the value its spitting out for original is correct, but once the shader finishes running the buffer fully resets to 0. I have a different InterlockedAdd that's running properly.
After execution _labelCount[0] is the expected value, but _labelSizeBuffer is filled entirely with either -1 or 0.
cbuffer _ : register(b0)
{
uint __x;
uint __y;
uint __z;
int _filterSize;
}
RWTexture2D<int> _clusterIdBuffer : register(u0);
RWStructuredBuffer<int> _labelSizeBuffer : register(u1);
RWStructuredBuffer<int> _labelCount : register(u2);
[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]
void Execute(uint3 ThreadIds : SV_DispatchThreadID)
{
if (ThreadIds.x < __x && ThreadIds.y < __y && ThreadIds.z < __z)
{
int og;
int2 xy = ThreadIds.xy;
int2 dispatch = int2(__x, __y);
int i = xy.y * dispatch.x + xy.x;
int id = _clusterIdBuffer[xy];
if (id == -1)
{
_labelSizeBuffer[i] = -1;
return;
}
InterlockedAdd(_labelSizeBuffer[id], 1, og);
if (og == _filterSize - 1)
{
InterlockedAdd(_labelCount[0], 1);
}
}
}