Write to a UAV from pixel shader?

Hello,

I’ve been trying to write to a UAV from a pixel shader but could not find such a thing anywhere in the engine. Even in “ShaderParameterUtils.h”, it looks like UAVs can only be binded to compute shaders.
Is there a reason for this? My first assumption was backwards compatibility for older cards that don’t support older shading models but I’ve seen instances in the engine where a specific feature would check if a card is compatible before using the feature…

Please advise…
Thank you,

Check DistanceFieldSurfaceCacheLighting.cpp, there are some working examples

Set UAVs as output

TArray<FUnorderedAccessViewRHIParamRef> UAVs;
PixelShader->GetUAVs(Views[0], UAVs);
RHICmdList.SetRenderTargets(0, (const FRHIRenderTargetView*)NULL, NULL, UAVs.Num(), UAVs.GetData());

UAV shader parameters C++

FRWShaderParameter TileHeadDataUnpacked;
FRWShaderParameter TileArrayData;

UAV in usf

RWBuffer<uint> RWTileHeadDataUnpacked;

Aaah, I see!
Thanks a lot for your answer.

@davids190 Where you able to implement this?
@DanielW Could you please expand on how to implement this?

I am trying to do the same thing but I am unable to figure out how to do it. Any help would be highly appreciated.

I think it has changed since then, take a look at how i bind my uavs here on line 1474:
https://github.com/kostenickj/UnrealEngine/blob/420_3_OIT_Main/Engine/Source/Runtime/Renderer/Private/PostProcess/SceneRenderTargets.cpp

the function is void FSceneRenderTargets::SetKBufferUAVs
look at where that function is called from and how the output is used.

To see how the uavs are accessed in the shader look in
https://github.com/kostenickj/UnrealEngine/blob/420_3_OIT_Main/Engine/Shaders/Private/OITPPLL/PPLLCommon.ush

bind to slots specifically with u1, u2 etc.

The actual binding is handled in basepassrendering.h. Just search for OIT in that file and use defines to compile them out when you dont need them.

I just consider how to set RWStructuredBuffer in pixel shader under D3D11, it seems that unreal doesn’t provide us a convenient function in the RHICommandList. your code made me know how to do it, thank u very much!