1*8975f5c5SAndroid Build Coastguard Worker# ANGLE Development Update - July 4, 2012 2*8975f5c5SAndroid Build Coastguard Worker 3*8975f5c5SAndroid Build Coastguard WorkerWe haven't posted an update on the development status of ANGLE in quite some 4*8975f5c5SAndroid Build Coastguard Workertime and we'd like to provide an update on some of the new features and 5*8975f5c5SAndroid Build Coastguard Workerimprovements that we've been working on. 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Worker## Conformance 8*8975f5c5SAndroid Build Coastguard Worker 9*8975f5c5SAndroid Build Coastguard WorkerAs announced in the [Chromium Blog] 10*8975f5c5SAndroid Build Coastguard Worker(http://blog.chromium.org/2011/11/opengl-es-20-certification-for-angle.html), 11*8975f5c5SAndroid Build Coastguard WorkerANGLE v1.0 has passed the Khronos OpenGL ES 2.0 certification process and is now 12*8975f5c5SAndroid Build Coastguard Workera [conformant](http://www.khronos.org/conformance/adopters/conformant-products/) 13*8975f5c5SAndroid Build Coastguard WorkerOpenGL ES 2.0 implementation. 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard Worker## Extensions 16*8975f5c5SAndroid Build Coastguard Worker 17*8975f5c5SAndroid Build Coastguard WorkerWe have recently completed the implementation of depth texture support 18*8975f5c5SAndroid Build Coastguard Worker([ANGLE\_depth\_texture] 19*8975f5c5SAndroid Build Coastguard Worker(https://code.google.com/p/angleproject/source/browse/extensions/ANGLE_depth_texture.txt?name=master)) 20*8975f5c5SAndroid Build Coastguard Workerand earlier in the year we added support for instancing via attribute array 21*8975f5c5SAndroid Build Coastguard Workerdivisors ([ANGLE\_instanced\_arrays] 22*8975f5c5SAndroid Build Coastguard Worker(https://code.google.com/p/angleproject/source/browse/extensions/ANGLE_instanced_arrays.txt?name=master)). 23*8975f5c5SAndroid Build Coastguard WorkerSee ExtensionSupport for a complete list of extensions that are supported by 24*8975f5c5SAndroid Build Coastguard WorkerANGLE. 25*8975f5c5SAndroid Build Coastguard Worker 26*8975f5c5SAndroid Build Coastguard Worker## Shader Compiler 27*8975f5c5SAndroid Build Coastguard Worker 28*8975f5c5SAndroid Build Coastguard WorkerWe have also made a number of improvements in the shader compiler. 29*8975f5c5SAndroid Build Coastguard Worker 30*8975f5c5SAndroid Build Coastguard Worker* We addressed a number of defects related to scoping differences between HLSL and 31*8975f5c5SAndroid Build Coastguard WorkerGLSL and improved the scoping support in ANGLE's compiler front-end. We also 32*8975f5c5SAndroid Build Coastguard Workerworked with The Khronos Group to get an ESSL spec bug fixed and several items 33*8975f5c5SAndroid Build Coastguard Workerclarified. 34*8975f5c5SAndroid Build Coastguard Worker* We addressed a number of correctness issues in the GLSL to HLSL 35*8975f5c5SAndroid Build Coastguard Workertranslation process. We fixed some bugs related to constant propagation and 36*8975f5c5SAndroid Build Coastguard Workercomma conditional assignments. More importantly, we fully implemented support 37*8975f5c5SAndroid Build Coastguard Workerfor short-circuiting boolean logic operations. In GLSL, Boolean expressions do 38*8975f5c5SAndroid Build Coastguard Workershort-circuit evaluation as in C, but HLSL evaluates them entirely. This only 39*8975f5c5SAndroid Build Coastguard Workerhas an observable effect if a short-circuited operation has side effects, such 40*8975f5c5SAndroid Build Coastguard Workeras a function call that modifies global variables. 41*8975f5c5SAndroid Build Coastguard Worker* We implemented detection 42*8975f5c5SAndroid Build Coastguard Workerfor discontinuous gradient or derivative computations inside loops and replace 43*8975f5c5SAndroid Build Coastguard Workerthem with explicitly defined continuous behaviour. HLSL and GLSL differ in their 44*8975f5c5SAndroid Build Coastguard Workerspecified behaviour for operations which compute gradients or derivatives. 45*8975f5c5SAndroid Build Coastguard WorkerGradients are computed by texture sampling functions which don't specify a 46*8975f5c5SAndroid Build Coastguard Workerspecific mipmap LOD level, and by the OES\_standard\_derivatives built-in 47*8975f5c5SAndroid Build Coastguard Workerfunctions. To determine the gradient, the corresponding values in neighbouring 48*8975f5c5SAndroid Build Coastguard Workerpixels are differentiated. If neighbouring pixels execute different paths 49*8975f5c5SAndroid Build Coastguard Workerthrough the shader this can cause a discontinuity in the gradient. GLSL 50*8975f5c5SAndroid Build Coastguard Workerspecifies that in these cases the gradient is undefined. HLSL tries to avoid the 51*8975f5c5SAndroid Build Coastguard Workerdiscontinuity in the compiler by unrolling loops so that every pixel executes 52*8975f5c5SAndroid Build Coastguard Workerall iterations. This can make the D3D HLSL compiler spend a long time generating 53*8975f5c5SAndroid Build Coastguard Workercode permutations, and possibly even fail compilation due to running out of 54*8975f5c5SAndroid Build Coastguard Workerinstruction slots or registers. Because the GLSL specification allows undefined 55*8975f5c5SAndroid Build Coastguard Workerbehaviour, we can define such texture sampling functions to use mipmap LOD level 56*8975f5c5SAndroid Build Coastguard Worker0, and have the derivatives functions return 0.0. To do this we examine the GLSL 57*8975f5c5SAndroid Build Coastguard Workercode's abstract syntax tree and detect whether the shader contains any loops 58*8975f5c5SAndroid Build Coastguard Workerwith discontinuities and gradient operations. Within such loops, we generate 59*8975f5c5SAndroid Build Coastguard WorkerHLSL code that uses explicitly defined texture LODs and derivative information. 60*8975f5c5SAndroid Build Coastguard WorkerOne additional consideration is that within these loops there can be calls to 61*8975f5c5SAndroid Build Coastguard Workeruser-defined functions which may contain gradient operations. In this case, we 62*8975f5c5SAndroid Build Coastguard Workergenerate variants of user-defined functions where these operations are 63*8975f5c5SAndroid Build Coastguard Workerexplicitly defined. We use these new functions instead of the original ones in 64*8975f5c5SAndroid Build Coastguard Workerloops with discontinuities. 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard WorkerThese fixes result in ANGLE being able successfully compile a number of the more 67*8975f5c5SAndroid Build Coastguard Workercomplex shaders. Unfortunately there are still some complex shaders which we 68*8975f5c5SAndroid Build Coastguard Workerhave not yet been able to obtain solutions for. Ultimately Direct3D 9 SM3 69*8975f5c5SAndroid Build Coastguard Workershaders are more restricted than what can be expressed in GLSL. Most of the 70*8975f5c5SAndroid Build Coastguard Workerproblematic shaders we've encountered will also not compile successfully on 71*8975f5c5SAndroid Build Coastguard Workercurrent ES 2.0 implementations. We would only be able to achieve parity with 72*8975f5c5SAndroid Build Coastguard WorkerDesktop GL implementations by using Direct3D 10 or above. 73*8975f5c5SAndroid Build Coastguard Worker 74*8975f5c5SAndroid Build Coastguard Worker## Texture Origin Changes 75*8975f5c5SAndroid Build Coastguard Worker 76*8975f5c5SAndroid Build Coastguard WorkerWe have also made a major change to ANGLE in the way the origin difference 77*8975f5c5SAndroid Build Coastguard Workerbetween D3D and OpenGL is handled. This difference is normally observable when 78*8975f5c5SAndroid Build Coastguard Workerusing render-to-texture techniques, and if not accounted for, it would appear 79*8975f5c5SAndroid Build Coastguard Workerthat images rendered to textures are upside down. In recent versions of ANGLE 80*8975f5c5SAndroid Build Coastguard Worker(r536 (on Google Code)-r1161 (on Google Code)), we have been storing surfaces 81*8975f5c5SAndroid Build Coastguard Workerfollowing the D3D Y convention where (0, 0) is the top-left, rather than GL's 82*8975f5c5SAndroid Build Coastguard Workerbottom-left convention. This was done by vertically flipping textures on load 83*8975f5c5SAndroid Build Coastguard Workerand then adjusting the texture coordinates in the shaders to compensate. This 84*8975f5c5SAndroid Build Coastguard Workerapproach worked well, but it did leave the orientation of pbuffers inverted when 85*8975f5c5SAndroid Build Coastguard Workercompared to native GL implementations. As of ANGLE r1162 (on Google Code), we 86*8975f5c5SAndroid Build Coastguard Workerhave changed this back to the original way it was implemented - textures are 87*8975f5c5SAndroid Build Coastguard Workerloaded and stored in the GL orientation, and the final rendered scene is flipped 88*8975f5c5SAndroid Build Coastguard Workerwhen it is displayed to a window by eglSwapBuffers. This should be essentially 89*8975f5c5SAndroid Build Coastguard Workertransparent to applications except that orientation of pbuffers will change. In 90*8975f5c5SAndroid Build Coastguard Workeraddition to fixing the pbuffer orientation, this change: 91*8975f5c5SAndroid Build Coastguard Worker 92*8975f5c5SAndroid Build Coastguard Worker* eliminates 93*8975f5c5SAndroid Build Coastguard Workerdependent-texture look-ups in the shaders, caused by flipping the texture 94*8975f5c5SAndroid Build Coastguard Workery-coordinates 95*8975f5c5SAndroid Build Coastguard Worker* rounding of texture coordinates (while previously within spec) 96*8975f5c5SAndroid Build Coastguard Workerwill be more consistent with other implementations, and 97*8975f5c5SAndroid Build Coastguard Worker* allows potential 98*8975f5c5SAndroid Build Coastguard Workerfaster paths for loading texture data to be implemented. The only potential 99*8975f5c5SAndroid Build Coastguard Workerdownside to this approach is that window-based rendering may be a bit slower for 100*8975f5c5SAndroid Build Coastguard Workersimple scenes. The good news is that this path is not used by browser 101*8975f5c5SAndroid Build Coastguard Workerimplementations on most versions of Windows. 102*8975f5c5SAndroid Build Coastguard Worker 103*8975f5c5SAndroid Build Coastguard Worker## Preprocessor 104*8975f5c5SAndroid Build Coastguard Worker 105*8975f5c5SAndroid Build Coastguard WorkerFinally, Alok P. from Google has been working on implementing a new shader 106*8975f5c5SAndroid Build Coastguard Workerpreprocessor for the last number of months and this effort is nearly complete. 107*8975f5c5SAndroid Build Coastguard WorkerThis new preprocessor should be more robust and much more maintainable. It also 108*8975f5c5SAndroid Build Coastguard Workerincludes many (~5000) unit tests and passes all WebGL conformance tests. If you 109*8975f5c5SAndroid Build Coastguard Workerwish to try this out before it is enabled by default, define 110*8975f5c5SAndroid Build Coastguard WorkerANGLE\_USE\_NEW\_PREPROCESSOR=1 in your project settings for the 111*8975f5c5SAndroid Build Coastguard Workertranslator\_common project. 112*8975f5c5SAndroid Build Coastguard Worker 113*8975f5c5SAndroid Build Coastguard Worker## Contributions 114*8975f5c5SAndroid Build Coastguard Worker 115*8975f5c5SAndroid Build Coastguard WorkerAs always we welcome contributions either in the bug reports (preferably with an 116*8975f5c5SAndroid Build Coastguard Workerisolated test-case) or in the form of code contributions. We have added a 117*8975f5c5SAndroid Build Coastguard Worker[ContributingCode](ContributingCode.md) wiki page documenting the preferred 118*8975f5c5SAndroid Build Coastguard Workerprocess for contributing code. We do need to ask that you sign a Contributor 119*8975f5c5SAndroid Build Coastguard WorkerLicense Agreement before we can integrate your patches. 120