├── LICENSE ├── README.md └── index.html /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Martin Valigursky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # webgl-parallel_shader_compile 2 | 3 | A simple WebGL application, to test the performance and behaviour of [KHR_parallel_shader_compile](https://developer.mozilla.org/en-US/docs/Web/API/KHR_parallel_shader_compile) across platforms and browsers. 4 | 5 | # Live Example 6 | 7 | https://htmlpreview.github.io/?https://github.com/mvaligursky/webgl-parallel_shader_compile/blob/main/index.html 8 | Open a development javascript console and observe the logs with timings. 9 | 10 | ![Screenshot 2023-01-25 at 10 54 57](https://user-images.githubusercontent.com/59932779/214546015-60427421-0103-4818-b7c7-923c5d6314b3.png) 11 | 12 | The program creates a WebGL 2 instance, and renders a simple spinning triangle, which allows us to see the rendering being blocked. 13 | 14 | On top of the web page, there are buttons to compile 10 or 50 instances of a shader. A large shader was generated by [PlayCanvas Engine](https://github.com/playcanvas/engine), which implements PBR / clustered lighting / area lights. There is a random number added in the source code of the fragment shader to avoid possibility of some caching behind the scenes. 15 | 16 | ## Overall implementation 17 | 1. prepare fragment and vertex shader source code for all shaders 18 | 2. **[COMPILE STEP]** trigger compile step on all vertex and fragment shaders 19 | 3. **[LINK STEP]** create programs, linking vertex and fragment shades, and trigger link step on all programs 20 | 4. inside requestAnimationFrame which executes each frame, for each shader which has not been fully processed yet: 21 | - **[COMPLETION STEP]** test COMPLETION_STATUS_KHR using the extension. This should be a non-blocking call, and return true if the shader is done linking. 22 | - **[LINK STATUS STEP]** get shaders LINK_STATUS if [COMPLETION STEP] has returned true - this is a blocking call if the shader has not been done linking yet. 23 | 24 | ## Expectation 25 | - on platforms that implement the mentioned extension, the triangle rotates smootly with no blocking during the shader compilation. 26 | 27 | ## Test Results 28 | 29 | None of the tested browser / OS combination delivered smooth triangle rotation while the compilation takes place. 30 | 31 | ### Chrome MacOS 13.1 32 | - compilation, linking, COMPLETION_STATUS_KHR and LINK_STATUS are fast, the extension is working well. 33 | - on multiple occasions, requestAnimationFrame is not being called for 1s or more, and so the bottleneck seems to have just moved to be inside the browser, instead of [LINK STATUS STEP]. It seems all shareds are completed during the same frame. The result is that the triangle still does not smoothly rotate at all. 34 | 35 | ### Safari MacOS 13.1 (Metal backend) 36 | - compilation is instant, all the time is taken by [LINK STEP] during which all the works seems to take place. [COMPLETION STEP] and [LINK STATUS STEP] are instant, as shader has already been fully processed. So there does not seem to be any advantage in using the extension here. 37 | 38 | ### Firefox MacOS 13.1 39 | - extension is not implemented, all time is taken by [LINK STATUS STEP] 40 | 41 | ### Chrome Windows 10 42 | - 10 shaders seem to get processed nicely, almost as if extension worked perfectly (some DTs are slightly longer). When compiling 50 shaders, similarly to MacOS, we get multiple 1s or longer intervals when requestAnimationFrame is not called. 43 | 44 | ### Firefox Windows 10 45 | - extension is not implemented, all time is taken by [LINK STATUS STEP] 46 | 47 | ## Separate note 48 | - the PBR/clustered/area lights shader has a compilation time on Windows considerably longer than on MacOS. 49 | 50 | # Created browser issues: 51 | - Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1412083 52 | - WebKit: https://bugs.webkit.org/show_bug.cgi?id=251514 53 | 54 | # References 55 | [1] - Basic WebGl spinning triangle application is based on https://www.tutorialspoint.com/webgl/webgl_rotation.htm 56 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 |
11 | 12 | 1539 | 1540 | --------------------------------------------------------------------------------