AppendStructuredBuffer/ConsumeStructuredBuffer not usable

hi,

I found AppendStructuredBuffer/ConsumeStructuredBuffer not working in UE4.
I searched the code base and it seems nobody is using it.

I’m trying to append some data in a pixel shader, and process it in another compute shader.
A structured buffer with append flag is created to store the appended data.
The code compiles correctly, but doesn’t work as expected. No valid data is poped from consume buffer.

As to the AppendStructuredBuffer/ConsumeStructuredBuffer:

  1. the DX11 provides an interface OMSetRenderTargetsAndUnorderedAccessViews(), and the last parameter is to set the initial counter value. But the code always keep the current counter value

    void FD3D11DynamicRHI::CommitRenderTargetsAndUAVs()
    {
    ID3D11RenderTargetView* RTArray[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
    for(uint32 RenderTargetIndex = 0;RenderTargetIndex < NumSimultaneousRenderTargets;++RenderTargetIndex)
    {
    RTArray[RenderTargetIndex] = CurrentRenderTargets[RenderTargetIndex];
    }
    ID3D11UnorderedAccessView* UAVArray[D3D11_PS_CS_UAV_REGISTER_COUNT];
    uint32 UAVInitialCountArray[D3D11_PS_CS_UAV_REGISTER_COUNT];
    for(uint32 UAVIndex = 0;UAVIndex < NumUAVs;++UAVIndex)
    {
    UAVArray[UAVIndex] = CurrentUAVs[UAVIndex];
    // Using the value that indicates to keep the current UAV counter
    UAVInitialCountArray[UAVIndex] = -1;
    }

     if (NumUAVs > 0)
     {
     	Direct3DDeviceIMContext->OMSetRenderTargetsAndUnorderedAccessViews(
     		NumSimultaneousRenderTargets,
     		RTArray,
     		CurrentDepthStencilTarget,
     		NumSimultaneousRenderTargets,
     		NumUAVs,
     		UAVArray,
     		UAVInitialCountArray
     		);
     }
     else
     {
     	// Use OMSetRenderTargets if there are no UAVs, works around a crash in PIX
     	Direct3DDeviceIMContext->OMSetRenderTargets(
     		NumSimultaneousRenderTargets,
     		RTArray,
     		CurrentDepthStencilTarget
     		);
     }
    

    }

  2. I think this buffer is difficult to use and debug. I cannot get the counter to check whether my buffer capacity is reached or the buffer is empty. I tried using another RWByteAddressBuffer to store the counter, but the interlockedAdd() interface doesn’t support decrement operations. Hard to use, really.

I struggled hours and finally get something work using the RWStructuredBuffer with counter. I changed the code to always set UAV initial counter to zero, and ignored the “capacity reached/buffer empty” issues. So there are still some bugs to fix.

So, any suggestions to handle such requirements? Appreciate your feedback. Thanks.

–TOM

Don’t know if this still helps, when I switch to DX12RHI, I can get data from AppendStructuredBuffer, the engine version is 5.0EA