src/compiler/translator/EmulatePrecision.cpp


Log

Author Commit Date CI Message
Jamie Madill 03d863c8 2016-07-27T18:15:53 translator: Refactor node replacement APIs. BUG=angleproject:851 Change-Id: I50c3b3a4f00b27fed85f09509738513a441c7b5b Reviewed-on: https://chromium-review.googlesource.com/363990 Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Zhenyao Mo <zmo@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Olli Etuaho b741c761 2016-06-29T15:49:22 Support precision emulation on HLSL Re-submit with missing virtual destructor and angle::NonCopyable added. Add precision emulation support to HLSL 4.1 output. This makes it possible for developers to test their shaders for precision issues easily on Chrome on Windows without having to use the GL backend. The patch has been verified with Chrome on Windows to reproduce some precision bugs in real-world WebGL content, including old versions of the babylon.js library. The EmulatePrecision AST transformation still relies on writing out raw shader code for the rounding functions, with raw HLSL code added alongside pre-existing GLSL and ESSL code. In some ways it would be nicer to do the EmulatePrecision step as a pure AST transformation, but on the other hand the raw code is much more readable and easier to optimize. To better support multiple output languages in EmulatePrecision, add a RoundingHelperWriter class that has different subclasses for writing the rounding functions in different languages. The unit tests are expanded to cover the HLSL output of precision emulation. The parts of the tests that require the HLSL output are only active on Windows where ANGLE_ENABLE_HLSL define is added to the unit tests. Putting the HLSL tests in an entirely separate file is a worse alternative, since it would require either a lot of code duplication or add a lot of boilerplate to the individual tests. BUG=angleproject:1437 TEST=angle_unittests Change-Id: I47d501037c206f4bd8b976d3acab9b21c717084c Reviewed-on: https://chromium-review.googlesource.com/360152 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 3fdaf6f2 2016-07-13T15:07:41 Revert "Support precision emulation on HLSL" Forgot to add virtual destructors. BUG=angleproject:1437 This reverts commit a42e8b2cb9d0857f53c0490b5be3bf25b4e1f827. Change-Id: If33fecfeca9947deedf4668c64dbadf25a5dc5eb Reviewed-on: https://chromium-review.googlesource.com/360122 Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho a42e8b2c 2016-06-29T15:49:22 Support precision emulation on HLSL Add precision emulation support to HLSL 4.1 output. This makes it possible for developers to test their shaders for precision issues easily on Chrome on Windows without having to use the GL backend. The patch has been verified with Chrome on Windows to reproduce some precision bugs in real-world WebGL content, including old versions of the babylon.js library. The EmulatePrecision AST transformation still relies on writing out raw shader code for the rounding functions, with raw HLSL code added alongside pre-existing GLSL and ESSL code. In some ways it would be nicer to do the EmulatePrecision step as a pure AST transformation, but on the other hand the raw code is much more readable and easier to optimize. To better support multiple output languages in EmulatePrecision, add a RoundingHelperWriter class that has different subclasses for writing the rounding functions in different languages. The unit tests are expanded to cover the HLSL output of precision emulation. The parts of the tests that require the HLSL output are only active on Windows where ANGLE_ENABLE_HLSL define is added to the unit tests. Putting the HLSL tests in an entirely separate file is a worse alternative, since it would require either a lot of code duplication or add a lot of boilerplate to the individual tests. BUG=angleproject:1437 TEST=angle_unittests Change-Id: Ia4ba0374cd415908f16f34752321af1cb93525a5 Reviewed-on: https://chromium-review.googlesource.com/358473 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 61b81acf 2016-06-28T14:15:20 Support non-square matrices in precision emulation In case the shader version is greater than ESSL 1.00, the precision emulation needs to output rounding functions for non-square matrix types. Writing emulated compound assignment functions for non-square matrices already had most of the code in place before this change. New compound assignment operators like >>= don't need floating point precision emulation in ESSL 3.00, since all of them only operate on integers. BUG=angleproject:1434 TEST=angle_unittests Change-Id: I4678f511edf4f9f744fe23bb8d7dab4387f07f20 Reviewed-on: https://chromium-review.googlesource.com/358472 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho e92507bc 2016-07-04T11:20:10 Reuse code for determining built-in type name string Add TType::getBuiltInTypeNameString() that returns an unique char pointer for each built-in type. They can be easily stored in an std::set as required by EmulatePrecision, and the function can also be used in TOutputGLSLBase. BUG=angleproject:1437 TEST=angle_unittests Change-Id: I9acfe1b149546dedeae058841cbabf0d9829cdc9 Reviewed-on: https://chromium-review.googlesource.com/358471 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 3820e9c1 2016-07-04T16:01:15 Set correct type on nodes created in precision emulation The correct type needs to be set so that HLSL output will be able to disambiguate user-defined function calls correctly based on argument types. HLSL output support will be added to precision emulation in a future patch, which will also have tests that verify this patch. The lack of correct type on the nodes is not known to cause any bugs in GLSL output. BUG=angleproject:1437 Change-Id: I53200df066ece0ab4bd7d7a6aab699d6a1ecb659 Reviewed-on: https://chromium-review.googlesource.com/358470 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 59f9a641 2015-08-06T20:38:26 Remove EOpInternalFunctionCall It's cleaner to mark internal functions by using the TName class, similarly to TIntermSymbol. TEST=angle_unittests BUG=angleproject:1116 Change-Id: I12a03a3dea42b3fc571fa25a1b11d0161f24de72 Reviewed-on: https://chromium-review.googlesource.com/291621 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 217fe6ec 2015-08-05T13:25:08 Detect when built-in modf requires an l-value in AST traversal This fixes an omission that out parameter tracking had inherited from EmulatePrecision. Accurate tracking of when values are written is required for converting dynamic indexing of vectors and matrices to function calls. A new test covering this is added to angle_unittests. TEST=angle_unittests BUG=angleproject:1116 Change-Id: I05c5fd60355117d0053b84110748ae221375a790 Reviewed-on: https://chromium-review.googlesource.com/290562 Reviewed-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 3fc9337f 2015-08-11T14:50:59 Refactor l-value tracking to a separate traverser parent class This makes TIntermTraverser implementation easier to understand and removes the overhead of maintaining the user-defined GLSL function table from the traversers that don't need it. Some logic is duplicated between TIntermTraverser and its new subclass TLValueTrackingTraverser, but duplication is hard to eliminate completely since there are some differences scattered throughout the code. BUG=angleproject:1116 TEST=angle_unittests Change-Id: Iab4a0c1d4320ecfafaf18ea3a45824d756890774 Reviewed-on: https://chromium-review.googlesource.com/292721 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho a26ad58d 2015-08-04T13:51:47 Track where l-values are required in AST traversal This functionality is refactored out of EmulatePrecision to be a common feature of TIntermTraverser. This is done since tracking where l-values are required will be useful for other traversers. For example, it will be needed for converting dynamic indexing of matrices and vectors to function calls. This change adds some overhead to all tree traversers, but the overhead is expected to be small for typical shaders which don't contain too many user-defined functions. BUG=angleproject:1116 TEST=angle_unittests Change-Id: I54d34c2b5093ef028f2b24d854c11c0195dc1dbb Reviewed-on: https://chromium-review.googlesource.com/290514 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Alexis Hetu 07e57df7 2015-06-16T16:55:52 Added non square matrix construction Added new construction operations for non square matrices, along with the required changes to the related translation functions. Change-Id: I04ae7d4b2d1bb363b35d088cea45c0e7c4bc8a13 Reviewed-on: https://chromium-review.googlesource.com/277729 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
Qingqing Deng ad0d0799 2015-04-08T14:25:06 Expand ShShaderOutput for different GLSL versions BUG=angleproject:968 Change-Id: I2d4c0a8e9a91a940922da4501c22124da0c0399c Reviewed-on: https://chromium-review.googlesource.com/264840 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Jamie Madill <jmadill@chromium.org>
Zhenyao Mo 05b6b7fc 2015-03-02T17:08:09 Add an SH_GLSL_CORE_OUTPUT profile. So we could generate shaders for Apple using core GL profile. By switching to core profile, we still pass most WebGL conformance tests 1.0.2 on Linux, but not all, so apparently more work is needed. However, I think it's OK to check this CL in because this output profile will be only used behind a chromium switch. BUG=angleproject:933 TEST=webgl conformance tests Change-Id: Iad70e1aebf82349d3fc5f4116c1d6bc4448193fd Reviewed-on: https://chromium-review.googlesource.com/255282 Tested-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho 1be8870b 2015-01-19T16:56:44 Avoid precision emulation overhead on unused values Avoid rounding intermediate values when the intermediate value is not consumed. For example, this avoids rounding the return value of assignment, so "b = a;" becomes "b = frm(a);" instead of "frm(b = frm(a))". BUG=angle:874 TEST=compiler_tests Change-Id: Ifcdb53fb1d07a2cf24e429cc237c2d0262dc32f8 Reviewed-on: https://chromium-review.googlesource.com/241852 Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 853dc1ab 2014-11-06T17:25:48 Add mediump and lowp precision emulation support for GLSL output This implements the rounding as specified in WEBGL_debug_shader_precision extension proposal for desktop GLSL and ESSL output. The bulk of the new functionality is added in the form of a new EmulatePrecision AST traverser, which inserts calls to the rounding routines angle_frm and angle_frl in the appropriate places, and writes the rounding routines themselves to the shader. Compound assignments which are subject to emulation are transformed from "x op= y" to "angle_compound_op_frm(x, y)", a call to a function which does the appropriate rounding and places the result of the operation to x. The angle_ prefixed names should not clash with user-defined names if name hashing is on. If name hashing is not on, the precision emulation can only be used if the angle_ prefix is reserved for use by ANGLE. To support the rounding routines in output, a new operator type is added for internal helper function calls, which are not subject to name hashing. In ESSL output, all variables are forced to highp when precision emulation is on to ensure consistency with how precision emulation performs on desktop. Comprehensive tests for the added code generation are included. BUG=angle:787 Change-Id: I0d0ad9327888f803a32e79b64b08763c654c913b Reviewed-on: https://chromium-review.googlesource.com/229631 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>