KHR_parallel_shader_compile 擴充套件
KHR_parallel_shader_compile 擴充套件是 WebGL API 的一部分,它啟用非阻塞的輪詢操作,這樣就可以查詢編譯/連結狀態的可用性(COMPLETION_STATUS_KHR),而不會導致潛在的停頓。換句話說,您可以檢查著色器編譯的狀態,而不會阻塞執行時。
可以使用 WebGLRenderingContext.getExtension() 方法來訪問 WebGL 擴充套件。有關更多資訊,請參閱 WebGL 教程中的 使用擴充套件。
常量
ext.COMPLETION_STATUS_KHR-
一個 GLenum。
示例
啟用擴充套件
js
const ext = gl.getExtension("KHR_parallel_shader_compile");
總的來說,無論是否使用此擴充套件,最佳實踐都是
js
// Assuming lists of `shaders` and `programs`:
for (const x of shaders) gl.compileShader(x); // Never check compile status unless subsequent linking fails.
for (const x of programs) gl.linkProgram(x);
使用此擴充套件,應用程式將能夠在不出現卡頓的情況下輪詢程式是否已連結,但這些程式連結的總實際時間可能相同。
js
// Generator yielding a progress ratio [0.0, 1.0].
// Without the extension, this will jank and only check one program per generation.
function* linkingProgress(programs) {
const ext = gl.getExtension("KHR_parallel_shader_compile");
let todo = programs.slice();
while (todo.length) {
if (ext) {
todo = todo.filter(
(x) => !gl.getProgramParameter(x, ext.COMPLETION_STATUS_KHR),
);
} else {
const x = todo.pop();
gl.getProgramParameter(x, gl.LINK_STATUS);
}
if (!todo.length) return;
yield 1.0 - todo.length / programs.length;
}
}
規範
| 規範 |
|---|
| WebGL KHR_parallel_shader_compile 擴充套件規範 |
瀏覽器相容性
載入中…