It is possible Excute Early befor Fragment Shader Test in Pipeline

在渲染管線中這些測試包含 裁剪測試 模板測試 深度測試 。只要在執行的過程中不影響這些測試,默認都可以讓這些測試提前執行。

這些影響測試的條件包括:

 1 寫出深度 gl_FragDpth 因爲改變了原有片段的深度值。

2 硬件限制 比如 如果alpha test 被激活的話,有一些硬件就不會進行深度的提前測試因爲必須需要執行alpha test .而alpha測試沒法提前執行(因爲物體的alpha值不能通過頂點着色器獲得而只能通過採樣獲得可以腦洞一下如果alpha值能提前獲得會怎麼樣影響流水線).

3.在片段着色器中使用 discard關鍵字。因爲這在一些硬件上執行的時候,相當於已經關閉了深度測試。

但是在一些硬件上也會強制執行提前進行深度測試以OpenGL爲例比如使用 

layout(early_fragment_tests) in;
具體參見維基百科:

his will also perform early stencil tests.

There is a caveat with this. This feature cannot be used to violate the sanctity of the depth test. When this is activated, any writes to gl_FragDepth will be ignored. The value written to the depth buffer will be exactly what was tested against the depth buffer: the fragment's depth computed through rasterization.

This feature exists to ensure proper behavior when using Image Load Store or other incoherent memory writing. Without turning this on, fragments that fail the depth test would still perform their Image Load/Store operations, since the fragment shader that performed those operations successfully executed. However, with early fragment tests, those tests were run before the fragment shader. So this ensures that image load/store operations will only happen on fragments that pass the depth test.

Note that enabling this feature has consequences for the results of a discarded fragment.

大概意思就是 執行了上面的方法後,一些操作會失效比如深度寫入和discard。好處就是當我們進行圖片加載存儲的時候,可以提前進行深度測試節省內存。

因此爲了性能考慮我們應該儘量不適用影響提前進行測試的操作比如深度寫入 discard操作等




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章