FRHICommandListImmediate& RHICmdList = FRHICommandListExecutor::GetImmediateCommandList();
// Copy BackBuffer into CopiedBackTexture
FTextureRHIRef CopiedBackTexture = this->GetOrCreateTexture(BackBuffer);
RHICmdList.CopyTexture(BackBuffer, CopiedBackTexture, FRHICopyTextureInfo{});
Thanks to the Unified Memory of Apple’s M1/2/3. Now I can have GPU copies BackBuffer into a texture, then read this texture directly by CPU in another thread in order to to avoid stalling render thread.
This approach works and CPU can successfully read texture written by GPU. The only problem now is – The CPU thread must wait for a short moment(e.g. 50ms) after RHICmdList.CopyTexture is executed in render thread. because at that point GPU does not complete executing that command yet. Waiting 50ms is stupid but works.
Now I want to improve this waiting time.
Maybe I can add a fence or event object into the commands buffer?
Or it there some way to access Metal’s commandQueue within UnrealEngine?