Game Engine Gems 1Chap 10.Camera-Centric Engine Designfor Multithreaded Renderingohyecloudy http://ohyecloudy.comshader ca...
Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFut...
frameMain      Sim                          Shadow   Reflect   Main    Post-thread   Update                         Maps  ...
frameMain      Sim                          Shadow   Reflect   Main    Post-thread   Update                         Maps  ...
frameMain      Sim                        Shadow   Reflect   Main    Post-thread   Update                       Maps     M...
Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFut...
• 그리기 명령을 수행하는데 필요한 정보  – device level• rendering API 내부에 존재  – API를 호출하면 버퍼를 채움  – CPU 사용
• command buffer를 추상화  – multithread로 command buffer를 채울 수 있게  – device 독립• DX9  – multithread command buffer 불가능  – devic...
Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFut...
struct RenderCommand {        ResourceHandle   VertexBufferHandle;        uint32           VertexDeclEnumIndex;        uin...
void RenderObject::fillCommandBuffer (RenderCommand *RC){       ThreadAssert(ThreadPoolThread);      if (ObjectType == kTy...
void RenderObject::fillCommandBuffer (RenderCommand *RC){       ThreadAssert(ThreadPoolThread);              렌더링 리소스 수명을 제...
void RenderObject::fillCommandBuffer (RenderCommand *RC){            RenderObject 상태를 단지 읽기만 한다.       ThreadAssert(Thread...
void renderControl::executeDrawCommandDx9 (const RenderCommand *params){        ThreadAssert(DeviceOwningThread);        c...
Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFut...
• load balancing 필요  – command buffer 채우는 작업을 할당  – thread 별로 어떻게 할당?• 최종 장면이 나오기 전까지 여러 장면을 렌더링  – shadow map, reflection...
• camera 단위  – command buffer 생성을 쪼갠다.• draw call 묶기  – API 호출에 따른 오버헤드 최소화  – render state 변경 최소화  – batch
frame                                                 SubmitMain      Sim                                                 ...
struct Camera {        Float3 at, up, right;        float   aspectRatio;};struct RenderView {        Camera               ...
void renderControl::CreateRenderViews(){         List<RenderView *>          currentViews;         for (int i = 0; i < mCa...
void renderControl::procThreadedFillRenderView (       void *DataPacket) {      RenderView *currView = (RenderView *)DataP...
void renderControl::serializeRenderView (List<RenderView *> Views) {    for (int viewType = 0; viewType < Count; ++viewTyp...
Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFut...
• Sorting and Instancing  – material index, vertex data, object type…  – instancing command    • draw command 여러 개를• Bette...
[GEG1] 10.camera-centric engine design for multithreaded rendering
[GEG1] 10.camera-centric engine design for multithreaded rendering
Upcoming SlideShare
Loading in...5
×

[GEG1] 10.camera-centric engine design for multithreaded rendering

1,939

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,939
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[GEG1] 10.camera-centric engine design for multithreaded rendering

  1. 1. Game Engine Gems 1Chap 10.Camera-Centric Engine Designfor Multithreaded Renderingohyecloudy http://ohyecloudy.comshader café http://cafe.naver.com/shader 2011.04.11
  2. 2. Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFuture Work
  3. 3. frameMain Sim Shadow Reflect Main Post-thread Update Maps Maps View Process Anim Particle Physics UpdateThread UpdatePool
  4. 4. frameMain Sim Shadow Reflect Main Post-thread Update Maps Maps View Process Anim Particle Rendering API를 Physics Update Update 호출할 필요가 없는 작업만ThreadPool multithread
  5. 5. frameMain Sim Shadow Reflect Main Post-thread Update Maps Maps View Process Stage 별로 그룹화 Anim 각Physics Particle 직접 device call 스테이지에서 UpdateThread UpdatePool 그래서 device를 소유하는 thread에서 대부분 일을 처리
  6. 6. Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFuture Work
  7. 7. • 그리기 명령을 수행하는데 필요한 정보 – device level• rendering API 내부에 존재 – API를 호출하면 버퍼를 채움 – CPU 사용
  8. 8. • command buffer를 추상화 – multithread로 command buffer를 채울 수 있게 – device 독립• DX9 – multithread command buffer 불가능 – device를 소유한 thread에서만 API call – multithread를 지원 옵션이 있긴 있다 • 모든 call에 베타제어 • 성능 저하가 심함 • 제외
  9. 9. Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFuture Work
  10. 10. struct RenderCommand { ResourceHandle VertexBufferHandle; uint32 VertexDeclEnumIndex; uint32 NumTriangles; uint32 NumVerts; enum PrimType { kTriList, kTriStrip }; PrimType PrimitiveType; RenderCommand enum BlendType { kBlend_None, 드로우 콜 단위 kBlend_Standard, kBlend_Additive, kBlend_Subtractive }; BlendType BlendType; // and so on…};
  11. 11. void RenderObject::fillCommandBuffer (RenderCommand *RC){ ThreadAssert(ThreadPoolThread); if (ObjectType == kTypeOpaqueMesh) { RC->VertexBufferHandle = mVBHandle; RC->VertexDeclEnumIndex = kVD_Mesh; RC->PrimitiveType = kTriList; RC->BlendType = kBlend_None; RC->NumTriangles = numTrisFromPrimType(); RC->NumVerts = mNumVerts; } else if (ObjectType == kTypeTransparentMesh) { // and so on… }}
  12. 12. void RenderObject::fillCommandBuffer (RenderCommand *RC){ ThreadAssert(ThreadPoolThread); 렌더링 리소스 수명을 제어하는 객체 오브젝트 하나가 if (ObjectType == kTypeOpaqueMesh) 여러 개 RenderCommand를 만들 수 있음 { RC->VertexBufferHandle = mVBHandle; character, RC->VertexDeclEnumIndex = kVD_Mesh; terrain, RC->PrimitiveType = kTriList; … RC->BlendType = kBlend_None; RC->NumTriangles = numTrisFromPrimType(); RC->NumVerts = mNumVerts; } else if (ObjectType == kTypeTransparentMesh) { // and so on… }}
  13. 13. void RenderObject::fillCommandBuffer (RenderCommand *RC){ RenderObject 상태를 단지 읽기만 한다. ThreadAssert(ThreadPoolThread); thread safe if (ObjectType == kTypeOpaqueMesh) { RC->VertexBufferHandle = mVBHandle; RC->VertexDeclEnumIndex = kVD_Mesh; RC->PrimitiveType = kTriList; RC->BlendType = kBlend_None; RC->NumTriangles = numTrisFromPrimType(); RC->NumVerts = mNumVerts; } else if (ObjectType == kTypeTransparentMesh) { // and so on… }}
  14. 14. void renderControl::executeDrawCommandDx9 (const RenderCommand *params){ ThreadAssert(DeviceOwningThread); const VertexBufferContainer *vbc = mManagedVBs.getElement(params->vbHandle); DX9Dev->SetStreamSource( 0, (IDirect3DVertexBuffer9 *)vbc->devicehandle, 0, vbc->perVertSizeInBytes); SetShaderData(params); SetRenderStates(params); DX9Dev->SetVertexDeclaration( StaticVDeclHandles[params->vDecl]); D3DPRIMITIVETYPE type = PrimTypeMappingLUT[params->PrimitiveType]; DX9Dev->DrawPrimitive(type, 0, params->NumTriangles);}
  15. 15. Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFuture Work
  16. 16. • load balancing 필요 – command buffer 채우는 작업을 할당 – thread 별로 어떻게 할당?• 최종 장면이 나오기 전까지 여러 장면을 렌더링 – shadow map, reflection, post processing, … – 카메라 • 장면마다 공유
  17. 17. • camera 단위 – command buffer 생성을 쪼갠다.• draw call 묶기 – API 호출에 따른 오버헤드 최소화 – render state 변경 최소화 – batch
  18. 18. frame SubmitMain Sim tothread Update Device Anim Render Particle Physics View UpdateThread Update FillingPool
  19. 19. struct Camera { Float3 at, up, right; float aspectRatio;};struct RenderView { Camera ViewCamera; Frustum Frust; RenderTargetHandle DestColorRTT; RenderTargetHandle DestDepthRTT; List<RenderCommand *> RenderCommands; enum ViewType { kVT_ShadowMap, kVT_ReflectionMap, kVT_MainCamera, kVT_PostProcessing, kVT_Count }; ViewType ViewType;};
  20. 20. void renderControl::CreateRenderViews(){ List<RenderView *> currentViews; for (int i = 0; i < mCameras.size(); ++i) { currentViews.add( new RenderView(mCameras[i], kVT_MainCamera)); } for (int i = 0; i < mLights.size(); ++i) { if (mLights[i].IsShadowCasting()) { currentViews.add( new RenderView( mLights[i].getShadowCamera(), kVT_ShadowMap)); } } for (int i = 0; i < currentViews.size(); ++i) { ThreadPool.QueueWork( procThreadedFillRenderView, currentViews[i]); } ThreadPool.waitForWorkToFinish();}
  21. 21. void renderControl::procThreadedFillRenderView ( void *DataPacket) { RenderView *currView = (RenderView *)DataPacket; List<RenderObject *> objects = gObjectManager.giveFrustumCollision( currView->frustum); for (int q = 0; q < objects.size(); ++q) { RenderCommand *RC = new RenderCommand(); Objects[q]->fillCommandBuffer(RC); currentViews[i].RenderCommands.add(RC); }}
  22. 22. void renderControl::serializeRenderView (List<RenderView *> Views) { for (int viewType = 0; viewType < Count; ++viewType) { for (int i = 0; i < Views.size(); ++i) { if (Views[i].mViewType != viewType) continue; BindRenderTarget( Views[i]->renderTarget, Views[i]->DepthTarget); if (Views[i]->clearTargets) { ClearTarget( Views[i]->clearFlags, Views[i]->clearColor, Views[i]->clearDepths); } for (int k = 0; k < Views[i]->commands.size(); ++k) { executeDrawCommand(Views[i]->commands[k]); } } }}
  23. 23. Uses of Multi-Core in Video GamesMultithreaded Command BuffersDevice-Independent Command BuffersA Camera-Centric DesignFuture Work
  24. 24. • Sorting and Instancing – material index, vertex data, object type… – instancing command • draw command 여러 개를• Better Load Balancing – draw call을 job 하나로 – job을 잘게 나눠 thread utilization을 높임
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×