unigine多線程處理系統(tǒng):
一。 更新系統(tǒng):
主線程World::update_multiple()中:
1. 清空update_threads[]中每一個(gè)thread的所有結(jié)點(diǎn)
2. 處理所有node,將node.frame==engine.frame + 1的結(jié)點(diǎn)均衡地分配給update_threads[](即每個(gè)updatethread盡量擁有數(shù)量相同的node, 以便線程處理時(shí)間平衡), 同時(shí)設(shè)置分配后的node.frame=engine.frame(防止更新重入時(shí)再次加入此結(jié)點(diǎn))
3. 接著通過update_shader->runSync(size);函數(shù)同步更新上述加入的所有結(jié)點(diǎn):
遍歷所有存有node的update_threads[],將它們與cpu工作線程關(guān)聯(lián)(這樣他們的線程run時(shí)會(huì)轉(zhuǎn)調(diào)轉(zhuǎn)回調(diào)用world中的update_threads[id].update(ifps);, 而update_threads[id]能遍歷所有加入的node->update()函數(shù)同時(shí)重置node.frame=engine.frame + 1;
最后等待線程同步執(zhí)行完所有更新再返回.
【注意】上述第3點(diǎn)的runSync()中對(duì)應(yīng)cpu工作線程數(shù)為實(shí)際cpu-1個(gè),當(dāng)cpu為1個(gè)時(shí)就不用線程而是直接運(yùn)行完所有結(jié)點(diǎn)更新,而如果是
有超過一個(gè)cpu的則本地和cpu線程同時(shí)進(jìn)行更新工作。雖然在主線程中同步等待完成,但這樣如果有多核則能并發(fā)同時(shí)處理。
另外還有異步runAsync()函數(shù),分別在PathFind和Physics的更新函數(shù)中調(diào)用。這個(gè)runAsync()函數(shù)功能和runSync()差不多,只是它的工作線程為實(shí)際cpu個(gè)數(shù),然后將任務(wù)均衡交給各線程處理,并且不會(huì)同步等待完成就返回了。所以是異步并發(fā)的。
二。渲染系統(tǒng):
1.收集可視surfaces(scene intersection):
在RenderRenderer::render_world()中調(diào)用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線程并發(fā)處理所有沒被occulude排除的
visible node將它置為visible并將它們?cè)赽ound_frustum中的surface(submesh)加入surfaces中.
c. 在update_intersection()函數(shù)中遍歷各線程所加入的surfaces[iThread].size, 將其按材質(zhì)是否透明收集
到opacity_surfaces和transparent_surfaces中。
2. 反射渲染(render reflections):
render reflections中遍歷opacity_surfaces和transparent_surfaces處理收集reflection_2d_surfaces和 reflection_cube_surfaces.并進(jìn)行反射渲染.
3. update scene:
分別UpdateSurface了opacity_surfaces和transparent_surfaces兩種surface,
內(nèi)部好像只是針對(duì)OpctitySurfacefade state和tessellation state設(shè)置了對(duì)應(yīng)的材質(zhì),并將surface鏈接起來遍歷調(diào)用
它們的create(),而create()內(nèi)部只調(diào)用了create(ObjectSurface *surface), 這個(gè)好像只有skinmesh重載進(jìn)行了處理。
4. sort scene:
按照type、mask、center.x順序分別對(duì)Lights、defferredLights、forwardLights進(jìn)行排序
按照material、resource順序?qū)pacity_surfaces進(jìn)行排序
按照order、sequence、distance、blending順序?qū)ransparent_surfaces進(jìn)行了排序。
在scene->optimize()中將opacity_surfaces和transparent_surfaces統(tǒng)一收集到optimized_surfaces中,然后讓 opacity_surfaces和transparent_surfaces重新指向?qū)?yīng)的optimized_surfaces中元素。(這是為了讓surface更緊湊達(dá)到優(yōu)化效果?)
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:
這個(gè)是使用dx9的硬件查詢進(jìn)行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 閱讀(334)
評(píng)論(0) 編輯 收藏 引用