Possible Duplicate Stencil Clear

I think I may have found a duplicate stencil buffer clear call.

PostProcessDeferredDecals.cpp, around line 773:

// we don't modify stencil but if out input was having stencil for us (after base pass - we need to clear)
// Clear stencil to 0, which is the assumed default by other passes
RHICmdList.Clear(false, FLinearColor::White, false, (float)ERHIZBuffer::FarPlane, true, 0, FIntRect());

DeferredShadingRenderer.cpp, around line 1254:

// Clear stencil to 0 now that deferred decals are done using what was setup in the base pass
// Shadow passes and other users of stencil assume it is cleared to 0 going in
RHICmdList.SetRenderTargetsAndClear(Info);

If I’m not mistaken, the PostProcessDeferredDecals clear occurs just before the DeferredShadingRenderer clear, making the earlier clear unnecessary. Does that seem correct, or am I missing something?

Hi Aaron, I think your summary is correct. The second stencil clear is redundant if we’re rendering decals because the decal passes clear the stencil at the end of each pass if required anyway.

It may be that we still need to clear the stencil if we aren’t rendering decals for some reason, but certainly if decals are being rendered, there’s no point in clearing again.

I’ve raised bug UE-32759 to investigate this further.