| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<?xml-stylesheet href="../../extension.xsl" type="text/xsl"?> |
| 4 |
<draft href="KHR_parallel_shader_compile/"> |
| 5 |
<name>KHR_parallel_shader_compile</name> |
| 6 |
|
| 7 |
<contact> <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL |
| 8 |
working group</a> (public_webgl 'at' khronos.org) </contact> |
| 9 |
|
| 10 |
<contributors> |
| 11 |
<contributor>Jie Chen, (jie.a.chen 'at' intel.com)</contributor> |
| 12 |
<contributor>Geoff Lang, (geofflang 'at' google.com)</contributor> |
| 13 |
<contributor>Members of the WebGL working group</contributor> |
| 14 |
</contributors> |
| 15 |
|
| 16 |
<number>37</number> |
| 17 |
|
| 18 |
<depends> |
| 19 |
<api version="1.0"/> |
| 20 |
</depends> |
| 21 |
|
| 22 |
<overview> |
| 23 |
<mirrors href="https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_parallel_shader_compile.txt" |
| 24 |
name="KHR_parallel_shader_compile"> |
| 25 |
</mirrors> |
| 26 |
|
| 27 |
<features> |
| 28 |
<feature> |
| 29 |
Shader compilation and program linking may be performed in a separate CPU thread. This extension provides a mechanism for the application to provide a hint to limit the number of threads it wants to be used to compile shaders, as well as a query to determine if the compilation process is complete. |
| 30 |
</feature> |
| 31 |
</features> |
| 32 |
</overview> |
| 33 |
|
| 34 |
<idl xml:space="preserve"> |
| 35 |
[NoInterfaceObject] |
| 36 |
interface KHR_parallel_shader_compile { |
| 37 |
const GLenum MAX_SHADER_COMPILER_THREADS_KHR = 0x91B0; |
| 38 |
const GLenum COMPLETION_STATUS_KHR = 0x91B1; |
| 39 |
|
| 40 |
void maxShaderCompilerThreadsKHR(GLuint count); |
| 41 |
}; |
| 42 |
</idl> |
| 43 |
|
| 44 |
<samplecode xml:space="preserve"> |
| 45 |
<pre> |
| 46 |
var canvas = document.createElement("canvas"); |
| 47 |
var gl = canvas.getContext("webgl"); |
| 48 |
var ext = gl.getExtension('KHR_parallel_shader_compile'); |
| 49 |
if (ext) { |
| 50 |
// Just for demo of API usage. Generally it's not needed unless you really |
| 51 |
// want to override the implementation-specific maximum. |
| 52 |
var threads = gl.getParameter(ext.MAX_SHADER_COMPILER_THREADS_KHR); |
| 53 |
ext.maxShaderCompilerThreadsKHR(Math.max(2, threads)); |
| 54 |
} |
| 55 |
|
| 56 |
var vSource = "attribute vec2 position; void main() { gl_Position = vec4(position, 0, 1); }"; |
| 57 |
var fSource = "precision mediump float; void main() { gl_FragColor = vec4(1,0,0,1); }"; |
| 58 |
|
| 59 |
var vShader = gl.createShader(gl.VERTEX_SHADER); |
| 60 |
gl.shaderSource(vShader, vSource); |
| 61 |
gl.compileShader(vShader); |
| 62 |
|
| 63 |
var fShader = gl.createShader(gl.FRAGMENT_SHADER); |
| 64 |
gl.shaderSource(fShader, fSource); |
| 65 |
gl.compileShader(fShader); |
| 66 |
|
| 67 |
var program = gl.createProgram(); |
| 68 |
gl.attachShader(program, vShader); |
| 69 |
gl.attachShader(program, fShader); |
| 70 |
gl.linkProgram(program); |
| 71 |
|
| 72 |
function checkToUseProgram() { |
| 73 |
if (gl.getProgramParameter(program, gl.LINK_STATUS) == true) { |
| 74 |
gl.useProgram(program); |
| 75 |
} else { |
| 76 |
// error check. |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if (ext) { |
| 81 |
function checkCompletion() { |
| 82 |
if (gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR) == true) { |
| 83 |
checkToUseProgram(); |
| 84 |
} else { |
| 85 |
requestAnimationFrame(checkCompletion); |
| 86 |
} |
| 87 |
} |
| 88 |
requestAnimationFrame(checkCompletion); |
| 89 |
} else { |
| 90 |
checkToUseProgram(); |
| 91 |
} |
| 92 |
</pre> |
| 93 |
</samplecode> |
| 94 |
|
| 95 |
<history> |
| 96 |
<revision date="2018/08/07"> |
| 97 |
<change>Initial revision.</change> |
| 98 |
</revision> |
| 99 |
<revision date="2018/09/14"> |
| 100 |
<change>Moved to draft status.</change> |
| 101 |
</revision> |
| 102 |
</history> |
| 103 |
</draft> |