unigine多線程處理系統:
一。 更新系統:
主線程World::update_multiple()中:
1. 清空update_threads[]中每一個thread的所有結點
2. 處理所有node,將node.frame==engine.frame + 1的結點均衡地分配給update_threads[](即每個updatethread盡量擁有數量相同的node, 以便線程處理時間平衡), 同時設置分配后的node.frame=engine.frame(防止更新重入時再次加入此結點)
3. 接著通過update_shader->runSync(size);函數同步更新上述加入的所有結點:
遍歷所有存有node的update_threads[],將它們與cpu工作線程關聯(這樣他們的線程run時會轉調轉回調用world中的update_threads[id].update(ifps);, 而update_threads[id]能遍歷所有加入的node->update()函數同時重置node.frame=engine.frame + 1;
最后等待線程同步執行完所有更新再返回.
【注意】上述第3點的runSync()中對應cpu工作線程數為實際cpu-1個,當cpu為1個時就不用線程而是直接運行完所有結點更新,而如果是
有超過一個cpu的則本地和cpu線程同時進行更新工作。雖然在主線程中同步等待完成,但這樣如果有多核則能并發同時處理。
另外還有異步runAsync()函數,分別在PathFind和Physics的更新函數中調用。這個runAsync()函數功能和runSync()差不多,只是它的工作線程為實際cpu個數,然后將任務均衡交給各線程處理,并且不會同步等待完成就返回了。所以是異步并發的。
二。渲染系統:
1.收集可視surfaces(scene intersection):
在RenderRenderer::render_world()中調用scene::getIntersection(bound_frustum,occluder,exclude)中:
a. render world occluders得到所有被occluders排除的nodes;
b. 判斷node是否被occluder所排除(exclude),沒有則add visible nodes.
c. objects_shader->runSync(RENDER_SCENE_NUM_THREADS);同步等待8線程并發處理所有沒被occulude排除的
visible node將它置為visible并將它們在bound_frustum中的surface(submesh)加入surfaces中.
c. 在update_intersection()函數中遍歷各線程所加入的surfaces[iThread].size, 將其按材質是否透明收集
到opacity_surfaces和transparent_surfaces中。
2. 反射渲染(render reflections):
render reflections中遍歷opacity_surfaces和transparent_surfaces處理收集reflection_2d_surfaces和 reflection_cube_surfaces.并進行反射渲染.
3. update scene:
分別UpdateSurface了opacity_surfaces和transparent_surfaces兩種surface,
內部好像只是針對OpctitySurfacefade state和tessellation state設置了對應的材質,并將surface鏈接起來遍歷調用
它們的create(),而create()內部只調用了create(ObjectSurface *surface), 這個好像只有skinmesh重載進行了處理。
4. sort scene:
按照type、mask、center.x順序分別對Lights、defferredLights、forwardLights進行排序
按照material、resource順序對opacity_surfaces進行排序
按照order、sequence、distance、blending順序對transparent_surfaces進行了排序。
在scene->optimize()中將opacity_surfaces和transparent_surfaces統一收集到optimized_surfaces中,然后讓 opacity_surfaces和transparent_surfaces重新指向對應的optimized_surfaces中元素。(這是為了讓surface更緊湊達到優化效果?)
5. deferred textures:
a. 先得到
deferred->depth_texture、
deferred->color_texture、
deferred->normal_texture、
deferred->parallax_texture、
deferred->texturerender
b. render deferred surfaces:
render_deferred_surfaces(scene->getOpacitySurfaces(),0)
render_deferred_surfaces(scene-getTransparentSurfaces(),0)
6. occlusion queries:
這個是使用dx9的硬件查詢進行occulsion的culling.
http://frustum.org/
http://www.humus.name/index.php?page=3D
https://www.assembla.com/code/scavenger/subversion/nodes/692/Scavenger
http://www.hmrengine.com/blog/?cat=5
posted on 2014-03-21 16:01
flipcode 閱讀(331)
評論(0) 編輯 收藏 引用