虚幻4 笔记

namespace ENamedThreads
{
	CORE_API Type RenderThread = ENamedThreads::GameThread; // defaults to game and is set and reset by the render thread itself
	CORE_API Type RenderThread_Local = ENamedThreads::GameThread_Local; // defaults to game local and is set and reset by the render thread itself
}

渲染线程维护两个队列,一个是主线程发送给渲染线程的RenderThread队列,

还有一个RenderThread_Local队列,使用方法大概类似于这样:

	// We need to do this on the render thread

	FRHICommandList* CmdList = new FRHICommandList;
	CmdList->CopyRenderThreadContexts(RHICmdList);
	FGraphEventRef RenderThreadCompletionEvent = TGraphTask::CreateTask().ConstructAndDispatchWhenReady(*CmdList, GlobalBoundShaderState, FeatureLevel);
	RHICmdList.QueueRenderThreadCommandListSubmit(RenderThreadCompletionEvent, CmdList);

RenderThread_Local队列应该是渲染线程向RHI线程发送CMD的队列,但是目前没有发现RHI线程。。。。。。

在Engine\Source\Runtime\Renderer\Private\DeferredShadingRenderer.cpp文件中,

// The render thread is involved in sending stuff to the RHI, so we will periodically service that queue
static void ServiceLocalQueue()
{
	SCOPE_CYCLE_COUNTER(STAT_FDeferredShadingSceneRenderer_Render_ServiceLocalQueue);
	FTaskGraphInterface::Get().ProcessThreadUntilIdle(ENamedThreads::RenderThread_Local);
}


被Render函数调用,

看来一些代码,应该是只有Metal和D3D12使用到 了RHIThread,具体为何还不知道。

RHI.h文件中找到了这段注释。

/** Whether or not the RHI supports an RHI thread.
Requirements for RHI thread
* Microresources (those in RHIStaticStates.h) need to be able to be created by any thread at any time and be able to work with a radically simplified rhi resource lifecycle. CreateSamplerState, CreateRasterizerState, CreateDepthStencilState, CreateBlendState
* CreateUniformBuffer needs to be threadsafe
* GetRenderQueryResult should be threadsafe, but this isn't required. If it isn't threadsafe, then you need to flush yourself in the RHI
* GetViewportBackBuffer and AdvanceFrameForGetViewportBackBuffer need to be threadsafe and need to support the fact that the render thread has a different concept of "current backbuffer" than the RHI thread. Without an RHIThread this is moot due to the next two items.
* AdvanceFrameForGetViewportBackBuffer needs be added as an RHI method and this needs to work with GetViewportBackBuffer to give the render thread the right back buffer even though many commands relating to the beginning and end of the frame are queued.
* BeginDrawingViewport, and 5 or so other frame advance methods are queued with an RHIThread. Without an RHIThread, these just flush internally.
***/
extern RHI_API bool GRHISupportsRHIThread;





你可能感兴趣的:(虚幻4)