There’s a crash on D3D12 when trying to obtain context from RHICmdList during pass added to Render Graph.
Pass is added in custom Scene View Extension on PostRenderViewFamily_RenderThread call.
It makes impossible to obtain raw pointer to DirectX12 command list through dynamic RHI.
Hinted by error message “There is no active graphics context on this command list. There may be a missing call to SwitchPipeline().” I checked if the SwitchPipeline is called before the pass. It is called but it does nothing since AcivePipelines is already set to Graphics. Both GraphicsContext and ComputeContext are set to nullptr in the FRHICommandList object during the pass.
Example PostRenderViewFamily_RenderThread call which makes the error:
void FReproSceneViewExtension::PostRenderViewFamily_RenderThread(FRDGBuilder& GraphBuilder, FSceneViewFamily& InViewFamily)
{
check(IsInRenderingThread());
auto PassParameters = GraphBuilder.AllocParameters<FRenderTargetParameters>();
PassParameters->RenderTargets[0] = FRenderTargetBinding(InViewFamily.RenderTarget->GetRenderTargetTexture(GraphBuilder), ERenderTargetLoadAction::EClear);
GraphBuilder.AddPass(RDG_EVENT_NAME("Repro_PostRenderViewFamily"), PassParameters, ERDGPassFlags::Raster | ERDGPassFlags::NeverCull, [this, BackBuffer = InViewFamily.RenderTarget->GetRenderTargetTexture()](FRHICommandList& RHICmdList) {
auto& Context = RHICmdList.GetContext();
//used in log so the variable isn't optimized away
UE_LOG(LogTemp, Warning, TEXT("Context %p"), Context.RHIGetNativeCommandBuffer())
});
}