src/compiler/translator/BuiltInFunctionEmulator.cpp


Log

Author Commit Date CI Message
Shahbaz Youssefi 061188a7 2021-08-04T10:07:47 Translator: General clean up General clean up done as part of other changes, split to simplify review. Bug: angleproject:4889 Bug: angleproject:6132 Change-Id: Iade9954d187a759be9edd0e3754be007f4133c56 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3071598 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 8b869a95 2021-06-13T01:09:27 Translator: Generate Ops for all built-in functions EOpCallBuiltInFunction is removed in this change, as well as the "op": "auto" property in builtin_function_declarations.txt. Instead, gen_builtin_symbols.py automatically generates Ops for every built-in function and generates the TOperator enum accordingly. This simplifies SPIR-V code generation by allowing switches to be used on operators instead of string comparisons. Bug: angleproject:4589 Bug: angleproject:4889 Change-Id: Ia351524400b0e12a10a5572e27e9b88c6ec2e61c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2958869 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: Tim Van Patten <timvp@google.com>
Stuart Morgan 9d737966 2019-08-14T12:25:12 Standardize copyright notices to project style For all "ANGLE Project" copyrights, standardize to the format specified by the style guide. Changes: - "Copyright (c)" and "Copyright(c)" changed to just "Copyright". - Removed the second half of date ranges ("Y1Y1-Y2Y2"->"Y1Y1"). - Fixed a small number of files that had no copyright date using the initial commit year from the version control history. - Fixed one instance of copyright being "The ANGLE Project" rather than "The ANGLE Project Authors" These changes are applied both to the copyright of source file, and where applicable to copyright statements that are generated by templates. BUG=angleproject:3811 Change-Id: I973dd65e4ef9deeba232d5be74c768256a0eb2e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1754397 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill b980c563 2018-11-27T11:34:27 Reformat all cpp and h files. This applies git cl format --full to all ANGLE sources. Bug: angleproject:2986 Change-Id: Ib504e618c1589332a37e97696cdc3515d739308f Reviewed-on: https://chromium-review.googlesource.com/c/1351367 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Olli Etuaho 5fec7ab2 2018-04-04T11:58:33 Identify functions by unique id in BuiltInFunctionEmulator Now that unique ids of all builtins are compile-time constants, we can use them to look up functions in BuiltInFunctionEmulator. This is simpler than using a custom struct with the name and parameters for identifying functions. This requires that we store a reference to a TFunction in those TIntermUnary nodes that were created based on a function. This decreases shader_translator binary size by about 6 KB on Windows. BUG=angleproject:2267 BUG=chromium:823856 TEST=angle_unittests Change-Id: Idd5a00c772c6f26dd36fdbbfbe161d22ab27c2fe Reviewed-on: https://chromium-review.googlesource.com/995372 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho c26214de 2018-03-16T10:43:11 Move AST utilities to a subdirectory Move AST related utilities to compiler/translator/tree_util. BUG=angleproject:2409 TEST=angle_unittests Change-Id: I7567c2f6f2710292029263257c7ac26e2a144ac8 Reviewed-on: https://chromium-review.googlesource.com/966032 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Kai Ninomiya 614dd0f5 2017-11-22T14:04:48 Replace TCache with static TType instances Replaces TCache with (static generation + static/dynamic lookups) of TType instances, using compile-time template and constexpr magic. Work started by jmadill here: https://crrev.com/c/776280 With more contributions from jmadill here: https://crrev.com/c/801494 Bug: angleproject:1432 Change-Id: I07181543f8fee4b2606cdd2d0738351e83d4ce57 Reviewed-on: https://chromium-review.googlesource.com/786317 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho c634a637 2017-05-18T14:09:49 Remove webgl_ prefix from emulated function names The prefix is unnecessary now that user-defined names are prefixed in both GLSL and HLSL output. Removing the prefix makes compiler output a bit simpler to read. BUG=angleproject:2038 TEST=angle_unittests Change-Id: I9ffc508f50d6146a2d85798875c88e2c385b83fe Reviewed-on: https://chromium-review.googlesource.com/508730 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho cccf2b00 2017-07-05T14:50:54 Reorganize AST traversal utility code Define TIntermTraverser and TIntermLValueTrackingTraverser in a separate header file. hash() function is moved out from TIntermTraverser as it is not related to the core functionality of traversing and transforming ASTs. Also reorganize some traversers to follow common conventions: - Intermediate output is now in OutputTree.h/.cpp - Max tree depth check is now in IsASTDepthBelowLimit.h/.cpp BUG=angleproject:1490 TEST=angle_unittests Change-Id: Id4968aa9d4e24d0c5bac90dc147fc9f310de0184 Reviewed-on: https://chromium-review.googlesource.com/559531 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Jamie Madill 35bcad42 2017-06-06T15:12:27 Optimize builtin function emulator class. This refactor uses a generator to produce static arrays instead of using a bunch of std::map inserting statements. It speeds up shader translation because every shader compile would create and tear down this table. Currently it is implemented as a flat array, but in the future we could use compile-time hashing to implement faster lookup. BUG=chromium:697758 Change-Id: I689f7de4d9b2c8c76095bb313f4c040116fc61d2 Reviewed-on: https://chromium-review.googlesource.com/521226 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 1ecd14b8 2017-01-26T13:54:15 Fold user-definedness of function nodes into TOperator Whether a function call is user-defined is not orthogonal to TOperator associated with the call node - other ops than function calls can't be user-defined. Because of this it makes sense to store the user- definedness by having different TOperator enums for different types of calls. This patch also tags internal helper functions that have a raw definition outside the AST with a separate TOperator enum. This way they can be handled with logic that is easy to understand. Before this, function calls like this left the user-defined bit unset, despite not really being built-ins either. The EmulatePrecision traverser uses this. This is also something that could be used to clean up built-in emulation in the future. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I597fcd9789d0cc22b689ef3ce5a0cc3f621d4859 Reviewed-on: https://chromium-review.googlesource.com/433443 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho dfa75e87 2017-01-23T09:43:06 Add support for 4-parameter functions to BuiltInFunctionEmulator New entry points are needed to support built-ins with more parameters. Also, now that ops that are not function calls don't use the TIntermAggregate class any more, it's easier to exclude nodes that are not candidates for built-in emulation using a simple blacklist rather than to use a whitelist. Also includes function name style cleanup in BuiltInFunctionEmulator. This will make it possible to add necessary emulation for built-ins from ESSL 3.10. BUG=angleproject:1730 TEST=angle_unittests Change-Id: If267fc68f5cb9b2ee6703cbcbbe4d157da44a7e0 Reviewed-on: https://chromium-review.googlesource.com/431297 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho d68924e5 2017-01-02T17:34:40 Use GetOperatorString when writing GLSL unary built-in calls GetOperatorString is now used when writing GLSL for built-in calls that fall under TIntermUnary. Component-wise not TOperator enum is renamed for consistency. This also cleans up some unnecessary creation of string objects when writing built-in functions. BUG=angleproject:1682 TEST=angle_unittests, angle_end2end_tests, WebGL conformance tests Change-Id: I89b2ef222bf5af479d4977417f320789b58ace85 Reviewed-on: https://chromium-review.googlesource.com/424552 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho e180559f 2017-01-02T16:41:20 Use GetOperatorString when writing GLSL built-in function calls GetOperatorString is now used when writing GLSL for built-in calls that fall under TIntermAggregate. Component wise and not component wise TOperator enums are disambiguated from each other. BUG=angleproject:1682 TEST=angle_unittests, angle_end2end_tests, WebGL conformance tests Change-Id: I861f1e94eb695eb712592df99705848b442ef07b Reviewed-on: https://chromium-review.googlesource.com/424532 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho da9fb093 2016-12-09T17:32:29 Work around atan(y, x) bug on NVIDIA atan(y, x) is not always returning expected results on NVIDIA OpenGL drivers between versions 367 and 375. Work around this by emulating atan(y, x) using the regular atan(x) function. A fix to the driver is expected in a future release. It is most convenient to implement the vector atan(y, x) functions by using the scalar atan(y, x) function. Support for simple dependencies between emulated functions is added to BuiltInFunctionEmulator. In the current implementation one function is allowed to have at most one other function as its dependency. BUG=chromium:672380 TEST=angle_end2end_tests Change-Id: I9eba8b0b7979c7c7eaed353b264932e41830beb1 Reviewed-on: https://chromium-review.googlesource.com/419016 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill d7b1ab58 2016-12-12T14:42:19 Fix up translator style. Using git cl format. BUG=angleproject:650 Change-Id: I7d3f98d2b0dcfb0a8de6c35327db74e55c28d761 Reviewed-on: https://chromium-review.googlesource.com/419059 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Jamie Madill 45bcc784 2016-11-07T13:58:48 translator: Scope all classes with "sh". I was seeing an odd problem with our PoolAlloc conflicting with the glslang/Vulkan TIntermNode, so the fix was to move everything to a separate namespace. The bison grammars are also regenerated. No functional changes. BUG=angleproject:1576 Change-Id: I959c7afe4c092f0d458432c07b4dcee4d39513f3 Reviewed-on: https://chromium-review.googlesource.com/408267 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Jamie Madill 438dbcf1 2016-06-17T14:20:05 translator: Fix builtin function emulator use-after-free. We were calling the global pool allocator in the builtin function emulator, which would lead to us freeing TTypes that were still referenced. Fix this by using the TCache which was designed for such a purpose, and locking the allocator around the builtin function emulator to try and prevent similar bugs from creeping in. Eventually we would like to get rid of the global allocator and replace it with different pools in different contexts, which are managed more safely. BUG=620937 Change-Id: If501ff6ea4d9bf8a2b8f89f2c94a01386f79ee3a Reviewed-on: https://chromium-review.googlesource.com/353671 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Corentin Wallez e5a1f271 2015-08-21T02:58:25 Use override in all the places where it is possible This will avoid -Winconsistent-overrides in the future. Done using the -Wsuggest-override warning of GCC 5.1 BUG= Change-Id: I707a649dc368f5dd1e139fd144370abcac0b6263 Reviewed-on: https://chromium-review.googlesource.com/294920 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho 3d0d9a48 2015-06-01T12:16:36 Clean up TIntermTraverser usage Remove default parameters from TIntermTraverser. Also clean up a few dead function declarations in traversers. TEST=angle_unittests, angle_end2end_tests BUG=angleproject:1037 Change-Id: I8d126c6c2d5b53e8b14e23e3d102f204a59323b3 Reviewed-on: https://chromium-review.googlesource.com/275184 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 950457b3 2015-05-26T14:36:59 Fix destructing TStrings through BuiltInFunctionEmulator after free BuiltInFunctionEmulator gets destructed after the PoolAllocator has already freed memory. That's why BuiltInFunctionEmulator can't hold any objects that contain parts stored in the memory pool that would be accessed in its destructor. Use only pointers to TType objects inside BuiltInFunctionEmulator, so that the BuiltInFunctionEmulator destructor doesn't access TStrings which have data in the memory pool. Also fix style issues in BuiltInFunctionEmulator. BUG=angleproject:1010 TEST=dEQP-GLES3.functional.shaders.builtin_functions.* Change-Id: Ic35caf80bf125d0427c2ed2024e98657756103b6 Reviewed-on: https://chromium-review.googlesource.com/272738 Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Olli Etuaho 8efc5ad5 2015-03-03T17:21:10 Initialize BuiltInFunctionEmulator outside Compiler This moves GLSL output specific code from the Compiler class to the GLSL/ESSL translators. BUG=angleproject:865 Change-Id: I2d552e9cdb41f7d8ddfee7b0249a99d629a6d7d7 Reviewed-on: https://chromium-review.googlesource.com/255471 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 80a5a6c6 2015-01-12T15:35:27 Clean up BuiltInFunctionEmulator public interface This removes all language-specific bits from BuiltInFunctionEmulator parent class, and makes the public interface of BuiltInFunctionEmulator minimal. Writing comments around emulated function definitions is removed from OutputHLSL, they are not necessary as the emulated function definitions are just another part of the shader header. Change-Id: I9abf57d86f4e37b0674d7dfafe653298f205dd27 Reviewed-on: https://chromium-review.googlesource.com/240230 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Nicolas Capens <capn@chromium.org> Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho e39706d0 2014-12-30T16:40:36 Implement simple ESSL3 matrix functions Add support for built-in functions outerProduct, determinant, transpose and the variations of matrixCompMult that were previously unsupported. BUG=angle:859 Change-Id: Ie2b9cf83cd80c5a886c6d4eb190c7ce25a32d0a4 Reviewed-on: https://chromium-review.googlesource.com/239873 Reviewed-by: Nicolas Capens <capn@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho f6bdb312 2015-01-09T15:21:38 Refactor defining emulated functions in BuiltInFunctionEmulator This removes the fixed enumeration of emulated functions in favor of a dynamic map. This makes the code more compact and flexible. The main benefit is that maintaining the list emulated functions is a lot simpler now. Change-Id: Ic9951a496b9f021c76ad5b4c3daccd89af5ac093 Reviewed-on: https://chromium-review.googlesource.com/239871 Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Nicolas Capens <capn@chromium.org>
Olli Etuaho 5c9cd3d1 2014-12-18T13:04:25 Implement hyperbolic function support for ESSL 3.00 Emulating arc hyperbolic functions is required on HLSL, where they do not exist natively. For this, BuiltInFunctionEmulator is split into GLSL and HLSL subclasses. The GLSL subclass handles the pre-existing built-in emulation implemented for working around OSX bugs, and the HLSL subclass handles emulating asinh, acosh and atanh on HLSL. BUG=angle:855 Change-Id: I0dfeffb862ac27ba7f9ecf5492ec31d9d952b273 Reviewed-on: https://chromium-review.googlesource.com/236861 Reviewed-by: Nicolas Capens <capn@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Zhenyao Mo e40d1e9c 2014-07-16T17:40:36 Fix style violations. BUG=angle:650 TEST=no behavior change Change-Id: I3096615a181b1ec2c18ce60566c3d6249975b84e Reviewed-on: https://chromium-review.googlesource.com/208569 Tested-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill 183bde55 2014-07-02T15:31:19 Return shader variable information using GLenum values. Instead of duplicating GL header define values, explictly return GLenum for variable queries in the shader inspection API. This reduces the duplicate defines in the shader compiler header. BUG=angle:466 Change-Id: Iddaaff597b188251fa2e546f352bf77ab3ac43bc Reviewed-on: https://chromium-review.googlesource.com/205860 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Nicolas Capens <capn@chromium.org>
Jamie Madill ce505553 2014-06-26T14:56:33 Revert "Return variable type queries using GLenum values." Breaks the FYI bots until we get Chromium patched. BUG=angle:466 This reverts commit 53221f5a0382887155d90f7f286e41190d4f5bfb. Change-Id: Ib28548df5c10a6f76f46e4cf8f2013dca5cf0ee2 Reviewed-on: https://chromium-review.googlesource.com/205850 Reviewed-by: Shannon Woods <shannonwoods@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill 53221f5a 2014-06-25T16:04:59 Return variable type queries using GLenum values. Instead of duplicating GL header define values, explictly return GLenum for variable queries in the shader inspection API. This reduces the duplicate defines in the shader compiler header. BUG=angle:466 Change-Id: If631b20ce68747297a946e1371def7709027a613 Reviewed-on: https://chromium-review.googlesource.com/204937 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Nicolas Capens <nicolascapens@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Geoff Lang 17732823 2013-08-29T13:46:49 Moved the compiler source files into directories based on their project and added a compiler.gypi to generate the compiler projects.