How to convert from SetRenderTargets API

I’m moving old code into the new 4.22 codebase and encountering this message:

SetRenderTargets API is deprecated; please use RHIBegin/EndRenderPass instead

However, I’ve been unable to find any information on this change or what the implications are. Can anyone point me into the right direction?

Hi,
well this looks like a bit old but as it’s actually badly documented I want to explain how I fixed the issue on my side:
here is my original code:

SetRenderTarget(RHICmdList, renderTargetResource->GetRenderTargetTexture(), FTextureRHIRef(), true);
DrawClearQuad(RHICmdList, FLinearColor(0.0, 0.0, 0.0, 1.0));

that became:

FRHIRenderPassInfo info(renderTargetResource->GetRenderTargetTexture()->GetTexture2D(), ERenderTargetActions::DontLoad_Store);
IRHICommandContext& c = RHICmdList.GetContext();
c.RHIBeginRenderPass(info, TEXT("NameOfMyRenderpass"));
DrawClearQuad(RHICmdList, FLinearColor(0.0, 0.0, 0.0, 1.0));
c.RHIEndRenderPass();

the “begin/EndRenderPass” they are talking about is in the context of the cmdlist (that make a lot more sense IMO). Using a setRenderTarget like that make it looks like you could change the target between commands (which is not possible AFAIK). Additionally you should also pay attention to the new argument “ERenderTargetActions::DontLoad_Store”. There is quite a few modes, this will have an impact on performance or could break your code in some cases.

you can refer to Engine\Plugins\Compositing\LensDistortion\LensDistortionRendering.cpp

Soucre:
FRHIRenderPassInfo RPInfo(OutTextureRenderTargetResource->GetRenderTargetTexture(),
ERenderTargetActions::DontLoad_Store, OutTextureRenderTargetResource->TextureRHI);
RHICmdList.BeginRenderPass(RPInfo, TEXT(“DrawUVDisplacement”));
{


// Draw grid.
uint32 PrimitiveCount = kGridSubdivisionX * kGridSubdivisionY * 2;
RHICmdList.DrawPrimitive(0, PrimitiveCount, 1);
}
RHICmdList.EndRenderPass();