WebGL
Khronos
 

WebGL KHR_parallel_shader_compile Extension Proposed Specification

DO NOT IMPLEMENT!!!

Name

KHR_parallel_shader_compile

Contact

WebGL working group (public_webgl 'at' khronos.org)

Contributors

Jie Chen, (jie.a.chen 'at' intel.com)

Geoff Lang, (geofflang 'at' google.com)

Members of the WebGL working group

Version

Last modified date: August 07, 2018
Revision: 1

Number

WebGL extension #XYZ

Dependencies

Written against the WebGL API 1.0 specification.

Overview

This extension exposes the KHR_parallel_shader_compile functionality to WebGL.

There are no WebGL-specific behavioral changes.

Consult the above extension for documentation, issues and new functions and enumerants.

When this extension is enabled:

IDL

    [NoInterfaceObject]
    interface KHR_parallel_shader_compile {
      const GLenum MAX_SHADER_COMPILER_THREADS_KHR      = 0x91B0;
      const GLenum COMPLETION_STATUS_KHR                = 0x91B1;
	
      void maxShaderCompilerThreadsKHR(GLuint count);
    };
  

Sample Code

    var canvas = document.createElement("canvas");
    var gl = canvas.getContext("webgl");
    var ext = gl.getExtension('KHR_parallel_shader_compile');
    if (ext) {
      // Just for demo of API usage. Generally it's not needed unless you really
      // want to override the implementation-specific maximum.
      var threads = gl.getParameter(ext.MAX_SHADER_COMPILER_THREADS_KHR);
      ext.maxShaderCompilerThreadsKHR(Math.max(2, threads));
    }

    var vSource = "attribute vec2 position; void main() { gl_Position = vec4(position, 0, 1); }";
    var fSource = "precision mediump float; void main() { gl_FragColor = vec4(1,0,0,1); }";

    var vShader = gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vShader, vSource);
    gl.compileShader(vShader);

    var fShader = gl.createShader(gl.FRAGMENT_SHADER);
    gl.shaderSource(fShader, fSource);
    gl.compileShader(fShader);

    var program = gl.createProgram();
    gl.attachShader(program, vShader);
    gl.attachShader(program, fShader);
    gl.linkProgram(program);

    function checkToUseProgram() {
      if (gl.getProgramParameter(program, gl.LINK_STATUS) == true) {
        gl.useProgram(program);
      } else {
        // error check.
      }
    }

    if (ext) {
      function checkCompletion() {
        if (gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR) == true) {
          checkToUseProgram();
        } else {
          requestAnimationFrame(checkCompletion);
        }
      }
      requestAnimationFrame(checkCompletion);
    } else {
      checkToUseProgram();
    }
    

Revision History

Revision 1, 2018/08/07