Unreal 엔진
[UE] 언리얼 엔진 DirectX 11 RHI 렌더링 분석 노트
원소랑
2023. 9. 12. 15:25
DirectX SDK API 핵심 요소를 언리얼엔진의 어떤 모듈에서 호출하는지 구조 살펴보기.
<ID3D11DynamicRHI.h>
...
typedef ID3D11DeviceContext FD3D11DeviceContext;
typedef ID3D11Device FD3D11Device;
struct ID3D11DynamicRHI { ... }
...
<D3D11RHIPrivate.h>
class FD3D11DynamicRHI : public ID3D11DynamicRHI, public IRHICommandContextPSOFallback
{
...
TRefCountPtr<FD3D11DeviceContext> Direct3DDeviceIMContext;
TRefCountPtr<FD3D11Device> Direct3DDevice;
TArray<FD3D11Viewport*> Viewports;
...
}
FD3D11DynamicRHI::InitD3DDevice()
{
...
if (!bDeviceCreated)
{
UE_LOG(LogD3D11RHI, Log, TEXT("Creating D3DDevice using adapter:"));
LogDXGIAdapterDesc(Adapter.DXGIAdapterDesc);
// Creating the Direct3D device.
VERIFYD3D11RESULT(D3D11CreateDevice(
Adapter.DXGIAdapter,
DriverType,
NULL,
DeviceFlags,
&FeatureLevel,
1,
D3D11_SDK_VERSION,
Direct3DDevice.GetInitReference(),
&ActualFeatureLevel,
Direct3DDeviceIMContext.GetInitReference()
));
}
...
}
FD3D11Viewport::FD3D11Viewport(...)
{
...
// Ensure that the D3D device has been created.
D3DRHI->InitD3DDevice();
...
}
// RenderTargetView, Viewport 생성
// Viewport 는 생성자에서 FD3D11DynamicRHI::Viewports 에 추가됨.
FViewportRHIRef FD3D11DynamicRHI::RHICreateViewport(void* WindowHandle,uint32 SizeX,uint32 SizeY,bool bIsFullscreen,EPixelFormat PreferredPixelFormat)
{
...
return new FD3D11Viewport(this,(HWND)WindowHandle,SizeX,SizeY,bIsFullscreen,PreferredPixelFormat);
}
FORCEINLINE FViewportRHIRef RHICreateViewport(void* WindowHandle, uint32 SizeX, uint32 SizeY, bool bIsFullscreen, EPixelFormat PreferredPixelFormat)
{
return GDynamicRHI->RHICreateViewport(WindowHandle, SizeX, SizeY, bIsFullscreen, PreferredPixelFormat);
}
// FViewport::InitRHI 에서 Viewport 생성 및 디바이스 초기화 처리.
void FViewport::InitRHI()
{
FlushRenderingCommands();
if(!IsValidRef(ViewportRHI))
{
ViewportRHI = RHICreateViewport(
GetWindow(),
SizeX,
SizeY,
IsFullscreen(),
EPixelFormat::PF_Unknown
);
UpdateRenderTargetSurfaceRHIToCurrentBackBuffer();
}
}
class ENGINE_API FSceneViewport : public FViewportFrame, public FViewport ...
{ ... }
FSceneViewport* UGameViewportClient::CreateGameViewport(TSharedPtr<SViewport> InViewportWidget)
{
return new FSceneViewport(this, InViewportWidget);
}
void UGameEngine::CreateGameViewport( UGameViewportClient* GameViewportClient )
{
...
SceneViewport = MakeShareable( GameViewportClient->CreateGameViewport(GameViewportWidgetRef) );
GameViewportClient->Viewport = SceneViewport.Get();
...
}
void UGameEngine::Init(IEngineLoop* InEngineLoop)
{
...
CreateGameViewport( ViewportClient );
...
}
FViewport::InitRHI() 메소드에서 RHICreateViewport() 호출. FD3D11DynamicRHI::RHICreateViewport 에서 FD3D11Viewport 를 생성. FD3D11Viewport 생성자에서 Device 초기화.
참조 : https://blog.naver.com/sorang226/223163474120
<리얼-타임 렌더링(REAL-TIME RENDERING) 4/e> 구입 링크
https://link.coupang.com/a/8VWas
<DirectX 12를 이용한 3D 게임 프로그래밍 입문> 구입 링크
https://link.coupang.com/a/8V4Wq
유니티 에셋 스토어 링크
https://assetstore.unity.com?aid=1011lvz7h
(링크를 통해 도서/에셋 구입시 일정액의 수수료를 지급받습니다.)
728x90
반응형